Project

General

Profile

« Previous | Next » 

Revision 55027

[Trunk|AdminTools]: 1. Add Layout Collection 2. Create getLayout, updateLayout, resetLayout in CommunityController 3. Add at admintooles.properties default color=color of connect

View differences:

modules/uoa-admin-tools/update_db.js
108 108
function createShareInZenodoPage() {
109 109
	db.page.save({"name" : "Share in Zenodo", "route" : "/participate/share-zenodo", "type" : "share", "connect":true,"openaire":false,"entities" : []});
110 110
    shareInZenodo = db.page.find( { route: "/participate/share-zenodo" }).map( function(page) { return page._id.str; } ).toString();
111

  
112 111
	communities = db.community.find().map( function(community) { return community; } );
113 112

  
114 113
	for (var i = 0; i < communities.length; i++) {
......
122 121
    }
123 122
}
124 123

  
124
function addCommunityLayout() {
125
    db.createCollection("layout");
126
    communities = db.community.find().map( function(community) { return community; } );
127
    for (var i = 0; i < communities.length; i++) {
128
        var layoutId = db.layout.insertOne({"color": "#EBB13E"}).insertedId.str;
129
        community_pid = communities[i].pid;
130
        db.community.update({ "pid" : community_pid }, {$set: {"layout": layoutId}});
131
        print("Creating layout for " + community_pid);
132
    }
133
}
134

  
125 135
 use openaire_admin;
126 136

  
127 137
//updatePages();
......
141 151

  
142 152
//createOtherResearchProducts();
143 153

  
144
addDefaultHtmlToHtmlPagesForCommunity("clarin");
145
createNotificationsCollection();
146
addDivHelpContentsForCommunity("clarin");
147
addORPInStatistics();
148
createShareInZenodoPage();
154
//addDefaultHtmlToHtmlPagesForCommunity("clarin");
155
//createNotificationsCollection();
156
//addDivHelpContentsForCommunity("clarin");
157
//addORPInStatistics();
158
//createShareInZenodoPage();
159
addCommunityLayout();
modules/uoa-admin-tools/init_db.js
8 8
function createCollections(){
9 9
print("\n\n Create Collections \n\n")
10 10
	db.createCollection("community")
11
	db.createCollection("layout")
11 12
	db.createCollection("divHelpContent")
12 13
	db.createCollection("divId")
13 14
	db.createCollection("entity")
......
220 221
	community_entities[projectId] = true;
221 222
	community_entities[organizationId] = true;
222 223
	community_entities[datasourceId] = true;
224
	var layoutId = db.layout.insertOne({"color": "#EBB13E"}).insertedId.str;
225
	print("Layout:" + layoutId);
226
 	db.community.save({	"name" : name,
227
		"pid" : communityPid, "pages" : community_pages, "entities" : community_entities, "layout": layoutId})
223 228

  
224
 	db.community.save({	"name" : name, "pid" : communityPid, "pages" : community_pages, "entities" : community_entities})
225

  
226 229
	openaireCommunity = db.community.find( { pid: communityPid }).map( function(community) { return community._id.str; } ).toString()
227 230

  
228 231
    var numbers_map = {};
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/LayoutDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Layout;
4

  
5
import java.util.List;
6

  
7
public interface LayoutDAO {
8
    List<Layout> findAll();
9

  
10
    Layout findById(String Id);
11

  
12
    Layout findByColor(String color);
13

  
14
    Layout save(Layout entity);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBLayoutDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Layout;
4
import org.springframework.data.mongodb.repository.MongoRepository;
5

  
6
import java.util.List;
7

  
8
public interface MongoDBLayoutDAO extends LayoutDAO, MongoRepository<Layout, String> {
9

  
10
    List<Layout> findAll();
11

  
12
    Layout findById(String Id);
13

  
14
    Layout findByColor(String color);
15

  
16
    Layout save(Layout entity);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/CommunityResponse.java
5 5
import org.springframework.data.annotation.Id;
6 6

  
7 7
import java.util.List;
8
import java.util.Map;
9 8

  
10 9
public class CommunityResponse {
11 10

  
......
17 16
    private String name;
18 17
    private List<CommunityPage> pages;
19 18
    private List<CommunityEntity> entities;
19
    private Layout layout;
20 20

  
21 21
    public CommunityResponse() {}
22 22

  
......
59 59
    public void setEntities(List<CommunityEntity> entities) {
60 60
        this.entities = entities;
61 61
    }
62

  
63
    public Layout getLayout() {
64
        return layout;
65
    }
66

  
67
    public void setLayout(Layout layout) {
68
        this.layout = layout;
69
    }
62 70
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Layout.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.springframework.data.annotation.Id;
5

  
6
public class Layout {
7

  
8
    @Id
9
    @JsonProperty("_id")
10
    private String id;
11
    private String color;
12

  
13
    public Layout() { }
14

  
15
    public String getId() {
16
        return id;
17
    }
18

  
19
    public void setId(String id) {
20
        this.id = id;
21
    }
22

  
23
    public String getColor() {
24
        return color;
25
    }
26

  
27
    public void setColor(String color) {
28
        this.color = color;
29
    }
30
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Community.java
17 17
    private String name;
18 18
    private Map<String, Boolean> pages;
19 19
    private Map<String, Boolean> entities;
20
    private String layout;
20 21

  
21 22
    public Community() {
22 23
    }
......
54 55
    public void setEntities(Map<String, Boolean> entities) {
55 56
        this.entities = entities;
56 57
    }
58

  
59
    public String getLayout() {
60
        return layout;
61
    }
62

  
63
    public void setLayout(String layout) {
64
        this.layout = layout;
65
    }
57 66
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java
5 5

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

  
11
import javax.swing.text.html.HTML;
12 12
import java.util.*;
13 13

  
14 14
@RestController
......
20 20
    private CommunityDAO communityDAO;
21 21

  
22 22
    @Autowired
23
    private LayoutDAO layoutDAO;
24

  
25
    @Autowired
23 26
    private PageDAO pageDAO;
24 27

  
25 28
    @Autowired
......
45 48
    @Autowired
46 49
    private CommunitySubscribersDAO  communitySubscribersDAO;
47 50

  
51
    @Value( "${admintool.defaultColor}" )
52
    private String defaultColor;
53

  
48 54
    @RequestMapping(value = "/community", method = RequestMethod.GET)
49 55
    public List<Community> getAllCommunities() {
50 56
        List<Community> communities = communityDAO.findAll();
......
81 87
                }
82 88
            }
83 89
            communityResponse.setEntities(entities);
84

  
90
            Layout layout = layoutDAO.findById(community.getLayout());
91
            communityResponse.setLayout(layout);
85 92
            communitiesResponse.add(communityResponse);
86 93
        }
87 94
        return communitiesResponse;
......
111 118
            }
112 119
        }
113 120
        communityResponse.setEntities(entities);
121
        Layout layout = layoutDAO.findById(community.getLayout());
122
        communityResponse.setLayout(layout);
114 123
//        communityResponse.setPages(this.getPagesForCommunityByType(community.getId(), null));
115 124
//        communityResponse.setEntities(this.getEntitiesForCommunity(community.getId()));
116 125

  
......
187 196

  
188 197
        community.setEntities(entities);
189 198
        community.setPages(pages);
199
        Layout layout = new Layout();
200
        layout.setColor(defaultColor);
201
        layout = layoutDAO.save(layout);
202
        community.setLayout(layout.getId());
190 203
        Statistics statistics =  new Statistics(community.getPid());
191 204
        statisticsDAO.save(statistics);
192 205
        CommunitySubscribers communitySubscribers =  new CommunitySubscribers(community.getPid());
......
281 294
            }
282 295
        }
283 296
        community.setPages(pages);
297
        Layout layout = communityResponse.getLayout();
298
        community.setLayout(layout.getId());
284 299

  
285 300
        return community;
286 301
    }
......
288 303
    @RequestMapping(value = "/community/delete", method = RequestMethod.POST)
289 304
    public Boolean deleteCommunities(@RequestBody List<String> communities) throws Exception {
290 305
        for (String id: communities) {
291
            String pid = communityDAO.findById(id).getPid();
306
            Community community = communityDAO.findById(id);
307
            String pid = community.getPid();
292 308

  
293 309
            // delete div contents related to this community
294 310
            List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(pid, null, null, null);
......
317 333
                communitySubscribersDAO.delete(communitySubscribers.getId());
318 334
            }
319 335

  
336
            Layout layout = layoutDAO.findById(community.getLayout());
337
            if(layout != null) {
338
                layoutDAO.delete(layout.getId());
339
            }
340

  
320 341
            communityDAO.delete(id);
321 342
        }
322 343

  
......
464 485
        }
465 486
        return return_entities;
466 487
    }
488

  
489
    @RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.GET)
490
    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
491
        Community community = communityDAO.findByPid(pid);
492
        return layoutDAO.findById(community.getLayout());
493
    }
494

  
495
    @RequestMapping(value = "/community/{pid}/updateLayout", method = RequestMethod.POST)
496
    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
497
        Community community = communityDAO.findByPid(pid);
498
        if(community.getLayout() != null) {
499
            layout.setId(community.getLayout());
500
            layout = layoutDAO.save(layout);
501
        } else {
502
            layout = layoutDAO.save(layout);
503
            community.setLayout(layout.getId());
504
            communityDAO.save(community);
505
        }
506
        return layout;
507
    }
508

  
509
    @RequestMapping(value = "/community/{pid}/resetLayout", method = RequestMethod.POST)
510
    public Layout resetLayoutForCommunity(@PathVariable(value = "pid") String pid) {
511
        Layout layout;
512
        Community community = communityDAO.findByPid(pid);
513
        if(community.getLayout() != null) {
514
            layout = layoutDAO.findById(community.getLayout());
515
            layout.setColor(defaultColor);
516
            layout = layoutDAO.save(layout);
517
        } else {
518
            layout = new Layout();
519
            layout.setColor(defaultColor);
520
            layout = layoutDAO.save(layout);
521
            community.setLayout(layout.getId());
522
            communityDAO.save(community);
523
        }
524
        return layout;
525
    }
467 526
}
468 527

  
modules/uoa-admin-tools/src/main/resources/admintools.properties
7 7
admintool.from = openaire.test@gmail.com
8 8
admintool.username = openaire.test@gmail.com
9 9
admintool.password = ...
10
admintool.defaultColor = #EBB13E
10 11

  
11 12
#beta
12 13
#admintool.userInfoUrl =  https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
......
17 18
#admintool.username = no-reply@openaire.eu
18 19
#admintool.from = no-reply@beta.openaire.eu
19 20
#admintool.password = ...
21
#admintool.defaultColor = #EBB13E
20 22

  
21 23

  
22 24
#production
23 25
#admintool.userInfoUrl =  https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
24 26
#admintool.originServer = .openaire.eu
27
#admintool.defaultColor = #EBB13E
25 28

  

Also available in: Unified diff