Compare commits
13 Commits
uoa-admin-
...
master
Author | SHA1 | Date |
---|---|---|
Konstantinos Triantafyllou | 446e6fddcf | |
Konstantinos Triantafyllou | 691e78adec | |
Konstantinos Triantafyllou | b1c115ac80 | |
argirok | ecbf34057b | |
Konstantinos Triantafyllou | 76f0407f78 | |
Konstantinos Triantafyllou | a5882649a8 | |
argirok | 53edbf4b01 | |
argirok | 5bcef9ebcd | |
argirok | 4eaac0ee19 | |
Konstantinos Triantafyllou | 0c75baa89b | |
Konstantinos Triantafyllou | 4a171d647e | |
Konstantinos Triantafyllou | 0a575fbcd2 | |
Konstantinos Triantafyllou | cd59cc9ccc |
6
pom.xml
6
pom.xml
|
@ -2,7 +2,7 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>uoa-admin-tools-library</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<version>1.0.13-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>uoa-admin-tools-library</name>
|
||||
<parent>
|
||||
|
@ -12,7 +12,7 @@
|
|||
</parent>
|
||||
<scm>
|
||||
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-admin-tools-library.git</developerConnection>
|
||||
<tag>uoa-admin-tools-library-1.0.9</tag>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -34,7 +34,7 @@
|
|||
<dependency>
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>uoa-authorization-library</artifactId>
|
||||
<version>2.1.3</version>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -3,7 +3,7 @@ package eu.dnetlib.uoaadmintoolslibrary;
|
|||
import eu.dnetlib.uoaadmintoolslibrary.configuration.GlobalVars;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.configuration.properties.GoogleConfig;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.configuration.properties.MailConfig;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
|
||||
import eu.dnetlib.uoaauthorizationlibrary.configuration.IgnoreSecurityConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -12,5 +12,5 @@ import org.springframework.context.annotation.Import;
|
|||
@Configuration
|
||||
@EnableConfigurationProperties({MailConfig.class, GoogleConfig.class, GlobalVars.class})
|
||||
@ComponentScan(basePackages = { "eu.dnetlib.uoaadmintoolslibrary" })
|
||||
@Import(AuthorizationConfiguration.class)
|
||||
public class UoaAdminToolsLibraryConfiguration {}
|
||||
@Import({IgnoreSecurityConfiguration.class})
|
||||
public class UoaAdminToolsLibraryConfiguration {}
|
||||
|
|
|
@ -2,19 +2,20 @@ package eu.dnetlib.uoaadmintoolslibrary.controllers;
|
|||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.*;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.Plugin;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.ResponseHelper;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.services.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "{portalType}")
|
||||
|
@ -28,6 +29,9 @@ public class AdminPortalRelationsController {
|
|||
@Autowired
|
||||
private DivHelpContentService divHelpContentService;
|
||||
|
||||
@Autowired
|
||||
private PluginService pluginService;
|
||||
|
||||
@Autowired
|
||||
private DivIdService divIdService;
|
||||
|
||||
|
@ -127,6 +131,56 @@ public class AdminPortalRelationsController {
|
|||
return mapCount;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{pid}/pluginTemplate/page/count", method = RequestMethod.GET)
|
||||
public Map<String, Integer> countPluginTemplatesForPages(@PathVariable PortalType portalType, @PathVariable(value = "pid") String pid) {
|
||||
Map<String, Integer> mapCount = new HashMap<String, Integer>();
|
||||
|
||||
List<Page> pages = pageService.getAllPages(pid, null, null);
|
||||
for(Page page : pages){
|
||||
List<PluginTemplate> plugin = pluginService.getPluginTemplatesByPage( page.getId());
|
||||
if (plugin == null) {
|
||||
mapCount.put(page.getId(), 0);
|
||||
} else {
|
||||
mapCount.put(page.getId(), plugin.size());
|
||||
}
|
||||
}
|
||||
return mapCount;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{pid}/plugins/page/{pageId}", method = RequestMethod.GET)
|
||||
public List<Plugin> getPluginsForPage(@PathVariable PortalType portalType,@PathVariable(value = "pid") String pid, @PathVariable(value = "pageId") String pageId) {
|
||||
return pluginService.getPluginsByPage(pid, pageId);
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{pid}/pluginTemplates/page/{pageId}", method = RequestMethod.GET)
|
||||
public List<PluginTemplate> getPluginTemplatesForPages(@PathVariable PortalType portalType,@PathVariable(value = "pid") String pid, @PathVariable(value = "pageId") String pageId) {
|
||||
return pluginService.getPluginTemplatesByPage(pageId);
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{pid}/plugins/page/route", method = RequestMethod.GET)
|
||||
public List<Plugin> getPluginsForPageRoute(@PathVariable PortalType portalType, @PathVariable(value = "pid") String pid, @RequestParam(value = "route") String route, HttpServletResponse HSResponse, HttpServletRequest request) {
|
||||
Page p = pageService.getPageByPortalTypeAndRoute(portalType + "", route, pid);
|
||||
List<Plugin> response = new ArrayList<Plugin>();
|
||||
if (p != null) {
|
||||
response = pluginService.getPluginsByPage(pid, p.getId());
|
||||
}
|
||||
ResponseHelper.getCacheHeadersWithTag(response.toString(), HSResponse, request);
|
||||
return response;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{pid}/pluginTemplates/page/route", method = RequestMethod.GET)
|
||||
public List<PluginTemplate> getPluginTemplatesForPageRoute(@PathVariable PortalType portalType, @PathVariable(value = "pid") String pid,
|
||||
@RequestParam(value = "route") String route, HttpServletResponse HSResponse, HttpServletRequest request) {
|
||||
Page p = pageService.getPageByPortalTypeAndRoute(portalType + "", route, pid);
|
||||
List<PluginTemplate> response = new ArrayList<PluginTemplate>();
|
||||
if (p != null) {
|
||||
response = pluginService.getPluginTemplatesByPage(p.getId());
|
||||
}
|
||||
ResponseHelper.getCacheHeadersWithTag(response.toString(), HSResponse, request);
|
||||
return response;
|
||||
}
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
||||
|
@ -374,5 +428,4 @@ public class AdminPortalRelationsController {
|
|||
@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
|
||||
return pageHelpContentService.togglePageHelpContent(pageHelpContents, status, pid, portalType);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package eu.dnetlib.uoaadmintoolslibrary.controllers;
|
|||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalPage;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
||||
|
@ -107,11 +108,11 @@ public class PageController {
|
|||
return pageService.deletePages(pages);
|
||||
}
|
||||
|
||||
// // not used by portals
|
||||
// @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
|
||||
// public Page getPage(@PathVariable(value = "id") String id) {
|
||||
// return pageService.getPage(id);
|
||||
// }
|
||||
//used from admin - manage templates per page
|
||||
@RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
|
||||
public Page getPage(@PathVariable(value = "id") String id) {
|
||||
return pageService.getPage(id);
|
||||
}
|
||||
//
|
||||
// // not used by portals
|
||||
// @RequestMapping(value = "/page/{id}", method = RequestMethod.DELETE)
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.controllers;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.Plugin;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.services.PluginService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*")
|
||||
public class PluginController {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private PluginService pluginService;
|
||||
@Autowired
|
||||
private PageService pageService;
|
||||
// used WITHOUT ANY PARAMS
|
||||
@RequestMapping(value = "/plugins", method = RequestMethod.GET)
|
||||
public List<Plugin> getPlugins() {
|
||||
return pluginService.getPlugins(null, null, null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/plugins/template/{id}", method = RequestMethod.GET)
|
||||
public List<Plugin> getPluginsByTemplate(@PathVariable(value = "id") String id) {
|
||||
return pluginService.getPluginsByTemplateId(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pluginTemplates", method = RequestMethod.GET)
|
||||
public List<PluginTemplate> getPluginTemplates(/*@RequestParam(required = false) String page,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(value="portal", required = false) String pid*/) {
|
||||
return pluginService.getPluginTemplates(null, null, null);
|
||||
}
|
||||
@RequestMapping(value = "/pluginTemplates/page/{pageId}", method = RequestMethod.GET)
|
||||
public List<PluginTemplate> getPluginTemplatesByPage(@PathVariable(value = "pageId") String pageId) {
|
||||
return pluginService.getPluginTemplates(pageId, null, null);
|
||||
}
|
||||
@RequestMapping(value = "/pluginTemplates/{id}", method = RequestMethod.GET)
|
||||
public PluginTemplate getPluginTemplateById(@PathVariable(value = "id") String id) {
|
||||
return pluginService.getPluginTemplateById(id);
|
||||
}
|
||||
@RequestMapping(value = "/plugin/{id}", method = RequestMethod.GET)
|
||||
public Plugin getPluginById(@PathVariable(value = "id") String id) {
|
||||
return pluginService.getPluginById(id);
|
||||
}
|
||||
|
||||
// used
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community'))")
|
||||
@RequestMapping(value = "/pluginTemplate/save", method = RequestMethod.POST)
|
||||
public PluginTemplate insertTemplate(@RequestBody PluginTemplate pluginTemplate ) {
|
||||
return pluginService.savePluginTemplate(pluginTemplate);
|
||||
}
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community'))")
|
||||
@RequestMapping(value = "/pluginTemplate/save/order/{position}", method = RequestMethod.POST)
|
||||
public PluginTemplate updatePluginTemplateOrder(@RequestBody PluginTemplate pluginTemplate, @PathVariable(value = "position") Integer position ) {
|
||||
PluginTemplate pt = pluginService.getPluginTemplateById(pluginTemplate.getId());
|
||||
pt.setOrder(pt.getOrder() != null ? pt.getOrder() + position: 0 );
|
||||
return pluginService.savePluginTemplate(pt);
|
||||
}
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community')," +
|
||||
"@AuthorizationService.manager('community', #pid))")
|
||||
@RequestMapping(value = "/community/{pid}/plugin/save/order/{position}", method = RequestMethod.POST)
|
||||
public Plugin updatePluginOrder(@PathVariable String pid,@RequestBody Plugin plugin, @PathVariable(value = "position") Integer position ) {
|
||||
Plugin pl = pluginService.getPluginById(plugin.getId());
|
||||
pl.setOrder(pl.getOrder() != null ? pl.getOrder() + position: 0 );
|
||||
return pluginService.savePlugin(pl);
|
||||
}
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community')," +
|
||||
"@AuthorizationService.manager('community', #pid))")
|
||||
@RequestMapping(value = "/community/{pid}/plugin/save", method = RequestMethod.POST)
|
||||
public Plugin savePlugin(@PathVariable String pid, @RequestBody Plugin plugin ) {
|
||||
return pluginService.savePlugin(plugin);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community'))")
|
||||
@RequestMapping(value = "/community/{pid}/plugin/status/{id}", method = RequestMethod.POST)
|
||||
public Plugin updatePluginStatus(@PathVariable String pid, @PathVariable(value = "id") String id, @RequestBody String status ) {
|
||||
return pluginService.updatePluginStatus(id,status);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pluginTemplate/page/count", method = RequestMethod.GET)
|
||||
public Map<String, Integer> countPluginTemplatesForPages() {
|
||||
Map<String, Integer> mapCount = new HashMap<String, Integer>();
|
||||
|
||||
List<Page> pages = pageService.getAllPages(null, null, null);
|
||||
for(Page page : pages){
|
||||
List<PluginTemplate> plugin = pluginService.getPluginTemplatesByPage( page.getId());
|
||||
if (plugin == null) {
|
||||
mapCount.put(page.getId(), 0);
|
||||
} else {
|
||||
mapCount.put(page.getId(), plugin.size());
|
||||
}
|
||||
}
|
||||
return mapCount;
|
||||
}
|
||||
|
||||
// not used by portals
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community'))")
|
||||
@RequestMapping(value = "/pluginTemplate/{id}", method = RequestMethod.DELETE)
|
||||
public void deletePluginTemplate(@PathVariable(value = "id") String id) {
|
||||
pluginService.deletePluginTemplate(id);
|
||||
}
|
||||
// not used by portals
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator('community'))")
|
||||
@RequestMapping(value = "/plugin/{id}", method = RequestMethod.DELETE)
|
||||
public void deletePlugin(@PathVariable(value = "id") String id) {
|
||||
pluginService.deletePlugin(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/plugin/template/count", method = RequestMethod.GET)
|
||||
public Map<String, Integer> countPluginsByTemplate() {
|
||||
Map<String, Integer> mapCount = new HashMap<String, Integer>();
|
||||
|
||||
List<PluginTemplate> templates = pluginService.getPluginTemplates(null,null,null);
|
||||
for(PluginTemplate template: templates){
|
||||
List<Plugin> plugins = pluginService.getPluginsByTemplateId(template.getId());
|
||||
if (plugins == null) {
|
||||
mapCount.put(template.getId(), 0);
|
||||
} else {
|
||||
mapCount.put(template.getId(), plugins.size());
|
||||
}
|
||||
}
|
||||
return mapCount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.dao.MongoDBDAOs;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PluginDAO;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.Plugin;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MongoDBPluginDAO extends PluginDAO, MongoRepository<Plugin, String> {
|
||||
Plugin findById(String Id);
|
||||
|
||||
List<Plugin> findAll();
|
||||
List<Plugin> findByPage(String page);
|
||||
List<Plugin> findByPageAndPid(String page, String pid);
|
||||
List<Plugin> findByTemplateId(String templateId);
|
||||
Plugin save(Plugin plugin);
|
||||
void deleteAll();
|
||||
void delete(String id);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.dao.MongoDBDAOs;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.dao.DivIdDAO;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PluginTemplateDAO;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MongoDBPluginTemplateDAO extends PluginTemplateDAO, MongoRepository<PluginTemplate, String> {
|
||||
PluginTemplate findById(String Id);
|
||||
PluginTemplate findByCode(String code);
|
||||
List<PluginTemplate> findAll();
|
||||
@Query("{ pages: ?0 }")
|
||||
List<PluginTemplate> findByPages(String page);
|
||||
PluginTemplate save(PluginTemplate pluginTemplate);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
void delete(String id);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.dao;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PluginDAO {
|
||||
Plugin findById(String Id);
|
||||
|
||||
List<Plugin> findAll();
|
||||
List<Plugin> findByPage(String page);
|
||||
List<Plugin> findByPageAndPid(String page, String pid);
|
||||
List<Plugin> findByTemplateId(String templateId);
|
||||
Plugin save(Plugin plugin);
|
||||
void deleteAll();
|
||||
void delete(String id);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.dao;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import java.util.List;
|
||||
|
||||
public interface PluginTemplateDAO {
|
||||
PluginTemplate findById(String Id);
|
||||
List<PluginTemplate> findAll();
|
||||
List<PluginTemplate> findByPage(String page);
|
||||
PluginTemplate save(PluginTemplate pluginTemplate);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
void delete(String id);
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.entities.plugin;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Plugin {
|
||||
@Id
|
||||
@JsonProperty("_id")
|
||||
private String id;
|
||||
private String pid;
|
||||
private String templateCode;
|
||||
private String templateId;
|
||||
private String page;
|
||||
private String placement;
|
||||
private Integer order;
|
||||
private Boolean isActive = true;
|
||||
private Boolean isCustom = true;
|
||||
private Map<String,String> settingsValues = new HashMap<>();
|
||||
private Object object;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getTemplateCode() {
|
||||
|
||||
|
||||
return templateCode;
|
||||
}
|
||||
|
||||
public void setTemplateCode(String templateCode) {
|
||||
this.templateCode = templateCode;
|
||||
}
|
||||
|
||||
public String getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public void setTemplateId(String templateId) {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(String page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public String getPlacement() {
|
||||
return placement;
|
||||
}
|
||||
|
||||
public void setPlacement(String placement) {
|
||||
this.placement = placement;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Boolean getActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setActive(Boolean active) {
|
||||
isActive = active;
|
||||
}
|
||||
|
||||
public Map<String, String> getSettingsValues() {
|
||||
return settingsValues;
|
||||
}
|
||||
|
||||
public void setSettingsValues(Map<String, String> settingsValues) {
|
||||
this.settingsValues = settingsValues;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public Boolean getCustom() {
|
||||
return isCustom;
|
||||
}
|
||||
|
||||
public void setCustom(Boolean custom) {
|
||||
isCustom = custom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Plugin{" +
|
||||
"id='" + id + '\'' +
|
||||
", pid='" + pid + '\'' +
|
||||
", templateCode='" + templateCode + '\'' +
|
||||
", templateId='" + templateId + '\'' +
|
||||
", page='" + page + '\'' +
|
||||
", placement='" + placement + '\'' +
|
||||
", order=" + order +
|
||||
", isActive=" + isActive +
|
||||
", isCustom=" + isCustom +
|
||||
", settingsValues=" + settingsValues +
|
||||
", object=" + object +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.entities.plugin;
|
||||
|
||||
public class PluginAttributes {
|
||||
String name;
|
||||
String type;
|
||||
String value;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.entities.plugin;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PluginTemplate {
|
||||
|
||||
@Id
|
||||
@JsonProperty("_id")
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String code;
|
||||
private Boolean custom;
|
||||
private String image;
|
||||
private String page;
|
||||
private String placement;
|
||||
private Integer order;
|
||||
private PortalType portalType; // explore, connect, community, monitor
|
||||
private String plan; // e.g basic, ultimate, etc for paid communities
|
||||
private Boolean defaultIsActive;
|
||||
private ArrayList<String> portalSpecific = new ArrayList<>();
|
||||
private Map<String,PluginAttributes> settings = new HashMap<>();
|
||||
private Object object;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public PortalType getPortalType() {
|
||||
return portalType;
|
||||
}
|
||||
|
||||
public void setPortalType(PortalType portalType) {
|
||||
this.portalType = portalType;
|
||||
}
|
||||
|
||||
public String getPlan() {
|
||||
return plan;
|
||||
}
|
||||
|
||||
public void setPlan(String plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public Map<String, PluginAttributes> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setSettings(Map<String, PluginAttributes> settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
|
||||
public Integer getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(String page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public String getPlacement() {
|
||||
return placement;
|
||||
}
|
||||
|
||||
public void setPlacement(String placement) {
|
||||
this.placement = placement;
|
||||
}
|
||||
|
||||
public ArrayList<String> getPortalSpecific() {
|
||||
return portalSpecific;
|
||||
}
|
||||
|
||||
public void setPortalSpecific(ArrayList<String> portalSpecific) {
|
||||
this.portalSpecific = portalSpecific;
|
||||
}
|
||||
|
||||
public Boolean getDefaultIsActive() {
|
||||
return defaultIsActive;
|
||||
}
|
||||
|
||||
public void setDefaultIsActive(Boolean defaultIsActive) {
|
||||
this.defaultIsActive = defaultIsActive;
|
||||
}
|
||||
|
||||
public Boolean getCustom() {
|
||||
return custom;
|
||||
}
|
||||
|
||||
public void setCustom(Boolean custom) {
|
||||
this.custom = custom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PluginTemplate{" +
|
||||
"id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", code='" + code + '\'' +
|
||||
", custom=" + custom +
|
||||
", image='" + image + '\'' +
|
||||
", page='" + page + '\'' +
|
||||
", placement='" + placement + '\'' +
|
||||
", order=" + order +
|
||||
", portalType=" + portalType +
|
||||
", plan='" + plan + '\'' +
|
||||
", defaultIsActive=" + defaultIsActive +
|
||||
", portalSpecific=" + portalSpecific +
|
||||
", settings=" + settings +
|
||||
", object=" + object +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setStatus(HttpStatus.BAD_REQUEST);
|
||||
log.error("invalidInput exception");
|
||||
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MismatchingContentException.class)
|
||||
|
@ -35,7 +35,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.BAD_REQUEST);
|
||||
log.error("mismatchingContent exception: " + response.getErrorCode()+ " "+response.getErrorMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(ContentNotFoundException.class)
|
||||
|
@ -46,7 +46,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.NOT_FOUND);
|
||||
log.error("contentNotFound exception: " + response.getErrorCode()+ " - "+response.getErrorMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler(NullPointerException.class)
|
||||
|
@ -57,7 +57,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.BAD_REQUEST);
|
||||
log.error("nullPointerException exception" + response.getErrorCode()+ " - "+response.getErrorMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(InvalidReCaptchaException.class)
|
||||
|
@ -68,7 +68,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.BAD_REQUEST);
|
||||
log.error("invalidReCaptchaException exception");
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,7 +80,18 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.NOT_FOUND);
|
||||
log.error("notFoundException exception : "+ ex.getMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler(UnauthorizedException.class)
|
||||
public ResponseEntity<ExceptionResponse> unauthorizedException(Exception ex) {
|
||||
ExceptionResponse response = new ExceptionResponse();
|
||||
response.setErrorCode("Unauthorized Exception");
|
||||
response.setErrorMessage("Unauthorized Exception");
|
||||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED);
|
||||
log.error("Unauthorized exception: "+ ex.getMessage());
|
||||
return new ResponseEntity<>(response, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@ExceptionHandler(ForbiddenException.class)
|
||||
|
@ -91,7 +102,7 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.FORBIDDEN);
|
||||
log.error("forbiddenException exception: "+ ex.getMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.FORBIDDEN);
|
||||
return new ResponseEntity<>(response, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
@ExceptionHandler(DuplicateKeyException.class)
|
||||
|
@ -102,6 +113,6 @@ public class AdminToolsLibraryExceptionsHandler {
|
|||
response.setErrors(ex.getMessage());
|
||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
log.error("duplicateKeyException exception: "+ ex.getMessage());
|
||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.handlers;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
public class UnauthorizedException extends RuntimeException {
|
||||
public UnauthorizedException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.handlers.utils;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class ResponseHelper {
|
||||
|
||||
public static String generateETag(String content) {
|
||||
// Generate a unique hash based on the content
|
||||
String hash = DigestUtils.md5DigestAsHex(content.getBytes());
|
||||
return "\"" + hash + "\""; // ETag format: "hash_value"
|
||||
}
|
||||
|
||||
public static HttpHeaders getCacheHeadersWithTag(String response, Date date){
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setETag(ResponseHelper.generateETag(response));
|
||||
headers.setCacheControl("max-age=3600");
|
||||
if(date != null) {
|
||||
headers.setLastModified(date.getTime());
|
||||
}
|
||||
Date now = new Date();
|
||||
headers.setExpires(now.getTime() + 3600000);
|
||||
headers.setExpires(now.getTime() + 7200000);
|
||||
return headers;
|
||||
}
|
||||
public static void getCacheHeadersWithTag(String response, HttpServletResponse HSResponse, HttpServletRequest request){
|
||||
String tag = ResponseHelper.generateETag(response.toString());
|
||||
String ifMatchHeader = request.getHeader("If-Match");
|
||||
if (ifMatchHeader != null && ifMatchHeader.equals(tag)) {
|
||||
HSResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
} else {
|
||||
|
||||
Date now = new Date();
|
||||
now.setTime(now.getTime() + 3600000);
|
||||
HSResponse.setHeader("ETag",tag);
|
||||
HSResponse.setHeader("Cache-Control","no-cache, max-age=3600");
|
||||
HSResponse.setHeader("Expires",ResponseHelper.getvalidHeaderDateFormat(now));
|
||||
//TODO need to set proper date
|
||||
// HSResponse.setHeader("Last-Modified", ResponseHelper.getvalidHeaderDateFormat(new Date(1640995200000L)));
|
||||
}
|
||||
}
|
||||
public static void getCacheHeadersWithTag( String tag, HttpServletResponse HSResponse){
|
||||
Date now = new Date();
|
||||
now.setTime(now.getTime() + 3600000);
|
||||
HSResponse.setHeader("ETag",tag);
|
||||
HSResponse.setHeader("Cache-Control","no-cache, max-age=3600");
|
||||
HSResponse.setHeader("Expires",ResponseHelper.getvalidHeaderDateFormat(now));
|
||||
HSResponse.setHeader("Last-Modified", ResponseHelper.getvalidHeaderDateFormat(new Date(1640995200000L)));
|
||||
|
||||
}
|
||||
public static String getvalidHeaderDateFormat(Date date){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return dateFormat.format(date);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package eu.dnetlib.uoaadmintoolslibrary.services;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PluginDAO;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PluginTemplateDAO;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.Plugin;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.plugin.PluginTemplate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PluginService {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private PluginTemplateDAO pluginTemplateDAO;
|
||||
|
||||
@Autowired
|
||||
private PluginDAO pluginDAO;
|
||||
|
||||
public List<PluginTemplate> getPluginTemplates(String page, String name, String pid) {
|
||||
List<PluginTemplate> templates;
|
||||
if(page != null){
|
||||
templates = this.pluginTemplateDAO.findByPage(page);
|
||||
}else {
|
||||
templates = this.pluginTemplateDAO.findAll();
|
||||
}
|
||||
templates.sort(Comparator.comparingInt(PluginTemplate::getOrder));
|
||||
return templates;
|
||||
}
|
||||
|
||||
public List<Plugin> getPlugins(String page, String name, String pid) {
|
||||
return this.pluginDAO.findAll();
|
||||
}
|
||||
public Plugin getPluginById(String id) {
|
||||
return this.pluginDAO.findById(id);
|
||||
|
||||
}
|
||||
public PluginTemplate getPluginTemplateById(String id) {
|
||||
return this.pluginTemplateDAO.findById(id);
|
||||
|
||||
}
|
||||
public List<Plugin> getPluginsByTemplateId(String id) {
|
||||
return this.pluginDAO.findByTemplateId(id);
|
||||
}
|
||||
|
||||
public List<PluginTemplate> getPluginTemplatesByPage(String pageId) {
|
||||
ArrayList<String> pages = new ArrayList<String>();
|
||||
pages.add(pageId);
|
||||
List<PluginTemplate> templates = this.pluginTemplateDAO.findByPage(pageId);
|
||||
templates.sort(Comparator.comparingInt(PluginTemplate::getOrder));
|
||||
return templates;
|
||||
|
||||
}
|
||||
public List<Plugin> getPluginsByPage(String pid, String pageId) {
|
||||
ArrayList<String> pages = new ArrayList<String>();
|
||||
pages.add(pageId);
|
||||
return this.pluginDAO.findByPageAndPid(pageId,pid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PluginTemplate savePluginTemplate(PluginTemplate pluginTemplate) {
|
||||
return this.pluginTemplateDAO.save(pluginTemplate);
|
||||
}
|
||||
public Plugin savePlugin(Plugin plugin) {
|
||||
return this.pluginDAO.save(plugin);
|
||||
}
|
||||
|
||||
public Plugin updatePluginStatus(String id, String status) {
|
||||
Plugin plugin = this.pluginDAO.findById(id);
|
||||
if(plugin != null) {
|
||||
plugin.setActive(Boolean.parseBoolean(status));
|
||||
}
|
||||
return this.pluginDAO.save(plugin);
|
||||
}
|
||||
|
||||
|
||||
public void deletePluginTemplate(String id) {
|
||||
pluginTemplateDAO.delete(id);
|
||||
List <Plugin> plugins = pluginDAO.findByTemplateId(id);
|
||||
for(Plugin p: plugins){
|
||||
pluginDAO.delete(p.getId());
|
||||
}
|
||||
|
||||
}
|
||||
public void deletePlugin(String id) {
|
||||
pluginDAO.delete(id);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue