1
|
package eu.dnetlib.openaire.exporter.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.web.bind.annotation.*;
|
10
|
|
11
|
import static eu.dnetlib.openaire.exporter.ExporterConstants.*;
|
12
|
|
13
|
@RestController
|
14
|
@io.swagger.annotations.Api(tags = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
|
15
|
public class CommunityApiController {
|
16
|
|
17
|
@Autowired
|
18
|
private CommunityApiCore communityApiCore;
|
19
|
|
20
|
@RequestMapping(value = "/community/communities", produces = { "application/json" }, method = RequestMethod.GET)
|
21
|
@ApiOperation(
|
22
|
value = "get all community profiles",
|
23
|
notes = "get all community profiles",
|
24
|
tags = { C, R },
|
25
|
response = CommunitySummary[].class)
|
26
|
@ApiResponses(value = {
|
27
|
@ApiResponse(code = 200, message = "OK", response = CommunitySummary[].class),
|
28
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
29
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
30
|
return communityApiCore.listCommunities();
|
31
|
}
|
32
|
|
33
|
@RequestMapping(value = "/community/{id}", produces = { "application/json" }, method = RequestMethod.GET)
|
34
|
@ApiOperation(
|
35
|
value = "get community profile",
|
36
|
notes = "get community profile",
|
37
|
tags = { C, R },
|
38
|
response = CommunityDetails.class)
|
39
|
@ApiResponses(value = {
|
40
|
@ApiResponse(code = 200, message = "OK", response = CommunityDetails.class),
|
41
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
42
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
43
|
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
44
|
return communityApiCore.getCommunity(id);
|
45
|
}
|
46
|
|
47
|
@RequestMapping(value = "/community/{id}", produces = { "application/json" }, method = RequestMethod.POST)
|
48
|
@ApiOperation(
|
49
|
value = "update community details",
|
50
|
notes = "update community details",
|
51
|
tags = { C, R })
|
52
|
@ApiResponses(value = {
|
53
|
@ApiResponse(code = 200, message = "OK"),
|
54
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
55
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
56
|
public void setCommunity(
|
57
|
@PathVariable final String id,
|
58
|
@RequestBody CommunityWritableProperties properties) throws CommunityException, CommunityNotFoundException {
|
59
|
|
60
|
communityApiCore.setCommunity(id, properties);
|
61
|
}
|
62
|
|
63
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.GET)
|
64
|
@ApiOperation(
|
65
|
value = "get community projects",
|
66
|
notes = "get community projects",
|
67
|
tags = { C_PJ, R },
|
68
|
response = CommunityProject[].class)
|
69
|
@ApiResponses(value = {
|
70
|
@ApiResponse(code = 200, message = "OK", response = CommunityProject[].class),
|
71
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
72
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
73
|
public List<CommunityProject> getCommunityProjects(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
74
|
return communityApiCore.getCommunityProjects(id);
|
75
|
}
|
76
|
|
77
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.POST)
|
78
|
@ApiOperation(
|
79
|
value = "associate a project to the community",
|
80
|
notes = "associate a project to the community",
|
81
|
tags = { C_PJ, W })
|
82
|
@ApiResponses(value = {
|
83
|
@ApiResponse(code = 200, message = "OK"),
|
84
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
85
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
86
|
public void addCommunityProject(
|
87
|
@PathVariable final String id,
|
88
|
@RequestBody final CommunityProject project) throws CommunityException, CommunityNotFoundException {
|
89
|
|
90
|
communityApiCore.addCommunityProject(id, project);
|
91
|
}
|
92
|
|
93
|
@RequestMapping(value = "/community/{id}/projects", produces = { "application/json" }, method = RequestMethod.DELETE)
|
94
|
@ApiOperation(
|
95
|
value = "remove a project from the community",
|
96
|
notes = "remove a project from the community",
|
97
|
tags = { C_PJ, W })
|
98
|
@ApiResponses(value = {
|
99
|
@ApiResponse(code = 200, message = "OK"),
|
100
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
101
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
102
|
public void deleteCommunityProject(
|
103
|
@PathVariable final String id,
|
104
|
@RequestBody final String projectId) throws CommunityException, CommunityNotFoundException {
|
105
|
|
106
|
communityApiCore.removeCommunityProject(id, projectId);
|
107
|
}
|
108
|
|
109
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.GET)
|
110
|
@ApiOperation(
|
111
|
value = "get the list of content providers associated to a given community",
|
112
|
notes = "get the list of content providers associated to a given community",
|
113
|
tags = { C_CP, R },
|
114
|
response = CommunityContentprovider[].class)
|
115
|
@ApiResponses(value = {
|
116
|
@ApiResponse(code = 200, message = "OK", response = CommunityContentprovider[].class),
|
117
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
118
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
119
|
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
120
|
return communityApiCore.getCommunityContentproviders(id);
|
121
|
}
|
122
|
|
123
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.POST)
|
124
|
@ApiOperation(
|
125
|
value = "associate a content provider to the community",
|
126
|
notes = "associate a content provider to the community",
|
127
|
tags = { C_CP, W })
|
128
|
@ApiResponses(value = {
|
129
|
@ApiResponse(code = 200, message = "OK"),
|
130
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
131
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
132
|
public void addCommunityContentprovider(
|
133
|
@PathVariable final String id,
|
134
|
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException, CommunityNotFoundException {
|
135
|
|
136
|
communityApiCore.addCommunityContentprovider(id, contentprovider);
|
137
|
}
|
138
|
|
139
|
@RequestMapping(value = "/community/{id}/contentproviders", produces = { "application/json" }, method = RequestMethod.DELETE)
|
140
|
@ApiOperation(
|
141
|
value = "remove the association between a content provider and the community",
|
142
|
notes = "remove the association between a content provider and the community",
|
143
|
tags = { C_CP, W })
|
144
|
@ApiResponses(value = {
|
145
|
@ApiResponse(code = 200, message = "OK"),
|
146
|
@ApiResponse(code = 404, message = "not found", response = CommunityNotFoundException.class),
|
147
|
@ApiResponse(code = 500, message = "unexpected error", response = CommunityException.class) })
|
148
|
public void removeCommunityContentprovider(
|
149
|
@PathVariable final String id,
|
150
|
@RequestBody final String contentproviderId) throws CommunityException, CommunityNotFoundException {
|
151
|
|
152
|
communityApiCore.removeCommunityContentProvider(id, contentproviderId);
|
153
|
}
|
154
|
|
155
|
}
|