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.logging.api;
20  
21  import fr.cnes.doi.application.DoiMdsApplication;
22  import fr.cnes.doi.resource.mds.DoiResource;
23  import fr.cnes.doi.resource.mds.DoisResource;
24  import fr.cnes.doi.resource.mds.MetadataResource;
25  import fr.cnes.doi.resource.mds.MetadatasResource;
26  import fr.cnes.doi.server.DoiServer;
27  import fr.cnes.doi.services.DoiMonitoring;
28  import fr.cnes.doi.settings.Consts;
29  import fr.cnes.doi.settings.DoiSettings;
30  import fr.cnes.doi.utils.spec.Requirement;
31  import org.restlet.Context;
32  import org.restlet.data.Method;
33  import org.restlet.routing.Filter;
34  import org.restlet.service.LogService;
35  
36  /**
37   * Creates a LOG service to monitor the speed of applications.
38   *
39   * @author Jean-Christophe Malapert (jean-christophe.malapert@cnes.fr)
40   */
41  @Requirement(reqId = Requirement.DOI_ARCHI_020, reqName = Requirement.DOI_ARCHI_020_NAME)
42  public class DoiLogDataServer extends LogService {
43  
44      /**
45       * Constructs a new logger.
46       *
47       * @param logName logger name
48       * @param isEnabled true when logger is enabled otherwise false
49       */
50      public DoiLogDataServer(final String logName,
51              final boolean isEnabled) {
52          super(isEnabled);
53          this.setLoggerName(logName);
54          this.setResponseLogFormat(DoiSettings.getInstance().getString(Consts.LOG_FORMAT));
55      }
56  
57      /**
58       * Create the filter that should be invoked for incoming calls
59       *
60       * @param context context
61       * @return filter
62       */
63      @Override
64      public Filter createInboundFilter(final Context context) {
65          return new MonitoringLogFilter(context, initMonitoring(), this);
66      }
67  
68      /**
69       * Init Monitoring
70       *
71       * @return monitoring object
72       */
73      private DoiMonitoring initMonitoring() {
74  
75          final DoiMonitoring monitoring = new DoiMonitoring();
76          monitoring.register(Method.GET,
77                  DoiServer.MDS_URI + DoiMdsApplication.DOI_URI,
78                  DoisResource.LIST_ALL_DOIS
79          );
80          monitoring.register(Method.POST,
81                  DoiServer.MDS_URI + DoiMdsApplication.DOI_URI,
82                  DoisResource.CREATE_DOI
83          );
84          monitoring.register(Method.GET,
85                  DoiServer.MDS_URI + DoiMdsApplication.DOI_URI + DoiMdsApplication.DOI_NAME_URI,
86                  DoiResource.GET_DOI
87          );
88          monitoring.register(Method.POST,
89                  DoiServer.MDS_URI + DoiMdsApplication.METADATAS_URI,
90                  MetadatasResource.CREATE_METADATA
91          );
92          monitoring.register(Method.GET,
93                  DoiServer.MDS_URI + DoiMdsApplication.METADATAS_URI
94                  + DoiMdsApplication.DOI_NAME_URI,
95                  MetadataResource.GET_METADATA
96          );
97          monitoring.register(Method.DELETE,
98                  DoiServer.MDS_URI + DoiMdsApplication.METADATAS_URI
99                  + DoiMdsApplication.DOI_NAME_URI,
100                 MetadataResource.DELETE_METADATA
101         );
102 
103         return monitoring;
104     }
105 
106 }