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