Project

General

Profile

« Previous | Next » 

Revision 50612

1. Added DivId class and API : special classes to be used by explore portal pages which have steps
2. Added DivHelpContent class and API
3. Added parameter 'div' (true/false) in '/community' to get communities related to some divIds
4. Added parameter 'div' (true/false) in '/community/{pid}/pages' to get pages of a community, which are related to some divIds
5. Added parameter 'before' (true/false) in '/pagehelpcontent'
6. When a community is deleted, all divIds, div contents, page contents related to this community are deleted too
7. When a page is deleted, all divIds, div contents, page contents related to this page are deleted too (page is also deleted from all communities)
8. In 'PageHelpContent' class 'before' field renamed to 'isPriorTo'
9. Bug fixes to ask community by 'pid' not 'id'

View differences:

modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/PageHelpContentDAO.java
7 7
public interface PageHelpContentDAO {
8 8
    List<PageHelpContent> findAll();
9 9

  
10
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isActive, boolean isPriorTo);
11
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(String communityId, String position, boolean isActive);
12
    List<PageHelpContent> findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isPriorTo);
13
    List<PageHelpContent> findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isActive, boolean isPriorTo);
14
    List<PageHelpContent> findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String position, boolean isActive, boolean isPriorTo);
10 15
    List<PageHelpContent> findByCommunityAndPlacementOrderByOrderAsc(String communityId, String postion);
16
    List<PageHelpContent> findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(String communityId, boolean isActive);
17
    List<PageHelpContent> findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isPriorTo);
18
    List<PageHelpContent> findByPlacementAndIsActiveOrderByOrderAsc(String position, boolean isActive);
19
    List<PageHelpContent> findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo);
20
    List<PageHelpContent> findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo);
11 21
    List<PageHelpContent> findByCommunityOrderByPlacementAscOrderAsc(String communityId);
12 22
    List<PageHelpContent> findByPlacementOrderByOrderAsc(String postion);
23
    List<PageHelpContent> findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive);
24
    List<PageHelpContent> findByIsPriorToOrderByPlacementAscOrderAsc(boolean isPriorTo);
13 25
    List<PageHelpContent> findAllByOrderByPlacementAscOrderAsc();
14 26

  
27
    //List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String postion, boolean isActive, boolean isBefore);
28

  
29

  
15 30
    PageHelpContent findById(String Id);
16 31

  
17 32
    PageHelpContent findByIdOrderByOrder(String Id);
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBPageHelpContentDAO.java
9 9
public interface MongoDBPageHelpContentDAO extends PageHelpContentDAO, MongoRepository<PageHelpContent, String> {
10 10
    List<PageHelpContent> findAll();
11 11

  
12
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isActive, boolean isPriorTo);
13
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(String communityId, String position, boolean isActive);
14
    List<PageHelpContent> findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isPriorTo);
15
    List<PageHelpContent> findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isActive, boolean isPriorTo);
16
    List<PageHelpContent> findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String position, boolean isActive, boolean isPriorTo);
12 17
    List<PageHelpContent> findByCommunityAndPlacementOrderByOrderAsc(String communityId, String postion);
18
    List<PageHelpContent> findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(String communityId, boolean isActive);
19
    List<PageHelpContent> findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isPriorTo);
20
    List<PageHelpContent> findByPlacementAndIsActiveOrderByOrderAsc(String position, boolean isActive);
21
    List<PageHelpContent> findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo);
22
    List<PageHelpContent> findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo);
13 23
    List<PageHelpContent> findByCommunityOrderByPlacementAscOrderAsc(String communityId);
14 24
    List<PageHelpContent> findByPlacementOrderByOrderAsc(String postion);
25
    List<PageHelpContent> findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive);
26
    List<PageHelpContent> findByIsPriorToOrderByPlacementAscOrderAsc(boolean isPriorTo);
15 27
    List<PageHelpContent> findAllByOrderByPlacementAscOrderAsc();
16 28

  
29

  
30
    //List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndBeforeOrderByOrderAsc(String communityId, String postion, boolean isActive, boolean before);
31

  
17 32
    PageHelpContent findById(String Id);
18 33

  
19 34
    PageHelpContent findByIdOrderByOrder(String Id);
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContentResponse.java
16 16
    private int order;
17 17
    private String content;
18 18
    private boolean isActive = true;
19
    private boolean before = false;
19
    private boolean isPriorTo = false;
20 20

  
21 21
    public PageHelpContentResponse() {
22 22
    }
......
27 27
        this.order = pageHelpContent.getOrder();
28 28
        this.content = pageHelpContent.getContent();
29 29
        this.isActive = pageHelpContent.getIsActive();
30
        this.isPriorTo = pageHelpContent.getIsPriorTo();
30 31
    }
31 32

  
32 33
    public String getId() {
......
85 86
        this.isActive = isActive;
86 87
    }
87 88

  
88
    public boolean isBefore() { return before; }
89
    public boolean getIsPriorTo() { return isPriorTo; }
89 90

  
90
    public void setBefore(boolean before) { this.before = before; }
91
    public void setIsPriorTo(boolean isPriorTo) { this.isPriorTo = isPriorTo; }
91 92
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContent.java
16 16
    private int order;
17 17
    private String content;
18 18
    private boolean isActive = true;
19
    private boolean before = false;
19
    private boolean isPriorTo = false;
20 20

  
21 21
    public PageHelpContent() {
22 22
    }
......
77 77
        this.isActive = isActive;
78 78
    }
79 79

  
80
    public boolean isBefore() { return before; }
80
    public boolean getIsPriorTo() { return isPriorTo; }
81 81

  
82
    public void setBefore(boolean before) { this.before = before; }
82
    public void setIsPriorTo(boolean isPriorTo) { this.isPriorTo = isPriorTo; }
83 83
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/EntityController.java
99 99
        for (String id: entities) {
100 100
            entityDAO.delete(id);
101 101

  
102
            // delete entities from communities
102
            // delete entity from communities
103 103
            List<Community> communities = communityDAO.findAll();
104 104
            for( Community community : communities ) {
105 105
                Map<String, Boolean> communityEntities = community.getEntities();
......
108 108
                communityDAO.save(community);
109 109
            }
110 110

  
111
            // delete entities from pages
111
            // delete entity from pages
112 112
            List<Page> pages = pageDAO.findAll();
113 113
            for( Page page : pages ) {
114 114
                List<String> pageEntities = page.getEntities();
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

  
3 3
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
4
import eu.dnetlib.uoaadmintools.entities.Community;
5
import eu.dnetlib.uoaadmintools.entities.CommunityPage;
6
import eu.dnetlib.uoaadmintools.entities.Entity;
7
import eu.dnetlib.uoaadmintools.entities.Page;
4
import eu.dnetlib.uoaadmintools.entities.*;
8 5
import eu.dnetlib.uoaadmintools.dao.PageDAO;
9 6

  
10 7
import org.apache.log4j.Logger;
......
12 9
import org.springframework.beans.factory.annotation.Autowired;
13 10

  
14 11
import java.util.ArrayList;
12
import java.util.Iterator;
15 13
import java.util.List;
16 14
import java.util.Map;
17 15

  
......
26 24
    @Autowired
27 25
    private CommunityDAO communityDAO;
28 26

  
27
    @Autowired
28
    private PageHelpContentController pageHelpContentController;
29

  
30
    @Autowired
31
    private DivHelpContentController divHelpContentController;
32

  
33
    @Autowired
34
    private DivIdController divIdController;
35

  
29 36
    @RequestMapping(value = "/page", method = RequestMethod.GET)
30 37
    public List<Page> getAllPages() {
31 38
        return pageDAO.findAll();
......
83 90
        for (String id: pages) {
84 91
            pageDAO.delete(id);
85 92

  
86
            // delete pages from communities
93
            // delete divIds related to this page from all communities
94
            List<DivId> divIds = divIdController.getDivIds(null, id);
95
            for(DivId divId : divIds) {
96
                divIdController.deleteDivId(divId.getId());
97
            }
98

  
99
            // delete div contents related to this page from all communities
100
            List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(null, id, null);
101
            for(DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
102
                divHelpContentController.deleteDivHelpContent(divHelpContentResponse.getId());
103
            }
104

  
105
            // delete page contents related to this page from all communities
106
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, id, null, null, null);
107
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
108
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
109
            }
110

  
111
            // delete page from communities
87 112
            List<Community> communities = communityDAO.findAll();
88 113
            for( Community community : communities ) {
89 114
                Map<String, Boolean> communityPages = community.getPages();
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageHelpContentController.java
36 36
    private CommunityDAO communityDAO;
37 37

  
38 38
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
39
    public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community, @RequestParam(required=false) String page, @RequestParam(required=false) String position ) {
39
    public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community,
40
                                                             @RequestParam(required=false) String page,
41
                                                             @RequestParam(required=false) String position,
42
                                                             @RequestParam(required=false) String active,
43
                                                             @RequestParam(required=false) String before) {
40 44
        List<PageHelpContent> pageHelpContents = null;
41 45

  
42 46
        Community _community = null;
43 47
        if(community != null) {
44 48
            _community = communityDAO.findByPid(community);
45 49
        }
50
        //pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndisPriorToOrderByOrderAsc(community, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
46 51

  
47
        if(community != null && position != null){
52
        if(community != null && position != null && active != null && before != null) {
53
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(_community.getId(), position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
54
        } else if(community != null && position != null && active != null) {
55
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(_community.getId(), position, Boolean.parseBoolean(active));
56
        } else if(community != null && position != null && before != null) {
57
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(_community.getId(), position, Boolean.parseBoolean(before));
58
        } else if(community != null && active != null && before != null) {
59
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(_community.getId(), Boolean.parseBoolean(active), Boolean.parseBoolean(before));
60
        } else if(position != null && active != null && before != null) {
61
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
62
        } else if(community != null && position != null ) {
48 63
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementOrderByOrderAsc(_community.getId(), position);
64
        } else if(community != null && active != null ) {
65
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(_community.getId(), Boolean.parseBoolean(active));
66
        } else if(community != null && before != null) {
67
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(_community.getId(), Boolean.parseBoolean(before));
68
        } else if(position != null && active != null) {
69
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
70
        } else if(position != null && before != null) {
71
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position,  Boolean.parseBoolean(before));
72
        } else if(active != null && before != null) {
73
            pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
49 74
        } else if(community != null) {
50 75
            pageHelpContents = pageHelpContentDAO.findByCommunityOrderByPlacementAscOrderAsc(_community.getId());
51 76
        } else if(position != null) {
52 77
            pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
78
        } else if(active != null) {
79
            pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
80
        } else if(before != null) {
81
            pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
53 82
        } else {
54 83
            pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
55 84
        }
......
103 132
        return pageHelpContentDAO.findById(id);
104 133
    }
105 134

  
106
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
107
    public void deletePageHelpContent(@PathVariable(value = "id") String id) {
108
        pageHelpContentDAO.delete(id);
109
    }
110

  
111 135
    @RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
112 136
    public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
113 137
        for (String id: pageHelpContents) {
......
119 143
        return pageHelpContents;
120 144
    }
121 145

  
146
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
147
    public void deletePageHelpContent(@PathVariable(value = "id") String id) {
148
        pageHelpContentDAO.delete(id);
149
    }
150

  
122 151
    @RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
123 152
    public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
124 153
        for (String id: pageHelpContents) {
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

  
3
import eu.dnetlib.uoaadmintools.dao.DivIdDAO;
3 4
import eu.dnetlib.uoaadmintools.dao.EntityDAO;
4 5
import eu.dnetlib.uoaadmintools.dao.PageDAO;
5 6
import eu.dnetlib.uoaadmintools.entities.*;
......
25 26
    @Autowired
26 27
    private EntityDAO entityDAO;
27 28

  
29
    @Autowired
30
    private DivIdDAO divIdDAO;
31

  
32
    @Autowired
33
    private PageHelpContentController pageHelpContentController;
34

  
35
    @Autowired
36
    private DivHelpContentController divHelpContentController;
37

  
38
    @Autowired
39
    private DivIdController divIdController;
40

  
28 41
    @RequestMapping(value = "/community", method = RequestMethod.GET)
29
    public List<Community> getAllCommunities() {
30
        return communityDAO.findAll();
42
    public List<Community> getAllCommunities(@RequestParam(value="div", required = false) String div) {
43
        List<Community> communities = communityDAO.findAll();
44
        Iterator it = communities.iterator();
45
        while(it.hasNext()) {
46
            Community community = (Community)it.next();
47
            if(div != null && div.equals("true")) {
48
                List<DivId> divIds = divIdDAO.findByCommunity(community.getId());
49
                if(divIds.isEmpty()) {
50
                    it.remove();
51
                }
52
            }
53
        }
54
        return communities;
31 55
    }
32 56

  
33 57
    @RequestMapping(value = "/communityFull", method = RequestMethod.GET)
......
37 61
        for(Community community : communities) {
38 62
            CommunityResponse communityResponse = new CommunityResponse(community);
39 63

  
40
            List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null);
64
            List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
41 65
            log.debug("PAGES number="+pages.size());
42 66
            Iterator<CommunityPage> iteratorPages = pages.iterator();
43 67
            while(iteratorPages.hasNext()) {
......
70 94
        Community community = communityDAO.findByPid(pid);
71 95
        CommunityResponse communityResponse = new CommunityResponse(community);
72 96

  
73
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null);
97
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getPid(), null, null, null);
74 98
        Iterator<CommunityPage> iteratorPages = pages.iterator();
75 99
        while(iteratorPages.hasNext()) {
76 100
            CommunityPage page = iteratorPages.next();
......
132 156
        com.setPid(community.getPid());
133 157
        // = this.getCommunityByCommunityResponse(communityResponse);
134 158
        communityDAO.save(com);
135
        CommunityResponse communityResponse = this.getCommunityFull(community.getId());
159
        CommunityResponse communityResponse = this.getCommunityFull(community.getPid());
136 160

  
137 161
        return communityResponse;
138 162
    }
......
160 184

  
161 185
            communityPages.add(communityPage);
162 186
        }
187

  
163 188
        community.setEntities(entities);
164 189
        community.setPages(pages);
190

  
165 191
        Community savedCommunity = communityDAO.save(community);
166
//        communityResponse.setId(savedCommunity.getId());
167
        CommunityResponse communityResponse = this.getCommunityFull(community.getId());//new CommunityResponse();
192
        CommunityResponse communityResponse = this.getCommunityFull(savedCommunity.getPid());
168 193

  
169 194
        return communityResponse;
170 195
    }
......
205 230
    public Boolean deleteCommunities(@RequestBody List<String> communities) throws Exception {
206 231
        for (String id: communities) {
207 232
            communityDAO.delete(id);
233

  
234
            // delete divIds related to this page from all communities
235
            List<DivId> divIds = divIdController.getDivIds(id, null);
236
            for(DivId divId : divIds) {
237
                divIdController.deleteDivId(divId.getId());
238
            }
239

  
240
            // delete div contents related to this page from all communities
241
            List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(null, id, null);
242
            for(DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
243
                divHelpContentController.deleteDivHelpContent(divHelpContentResponse.getId());
244
            }
245

  
246
            // delete contents related to this community
247
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(id, null, null, null, null);
248
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
249
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
250
            }
208 251
        }
209 252

  
210 253
        return true;
211 254
    }
212 255

  
213
    @RequestMapping(value = "/community", method = RequestMethod.DELETE)
214
    public void deleteAllCommunities() {
215
        communityDAO.deleteAll();
216
    }
256
//    @RequestMapping(value = "/community", method = RequestMethod.DELETE)
257
//    public void deleteAllCommunities() {
258
//        communityDAO.deleteAll();
259
//    }
217 260

  
218 261
    @RequestMapping(value = "/community", method = RequestMethod.POST)
219 262
    public Community insertOrUpdateCommunity(@RequestBody Community community) {
......
232 275
    }
233 276

  
234 277
    @RequestMapping(value = "/community/{pid}/pages", method = RequestMethod.GET)
235
    public List<CommunityPage> getPagesForCommunityByType(@PathVariable(value = "pid") String pid, @RequestParam(value="page_type", required=false) String page_type, @RequestParam(value="page_route", required=false) String page_route) {
278
    public List<CommunityPage> getPagesForCommunityByType(@PathVariable(value = "pid") String pid,
279
                                                          @RequestParam(value="page_type", required=false) String page_type,
280
                                                          @RequestParam(value="page_route", required=false) String page_route,
281
                                                          @RequestParam(value="div", required = false) String div) {
236 282
        List<CommunityPage> return_pages = new ArrayList<CommunityPage>();
237 283
        Map<String, Boolean> pages = communityDAO.findByPid(pid).getPages();
238 284

  
239 285
        if(pages != null) {
240 286
            for (Map.Entry<String, Boolean> page : pages.entrySet()) {
287
                if(div != null && div.equals("true")) {
288
                    Community community = communityDAO.findByPid(pid);
289
                    List<DivId> divIds = divIdDAO.findByCommunityAndPage(community.getId(), page.getKey());
290
                    if(divIds.isEmpty()) {
291
                        continue;
292
                    }
293
                }
294

  
241 295
                Page p = pageDAO.findById(page.getKey());
242 296
                if ((page_type == null && page_route == null) || (page_route == null && p.getType().equals(page_type))
243 297
                        || p.getRoute().equals(page_route)) {

Also available in: Unified diff