View Javadoc
1   package fr.ifremer.quadrige2.synchro.server.application;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 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.quadrige2.synchro.server.config.SynchroServerConfiguration;
28  import fr.ifremer.quadrige2.synchro.server.config.SynchroServerConfigurationOption;
29  import fr.ifremer.quadrige2.synchro.server.pages.EmptyPage;
30  import fr.ifremer.quadrige2.synchro.server.pages.admin.JobManagerPage;
31  import fr.ifremer.quadrige2.synchro.server.pages.admin.ToolsPage;
32  import fr.ifremer.quadrige2.synchro.server.pages.doc.DocPage;
33  import fr.ifremer.quadrige2.synchro.server.pages.doc.api.ServiceApiPage;
34  import fr.ifremer.quadrige2.synchro.server.pages.doc.debug.DebugPage;
35  import fr.ifremer.quadrige2.synchro.server.pages.doc.synchro.SynchroTablePage;
36  import fr.ifremer.quadrige2.synchro.server.pages.home.HomePage;
37  import fr.ifremer.quadrige2.synchro.server.pages.install.InstallPage;
38  import fr.ifremer.quadrige2.synchro.server.pages.login.LoginPage;
39  import fr.ifremer.quadrige2.synchro.server.pages.synchro.NewDatabasePage;
40  import fr.ifremer.quadrige2.synchro.server.resource.DownloadFileRessource;
41  import fr.ifremer.quadrige2.synchro.server.service.ServiceLocator;
42  import org.apache.commons.logging.Log;
43  import org.apache.commons.logging.LogFactory;
44  import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
45  import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
46  import org.apache.wicket.markup.html.WebPage;
47  import org.apache.wicket.request.resource.IResource;
48  import org.apache.wicket.request.resource.ResourceReference;
49  import org.apache.wicket.util.time.Duration;
50  import org.nuiton.i18n.I18n;
51  import org.springframework.stereotype.Component;
52  
53  /**
54   * <p>Application class.</p>
55   *
56   */
57  @Component("wicketApplication")
58  public class Application extends AuthenticatedWebApplication {
59  
60      /* Logger */
61      private static final Log log = LogFactory.getLog(Application.class);
62  
63      private final SynchroServerConfiguration config;
64  
65      /**
66       * <p>Constructor for Application.</p>
67       */
68      public Application() {
69          // init config
70          config = SynchroServerConfiguration.getInstance();
71      }
72  
73      /** {@inheritDoc} */
74      @SuppressWarnings("unchecked")
75      @Override
76      public void init() {
77          super.init();
78  
79          // add the capability to gather extended browser info stuff like screen resolution
80          getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
81          // set the default page timeout
82          getRequestCycleSettings().setTimeout(Duration.minutes(10));
83          // set the UTF-8 charset
84          getRequestCycleSettings().setResponseRequestEncoding("UTF-8");
85          getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
86  
87  
88          mountPage("login", LoginPage.class);
89          mountPage("home", HomePage.class);
90          mountPage("data", NewDatabasePage.class);
91          mountPage("admin/jobs", JobManagerPage.class);
92          mountPage("admin/tools", ToolsPage.class);
93          mountPage("install", InstallPage.class);
94          mountPage("doc", DocPage.class);
95          mountPage("doc/api", ServiceApiPage.class);
96          mountPage("doc/synchro", SynchroTablePage.class);
97          mountPage("debug", DebugPage.class);
98  
99          mountResource("download/${type}/${file}", new ResourceReference("downloadFile") {
100             private static final long serialVersionUID = 1L;
101 
102             @Override
103             public IResource getResource() {
104                 return new DownloadFileRessource();
105             }
106         });
107 
108         getMarkupSettings().setStripWicketTags(true);
109 
110         // When all is started: init services
111         initServices();
112     }
113 
114     /** {@inheritDoc} */
115     @Override
116     @SuppressWarnings("rawtypes")
117     public Class getHomePage() {
118         return EmptyPage.class;
119     }
120 
121     /**
122      * <p>getConfiguration.</p>
123      *
124      * @return a {@link fr.ifremer.quadrige2.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("quadrige2.synchro.server.service.lazy", SynchroServerConfigurationOption.SYNCHRO_SERVICE_LAZY.getKey()));
158         }
159     }
160 
161 }