Project

General

Profile

1
package eu.dnetlib.uoaadmintools.controllers;
2

    
3
import eu.dnetlib.uoaadmintools.dao.*;
4
import eu.dnetlib.uoaadmintools.entities.*;
5

    
6
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
7
import org.apache.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.web.bind.annotation.*;
10
import org.springframework.beans.factory.annotation.Autowired;
11

    
12
import java.util.*;
13

    
14
@RestController
15
@CrossOrigin(origins = "*")
16
public class CommunityController {
17
    private final Logger log = Logger.getLogger(this.getClass());
18

    
19
    @Autowired
20
    private CommunityDAO communityDAO;
21

    
22
    @Autowired
23
    private LayoutDAO layoutDAO;
24

    
25
    @Autowired
26
    private PageDAO pageDAO;
27

    
28
    @Autowired
29
    private EntityDAO entityDAO;
30

    
31
    @Autowired
32
    private DivIdDAO divIdDAO;
33

    
34
    @Autowired
35
    private PageHelpContentController pageHelpContentController;
36

    
37
    @Autowired
38
    private DivHelpContentController divHelpContentController;
39

    
40
    @Autowired
41
    private HtmlPageContentController htmlPageContentController;
42

    
43
    @Autowired
44
    private DivIdController divIdController;
45

    
46
    @Autowired
47
    private StatisticsDAO statisticsDAO;
48
    @Autowired
49
    private CommunitySubscribersDAO  communitySubscribersDAO;
50

    
51
    // TODO moved to properties
52
    private String defaultColor = "#EBB13E";
53

    
54
    @RequestMapping(value = "/community", method = RequestMethod.GET)
55
    public List<Community> getAllCommunities() {
56
        List<Community> communities = communityDAO.findAll();
57

    
58
        return communities;
59
    }
60

    
61
    @RequestMapping(value = "/communityFull", method = RequestMethod.GET)
62
    public List<CommunityResponse> getAllCommunitiesFull() {
63
        List<Community> communities = communityDAO.findAll();
64
        List<CommunityResponse> communitiesResponse = new ArrayList<>();
65
        for(Community community : communities) {
66
            CommunityResponse communityResponse = new CommunityResponse(community);
67

    
68
            List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
69
            log.debug("PAGES number="+pages.size());
70
            Iterator<CommunityPage> iteratorPages = pages.iterator();
71
            while(iteratorPages.hasNext()) {
72
                CommunityPage page = iteratorPages.next();
73
                if(!page.getIsEnabled()) {
74
                    iteratorPages.remove();
75
                }
76
            }
77
            communityResponse.setPages(pages);
78
            log.debug("PAGES set");
79

    
80
            List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getPid(), null);
81
            log.debug("ENTITIES number="+entities.size());
82
            Iterator<CommunityEntity> iteratorEntities = entities.iterator();
83
            while(iteratorEntities.hasNext()) {
84
                CommunityEntity entity = iteratorEntities.next();
85
                if(!entity.getIsEnabled()) {
86
                    iteratorEntities.remove();
87
                }
88
            }
89
            communityResponse.setEntities(entities);
90
            Layout layout = layoutDAO.findById(community.getLayout());
91
            communityResponse.setLayout(layout);
92
            communitiesResponse.add(communityResponse);
93
        }
94
        return communitiesResponse;
95
    }
96

    
97
    @RequestMapping(value = "/communityFull/{pid}", method = RequestMethod.GET)
98
    public CommunityResponse getCommunityFull(@PathVariable(value = "pid") String pid) {
99
        Community community = communityDAO.findByPid(pid);
100
        CommunityResponse communityResponse = new CommunityResponse(community);
101

    
102
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
103
        Iterator<CommunityPage> iteratorPages = pages.iterator();
104
        while(iteratorPages.hasNext()) {
105
            CommunityPage page = iteratorPages.next();
106
            if(!page.getIsEnabled()) {
107
                iteratorPages.remove();
108
            }
109
        }
110
        communityResponse.setPages(pages);
111

    
112
        List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getPid(), null);
113
        Iterator<CommunityEntity> iteratorEntities = entities.iterator();
114
        while(iteratorEntities.hasNext()) {
115
            CommunityEntity entity = iteratorEntities.next();
116
            if(!entity.getIsEnabled()) {
117
                iteratorEntities.remove();
118
            }
119
        }
120
        communityResponse.setEntities(entities);
121
        Layout layout = layoutDAO.findById(community.getLayout());
122
        communityResponse.setLayout(layout);
123
//        communityResponse.setPages(this.getPagesForCommunityByType(community.getId(), null));
124
//        communityResponse.setEntities(this.getEntitiesForCommunity(community.getId()));
125

    
126
        return communityResponse;
127
    }
128
/*
129

    
130
    @RequestMapping(value = "/communityFullByName/{name}", method = RequestMethod.GET)
131
    public CommunityResponse getCommunityFullByName(@PathVariable(value = "name") String name) {
132
        Community community = communityDAO.findByName(name);
133
        CommunityResponse communityResponse = new CommunityResponse(community);
134

    
135
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getId(), null, null);
136
        Iterator<CommunityPage> iteratorPages = pages.iterator();
137
        while(iteratorPages.hasNext()) {
138
            CommunityPage page = iteratorPages.next();
139
            if(!page.getIsEnabled()) {
140
                iteratorPages.remove();
141
            }
142
        }
143
        communityResponse.setPages(pages);
144

    
145
        List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getId(), null);
146
        Iterator<CommunityEntity> iteratorEntities = entities.iterator();
147
        while(iteratorEntities.hasNext()) {
148
            CommunityEntity entity = iteratorEntities.next();
149
            if(!entity.getIsEnabled()) {
150
                iteratorEntities.remove();
151
            }
152
        }
153
        communityResponse.setEntities(entities);
154

    
155
        return communityResponse;
156
    }
157
*/
158

    
159
    @RequestMapping(value = "/community/update", method = RequestMethod.POST)
160
    public CommunityResponse updateCommunity(@RequestBody Community community) {
161
        Community com = communityDAO.findById(community.getId());
162
        com.setName(community.getName());
163
        com.setPid(community.getPid());
164
        // = this.getCommunityByCommunityResponse(communityResponse);
165
        communityDAO.save(com);
166
        CommunityResponse communityResponse = this.getCommunityFull(community.getPid());
167

    
168
        return communityResponse;
169
    }
170

    
171
    @RequestMapping(value = "/community/save", method = RequestMethod.POST)
172
    public CommunityResponse insertCommunity(@RequestBody Community community) {
173
        //Community community = this.getCommunityByCommunityResponse(communityResponse);
174

    
175
        List<CommunityEntity> communityEntities = new ArrayList<>();
176
        List<CommunityPage> communityPages = new ArrayList<>();
177
        Map<String, Boolean> entities = new HashMap<>();
178
        Map<String, Boolean> pages = new HashMap<>();
179

    
180
        for(Entity entity : entityDAO.findAll()) {
181
            entities.put(entity.getId(), true);
182

    
183
            CommunityEntity communityEntity = new CommunityEntity(entity);
184
            communityEntity.setIsEnabled(true);
185
            communityEntities.add(communityEntity);
186
        }
187

    
188
        for(Page page : pageDAO.findAll()) {
189
            pages.put(page.getId(), true);
190

    
191
            CommunityPage communityPage = new CommunityPage(page);
192
            if(page.getRoute().equals("/curators") || page.getRoute().equals("/organizations")) {
193
                communityPage.setIsEnabled(false);
194
            } else {
195
                communityPage.setIsEnabled(true);
196
            }
197

    
198
            communityPages.add(communityPage);
199
        }
200

    
201
        community.setEntities(entities);
202
        community.setPages(pages);
203
        Layout layout = new Layout();
204
        layout.setColor(defaultColor);
205
        layout = layoutDAO.save(layout);
206
        community.setLayout(layout.getId());
207
        Statistics statistics =  new Statistics(community.getPid());
208
        statisticsDAO.save(statistics);
209
        CommunitySubscribers communitySubscribers =  new CommunitySubscribers(community.getPid());
210
        communitySubscribersDAO.save(communitySubscribers);
211
        Community savedCommunity = communityDAO.save(community);
212
        CommunityResponse communityResponse = this.getCommunityFull(savedCommunity.getPid());
213

    
214
        log.debug("pid of saved community: "+savedCommunity.getPid());
215

    
216
        String id = savedCommunity.getId();
217

    
218
        divHelpContentController.addDivHelpContentsInCommunity(savedCommunity.getPid(), id, null);
219
        pageHelpContentController.addPageHelpContentsInCommunity(savedCommunity.getPid(), id);
220
        /*
221
        Page page = null;
222
        page = pageDAO.findByRoute("/about" );
223
        if(page != null) {
224
            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>";
225
            HtmlPageContent htmlPageContent = new HtmlPageContent(page.getId(), id, htmlContent);
226
            htmlPageContentController.updateHtmlPageContent(htmlPageContent);
227
        }
228
        */
229

    
230
        /*
231
        page = pageDAO.findByRoute("/organizations");
232
        if(page != null) {
233
            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>";
234
            HtmlPageContent htmlPageContent = new HtmlPageContent(page.getId(), id, htmlContent);
235
            htmlPageContentController.updateHtmlPageContent(htmlPageContent);
236
        }
237
        */
238

    
239
        return communityResponse;
240
    }
241

    
242
    private Community getCommunityByCommunityResponse(CommunityResponse communityResponse) {
243
        Community community = new Community();
244
        community.setId(communityResponse.getId());
245
        community.setName(communityResponse.getName());
246

    
247
        List<CommunityEntity> fullEntities = communityResponse.getEntities();
248
        Map<String, Boolean> entities = new HashMap<String, Boolean>();
249
        for(CommunityEntity entity : fullEntities) {
250
            entities.put(entity.getId(), true);
251
        }
252
        for(Entity entity : entityDAO.findAll()) {
253
            if(!entities.containsKey(entity.getId())) {
254
                entities.put(entity.getId(), false);
255
            }
256
        }
257
        community.setEntities(entities);
258

    
259
        List<CommunityPage> fullPages = communityResponse.getPages();
260
        Map<String, Boolean> pages = new HashMap<String, Boolean>();
261
        for(CommunityPage page : fullPages) {
262
            pages.put(page.getId(), true);
263
        }
264
        for(Page page : pageDAO.findAll()) {
265
            if(!pages.containsKey(page.getId())) {
266
                pages.put(page.getId(), false);
267
            }
268
        }
269
        community.setPages(pages);
270
        Layout layout = communityResponse.getLayout();
271
        community.setLayout(layout.getId());
272

    
273
        return community;
274
    }
275

    
276
    @RequestMapping(value = "/community/delete", method = RequestMethod.POST)
277
    public Boolean deleteCommunities(@RequestBody List<String> communities) throws Exception {
278
        for (String id: communities) {
279
            Community community = communityDAO.findById(id);
280
            String pid = community.getPid();
281

    
282
            // delete div contents related to this community
283
            List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(pid, null, null, null);
284
            for(DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
285
                divHelpContentController.deleteDivHelpContent(divHelpContentResponse.getId());
286
            }
287

    
288
            // delete page contents related to this community
289
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(pid, null, null, null, null);
290
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
291
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
292
            }
293

    
294
            List<HtmlPageContent> htmlPageContents = htmlPageContentController.getHtmlPageContents(pid, null);
295
            for(HtmlPageContent htmlPageContent : htmlPageContents) {
296
                htmlPageContentController.deleteHtmlPageContent(htmlPageContent.getId());
297
            }
298

    
299
            Statistics stats = statisticsDAO.findByPid(pid);
300
            if(stats != null) {
301
                statisticsDAO.delete(stats.getId());
302
            }
303

    
304
            CommunitySubscribers communitySubscribers = communitySubscribersDAO.findByPid(pid);
305
            if(communitySubscribers != null) {
306
                communitySubscribersDAO.delete(communitySubscribers.getId());
307
            }
308

    
309
            Layout layout = layoutDAO.findById(community.getLayout());
310
            if(layout != null) {
311
                layoutDAO.delete(layout.getId());
312
            }
313

    
314
            communityDAO.delete(id);
315
        }
316

    
317
        return true;
318
    }
319

    
320
//    @RequestMapping(value = "/community", method = RequestMethod.DELETE)
321
//    public void deleteAllCommunities() {
322
//        communityDAO.deleteAll();
323
//    }
324

    
325
    @RequestMapping(value = "/community", method = RequestMethod.POST)
326
    public Community insertOrUpdateCommunity(@RequestBody Community community) {
327
        return communityDAO.save(community);
328
    }
329

    
330
    @RequestMapping(value = "/community/{pid}", method = RequestMethod.GET)
331
    public Community getCommunity(@PathVariable(value = "pid") String pid) {
332
        log.debug("PID: "+ pid);
333
        return communityDAO.findByPid(pid);
334
    }
335

    
336
    @RequestMapping(value = "/community/{id}", method = RequestMethod.DELETE)
337
    public void deleteCommunity(@PathVariable(value = "id") String id) {
338
        communityDAO.delete(id);
339
    }
340

    
341
    @RequestMapping(value = "/community/{pid}/pages", method = RequestMethod.GET)
342
    public List<CommunityPage> getPagesForCommunityByType(@PathVariable(value = "pid") String pid,
343
                                                          @RequestParam(value="page_type", required=false) String page_type,
344
                                                          @RequestParam(value="page_route", required=false) String page_route,
345
                                                          @RequestParam(value="div", required = false) String div) {
346
        List<CommunityPage> return_pages = new ArrayList<CommunityPage>();
347
        Map<String, Boolean> pages = communityDAO.findByPid(pid).getPages();
348

    
349
        if(pages != null) {
350
            for (Map.Entry<String, Boolean> page : pages.entrySet()) {
351
                if(div != null && div.equals("true")) {
352
                    Community community = communityDAO.findByPid(pid);
353
                    List<DivId> divIds = divIdDAO.findByPagesContaining(page.getKey());
354
                    Iterator<DivId> divIdIterator = divIds.iterator();
355

    
356
                    while (divIdIterator.hasNext()) {
357
                        DivId divId = divIdIterator.next();
358
                        if((pid.equals("openaire") && !divId.getOpenaire()) ||
359
                                (pid.equals("connect") && !divId.getConnect()) ||
360
                                (!pid.equals("openaire") && !pid.equals("connect") && !divId.getCommunities())) {
361
                            divIdIterator.remove();
362
                        }
363
                    }
364

    
365
                    if(divIds.isEmpty()) {
366
                        continue;
367
                    }
368
                }
369

    
370
                Page p = pageDAO.findById(page.getKey());
371

    
372
                if((pid.equals("openaire") && p.getOpenaire()) || (pid.equals("connect") && p.getConnect()) ||(!pid.equals("openaire") && !pid.equals("connect") && p.getCommunities())) {
373
                    if ((page_type == null && page_route == null) || (page_route == null && p.getType().equals(page_type))
374
                            || p.getRoute().equals(page_route)) {
375
                        CommunityPage communityPage = new CommunityPage(p);
376

    
377
                        List<Entity> entities = new ArrayList<>();
378
                        for (String entity : p.getEntities()) {
379
                            entities.add(entityDAO.findById(entity));
380
                        }
381
                        communityPage.setEntities(entities);
382
                        communityPage.setIsEnabled(page.getValue());
383

    
384
                        return_pages.add(communityPage);
385

    
386
                        if (page_route != null) {
387
                            break;
388
                        }
389
                    }
390
                }
391
            }
392
        }
393
        return_pages.sort(Comparator.comparing(CommunityPage::getName));
394
        return return_pages;
395
    }
396

    
397
    @RequestMapping(value = "/community/{id}/page", method = RequestMethod.POST)
398
    public Community insertOrUpdatePage(@PathVariable(value = "id") String id, @RequestBody CommunityPage page) {
399
        Community community = communityDAO.findById(id);
400
        Map<String, Boolean> pages = community.getPages();
401

    
402
        String name = page.getName();
403
        boolean isEnabled = page.getIsEnabled();
404

    
405
        pages.put(name, isEnabled);
406
        community.setPages(pages);
407

    
408
        return communityDAO.save(community);
409
    }
410

    
411
    @RequestMapping(value = "community/{pid}/page/toggle", method = RequestMethod.POST)
412
    public Community togglePage(@PathVariable(value = "pid") String pid, @RequestBody List<String> pageIds, @RequestParam String status) throws Exception {
413
        Community community = communityDAO.findByPid(pid);
414
        Map<String, Boolean> pages = community.getPages();
415

    
416
        for (String pageId: pageIds) {
417
            log.debug("Toggle community page: " + pageId + " of community: " + pid + " to " + status);
418
            pages.put(pageId, Boolean.parseBoolean(status));
419
        }
420

    
421
        community.setPages(pages);
422
        return communityDAO.save(community);
423
    }
424

    
425
    @RequestMapping(value = "community/{pid}/entity/toggle", method = RequestMethod.POST)
426
    public Community toggleEntity(@PathVariable(value = "pid") String pid, @RequestBody List<String> entityIds, @RequestParam String status) throws Exception {
427
        Community community = communityDAO.findByPid(pid);
428
        Map<String, Boolean> entities = community.getEntities();
429
        Map<String, Boolean> pages = community.getPages();
430

    
431
        for (String entityId: entityIds) {
432
            log.debug("Toggle community entity: " + entityId + " of community: " + pid + " to " + status);
433

    
434
            entities.put(entityId, Boolean.parseBoolean(status));
435

    
436
            if(pages != null) {
437
                for (Map.Entry<String, Boolean> pageEntry : pages.entrySet()) {
438
                    Page page = pageDAO.findById(pageEntry.getKey());
439
                    if (page.getEntities().contains(entityId) && page.getType().equals("search")) {
440
                        pages.put(pageEntry.getKey(), Boolean.parseBoolean(status));
441
                    }
442
                }
443
            }
444
        }
445

    
446
        community.setEntities(entities);
447
        return communityDAO.save(community);
448
    }
449

    
450
    @RequestMapping(value = "/community/{pid}/entities", method = RequestMethod.GET)
451
    public List<CommunityEntity> getEntitiesForCommunity(@PathVariable(value = "pid") String pid, @RequestParam(value="entity", required=false) String entity) {
452
        List<CommunityEntity> return_entities = new ArrayList<CommunityEntity>();
453
        Map<String, Boolean> entities = communityDAO.findByPid(pid).getEntities();
454

    
455
        log.debug("/community/"+pid+"/entities -- entity: "+entity);
456
        if (entity != null) {
457
            String entityId = entityDAO.findByPid(entity).getId();
458
            CommunityEntity communityEntity = new CommunityEntity(entityDAO.findById(entityId));
459
            communityEntity.setIsEnabled(entities.get(entityId));
460
            return_entities.add(communityEntity);
461
        } else {
462
            if(entities != null) {
463
                for (Map.Entry<String, Boolean> _entity : entities.entrySet()) {
464
                    CommunityEntity communityEntity = new CommunityEntity(entityDAO.findById(_entity.getKey()));
465
                    communityEntity.setIsEnabled(_entity.getValue());
466
                    return_entities.add(communityEntity);
467
                }
468
            }
469
        }
470
        return return_entities;
471
    }
472

    
473
    @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.GET)
474
    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
475
        Community community = communityDAO.findByPid(pid);
476
        return layoutDAO.findById(community.getLayout());
477
    }
478

    
479
    @RequestMapping(value = "/community/{pid}/updateLayout", method = RequestMethod.POST)
480
    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
481
        Community community = communityDAO.findByPid(pid);
482
        if(community.getLayout() != null) {
483
            layout.setId(community.getLayout());
484
            layout = layoutDAO.save(layout);
485
        } else {
486
            layout = layoutDAO.save(layout);
487
            community.setLayout(layout.getId());
488
            communityDAO.save(community);
489
        }
490
        return layout;
491
    }
492

    
493
    @RequestMapping(value = "/community/{pid}/resetLayout", method = RequestMethod.POST)
494
    public Layout resetLayoutForCommunity(@PathVariable(value = "pid") String pid) {
495
        Layout layout;
496
        Community community = communityDAO.findByPid(pid);
497
        if(community.getLayout() != null) {
498
            layout = layoutDAO.findById(community.getLayout());
499
            layout.setColor(defaultColor);
500
            layout = layoutDAO.save(layout);
501
        } else {
502
            layout = new Layout();
503
            layout.setColor(defaultColor);
504
            layout = layoutDAO.save(layout);
505
            community.setLayout(layout.getId());
506
            communityDAO.save(community);
507
        }
508
        return layout;
509
    }
510

    
511
    @RequestMapping(value = "/community/{pid}/pagehelpcontent", method = RequestMethod.GET)
512
    public Map<String, List<PageHelpContentResponse>> getPageHelpContentsByPosition(@PathVariable(value = "pid") String pid,
513
                                                                       @RequestParam(required=false) String page,
514
                                                                       @RequestParam(required=false) String active) {
515
        Map<String, List<PageHelpContentResponse>> pageHelpContentResponses = new HashMap<>();
516

    
517
        List<PageHelpContentResponse> pageHelpContents = null;
518
        pageHelpContents = pageHelpContentController.getPageHelpContents(pid, page, null, active, null);
519

    
520
        pageHelpContentResponses.put("top", new ArrayList<>());
521
        pageHelpContentResponses.put("bottom", new ArrayList<>());
522
        pageHelpContentResponses.put("left", new ArrayList<>());
523
        pageHelpContentResponses.put("right", new ArrayList<>());
524

    
525
        for (PageHelpContentResponse pageHelpContentResponse : pageHelpContents) {
526
            pageHelpContentResponses.get(pageHelpContentResponse.getPlacement()).add(pageHelpContentResponse);
527
        }
528

    
529

    
530
        return pageHelpContentResponses;
531
    }
532

    
533
    @RequestMapping(value = "/community/{pid}/divhelpcontent", method = RequestMethod.GET)
534
    public Map<String, List<DivHelpContentResponse>> getDivHelpContentsByPosition(@PathVariable(value = "pid") String pid,
535
                                                                                    @RequestParam(required=false) String page,
536
                                                                                    @RequestParam(required=false) String active) {
537
        Map<String, List<DivHelpContentResponse>> divHelpContentResponses = new HashMap<>();
538

    
539
        List<DivHelpContentResponse> divHelpContents = null;
540
        divHelpContents = divHelpContentController.getDivHelpContents(pid, page, null, active);
541

    
542
        for (DivHelpContentResponse divHelpContentResponse : divHelpContents) {
543
            if(!divHelpContentResponses.containsKey(divHelpContentResponse.getDivId())) {
544
                divHelpContentResponses.put(divHelpContentResponse.getDivId().getName(), new ArrayList<>());
545
            }
546
            divHelpContentResponses.get(divHelpContentResponse.getDivId().getName()).add(divHelpContentResponse);
547
        }
548

    
549

    
550
        return divHelpContentResponses;
551
    }
552
}
553

    
(1-1/16)