1
|
package eu.dnetlib.uoaadmintoolslibrary.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintoolslibrary.entities.*;
|
4
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
|
5
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
6
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.services.*;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.web.bind.annotation.*;
|
11
|
|
12
|
import java.util.List;
|
13
|
import java.util.Set;
|
14
|
|
15
|
@RestController
|
16
|
@RequestMapping(value = "{portalType}")
|
17
|
@CrossOrigin(origins = "*")
|
18
|
public class AdminPortalRelationsController {
|
19
|
private final Logger log = Logger.getLogger(this.getClass());
|
20
|
|
21
|
@Autowired
|
22
|
private PortalService portalService;
|
23
|
|
24
|
@Autowired
|
25
|
private DivHelpContentService divHelpContentService;
|
26
|
|
27
|
@Autowired
|
28
|
private DivIdService divIdService;
|
29
|
|
30
|
@Autowired
|
31
|
private PageService pageService;
|
32
|
|
33
|
@Autowired
|
34
|
private PageHelpContentService pageHelpContentService;
|
35
|
|
36
|
// ENTITIES
|
37
|
|
38
|
@RequestMapping(value = {"/{pid}/entities"}, method = RequestMethod.GET)
|
39
|
public List<PortalEntity> getEntitiesForCommunity(@PathVariable PortalType portalType,
|
40
|
@PathVariable(value = "pid") String pid) {
|
41
|
//@RequestParam(value="entity", required=false) String entity) {
|
42
|
return portalService.getEntitiesForPortal(pid, null);
|
43
|
}
|
44
|
|
45
|
// cannot handle MismatchingContent
|
46
|
// @PreAuthorize("hasAnyAuthority(" +
|
47
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
48
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
49
|
@RequestMapping(value = {"/{pid}/entity/toggle"}, method = RequestMethod.POST)
|
50
|
public Portal toggleEntity(@PathVariable PortalType portalType,
|
51
|
@PathVariable(value = "pid") String pid,
|
52
|
@RequestBody List<String> entityIds, @RequestParam String status) throws Exception {
|
53
|
return portalService.toggleEntity(pid, entityIds, status);
|
54
|
}
|
55
|
|
56
|
// DIV HELP CONTENTS
|
57
|
|
58
|
// not used by portals
|
59
|
// // @RequestMapping(value = {"/community/{pid}/divhelpcontent", "/explore/{pid}/divhelpcontent", "/connect/{pid}/divhelpcontent"}, method = RequestMethod.GET)
|
60
|
// @RequestMapping(value = {"/{pid}/divhelpcontent/test"}, method = RequestMethod.GET)
|
61
|
// public Map<String, List<DivHelpContentResponse>> getDivHelpContentsByPositionAdmin(@PathVariable PortalType portalType,
|
62
|
// @PathVariable(value = "pid") String pid,
|
63
|
// @RequestParam(required=false) String page,
|
64
|
// @RequestParam(required=false) String active) {
|
65
|
// return portalService.getDivHelpContentsByPosition(pid, page, active);
|
66
|
// }
|
67
|
|
68
|
@RequestMapping(value = "/{pid}/divhelpcontent", method = RequestMethod.GET)
|
69
|
public List<DivHelpContentResponse> getDivHelpContents(@PathVariable PortalType portalType,
|
70
|
@PathVariable(value = "pid") String pid) {
|
71
|
return divHelpContentService.getDivHelpContents(pid, null, null, null);
|
72
|
}
|
73
|
|
74
|
@RequestMapping(value = "/{pid}/divhelpcontent/{id}", method = RequestMethod.GET)
|
75
|
public DivHelpContent getDivHelpContent(@PathVariable PortalType portalType,
|
76
|
@PathVariable(value = "pid") String pid,
|
77
|
@PathVariable(value = "id") String id) {
|
78
|
DivHelpContent divHelpContent = divHelpContentService.getDivHelpContent(id);
|
79
|
if(divHelpContent == null) {
|
80
|
throw new ContentNotFoundException("DivHelpContent with id: "+id+" not found");
|
81
|
}
|
82
|
|
83
|
Portal portal = portalService.getPortalById(divHelpContent.getPortal());
|
84
|
portalService.checkPortalInfo(pid, portalType.name(), portal, divHelpContent.getPortal());
|
85
|
return divHelpContent;
|
86
|
}
|
87
|
|
88
|
// @PreAuthorize("hasAnyAuthority(" +
|
89
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
90
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
91
|
@RequestMapping(value = "/{pid}/divhelpcontent/save", method = RequestMethod.POST)
|
92
|
public DivHelpContent saveDivHelpContent(@PathVariable PortalType portalType,
|
93
|
@PathVariable(value = "pid") String pid,
|
94
|
@RequestBody DivHelpContent divHelpContent) {
|
95
|
Portal portal = portalService.getPortal(divHelpContent.getPortal());
|
96
|
portalService.checkPortalInfo(pid, portalType.name(), portal, divHelpContent.getPortal());
|
97
|
divHelpContent.setPortal(portal.getId());
|
98
|
return divHelpContentService.insertOrUpdateDivHelpContent(divHelpContent);
|
99
|
}
|
100
|
|
101
|
// @PreAuthorize("hasAnyAuthority(" +
|
102
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
103
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
104
|
@RequestMapping(value = "/{pid}/divhelpcontent/update", method = RequestMethod.POST)
|
105
|
public DivHelpContent updateDivHelpContent(@PathVariable PortalType portalType,
|
106
|
@PathVariable(value = "pid") String pid,
|
107
|
@RequestBody DivHelpContent divHelpContent) {
|
108
|
Portal portal = portalService.getPortalById(divHelpContent.getPortal());
|
109
|
portalService.checkPortalInfo(pid, portalType.name(), portal, divHelpContent.getPortal());
|
110
|
return divHelpContentService.insertOrUpdateDivHelpContent(divHelpContent);
|
111
|
}
|
112
|
|
113
|
// cannot handle MismatchingContent
|
114
|
// @PreAuthorize("hasAnyAuthority(" +
|
115
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
116
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
117
|
@RequestMapping(value = "/{pid}/divhelpcontent/delete", method = RequestMethod.POST)
|
118
|
public Boolean deleteDivHelpContents(@PathVariable PortalType portalType,
|
119
|
@PathVariable(value = "pid") String pid,
|
120
|
@RequestBody List<String> divHelpContents) throws Exception {
|
121
|
return divHelpContentService.deleteDivHelpContents(divHelpContents);
|
122
|
}
|
123
|
|
124
|
// cannot handle MismatchingContent
|
125
|
// @PreAuthorize("hasAnyAuthority(" +
|
126
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
127
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
128
|
@RequestMapping(value = "/{pid}/divhelpcontent/toggle", method = RequestMethod.POST)
|
129
|
public List<String> toggleDivHelpContent(@PathVariable PortalType portalType,
|
130
|
@PathVariable(value = "pid") String pid,
|
131
|
@RequestBody List<String> divHelpContents, @RequestParam String status) throws Exception {
|
132
|
return divHelpContentService.toggleDivHelpContent(divHelpContents, status);
|
133
|
}
|
134
|
|
135
|
|
136
|
// DIVIDS
|
137
|
|
138
|
@RequestMapping(value = "/{pid}/div/full", method = RequestMethod.GET)
|
139
|
public List<DivIdResponse> getDivIdsFull(@PathVariable PortalType portalType,
|
140
|
@PathVariable(value = "pid") String pid,
|
141
|
@RequestParam(required = false) String page) {
|
142
|
return divIdService.getDivIdsFull(page, null, pid);
|
143
|
}
|
144
|
|
145
|
@RequestMapping(value = "/{pid}/div/{id}/full", method = RequestMethod.GET)
|
146
|
public DivIdResponse getDivIdFull(@PathVariable PortalType portalType,
|
147
|
@PathVariable(value = "pid") String pid,
|
148
|
@PathVariable(value = "id") String id) {
|
149
|
DivIdResponse divIdResponse = divIdService.getDivIdFull(id);
|
150
|
if(divIdResponse == null) {
|
151
|
throw new ContentNotFoundException("DivId with id: "+id+" not found");
|
152
|
}
|
153
|
if(!divIdResponse.getPortalType().equals(portalType.name())) {
|
154
|
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting portal info: type: "+divIdResponse.getPortalType());
|
155
|
}
|
156
|
return divIdResponse;
|
157
|
}
|
158
|
|
159
|
@RequestMapping(value = "/{pid}/div/pages", method = RequestMethod.GET)
|
160
|
public Set<String> getDivIdsPages(@PathVariable PortalType portalType,
|
161
|
@PathVariable(value = "pid") String pid) {
|
162
|
return divIdService.getDivIdsPages(pid);
|
163
|
}
|
164
|
|
165
|
// PAGES
|
166
|
|
167
|
// used
|
168
|
@RequestMapping(value = {"/{pid}/pages"}, method = RequestMethod.GET)
|
169
|
public List<PortalPage> getPagesForPortalByType(@PathVariable PortalType portalType,
|
170
|
@PathVariable(value = "pid") String pid,
|
171
|
@RequestParam(value="page_type", required=false) String page_type,
|
172
|
//@RequestParam(value="page_route", required=false) String page_route,
|
173
|
@RequestParam(value="div", required = false) String div,
|
174
|
@RequestParam(value="with_positions", required = false) String with_positions) {
|
175
|
return portalService.getPagesForPortalByType(pid, page_type, null, div, with_positions);
|
176
|
}
|
177
|
|
178
|
// not used by portals
|
179
|
// @RequestMapping(value = "/{pid}/page", method = RequestMethod.GET)
|
180
|
// public List<Page> getAllPages(@PathVariable PortalType portalType,
|
181
|
// @PathVariable(value = "pid") String pid,
|
182
|
// @RequestParam(value="page_route", required=false) String page_route,
|
183
|
// @RequestParam(value="with_positions", required=false) String with_positions) {
|
184
|
// return pageService.getAllPages(pid, page_route, with_positions);
|
185
|
// }
|
186
|
|
187
|
// // not used by portals
|
188
|
// @RequestMapping(value = {"/{id}/page"}, method = RequestMethod.POST)
|
189
|
// public Portal insertOrUpdatePage(@PathVariable PortalType portalType,
|
190
|
// @PathVariable(value = "id") String id, @RequestBody PortalPage page) {
|
191
|
// return portalService.insertOrUpdatePage(id, page);
|
192
|
// }
|
193
|
|
194
|
// used
|
195
|
// @PreAuthorize("hasAnyAuthority(" +
|
196
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
197
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
198
|
@RequestMapping(value = {"/{pid}/page/toggle"}, method = RequestMethod.POST)
|
199
|
public Portal togglePage(@PathVariable PortalType portalType,
|
200
|
@PathVariable(value = "pid") String pid,
|
201
|
@RequestBody List<String> pageIds, @RequestParam String status) throws Exception {
|
202
|
return portalService.togglePage(pid, pageIds, status);
|
203
|
}
|
204
|
|
205
|
@RequestMapping(value = "/{pid}/page", method = RequestMethod.GET)
|
206
|
public Page getPageByRoute(@PathVariable PortalType portalType,
|
207
|
@PathVariable(value = "pid") String pid,
|
208
|
@RequestParam(value="page_route", required=true) String page_route) {
|
209
|
List<Page> pageInArray = pageService.getAllPages(pid, page_route, null);
|
210
|
if(pageInArray == null || pageInArray.size() == 0) {
|
211
|
throw new ContentNotFoundException("No page with route: "+page_route + " found for portal with pid: "+pid);
|
212
|
}
|
213
|
return pageInArray.get(0);
|
214
|
}
|
215
|
|
216
|
@RequestMapping(value = "/{pid}/page/{id}", method = RequestMethod.GET)
|
217
|
public Page getPage(@PathVariable PortalType portalType,
|
218
|
@PathVariable(value = "pid") String pid,
|
219
|
@PathVariable(value = "id") String id) {
|
220
|
Page page = pageService.getPage(id);
|
221
|
if(page == null) {
|
222
|
throw new ContentNotFoundException("Page with id: "+id+" not found");
|
223
|
}
|
224
|
if(!page.getPortalType().equals(portalType.name())) {
|
225
|
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting portal info: type: "+page.getPortalType());
|
226
|
}
|
227
|
return page;
|
228
|
}
|
229
|
|
230
|
// PAGE HELP CONTENTS
|
231
|
|
232
|
// not used by portals
|
233
|
// @RequestMapping(value = {"/{pid}/pagehelpcontent/test"}, method = RequestMethod.GET)
|
234
|
// public Map<String, List<PageHelpContentResponse>> getPageHelpContentsByPositionAdmin(@PathVariable PortalType portalType,
|
235
|
// @PathVariable(value = "pid") String pid,
|
236
|
// @RequestParam(required=false) String page,
|
237
|
// @RequestParam(required=false) String active) {
|
238
|
// return portalService.getPageHelpContentsByPosition(pid, page, active);
|
239
|
// }
|
240
|
|
241
|
@RequestMapping(value = "/{pid}/pagehelpcontent", method = RequestMethod.GET)
|
242
|
public List<PageHelpContentResponse> getPageHelpContents(@PathVariable PortalType portalType,
|
243
|
@PathVariable(value = "pid") String pid) {
|
244
|
return pageHelpContentService.getPageHelpContents(pid, null, null, null, null, null);
|
245
|
}
|
246
|
|
247
|
@RequestMapping(value = "/{pid}/pagehelpcontent/{id}", method = RequestMethod.GET)
|
248
|
public PageHelpContent getPageHelpContent(@PathVariable PortalType portalType,
|
249
|
@PathVariable(value = "pid") String pid,
|
250
|
@PathVariable(value = "id") String id) {
|
251
|
PageHelpContent pageHelpContent = pageHelpContentService.getPageHelpContent(id);
|
252
|
if(pageHelpContent == null) {
|
253
|
throw new ContentNotFoundException("PageHelpContent with id: "+id+" not found");
|
254
|
}
|
255
|
|
256
|
Portal portal = portalService.getPortalById(pageHelpContent.getPortal());
|
257
|
portalService.checkPortalInfo(pid, portalType.name(), portal, pageHelpContent.getPortal());
|
258
|
return pageHelpContent;
|
259
|
}
|
260
|
|
261
|
// @PreAuthorize("hasAnyAuthority(" +
|
262
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
263
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
264
|
@RequestMapping(value = "/{pid}/pagehelpcontent/save", method = RequestMethod.POST)
|
265
|
public PageHelpContent insertPageHelpContent(@PathVariable PortalType portalType,
|
266
|
@PathVariable(value = "pid") String pid,
|
267
|
@RequestBody PageHelpContent pageHelpContent) {
|
268
|
Portal portal = portalService.getPortal(pageHelpContent.getPortal());
|
269
|
portalService.checkPortalInfo(pid, portalType.name(), portal, pageHelpContent.getPortal());
|
270
|
pageHelpContent.setPortal(portal.getId());
|
271
|
return pageHelpContentService.insertOrUpdatePageHelpContent(pageHelpContent);
|
272
|
}
|
273
|
|
274
|
// @PreAuthorize("hasAnyAuthority(" +
|
275
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
276
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
277
|
@RequestMapping(value = "/{pid}/pagehelpcontent/update", method = RequestMethod.POST)
|
278
|
public PageHelpContent updatePageHelpContent(@PathVariable PortalType portalType,
|
279
|
@PathVariable(value = "pid") String pid,
|
280
|
@RequestBody PageHelpContent pageHelpContent) {
|
281
|
Portal portal = portalService.getPortalById(pageHelpContent.getPortal());
|
282
|
portalService.checkPortalInfo(pid, portalType.name(), portal, pageHelpContent.getPortal());
|
283
|
return pageHelpContentService.insertOrUpdatePageHelpContent(pageHelpContent);
|
284
|
}
|
285
|
|
286
|
// cannot handle MismatchingContent
|
287
|
// @PreAuthorize("hasAnyAuthority(" +
|
288
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
289
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
290
|
@RequestMapping(value = "/{pid}/pagehelpcontent/delete", method = RequestMethod.POST)
|
291
|
public Boolean deletePageHelpContents(@PathVariable PortalType portalType,
|
292
|
@PathVariable(value = "pid") String pid,
|
293
|
@RequestBody List<String> pageHelpContents) throws Exception {
|
294
|
return pageHelpContentService.deletePageHelpContents(pageHelpContents);
|
295
|
}
|
296
|
|
297
|
// cannot handle MismatchingContent
|
298
|
// @PreAuthorize("hasAnyAuthority(" +
|
299
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
300
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
301
|
@RequestMapping(value = "/{pid}/pagehelpcontent/toggle", method = RequestMethod.POST)
|
302
|
public List<String> togglePageHelpContent(@PathVariable PortalType portalType,
|
303
|
@PathVariable(value = "pid") String pid,
|
304
|
@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
|
305
|
return pageHelpContentService.togglePageHelpContent(pageHelpContents, status);
|
306
|
}
|
307
|
|
308
|
}
|