1
|
package eu.dnetlib.uoaadmintoolslibrary.services;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintoolslibrary.dao.PageHelpContentDAO;
|
4
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
|
5
|
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
|
6
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
8
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse;
|
9
|
|
10
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
11
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.stereotype.Service;
|
15
|
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.List;
|
18
|
|
19
|
@Service
|
20
|
public class PageHelpContentService {
|
21
|
private final Logger log = Logger.getLogger(this.getClass());
|
22
|
|
23
|
@Autowired
|
24
|
private PageHelpContentDAO pageHelpContentDAO;
|
25
|
|
26
|
@Autowired
|
27
|
private PageService pageService;
|
28
|
|
29
|
@Autowired
|
30
|
private PortalService portalService;
|
31
|
|
32
|
public List<PageHelpContentResponse> getPageHelpContents(String pid, String portalType, String page, String position, String active, String before) {
|
33
|
List<PageHelpContent> pageHelpContents = null;
|
34
|
|
35
|
Portal _portal = null;
|
36
|
String portalId = null;
|
37
|
if(pid != null) {
|
38
|
_portal = portalService.getPortal(pid);
|
39
|
if(_portal != null) {
|
40
|
portalId = _portal.getId();
|
41
|
}
|
42
|
}
|
43
|
|
44
|
if(pid != null && position != null && active != null && before != null) {
|
45
|
pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(portalId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
46
|
} else if(pid != null && position != null && active != null) {
|
47
|
pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsActiveOrderByOrderAsc(portalId, position, Boolean.parseBoolean(active));
|
48
|
} else if(pid != null && position != null && before != null) {
|
49
|
pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsPriorToOrderByOrderAsc(portalId, position, Boolean.parseBoolean(before));
|
50
|
} else if(pid != null && active != null && before != null) {
|
51
|
pageHelpContents = pageHelpContentDAO.findByPortalAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
52
|
} else if(position != null && active != null && before != null) {
|
53
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
54
|
} else if(pid != null && position != null ) {
|
55
|
pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementOrderByOrderAsc(portalId, position);
|
56
|
} else if(pid != null && active != null ) {
|
57
|
pageHelpContents = pageHelpContentDAO.findByPortalAndIsActiveOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(active));
|
58
|
} else if(pid != null && before != null) {
|
59
|
pageHelpContents = pageHelpContentDAO.findByPortalAndIsPriorToOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(before));
|
60
|
} else if(position != null && active != null) {
|
61
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
|
62
|
} else if(position != null && before != null) {
|
63
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(before));
|
64
|
} else if(active != null && before != null) {
|
65
|
pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
66
|
} else if(pid != null) {
|
67
|
pageHelpContents = pageHelpContentDAO.findByPortalOrderByPlacementAscOrderAsc(portalId);
|
68
|
} else if(position != null) {
|
69
|
pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
|
70
|
} else if(active != null) {
|
71
|
pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
|
72
|
} else if(before != null) {
|
73
|
pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
|
74
|
} else {
|
75
|
pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
|
76
|
}
|
77
|
|
78
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
79
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
80
|
Page _page = pageService.getPage(pageHelpContent.getPage());
|
81
|
if((page == null || page.equals(_page.getRoute())) && (portalType == null || portalType.equals(_page.getPortalType()))) {
|
82
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
83
|
|
84
|
pageHelpContentResponse.setPage(_page);
|
85
|
pageHelpContentResponse.setPortal(portalService.getPortalById(pageHelpContent.getPortal()));
|
86
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
87
|
}
|
88
|
}
|
89
|
return pageHelpContentResponses;
|
90
|
}
|
91
|
|
92
|
public void deleteAllPageHelpContents() {
|
93
|
pageHelpContentDAO.deleteAll();
|
94
|
}
|
95
|
|
96
|
// public PageHelpContent insertPageHelpContent(PageHelpContent pageHelpContent) {
|
97
|
// String portalId = portalService.getPortal(pageHelpContent.getPortal()).getId();
|
98
|
// pageHelpContent.setPortal(portalId);
|
99
|
// return pageHelpContentDAO.save(pageHelpContent);
|
100
|
// }
|
101
|
//
|
102
|
// public PageHelpContent updatePageHelpContent(PageHelpContent pageHelpContent) {
|
103
|
// return pageHelpContentDAO.save(pageHelpContent);
|
104
|
// }
|
105
|
|
106
|
public PageHelpContent insertOrUpdatePageHelpContent(PageHelpContent pageHelpContent) {
|
107
|
return pageHelpContentDAO.save(pageHelpContent);
|
108
|
}
|
109
|
|
110
|
public PageHelpContent getPageHelpContent(String id) {
|
111
|
return pageHelpContentDAO.findById(id);
|
112
|
}
|
113
|
|
114
|
public List<String> togglePageHelpContent(List<String> pageHelpContents, String status, String pid, PortalType portalType) throws Exception {
|
115
|
Portal portal = portalService.getPortal(pid);
|
116
|
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid");
|
117
|
|
118
|
for (String id: pageHelpContents) {
|
119
|
// log.debug("Id of pageHelpContent: "+id);
|
120
|
PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
|
121
|
if(pageHelpContent == null) {
|
122
|
throw new ContentNotFoundException("Page help content with id: " + id + " not found");
|
123
|
}
|
124
|
if(!pageHelpContent.getPortal().equals(portal.getId())) {
|
125
|
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal());
|
126
|
}
|
127
|
pageHelpContent.setIsActive(Boolean.parseBoolean(status));
|
128
|
pageHelpContentDAO.save(pageHelpContent);
|
129
|
}
|
130
|
return pageHelpContents;
|
131
|
}
|
132
|
|
133
|
public void deletePageHelpContent(String id) {
|
134
|
pageHelpContentDAO.delete(id);
|
135
|
}
|
136
|
|
137
|
public Boolean deletePageHelpContents(List<String> pageHelpContents, String pid, PortalType portalType) throws Exception {
|
138
|
Portal portal = portalService.getPortal(pid);
|
139
|
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid");
|
140
|
|
141
|
for (String id: pageHelpContents) {
|
142
|
PageHelpContent pageHelpContent = getPageHelpContent(id);
|
143
|
if(pageHelpContent == null) {
|
144
|
throw new ContentNotFoundException("Page help content with id: " + id + " not found");
|
145
|
}
|
146
|
if(!pageHelpContent.getPortal().equals(portal.getId())) {
|
147
|
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal());
|
148
|
}
|
149
|
pageHelpContentDAO.delete(id);
|
150
|
}
|
151
|
return true;
|
152
|
}
|
153
|
|
154
|
public void addPageHelpContentsInPortal(String portalId, String portalType) {
|
155
|
Page organizationsPage = pageService.getPageByPortalTypeAndRoute(portalType, "/organizations");
|
156
|
if(organizationsPage != null) {
|
157
|
String organizations_page_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
|
158
|
|
159
|
PageHelpContent organizations_pageHelpContent = new PageHelpContent(organizationsPage.getId(), portalId, "top", 1, organizations_page_content, false, false);
|
160
|
//this.insertPageHelpContent(organizations_pageHelpContent);
|
161
|
pageHelpContentDAO.save(organizations_pageHelpContent);
|
162
|
}
|
163
|
|
164
|
Page depositLearnHowPage = pageService.getPageByPortalTypeAndRoute(portalType, "/participate/deposit/learn-how");
|
165
|
if(depositLearnHowPage != null) {
|
166
|
String depositLearnHow_page_content = "" +
|
167
|
"<div class=\"uk-width-3-5 uk-align-center\"> " +
|
168
|
" <div class=\"uk-text-bold\">How to comply with funder Open Access policies</div> " +
|
169
|
" <ul class=\"uk-list uk-list-bullet\"> " +
|
170
|
" <li>Read the <a href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-publications\" target=\"_blank\"> <span>OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on publications>/span> <span class=\"custom-external custom-icon space\"> </span> </a></li> " +
|
171
|
" <li>Read the <a href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-data\" target=\"_blank\"> <span>OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on research data</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
|
172
|
" <li>If you want to know about National Open Access policies, please check them out <a href=\"https://www.openaire.eu/frontpage/country-pages\" target=\"_blank\"><span>here</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
|
173
|
" <li>All OpenAIRE guides can be found <a href=\"https://www.openaire.eu/guides\" target=\"_blank\"><span>here</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
|
174
|
" </ul> " +
|
175
|
"</div>";
|
176
|
|
177
|
PageHelpContent depositLearnHow_pageHelpContent = new PageHelpContent(depositLearnHowPage.getId(), portalId, "bottom", 1, depositLearnHow_page_content, true, false);
|
178
|
//this.insertPageHelpContent(depositLearnHow_pageHelpContent);
|
179
|
pageHelpContentDAO.save(depositLearnHow_pageHelpContent);
|
180
|
}
|
181
|
}
|
182
|
}
|