Project

General

Profile

« Previous | Next » 

Revision 50222

Community and Entity class created | All Classes and APIs configured according to OpenAIRE (Community's APIs may change)

View differences:

modules/uoa-admin-tools/src/test/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplicationTests.java
1 1
package eu.dnetlib.uoaadmintools;
2 2

  
3
import eu.dnetlib.uoaadmintools.dao.*;
4
import eu.dnetlib.uoaadmintools.entities.Community;
5
import eu.dnetlib.uoaadmintools.entities.Entity;
6
import eu.dnetlib.uoaadmintools.entities.Page;
7
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
3 8
import org.junit.Test;
4 9
import org.junit.runner.RunWith;
10
import org.springframework.beans.factory.annotation.Autowired;
5 11
import org.springframework.boot.test.context.SpringBootTest;
6 12
import org.springframework.test.context.junit4.SpringRunner;
7 13

  
14
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18

  
19
import static javax.swing.text.html.HTML.Tag.P;
20

  
8 21
@RunWith(SpringRunner.class)
9 22
@SpringBootTest
10 23
public class UoaAdminToolsApplicationTests {
11 24

  
25
	@Autowired
26
	private CommunityDAO communityDAO;
27

  
28
	@Autowired
29
	private EntityDAO entityDAO;
30

  
31
	@Autowired
32
	private PageDAO pageDAO;
33

  
34
	@Autowired
35
	private PageHelpContentDAO pageHelpContentDAO;
36

  
37
/*
12 38
	@Test
39
	public void deleteAllEntities() {
40
		List<Entity> entities = entityDAO.findAll();
41
		for(Entity entity : entities) {
42
			entityDAO.delete(entity.getId());
43
		}
44
	}
45

  
46
	@Test
47
	public void deleteAllCommunities() {
48
		List<Community> communities = communityDAO.findAll();
49
		for(Community community : communities) {
50
			communityDAO.delete(community.getId());
51
		}
52
	}
53

  
54
	@Test
55
	public void deleteAllPages() {
56
		List<Page> pages = pageDAO.findAll();
57
		for(Page page : pages) {
58
			pageDAO.delete(page.getId());
59
		}
60
	}
61

  
62
	@Test
63
	public void deleteAllPageContents() {
64
		List<PageHelpContent> pageHelpContents = pageHelpContentDAO.findAll();
65
		for(PageHelpContent pageHelpContent : pageHelpContents) {
66
			pageHelpContentDAO.delete(pageHelpContent.getId());
67
		}
68
	}
69

  
70
	@Test
71
	public void createEntity() {
72
		Entity entity = new Entity();
73
		entity.setName("Publication");
74
		entityDAO.save(entity);
75
	}
76

  
77
	@Test
78
	public void createPage() {
79
		List<String> entities = new ArrayList<String>();
80
		//entities.add("5a300ee4c97a7d2c000b9e9d");	// Publication
81
		entities.add("5a319f8bc97a7d241ebddf75");	// Research Data
82

  
83

  
84
		Page page = new Page();
85
		page.setName("Search Research Data");
86
		page.setRoute("/search/find/datasets");
87
		page.setType("search");
88
		page.setEntities(entities);
89
		pageDAO.save(page);
90
	}
91

  
92
	@Test
93
	public void createCommunity() {
94
		Map<String, Boolean> entities = new HashMap<String, Boolean>();
95
		//entities.put("5a300ee4c97a7d2c000b9e9d", true);	// Publication
96
		entities.put("5a319f8bc97a7d241ebddf75", false);	// Research Data
97
		//entities.put("5a3064f9c97a7d4964408ee0", false);	// Software
98
		//entities.put("5a30652ec97a7d4964408ee1", false);	// Organization
99
		//entities.put("5a306539c97a7d4964408ee2", false);	// Project
100
		//entities.put("5a30654dc97a7d4964408ee3", false);	// Content Provider
101

  
102
		Map<String, Boolean> pages = new HashMap<String, Boolean>();
103
		//pages.put("5a30191ac97a7d3a7fa77362", true);		// Search Publications
104
		pages.put("5a31a4cac97a7d28468f0f5c", false);		// Search Research Data
105
		//pages.put("5a30657ac97a7d4964408ee4", false);		// Search Software
106
		//pages.put("5a30eeffc97a7d74234434ad", false);		// Search Organizations
107
		//pages.put("5a30efd9c97a7d7609b77ca5", false);		// Search Projects
108
		//pages.put("5a30f08bc97a7d7609b77ca7", false);		// Search Content Providers
109

  
110
		//pages.put("5a300f19c97a7d2c6e084b9f", false);		// Test
111

  
112
		Community community = new Community();
113
		community.setName("Test Community");
114
		community.setEntities(entities);
115
		community.setPages(pages);
116
		communityDAO.save(community);
117
	}
118
*/
119

  
120
	@Test
13 121
	public void contextLoads() {
14 122
	}
15 123

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/PageDAO.java
9 9

  
10 10
    Page findById(String Id);
11 11

  
12
    Page findByName(String name);
13

  
12 14
    Page save(Page page);
13 15

  
14 16
    void deleteAll();
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/EntityDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

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

  
5
import java.util.List;
6

  
7
public interface EntityDAO {
8
    List<Entity> findAll();
9

  
10
    Entity findById(String Id);
11

  
12
    Entity findByName(String name);
13

  
14
    Entity save(Entity entity);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
20

  
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> findByCommunity(String CommunityId);
11

  
10 12
    PageHelpContent findById(String Id);
11 13

  
12 14
    PageHelpContent save(PageHelpContent pageHelpContent);
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBPageDAO.java
11 11

  
12 12
    Page findById(String Id);
13 13

  
14
    Page findByName(String name);
15

  
14 16
    Page save(Page page);
15 17

  
16 18
    void deleteAll();
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBEntityDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

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

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBEntityDAO extends EntityDAO, MongoRepository<Entity, String> {
10
    List<Entity> findAll();
11

  
12
    Entity findById(String Id);
13

  
14
    Entity findByName(String name);
15

  
16
    Entity save(Entity entity);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
22

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/CommunityDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

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

  
5
import java.util.List;
6

  
7
public interface CommunityDAO {
8
    List<Community> findAll();
9

  
10
    Community findById(String Id);
11

  
12
    Community findByName(String Name);
13

  
14
    Community save(Community community);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
20

  
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> findByCommunity(String CommunityId);
13

  
12 14
    PageHelpContent findById(String Id);
13 15

  
14 16
    PageHelpContent save(PageHelpContent pageHelpContent);
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBCommunityDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

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

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBCommunityDAO extends CommunityDAO, MongoRepository<Community, String> {
10
    List<Community> findAll();
11

  
12
    Community findById(String Id);
13

  
14
    Community findByName(String Name);
15

  
16
    Community save(Community community);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContentResponse.java
11 11
    private String id;
12 12

  
13 13
    private Page page;
14
    private Community community;
14 15
    private String placement;
15 16
    private int order;
16 17
    private String content;
17 18
    private boolean isActive = true;
19
    private boolean before = false;
18 20

  
19 21
    public PageHelpContentResponse() {
20 22
    }
......
43 45
        this.page = page;
44 46
    }
45 47

  
48
    public Community getCommunity() {
49
        return community;
50
    }
51

  
52
    public void setCommunity(Community community) {
53
        this.community = community;
54
    }
55

  
46 56
    public String getPlacement() {
47 57
        return placement;
48 58
    }
......
74 84
    public void setIsActive(boolean isActive) {
75 85
        this.isActive = isActive;
76 86
    }
87

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

  
90
    public void setBefore(boolean before) { this.before = before; }
77 91
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContent.java
11 11
    private String id;
12 12

  
13 13
    private String page;
14
    private String community;
14 15
    private String placement;
15 16
    private int order;
16 17
    private String content;
17 18
    private boolean isActive = true;
19
    private boolean before = false;
18 20

  
19 21
    public PageHelpContent() {
20 22
    }
......
35 37
        this.page = page;
36 38
    }
37 39

  
40
    public String getCommunity() {
41
        return community;
42
    }
43

  
44
    public void setCommunity(String community) {
45
        this.community = community;
46
    }
47

  
38 48
    public String getPlacement() {
39 49
        return placement;
40 50
    }
......
66 76
    public void setIsActive(boolean isActive) {
67 77
        this.isActive = isActive;
68 78
    }
79

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

  
82
    public void setBefore(boolean before) { this.before = before; }
69 83
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/CommunityPage.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

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

  
10
public class CommunityPage {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String route;
17
    private String name;
18
    private String type;
19
    private List<Entity> entities;
20
    private Boolean isEnabled;
21

  
22
    public CommunityPage() {}
23

  
24
    public CommunityPage(Page page) {
25
        this.setId(page.getId());
26
        this.setRoute(page.getRoute());
27
        this.setName(page.getName());
28
        this.setType(page.getType());
29
    }
30

  
31
    public String getId() {
32
        return id;
33
    }
34

  
35
    public void setId(String id) {
36
        this.id = id;
37
    }
38

  
39
    public String getRoute() {
40
        return route;
41
    }
42

  
43
    public void setRoute(String route) {
44
        this.route = route;
45
    }
46

  
47
    public String getName() {
48
        return name;
49
    }
50

  
51
    public void setName(String name) {
52
        this.name = name;
53
    }
54

  
55
    public String getType() {
56
        return type;
57
    }
58

  
59
    public void setType(String type) {
60
        this.type = type;
61
    }
62

  
63
    public List<Entity> getEntities() { return entities; }
64

  
65
    public void setEntities(List<Entity> entities) { this.entities = entities; }
66

  
67
    public Boolean getIsEnabled() { return isEnabled; }
68

  
69
    public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; }
70
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/CommunityEntity.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

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

  
10
public class CommunityEntity {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String name;
17
    private Boolean isEnabled;
18

  
19
    public CommunityEntity() {}
20

  
21
    public CommunityEntity(Entity entity) {
22
        this.setId(entity.getId());
23
        this.setName(entity.getName());
24
        this.setIsEnabled(true);
25
    }
26

  
27
    public String getId() {
28
        return id;
29
    }
30

  
31
    public void setId(String id) {
32
        this.id = id;
33
    }
34

  
35
    public String getName() {
36
        return name;
37
    }
38

  
39
    public void setName(String name) {
40
        this.name = name;
41
    }
42

  
43
    public Boolean getIsEnabled() { return isEnabled; }
44

  
45
    public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; }
46
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/CommunityResponse.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

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

  
10
public class CommunityResponse {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String name;
17
    private List<CommunityPage> pages;
18
    private List<CommunityEntity> entities;
19

  
20
    public CommunityResponse() {}
21

  
22
    public CommunityResponse(Community community) {
23
        this.setId(community.getId());
24
        this.setName(community.getName());
25
    }
26

  
27
    public String getId() {
28
        return id;
29
    }
30

  
31
    public void setId(String id) {
32
        this.id = id;
33
    }
34

  
35
    public String getName() {
36
        return name;
37
    }
38

  
39
    public void setName(String name) {
40
        this.name = name;
41
    }
42

  
43
    public List<CommunityPage> getPages() { return pages; }
44

  
45
    public void setPages(List<CommunityPage> pages) { this.pages = pages; }
46

  
47
    public List<CommunityEntity> getEntities() { return entities; }
48

  
49
    public void setEntities(List<CommunityEntity> entities) {
50
        this.entities = entities;
51
    }
52
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Community.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

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

  
10
public class Community {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String name;
17
    private Map<String, Boolean> pages;
18
    private Map<String, Boolean> entities;
19

  
20
    public Community() {
21
    }
22

  
23
    public String getId() {
24
        return id;
25
    }
26

  
27
    public void setId(String id) {
28
        this.id = id;
29
    }
30

  
31
    public String getName() {
32
        return name;
33
    }
34

  
35
    public void setName(String name) {
36
        this.name = name;
37
    }
38

  
39
    public Map<String, Boolean> getPages() { return pages; }
40

  
41
    public void setPages(Map<String, Boolean> pages) { this.pages = pages; }
42

  
43
    public Map<String, Boolean> getEntities() { return entities; }
44

  
45
    public void setEntities(Map<String, Boolean> entities) {
46
        this.entities = entities;
47
    }
48
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Page.java
4 4

  
5 5
import org.springframework.data.annotation.Id;
6 6

  
7
import java.util.List;
8

  
7 9
public class Page {
8 10

  
9 11
    @Id
......
12 14

  
13 15
    private String route;
14 16
    private String name;
17
    private String type;
18
    private List<String> entities;
15 19

  
16 20
    public Page() {
17 21
    }
......
39 43
    public void setName(String name) {
40 44
        this.name = name;
41 45
    }
46

  
47
    public String getType() {
48
        return type;
49
    }
50

  
51
    public void setType(String type) {
52
        this.type = type;
53
    }
54

  
55
    public List<String> getEntities() { return entities; }
56

  
57
    public void setEntities(List<String> entities) { this.entities = entities; }
42 58
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Entity.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
public class Entity {
8

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

  
13
    private String name;
14

  
15
    public Entity() {
16
    }
17

  
18
    public String getId() {
19
        return id;
20
    }
21

  
22
    public void setId(String id) {
23
        this.id = id;
24
    }
25

  
26
    public String getName() {
27
        return name;
28
    }
29

  
30
    public void setName(String name) {
31
        this.name = name;
32
    }
33
}
34

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

  
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;
3 7
import eu.dnetlib.uoaadmintools.entities.Page;
4 8
import eu.dnetlib.uoaadmintools.dao.PageDAO;
5 9

  
6 10
import org.apache.log4j.Logger;
7
import org.springframework.web.bind.annotation.CrossOrigin;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.RequestMethod;
10
import org.springframework.web.bind.annotation.RequestBody;
11
import org.springframework.web.bind.annotation.PathVariable;
11
import org.springframework.web.bind.annotation.*;
12 12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.web.bind.annotation.RestController;
14 13

  
14
import java.util.ArrayList;
15 15
import java.util.List;
16
import java.util.Map;
16 17

  
17 18
@RestController
18 19
@CrossOrigin(origins = "*")
......
22 23
    @Autowired
23 24
    private PageDAO pageDAO;
24 25

  
26
    @Autowired
27
    private CommunityDAO communityDAO;
28

  
25 29
    @RequestMapping(value = "/page", method = RequestMethod.GET)
26 30
    public List<Page> getAllPages() {
27 31
        return pageDAO.findAll();
......
32 36
        pageDAO.deleteAll();
33 37
    }
34 38

  
35
    @RequestMapping(value = "/page", method = RequestMethod.POST)
36
    public Page insertOrUpdatePage(@RequestBody Page page) {
37
        return pageDAO.save(page);
39
    @RequestMapping(value = "/page/update", method = RequestMethod.POST)
40
    public CommunityPage updatePage(@RequestBody CommunityPage communityPage) {
41
        Page page = this.getPageByCommunityPage(communityPage);
42
        pageDAO.save(page);
43
        return communityPage;
38 44
    }
39 45

  
46
    @RequestMapping(value = "/page/save", method = RequestMethod.POST)
47
    public CommunityPage insertPage(@RequestBody CommunityPage communityPage) {
48
        Page page = this.getPageByCommunityPage(communityPage);
49
        Page savedPage = pageDAO.save(page);
50
        communityPage.setId(savedPage.getId());
51

  
52
        // add page in communities
53
        List<Community> communities = communityDAO.findAll();
54
        for( Community community : communities ) {
55
            Map<String, Boolean> pages = community.getPages();
56
            pages.put(page.getId(), false);
57
            community.setPages(pages);
58
            communityDAO.save(community);
59
        }
60

  
61
        return communityPage;
62
    }
63

  
64
    private Page getPageByCommunityPage(CommunityPage communityPage) {
65
        Page page = new Page();
66
        page.setId(communityPage.getId());
67
        page.setRoute(communityPage.getRoute());
68
        page.setName(communityPage.getName());
69
        page.setType(communityPage.getType());
70

  
71
        List<Entity> fullEntities = communityPage.getEntities();
72
        List<String> entities = new ArrayList<String>();
73
        for(Entity entity : fullEntities) {
74
            entities.add(entity.getId());
75
        }
76
        page.setEntities(entities);
77

  
78
        return page;
79
    }
80

  
81
    @RequestMapping(value = "/page/delete", method = RequestMethod.POST)
82
    public Boolean deletePages(@RequestBody List<String> pages) throws Exception {
83
        for (String id: pages) {
84
            pageDAO.delete(id);
85

  
86
            // delete pages from communities
87
            List<Community> communities = communityDAO.findAll();
88
            for( Community community : communities ) {
89
                Map<String, Boolean> communityPages = community.getPages();
90
                communityPages.remove(id);
91
                community.setPages(communityPages);
92
                communityDAO.save(community);
93
            }
94
        }
95

  
96
        return true;
97
    }
98

  
40 99
    @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
41 100
    public Page getPage(@PathVariable(value = "id") String id) {
42 101
        return pageDAO.findById(id);
......
47 106
        pageDAO.delete(id);
48 107
    }
49 108

  
109
    @RequestMapping(value = "/page/{id}/entity", method = RequestMethod.GET)
110
    public List<String> getPageEntities(@PathVariable(value = "id") String id) {
111
        return pageDAO.findById(id).getEntities();
112
    }
50 113

  
114
    @RequestMapping(value = "page/{id}/entity/toggle", method = RequestMethod.POST)
115
    public Page togglePageEntity(@PathVariable(value = "id") String id, @RequestParam String entityId, @RequestParam String status) throws Exception {
116
        log.debug("Toggle entity : "+entityId +" of page: "+id+" to "+status);
117
        Page page = pageDAO.findById(id);
118
        List<String> entities = page.getEntities();
119
        if(Boolean.parseBoolean(status) && !entities.contains(entityId)) {
120
            entities.add(entityId);
121
        } else if (!Boolean.parseBoolean(status)) {
122
            entities.remove(entityId);
123
        }
124
        page.setEntities(entities);
125
        return pageDAO.save(page);
126
    }
51 127
}
52 128

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/EntityController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
4
import eu.dnetlib.uoaadmintools.dao.PageDAO;
5
import eu.dnetlib.uoaadmintools.entities.Community;
6
import eu.dnetlib.uoaadmintools.entities.CommunityEntity;
7
import eu.dnetlib.uoaadmintools.entities.Entity;
8
import eu.dnetlib.uoaadmintools.dao.EntityDAO;
9

  
10
import eu.dnetlib.uoaadmintools.entities.Page;
11
import org.apache.log4j.Logger;
12
import org.springframework.web.bind.annotation.CrossOrigin;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestBody;
16
import org.springframework.web.bind.annotation.PathVariable;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.web.bind.annotation.RestController;
19

  
20
import java.util.List;
21
import java.util.Map;
22

  
23
@RestController
24
@CrossOrigin(origins = "*")
25
public class EntityController {
26
    private final Logger log = Logger.getLogger(this.getClass());
27

  
28
    @Autowired
29
    private EntityDAO entityDAO;
30

  
31
    @Autowired
32
    private PageDAO pageDAO;
33

  
34
    @Autowired
35
    private CommunityDAO communityDAO;
36

  
37
    @RequestMapping(value = "/entity", method = RequestMethod.GET)
38
    public List<Entity> getAllEntities() {
39
        return entityDAO.findAll();
40
    }
41

  
42
    @RequestMapping(value = "/entity", method = RequestMethod.DELETE)
43
    public void deleteAllEntities() {
44
        entityDAO.deleteAll();
45
    }
46

  
47
    @RequestMapping(value = "/entity", method = RequestMethod.POST)
48
    public Entity insertOrUpdateEntity(@RequestBody Entity entity) {
49
        return entityDAO.save(entity);
50
    }
51

  
52
    @RequestMapping(value = "/entity/{id}", method = RequestMethod.GET)
53
    public Entity getEntity(@PathVariable(value = "id") String id) {
54
        return entityDAO.findById(id);
55
    }
56

  
57
    @RequestMapping(value = "/entity/{id}", method = RequestMethod.DELETE)
58
    public void deleteEntity(@PathVariable(value = "id") String id) {
59
        entityDAO.delete(id);
60
    }
61

  
62
    @RequestMapping(value = "/entity/update", method = RequestMethod.POST)
63
    public CommunityEntity updateEntity(@RequestBody CommunityEntity communityEntity) {
64
        Entity entity = this.getEntityByCommunityEntity(communityEntity);
65
        entityDAO.save(entity);
66
        return communityEntity;
67
    }
68

  
69
    @RequestMapping(value = "/entity/save", method = RequestMethod.POST)
70
    public CommunityEntity insertEntity(@RequestBody CommunityEntity communityEntity) {
71
        Entity entity = this.getEntityByCommunityEntity(communityEntity);
72
        Entity savedEntity = entityDAO.save(entity);
73
        communityEntity.setId(savedEntity.getId());
74

  
75
        // add entity in communities
76
        List<Community> communities = communityDAO.findAll();
77
        for( Community community : communities ) {
78
            Map<String, Boolean> entities = community.getEntities();
79
            entities.put(entity.getId(), false);
80
            community.setEntities(entities);
81
            communityDAO.save(community);
82
        }
83

  
84
        return communityEntity;
85
    }
86

  
87
    private Entity getEntityByCommunityEntity(CommunityEntity communityPage) {
88
        Entity entity = new Entity();
89
        entity.setId(communityPage.getId());
90
        entity.setName(communityPage.getName());
91

  
92
        return entity;
93
    }
94

  
95
    @RequestMapping(value = "/entity/delete", method = RequestMethod.POST)
96
    public Boolean deleteEntities(@RequestBody List<String> entities) throws Exception {
97
        for (String id: entities) {
98
            entityDAO.delete(id);
99

  
100
            // delete entities from communities
101
            List<Community> communities = communityDAO.findAll();
102
            for( Community community : communities ) {
103
                Map<String, Boolean> communityEntities = community.getEntities();
104
                communityEntities.remove(id);
105
                community.setEntities(communityEntities);
106
                communityDAO.save(community);
107
            }
108

  
109
            // delete entities from pages
110
            List<Page> pages = pageDAO.findAll();
111
            for( Page page : pages ) {
112
                List<String> pageEntities = page.getEntities();
113
                int index = 0;
114
                for(String pageEntity : pageEntities) {
115
                    if(pageEntity == id) {
116
                        pageEntities.remove(index);
117
                        break;
118
                    }
119
                    index++;
120
                }
121
                page.setEntities(pageEntities);
122
                pageDAO.save(page);
123
            }
124
        }
125

  
126
        return true;
127
    }
128
}
129

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageHelpContentController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

  
3
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
3 4
import eu.dnetlib.uoaadmintools.dao.PageDAO;
4 5
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
5 6
import eu.dnetlib.uoaadmintools.dao.PageHelpContentDAO;
......
29 30
    @Autowired
30 31
    private PageDAO pageDAO;
31 32

  
33
    @Autowired
34
    private CommunityDAO communityDAO;
35

  
32 36
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
33 37
    public List<PageHelpContentResponse> getAllPageHelpContents() {
34 38
        List<PageHelpContent> pageHelpContents =  pageHelpContentDAO.findAll();
......
36 40
        for (PageHelpContent pageHelpContent : pageHelpContents) {
37 41
           PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
38 42
           pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
39
           pageHelpContentResponses.add(pageHelpContentResponse);
43
            pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
44
            pageHelpContentResponses.add(pageHelpContentResponse);
40 45
        }
41 46
        return pageHelpContentResponses;
42 47
    }
43 48

  
49
    @RequestMapping(value = "/pagehelpcontent/community/{id}", method = RequestMethod.GET)
50
    public List<PageHelpContentResponse> getCommunityPageHelpContents(@PathVariable(value = "id") String communityId) {
51
        List<PageHelpContent> pageHelpContents =  pageHelpContentDAO.findByCommunity(communityId);
52
        List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
53
        for (PageHelpContent pageHelpContent : pageHelpContents) {
54
            PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
55
            pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
56
            pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
57
            pageHelpContentResponses.add(pageHelpContentResponse);
58
        }
59
        return pageHelpContentResponses;
60
    }
61

  
44 62
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
45 63
    public void deleteAllPageHelpContents() {
46 64
        pageHelpContentDAO.deleteAll();
......
62 80
    }
63 81

  
64 82
    @RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
65
    public void togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
83
    public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
66 84
        for (String id: pageHelpContents) {
85
            log.debug("Id of pageHelpContent: "+id);
67 86
            PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
68 87
            pageHelpContent.setIsActive(Boolean.parseBoolean(status));
69 88
            pageHelpContentDAO.save(pageHelpContent);
70 89
        }
90
        return pageHelpContents;
71 91
    }
72 92

  
93
    @RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
94
    public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
95
        for (String id: pageHelpContents) {
96
            pageHelpContentDAO.delete(id);
97
        }
98
        return true;
99
    }
73 100

  
101

  
74 102
}
75 103

  
76 104

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.dao.EntityDAO;
4
import eu.dnetlib.uoaadmintools.dao.PageDAO;
5
import eu.dnetlib.uoaadmintools.entities.*;
6
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
7

  
8
import org.apache.log4j.Logger;
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 PageDAO pageDAO;
24

  
25
    @Autowired
26
    private EntityDAO entityDAO;
27

  
28
    @RequestMapping(value = "/community", method = RequestMethod.GET)
29
    public List<Community> getAllCommunities() {
30
        return communityDAO.findAll();
31
    }
32

  
33
    @RequestMapping(value = "/communityFull", method = RequestMethod.GET)
34
    public List<CommunityResponse> getAllCommunitiesFull() {
35
        List<Community> communities = communityDAO.findAll();
36
        List<CommunityResponse> communitiesResponse = new ArrayList<>();
37
        for(Community community : communities) {
38
            CommunityResponse communityResponse = new CommunityResponse(community);
39

  
40
            List<CommunityPage> pages = this.getPagesForCommunityByType(community.getId(), null);
41
            Iterator<CommunityPage> iteratorPages = pages.iterator();
42
            while(iteratorPages.hasNext()) {
43
                CommunityPage page = iteratorPages.next();
44
                if(!page.getIsEnabled()) {
45
                    iteratorPages.remove();
46
                }
47
            }
48
            communityResponse.setPages(pages);
49

  
50
            List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getId());
51
            Iterator<CommunityEntity> iteratorEntities = entities.iterator();
52
            while(iteratorEntities.hasNext()) {
53
                CommunityEntity entity = iteratorEntities.next();
54
                if(!entity.getIsEnabled()) {
55
                    iteratorEntities.remove();
56
                }
57
            }
58
            communityResponse.setEntities(entities);
59

  
60
            communitiesResponse.add(communityResponse);
61
        }
62
        return communitiesResponse;
63
    }
64

  
65
    @RequestMapping(value = "/communityFull/{id}", method = RequestMethod.GET)
66
    public CommunityResponse getCommunityFull(@PathVariable(value = "id") String id) {
67
        Community community = communityDAO.findById(id);
68
        CommunityResponse communityResponse = new CommunityResponse(community);
69

  
70
        List<CommunityPage> pages = this.getPagesForCommunityByType(community.getId(), null);
71
        Iterator<CommunityPage> iteratorPages = pages.iterator();
72
        while(iteratorPages.hasNext()) {
73
            CommunityPage page = iteratorPages.next();
74
            if(!page.getIsEnabled()) {
75
                iteratorPages.remove();
76
            }
77
        }
78
        communityResponse.setPages(pages);
79

  
80
        List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getId());
81
        Iterator<CommunityEntity> iteratorEntities = entities.iterator();
82
        while(iteratorEntities.hasNext()) {
83
            CommunityEntity entity = iteratorEntities.next();
84
            if(!entity.getIsEnabled()) {
85
                iteratorEntities.remove();
86
            }
87
        }
88
        communityResponse.setEntities(entities);
89
//        communityResponse.setPages(this.getPagesForCommunityByType(community.getId(), null));
90
//        communityResponse.setEntities(this.getEntitiesForCommunity(community.getId()));
91

  
92
        return communityResponse;
93
    }
94

  
95
    @RequestMapping(value = "/communityFullByName/{name}", method = RequestMethod.GET)
96
    public CommunityResponse getCommunityFullByName(@PathVariable(value = "name") String name) {
97
        Community community = communityDAO.findByName(name);
98
        CommunityResponse communityResponse = new CommunityResponse(community);
99

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

  
110
        List<CommunityEntity> entities = this.getEntitiesForCommunity(community.getId());
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

  
120
        return communityResponse;
121
    }
122

  
123

  
124
    @RequestMapping(value = "/community/update", method = RequestMethod.POST)
125
    public CommunityResponse updateCommunity(@RequestBody Community community) {
126
        CommunityResponse communityResponse = this.getCommunityFull(community.getId());
127
        communityResponse.setName(community.getName());
128
        Community com = communityDAO.findById(community.getId());
129
        com.setName(community.getName());
130
        // = this.getCommunityByCommunityResponse(communityResponse);
131
        communityDAO.save(com);
132
        return communityResponse;
133
    }
134

  
135
    @RequestMapping(value = "/community/save", method = RequestMethod.POST)
136
    public CommunityResponse insertCommunity(@RequestBody Community community) {
137
        //Community community = this.getCommunityByCommunityResponse(communityResponse);
138

  
139
        List<CommunityEntity> communityEntities = new ArrayList<>();
140
        List<CommunityPage> communityPages = new ArrayList<>();
141
        Map<String, Boolean> pages = new HashMap<>();
142
        Map<String, Boolean> entities = new HashMap<>();
143
        for(Entity entity : entityDAO.findAll()) {
144
            entities.put(entity.getId(), false);
145

  
146
            CommunityEntity communityEntity = new CommunityEntity(entity);
147
            communityEntity.setIsEnabled(false);
148
            communityEntities.add(communityEntity);
149
        }
150
        for(Page page : pageDAO.findAll()) {
151
            pages.put(page.getId(), false);
152

  
153
            CommunityPage communityPage = new CommunityPage(page);
154
            communityPage.setIsEnabled(false);
155

  
156
            communityPages.add(communityPage);
157
        }
158
        community.setEntities(entities);
159
        Community savedCommunity = communityDAO.save(community);
160
//        communityResponse.setId(savedCommunity.getId());
161
        CommunityResponse communityResponse = new CommunityResponse();
162

  
163
        return communityResponse;
164
    }
165

  
166
    private Community getCommunityByCommunityResponse(CommunityResponse communityResponse) {
167
        Community community = new Community();
168
        community.setId(communityResponse.getId());
169
        community.setName(communityResponse.getName());
170

  
171
        List<CommunityEntity> fullEntities = communityResponse.getEntities();
172
        Map<String, Boolean> entities = new HashMap<String, Boolean>();
173
        for(CommunityEntity entity : fullEntities) {
174
            entities.put(entity.getId(), true);
175
        }
176
        for(Entity entity : entityDAO.findAll()) {
177
            if(!entities.containsKey(entity.getId())) {
178
                entities.put(entity.getId(), false);
179
            }
180
        }
181
        community.setEntities(entities);
182

  
183
        List<CommunityPage> fullPages = communityResponse.getPages();
184
        Map<String, Boolean> pages = new HashMap<String, Boolean>();
185
        for(CommunityPage page : fullPages) {
186
            pages.put(page.getId(), true);
187
        }
188
        for(Page page : pageDAO.findAll()) {
189
            if(!pages.containsKey(page.getId())) {
190
                pages.put(page.getId(), false);
191
            }
192
        }
193
        community.setPages(pages);
194

  
195
        return community;
196
    }
197

  
198
    @RequestMapping(value = "/community/delete", method = RequestMethod.POST)
199
    public Boolean deleteCommunities(@RequestBody List<String> communities) throws Exception {
200
        for (String id: communities) {
201
            communityDAO.delete(id);
202
        }
203

  
204
        return true;
205
    }
206

  
207
    @RequestMapping(value = "/community", method = RequestMethod.DELETE)
208
    public void deleteAllCommunities() {
209
        communityDAO.deleteAll();
210
    }
211

  
212
    @RequestMapping(value = "/community", method = RequestMethod.POST)
213
    public Community insertOrUpdateCommunity(@RequestBody Community community) {
214
        return communityDAO.save(community);
215
    }
216

  
217
    @RequestMapping(value = "/community/{id}", method = RequestMethod.GET)
218
    public Community getCommunity(@PathVariable(value = "id") String id) {
219
        return communityDAO.findById(id);
220
    }
221

  
222
    @RequestMapping(value = "/community/{id}", method = RequestMethod.DELETE)
223
    public void deleteCommunity(@PathVariable(value = "id") String id) {
224
        communityDAO.delete(id);
225
    }
226

  
227
    @RequestMapping(value = "/community/{id}/pages", method = RequestMethod.GET)
228
    public List<CommunityPage> getPagesForCommunityByType(@PathVariable(value = "id") String id, @RequestParam(value="page_type", required=false) String page_type) {
229
        List<CommunityPage> return_pages = new ArrayList<CommunityPage>();
230
        Map<String, Boolean> pages = communityDAO.findById(id).getPages();
231
        for(Map.Entry<String, Boolean> page : pages.entrySet()) {
232

  
233
            Page p = pageDAO.findById(page.getKey());
234
            if (page_type==null || p.getType().equals(page_type)) {
235
                CommunityPage communityPage = new CommunityPage(p);
236

  
237
                List<Entity> entities = new ArrayList<>();
238
                for (String entity : p.getEntities()) {
239
                    entities.add(entityDAO.findById(entity));
240
                }
241
                communityPage.setEntities(entities);
242
                communityPage.setIsEnabled(page.getValue());
243

  
244
                return_pages.add(communityPage);
245
            }
246
        }
247
        return return_pages;
248
    }
249

  
250
    @RequestMapping(value = "/community/{id}/page", method = RequestMethod.POST)
251
    public Community insertOrUpdatePage(@PathVariable(value = "id") String id, @RequestBody CommunityPage page) {
252
        Community community = communityDAO.findById(id);
253
        Map<String, Boolean> pages = community.getPages();
254

  
255
        String name = page.getName();
256
        boolean isEnabled = page.getIsEnabled();
257

  
258
        pages.put(name, isEnabled);
259
        community.setPages(pages);
260

  
261
        return communityDAO.save(community);
262
    }
263

  
264
    @RequestMapping(value = "community/{id}/page/toggle", method = RequestMethod.POST)
265
    public Community togglePage(@PathVariable(value = "id") String id, @RequestParam String pageId, @RequestParam String status) throws Exception {
266
        log.debug("Toggle community page: "+pageId +" of community: "+id+" to "+status);
267
        Community community = communityDAO.findById(id);
268
        Map<String, Boolean> pages = community.getPages();
269
        pages.put(pageId, Boolean.parseBoolean(status));
270
        community.setPages(pages);
271
        return communityDAO.save(community);
272
    }
273

  
274
    @RequestMapping(value = "community/{id}/entity/toggle", method = RequestMethod.POST)
275
    public Community toggleEntity(@PathVariable(value = "id") String id, @RequestParam String entityId, @RequestParam String status) throws Exception {
276
        log.debug("Toggle community entity: "+entityId +" of community: "+id+" to "+status);
277
        Community community = communityDAO.findById(id);
278
        Map<String, Boolean> entities = community.getEntities();
279
        entities.put(entityId, Boolean.parseBoolean(status));
280
        community.setEntities(entities);
281

  
282
        Map<String, Boolean> pages = community.getPages();
283
        /*
284
        if(entityId.equals("5a300ed5c97a7d2bc448fdb5")) { // Research Data
285
            pages.put("5a301570c97a7d35ef89e601", Boolean.parseBoolean(status));    // Search Research Data
286
        } else if(entityId.equals("5a300ee4c97a7d2c000b9e9d")) { // Publication
287
            pages.put("5a30191ac97a7d3a7fa77362", Boolean.parseBoolean(status));    // Search Publications
288
        } else if(entityId.equals("5a3064f9c97a7d4964408ee0")) { // Software
289
            pages.put("5a30657ac97a7d4964408ee4", Boolean.parseBoolean(status));    // Search Software
290
        } else if(entityId.equals("5a30652ec97a7d4964408ee1")) { // Organization
291
            pages.put("5a30eeffc97a7d74234434ad", Boolean.parseBoolean(status));    // Search Organizations
292
        } else if(entityId.equals("5a306539c97a7d4964408ee2")) { // Project
293
            pages.put("5a30efd9c97a7d7609b77ca5", Boolean.parseBoolean(status));    // Search Projects
294
        } else if(entityId.equals("5a30654dc97a7d4964408ee3")) { // Content Provider
295
            pages.put("5a30f08bc97a7d7609b77ca7", Boolean.parseBoolean(status));    // Search Content Providers
296
        }
297
        */
298
        for(Map.Entry<String, Boolean> pageEntry : pages.entrySet()) {
299
            Page page = pageDAO.findById(pageEntry.getKey());
300
            if(page.getEntities().contains(entityId) && page.getType().equals("search")) {
301
                pages.put(pageEntry.getKey(), Boolean.parseBoolean(status));
302
            }
303
        }
304
        return communityDAO.save(community);
305
    }
306

  
307
    @RequestMapping(value = "/community/{id}/entities", method = RequestMethod.GET)
308
    public List<CommunityEntity> getEntitiesForCommunity(@PathVariable(value = "id") String id) {
309
        List<CommunityEntity> return_entities = new ArrayList<CommunityEntity>();
310
        Map<String, Boolean> entities = communityDAO.findById(id).getEntities();
311
        for(Map.Entry<String, Boolean> entity : entities.entrySet()) {
312
            CommunityEntity communityEntity = new CommunityEntity(entityDAO.findById(entity.getKey()));
313
            communityEntity.setIsEnabled(entity.getValue());
314
            return_entities.add(communityEntity);
315
        }
316
        return return_entities;
317
    }
318
}
319

  
modules/uoa-admin-tools/src/main/resources/log4j.properties
1
log4j.rootLogger = WARN, R
2

  
3
log4j.logger.eu.dnetlib = DEBUG
4
log4j.logger.org.springframework = INFO, S
5

  
6
log4j.additivity.org.springframework = false
7

  
8
log4j.appender.R=org.apache.log4j.RollingFileAppender
9
log4j.appender.R.File=/var/log/dnet/admin-tools/admin-tools.log
10
log4j.appender.R.MaxFileSize=10MB
11
log4j.appender.R.MaxBackupIndex=10
12
log4j.appender.R.layout=org.apache.log4j.PatternLayout
13
log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
14

  
15
log4j.appender.S=org.apache.log4j.RollingFileAppender
16
log4j.appender.S.File=/var/log/dnet/admin-tools/admin-tools-spring.log
17
log4j.appender.S.MaxFileSize=10MB
18
log4j.appender.S.MaxBackupIndex=10
19
log4j.appender.S.layout=org.apache.log4j.PatternLayout
20
log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n
modules/uoa-admin-tools/pom.xml
31 31
		<dependency>
32 32
			<groupId>org.springframework.boot</groupId>
33 33
			<artifactId>spring-boot-starter-web</artifactId>
34
			<exclusions>
35
				<exclusion>
36
					<groupId> org.springframework.boot</groupId>
37
					<artifactId>spring-boot-starter-logging</artifactId>
38
				</exclusion>
39
			</exclusions>
34 40
		</dependency>
35 41

  
36 42
		<dependency>
......
43 49
			<artifactId>spring-boot-starter-test</artifactId>
44 50
			<scope>test</scope>
45 51
		</dependency>
52

  
53
		<dependency>
54
			<groupId>log4j</groupId>
55
			<artifactId>log4j</artifactId>
56
			<version>1.2.17</version>
57
		</dependency>
46 58
	</dependencies>
47 59

  
48 60
	<build>

Also available in: Unified diff