Revision 50613
Added by Konstantina Galouni over 5 years ago
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/DivHelpContentDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.entities.DivHelpContent; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface DivHelpContentDAO { |
|
8 |
List<DivHelpContent> findAll(); |
|
9 |
|
|
10 |
List<DivHelpContent> findByDivId(String divId); |
|
11 |
|
|
12 |
DivHelpContent findById(String Id); |
|
13 |
|
|
14 |
DivHelpContent save(DivHelpContent divHelpContent); |
|
15 |
|
|
16 |
void deleteAll(); |
|
17 |
|
|
18 |
void delete(String id); |
|
19 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDivHelpContentDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.entities.DivHelpContent; |
|
4 |
import org.springframework.data.mongodb.repository.MongoRepository; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface MongoDBDivHelpContentDAO extends DivHelpContentDAO, MongoRepository<DivHelpContent, String> { |
|
9 |
List<DivHelpContent> findAll(); |
|
10 |
|
|
11 |
List<DivHelpContent> findByDivId(String divId); |
|
12 |
|
|
13 |
DivHelpContent findById(String Id); |
|
14 |
|
|
15 |
DivHelpContent save(DivHelpContent divHelpContent); |
|
16 |
|
|
17 |
void deleteAll(); |
|
18 |
|
|
19 |
void delete(String id); |
|
20 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/DivIdDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.entities.DivId; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface DivIdDAO { |
|
8 |
List<DivId> findAll(); |
|
9 |
|
|
10 |
List<DivId> findByCommunity(String community); |
|
11 |
List<DivId> findByCommunityAndPage(String community, String page); |
|
12 |
|
|
13 |
DivId findById(String Id); |
|
14 |
|
|
15 |
DivId save(DivId divId); |
|
16 |
|
|
17 |
void deleteAll(); |
|
18 |
|
|
19 |
void delete(String id); |
|
20 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDivIdDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.entities.DivId; |
|
4 |
import org.springframework.data.mongodb.repository.MongoRepository; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface MongoDBDivIdDAO extends DivIdDAO, MongoRepository<DivId, String> { |
|
9 |
List<DivId> findAll(); |
|
10 |
|
|
11 |
List<DivId> findByCommunity(String community); |
|
12 |
List<DivId> findByCommunityAndPage(String community, String page); |
|
13 |
|
|
14 |
DivId findById(String Id); |
|
15 |
|
|
16 |
DivId save(DivId divId); |
|
17 |
|
|
18 |
void deleteAll(); |
|
19 |
|
|
20 |
void delete(String id); |
|
21 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/DivId.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 DivId { |
|
7 |
@Id |
|
8 |
@JsonProperty("_id") |
|
9 |
private String id; |
|
10 |
|
|
11 |
private String name; |
|
12 |
private String page; |
|
13 |
private String community; |
|
14 |
|
|
15 |
public DivId() { |
|
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 |
public String getPage() { |
|
35 |
return page; |
|
36 |
} |
|
37 |
|
|
38 |
public void setPage(String page) { |
|
39 |
this.page = page; |
|
40 |
} |
|
41 |
|
|
42 |
public String getCommunity() { |
|
43 |
return community; |
|
44 |
} |
|
45 |
|
|
46 |
public void setCommunity(String community) { |
|
47 |
this.community = community; |
|
48 |
} |
|
49 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/DivHelpContentResponse.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 DivHelpContentResponse { |
|
7 |
@Id |
|
8 |
@JsonProperty("_id") |
|
9 |
private String id; |
|
10 |
|
|
11 |
private DivIdResponse divId; |
|
12 |
private String content; |
|
13 |
private boolean isActive = true; |
|
14 |
|
|
15 |
public DivHelpContentResponse(DivHelpContent divHelpContent) { |
|
16 |
this.id = divHelpContent.getId(); |
|
17 |
this.content = divHelpContent.getContent(); |
|
18 |
this.isActive = divHelpContent.getIsActive(); |
|
19 |
} |
|
20 |
|
|
21 |
public String getId() { |
|
22 |
return id; |
|
23 |
} |
|
24 |
|
|
25 |
public void setId(String id) { |
|
26 |
this.id = id; |
|
27 |
} |
|
28 |
|
|
29 |
public DivIdResponse getDivId() { |
|
30 |
return divId; |
|
31 |
} |
|
32 |
|
|
33 |
public void setDivId(DivIdResponse divId) { |
|
34 |
this.divId = divId; |
|
35 |
} |
|
36 |
|
|
37 |
public String getContent() { |
|
38 |
return content; |
|
39 |
} |
|
40 |
|
|
41 |
public void setContent(String content) { |
|
42 |
this.content = content; |
|
43 |
} |
|
44 |
|
|
45 |
public boolean getIsActive() { |
|
46 |
return isActive; |
|
47 |
} |
|
48 |
|
|
49 |
public void setIsActive(boolean isActive) { |
|
50 |
this.isActive = isActive; |
|
51 |
} |
|
52 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/DivIdResponse.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 DivIdResponse { |
|
7 |
@Id |
|
8 |
@JsonProperty("_id") |
|
9 |
private String id; |
|
10 |
|
|
11 |
private String name; |
|
12 |
private Page page; |
|
13 |
private Community community; |
|
14 |
|
|
15 |
public DivIdResponse(DivId divId) { |
|
16 |
this.id = divId.getId(); |
|
17 |
this.name = divId.getName(); |
|
18 |
} |
|
19 |
|
|
20 |
public String getId() { |
|
21 |
return id; |
|
22 |
} |
|
23 |
|
|
24 |
public void setId(String id) { |
|
25 |
this.id = id; |
|
26 |
} |
|
27 |
|
|
28 |
public String getName() { |
|
29 |
return name; |
|
30 |
} |
|
31 |
|
|
32 |
public void setName(String name) { |
|
33 |
this.name = name; |
|
34 |
} |
|
35 |
|
|
36 |
public Page getPage() { |
|
37 |
return page; |
|
38 |
} |
|
39 |
|
|
40 |
public void setPage(Page page) { |
|
41 |
this.page = page; |
|
42 |
} |
|
43 |
|
|
44 |
public Community getCommunity() { |
|
45 |
return community; |
|
46 |
} |
|
47 |
|
|
48 |
public void setCommunity(Community community) { |
|
49 |
this.community = community; |
|
50 |
} |
|
51 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/DivHelpContent.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 DivHelpContent { |
|
7 |
@Id |
|
8 |
@JsonProperty("_id") |
|
9 |
private String id; |
|
10 |
|
|
11 |
private String divId; |
|
12 |
private String content; |
|
13 |
private boolean isActive = true; |
|
14 |
|
|
15 |
public DivHelpContent() { |
|
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 getDivId() { |
|
27 |
return divId; |
|
28 |
} |
|
29 |
|
|
30 |
public void setDivId(String divId) { |
|
31 |
this.divId = divId; |
|
32 |
} |
|
33 |
|
|
34 |
public String getContent() { |
|
35 |
return content; |
|
36 |
} |
|
37 |
|
|
38 |
public void setContent(String content) { |
|
39 |
this.content = content; |
|
40 |
} |
|
41 |
|
|
42 |
public boolean getIsActive() { |
|
43 |
return isActive; |
|
44 |
} |
|
45 |
|
|
46 |
public void setIsActive(boolean isActive) { |
|
47 |
this.isActive = isActive; |
|
48 |
} |
|
49 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/DivIdController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.controllers; |
|
2 |
|
|
3 |
import com.sun.org.apache.xpath.internal.operations.Div; |
|
4 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
|
5 |
import eu.dnetlib.uoaadmintools.dao.DivIdDAO; |
|
6 |
import eu.dnetlib.uoaadmintools.dao.PageDAO; |
|
7 |
import eu.dnetlib.uoaadmintools.entities.DivId; |
|
8 |
import eu.dnetlib.uoaadmintools.entities.DivIdResponse; |
|
9 |
import eu.dnetlib.uoaadmintools.entities.Page; |
|
10 |
import org.apache.log4j.Logger; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
import org.springframework.web.bind.annotation.*; |
|
13 |
|
|
14 |
import java.util.*; |
|
15 |
|
|
16 |
@RestController |
|
17 |
@CrossOrigin(origins = "*") |
|
18 |
public class DivIdController { |
|
19 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private DivIdDAO divIdDAO; |
|
23 |
|
|
24 |
@Autowired |
|
25 |
private CommunityDAO communityDAO; |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private PageDAO pageDAO; |
|
29 |
|
|
30 |
DivIdController() {} |
|
31 |
|
|
32 |
@RequestMapping(value = "/div", method = RequestMethod.GET) |
|
33 |
public List<DivId> getDivIds(@RequestParam(required = false) String community, |
|
34 |
@RequestParam(required = false) String page) { |
|
35 |
List<DivId> divIds = null; |
|
36 |
if(community != null && page != null) { |
|
37 |
String communityId = communityDAO.findByPid(community).getId(); |
|
38 |
divIds = divIdDAO.findByCommunityAndPage(communityId, page); |
|
39 |
} else if(community != null) { |
|
40 |
String communityId = communityDAO.findByPid(community).getId(); |
|
41 |
divIds = divIdDAO.findByCommunity(communityId); |
|
42 |
} else { |
|
43 |
divIds = divIdDAO.findAll(); |
|
44 |
} |
|
45 |
return divIds; |
|
46 |
} |
|
47 |
|
|
48 |
@RequestMapping(value = "/divFull", method = RequestMethod.GET) |
|
49 |
public List<DivIdResponse> getDivIdsFull(@RequestParam(required = false) String community, |
|
50 |
@RequestParam(required = false) String page) { |
|
51 |
|
|
52 |
List<DivId> divIds = this.getDivIds(community, page); |
|
53 |
|
|
54 |
List<DivIdResponse> divIdResponses = new ArrayList<>(); |
|
55 |
for(DivId divId : divIds) { |
|
56 |
DivIdResponse divIdResponse = new DivIdResponse(divId); |
|
57 |
divIdResponse.setCommunity(communityDAO.findById(divId.getCommunity())); |
|
58 |
divIdResponse.setPage(pageDAO.findById(divId.getPage())); |
|
59 |
|
|
60 |
divIdResponses.add(divIdResponse); |
|
61 |
} |
|
62 |
|
|
63 |
return divIdResponses; |
|
64 |
} |
|
65 |
|
|
66 |
@RequestMapping(value = "/div/{id}", method = RequestMethod.GET) |
|
67 |
public DivId getDivId(@PathVariable(value = "id") String id) { |
|
68 |
return divIdDAO.findById(id); |
|
69 |
} |
|
70 |
|
|
71 |
@RequestMapping(value = "/divFull/{id}", method = RequestMethod.GET) |
|
72 |
public DivIdResponse getDivIdFull(@PathVariable(value = "id") String id) { |
|
73 |
DivId divId = divIdDAO.findById(id); |
|
74 |
DivIdResponse divIdResponse = new DivIdResponse(divId); |
|
75 |
divIdResponse.setCommunity(communityDAO.findById(divId.getCommunity())); |
|
76 |
divIdResponse.setPage(pageDAO.findById(divId.getPage())); |
|
77 |
return divIdResponse; |
|
78 |
} |
|
79 |
|
|
80 |
@RequestMapping(value = "/div", method = RequestMethod.DELETE) |
|
81 |
public void deleteAllDivIds() { |
|
82 |
divIdDAO.deleteAll(); |
|
83 |
} |
|
84 |
|
|
85 |
@RequestMapping(value = "/div/save", method = RequestMethod.POST) |
|
86 |
public DivIdResponse insertDivId(@RequestBody DivId divId) { |
|
87 |
String community_id = communityDAO.findByPid(divId.getCommunity()).getId(); |
|
88 |
divId.setCommunity(community_id); |
|
89 |
divIdDAO.save(divId); |
|
90 |
return this.getDivIdFull(divId.getId()); |
|
91 |
} |
|
92 |
|
|
93 |
@RequestMapping(value = "/div/update", method = RequestMethod.POST) |
|
94 |
public DivIdResponse updateDivId(@RequestBody DivIdResponse divIdResponse) { |
|
95 |
DivId divId = divIdDAO.findById(divIdResponse.getId()); |
|
96 |
divId.setName(divIdResponse.getName()); |
|
97 |
divId.setPage(divIdResponse.getPage().getId()); |
|
98 |
divIdDAO.save(divId); |
|
99 |
return divIdResponse; |
|
100 |
} |
|
101 |
|
|
102 |
@RequestMapping(value = "/div/delete", method = RequestMethod.POST) |
|
103 |
public Boolean deleteDivIds(@RequestBody List<String> divIds) throws Exception { |
|
104 |
for (String id: divIds) { |
|
105 |
divIdDAO.delete(id); |
|
106 |
} |
|
107 |
return true; |
|
108 |
} |
|
109 |
|
|
110 |
@RequestMapping(value = "/div/{id}", method = RequestMethod.DELETE) |
|
111 |
public void deleteDivId(@PathVariable(value = "id") String id) { |
|
112 |
divIdDAO.delete(id); |
|
113 |
} |
|
114 |
|
|
115 |
@RequestMapping(value = "/div/pages", method = RequestMethod.GET) |
|
116 |
public Map<String, Set<String>> getDivIdsPages(@RequestParam(required = false) String community) { |
|
117 |
List<DivId> divIds = null; |
|
118 |
Map<String, Set<String>> hasCommunityPageDivIds = new HashMap<>(); |
|
119 |
if(community != null) { |
|
120 |
String communityId = communityDAO.findByPid(community).getId(); |
|
121 |
divIds = divIdDAO.findByCommunity(communityId); |
|
122 |
} else { |
|
123 |
divIds = divIdDAO.findAll(); |
|
124 |
} |
|
125 |
|
|
126 |
for(DivId divId : divIds) { |
|
127 |
String communityPid; |
|
128 |
if(community == null) { |
|
129 |
communityPid = communityDAO.findById(divId.getCommunity()).getPid(); |
|
130 |
} else { |
|
131 |
communityPid = community; |
|
132 |
} |
|
133 |
|
|
134 |
if(hasCommunityPageDivIds.containsKey(communityPid)) { |
|
135 |
hasCommunityPageDivIds.get(communityPid).add(divId.getPage()); |
|
136 |
} else { |
|
137 |
hasCommunityPageDivIds.put(communityPid, new HashSet<>()); |
|
138 |
hasCommunityPageDivIds.get(communityPid).add(divId.getPage()); |
|
139 |
} |
|
140 |
} |
|
141 |
return hasCommunityPageDivIds; |
|
142 |
} |
|
143 |
} |
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/DivHelpContentController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
|
4 |
import eu.dnetlib.uoaadmintools.dao.DivHelpContentDAO; |
|
5 |
import eu.dnetlib.uoaadmintools.dao.DivIdDAO; |
|
6 |
import eu.dnetlib.uoaadmintools.dao.PageDAO; |
|
7 |
import eu.dnetlib.uoaadmintools.entities.*; |
|
8 |
import org.apache.log4j.Logger; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.web.bind.annotation.*; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
@RestController |
|
16 |
@CrossOrigin(origins = "*") |
|
17 |
public class DivHelpContentController { |
|
18 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
19 |
|
|
20 |
@Autowired |
|
21 |
DivIdController divIdController; |
|
22 |
|
|
23 |
@Autowired |
|
24 |
private DivHelpContentDAO divHelpContentDAO; |
|
25 |
|
|
26 |
@Autowired |
|
27 |
private DivIdDAO divIdDAO; |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private PageDAO pageDAO; |
|
31 |
|
|
32 |
@Autowired |
|
33 |
private CommunityDAO communityDAO; |
|
34 |
|
|
35 |
@RequestMapping(value = "/divhelpcontent", method = RequestMethod.GET) |
|
36 |
public List<DivHelpContentResponse> getDivHelpContents(@RequestParam(required = false) String community, |
|
37 |
@RequestParam(required = false) String page, |
|
38 |
@RequestParam(required = false) String active) { |
|
39 |
List<DivHelpContentResponse> divHelpContentResponses = new ArrayList<>(); |
|
40 |
List<DivIdResponse> divIdResponses = null; |
|
41 |
|
|
42 |
if(community != null) { |
|
43 |
divIdResponses = divIdController.getDivIdsFull(community, null); |
|
44 |
} else { |
|
45 |
divIdResponses = divIdController.getDivIdsFull(null, null); |
|
46 |
} |
|
47 |
|
|
48 |
for(DivIdResponse divIdResponse : divIdResponses) { |
|
49 |
if(page == null || divIdResponse.getPage().getRoute().equals(page)) { |
|
50 |
List<DivHelpContent> divHelpContents = divHelpContentDAO.findByDivId(divIdResponse.getId()); |
|
51 |
|
|
52 |
for (DivHelpContent divHelpContent : divHelpContents) { |
|
53 |
if(active == null || Boolean.parseBoolean(active) == divHelpContent.getIsActive()) { |
|
54 |
DivHelpContentResponse divHelpContentResponse = new DivHelpContentResponse(divHelpContent); |
|
55 |
divHelpContentResponse.setDivId(divIdResponse); |
|
56 |
divHelpContentResponses.add(divHelpContentResponse); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
return divHelpContentResponses; |
|
63 |
} |
|
64 |
|
|
65 |
@RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.GET) |
|
66 |
public DivHelpContent getDivHelpContent(@PathVariable(value = "id") String id) { |
|
67 |
return divHelpContentDAO.findById(id); |
|
68 |
} |
|
69 |
|
|
70 |
@RequestMapping(value = "/divhelpcontent", method = RequestMethod.POST) |
|
71 |
public DivHelpContent insertOrUpdateDivHelpContent(@RequestBody DivHelpContent divHelpContent) { |
|
72 |
return divHelpContentDAO.save(divHelpContent); |
|
73 |
} |
|
74 |
|
|
75 |
@RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.DELETE) |
|
76 |
public void deleteDivHelpContent(@PathVariable(value = "id") String id) { |
|
77 |
divHelpContentDAO.delete(id); |
|
78 |
} |
|
79 |
|
|
80 |
@RequestMapping(value = "/divhelpcontent/delete", method = RequestMethod.POST) |
|
81 |
public Boolean deleteDivHelpContents(@RequestBody List<String> divHelpContents) throws Exception { |
|
82 |
for (String id: divHelpContents) { |
|
83 |
divHelpContentDAO.delete(id); |
|
84 |
} |
|
85 |
return true; |
|
86 |
} |
|
87 |
|
|
88 |
@RequestMapping(value = "/divhelpcontent/toggle", method = RequestMethod.POST) |
|
89 |
public List<String> toggleDivHelpContent(@RequestBody List<String> divHelpContents, @RequestParam String status) throws Exception { |
|
90 |
for (String id: divHelpContents) { |
|
91 |
log.debug("Id of divHelpContent: "+id); |
|
92 |
DivHelpContent divHelpContent = divHelpContentDAO.findById(id); |
|
93 |
divHelpContent.setIsActive(Boolean.parseBoolean(status)); |
|
94 |
divHelpContentDAO.save(divHelpContent); |
|
95 |
} |
|
96 |
return divHelpContents; |
|
97 |
} |
|
98 |
|
|
99 |
} |
Also available in: Unified diff
Added missing files from previous commit about DivId and DivHelpContent