View Javadoc
1   package fr.ifremer.quadrige3.synchro.server.application;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Synchro server
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  
27  import fr.ifremer.quadrige3.synchro.server.config.SynchroServerConfiguration;
28  import fr.ifremer.quadrige3.synchro.server.config.SynchroServerConfigurationOption;
29  import fr.ifremer.quadrige3.synchro.server.pages.EmptyPage;
30  import fr.ifremer.quadrige3.synchro.server.pages.admin.ConfigPage;
31  import fr.ifremer.quadrige3.synchro.server.pages.admin.JobManagerPage;
32  import fr.ifremer.quadrige3.synchro.server.pages.admin.ToolsPage;
33  import fr.ifremer.quadrige3.synchro.server.pages.doc.DocPage;
34  import fr.ifremer.quadrige3.synchro.server.pages.doc.api.ServiceApiPage;
35  import fr.ifremer.quadrige3.synchro.server.pages.doc.debug.DebugPage;
36  import fr.ifremer.quadrige3.synchro.server.pages.doc.synchro.SynchroTablePage;
37  import fr.ifremer.quadrige3.synchro.server.pages.home.HomePage;
38  import fr.ifremer.quadrige3.synchro.server.pages.install.InstallPage;
39  import fr.ifremer.quadrige3.synchro.server.pages.login.LoginPage;
40  import fr.ifremer.quadrige3.synchro.server.resource.DownloadFileResource;
41  import fr.ifremer.quadrige3.synchro.server.service.ServiceLocator;
42  import org.apache.commons.logging.Log;
43  import org.apache.commons.logging.LogFactory;
44  import org.apache.wicket.Page;
45  import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
46  import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
47  import org.apache.wicket.markup.html.WebPage;
48  import org.apache.wicket.request.resource.IResource;
49  import org.apache.wicket.request.resource.ResourceReference;
50  import org.apache.wicket.util.time.Duration;
51  import org.nuiton.i18n.I18n;
52  import org.springframework.stereotype.Component;
53  
54  /**
55   * <p>Application class.</p>
56   *
57   */
58  @Component("wicketApplication")
59  public class Application extends AuthenticatedWebApplication {
60  
61      /* Logger */
62      private static final Log log = LogFactory.getLog(Application.class);
63  
64      private final SynchroServerConfiguration config;
65  
66      /**
67       * <p>Constructor for Application.</p>
68       */
69      public Application() {
70          // init config
71          config = SynchroServerConfiguration.getInstance();
72      }
73  
74      /** {@inheritDoc} */
75      @SuppressWarnings("unchecked")
76      @Override
77      public void init() {
78          super.init();
79  
80          // add the capability to gather extended browser info stuff like screen resolution
81          getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
82          // set the default page timeout
83          getRequestCycleSettings().setTimeout(Duration.minutes(10));
84          // set the UTF-8 charset
85          getRequestCycleSettings().setResponseRequestEncoding("UTF-8");
86          getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
87  
88  
89          mountPage("login", LoginPage.class);
90          mountPage("home", HomePage.class);
91          mountPage("admin/jobs", JobManagerPage.class);
92          mountPage("admin/config", ConfigPage.class);
93          mountPage("admin/tools", ToolsPage.class);
94          mountPage("install", InstallPage.class);
95          mountPage("doc", DocPage.class);
96          mountPage("doc/api", ServiceApiPage.class);
97          mountPage("doc/synchro", SynchroTablePage.class);
98          mountPage("debug", DebugPage.class);
99  
100         mountResource("download/${type}/${file}", new ResourceReference("downloadFile") {
101             private static final long serialVersionUID = 1L;
102 
103             @Override
104             public IResource getResource() {
105                 return new DownloadFileResource();
106             }
107         });
108 
109         getMarkupSettings().setStripWicketTags(true);
110 
111         // When all is started: init services
112         initServices();
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public Class<? extends Page> getHomePage() {
118         return EmptyPage.class;
119     }
120 
121     /**
122      * <p>getConfiguration.</p>
123      *
124      * @return a {@link fr.ifremer.quadrige3.synchro.server.config.SynchroServerConfiguration} object.
125      */
126     public SynchroServerConfiguration getConfiguration() {
127         return config;
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass() {
133         return WebSession.class;
134     }
135 
136     /** {@inheritDoc} */
137     @Override
138     protected Class<? extends WebPage> getSignInPageClass() {
139         return LoginPage.class;
140     }
141 
142     /**
143      * <p>initServices.</p>
144      */
145     protected void initServices() {
146         // Make sure the service locator is initialized
147         ServiceLocator.initDefault();
148 
149         // Make sure services has been started, if not lazy        
150         if (!config.isSynchroServiceLazy()) {
151             ServiceLocator.instance().getReferentialSynchroService();
152             ServiceLocator.instance().getDataSynchroService();
153             ServiceLocator.instance().getSynchroJobService();
154         }
155         else {
156             // warn: should be NOT lazy in production
157             log.warn(I18n.t("quadrige3.synchro.server.service.lazy", SynchroServerConfigurationOption.SYNCHRO_SERVICE_LAZY.getKey()));
158         }
159     }
160 
161 }