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 StyleCitationResource 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 style");
51 description.append("A \"style\" can be chosen from the list of style "
52 + "names found in the CSL style repository.");
53 description.append("Many styles are supported, including common styles "
54 + "such as apa and harvard3.");
55 setDescription(description.toString());
56 LOG.traceExit();
57 }
58
59
60
61
62
63
64
65
66 @Requirement(reqId = Requirement.DOI_SRV_100, reqName = Requirement.DOI_SRV_100_NAME)
67 @Requirement(reqId = Requirement.DOI_MONIT_020, reqName = Requirement.DOI_MONIT_020_NAME)
68 @Get("json|xml")
69 public List<String> getStyles() throws ResourceException {
70 LOG.traceEntry();
71 final List<String> result;
72 try {
73 result = this.getApp().getClient().getStyles();
74 } catch (ClientCrossCiteException ex) {
75 ((AbstractApplication) getApplication()).sendAlertWhenDataCiteFailed(ex);
76 throw LOG.throwing(Level.ERROR, new ResourceException(ex.getStatus(), ex.
77 getDetailMessage(), ex));
78 }
79 return LOG.traceExit(result);
80 }
81
82
83
84
85
86
87 @Requirement(reqId = Requirement.DOI_DOC_010, reqName = Requirement.DOI_DOC_010_NAME)
88 @Override
89 protected final void describeGet(final MethodInfo info) {
90 info.setName(Method.GET);
91 info.setDocumentation("Retrieves the list of supported styles");
92 addResponseDocToMethod(info, createResponseDoc(
93 Status.SUCCESS_OK, "Operation successful",
94 listRepresentation("Style representation", MediaType.TEXT_XML,
95 "A List of String representing the possible styles"))
96 );
97 addResponseDocToMethod(info, createResponseDoc(
98 Status.SUCCESS_OK, "Operation successful",
99 listRepresentation("Style representation",
100 MediaType.APPLICATION_JSON,
101 "A JSON array representing the possible styles"))
102 );
103 addResponseDocToMethod(info, createResponseDoc(
104 Status.SERVER_ERROR_INTERNAL, "server internal error, try later "
105 + "and if problem persists please contact us")
106 );
107 }
108 }