1
|
package eu.dnetlib.openaire.community;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.List;
|
5
|
|
6
|
import io.swagger.annotations.ApiOperation;
|
7
|
import io.swagger.annotations.ApiResponse;
|
8
|
import io.swagger.annotations.ApiResponses;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
11
|
import org.springframework.web.bind.annotation.*;
|
12
|
|
13
|
import static eu.dnetlib.openaire.common.ExporterConstants.*;
|
14
|
|
15
|
@RestController
|
16
|
@CrossOrigin(origins = { "*" })
|
17
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
18
|
@io.swagger.annotations.Api(tags = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
|
19
|
public class CommunityApiController {
|
20
|
|
21
|
@Autowired
|
22
|
private CommunityApiCore communityApiCore;
|
23
|
|
24
|
|
25
|
@RequestMapping(value = "/community/communities", produces = { "application/json" }, method = RequestMethod.GET)
|
26
|
@ApiOperation(
|
27
|
value = "get all community profiles",
|
28
|
notes = "get all community profiles",
|
29
|
tags = { C, R },
|
30
|
response = CommunitySummary[].class)
|
31
|
@ApiResponses(value = {
|
32
|
@ApiResponse(code = 200, message = "OK", response = CommunitySummary[].class),
|
33
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
34
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
35
|
return communityApiCore.listCommunities();
|
36
|
}
|
37
|
|
38
|
@RequestMapping(value = "/community/{id}", produces = { "application/json" }, method = RequestMethod.GET)
|
39
|
@ApiOperation(
|
40
|
value = "get community profile",
|
41
|
notes = "get community profile",
|
42
|
tags = { C, R },
|
43
|
response = CommunityDetails.class)
|
44
|
@ApiResponses(value = {
|
45
|
@ApiResponse(code = 200, message = "OK", response = CommunityDetails.class),
|
46
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
47
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
48
|
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
49
|
return communityApiCore.getCommunity(id);
|
50
|
}
|
51
|
|
52
|
@RequestMapping(value = "/community/{id}", produces = { "application/json" }, method = RequestMethod.POST)
|
53
|
@ApiOperation(
|
54
|
value = "update community details",
|
55
|
notes = "update community details",
|
56
|
tags = { C, R })
|
57
|
@ApiResponses(value = {
|
58
|
@ApiResponse(code = 200, message = "OK"),
|
59
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
60
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
61
|
public void setCommunity(
|
62
|
@PathVariable final String id,
|
63
|
@RequestBody CommunityWritableProperties properties) throws CommunityException, CommunityNotFoundException {
|
64
|
|
65
|
communityApiCore.setCommunity(id, properties);
|
66
|
}
|
67
|
|
68
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.GET)
|
69
|
@ApiOperation(
|
70
|
value = "get community projects",
|
71
|
notes = "get community projects",
|
72
|
tags = { C_PJ, R },
|
73
|
response = CommunityProject[].class)
|
74
|
@ApiResponses(value = {
|
75
|
@ApiResponse(code = 200, message = "OK", response = CommunityProject[].class),
|
76
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
77
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
78
|
public List<CommunityProject> getCommunityProjects(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
79
|
return communityApiCore.getCommunityProjects(id);
|
80
|
}
|
81
|
|
82
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.POST)
|
83
|
@ApiOperation(
|
84
|
value = "associate a project to the community",
|
85
|
notes = "associate a project to the community",
|
86
|
tags = { C_PJ, W })
|
87
|
@ApiResponses(value = {
|
88
|
@ApiResponse(code = 200, message = "OK"),
|
89
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
90
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
91
|
public CommunityProject addCommunityProject(
|
92
|
@PathVariable final String id,
|
93
|
@RequestBody final CommunityProject project) throws CommunityException, CommunityNotFoundException {
|
94
|
|
95
|
return communityApiCore.addCommunityProject(id, project);
|
96
|
}
|
97
|
|
98
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.DELETE)
|
99
|
@ApiOperation(
|
100
|
value = "remove a project from the community",
|
101
|
notes = "remove a project from the community",
|
102
|
tags = { C_PJ, W })
|
103
|
@ApiResponses(value = {
|
104
|
@ApiResponse(code = 200, message = "OK"),
|
105
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
106
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
107
|
public void deleteCommunityProject(
|
108
|
@PathVariable final String id,
|
109
|
@RequestBody final Integer projectId) throws CommunityException, CommunityNotFoundException {
|
110
|
|
111
|
communityApiCore.removeCommunityProject(id, projectId);
|
112
|
}
|
113
|
|
114
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.GET)
|
115
|
@ApiOperation(
|
116
|
value = "get the list of content providers associated to a given community",
|
117
|
notes = "get the list of content providers associated to a given community",
|
118
|
tags = { C_CP, R },
|
119
|
response = CommunityContentprovider[].class)
|
120
|
@ApiResponses(value = {
|
121
|
@ApiResponse(code = 200, message = "OK", response = CommunityContentprovider[].class),
|
122
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
123
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
124
|
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
125
|
return communityApiCore.getCommunityContentproviders(id);
|
126
|
}
|
127
|
|
128
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.POST)
|
129
|
@ApiOperation(
|
130
|
value = "associate a content provider to the community",
|
131
|
notes = "associate a content provider to the community",
|
132
|
tags = { C_CP, W })
|
133
|
@ApiResponses(value = {
|
134
|
@ApiResponse(code = 200, message = "OK"),
|
135
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
136
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
137
|
public CommunityContentprovider addCommunityContentprovider(
|
138
|
@PathVariable final String id,
|
139
|
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException, CommunityNotFoundException {
|
140
|
|
141
|
return communityApiCore.addCommunityContentprovider(id, contentprovider);
|
142
|
}
|
143
|
|
144
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.DELETE)
|
145
|
@ApiOperation(
|
146
|
value = "remove the association between a content provider and the community",
|
147
|
notes = "remove the association between a content provider and the community",
|
148
|
tags = { C_CP, W })
|
149
|
@ApiResponses(value = {
|
150
|
@ApiResponse(code = 200, message = "OK"),
|
151
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
152
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
153
|
public void removeCommunityContentprovider(
|
154
|
@PathVariable final String id,
|
155
|
@RequestBody final Integer contentproviderId) throws CommunityException, CommunityNotFoundException {
|
156
|
|
157
|
communityApiCore.removeCommunityContentProvider(id, contentproviderId);
|
158
|
}
|
159
|
|
160
|
@RequestMapping(value = "/community/{id}/subjects", produces = { "application/json" }, method = RequestMethod.POST)
|
161
|
@ApiOperation(
|
162
|
value = "associate a subject to the community",
|
163
|
notes = "associate a subject to the community",
|
164
|
tags = { C, W })
|
165
|
@ApiResponses(value = {
|
166
|
@ApiResponse(code = 200, message = "OK"),
|
167
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
168
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
169
|
public CommunityDetails addCommunitySubjects(
|
170
|
@PathVariable final String id,
|
171
|
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
172
|
|
173
|
return communityApiCore.addCommunitySubjects(id, subjects);
|
174
|
}
|
175
|
|
176
|
@RequestMapping(value = "/community/{id}/subjects", produces = { "application/json" }, method = RequestMethod.DELETE)
|
177
|
@ApiOperation(
|
178
|
value = "remove subjects from a community",
|
179
|
notes = "remove subjects from a community",
|
180
|
tags = { C, W })
|
181
|
@ApiResponses(value = {
|
182
|
@ApiResponse(code = 200, message = "OK"),
|
183
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
184
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
185
|
public CommunityDetails removeCommunitySubjects(
|
186
|
@PathVariable final String id,
|
187
|
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
188
|
|
189
|
return communityApiCore.removeCommunitySubjects(id, subjects);
|
190
|
}
|
191
|
|
192
|
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = { "application/json" }, method = RequestMethod.GET)
|
193
|
@ApiOperation(
|
194
|
value = "get the list of Zenodo communities associated to a given community",
|
195
|
notes = "get the list of Zenodo communities associated to a given community",
|
196
|
tags = { C_ZC, R },
|
197
|
response = CommunityZenodoCommunity[].class)
|
198
|
@ApiResponses(value = {
|
199
|
@ApiResponse(code = 200, message = "OK", response = CommunityZenodoCommunity[].class),
|
200
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
201
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
202
|
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
203
|
return communityApiCore.getCommunityZenodoCommunities(id);
|
204
|
}
|
205
|
|
206
|
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = { "application/json" }, method = RequestMethod.POST)
|
207
|
@ApiOperation(
|
208
|
value = "associate a Zenodo community to the community",
|
209
|
notes = "associate a Zenodo community to the community",
|
210
|
tags = { C_ZC, W })
|
211
|
@ApiResponses(value = {
|
212
|
@ApiResponse(code = 200, message = "OK"),
|
213
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
214
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
215
|
public CommunityZenodoCommunity addCommunityZenodoCommunity(
|
216
|
@PathVariable final String id,
|
217
|
@RequestBody final CommunityZenodoCommunity zenodocommunity) throws CommunityException, CommunityNotFoundException {
|
218
|
|
219
|
return communityApiCore.addCommunityZenodoCommunity(id, zenodocommunity);
|
220
|
|
221
|
}
|
222
|
|
223
|
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = { "application/json" }, method = RequestMethod.DELETE)
|
224
|
@ApiOperation(
|
225
|
value = "remove a Zenodo community from a community",
|
226
|
notes = "remove a Zenodo community from a community",
|
227
|
tags = { C_ZC, W })
|
228
|
@ApiResponses(value = {
|
229
|
@ApiResponse(code = 200, message = "OK"),
|
230
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
231
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
232
|
public void removeCommunityZenodoCommunity(
|
233
|
@PathVariable final String id,
|
234
|
@RequestBody final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException {
|
235
|
|
236
|
communityApiCore.removeCommunityZenodoCommunity(id, zenodoCommId);
|
237
|
|
238
|
}
|
239
|
|
240
|
|
241
|
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = { "application/json" }, method = RequestMethod.GET)
|
242
|
@ApiOperation(
|
243
|
value = "get the list of OpenAIRE communities associated to a given Zenodo community",
|
244
|
notes = "get the list of OpenAIRE communities associated to a given Zenodo community",
|
245
|
tags = { C_ZC, R })
|
246
|
@ApiResponses(value = {
|
247
|
@ApiResponse(code = 200, message = "OK"),
|
248
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
249
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
250
|
public List<String> getOpenAireCommunities(
|
251
|
@PathVariable final String zenodoId) throws IOException {
|
252
|
|
253
|
return communityApiCore.getOpenAIRECommunities(zenodoId);
|
254
|
|
255
|
}
|
256
|
}
|