Project

General

Profile

« Previous | Next » 

Revision 59470

[Trunk | Admin Tools]: Merging branch 'use-UoaAdminToolsLibrary' into trunk for revisions 58365:59468

View differences:

CommunityController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

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

  
6
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
3
import eu.dnetlib.uoaadmintools.entities.Layout;
4
import eu.dnetlib.uoaadmintools.services.LayoutService;
5
import eu.dnetlib.uoaadmintools.services.StatisticsService;
6
import eu.dnetlib.uoaadmintools.services.SubscriberService;
7
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
9
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
7 10
import org.apache.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Value;
9 11
import org.springframework.web.bind.annotation.*;
10 12
import org.springframework.beans.factory.annotation.Autowired;
11 13

  
12 14
import java.util.*;
13 15

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

  
19 22
    @Autowired
20
    private CommunityDAO communityDAO;
23
    private LayoutService layoutService;
21 24

  
22 25
    @Autowired
23
    private LayoutDAO layoutDAO;
26
    private StatisticsService statisticsService;
24 27

  
25 28
    @Autowired
26
    private PageDAO pageDAO;
29
    private SubscriberService subscriberService;
27 30

  
28 31
    @Autowired
29
    private EntityDAO entityDAO;
32
    private PortalService portalService;
30 33

  
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

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

  
56
        return communities;
34
    @RequestMapping(value = {"/"}, method = RequestMethod.GET)
35
    public List<Portal> getAllCommunities() {
36
        return portalService.getAllPortalsByType("community");
57 37
    }
58 38

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

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

  
78
            List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getPid(), null);
79
            log.debug("ENTITIES number="+entities.size());
80
            Iterator<CommunityEntity> iteratorEntities = entities.iterator();
81
            while(iteratorEntities.hasNext()) {
82
                CommunityEntity entity = iteratorEntities.next();
83
                if(!entity.getIsEnabled()) {
84
                    iteratorEntities.remove();
85
                }
86
            }
87
            communityResponse.setEntities(entities);
88
            Layout layout = layoutDAO.findById(community.getLayout());
89
            communityResponse.setLayout(layout);
90
            communitiesResponse.add(communityResponse);
91
        }
92
        return communitiesResponse;
39
    @RequestMapping(value = {"/full"}, method = RequestMethod.GET)
40
    public List<PortalResponse> getAllCommunitiesFull() {
41
        return portalService.getAllPortalsFullByType("community");
93 42
    }
94 43

  
95
    @RequestMapping(value = "/communityFull/{pid}", method = RequestMethod.GET)
96
    public CommunityResponse getCommunityFull(@PathVariable(value = "pid") String pid) {
97
        Community community = communityDAO.findByPid(pid);
98
        CommunityResponse communityResponse = new CommunityResponse(community);
44
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
45
    @RequestMapping(value = "/update", method = RequestMethod.POST)
46
    public PortalResponse updateCommunity(@RequestBody Portal portal) {
47
        PortalResponse portalResponse = portalService.updatePortal(portal);
99 48

  
100
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
101
        Iterator<CommunityPage> iteratorPages = pages.iterator();
102
        while(iteratorPages.hasNext()) {
103
            CommunityPage page = iteratorPages.next();
104
            if(!page.getIsEnabled()) {
105
                iteratorPages.remove();
106
            }
49
        String old_pid = portalResponse.getPid();
50
        String new_pid = portal.getPid();
51
        if(!old_pid.equals(new_pid)) {
52
            statisticsService.updatePid(old_pid, new_pid);
53
            subscriberService.updatePid(old_pid, new_pid);
54
            layoutService.updatePid(old_pid, new_pid);
107 55
        }
108
        communityResponse.setPages(pages);
109 56

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

  
124
        return communityResponse;
57
        return portalResponse;
125 58
    }
126
/*
127 59

  
128
    @RequestMapping(value = "/communityFullByName/{name}", method = RequestMethod.GET)
129
    public CommunityResponse getCommunityFullByName(@PathVariable(value = "name") String name) {
130
        Community community = communityDAO.findByName(name);
131
        CommunityResponse communityResponse = new CommunityResponse(community);
60
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
61
    @RequestMapping(value = "/save", method = RequestMethod.POST)
62
    public PortalResponse insertCommunity(@RequestBody Portal portal) {
63
        PortalResponse portalResponse = portalService.insertPortal(portal);
132 64

  
133
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getId(), null, null);
134
        Iterator<CommunityPage> iteratorPages = pages.iterator();
135
        while(iteratorPages.hasNext()) {
136
            CommunityPage page = iteratorPages.next();
137
            if(!page.getIsEnabled()) {
138
                iteratorPages.remove();
139
            }
140
        }
141
        communityResponse.setPages(pages);
65
        statisticsService.createPortalStatistics(portal.getPid());
66
        subscriberService.createPortalSubscribers(portal.getPid());
142 67

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

  
153
        return communityResponse;
68
        return portalResponse;
154 69
    }
155
*/
156 70

  
157
    @RequestMapping(value = "/community/update", method = RequestMethod.POST)
158
    public CommunityResponse updateCommunity(@RequestBody Community community) {
159
        Community com = communityDAO.findById(community.getId());
71
    // cannot handle MismatchingContent
72
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
73
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
74
    public Boolean deleteCommunities(@RequestBody List<String> portals) {
75
        for (String id: portals) {
76
            String pid = portalService.deletePortal(id);
160 77

  
161
        Statistics statistics = statisticsDAO.findByPid(com.getPid());
162
        statistics.setPid(community.getPid());
163
        statisticsDAO.save(statistics);
164

  
165
        CommunitySubscribers communitySubscribers =  communitySubscribersDAO.findByPid(com.getPid());
166
        communitySubscribers.setPid(community.getPid());
167
        communitySubscribersDAO.save(communitySubscribers);
168

  
169
        com.setName(community.getName());
170
        com.setPid(community.getPid());
171
        // = this.getCommunityByCommunityResponse(communityResponse);
172
        communityDAO.save(com);
173
        CommunityResponse communityResponse = this.getCommunityFull(community.getPid());
174

  
175
        return communityResponse;
176
    }
177

  
178
    @RequestMapping(value = "/community/save", method = RequestMethod.POST)
179
    public CommunityResponse insertCommunity(@RequestBody Community community) {
180
        //Community community = this.getCommunityByCommunityResponse(communityResponse);
181

  
182
        List<CommunityEntity> communityEntities = new ArrayList<>();
183
        List<CommunityPage> communityPages = new ArrayList<>();
184
        Map<String, Boolean> entities = new HashMap<>();
185
        Map<String, Boolean> pages = new HashMap<>();
186

  
187
        for(Entity entity : entityDAO.findAll()) {
188
            entities.put(entity.getId(), true);
189

  
190
            CommunityEntity communityEntity = new CommunityEntity(entity);
191
            communityEntity.setIsEnabled(true);
192
            communityEntities.add(communityEntity);
78
            statisticsService.deleteByPid(pid);
79
            subscriberService.deletePortalSubscribers(pid);
80
            layoutService.deleteByPid(pid);
193 81
        }
194 82

  
195
        for(Page page : pageDAO.findAll()) {
196
            pages.put(page.getId(), true);
197

  
198
            CommunityPage communityPage = new CommunityPage(page);
199
            if(page.getRoute().equals("/curators") || page.getRoute().equals("/organizations")) {
200
                communityPage.setIsEnabled(false);
201
            } else {
202
                communityPage.setIsEnabled(true);
203
            }
204

  
205
            communityPages.add(communityPage);
206
        }
207

  
208
        community.setEntities(entities);
209
        community.setPages(pages);
210
        Statistics statistics =  new Statistics(community.getPid());
211
        statisticsDAO.save(statistics);
212
        CommunitySubscribers communitySubscribers =  new CommunitySubscribers(community.getPid());
213
        communitySubscribersDAO.save(communitySubscribers);
214
        Community savedCommunity = communityDAO.save(community);
215
        CommunityResponse communityResponse = this.getCommunityFull(savedCommunity.getPid());
216

  
217
        log.debug("pid of saved community: "+savedCommunity.getPid());
218

  
219
        String id = savedCommunity.getId();
220

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

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

  
242
        return communityResponse;
243
    }
244

  
245
    private Community getCommunityByCommunityResponse(CommunityResponse communityResponse) {
246
        Community community = new Community();
247
        community.setId(communityResponse.getId());
248
        community.setName(communityResponse.getName());
249

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

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

  
276
        return community;
277
    }
278

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

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

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

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

  
302
            Statistics stats = statisticsDAO.findByPid(pid);
303
            if(stats != null) {
304
                statisticsDAO.delete(stats.getId());
305
            }
306

  
307
            CommunitySubscribers communitySubscribers = communitySubscribersDAO.findByPid(pid);
308
            if(communitySubscribers != null) {
309
                communitySubscribersDAO.delete(communitySubscribers.getId());
310
            }
311

  
312
            Layout layout = layoutDAO.findById(community.getLayout());
313
            if(layout != null) {
314
                layoutDAO.delete(layout.getId());
315
            }
316

  
317
            communityDAO.delete(id);
318
        }
319

  
320 83
        return true;
321 84
    }
322 85

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

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

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

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

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

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

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

  
368
                    if(divIds.isEmpty()) {
369
                        continue;
370
                    }
371
                }
372

  
373
                Page p = pageDAO.findById(page.getKey());
374

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

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

  
387
                        return_pages.add(communityPage);
388

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

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

  
405
        String name = page.getName();
406
        boolean isEnabled = page.getIsEnabled();
407

  
408
        pages.put(name, isEnabled);
409
        community.setPages(pages);
410

  
411
        return communityDAO.save(community);
412
    }
413

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

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

  
424
        community.setPages(pages);
425
        return communityDAO.save(community);
426
    }
427

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

  
434
        for (String entityId: entityIds) {
435
            log.debug("Toggle community entity: " + entityId + " of community: " + pid + " to " + status);
436

  
437
            entities.put(entityId, Boolean.parseBoolean(status));
438

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

  
449
        community.setEntities(entities);
450
        return communityDAO.save(community);
451
    }
452

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

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

  
476
    @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.GET)
86
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
477 87
    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
478
        Community community = communityDAO.findByPid(pid);
479
        if(community.getLayout() != null) {
480
            return layoutDAO.findById(community.getLayout());
481
        } else {
482
            return null;
483
        }
88
        return layoutService.findByPid(pid);
484 89
    }
485 90

  
486
    @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.POST)
91
//    @PreAuthorize("hasAnyAuthority(" +
92
//            "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
93
//            "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
94
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
487 95
    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
488
        Community community = communityDAO.findByPid(pid);
489
        if(community.getLayout() != null) {
490
            layout.setId(community.getLayout());
491
            layout = layoutDAO.save(layout);
492
        } else {
493
            layout = layoutDAO.save(layout);
494
            community.setLayout(layout.getId());
495
            communityDAO.save(community);
496
        }
497
        return layout;
96
        return layoutService.save(layout);
498 97
    }
499

  
500

  
501
    @RequestMapping(value = "/community/{pid}/pagehelpcontent", method = RequestMethod.GET)
502
    public Map<String, List<PageHelpContentResponse>> getPageHelpContentsByPosition(@PathVariable(value = "pid") String pid,
503
                                                                       @RequestParam(required=false) String page,
504
                                                                       @RequestParam(required=false) String active) {
505
        Map<String, List<PageHelpContentResponse>> pageHelpContentResponses = new HashMap<>();
506

  
507
        List<PageHelpContentResponse> pageHelpContents = null;
508
        pageHelpContents = pageHelpContentController.getPageHelpContents(pid, page, null, active, null);
509

  
510
        pageHelpContentResponses.put("top", new ArrayList<>());
511
        pageHelpContentResponses.put("bottom", new ArrayList<>());
512
        pageHelpContentResponses.put("left", new ArrayList<>());
513
        pageHelpContentResponses.put("right", new ArrayList<>());
514

  
515
        for (PageHelpContentResponse pageHelpContentResponse : pageHelpContents) {
516
            pageHelpContentResponses.get(pageHelpContentResponse.getPlacement()).add(pageHelpContentResponse);
517
        }
518

  
519

  
520
        return pageHelpContentResponses;
521
    }
522

  
523
    @RequestMapping(value = "/community/{pid}/divhelpcontent", method = RequestMethod.GET)
524
    public Map<String, List<DivHelpContentResponse>> getDivHelpContentsByPosition(@PathVariable(value = "pid") String pid,
525
                                                                                    @RequestParam(required=false) String page,
526
                                                                                    @RequestParam(required=false) String active) {
527
        Map<String, List<DivHelpContentResponse>> divHelpContentResponses = new HashMap<>();
528

  
529
        List<DivHelpContentResponse> divHelpContents = null;
530
        divHelpContents = divHelpContentController.getDivHelpContents(pid, page, null, active);
531

  
532
        for (DivHelpContentResponse divHelpContentResponse : divHelpContents) {
533
            if(!divHelpContentResponses.containsKey(divHelpContentResponse.getDivId())) {
534
                divHelpContentResponses.put(divHelpContentResponse.getDivId().getName(), new ArrayList<>());
535
            }
536
            divHelpContentResponses.get(divHelpContentResponse.getDivId().getName()).add(divHelpContentResponse);
537
        }
538

  
539

  
540
        return divHelpContentResponses;
541
    }
542 98
}
543 99

  

Also available in: Unified diff