1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.resource.citation;
20
21 import fr.cnes.doi.application.AbstractApplication;
22 import fr.cnes.doi.exception.ClientCrossCiteException;
23 import fr.cnes.doi.utils.spec.Requirement;
24 import java.util.List;
25 import org.apache.logging.log4j.Level;
26 import org.restlet.data.MediaType;
27 import org.restlet.data.Method;
28 import org.restlet.data.Status;
29 import org.restlet.ext.wadl.MethodInfo;
30 import org.restlet.resource.Get;
31 import org.restlet.resource.ResourceException;
32
33
34
35
36
37
38 public class LanguageCitationResource extends BaseCitationResource {
39
40
41
42
43
44
45 @Override
46 protected void doInit() throws ResourceException {
47 super.doInit();
48 LOG.traceEntry();
49 final StringBuilder description = new StringBuilder();
50 description.append("Selects a Language and Country.");
51 description.append("The language is used to format the citation.");
52 setDescription(description.toString());
53 LOG.traceExit();
54 }
55
56
57
58
59
60
61
62
63 @Requirement(reqId = Requirement.DOI_SRV_110, reqName = Requirement.DOI_SRV_110_NAME)
64 @Requirement(reqId = Requirement.DOI_MONIT_020, reqName = Requirement.DOI_MONIT_020_NAME)
65 @Get("json|xml")
66 public List<String> getLanguages() throws ResourceException {
67 LOG.traceEntry();
68 final List<String> result;
69 try {
70 result = this.getApp().getClient().getLanguages();
71 } catch (ClientCrossCiteException ex) {
72 ((AbstractApplication) getApplication()).sendAlertWhenDataCiteFailed(ex);
73 throw LOG.throwing(Level.ERROR, new ResourceException(ex.getStatus(), ex.
74 getDetailMessage(), ex));
75 }
76 return LOG.traceExit(result);
77 }
78
79
80
81
82
83
84 @Requirement(reqId = Requirement.DOI_DOC_010, reqName = Requirement.DOI_DOC_010_NAME)
85 @Override
86 protected final void describeGet(final MethodInfo info) {
87 info.setName(Method.GET);
88 info.setDocumentation("Retrieves the supported languages");
89 addResponseDocToMethod(info, createResponseDoc(
90 Status.SUCCESS_OK, "Operation successful",
91 listRepresentation("Language representation",
92 MediaType.TEXT_XML,
93 "A List of String representing the possible languages"))
94 );
95 addResponseDocToMethod(info, createResponseDoc(
96 Status.SUCCESS_OK, "Operation successful",
97 listRepresentation("Language representation",
98 MediaType.APPLICATION_JSON,
99 "A JSON array representing the possible languages"))
100 );
101 addResponseDocToMethod(info, createResponseDoc(
102 Status.SERVER_ERROR_INTERNAL, "server internal error, "
103 + "try later and if problem persists please contact us")
104 );
105 }
106 }