193 lines
12 KiB
Java
193 lines
12 KiB
Java
package eu.dnetlib.uoaadmintools.controllers;
|
|
|
|
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
|
import eu.dnetlib.uoaadmintools.dao.PageDAO;
|
|
import eu.dnetlib.uoaadmintools.entities.Community;
|
|
import eu.dnetlib.uoaadmintools.entities.Page;
|
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
|
|
import eu.dnetlib.uoaadmintools.dao.PageHelpContentDAO;
|
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContentResponse;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@CrossOrigin(origins = "*")
|
|
public class PageHelpContentController {
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
|
|
|
@Autowired
|
|
private PageHelpContentDAO pageHelpContentDAO;
|
|
|
|
@Autowired
|
|
private PageController pageController;
|
|
|
|
@Autowired
|
|
private CommunityController communityController;
|
|
|
|
@Autowired
|
|
private CommunityDAO communityDAO;
|
|
|
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
|
|
public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community,
|
|
@RequestParam(required=false) String page,
|
|
@RequestParam(required=false) String position,
|
|
@RequestParam(required=false) String active,
|
|
@RequestParam(required=false) String before) {
|
|
List<PageHelpContent> pageHelpContents = null;
|
|
|
|
Community _community = null;
|
|
String communityId = null;
|
|
if(community != null) {
|
|
_community = communityController.getCommunity(community);
|
|
if(_community != null) {
|
|
communityId = _community.getId();
|
|
}
|
|
}
|
|
//pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndisPriorToOrderByOrderAsc(community, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
|
|
|
if(community != null && position != null && active != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
|
} else if(community != null && position != null && active != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active));
|
|
} else if(community != null && position != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(before));
|
|
} else if(community != null && active != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
|
} else if(position != null && active != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
|
} else if(community != null && position != null ) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementOrderByOrderAsc(communityId, position);
|
|
} else if(community != null && active != null ) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active));
|
|
} else if(community != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(before));
|
|
} else if(position != null && active != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
|
|
} else if(position != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(before));
|
|
} else if(active != null && before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
|
} else if(community != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByCommunityOrderByPlacementAscOrderAsc(communityId);
|
|
} else if(position != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
|
|
} else if(active != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
|
|
} else if(before != null) {
|
|
pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
|
|
} else {
|
|
pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
|
|
}
|
|
|
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
|
Page _page = pageController.getPage(pageHelpContent.getPage());
|
|
if(page == null || page.equals(_page.getRoute())) {
|
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
|
|
|
pageHelpContentResponse.setPage(_page);
|
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
|
}
|
|
}
|
|
return pageHelpContentResponses;
|
|
}
|
|
/*
|
|
@RequestMapping(value = "/pagehelpcontent/community/{id}", method = RequestMethod.GET)
|
|
public List<PageHelpContentResponse> getCommunityPageHelpContents(@PathVariable(value = "id") String communityId) {
|
|
List<PageHelpContent> pageHelpContents = pageHelpContentDAO.findByCommunity(communityId);
|
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
|
pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
|
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
|
}
|
|
return pageHelpContentResponses;
|
|
}
|
|
*/
|
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
|
|
public void deleteAllPageHelpContents() {
|
|
pageHelpContentDAO.deleteAll();
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/save", method = RequestMethod.POST)
|
|
public PageHelpContent insertPageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
|
String communityId = communityController.getCommunity(pageHelpContent.getCommunity()).getId();
|
|
pageHelpContent.setCommunity(communityId);
|
|
return pageHelpContentDAO.save(pageHelpContent);
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/update", method = RequestMethod.POST)
|
|
public PageHelpContent updatePageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
|
return pageHelpContentDAO.save(pageHelpContent);
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.GET)
|
|
public PageHelpContent getPageHelpContent(@PathVariable(value = "id") String id) {
|
|
return pageHelpContentDAO.findById(id);
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
|
|
public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
|
|
for (String id: pageHelpContents) {
|
|
log.debug("Id of pageHelpContent: "+id);
|
|
PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
|
|
pageHelpContent.setIsActive(Boolean.parseBoolean(status));
|
|
pageHelpContentDAO.save(pageHelpContent);
|
|
}
|
|
return pageHelpContents;
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
|
|
public void deletePageHelpContent(@PathVariable(value = "id") String id) {
|
|
pageHelpContentDAO.delete(id);
|
|
}
|
|
|
|
@RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
|
|
public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
|
|
for (String id: pageHelpContents) {
|
|
pageHelpContentDAO.delete(id);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void addPageHelpContentsInCommunity(String pid, String communityId) {
|
|
if (pid != "connect" && pid != "openaire") {
|
|
String organizations_page_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
|
|
Page organizationsPage = (pageController.getAllPages(null, "/organizations", null)).get(0);
|
|
|
|
PageHelpContent organizations_pageHelpContent = new PageHelpContent(organizationsPage.getId(), pid, "top", 1, organizations_page_content, false, false);
|
|
this.insertPageHelpContent(organizations_pageHelpContent);
|
|
|
|
String depositLearnHow_page_content = "" +
|
|
"<div class=\"uk-width-3-5 uk-align-center\"> " +
|
|
" <div class=\"uk-text-bold\">How to comply with funder Open Access policies</div> " +
|
|
" <ul class=\"uk-list uk-list-bullet\"> " +
|
|
" <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> " +
|
|
" <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> " +
|
|
" <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> " +
|
|
" <li>All OpenAIRE guides can be found <a class=\"custom-external\" href=\"https://www.openaire.eu/guides\" target=\"_blank\">here</a></li> " +
|
|
" </ul> " +
|
|
"</div>";
|
|
Page depositLearnHowPage = (pageController.getAllPages(null, "/participate/deposit/learn-how", null)).get(0);
|
|
|
|
PageHelpContent depositLearnHow_pageHelpContent = new PageHelpContent(depositLearnHowPage.getId(), pid, "bottom", 1, depositLearnHow_page_content, true, false);
|
|
this.insertPageHelpContent(depositLearnHow_pageHelpContent);
|
|
}
|
|
}
|
|
}
|
|
|
|
|