1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.application;
20
21 import fr.cnes.doi.client.ClientCrossCiteCitation;
22 import fr.cnes.doi.resource.citation.FormatCitationResource;
23 import fr.cnes.doi.resource.citation.LanguageCitationResource;
24 import fr.cnes.doi.resource.citation.StyleCitationResource;
25 import fr.cnes.doi.settings.Consts;
26 import fr.cnes.doi.utils.spec.Requirement;
27 import org.apache.logging.log4j.LogManager;
28 import org.apache.logging.log4j.Logger;
29 import org.apache.logging.log4j.ThreadContext;
30 import org.restlet.Request;
31 import org.restlet.Response;
32 import org.restlet.Restlet;
33 import org.restlet.data.ClientInfo;
34 import org.restlet.routing.Filter;
35 import org.restlet.routing.Router;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 @Requirement(reqId = Requirement.DOI_SRV_100, reqName = Requirement.DOI_SRV_100_NAME)
76 @Requirement(reqId = Requirement.DOI_SRV_110, reqName = Requirement.DOI_SRV_110_NAME)
77 @Requirement(reqId = Requirement.DOI_SRV_120, reqName = Requirement.DOI_SRV_120_NAME)
78 @Requirement(reqId = Requirement.DOI_MONIT_020, reqName = Requirement.DOI_MONIT_020_NAME)
79 public final class DoiCrossCiteApplication extends AbstractApplication {
80
81
82
83
84
85 public static final String STYLES_URI = "/style";
86
87
88
89
90 public static final String LANGUAGE_URI = "/language";
91
92
93
94 public static final String FORMAT_URI = "/format";
95
96
97
98 public static final String NAME = "Cross Cite Application";
99
100
101
102
103 private static final Logger LOG = LogManager.getLogger(DoiCrossCiteApplication.class.getName());
104
105
106
107
108 private final ClientCrossCiteCitation client;
109
110
111
112
113 public DoiCrossCiteApplication() {
114 super();
115 setName(NAME);
116 final StringBuilder description = new StringBuilder();
117 description.append("Books and journal articles have long benefited from "
118 + "an infrastructure that makes them easy to cite, a key element"
119 + " in the process of research and academic discourse. "
120 + "We believe that you should cite data in just the same way "
121 + "that you can cite other sources of information, "
122 + "such as articles and books.");
123 description.append("DataCite DOIs help further research and assures "
124 + "reliable, predictable, and unambiguous access to research "
125 + "data in order to:");
126 description.append("<ul>");
127 description.append("<li>support proper attribution and credit</li>");
128 description.append("<li>support collaboration and reuse of data</li>");
129 description.append("<li>enable reproducibility of findings</li>");
130 description.append("<li>foster faster and more efficient research progress, and</li>");
131 description.append("<li>provide the means to share data with future researchers</li>");
132 description.append("</ul>");
133 description.append("DataCite also looks to community practices that provide"
134 + " data citation guidance. The Joint Declaration of Data Citation"
135 + " Principles is a set of guiding principles for data within "
136 + "scholarly literature, another dataset, or any other research "
137 + "object (Data Citation Synthesis Group 2014). The FAIR Guiding "
138 + "Principles provide a guideline for the those that want to "
139 + "enhance reuse of their data (Wilkinson 2016).");
140 setDescription(description.toString());
141 final String contextMode = this.getConfig().getString(Consts.CONTEXT_MODE);
142 this.client = new ClientCrossCiteCitation(
143 ClientCrossCiteCitation.Context.valueOf(contextMode)
144 );
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 @Override
162 public Restlet createInboundRoot() {
163 LOG.traceEntry();
164
165 final Filter logContext = new Filter() {
166
167
168
169
170
171
172
173
174 @Override
175 protected int beforeHandle(final Request request, final Response response) {
176 final ClientInfo clientInfo = request.getClientInfo();
177 final String ipAddress = request.getHeaders().getFirstValue(
178 Consts.PROXIFIED_IP, clientInfo.getUpstreamAddress()
179 );
180 ThreadContext.put(Consts.LOG_IP_ADDRESS, ipAddress);
181 return Filter.CONTINUE;
182 }
183 };
184
185 final Router router = new Router(getContext());
186 router.attach(STYLES_URI, StyleCitationResource.class);
187 router.attach(LANGUAGE_URI, LanguageCitationResource.class);
188 router.attach(FORMAT_URI, FormatCitationResource.class);
189
190 logContext.setNext(router);
191
192 return LOG.traceExit(logContext);
193 }
194
195
196
197
198
199
200 public ClientCrossCiteCitation getClient() {
201 return this.client;
202 }
203
204
205
206
207
208
209 @Override
210 public Logger getLog() {
211 return LOG;
212 }
213
214 }