1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.resource.admin;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.logging.log4j.Logger;
25 import org.restlet.data.MediaType;
26 import org.restlet.data.Method;
27 import org.restlet.data.Status;
28 import org.restlet.ext.wadl.DocumentationInfo;
29 import org.restlet.ext.wadl.MethodInfo;
30 import org.restlet.ext.wadl.RepresentationInfo;
31 import org.restlet.resource.Get;
32 import org.restlet.resource.ResourceException;
33
34 import fr.cnes.doi.application.AdminApplication;
35 import fr.cnes.doi.resource.AbstractResource;
36 import fr.cnes.doi.utils.spec.Requirement;
37
38
39
40
41
42
43
44 public class SuffixProjectsDoisResource extends AbstractResource {
45
46
47
48
49 private volatile Logger LOG;
50
51
52
53
54 private volatile String suffixProject;
55
56
57
58
59
60
61
62
63
64 @Override
65 protected void doInit() throws ResourceException {
66 super.doInit();
67 final AdminApplication app = (AdminApplication) getApplication();
68 LOG = app.getLog();
69 LOG.traceEntry();
70 setDescription("This resource handles the project suffix in the DOI name");
71 this.suffixProject = getResourcePath().replace(
72 AdminApplication.ADMIN_URI + AdminApplication.SUFFIX_PROJECT_URI + "/", "");
73 final int startIndex = this.suffixProject.indexOf(AdminApplication.DOIS_URI);
74 this.suffixProject = startIndex == -1 ? null : this.suffixProject.substring(0, startIndex);
75 LOG.debug(this.suffixProject);
76
77 LOG.traceExit();
78 }
79
80
81
82
83
84
85
86 @Requirement(reqId = Requirement.DOI_SRV_140, reqName = Requirement.DOI_SRV_140_NAME)
87 @Get
88 public List<String> getProjectsNameAsJson() {
89 LOG.traceEntry();
90
91
92 List<String> response = new ArrayList<>();
93
94 try {
95 response = (((AdminApplication)getApplication()).getDois(suffixProject));
96 } catch (Exception ex) {
97 LOG.error("Error in SuffixProjectsDoisResource while searching for dois in project {}",
98 this.suffixProject, ex);
99 }
100 return LOG.traceExit(response);
101 }
102
103
104
105
106
107
108 @Requirement(reqId = Requirement.DOI_DOC_010, reqName = Requirement.DOI_DOC_010_NAME)
109 private RepresentationInfo projectsRepresentation() {
110 final RepresentationInfo repInfo = new RepresentationInfo();
111 repInfo.setMediaType(MediaType.APPLICATION_XML);
112 final DocumentationInfo docInfo = new DocumentationInfo();
113 docInfo.setTitle("Projects Representation");
114 docInfo.setTextContent("The representation contains informations about all projects.");
115 repInfo.setDocumentation(docInfo);
116 return repInfo;
117 }
118
119
120
121
122
123
124
125 @Requirement(reqId = Requirement.DOI_DOC_010, reqName = Requirement.DOI_DOC_010_NAME)
126 @Override
127 protected void describeGet(final MethodInfo info) {
128 info.setName(Method.GET);
129 info.setDocumentation("Get information about the created projects");
130 addResponseDocToMethod(info, createResponseDoc(
131 Status.SUCCESS_OK,
132 "Operation successful",
133 projectsRepresentation()
134 ));
135 }
136
137 }