102 lines
3.7 KiB
Java
102 lines
3.7 KiB
Java
package eu.dnetlib.uoaadmintools.controllers;
|
|
|
|
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
|
import eu.dnetlib.uoaadmintools.dao.HtmlPageContentDAO;
|
|
import eu.dnetlib.uoaadmintools.dao.PageDAO;
|
|
import eu.dnetlib.uoaadmintools.entities.Community;
|
|
import eu.dnetlib.uoaadmintools.entities.HtmlPageContent;
|
|
import eu.dnetlib.uoaadmintools.entities.HtmlPageContentResponse;
|
|
import eu.dnetlib.uoaadmintools.entities.Page;
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@CrossOrigin(origins = "*")
|
|
public class HtmlPageContentController {
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
|
|
|
@Autowired
|
|
private HtmlPageContentDAO htmlPageContentDAO;
|
|
|
|
@Autowired
|
|
private PageDAO pageDAO;
|
|
|
|
@Autowired
|
|
private CommunityDAO communityDAO;
|
|
|
|
@RequestMapping(value = "/htmlpagecontent", method = RequestMethod.GET)
|
|
public List<HtmlPageContent> getHtmlPageContents(@RequestParam(required = false) String community,
|
|
@RequestParam(required = false) String page) {
|
|
List<HtmlPageContent> htmlPageContents = null;
|
|
|
|
Community _community = null;
|
|
String communityId = null;
|
|
if(community != null) {
|
|
_community = communityDAO.findByPid(community);
|
|
if(_community != null) {
|
|
communityId = _community.getId();
|
|
}
|
|
}
|
|
|
|
if(community != null) {
|
|
htmlPageContents = htmlPageContentDAO.findByCommunity(communityId);
|
|
} else {
|
|
htmlPageContents = htmlPageContentDAO.findAll();
|
|
}
|
|
|
|
Iterator<HtmlPageContent> iterator = htmlPageContents.iterator();
|
|
while(iterator.hasNext()) {
|
|
HtmlPageContent htmlPageContent = iterator.next();
|
|
|
|
Page _page = pageDAO.findById(htmlPageContent.getPage());
|
|
if (page != null && !page.equals(_page.getRoute())) {
|
|
iterator.remove();
|
|
}
|
|
}
|
|
return htmlPageContents;
|
|
}
|
|
|
|
/*
|
|
@RequestMapping(value = "/htmlpagecontent", method = RequestMethod.DELETE)
|
|
public void deleteAllHtmlPageContents() {
|
|
htmlPageContentDAO.deleteAll();
|
|
}
|
|
|
|
@RequestMapping(value = "/htmlpagecontent/save", method = RequestMethod.POST)
|
|
public HtmlPageContent insertHtmlPageContent(@RequestBody HtmlPageContent htmlPageContent) {
|
|
String communityId = communityDAO.findByPid(htmlPageContent.getCommunity()).getId();
|
|
htmlPageContent.setCommunity(communityId);
|
|
return htmlPageContentDAO.save(htmlPageContent);
|
|
}*/
|
|
|
|
@RequestMapping(value = "/htmlpagecontent/update", method = RequestMethod.POST)
|
|
public HtmlPageContent updateHtmlPageContent(@RequestBody HtmlPageContent htmlPageContent) {
|
|
return htmlPageContentDAO.save(htmlPageContent);
|
|
}
|
|
|
|
@RequestMapping(value = "/htmlpagecontent/{id}", method = RequestMethod.DELETE)
|
|
public void deleteHtmlPageContent(@PathVariable(value = "id") String id) {
|
|
htmlPageContentDAO.delete(id);
|
|
}
|
|
/*
|
|
@RequestMapping(value = "/htmlpagecontent/{id}", method = RequestMethod.GET)
|
|
public HtmlPageContent getHtmlPageContent(@PathVariable(value = "id") String id) {
|
|
return htmlPageContentDAO.findById(id);
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/htmlpagecontent/delete", method = RequestMethod.POST)
|
|
public Boolean deleteHtmlPageContents(@RequestBody List<String> htmlPageContents) throws Exception {
|
|
for (String id: htmlPageContents) {
|
|
htmlPageContentDAO.delete(id);
|
|
}
|
|
return true;
|
|
}
|
|
*/
|
|
}
|