1 |
58021
|
konstantin
|
package eu.dnetlib.uoaadmintoolslibrary.controllers;
|
2 |
|
|
|
3 |
|
|
import org.apache.log4j.Logger;
|
4 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
5 |
|
|
import org.springframework.web.bind.annotation.*;
|
6 |
|
|
|
7 |
|
|
import java.util.*;
|
8 |
|
|
|
9 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.dao.CommunityDAO;
|
10 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.dao.DivIdDAO;
|
11 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.dao.EntityDAO;
|
12 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.dao.PageDAO;
|
13 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
|
14 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
|
15 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
|
16 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
|
17 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
|
18 |
|
|
|
19 |
|
|
@RestController
|
20 |
|
|
@CrossOrigin(origins = "*")
|
21 |
|
|
public class CommunityController {
|
22 |
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
23 |
|
|
|
24 |
|
|
@Autowired
|
25 |
|
|
private CommunityDAO communityDAO;
|
26 |
|
|
|
27 |
|
|
@Autowired
|
28 |
|
|
private PageDAO pageDAO;
|
29 |
|
|
|
30 |
|
|
@Autowired
|
31 |
|
|
private EntityDAO entityDAO;
|
32 |
|
|
|
33 |
|
|
@Autowired
|
34 |
|
|
private DivIdDAO divIdDAO;
|
35 |
|
|
|
36 |
|
|
@Autowired
|
37 |
|
|
private PageHelpContentController pageHelpContentController;
|
38 |
|
|
|
39 |
|
|
@Autowired
|
40 |
|
|
private DivHelpContentController divHelpContentController;
|
41 |
|
|
|
42 |
|
|
@RequestMapping(value = "/community", method = RequestMethod.GET)
|
43 |
|
|
public List<Community> getAllCommunities() {
|
44 |
|
|
List<Community> communities = communityDAO.findAll();
|
45 |
|
|
|
46 |
|
|
return communities;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
@RequestMapping(value = "/communityFull", method = RequestMethod.GET)
|
50 |
|
|
public List<CommunityResponse> getAllCommunitiesFull() {
|
51 |
|
|
List<Community> communities = communityDAO.findAll();
|
52 |
|
|
List<CommunityResponse> communitiesResponse = new ArrayList<>();
|
53 |
|
|
for(Community community : communities) {
|
54 |
|
|
CommunityResponse communityResponse = new CommunityResponse(community);
|
55 |
|
|
|
56 |
|
|
List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
|
57 |
|
|
log.debug("PAGES number="+pages.size());
|
58 |
|
|
Iterator<CommunityPage> iteratorPages = pages.iterator();
|
59 |
|
|
while(iteratorPages.hasNext()) {
|
60 |
|
|
CommunityPage page = iteratorPages.next();
|
61 |
|
|
if(!page.getIsEnabled()) {
|
62 |
|
|
iteratorPages.remove();
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
communityResponse.setPages(pages);
|
66 |
|
|
log.debug("PAGES set");
|
67 |
|
|
|
68 |
|
|
List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getPid(), null);
|
69 |
|
|
log.debug("ENTITIES number="+entities.size());
|
70 |
|
|
Iterator<CommunityEntity> iteratorEntities = entities.iterator();
|
71 |
|
|
while(iteratorEntities.hasNext()) {
|
72 |
|
|
CommunityEntity entity = iteratorEntities.next();
|
73 |
|
|
if(!entity.getIsEnabled()) {
|
74 |
|
|
iteratorEntities.remove();
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
communityResponse.setEntities(entities);
|
78 |
|
|
// Layout layout = layoutDAO.findById(community.getLayout());
|
79 |
|
|
// communityResponse.setLayout(layout);
|
80 |
|
|
communitiesResponse.add(communityResponse);
|
81 |
|
|
}
|
82 |
|
|
return communitiesResponse;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
@RequestMapping(value = "/communityFull/{pid}", method = RequestMethod.GET)
|
86 |
|
|
public CommunityResponse getCommunityFull(@PathVariable(value = "pid") String pid) {
|
87 |
|
|
Community community = communityDAO.findByPid(pid);
|
88 |
|
|
CommunityResponse communityResponse = new CommunityResponse(community);
|
89 |
|
|
|
90 |
|
|
List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
|
91 |
|
|
Iterator<CommunityPage> iteratorPages = pages.iterator();
|
92 |
|
|
while(iteratorPages.hasNext()) {
|
93 |
|
|
CommunityPage page = iteratorPages.next();
|
94 |
|
|
if(!page.getIsEnabled()) {
|
95 |
|
|
iteratorPages.remove();
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
communityResponse.setPages(pages);
|
99 |
|
|
|
100 |
|
|
List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getPid(), null);
|
101 |
|
|
Iterator<CommunityEntity> iteratorEntities = entities.iterator();
|
102 |
|
|
while(iteratorEntities.hasNext()) {
|
103 |
|
|
CommunityEntity entity = iteratorEntities.next();
|
104 |
|
|
if(!entity.getIsEnabled()) {
|
105 |
|
|
iteratorEntities.remove();
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
communityResponse.setEntities(entities);
|
109 |
|
|
// Layout layout = layoutDAO.findById(community.getLayout());
|
110 |
|
|
// communityResponse.setLayout(layout);
|
111 |
|
|
// communityResponse.setPages(this.getPagesForCommunityByType(community.getId(), null));
|
112 |
|
|
// communityResponse.setEntities(this.getEntitiesForCommunity(community.getId()));
|
113 |
|
|
|
114 |
|
|
return communityResponse;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
@RequestMapping(value = "/community/update", method = RequestMethod.POST)
|
118 |
|
|
public CommunityResponse updateCommunity(@RequestBody Community community) {
|
119 |
|
|
Community com = communityDAO.findById(community.getId());
|
120 |
|
|
|
121 |
|
|
// Statistics statistics = statisticsDAO.findByPid(com.getPid());
|
122 |
|
|
// statistics.setPid(community.getPid());
|
123 |
|
|
// statisticsDAO.save(statistics);
|
124 |
|
|
//
|
125 |
|
|
// CommunitySubscribers communitySubscribers = communitySubscribersDAO.findByPid(com.getPid());
|
126 |
|
|
// communitySubscribers.setPid(community.getPid());
|
127 |
|
|
// communitySubscribersDAO.save(communitySubscribers);
|
128 |
|
|
|
129 |
|
|
com.setName(community.getName());
|
130 |
|
|
com.setPid(community.getPid());
|
131 |
|
|
// = this.getCommunityByCommunityResponse(communityResponse);
|
132 |
|
|
communityDAO.save(com);
|
133 |
|
|
CommunityResponse communityResponse = this.getCommunityFull(community.getPid());
|
134 |
|
|
|
135 |
|
|
return communityResponse;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
@RequestMapping(value = "/community/save", method = RequestMethod.POST)
|
139 |
|
|
public CommunityResponse insertCommunity(@RequestBody Community community) {
|
140 |
|
|
//Community community = this.getCommunityByCommunityResponse(communityResponse);
|
141 |
|
|
|
142 |
|
|
List<CommunityEntity> communityEntities = new ArrayList<>();
|
143 |
|
|
List<CommunityPage> communityPages = new ArrayList<>();
|
144 |
|
|
Map<String, Boolean> entities = new HashMap<>();
|
145 |
|
|
Map<String, Boolean> pages = new HashMap<>();
|
146 |
|
|
|
147 |
|
|
for(Entity entity : entityDAO.findAll()) {
|
148 |
|
|
entities.put(entity.getId(), true);
|
149 |
|
|
|
150 |
|
|
CommunityEntity communityEntity = new CommunityEntity(entity);
|
151 |
|
|
communityEntity.setIsEnabled(true);
|
152 |
|
|
communityEntities.add(communityEntity);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
for(Page page : pageDAO.findAll()) {
|
156 |
|
|
pages.put(page.getId(), true);
|
157 |
|
|
|
158 |
|
|
CommunityPage communityPage = new CommunityPage(page);
|
159 |
|
|
if(page.getRoute().equals("/curators") || page.getRoute().equals("/organizations")) {
|
160 |
|
|
communityPage.setIsEnabled(false);
|
161 |
|
|
} else {
|
162 |
|
|
communityPage.setIsEnabled(true);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
communityPages.add(communityPage);
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
community.setEntities(entities);
|
169 |
|
|
community.setPages(pages);
|
170 |
|
|
// Statistics statistics = new Statistics(community.getPid());
|
171 |
|
|
// statisticsDAO.save(statistics);
|
172 |
|
|
// CommunitySubscribers communitySubscribers = new CommunitySubscribers(community.getPid());
|
173 |
|
|
// communitySubscribersDAO.save(communitySubscribers);
|
174 |
|
|
Community savedCommunity = communityDAO.save(community);
|
175 |
|
|
CommunityResponse communityResponse = this.getCommunityFull(savedCommunity.getPid());
|
176 |
|
|
|
177 |
|
|
log.debug("pid of saved community: "+savedCommunity.getPid());
|
178 |
|
|
|
179 |
|
|
String id = savedCommunity.getId();
|
180 |
|
|
|
181 |
|
|
divHelpContentController.addDivHelpContentsInCommunity(savedCommunity.getPid(), id, null);
|
182 |
|
|
pageHelpContentController.addPageHelpContentsInCommunity(savedCommunity.getPid(), id);
|
183 |
|
|
/*
|
184 |
|
|
Page page = null;
|
185 |
|
|
page = pageDAO.findByRoute("/about" );
|
186 |
|
|
if(page != null) {
|
187 |
|
|
String htmlContent = "<div><div class=\"uk-article-title custom-article-title\"> About the community </div> <p> This is an introductory text. To be updated... </p> </div>";
|
188 |
|
|
HtmlPageContent htmlPageContent = new HtmlPageContent(page.getId(), id, htmlContent);
|
189 |
|
|
htmlPageContentController.updateHtmlPageContent(htmlPageContent);
|
190 |
|
|
}
|
191 |
|
|
*/
|
192 |
|
|
|
193 |
|
|
/*
|
194 |
|
|
page = pageDAO.findByRoute("/organizations");
|
195 |
|
|
if(page != null) {
|
196 |
|
|
String htmlContent = "<div><div class=\"uk-article-title custom-article-title\"> Organizations related to the community </div> <p> This is an introductory text. Here follows the list of organizations... </p> <div class=\"uk-child-width-1-3@m uk-text-center uk-grid-match \" uk-grid > <div class=\"uk-card uk-card-default uk-margin-bottom uk-padding-remove\"> <div class=\"uk-card-media-top\"> <img src=\"https://upload.wikimedia.org/wikipedia/el/2/2b/Logo_uoa_blue.png\" alt=\"\" class=\"uk-height-small uk-responsive-height \"> </div> <div class=\"uk-card-body\"> <h3 class=\"uk-card-title\"> <a class=\"wk-link-reset\" href=\"https://www.uoa.gr/\">University of Athens</a> </h3> </div> </div> <div class=\"uk-card uk-card-default uk-margin-bottom uk-padding-remove\"> <div class=\"uk-card-media-top\"> <img src=\"https://pbs.twimg.com/profile_images/631127495933165569/ElbqhHK0_400x400.jpg\" alt=\"\" class=\"uk-height-small uk-responsive-height \"> </div> <div class=\"uk-card-body\"> <h3 class=\"uk-card-title\"> <a class=\"wk-link-reset\" href=\"https://www.athena-innovation.gr/en\">Athena Research & Innovation center</a> </h3> </div> </div> <div class=\"uk-card uk-card-default uk-margin-bottom uk-padding-remove\"> <div class=\"uk-card-media-top\"> <img src=\"\" alt=\"Logo 1\" class=\"uk-height-small uk-responsive-height \"> </div> <div class=\"uk-card-body\"> <h3 class=\"uk-card-title\"> <a class=\"wk-link-reset\" href=\"\">Organization 1</a> </h3> </div> </div> <div class=\"uk-card uk-card-default uk-margin-bottom uk-padding-remove\"> <div class=\"uk-card-media-top\"> <img src=\"\" alt=\"Logo 2\" class=\"uk-height-small uk-responsive-height \"> </div> <div class=\"uk-card-body\"> <h3 class=\"uk-card-title\"> <a class=\"wk-link-reset\" href=\"\">Organization 2</a> </h3> </div> </div> <div class=\"uk-card uk-card-default uk-margin-bottom uk-padding-remove\"> <div class=\"uk-card-media-top\"> <img src=\"\" alt=\"Logo 3\" class=\"uk-height-small uk-responsive-height \"> </div> <div class=\"uk-card-body\"> <h3 class=\"uk-card-title\"> <a class=\"wk-link-reset\" href=\"\">Organization 3</a> </h3> </div> </div> </div></div>";
|
197 |
|
|
HtmlPageContent htmlPageContent = new HtmlPageContent(page.getId(), id, htmlContent);
|
198 |
|
|
htmlPageContentController.updateHtmlPageContent(htmlPageContent);
|
199 |
|
|
}
|
200 |
|
|
*/
|
201 |
|
|
|
202 |
|
|
return communityResponse;
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
private Community getCommunityByCommunityResponse(CommunityResponse communityResponse) {
|
206 |
|
|
Community community = new Community();
|
207 |
|
|
community.setId(communityResponse.getId());
|
208 |
|
|
community.setName(communityResponse.getName());
|
209 |
|
|
|
210 |
|
|
List<CommunityEntity> fullEntities = communityResponse.getEntities();
|
211 |
|
|
Map<String, Boolean> entities = new HashMap<String, Boolean>();
|
212 |
|
|
for(CommunityEntity entity : fullEntities) {
|
213 |
|
|
entities.put(entity.getId(), true);
|
214 |
|
|
}
|
215 |
|
|
for(Entity entity : entityDAO.findAll()) {
|
216 |
|
|
if(!entities.containsKey(entity.getId())) {
|
217 |
|
|
entities.put(entity.getId(), false);
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
community.setEntities(entities);
|
221 |
|
|
|
222 |
|
|
List<CommunityPage> fullPages = communityResponse.getPages();
|
223 |
|
|
Map<String, Boolean> pages = new HashMap<String, Boolean>();
|
224 |
|
|
for(CommunityPage page : fullPages) {
|
225 |
|
|
pages.put(page.getId(), true);
|
226 |
|
|
}
|
227 |
|
|
for(Page page : pageDAO.findAll()) {
|
228 |
|
|
if(!pages.containsKey(page.getId())) {
|
229 |
|
|
pages.put(page.getId(), false);
|
230 |
|
|
}
|
231 |
|
|
}
|
232 |
|
|
community.setPages(pages);
|
233 |
|
|
// Layout layout = communityResponse.getLayout();
|
234 |
|
|
// community.setLayout(layout.getId());
|
235 |
|
|
|
236 |
|
|
return community;
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
@RequestMapping(value = "/community/delete", method = RequestMethod.POST)
|
240 |
|
|
public Boolean deleteCommunities(@RequestBody List<String> communities) throws Exception {
|
241 |
|
|
for (String id: communities) {
|
242 |
|
|
Community community = communityDAO.findById(id);
|
243 |
|
|
String pid = community.getPid();
|
244 |
|
|
|
245 |
|
|
// delete div contents related to this community
|
246 |
|
|
List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(pid, null, null, null);
|
247 |
|
|
for(DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
|
248 |
|
|
divHelpContentController.deleteDivHelpContent(divHelpContentResponse.getId());
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
// delete page contents related to this community
|
252 |
|
|
List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(pid, null, null, null, null);
|
253 |
|
|
for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
|
254 |
|
|
pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
// List<HtmlPageContent> htmlPageContents = htmlPageContentController.getHtmlPageContents(pid, null);
|
258 |
|
|
// for(HtmlPageContent htmlPageContent : htmlPageContents) {
|
259 |
|
|
// htmlPageContentController.deleteHtmlPageContent(htmlPageContent.getId());
|
260 |
|
|
// }
|
261 |
|
|
//
|
262 |
|
|
// Statistics stats = statisticsDAO.findByPid(pid);
|
263 |
|
|
// if(stats != null) {
|
264 |
|
|
// statisticsDAO.delete(stats.getId());
|
265 |
|
|
// }
|
266 |
|
|
//
|
267 |
|
|
// CommunitySubscribers communitySubscribers = communitySubscribersDAO.findByPid(pid);
|
268 |
|
|
// if(communitySubscribers != null) {
|
269 |
|
|
// communitySubscribersDAO.delete(communitySubscribers.getId());
|
270 |
|
|
// }
|
271 |
|
|
//
|
272 |
|
|
// Layout layout = layoutDAO.findById(community.getLayout());
|
273 |
|
|
// if(layout != null) {
|
274 |
|
|
// layoutDAO.delete(layout.getId());
|
275 |
|
|
// }
|
276 |
|
|
|
277 |
|
|
communityDAO.delete(id);
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
return true;
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
// @RequestMapping(value = "/community", method = RequestMethod.DELETE)
|
284 |
|
|
// public void deleteAllCommunities() {
|
285 |
|
|
// communityDAO.deleteAll();
|
286 |
|
|
// }
|
287 |
|
|
|
288 |
|
|
@RequestMapping(value = "/community", method = RequestMethod.POST)
|
289 |
|
|
public Community insertOrUpdateCommunity(@RequestBody Community community) {
|
290 |
|
|
return communityDAO.save(community);
|
291 |
|
|
}
|
292 |
|
|
|
293 |
|
|
@RequestMapping(value = "/community/{pid}", method = RequestMethod.GET)
|
294 |
|
|
public Community getCommunity(@PathVariable(value = "pid") String pid) {
|
295 |
|
|
log.debug("PID: "+ pid);
|
296 |
|
|
return communityDAO.findByPid(pid);
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
@RequestMapping(value = "/community/{id}", method = RequestMethod.DELETE)
|
300 |
|
|
public void deleteCommunity(@PathVariable(value = "id") String id) {
|
301 |
|
|
communityDAO.delete(id);
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
@RequestMapping(value = "/community/{pid}/pages", method = RequestMethod.GET)
|
305 |
|
|
public List<CommunityPage> getPagesForCommunityByType(@PathVariable(value = "pid") String pid,
|
306 |
|
|
@RequestParam(value="page_type", required=false) String page_type,
|
307 |
|
|
@RequestParam(value="page_route", required=false) String page_route,
|
308 |
|
|
@RequestParam(value="div", required = false) String div) {
|
309 |
|
|
List<CommunityPage> return_pages = new ArrayList<CommunityPage>();
|
310 |
|
|
Map<String, Boolean> pages = communityDAO.findByPid(pid).getPages();
|
311 |
|
|
|
312 |
|
|
if(pages != null) {
|
313 |
|
|
for (Map.Entry<String, Boolean> page : pages.entrySet()) {
|
314 |
|
|
if(div != null && div.equals("true")) {
|
315 |
|
|
Community community = communityDAO.findByPid(pid);
|
316 |
|
|
List<DivId> divIds = divIdDAO.findByPagesContaining(page.getKey());
|
317 |
|
|
Iterator<DivId> divIdIterator = divIds.iterator();
|
318 |
|
|
|
319 |
|
|
while (divIdIterator.hasNext()) {
|
320 |
|
|
DivId divId = divIdIterator.next();
|
321 |
|
|
if((pid.equals("openaire") && !divId.getOpenaire()) ||
|
322 |
|
|
(pid.equals("connect") && !divId.getConnect()) ||
|
323 |
|
|
(!pid.equals("openaire") && !pid.equals("connect") && !divId.getCommunities())) {
|
324 |
|
|
divIdIterator.remove();
|
325 |
|
|
}
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
if(divIds.isEmpty()) {
|
329 |
|
|
continue;
|
330 |
|
|
}
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
Page p = pageDAO.findById(page.getKey());
|
334 |
|
|
|
335 |
|
|
if((pid.equals("openaire") && p.getOpenaire()) || (pid.equals("connect") && p.getConnect()) ||(!pid.equals("openaire") && !pid.equals("connect") && p.getCommunities())) {
|
336 |
|
|
if ((page_type == null && page_route == null) || (page_route == null && p.getType().equals(page_type))
|
337 |
|
|
|| p.getRoute().equals(page_route)) {
|
338 |
|
|
CommunityPage communityPage = new CommunityPage(p);
|
339 |
|
|
|
340 |
|
|
List<Entity> entities = new ArrayList<>();
|
341 |
|
|
for (String entity : p.getEntities()) {
|
342 |
|
|
entities.add(entityDAO.findById(entity));
|
343 |
|
|
}
|
344 |
|
|
communityPage.setEntities(entities);
|
345 |
|
|
communityPage.setIsEnabled(page.getValue());
|
346 |
|
|
|
347 |
|
|
return_pages.add(communityPage);
|
348 |
|
|
|
349 |
|
|
if (page_route != null) {
|
350 |
|
|
break;
|
351 |
|
|
}
|
352 |
|
|
}
|
353 |
|
|
}
|
354 |
|
|
}
|
355 |
|
|
}
|
356 |
|
|
return_pages.sort(Comparator.comparing(CommunityPage::getName));
|
357 |
|
|
return return_pages;
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
@RequestMapping(value = "/community/{id}/page", method = RequestMethod.POST)
|
361 |
|
|
public Community insertOrUpdatePage(@PathVariable(value = "id") String id, @RequestBody CommunityPage page) {
|
362 |
|
|
Community community = communityDAO.findById(id);
|
363 |
|
|
Map<String, Boolean> pages = community.getPages();
|
364 |
|
|
|
365 |
|
|
String name = page.getName();
|
366 |
|
|
boolean isEnabled = page.getIsEnabled();
|
367 |
|
|
|
368 |
|
|
pages.put(name, isEnabled);
|
369 |
|
|
community.setPages(pages);
|
370 |
|
|
|
371 |
|
|
return communityDAO.save(community);
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
@RequestMapping(value = "community/{pid}/page/toggle", method = RequestMethod.POST)
|
375 |
|
|
public Community togglePage(@PathVariable(value = "pid") String pid, @RequestBody List<String> pageIds, @RequestParam String status) throws Exception {
|
376 |
|
|
Community community = communityDAO.findByPid(pid);
|
377 |
|
|
Map<String, Boolean> pages = community.getPages();
|
378 |
|
|
|
379 |
|
|
for (String pageId: pageIds) {
|
380 |
|
|
log.debug("Toggle community page: " + pageId + " of community: " + pid + " to " + status);
|
381 |
|
|
pages.put(pageId, Boolean.parseBoolean(status));
|
382 |
|
|
}
|
383 |
|
|
|
384 |
|
|
community.setPages(pages);
|
385 |
|
|
return communityDAO.save(community);
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
@RequestMapping(value = "community/{pid}/entity/toggle", method = RequestMethod.POST)
|
389 |
|
|
public Community toggleEntity(@PathVariable(value = "pid") String pid, @RequestBody List<String> entityIds, @RequestParam String status) throws Exception {
|
390 |
|
|
Community community = communityDAO.findByPid(pid);
|
391 |
|
|
Map<String, Boolean> entities = community.getEntities();
|
392 |
|
|
Map<String, Boolean> pages = community.getPages();
|
393 |
|
|
|
394 |
|
|
for (String entityId: entityIds) {
|
395 |
|
|
log.debug("Toggle community entity: " + entityId + " of community: " + pid + " to " + status);
|
396 |
|
|
|
397 |
|
|
entities.put(entityId, Boolean.parseBoolean(status));
|
398 |
|
|
|
399 |
|
|
if(pages != null) {
|
400 |
|
|
for (Map.Entry<String, Boolean> pageEntry : pages.entrySet()) {
|
401 |
|
|
Page page = pageDAO.findById(pageEntry.getKey());
|
402 |
|
|
if (page.getEntities().contains(entityId) && page.getType().equals("search")) {
|
403 |
|
|
pages.put(pageEntry.getKey(), Boolean.parseBoolean(status));
|
404 |
|
|
}
|
405 |
|
|
}
|
406 |
|
|
}
|
407 |
|
|
}
|
408 |
|
|
|
409 |
|
|
community.setEntities(entities);
|
410 |
|
|
return communityDAO.save(community);
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
@RequestMapping(value = "/community/{pid}/entities", method = RequestMethod.GET)
|
414 |
|
|
public List<CommunityEntity> getEntitiesForCommunity(@PathVariable(value = "pid") String pid, @RequestParam(value="entity", required=false) String entity) {
|
415 |
|
|
List<CommunityEntity> return_entities = new ArrayList<CommunityEntity>();
|
416 |
|
|
Map<String, Boolean> entities = communityDAO.findByPid(pid).getEntities();
|
417 |
|
|
|
418 |
|
|
log.debug("/community/"+pid+"/entities -- entity: "+entity);
|
419 |
|
|
if (entity != null) {
|
420 |
|
|
String entityId = entityDAO.findByPid(entity).getId();
|
421 |
|
|
CommunityEntity communityEntity = new CommunityEntity(entityDAO.findById(entityId));
|
422 |
|
|
communityEntity.setIsEnabled(entities.get(entityId));
|
423 |
|
|
return_entities.add(communityEntity);
|
424 |
|
|
} else {
|
425 |
|
|
if(entities != null) {
|
426 |
|
|
for (Map.Entry<String, Boolean> _entity : entities.entrySet()) {
|
427 |
|
|
CommunityEntity communityEntity = new CommunityEntity(entityDAO.findById(_entity.getKey()));
|
428 |
|
|
communityEntity.setIsEnabled(_entity.getValue());
|
429 |
|
|
return_entities.add(communityEntity);
|
430 |
|
|
}
|
431 |
|
|
}
|
432 |
|
|
}
|
433 |
|
|
return return_entities;
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
// @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.GET)
|
437 |
|
|
// public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
438 |
|
|
// Community community = communityDAO.findByPid(pid);
|
439 |
|
|
// if(community.getLayout() != null) {
|
440 |
|
|
// return layoutDAO.findById(community.getLayout());
|
441 |
|
|
// } else {
|
442 |
|
|
// return null;
|
443 |
|
|
// }
|
444 |
|
|
// }
|
445 |
|
|
//
|
446 |
|
|
// @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.POST)
|
447 |
|
|
// public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
448 |
|
|
// Community community = communityDAO.findByPid(pid);
|
449 |
|
|
// if(community.getLayout() != null) {
|
450 |
|
|
// layout.setId(community.getLayout());
|
451 |
|
|
// layout = layoutDAO.save(layout);
|
452 |
|
|
// } else {
|
453 |
|
|
// layout = layoutDAO.save(layout);
|
454 |
|
|
// community.setLayout(layout.getId());
|
455 |
|
|
// communityDAO.save(community);
|
456 |
|
|
// }
|
457 |
|
|
// return layout;
|
458 |
|
|
// }
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
@RequestMapping(value = "/community/{pid}/pagehelpcontent", method = RequestMethod.GET)
|
462 |
|
|
public Map<String, List<PageHelpContentResponse>> getPageHelpContentsByPosition(@PathVariable(value = "pid") String pid,
|
463 |
|
|
@RequestParam(required=false) String page,
|
464 |
|
|
@RequestParam(required=false) String active) {
|
465 |
|
|
Map<String, List<PageHelpContentResponse>> pageHelpContentResponses = new HashMap<>();
|
466 |
|
|
|
467 |
|
|
List<PageHelpContentResponse> pageHelpContents = null;
|
468 |
|
|
pageHelpContents = pageHelpContentController.getPageHelpContents(pid, page, null, active, null);
|
469 |
|
|
|
470 |
|
|
pageHelpContentResponses.put("top", new ArrayList<>());
|
471 |
|
|
pageHelpContentResponses.put("bottom", new ArrayList<>());
|
472 |
|
|
pageHelpContentResponses.put("left", new ArrayList<>());
|
473 |
|
|
pageHelpContentResponses.put("right", new ArrayList<>());
|
474 |
|
|
|
475 |
|
|
for (PageHelpContentResponse pageHelpContentResponse : pageHelpContents) {
|
476 |
|
|
pageHelpContentResponses.get(pageHelpContentResponse.getPlacement()).add(pageHelpContentResponse);
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
return pageHelpContentResponses;
|
481 |
|
|
}
|
482 |
|
|
|
483 |
|
|
@RequestMapping(value = "/community/{pid}/divhelpcontent", method = RequestMethod.GET)
|
484 |
|
|
public Map<String, List<DivHelpContentResponse>> getDivHelpContentsByPosition(@PathVariable(value = "pid") String pid,
|
485 |
|
|
@RequestParam(required=false) String page,
|
486 |
|
|
@RequestParam(required=false) String active) {
|
487 |
|
|
Map<String, List<DivHelpContentResponse>> divHelpContentResponses = new HashMap<>();
|
488 |
|
|
|
489 |
|
|
List<DivHelpContentResponse> divHelpContents = null;
|
490 |
|
|
divHelpContents = divHelpContentController.getDivHelpContents(pid, page, null, active);
|
491 |
|
|
|
492 |
|
|
for (DivHelpContentResponse divHelpContentResponse : divHelpContents) {
|
493 |
|
|
if(!divHelpContentResponses.containsKey(divHelpContentResponse.getDivId())) {
|
494 |
|
|
divHelpContentResponses.put(divHelpContentResponse.getDivId().getName(), new ArrayList<>());
|
495 |
|
|
}
|
496 |
|
|
divHelpContentResponses.get(divHelpContentResponse.getDivId().getName()).add(divHelpContentResponse);
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
return divHelpContentResponses;
|
501 |
|
|
}
|
502 |
|
|
}
|