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.Page;
|
7
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
|
8
|
import eu.dnetlib.uoaadmintools.dao.PageHelpContentDAO;
|
9
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContentResponse;
|
10
|
|
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.RequestParam;
|
19
|
import org.springframework.web.bind.annotation.RestController;
|
20
|
|
21
|
import java.util.ArrayList;
|
22
|
import java.util.List;
|
23
|
|
24
|
@RestController
|
25
|
@CrossOrigin(origins = "*")
|
26
|
public class PageHelpContentController {
|
27
|
private final Logger log = Logger.getLogger(this.getClass());
|
28
|
|
29
|
@Autowired
|
30
|
private PageHelpContentDAO pageHelpContentDAO;
|
31
|
|
32
|
@Autowired
|
33
|
private PageController pageController;
|
34
|
|
35
|
@Autowired
|
36
|
private CommunityController communityController;
|
37
|
|
38
|
@Autowired
|
39
|
private CommunityDAO communityDAO;
|
40
|
|
41
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
|
42
|
public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community,
|
43
|
@RequestParam(required=false) String page,
|
44
|
@RequestParam(required=false) String position,
|
45
|
@RequestParam(required=false) String active,
|
46
|
@RequestParam(required=false) String before) {
|
47
|
List<PageHelpContent> pageHelpContents = null;
|
48
|
|
49
|
Community _community = null;
|
50
|
String communityId = null;
|
51
|
if(community != null) {
|
52
|
_community = communityController.getCommunity(community);
|
53
|
if(_community != null) {
|
54
|
communityId = _community.getId();
|
55
|
}
|
56
|
}
|
57
|
//pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndisPriorToOrderByOrderAsc(community, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
58
|
|
59
|
if(community != null && position != null && active != null && before != null) {
|
60
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
61
|
} else if(community != null && position != null && active != null) {
|
62
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active));
|
63
|
} else if(community != null && position != null && before != null) {
|
64
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(before));
|
65
|
} else if(community != null && active != null && before != null) {
|
66
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
67
|
} else if(position != null && active != null && before != null) {
|
68
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
69
|
} else if(community != null && position != null ) {
|
70
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementOrderByOrderAsc(communityId, position);
|
71
|
} else if(community != null && active != null ) {
|
72
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active));
|
73
|
} else if(community != null && before != null) {
|
74
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(before));
|
75
|
} else if(position != null && active != null) {
|
76
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
|
77
|
} else if(position != null && before != null) {
|
78
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(before));
|
79
|
} else if(active != null && before != null) {
|
80
|
pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
81
|
} else if(community != null) {
|
82
|
pageHelpContents = pageHelpContentDAO.findByCommunityOrderByPlacementAscOrderAsc(communityId);
|
83
|
} else if(position != null) {
|
84
|
pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
|
85
|
} else if(active != null) {
|
86
|
pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
|
87
|
} else if(before != null) {
|
88
|
pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
|
89
|
} else {
|
90
|
pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
|
91
|
}
|
92
|
|
93
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
94
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
95
|
Page _page = pageController.getPage(pageHelpContent.getPage());
|
96
|
if(page == null || page.equals(_page.getRoute())) {
|
97
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
98
|
|
99
|
pageHelpContentResponse.setPage(_page);
|
100
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
101
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
102
|
}
|
103
|
}
|
104
|
return pageHelpContentResponses;
|
105
|
}
|
106
|
/*
|
107
|
@RequestMapping(value = "/pagehelpcontent/community/{id}", method = RequestMethod.GET)
|
108
|
public List<PageHelpContentResponse> getCommunityPageHelpContents(@PathVariable(value = "id") String communityId) {
|
109
|
List<PageHelpContent> pageHelpContents = pageHelpContentDAO.findByCommunity(communityId);
|
110
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
111
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
112
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
113
|
pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
|
114
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
115
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
116
|
}
|
117
|
return pageHelpContentResponses;
|
118
|
}
|
119
|
*/
|
120
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
|
121
|
public void deleteAllPageHelpContents() {
|
122
|
pageHelpContentDAO.deleteAll();
|
123
|
}
|
124
|
|
125
|
@RequestMapping(value = "/pagehelpcontent/save", method = RequestMethod.POST)
|
126
|
public PageHelpContent insertPageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
127
|
//String communityId = communityController.getCommunity(pageHelpContent.getCommunity()).getId();
|
128
|
pageHelpContent.setCommunity(pageHelpContent.getCommunity());
|
129
|
return pageHelpContentDAO.save(pageHelpContent);
|
130
|
}
|
131
|
|
132
|
@RequestMapping(value = "/pagehelpcontent/update", method = RequestMethod.POST)
|
133
|
public PageHelpContent updatePageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
134
|
return pageHelpContentDAO.save(pageHelpContent);
|
135
|
}
|
136
|
|
137
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.GET)
|
138
|
public PageHelpContent getPageHelpContent(@PathVariable(value = "id") String id) {
|
139
|
return pageHelpContentDAO.findById(id);
|
140
|
}
|
141
|
|
142
|
@RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
|
143
|
public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
|
144
|
for (String id: pageHelpContents) {
|
145
|
log.debug("Id of pageHelpContent: "+id);
|
146
|
PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
|
147
|
pageHelpContent.setIsActive(Boolean.parseBoolean(status));
|
148
|
pageHelpContentDAO.save(pageHelpContent);
|
149
|
}
|
150
|
return pageHelpContents;
|
151
|
}
|
152
|
|
153
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
|
154
|
public void deletePageHelpContent(@PathVariable(value = "id") String id) {
|
155
|
pageHelpContentDAO.delete(id);
|
156
|
}
|
157
|
|
158
|
@RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
|
159
|
public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
|
160
|
for (String id: pageHelpContents) {
|
161
|
pageHelpContentDAO.delete(id);
|
162
|
}
|
163
|
return true;
|
164
|
}
|
165
|
|
166
|
public void addPageHelpContentsInCommunity(String pid, String communityId) {
|
167
|
if (pid != "connect" && pid != "openaire") {
|
168
|
String organizations_page_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
|
169
|
Page organizationsPage = (pageController.getAllPages(null, "/organizations", null)).get(0);
|
170
|
|
171
|
PageHelpContent organizations_pageHelpContent = new PageHelpContent(organizationsPage.getId(), communityId, "top", 1, organizations_page_content, false, false);
|
172
|
this.insertPageHelpContent(organizations_pageHelpContent);
|
173
|
|
174
|
String depositLearnHow_page_content = "" +
|
175
|
"<div class=\"uk-width-3-5 uk-align-center\"> " +
|
176
|
" <div class=\"uk-text-bold\">How to comply with funder Open Access policies</div> " +
|
177
|
" <ul class=\"uk-list uk-list-bullet\"> " +
|
178
|
" <li>Read the <a class=\"custom-external\" href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-publications\" target=\"_blank\"> OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on publications </a></li> " +
|
179
|
" <li>Read the <a class=\"custom-external\" href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-data\" target=\"_blank\"> OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on research data </a></li> " +
|
180
|
" <li>If you want to know about National Open Access policies, please check them out <a class=\"custom-external\" href=\"https://www.openaire.eu/frontpage/country-pages\" target=\"_blank\">here</a></li> " +
|
181
|
" <li>All OpenAIRE guides can be found <a class=\"custom-external\" href=\"https://www.openaire.eu/guides\" target=\"_blank\">here</a></li> " +
|
182
|
" </ul> " +
|
183
|
"</div>";
|
184
|
Page depositLearnHowPage = (pageController.getAllPages(null, "/participate/deposit/learn-how", null)).get(0);
|
185
|
|
186
|
PageHelpContent depositLearnHow_pageHelpContent = new PageHelpContent(depositLearnHowPage.getId(), communityId, "bottom", 1, depositLearnHow_page_content, true, false);
|
187
|
this.insertPageHelpContent(depositLearnHow_pageHelpContent);
|
188
|
}
|
189
|
}
|
190
|
}
|
191
|
|
192
|
|