View Javadoc

1   /*
2    * Copyright (C) 2017-2019 Centre National d'Etudes Spatiales (CNES).
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 3.0 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17   * MA 02110-1301  USA
18   */
19  package fr.cnes.doi.resource.admin;
20  
21  import fr.cnes.doi.application.AdminApplication;
22  import fr.cnes.doi.resource.AbstractResource;
23  import fr.cnes.doi.settings.Consts;
24  import fr.cnes.doi.settings.DoiSettings;
25  import java.util.Map;
26  import java.util.concurrent.ConcurrentHashMap;
27  import org.apache.logging.log4j.Logger;
28  import org.restlet.data.LocalReference;
29  import org.restlet.data.MediaType;
30  import org.restlet.data.Method;
31  import org.restlet.data.Status;
32  import org.restlet.ext.freemarker.TemplateRepresentation;
33  import org.restlet.ext.wadl.MethodInfo;
34  import org.restlet.representation.Representation;
35  import org.restlet.resource.ClientResource;
36  import org.restlet.resource.Get;
37  import org.restlet.resource.ResourceException;
38  
39  /**
40   * Retrieves IHM footer.
41   *
42   * @author Jean-Christophe Malapert (jean-christophe.malapert@cnes.fr)
43   */
44  public class FooterIhmResource extends AbstractResource {
45  
46      /**
47       * Logger.
48       */
49      private volatile Logger LOG;
50  
51      @Override
52      protected void doInit() throws ResourceException {
53          super.doInit();
54          final AdminApplication app = (AdminApplication) getApplication();
55          LOG = app.getLog();
56          LOG.traceEntry();
57          setDescription("This resource handles the GUI footer.");
58          LOG.traceExit();
59      }
60  
61      /**
62       * Creates a data model. The data model is used to replace values in the
63       * template ihm_footer.ftl.
64       *
65       * @return the data model
66       */
67      private Map<String, String> createDataModel() {
68          LOG.traceEntry();
69          final Map<String, String> dataModel = new ConcurrentHashMap<>();
70          dataModel.put("doi_prefix", DoiSettings.getInstance().getString(Consts.INIST_DOI));
71          dataModel.put("attribution", DoiSettings.getInstance().getString(Consts.ATTRIBUTION, ""));
72          return LOG.traceExit(dataModel);
73      }
74  
75      /**
76       * Returns the footer.
77       *
78       * @return the footer
79       */
80      @Get
81      public Representation getFooter() {
82          LOG.traceEntry();
83          final Map<String, String> dataModel = createDataModel();
84          final Representation configFtl = new ClientResource(LocalReference.createClapReference(
85                  "class/ihm_footer.ftl")).get();
86          return LOG.traceExit(new TemplateRepresentation(configFtl, dataModel, MediaType.TEXT_ALL));
87      }
88  
89      @Override
90      protected void describeGet(final MethodInfo info) {
91          info.setName(Method.GET);
92          info.setDocumentation("Returns the GUI footer");
93          addResponseDocToMethod(info, createResponseDoc(
94                  Status.SUCCESS_OK, "Operation successful",
95                  stringRepresentation())
96          );
97      }
98  
99  }