Merge from springboot3
This commit is contained in:
commit
bb27d58c27
|
@ -0,0 +1,31 @@
|
||||||
|
# UOA Admin Tools
|
||||||
|
|
||||||
|
This service provides method in order to save portal related configuration,
|
||||||
|
such as pages, plugins, entities etc. Also, it handles the machine cache for each portal
|
||||||
|
and expose managers information through an external service.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
- Check [Admin Tools Library](https://code-repo.d4science.org/MaDgIK/uoa-admin-tools-library)
|
||||||
|
|
||||||
|
### Mongo Configuration
|
||||||
|
|
||||||
|
admin-tools.mongodb.host # Required - Host of mongo server - Default: localhost
|
||||||
|
admin-tools.mongodb.database # Required - Database name
|
||||||
|
admin-tools.mongodb.username # Optional - Username if needed
|
||||||
|
admin-tools.mongodb.password # Optional - Password if needed
|
||||||
|
admin-tools.mongodb.port # Required - Mongo server port - Default: 27017
|
||||||
|
|
||||||
|
### Managers Configuration
|
||||||
|
|
||||||
|
admin-tools.managers.id # Required - External service URL to get OpenAIRE IDs of users that are managers of a portal.
|
||||||
|
admin-tools.managers.email # Required - External service URL to get emails of users that are managers of a portal.
|
||||||
|
|
||||||
|
|
||||||
|
### Cache Configuration
|
||||||
|
|
||||||
|
admin-tools.cache # Required - URL of machine cache.
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
Check [Spring boot Documentation](https://code-repo.d4science.org/MaDgIK/Documentation/wiki/Spring-boot) (need Login)
|
|
@ -1,38 +0,0 @@
|
||||||
!!!!Check the following for the override properties port
|
|
||||||
|
|
||||||
src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java
|
|
||||||
|
|
||||||
|
|
||||||
!! properties here cannot be overwritten in dnet-override.properties
|
|
||||||
src/main/resources/application.properties
|
|
||||||
|
|
||||||
!!Check dnet-override.properties that have override the properties from:
|
|
||||||
|
|
||||||
src/main/resources/admintools.properties
|
|
||||||
|
|
||||||
|
|
||||||
**DEV NEW 05-07-2019**
|
|
||||||
Replace admintool with admintool.mail on dnet-override properties
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
***BETA***
|
|
||||||
PORT: 8380
|
|
||||||
logs: /var/log/dnet/uoa-admin-tools/
|
|
||||||
|
|
||||||
#spring.data.mongodb.host=beta.services.openaire.eu
|
|
||||||
#spring.data.mongodb.port=27017
|
|
||||||
#spring.data.mongodb.database=openaireconnect
|
|
||||||
|
|
||||||
|
|
||||||
***Production***
|
|
||||||
|
|
||||||
PORT: 8480
|
|
||||||
logs: /var/log/dnet/uoa-admin-tools/
|
|
||||||
|
|
||||||
#spring.data.mongodb.host=services.openaire.eu
|
|
||||||
#spring.data.mongodb.port=27017
|
|
||||||
#spring.data.mongodb.database=openaireconnect
|
|
||||||
#spring.data.mongodb.username=dnet8480
|
|
||||||
#spring.data.mongodb.password=...
|
|
||||||
|
|
87
pom.xml
87
pom.xml
|
@ -1,85 +1,52 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>uoa-admin-tools</artifactId>
|
<parent>
|
||||||
<version>2.1.4-BETA-SNAPSHOT</version>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<packaging>war</packaging>
|
<artifactId>uoa-spring-boot-parent</artifactId>
|
||||||
<name>uoa-admin-tools</name>
|
<version>2.0.3</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>uoa-admin-tools</artifactId>
|
||||||
|
<version>3.0.0-BETA-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>uoa-admin-tools</name>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-admin-tools.git</developerConnection>
|
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-admin-tools.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<parent>
|
<properties>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<artifactId>uoa-spring-boot-parent</artifactId>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<version>1.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<timestamp>${maven.build.timestamp}</timestamp>
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
<maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
|
<maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.mail</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>mail</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
<version>1.5.0-b01</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>commons-io</groupId>-->
|
|
||||||
<!-- <artifactId>commons-io</artifactId>-->
|
|
||||||
<!-- <version>20030203.000550</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
|
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-admin-tools-library</artifactId>
|
<artifactId>uoa-admin-tools-library</artifactId>
|
||||||
<version>1.0.13</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
|
||||||
<!--swagger-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
|
||||||
<version>${swagger-version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--swagger official ui-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger-version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>${spring-boot-version}</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>eu.dnetlib.uoaadmintools.UoaAdminToolsApplication</mainClass>
|
<mainClass>eu.dnetlib.uoaadmintools.UoaAdminToolsApplication</mainClass>
|
||||||
<executable>true</executable>
|
<executable>true</executable>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.6</version>
|
|
||||||
<configuration>
|
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<finalName>uoa-admin-tools</finalName>
|
<finalName>uoa-admin-tools</finalName>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.dnetlib.uoaadmintools;
|
package eu.dnetlib.uoaadmintools;
|
||||||
|
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
public class ServletInitializer extends SpringBootServletInitializer {
|
public class ServletInitializer extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
package eu.dnetlib.uoaadmintools;
|
package eu.dnetlib.uoaadmintools;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.GlobalVars;
|
import eu.dnetlib.uoaadmintools.configuration.GlobalVars;
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.APIProperties;
|
import eu.dnetlib.uoaadmintools.configuration.properties.Properties;
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
|
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
|
||||||
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
|
import eu.dnetlib.uoaauthorizationlibrary.SecurityConfiguration;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.context.annotation.PropertySources;
|
import org.springframework.context.annotation.PropertySources;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools"})
|
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools"})
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
|
@ -25,20 +18,11 @@ import org.springframework.web.client.RestTemplate;
|
||||||
@PropertySource("classpath:admintools.properties"),
|
@PropertySource("classpath:admintools.properties"),
|
||||||
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
||||||
})
|
})
|
||||||
@EnableConfigurationProperties({MongoConfig.class, ManagersApiConfig.class, BrowserCacheConfig.class, GlobalVars.class, APIProperties.class})
|
@EnableConfigurationProperties({Properties.class, GlobalVars.class})
|
||||||
@Import({AuthorizationConfiguration.class, UoaAdminToolsLibraryConfiguration.class})
|
@Import({SecurityConfiguration.class, UoaAdminToolsLibraryConfiguration.class})
|
||||||
public class UoaAdminToolsApplication {
|
public class UoaAdminToolsApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(UoaAdminToolsApplication.class, args);
|
SpringApplication.run(UoaAdminToolsApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
RestTemplate restTemplate() {
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
||||||
converter.setObjectMapper(new ObjectMapper());
|
|
||||||
restTemplate.getMessageConverters().add(converter);
|
|
||||||
return restTemplate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ConfigurationProperties("admintool.globalVars")
|
@ConfigurationProperties("admin-tools.global-vars")
|
||||||
public class GlobalVars {
|
public class GlobalVars {
|
||||||
public static Date date = new Date();
|
public static Date date = new Date();
|
||||||
private Date buildDate;
|
private Date buildDate;
|
||||||
|
|
|
@ -1,108 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.APIProperties;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.ParameterBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.schema.ModelRef;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Parameter;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swagger configuration class
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@Profile({"swagger"})
|
|
||||||
@EnableSwagger2
|
|
||||||
public class SwaggerConfig extends WebMvcConfigurerAdapter {
|
|
||||||
|
|
||||||
private final APIProperties apiProperties;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SwaggerConfig(APIProperties apiProperties) {
|
|
||||||
this.apiProperties = apiProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
// .globalOperationParameters(globalParameterList())
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaadmintools.controllers"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApiLibrary() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
// .globalOperationParameters(globalParameterList())
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.groupName("Library")
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaadmintoolslibrary.controllers"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApiAuthorizationLibrary() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.groupName("Authorization Library")
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaauthorizationlibrary.controllers"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title(this.apiProperties.getTitle())
|
|
||||||
.description(this.apiProperties.getDescription())
|
|
||||||
.version(this.apiProperties.getVersion())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Parameter> globalParameterList() {
|
|
||||||
Parameter authTokenHeader = new ParameterBuilder()
|
|
||||||
.name("Session") // name of the header
|
|
||||||
.modelRef(new ModelRef("string")) // data-type of the header
|
|
||||||
.required(false)
|
|
||||||
.parameterType("header")
|
|
||||||
.description("Session ID")
|
|
||||||
.build();
|
|
||||||
return Collections.singletonList(authTokenHeader);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
|
||||||
registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs");
|
|
||||||
registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
|
|
||||||
registry.addRedirectViewController("/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
|
|
||||||
registry.addRedirectViewController("/swagger-resources", "/swagger-resources");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
registry.addResourceHandler("/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
|
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration.mongo;
|
package eu.dnetlib.uoaadmintools.configuration.mongo;
|
||||||
|
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClientSettings;
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig;
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Mongodb;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Properties;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
|
||||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -19,28 +20,29 @@ import java.util.Collections;
|
||||||
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoaadmintools.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"})
|
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoaadmintools.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"})
|
||||||
public class MongoConnection {
|
public class MongoConnection {
|
||||||
|
|
||||||
@Autowired
|
private final Mongodb config;
|
||||||
private MongoConfig mongoConfig;
|
|
||||||
|
|
||||||
@Bean
|
@Autowired
|
||||||
@Primary
|
public MongoConnection(Properties properties) {
|
||||||
public MongoDbFactory mongoDbFactory() {
|
this.config = properties.getMongodb();
|
||||||
return new SimpleMongoDbFactory(getMongoClient(), mongoConfig.getDatabase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "mongoTemplate")
|
@Bean(name = "mongoTemplate")
|
||||||
@Primary
|
|
||||||
public MongoTemplate getMongoTemplate() {
|
public MongoTemplate getMongoTemplate() {
|
||||||
return new MongoTemplate(mongoDbFactory());
|
return new MongoTemplate(getMongoClient(), config.getDatabase());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MongoClient getMongoClient() {
|
private MongoClient getMongoClient() {
|
||||||
if(mongoConfig.getUsername() != null && mongoConfig.getPassword() != null){
|
MongoClientSettings.Builder builder = MongoClientSettings.builder()
|
||||||
return new MongoClient(Collections.singletonList(
|
.applyToClusterSettings(b -> b.hosts(Collections.singletonList(new ServerAddress(config.getHost(), config.getPort()))));
|
||||||
new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort())),
|
if(config.getUsername() != null && config.getPassword() != null) {
|
||||||
Collections.singletonList(MongoCredential.createCredential(mongoConfig.getUsername(), mongoConfig.getDatabase(), mongoConfig.getPassword().toCharArray())));
|
MongoCredential credential = MongoCredential.createCredential(
|
||||||
} else {
|
config.getUsername(),
|
||||||
return new MongoClient(Collections.singletonList(new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort())));
|
config.getDatabase(),
|
||||||
|
config.getPassword().toCharArray()
|
||||||
|
);
|
||||||
|
builder.credential(credential);
|
||||||
}
|
}
|
||||||
|
return MongoClients.create(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration.properties;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
@ConfigurationProperties("api")
|
|
||||||
public class APIProperties {
|
|
||||||
|
|
||||||
private String title;
|
|
||||||
private String description;
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
public APIProperties() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration.properties;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
@ConfigurationProperties("admintool.cache")
|
|
||||||
public class BrowserCacheConfig {
|
|
||||||
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,6 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration.properties;
|
package eu.dnetlib.uoaadmintools.configuration.properties;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
public class Managers {
|
||||||
|
|
||||||
@ConfigurationProperties("admintool.managers.api")
|
|
||||||
public class ManagersApiConfig {
|
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String email;
|
private String email;
|
|
@ -1,9 +1,6 @@
|
||||||
package eu.dnetlib.uoaadmintools.configuration.properties;
|
package eu.dnetlib.uoaadmintools.configuration.properties;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
public class Mongodb {
|
||||||
|
|
||||||
@ConfigurationProperties("admintool.mongodb")
|
|
||||||
public class MongoConfig {
|
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private String database;
|
private String database;
|
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.dnetlib.uoaadmintools.configuration.properties;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties("admin-tools")
|
||||||
|
public class Properties {
|
||||||
|
private String cache;
|
||||||
|
private Mongodb mongodb = new Mongodb();
|
||||||
|
private Managers managers = new Managers();
|
||||||
|
|
||||||
|
public String getCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCache(String cache) {
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mongodb getMongodb() {
|
||||||
|
return mongodb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMongodb(Mongodb mongodb) {
|
||||||
|
this.mongodb = mongodb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Managers getManagers() {
|
||||||
|
return managers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManagers(Managers managers) {
|
||||||
|
this.managers = managers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,48 +1,29 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
import eu.dnetlib.uoaadmintools.services.AdminToolsDeployService;
|
||||||
import com.mongodb.CommandResult;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.GlobalVars;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.mongo.MongoConnection;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class AdminToolsCheckDeployController {
|
public class AdminToolsCheckDeployController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final AdminToolsDeployService service;
|
||||||
private MongoConnection mongoConnection;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MongoConfig mongoConfig;
|
public AdminToolsCheckDeployController(AdminToolsDeployService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET)
|
||||||
private ManagersApiConfig managersApiConfig;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BrowserCacheConfig browserCacheConfig;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GlobalVars globalVars;
|
|
||||||
|
|
||||||
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
|
||||||
public String hello() {
|
public String hello() {
|
||||||
log.debug("Hello from uoa-admin-tools!");
|
log.debug("Hello from uoa-admin-tools!");
|
||||||
return "Hello from uoa-admin-tools!";
|
return "Hello from uoa-admin-tools!";
|
||||||
|
@ -51,39 +32,6 @@ public class AdminToolsCheckDeployController {
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||||
public Map<String, String> checkEverything() {
|
public Map<String, String> checkEverything() {
|
||||||
Map<String, String> response = new HashMap<>();
|
return this.service.getProperties();
|
||||||
|
|
||||||
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
|
||||||
DBObject ping = new BasicDBObject("ping", "1");
|
|
||||||
try {
|
|
||||||
CommandResult answer = mt.getDb().command(ping);
|
|
||||||
response.put("Mongo try: error", answer.getErrorMessage());
|
|
||||||
} catch (Exception e) {
|
|
||||||
response.put("Mongo catch: error", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.put("admintool.mongodb.database", mongoConfig.getDatabase());
|
|
||||||
response.put("admintool.mongodb.host", mongoConfig.getHost());
|
|
||||||
response.put("admintool.mongodb.port", mongoConfig.getPort()+"");
|
|
||||||
response.put("admintool.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
|
|
||||||
response.put("admintool.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
|
|
||||||
// response.put("Define also", "admintool.mongodb.username, admintool.mongodb.password");
|
|
||||||
|
|
||||||
response.put("admintool.managers.api.id", managersApiConfig.getId());
|
|
||||||
response.put("admintool.managers.api.email", managersApiConfig.getEmail());
|
|
||||||
|
|
||||||
response.put("admintool.cache.url", browserCacheConfig.getUrl());
|
|
||||||
|
|
||||||
if(globalVars.date != null) {
|
|
||||||
response.put("Date of deploy", globalVars.date.toString());
|
|
||||||
}
|
|
||||||
if(globalVars.getBuildDate() != null) {
|
|
||||||
response.put("Date of build", globalVars.getBuildDate());
|
|
||||||
}
|
|
||||||
if(globalVars.getVersion() != null) {
|
|
||||||
response.put("Version", globalVars.getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,34 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
|
import eu.dnetlib.uoaadmintools.configuration.properties.Properties;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/cache")
|
@RequestMapping("/cache")
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class BrowserCacheController {
|
public class BrowserCacheController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final RestTemplate restTemplate;
|
||||||
private RestTemplate restTemplate;
|
private final String cache;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BrowserCacheConfig config;
|
public BrowserCacheController(RestTemplate restTemplate, Properties properties) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
this.cache = properties.getCache();
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/{pid}", method = RequestMethod.GET)
|
@RequestMapping(value = "/{pid}", method = RequestMethod.GET)
|
||||||
public boolean purge(@PathVariable(value = "pid") String pid) {
|
public ResponseEntity<Boolean> purge(@PathVariable(value = "pid") String pid) {
|
||||||
// try {
|
restTemplate.getForEntity(cache.replace("{community}", pid), String.class);
|
||||||
restTemplate.getForEntity(config.getUrl().replace("{community}", pid), String.class);
|
return ResponseEntity.ok(true);
|
||||||
// } catch(HttpClientErrorException httpClientErrorException) {
|
|
||||||
// log.debug("Purge browser cache: HttpClientErrorException for "+pid + " - code: " + httpClientErrorException.getStatusCode());
|
|
||||||
// return false;
|
|
||||||
// } catch(ResourceAccessException resourceAccessException) {
|
|
||||||
// log.debug("Purge browser cache: ResourceAccessException for "+pid);
|
|
||||||
// return false;
|
|
||||||
// } catch(Exception exception) {
|
|
||||||
// log.debug("Purge browser cache: " + exception.getClass() + " for "+pid);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
import eu.dnetlib.uoaadmintools.services.*;
|
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
||||||
|
import eu.dnetlib.uoaadmintools.services.MenuService;
|
||||||
|
import eu.dnetlib.uoaadmintools.services.NotificationsService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.utils.MismatchingContentException;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -19,167 +22,117 @@ import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/community")
|
@RequestMapping("/community")
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class CommunityController {
|
public class CommunityController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final LayoutService layoutService;
|
||||||
private RolesUtils rolesUtils;
|
private final NotificationsService notificationsService;
|
||||||
|
private final MenuService menuService;
|
||||||
@Autowired
|
|
||||||
private LayoutService layoutService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NotificationsService notificationsService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StatisticsService statisticsService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SubscriberService subscriberService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MenuService menuService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortalService portalService;
|
private PortalService portalService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PageService pageService;
|
private PageService pageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CommunityController(LayoutService layoutService, NotificationsService notificationsService, MenuService menuService) {
|
||||||
|
this.layoutService = layoutService;
|
||||||
|
this.notificationsService = notificationsService;
|
||||||
|
this.menuService = menuService;
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = {""}, method = RequestMethod.GET)
|
@RequestMapping(value = {""}, method = RequestMethod.GET)
|
||||||
public List<Portal> getAllCommunities() {
|
public ResponseEntity<List<Portal>> getAllCommunities() {
|
||||||
return portalService.getAllPortalsByType("community");
|
return ResponseEntity.ok(portalService.getAllPortalsByType("community"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = {"/full"}, method = RequestMethod.GET)
|
@RequestMapping(value = {"/full"}, method = RequestMethod.GET)
|
||||||
public List<PortalResponse> getAllCommunitiesFull() {
|
public ResponseEntity<List<PortalResponse>> getAllCommunitiesFull() {
|
||||||
return portalService.getAllPortalsFullByType("community");
|
return ResponseEntity.ok(portalService.getAllPortalsFullByType("community"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
public PortalResponse updateCommunity(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> updateCommunity(@RequestBody Portal portal) {
|
||||||
if(!portal.getType().equals("community")) {
|
if (!portal.getType().equals("community")) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("Update Community: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of community");
|
||||||
throw new MismatchingContentException("Update Community: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
||||||
String new_pid = portal.getPid();
|
|
||||||
|
|
||||||
PortalResponse portalResponse = portalService.updatePortal(portal);
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
||||||
|
if (!old_pid.equals(portal.getPid())) {
|
||||||
if(!old_pid.equals(new_pid)) {
|
log.debug("update portal pid - old: " + old_pid + " - new: " + portal.getPid());
|
||||||
log.debug("update portal pid - old: "+old_pid + " - new: "+new_pid);
|
layoutService.updatePid(old_pid, portal);
|
||||||
statisticsService.updatePid(old_pid, new_pid);
|
notificationsService.updatePid(old_pid, portal);
|
||||||
subscriberService.updatePid(old_pid, new_pid);
|
menuService.updatePid(old_pid, portal);
|
||||||
layoutService.updatePid(old_pid, new_pid);
|
pageService.updatePid(old_pid, portal);
|
||||||
notificationsService.updatePid(old_pid, new_pid);
|
|
||||||
menuService.updatePid(old_pid, new_pid);
|
|
||||||
pageService.updatePid(old_pid, new_pid, portal.getType());
|
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(portalResponse);
|
||||||
return portalResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
public PortalResponse insertCommunity(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> insertCommunity(@RequestBody Portal portal) {
|
||||||
if(!portal.getType().equals("community")) {
|
if (!portal.getType().equals("community")) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("Save Community: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of community");
|
||||||
throw new MismatchingContentException("Save Community: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(portalService.insertPortal(portal));
|
||||||
PortalResponse portalResponse = portalService.insertPortal(portal);
|
|
||||||
|
|
||||||
statisticsService.createPortalStatistics(portal.getPid());
|
|
||||||
subscriberService.createPortalSubscribers(portal.getPid());
|
|
||||||
|
|
||||||
return portalResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
public Boolean deleteCommunities(@RequestBody List<String> portals) throws Exception {
|
public ResponseEntity<Boolean> deleteCommunities(@RequestBody List<String> portals) throws Exception {
|
||||||
for (String id: portals) {
|
for (String id : portals) {
|
||||||
Portal portal = portalService.getPortalById(id);
|
Portal portal = portalService.getPortalById(id);
|
||||||
if(portal == null) {
|
if (!portal.getType().equals("community")) {
|
||||||
// EXCEPTION - Entity Not Found
|
throw new MismatchingContentException("Delete Community: Portal with id: " + id + " has type: " + portal.getType() + " instead of community");
|
||||||
throw new ContentNotFoundException("Delete community: Portal with id: " + id + " not found");
|
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Delete Community: Portal with id: "+id+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
String pid = portalService.deletePortal(id);
|
String pid = portalService.deletePortal(id);
|
||||||
|
|
||||||
statisticsService.deleteByPid(pid);
|
|
||||||
subscriberService.deletePortalSubscribers(pid);
|
|
||||||
layoutService.deleteByPid(pid);
|
layoutService.deleteByPid(pid);
|
||||||
notificationsService.deleteByPid(pid);
|
notificationsService.deleteByPid(pid);
|
||||||
menuService.deleteMenuByPortalPid(pid);
|
menuService.deleteMenuByPortalPid(pid);
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/layouts", method = RequestMethod.GET)
|
@RequestMapping(value = "/layouts", method = RequestMethod.GET)
|
||||||
public List<Layout> getAvailableLayouts() {
|
public ResponseEntity<List<Layout>> getAvailableLayouts() {
|
||||||
return this.layoutService.findAll();
|
return ResponseEntity.ok(this.layoutService.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
||||||
public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
public ResponseEntity<Layout> getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalService.getPortal(pid);
|
Portal portal = portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null) {
|
if (portal == null) {
|
||||||
// EXCEPTION - Entity Not Found
|
// EXCEPTION - Entity Not Found
|
||||||
throw new ContentNotFoundException("CommunityController - Get layout: Portal with pid: " + pid + " not found");
|
throw new NotFoundException("CommunityController - Get layout: Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(layoutService.findByPid(pid));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("CommunityController - Get layout: Portal with pid: "+pid+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
return layoutService.findByPid(pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
||||||
public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
public ResponseEntity<Layout> updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
||||||
Portal portal = portalService.getPortal(pid);
|
Portal portal = portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null) {
|
if (portal == null) {
|
||||||
// EXCEPTION - Entity Not Found
|
throw new NotFoundException("CommunityController - Update layout: Portal with pid: " + pid + " not found");
|
||||||
throw new ContentNotFoundException("CommunityController - Update layout: Portal with pid: " + pid + " not found");
|
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
layout.setPortalPid(portal.getPid());
|
||||||
// EXCEPTION - MismatchingContent
|
return ResponseEntity.ok(layoutService.save(layout));
|
||||||
throw new MismatchingContentException("CommunityController - Update layout: Portal with pid: "+pid+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
if(!pid.equals(layout.getPortalPid())) {
|
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("CommunityController - Update layout: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
|
|
||||||
}
|
|
||||||
return layoutService.save(layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'))")
|
"@AuthorizationService.curator('community'))")
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
|
||||||
public boolean deleteLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
public ResponseEntity<Boolean> deleteLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalService.getPortal(pid);
|
Portal portal = portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null) {
|
if (portal == null) {
|
||||||
// EXCEPTION - Entity Not Found
|
throw new NotFoundException("CommunityController - Delete layout: Portal with pid: " + pid + " not found");
|
||||||
throw new ContentNotFoundException("CommunityController - Delete layout: Portal with pid: " + pid + " not found");
|
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
layoutService.deleteByPid(pid);
|
||||||
// EXCEPTION - MismatchingContent
|
return ResponseEntity.ok(true);
|
||||||
throw new MismatchingContentException("CommunityController - Delete layout: Portal with pid: "+pid+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
return layoutService.deleteByPid(pid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,13 @@ import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.utils.MismatchingContentException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -18,22 +18,24 @@ import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/connect")
|
@RequestMapping("/connect")
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class ConnectController {
|
public class ConnectController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final LayoutService layoutService;
|
||||||
private LayoutService layoutService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortalService portalService;
|
private PortalService portalService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PageService pageService;
|
private PageService pageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ConnectController(LayoutService layoutService) {
|
||||||
|
this.layoutService = layoutService;
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
public PortalResponse updateConnect(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> updateConnect(@RequestBody Portal portal) {
|
||||||
if (!portal.getType().equals("connect")) {
|
if (!portal.getType().equals("connect")) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
||||||
|
@ -41,82 +43,72 @@ public class ConnectController {
|
||||||
|
|
||||||
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
||||||
String new_pid = portal.getPid();
|
String new_pid = portal.getPid();
|
||||||
|
|
||||||
PortalResponse portalResponse = portalService.updatePortal(portal);
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
||||||
|
|
||||||
if (!old_pid.equals(new_pid)) {
|
if (!old_pid.equals(new_pid)) {
|
||||||
layoutService.updatePid(old_pid, new_pid);
|
layoutService.updatePid(old_pid, portal);
|
||||||
pageService.updatePid(old_pid, new_pid, portal.getType());
|
pageService.updatePid(old_pid, portal);
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(portalResponse);
|
||||||
return portalResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
public PortalResponse insertConnect(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> insertConnect(@RequestBody Portal portal) {
|
||||||
if (!portal.getType().equals("connect")) {
|
if (!portal.getType().equals("connect")) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
||||||
}
|
}
|
||||||
|
|
||||||
PortalResponse portalResponse = portalService.insertPortal(portal);
|
return ResponseEntity.ok(portalService.insertPortal(portal));
|
||||||
return portalResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
public Boolean deleteConnect(@RequestBody List<String> portals) {
|
public ResponseEntity<Boolean> deleteConnect(@RequestBody List<String> portals) {
|
||||||
for (String id : portals) {
|
for (String id : portals) {
|
||||||
Portal portal = portalService.getPortalById(id);
|
Portal portal = portalService.getPortalById(id);
|
||||||
if (portal == null) {
|
|
||||||
// EXCEPTION - Entity Not Found
|
|
||||||
throw new ContentNotFoundException("Delete connect: Portal with id: " + id + " not found");
|
|
||||||
}
|
|
||||||
if (!portal.getType().equals("connect")) {
|
if (!portal.getType().equals("connect")) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect");
|
throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect");
|
||||||
}
|
}
|
||||||
|
|
||||||
String pid = portalService.deletePortal(id);
|
String pid = portalService.deletePortal(id);
|
||||||
layoutService.deleteByPid(pid);
|
layoutService.deleteByPid(pid);
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// no authorization here, because it is called by server
|
// no authorization here, because it is called by server
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
||||||
public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
public ResponseEntity<Layout> getLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
||||||
if(!pid.equals("connect") && !pid.equals("default")) {
|
if (!pid.equals("connect") && !pid.equals("default")) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("ConnectController - Get layout: Not accepted pid: "+pid);
|
throw new MismatchingContentException("ConnectController - Get layout: Not accepted pid: " + pid);
|
||||||
}
|
}
|
||||||
return layoutService.findByPid(pid);
|
return ResponseEntity.ok(layoutService.findByPid(pid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
||||||
public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
public ResponseEntity<Layout> updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
||||||
if(!pid.equals("connect") && !pid.equals("default")) {
|
if (!pid.equals("connect") && !pid.equals("default")) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("ConnectController - Update layout: Not accepted pid: "+pid);
|
throw new MismatchingContentException("ConnectController - Update layout: Not accepted pid: " + pid);
|
||||||
}
|
}
|
||||||
if(!pid.equals(layout.getPortalPid())) {
|
if (!pid.equals(layout.getPortalPid())) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("ConnectController - Update layout: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
|
throw new MismatchingContentException("ConnectController - Update layout: Portal has pid: " + pid + " while layout has portalPid: " + layout.getPortalPid());
|
||||||
}
|
}
|
||||||
return layoutService.save(layout);
|
return ResponseEntity.ok(layoutService.save(layout));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
|
||||||
public boolean deleteLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
public ResponseEntity<Boolean> deleteLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
||||||
if(!pid.equals("connect") && !pid.equals("default")) {
|
if (!pid.equals("connect") && !pid.equals("default")) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("ConnectController - Delete layout: Not accepted pid: "+pid);
|
throw new MismatchingContentException("ConnectController - Delete layout: Not accepted pid: " + pid);
|
||||||
}
|
}
|
||||||
return layoutService.deleteByPid(pid);
|
layoutService.deleteByPid(pid);
|
||||||
|
return ResponseEntity.ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,71 +3,63 @@ package eu.dnetlib.uoaadmintools.controllers;
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
||||||
import eu.dnetlib.uoaadmintools.services.CuratorService;
|
import eu.dnetlib.uoaadmintools.services.CuratorService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.utils.RolesUtils;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class CuratorController {
|
public class CuratorController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final CuratorService curatorService;
|
||||||
private CuratorService curatorService;
|
private final RolesUtils rolesUtils;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RolesUtils rolesUtils;
|
public CuratorController(CuratorService curatorService, RolesUtils rolesUtils) {
|
||||||
|
this.curatorService = curatorService;
|
||||||
|
this.rolesUtils = rolesUtils;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list with curator for a specific community
|
* Return a list with curator for a specific community
|
||||||
*
|
*
|
||||||
* @param pid
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
|
||||||
public List<CuratorResponse> getCurators(@PathVariable String pid) {
|
public ResponseEntity<List<CuratorResponse>> getCurators(@PathVariable String pid) {
|
||||||
return curatorService.getCurators(pid);
|
return ResponseEntity.ok(curatorService.getCurators(pid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Curator info of logged in user.
|
* Return Curator info of logged-in user.
|
||||||
*
|
*
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/curator", method = RequestMethod.GET)
|
@RequestMapping(value = "/curator", method = RequestMethod.GET)
|
||||||
public Curator getCuratorById() {
|
public ResponseEntity<Curator> getCuratorById() {
|
||||||
Curator curator = curatorService.findById(getId());
|
return ResponseEntity.ok(curatorService.findById(getId()));
|
||||||
if(curator != null) {
|
|
||||||
return curator;
|
|
||||||
}
|
|
||||||
throw new ContentNotFoundException("No curator found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create or update a curator, base on Curator object given on Request Body.
|
* Create or update a curator, base on Curator object given on Request Body.
|
||||||
*
|
*
|
||||||
* @param curator
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/curator", method = RequestMethod.POST)
|
@RequestMapping(value = "/curator", method = RequestMethod.POST)
|
||||||
public Curator insertCurator(@RequestBody Curator curator) {
|
public ResponseEntity<Curator> insertCurator(@RequestBody Curator curator) {
|
||||||
curator.setId(getId());
|
curator.setId(getId());
|
||||||
return curatorService.save(curator);
|
return ResponseEntity.ok(curatorService.save(curator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all curators for a spedific community.
|
* Delete all curators for a specific community.
|
||||||
*
|
*
|
||||||
* @param pid
|
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
|
||||||
|
|
|
@ -1,170 +1,104 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Manager;
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||||
import eu.dnetlib.uoaadmintools.services.ManagerService;
|
import eu.dnetlib.uoaadmintools.services.ManagerService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
import eu.dnetlib.uoaadmintools.services.NotificationsService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.exceptions.InvalidReCaptchaException;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
|
import eu.dnetlib.uoaadmintoolslibrary.services.EmailService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha;
|
import eu.dnetlib.uoaadmintoolslibrary.utils.RolesUtils;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class EmailController {
|
public class EmailController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
private final EmailService service;
|
||||||
|
private final RolesUtils rolesUtils;
|
||||||
|
private final PortalService portalService;
|
||||||
|
private final ManagerService managerService;
|
||||||
|
private final NotificationsService notificationsService;
|
||||||
|
private final EmailService emailService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmailSender emailSender;
|
public EmailController(EmailService service, RolesUtils rolesUtils, PortalService portalService, ManagerService managerService, NotificationsService notificationsService, EmailService emailService) {
|
||||||
@Autowired
|
this.service = service;
|
||||||
private NotificationsDAO notificationsDAO;
|
this.rolesUtils = rolesUtils;
|
||||||
@Autowired
|
this.portalService = portalService;
|
||||||
private PortalDAO portalDAO;
|
this.managerService = managerService;
|
||||||
@Autowired
|
this.notificationsService = notificationsService;
|
||||||
private VerifyRecaptcha verifyRecaptcha;
|
this.emailService = emailService;
|
||||||
@Autowired
|
}
|
||||||
private ManagerService managerService;
|
|
||||||
@Autowired
|
|
||||||
private RolesUtils rolesUtils;
|
|
||||||
|
|
||||||
@RequestMapping(value = "/contact", method = RequestMethod.POST)
|
@RequestMapping(value = "/contact", method = RequestMethod.POST)
|
||||||
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
|
public ResponseEntity<Boolean> contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
|
||||||
if(form.getRecaptcha() != null) {
|
this.service.processResponse(form.getRecaptcha());
|
||||||
verifyRecaptcha.processResponse(form.getRecaptcha());
|
|
||||||
}
|
|
||||||
Email email = form.getEmail();
|
Email email = form.getEmail();
|
||||||
ArrayList<String> sendTo = new ArrayList<>(email.getRecipients());
|
return ResponseEntity.ok(this.service.send(email.getRecipients(), email.getSubject(), email.getBody(), false));
|
||||||
return emailSender.send(sendTo, email.getSubject(), email.getBody(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/sendMail", method = RequestMethod.POST)
|
@RequestMapping(value = "/sendMail", method = RequestMethod.POST)
|
||||||
public Map<String, ArrayList<String>> sendEmail(@RequestBody Email email,
|
public ResponseEntity<Map<String, ArrayList<String>>> sendEmail(@RequestBody Email email,
|
||||||
@RequestParam(required = false) Optional<Boolean> optional) {
|
@RequestParam(required = false, name = "optional") Optional<Boolean> optional) {
|
||||||
String successString = "success";
|
String successString = "success";
|
||||||
String failureString = "failure";
|
String failureString = "failure";
|
||||||
Map<String, ArrayList<String>> mailResults = new HashMap<>();
|
Map<String, ArrayList<String>> mailResults = new HashMap<>();
|
||||||
boolean bcc = (optional.isPresent())?optional.get():true;
|
boolean bcc = optional.orElse(true);
|
||||||
for(String userMail:email.getRecipients()){
|
for (String userMail : email.getRecipients()) {
|
||||||
ArrayList<String> sendTo = new ArrayList<>();
|
boolean success = this.service.send(Collections.singletonList(userMail), email.getSubject(), email.getBody(), bcc);
|
||||||
sendTo.add(userMail);
|
if (success) {
|
||||||
boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), bcc);
|
if (!mailResults.containsKey(successString)) {
|
||||||
if(success){
|
|
||||||
if(!mailResults.containsKey(successString)) {
|
|
||||||
mailResults.put(successString, new ArrayList<>());
|
mailResults.put(successString, new ArrayList<>());
|
||||||
}
|
}
|
||||||
mailResults.get(successString).add(userMail);
|
mailResults.get(successString).add(userMail);
|
||||||
} else {
|
} else {
|
||||||
if(!mailResults.containsKey(failureString)) {
|
if (!mailResults.containsKey(failureString)) {
|
||||||
mailResults.put(failureString, new ArrayList<>());
|
mailResults.put(failureString, new ArrayList<>());
|
||||||
}
|
}
|
||||||
mailResults.get(failureString).add(userMail);
|
mailResults.get(failureString).add(userMail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mailResults;
|
return ResponseEntity.ok(mailResults);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/notifyNewManager", method = RequestMethod.POST)
|
|
||||||
public Boolean notifyNewManager(@RequestBody Email email) throws Exception {
|
|
||||||
String userMail = rolesUtils.getEmail();
|
|
||||||
ArrayList<String> sendTo = new ArrayList<>();
|
|
||||||
sendTo.add(userMail);
|
|
||||||
boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), true);
|
|
||||||
|
|
||||||
return success;
|
@RequestMapping(value = "/notifyNewManager", method = RequestMethod.POST)
|
||||||
|
public ResponseEntity<Boolean> notifyNewManager(@RequestBody Email email) throws Exception {
|
||||||
|
return ResponseEntity.ok(this.service.send(Collections.singletonList(rolesUtils.getEmail()), email.getSubject(), email.getBody(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/notifyManagers/{pid}/{newRoleType}", method = RequestMethod.POST)
|
@RequestMapping(value = "/notifyManagers/{pid}/{newRoleType}", method = RequestMethod.POST)
|
||||||
public Boolean notifyManagers(@PathVariable(value = "pid") String pid,
|
public ResponseEntity<Boolean> notifyManagers(@PathVariable(value = "pid") String pid,
|
||||||
@PathVariable(value = "newRoleType") String newRoleType,
|
@PathVariable(value = "newRoleType") String newRoleType,
|
||||||
@RequestBody Email email ) throws Exception {
|
@RequestBody Email email) throws Exception {
|
||||||
List<String> notifyrecipients = new ArrayList<String>();
|
Portal portal = this.portalService.getPortal(pid);
|
||||||
if(portalDAO.findByPid(pid) == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal not found");
|
throw new NotFoundException("Portal not found");
|
||||||
}
|
}
|
||||||
|
List<String> emails = Arrays.stream(managerService.getManagers(pid)).map(Manager::getEmail).collect(Collectors.toList());
|
||||||
Manager[] managers = managerService.getManagers(pid);
|
List<String> notifyRecipients = emails.stream().filter(address -> !address.equals(rolesUtils.getEmail())).filter(address -> {
|
||||||
List<String> emails = new ArrayList();
|
Notifications notifications = this.notificationsService.getUserNotifications(portal);
|
||||||
|
return notifications == null
|
||||||
for(Manager manager:managers){
|
|| (newRoleType.equals("manager") && notifications.getNotifyForNewManagers())
|
||||||
String userEmail = manager.getEmail();
|
|| (newRoleType.equals("subscriber") && notifications.getNotifyForNewSubscribers());
|
||||||
emails.add(userEmail);
|
}).collect(Collectors.toList());
|
||||||
|
if (!notifyRecipients.isEmpty()) {
|
||||||
// Do not send the notification to the new manager/ subscriber.
|
|
||||||
if(userEmail.equals(rolesUtils.getEmail())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(userEmail,pid);
|
|
||||||
|
|
||||||
if(userNotifications == null
|
|
||||||
|| (newRoleType.equals("manager") && userNotifications.getNotifyForNewManagers())
|
|
||||||
|| (newRoleType.equals("subscriber") && userNotifications.getNotifyForNewSubscribers())){
|
|
||||||
notifyrecipients.add(userEmail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(notifyrecipients.size() > 0){
|
|
||||||
email.setBody(email.getBody().replace("((__managers__))", String.join(", ", emails)));
|
email.setBody(email.getBody().replace("((__managers__))", String.join(", ", emails)));
|
||||||
|
return ResponseEntity.ok(emailService.send(notifyRecipients, email.getSubject(), email.getBody(), false));
|
||||||
return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
} else {
|
||||||
}else{
|
|
||||||
log.debug("There are no users to notify ");
|
log.debug("There are no users to notify ");
|
||||||
|
return ResponseEntity.ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// @RequestMapping(value = "/notifyForNewSubscribers/{pid}", method = RequestMethod.POST)
|
}
|
||||||
// public Boolean notifyNewSubscribers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception {
|
|
||||||
// List<String> notifyrecipients = new ArrayList<String>();
|
|
||||||
// if(portalDAO.findByPid(pid) == null){
|
|
||||||
// throw new ContentNotFoundException("Portal not found");
|
|
||||||
// }
|
|
||||||
// for(String user:email.getRecipients()){
|
|
||||||
// Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
|
||||||
//
|
|
||||||
// if(userNotifications == null || userNotifications.getNotifyForNewSubscribers()){
|
|
||||||
// notifyrecipients.add(user);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if(notifyrecipients.size() > 0){
|
|
||||||
// return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
|
||||||
// }else{
|
|
||||||
// log.debug("There are no users to notify ");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
|
||||||
public String test() throws Exception {
|
|
||||||
log.debug("Test mail");
|
|
||||||
List<String> mails = new ArrayList<>();
|
|
||||||
mails.add("argirok@di.uoa.gr");
|
|
||||||
mails.add("argirokokogiannaki@gmail.com");
|
|
||||||
log.debug("Recipients"+mails);
|
|
||||||
|
|
||||||
Email email = new Email();
|
|
||||||
email.setRecipients(mails);
|
|
||||||
email.setBody("Test body");
|
|
||||||
email.setSubject("Test theme");
|
|
||||||
String response = "";
|
|
||||||
response+=this.notifyManagers("ee", "manager", email);
|
|
||||||
log.debug("Notify managers "+response);
|
|
||||||
|
|
||||||
response+=" ";
|
|
||||||
response+=this.notifyManagers("ee", "subscriber", email);
|
|
||||||
log.debug("Notify for subscr "+response);
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.utils.MismatchingContentException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/explore")
|
@RequestMapping("/explore")
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
public class ExploreController {
|
public class ExploreController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
@ -28,49 +27,37 @@ public class ExploreController {
|
||||||
private PageService pageService;
|
private PageService pageService;
|
||||||
|
|
||||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
public PortalResponse updateExplore(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> updateExplore(@RequestBody Portal portal) {
|
||||||
if(!portal.getType().equals("explore")) {
|
if(!portal.getType().equals("explore")) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Update Explore: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of explore");
|
throw new MismatchingContentException("Update Explore: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of explore");
|
||||||
}
|
}
|
||||||
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
||||||
String new_pid = portal.getPid();
|
String new_pid = portal.getPid();
|
||||||
|
|
||||||
PortalResponse portalResponse = portalService.updatePortal(portal);
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
||||||
|
|
||||||
if (!old_pid.equals(new_pid)) {
|
if (!old_pid.equals(new_pid)) {
|
||||||
pageService.updatePid(old_pid, new_pid, portal.getType());
|
pageService.updatePid(old_pid, portal);
|
||||||
}
|
}
|
||||||
return portalResponse;
|
return ResponseEntity.ok(portalResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
public PortalResponse insertExplore(@RequestBody Portal portal) {
|
public ResponseEntity<PortalResponse> insertExplore(@RequestBody Portal portal) {
|
||||||
if(!portal.getType().equals("explore")) {
|
if(!portal.getType().equals("explore")) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Save Explore: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of explore");
|
throw new MismatchingContentException("Save Explore: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of explore");
|
||||||
}
|
}
|
||||||
PortalResponse portalResponse = portalService.insertPortal(portal);
|
return ResponseEntity.ok(portalService.insertPortal(portal));
|
||||||
return portalResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot handle MismatchingContent
|
|
||||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
public Boolean deleteExplore(@RequestBody List<String> portals) throws Exception {
|
public ResponseEntity<Boolean> deleteExplore(@RequestBody List<String> portals) {
|
||||||
for (String id : portals) {
|
for (String id : portals) {
|
||||||
Portal portal = portalService.getPortalById(id);
|
Portal portal = portalService.getPortalById(id);
|
||||||
if(portal == null) {
|
|
||||||
// EXCEPTION - Entity Not Found
|
|
||||||
throw new ContentNotFoundException("Delete Explore: Portal with id: " + id + " not found");
|
|
||||||
}
|
|
||||||
if(!portal.getType().equals("explore")) {
|
if(!portal.getType().equals("explore")) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Delete Explore: Portal with id: "+id+" has type: "+portal.getType()+" instead of explore");
|
throw new MismatchingContentException("Delete Explore: Portal with id: "+id+" has type: "+portal.getType()+" instead of explore");
|
||||||
}
|
}
|
||||||
portalService.deletePortal(id);
|
portalService.deletePortal(id);
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,87 +1,53 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.*;
|
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.menu.MenuFull;
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
|
||||||
import eu.dnetlib.uoaadmintools.services.MenuService;
|
import eu.dnetlib.uoaadmintools.services.MenuService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
import eu.dnetlib.uoaadmintoolslibrary.utils.MismatchingContentException;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class MenuController {
|
public class MenuController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
private final MenuService menuService;
|
||||||
|
private final PortalService portalService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MenuService menuService;
|
public MenuController(MenuService menuService, PortalService portalService) {
|
||||||
@Autowired
|
this.menuService = menuService;
|
||||||
private PortalDAO portalDAO;
|
this.portalService = portalService;
|
||||||
@Autowired
|
}
|
||||||
private RolesUtils rolesUtils;
|
|
||||||
|
|
||||||
// NOT USED - maybe leave it
|
|
||||||
//// @PreAuthorize("hasAnyAuthority(" +
|
|
||||||
//// "@AuthorizationService.PORTAL_ADMIN, " +
|
|
||||||
//// "@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
|
||||||
// @RequestMapping(value = "/community/{pid}/menu", method = RequestMethod.GET)
|
|
||||||
// public List<MenuItem> getMenuItems(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
|
|
||||||
// // @RequestParam(value="featured", required=false) String isFeatured
|
|
||||||
// Portal portal = portalDAO.findByPid(pid);
|
|
||||||
// if(portal == null){
|
|
||||||
// throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
|
||||||
// }
|
|
||||||
// if(!portal.getType().equals("community")) {
|
|
||||||
// // EXCEPTION - MismatchingContent
|
|
||||||
// throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List<MenuItem> menuItems = menuService.getMenuItems(pid);
|
|
||||||
// if(menuItems == null || menuItems.size() == 0){
|
|
||||||
// throw new ContentNotFoundException("Menu for community with pid: "+pid+" not found");
|
|
||||||
// }
|
|
||||||
// return menuItems;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// OLD endpoint
|
// OLD endpoint
|
||||||
@RequestMapping(value = "/community/{pid}/menu/root/full", method = RequestMethod.GET)
|
@RequestMapping(value = "/community/{pid}/menu/root/full", method = RequestMethod.GET)
|
||||||
public List<MenuItemFull> getRootMenuItemsFull(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
|
public ResponseEntity<List<MenuItemFull>> getRootMenuItemsFull(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(menuService.getRootMenuItemsFull(pid));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MenuItemFull> menuItems = menuService.getRootMenuItemsFull(pid);
|
|
||||||
// if(menuItems == null || menuItems.size() == 0){
|
|
||||||
// throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found");
|
|
||||||
// }
|
|
||||||
return menuItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{pid}/menu/full", method = RequestMethod.GET)
|
@RequestMapping(value = "/community/{pid}/menu/full", method = RequestMethod.GET)
|
||||||
public MenuFull getMenuFull(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
|
public ResponseEntity<MenuFull> getMenuFull(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(menuService.getMenuFull(pid));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuFull menu = menuService.getMenuFull(pid);
|
|
||||||
return menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -89,38 +55,29 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/menu/update", method = RequestMethod.POST)
|
@RequestMapping(value = "/community/{pid}/menu/update", method = RequestMethod.POST)
|
||||||
public MenuItemFull updateMenuItem(@PathVariable String pid, @RequestBody MenuItemFull menuItemFull) {
|
public ResponseEntity<MenuItemFull> updateMenuItem(@PathVariable String pid, @RequestBody MenuItemFull menuItemFull) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
if (menuItemFull.getIsFeatured() && menuItemFull.getItems() != null && !menuItemFull.getItems().isEmpty()) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("updateMenuItem: MenuItem " + menuItemFull.getId() + " cannot be featured because it has " + menuItemFull.getItems().size() + " sub menu items");
|
||||||
throw new MismatchingContentException("updateMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
}
|
||||||
if(menuItemFull.getIsFeatured() && menuItemFull.getItems() != null && menuItemFull.getItems().size() > 0) {
|
if (menuItemFull.getType() == null ||
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("updateMenuItem: MenuItem "+menuItemFull.getId()+" cannot be featured because it has "+menuItemFull.getItems().size() + " sub menu items");
|
|
||||||
}
|
|
||||||
if(menuItemFull.getType() == null ||
|
|
||||||
(menuItemFull.getType().equals("internal") && menuItemFull.getRoute() == null) ||
|
(menuItemFull.getType().equals("internal") && menuItemFull.getRoute() == null) ||
|
||||||
(menuItemFull.getType().equals("external") && menuItemFull.getUrl() == null)) {
|
(menuItemFull.getType().equals("external") && menuItemFull.getUrl() == null)) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type=" + menuItemFull.getType()
|
||||||
throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type="+menuItemFull.getType()
|
+ " - url=" + menuItemFull.getUrl() + " - route=" + menuItemFull.getRoute());
|
||||||
+ " - url="+menuItemFull.getUrl() + " - route="+menuItemFull.getRoute());
|
|
||||||
}
|
}
|
||||||
if(menuItemFull.getPortalPid() == null) {
|
if (menuItemFull.getPortalPid() == null) {
|
||||||
menuItemFull.setPortalPid(pid);
|
menuItemFull.setPortalPid(pid);
|
||||||
} else if(!menuItemFull.getPortalPid().equals(pid)) {
|
} else if (!menuItemFull.getPortalPid().equals(pid)) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("updateMenuItem: MenuItem has portalPid: " + menuItemFull.getPortalPid() + " instead of " + pid);
|
||||||
throw new MismatchingContentException("updateMenuItem: MenuItem has portalPid: "+menuItemFull.getPortalPid()+" instead of "+pid);
|
|
||||||
}
|
}
|
||||||
if(menuItemFull.getId() == null) {
|
if (menuItemFull.getId() == null) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("updateMenuItem: This MenuItem has no id.");
|
throw new MismatchingContentException("updateMenuItem: This MenuItem has no id.");
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(menuService.updateMenu(menuItemFull, pid));
|
||||||
return menuService.updateMenu(menuItemFull, pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -128,38 +85,31 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/menu/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/community/{pid}/menu/save", method = RequestMethod.POST)
|
||||||
public MenuItemFull insertMenuItem(@PathVariable String pid, @RequestBody MenuItem menuItem) {
|
public ResponseEntity<MenuItemFull> insertMenuItem(@PathVariable String pid, @RequestBody MenuItem menuItem) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(portal.getType() == null || !portal.getType().equals("community")) {
|
if (menuItem.getIsFeatured() && menuItem.getItems() != null && !menuItem.getItems().isEmpty()) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("insertMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
throw new MismatchingContentException("updateMenuItem: MenuItem " + menuItem.getId() + " cannot be featured because it has " + menuItem.getItems().size() + " sub menu items");
|
||||||
}
|
}
|
||||||
if(menuItem.getIsFeatured() && menuItem.getItems() != null && menuItem.getItems().size() > 0) {
|
if (menuItem.getType() == null ||
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("updateMenuItem: MenuItem "+menuItem.getId()+" cannot be featured because it has "+menuItem.getItems().size() + " sub menu items");
|
|
||||||
}
|
|
||||||
if(menuItem.getType() == null ||
|
|
||||||
(menuItem.getType().equals("internal") && menuItem.getRoute() == null) ||
|
(menuItem.getType().equals("internal") && menuItem.getRoute() == null) ||
|
||||||
(menuItem.getType().equals("external") && menuItem.getUrl() == null)) {
|
(menuItem.getType().equals("external") && menuItem.getUrl() == null)) {
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type="+menuItem.getType()
|
throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type=" + menuItem.getType()
|
||||||
+ " - url="+menuItem.getUrl() + " - route="+menuItem.getRoute());
|
+ " - url=" + menuItem.getUrl() + " - route=" + menuItem.getRoute());
|
||||||
}
|
}
|
||||||
if(menuItem.getPortalPid() == null) {
|
if (menuItem.getPortalPid() == null) {
|
||||||
menuItem.setPortalPid(pid);
|
menuItem.setPortalPid(pid);
|
||||||
} else if(!menuItem.getPortalPid().equals(pid)) {
|
} else if (!menuItem.getPortalPid().equals(pid)) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("insertMenuItem: MenuItem has portalPid: " + menuItem.getPortalPid() + " instead of " + pid);
|
||||||
throw new MismatchingContentException("insertMenuItem: MenuItem has portalPid: "+menuItem.getPortalPid()+" instead of "+pid);
|
|
||||||
}
|
}
|
||||||
if(menuItem.getId() != null) {
|
if (menuItem.getId() != null) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("insertMenuItem: MenuItem has already an id: " + menuItem.getId());
|
||||||
throw new MismatchingContentException("insertMenuItem: MenuItem has already an id: "+menuItem.getId());
|
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(menuService.insertMenuItemInMenu(menuItem, pid));
|
||||||
return menuService.insertMenuItemInMenu(menuItem, pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -167,17 +117,12 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/menu/delete", method = RequestMethod.POST)
|
@RequestMapping(value = "/community/{pid}/menu/delete", method = RequestMethod.POST)
|
||||||
public Boolean deleteMenuItem(@PathVariable String pid, @RequestBody String menuItemId) throws Exception {
|
public ResponseEntity<Boolean> deleteMenuItem(@PathVariable String pid, @RequestBody String menuItemId) throws Exception {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(menuService.deleteMenuItem(menuItemId, pid));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("deleteMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
return menuService.deleteMenuItem(menuItemId, pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -185,17 +130,12 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/menu/reorder", method = RequestMethod.POST)
|
@RequestMapping(value = "/community/{pid}/menu/reorder", method = RequestMethod.POST)
|
||||||
public Boolean reorderMenuItems(@PathVariable String pid, @RequestBody List<MenuItemFull> menuItems) throws Exception {
|
public ResponseEntity<Boolean> reorderMenuItems(@PathVariable String pid, @RequestBody List<MenuItemFull> menuItems) throws Exception {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(menuService.reorderMenuItems(menuItems, pid));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("reorderMenuItems: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
return menuService.reorderMenuItems(menuItems, pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -203,8 +143,8 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = {"/community/{pid}/menu/toggle"}, method = RequestMethod.POST)
|
@RequestMapping(value = {"/community/{pid}/menu/toggle"}, method = RequestMethod.POST)
|
||||||
public Menu toggleMenu(@PathVariable(value = "pid") String pid, @RequestParam String status, @RequestParam(value="featured", required=false) String isFeatured) throws Exception {
|
public ResponseEntity<Menu> toggleMenu(@PathVariable(value = "pid") String pid, @RequestParam String status, @RequestParam(value = "featured", required = false) String isFeatured) throws Exception {
|
||||||
return menuService.toggleMenu(pid, status, isFeatured);
|
return ResponseEntity.ok(menuService.toggleMenu(pid, status, isFeatured));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
|
@ -212,7 +152,7 @@ public class MenuController {
|
||||||
"@AuthorizationService.curator('community')," +
|
"@AuthorizationService.curator('community')," +
|
||||||
"@AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = {"/community/{pid}/menu/align"}, method = RequestMethod.POST)
|
@RequestMapping(value = {"/community/{pid}/menu/align"}, method = RequestMethod.POST)
|
||||||
public Menu alignMenu(@PathVariable(value = "pid") String pid, @RequestParam String alignment) throws Exception {
|
public ResponseEntity<Menu> alignMenu(@PathVariable(value = "pid") String pid, @RequestParam String alignment) throws Exception {
|
||||||
return menuService.alignMenu(pid, alignment);
|
return ResponseEntity.ok(menuService.alignMenu(pid, alignment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
import eu.dnetlib.uoaadmintools.services.NotificationsService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -19,79 +19,58 @@ import java.util.List;
|
||||||
* Created by argirok on 6/7/2018.
|
* Created by argirok on 6/7/2018.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class NotificationsController {
|
public class NotificationsController {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
|
private final NotificationsService notificationsService;
|
||||||
|
private final PortalService portalService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NotificationsDAO notificationsDAO;
|
public NotificationsController(NotificationsService notificationsService, PortalService portalService) {
|
||||||
@Autowired
|
this.notificationsService = notificationsService;
|
||||||
private PortalDAO portalDAO;
|
this.portalService = portalService;
|
||||||
@Autowired
|
}
|
||||||
private RolesUtils rolesUtils;
|
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/community/{pid}/notifications/all", method = RequestMethod.GET)
|
@RequestMapping(value = "/community/{pid}/notifications/all", method = RequestMethod.GET)
|
||||||
public List<Notifications> getNotifications(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
|
public ResponseEntity<List<Notifications>> getNotifications(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
List<Notifications> notifications = this.notificationsService.getAllNotifications(portal);
|
||||||
// EXCEPTION - MismatchingContent
|
if (notifications.isEmpty()) {
|
||||||
throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
throw new NotFoundException("Notifications settings for community with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(notifications);
|
||||||
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid);
|
|
||||||
if(notifications == null || notifications.size() == 0){
|
|
||||||
throw new ContentNotFoundException("Notifications settings for community with pid: "+pid+" not found");
|
|
||||||
}
|
|
||||||
return notifications;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.GET)
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.GET)
|
||||||
public Notifications getNotificationsForUser(@PathVariable(value = "pid") String pid) throws ContentNotFoundException {
|
public ResponseEntity<Notifications> getNotificationsForUser(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
Notifications notifications = this.notificationsService.getUserNotifications(portal);
|
||||||
// EXCEPTION - MismatchingContent
|
if (notifications == null) {
|
||||||
throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
throw new NotFoundException("Notifications settings for community with pid: " + pid + " not found for this user.");
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(notifications);
|
||||||
String email = rolesUtils.getEmail();
|
|
||||||
|
|
||||||
Notifications notifications = notificationsDAO.findByManagerEmailAndPortalPid(email, pid);
|
|
||||||
if(notifications == null){
|
|
||||||
throw new ContentNotFoundException("Notifications settings for community with pid: "+pid+" and user email: "+email+" not found");
|
|
||||||
}
|
|
||||||
return notifications;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.DELETE)
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.DELETE)
|
||||||
public void deleteNotification(@PathVariable(value = "pid") String pid) throws ContentNotFoundException {
|
public void deleteNotification(@PathVariable(value = "pid") String pid) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
|
||||||
if(!portal.getType().equals("community")) {
|
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Delete Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
String email = rolesUtils.getEmail();
|
|
||||||
Notifications notifications = notificationsDAO.findByManagerEmailAndPortalPid(email,pid);
|
|
||||||
if(notifications!= null){
|
|
||||||
notificationsDAO.delete(notifications.getId());
|
|
||||||
}else{
|
|
||||||
throw new ContentNotFoundException("Notifications settings for community with pid: "+pid+" and user email: "+email+" not found");
|
|
||||||
}
|
}
|
||||||
|
this.notificationsService.deleteUserNotifications(portal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,36 +78,12 @@ public class NotificationsController {
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
||||||
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.POST)
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.POST)
|
||||||
public Notifications saveNotification(@PathVariable(value = "pid") String pid, @RequestBody Notifications notifications) throws ContentNotFoundException {
|
public ResponseEntity<Notifications> saveNotification(@PathVariable(value = "pid") String pid, @RequestBody Notifications notifications) {
|
||||||
Portal portal = portalDAO.findByPid(pid);
|
Portal portal = this.portalService.getPortal(PortalType.community, pid);
|
||||||
if(portal == null){
|
if (portal == null) {
|
||||||
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
|
throw new NotFoundException("Portal with pid: " + pid + " not found");
|
||||||
}
|
}
|
||||||
if(!portal.getType().equals("community")) {
|
return ResponseEntity.ok(this.notificationsService.save(portal, notifications));
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Save Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications.setManagerEmail(rolesUtils.getEmail());
|
|
||||||
notifications.setAaiId(rolesUtils.getAaiId());
|
|
||||||
|
|
||||||
// if(notifications.getManagerEmail() != null && !notifications.getManagerEmail().isEmpty()){
|
|
||||||
Notifications saved = notificationsDAO.findByManagerEmailAndPortalPid(notifications.getManagerEmail(),pid);
|
|
||||||
log.debug(saved);
|
|
||||||
if(saved!= null){
|
|
||||||
notifications.setId(saved.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications.setPortalPid(pid);
|
|
||||||
log.debug(notifications);
|
|
||||||
Notifications savedNotifications = notificationsDAO.save(notifications);
|
|
||||||
return savedNotifications;
|
|
||||||
// } else{
|
|
||||||
// log.error("Save notifications: No user e-mail specified");
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,238 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse;
|
|
||||||
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 java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 2/3/2018.
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class PortalSubscribersController {
|
|
||||||
@Autowired
|
|
||||||
PortalSubscribersDAO portalSubscribersDAO;
|
|
||||||
@Autowired
|
|
||||||
SubscriberDAO subscriberDAO;
|
|
||||||
@Autowired
|
|
||||||
PortalDAO portalDAO;
|
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private SecurityConfig securityConfig;
|
|
||||||
|
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{pid}/subscribers/count", method = RequestMethod.GET)
|
|
||||||
public SingleValueWrapperResponse<Integer> getNumberOfSubscribersPerPortal(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
|
||||||
SingleValueWrapperResponse<Integer> singleValueWrapperResponse = new SingleValueWrapperResponse(0);
|
|
||||||
|
|
||||||
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
if(portalSubscribers != null){
|
|
||||||
if(portalSubscribers.getSubscribers() != null) {
|
|
||||||
singleValueWrapperResponse.setValue(portalSubscribers.getSubscribers().size());
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
throw new ContentNotFoundException("Portal Subscribers not found");
|
|
||||||
|
|
||||||
}
|
|
||||||
return singleValueWrapperResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/community/subscribers", method = RequestMethod.GET)
|
|
||||||
public List<PortalSubscribers> getAllPortalSubscribers(){
|
|
||||||
return portalSubscribersDAO.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.GET)
|
|
||||||
public PortalSubscribers getSubscribersPerPortal(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
|
||||||
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
if(portalSubscribers != null){
|
|
||||||
return portalSubscribers;
|
|
||||||
}else{
|
|
||||||
throw new ContentNotFoundException("Portal Subscribers not found");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// @RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
|
|
||||||
// public PortalSubscribers addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
|
||||||
// PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if(portalSubscribers == null){
|
|
||||||
// throw new ContentNotFoundException("Portal Subscribers not found");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail());
|
|
||||||
// if(savedSubscriber==null){
|
|
||||||
// savedSubscriber = subscriberDAO.save(subscriber);
|
|
||||||
// }
|
|
||||||
// for(Subscriber sub: portalSubscribers.getSubscribers()){
|
|
||||||
// if(sub.getEmail().equals(subscriber.getEmail())){
|
|
||||||
// //already subscribed
|
|
||||||
// return portalSubscribers;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //not subscribed yet
|
|
||||||
// portalSubscribers.getSubscribers().add(savedSubscriber);
|
|
||||||
// return portalSubscribersDAO.save(portalSubscribers);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
|
|
||||||
// public Boolean getIsSubscribedToPortal(@PathVariable(value="pid", required = true) String pid,
|
|
||||||
// //@RequestBody String email,
|
|
||||||
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
||||||
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
||||||
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
||||||
// UserInfo userInfo = helper.getUserInfo(token);
|
|
||||||
//
|
|
||||||
// if(userInfo != null) {
|
|
||||||
// String email = userInfo.getEmail();
|
|
||||||
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if (communitySubscribers != null) {
|
|
||||||
// if (communitySubscribers.getSubscribers() != null) {
|
|
||||||
// for (Subscriber subscriber : communitySubscribers.getSubscribers()) {
|
|
||||||
// if (subscriber.getEmail().equals(email)) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// throw new ContentNotFoundException("Portal Subscribers not found");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST)
|
|
||||||
// public Boolean addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid,
|
|
||||||
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
||||||
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
||||||
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
||||||
// UserInfo userInfo = helper.getUserInfo(token);
|
|
||||||
//
|
|
||||||
// if(userInfo != null) {
|
|
||||||
// String email = userInfo.getEmail();
|
|
||||||
// Subscriber subscriber = new Subscriber(email);
|
|
||||||
//
|
|
||||||
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if (communitySubscribers == null) {
|
|
||||||
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Subscriber savedSubscriber = subscriberDAO.findByEmail(email);
|
|
||||||
// if (savedSubscriber == null) {
|
|
||||||
// savedSubscriber = subscriberDAO.save(subscriber);
|
|
||||||
// }
|
|
||||||
// for (Subscriber sub : communitySubscribers.getSubscribers()) {
|
|
||||||
// if (sub.getEmail().equals(subscriber.getEmail())) {
|
|
||||||
// //already subscribed
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //not subscribed yet
|
|
||||||
// communitySubscribers.getSubscribers().add(savedSubscriber);
|
|
||||||
// portalSubscribersDAO.save(communitySubscribers);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// @RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST)
|
|
||||||
// public Boolean deleteSubscriberFromPortal(@PathVariable(value="pid", required = true) String pid,
|
|
||||||
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
||||||
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
||||||
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
||||||
// UserInfo userInfo = helper.getUserInfo(token);
|
|
||||||
//
|
|
||||||
// if(userInfo != null) {
|
|
||||||
// String email = userInfo.getEmail();
|
|
||||||
//
|
|
||||||
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if (communitySubscribers == null) {
|
|
||||||
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator();
|
|
||||||
// while(subscriberIterator.hasNext()) {
|
|
||||||
// Subscriber subscriber = subscriberIterator.next();
|
|
||||||
// if(subscriber.getEmail().equals(email)) {
|
|
||||||
// subscriberIterator.remove();
|
|
||||||
// portalSubscribersDAO.save(communitySubscribers);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
|
|
||||||
// public PortalSubscribers addSubscriberInPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
|
||||||
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if(communitySubscribers == null){
|
|
||||||
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail());
|
|
||||||
// if(savedSubscriber==null){
|
|
||||||
// savedSubscriber = subscriberDAO.save(subscriber);
|
|
||||||
// }
|
|
||||||
// for(Subscriber sub:communitySubscribers.getSubscribers()){
|
|
||||||
// if(sub.getEmail().equals(subscriber.getEmail())){
|
|
||||||
// //already subscribed
|
|
||||||
// return communitySubscribers;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //not subscribed yet
|
|
||||||
// communitySubscribers.getSubscribers().add(savedSubscriber);
|
|
||||||
// return portalSubscribersDAO.save(communitySubscribers);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// @RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST)
|
|
||||||
// public PortalSubscribers deleteSubscriberFromPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
|
|
||||||
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if(communitySubscribers == null){
|
|
||||||
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
||||||
// }
|
|
||||||
// List<Subscriber> list = new ArrayList<>();
|
|
||||||
// for(Subscriber s:communitySubscribers.getSubscribers()){
|
|
||||||
// if(emails.indexOf(s.getEmail())==-1){
|
|
||||||
// list.add(s);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// communitySubscribers.setSubscribers(list);
|
|
||||||
// return portalSubscribersDAO.save(communitySubscribers);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET)
|
|
||||||
// public List<String> getPortalsPerSubcriber(//@RequestParam(value="email", required = true) String email,
|
|
||||||
// @RequestHeader("X-XSRF-TOKEN") String token) {
|
|
||||||
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
||||||
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
||||||
// UserInfo userInfo = helper.getUserInfo(token);
|
|
||||||
//
|
|
||||||
// List<String> list = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// if (userInfo != null) {
|
|
||||||
// String email = userInfo.getEmail();
|
|
||||||
// List<PortalSubscribers> communitySubscribers = portalSubscribersDAO.findAll();
|
|
||||||
//
|
|
||||||
// for (PortalSubscribers s : communitySubscribers) {
|
|
||||||
// for (Subscriber sub : s.getSubscribers()) {
|
|
||||||
// if (sub.getEmail().equals(email)) {
|
|
||||||
// list.add(s.getPid());
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,123 +0,0 @@
|
||||||
//package eu.dnetlib.uoaadmintools.controllers;
|
|
||||||
//
|
|
||||||
//import eu.dnetlib.uoaadmintools.dao.*;
|
|
||||||
//import eu.dnetlib.uoaadmintools.entities.statistics.*;
|
|
||||||
//import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
//import org.apache.log4j.Logger;
|
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
//import org.springframework.web.bind.annotation.*;
|
|
||||||
//
|
|
||||||
//import java.util.*;
|
|
||||||
//
|
|
||||||
//@RestController
|
|
||||||
//@CrossOrigin(origins = "*")
|
|
||||||
//public class StatisticsController {
|
|
||||||
// private final Logger log = Logger.getLogger(this.getClass());
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// private StatisticsDAO statisticsDAO;
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/statistics", method = RequestMethod.GET)
|
|
||||||
// public List<Statistics> getAllStatistics() throws ContentNotFoundException {
|
|
||||||
// log.info("getAllStatistics");
|
|
||||||
// List<Statistics> statistics = statisticsDAO.findAll();
|
|
||||||
// if(statistics == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found");
|
|
||||||
// }
|
|
||||||
// return statistics;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/statistics/{pid}", method = RequestMethod.GET)
|
|
||||||
// public Statistics getStatistics(@PathVariable(value = "pid") String pid) throws ContentNotFoundException {
|
|
||||||
// Statistics statistics = statisticsDAO.findByPid(pid);
|
|
||||||
// if(statistics == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found");
|
|
||||||
// }
|
|
||||||
// return statistics;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/statistics/{id}/toggle", method = RequestMethod.POST)
|
|
||||||
// public Boolean toggleStatistics(@PathVariable String id) throws Exception {
|
|
||||||
// Statistics statistics = statisticsDAO.findById(id);
|
|
||||||
// boolean status = statistics.getIsActive();
|
|
||||||
// statistics.setIsActive(!status);
|
|
||||||
// statisticsDAO.save(statistics);
|
|
||||||
// return statistics.getIsActive();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/statistics/save", method = RequestMethod.POST)
|
|
||||||
// public Statistics insertStatistics(@RequestBody Statistics statistics) {
|
|
||||||
// Statistics savedStatistics = statisticsDAO.save(statistics);
|
|
||||||
// return savedStatistics;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "/statistics/delete", method = RequestMethod.POST)
|
|
||||||
// public Boolean deleteStatistics(@RequestBody List<String> statistics) throws Exception {
|
|
||||||
// for (String id: statistics) {
|
|
||||||
// statisticsDAO.delete(id);
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @RequestMapping(value = "statistics/{pid}/{entity}/charts", method = RequestMethod.POST)
|
|
||||||
// public Statistics toggleCharts(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
|
|
||||||
// Statistics statistics = statisticsDAO.findByPid(pid);
|
|
||||||
// if(statistics == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for portal");
|
|
||||||
// }
|
|
||||||
// StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
|
|
||||||
// if(statisticsEntity == null ){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for entity");
|
|
||||||
// }
|
|
||||||
// ChartsMap charts = statisticsEntity.getCharts();
|
|
||||||
// if(charts == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found - no charts");
|
|
||||||
// }
|
|
||||||
// StatisticsStatus statisticsStatus= charts.getMap().get(key);
|
|
||||||
// if(statisticsStatus == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for key");
|
|
||||||
// }
|
|
||||||
// if(Boolean.parseBoolean(monitor)){
|
|
||||||
// statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
|
|
||||||
// }else{
|
|
||||||
// statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
|
|
||||||
// }
|
|
||||||
//// stats.put(key,statisticsStatus);
|
|
||||||
// return statisticsDAO.save(statistics);
|
|
||||||
// }
|
|
||||||
// @RequestMapping(value = "statistics/{pid}/{entity}/numbers", method = RequestMethod.POST)
|
|
||||||
// public Statistics toggleNumber(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
|
|
||||||
// Statistics statistics = statisticsDAO.findByPid(pid);
|
|
||||||
// if(statistics == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for portal");
|
|
||||||
// }
|
|
||||||
// StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
|
|
||||||
// if(statisticsEntity == null ){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for entity");
|
|
||||||
// }
|
|
||||||
// NumbersMap numbers = statisticsEntity.getNumbers();
|
|
||||||
// if(numbers == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found - no numbers");
|
|
||||||
// }
|
|
||||||
// StatisticsStatus statisticsStatus= numbers.getMap().get(key);
|
|
||||||
// if(statisticsStatus == null){
|
|
||||||
// throw new ContentNotFoundException("Statistics not found for key");
|
|
||||||
// }
|
|
||||||
// if(Boolean.parseBoolean(monitor)){
|
|
||||||
// statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
|
|
||||||
// }else{
|
|
||||||
// statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
|
|
||||||
// }
|
|
||||||
//// stats.put(key,statisticsStatus);
|
|
||||||
// return statisticsDAO.save(statistics);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
||||||
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 java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 2/3/2018.
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class SubscriberController {
|
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
|
||||||
@Autowired
|
|
||||||
private SubscriberDAO subscriberDAO;
|
|
||||||
@RequestMapping(value = "/subscriber", method = RequestMethod.GET)
|
|
||||||
public List<Subscriber> getSubscriber() throws ContentNotFoundException {
|
|
||||||
List<Subscriber> list = subscriberDAO.findAll();
|
|
||||||
if(list == null){
|
|
||||||
throw new ContentNotFoundException("Subscribers not found");
|
|
||||||
}
|
|
||||||
return subscriberDAO.findAll();
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/subscriber/{email}", method = RequestMethod.GET)
|
|
||||||
public Subscriber getSubscriber(@PathVariable(value="email", required = true) String email) throws ContentNotFoundException {
|
|
||||||
Subscriber subscriber = subscriberDAO.findByEmail(email);
|
|
||||||
if(subscriber == null){
|
|
||||||
throw new ContentNotFoundException("Subscribers not found");
|
|
||||||
}
|
|
||||||
return subscriber;
|
|
||||||
}
|
|
||||||
// @RequestMapping(value = "/subscriber", method = RequestMethod.POST)
|
|
||||||
// public Subscriber saveSubscriber(@RequestBody Subscriber subscriber) {
|
|
||||||
// return subscriberDAO.save(subscriber);
|
|
||||||
// }
|
|
||||||
// @RequestMapping(value = "/subscriber/{email}", method = RequestMethod.DELETE)
|
|
||||||
// public void deleteSubscriber(@PathVariable(value="email", required = true) String email) throws ContentNotFoundException {
|
|
||||||
// Subscriber subscriber = subscriberDAO.findByEmail(email);
|
|
||||||
// if(subscriber == null){
|
|
||||||
// throw new ContentNotFoundException("Subscribers not found");
|
|
||||||
// }
|
|
||||||
// subscriberDAO.delete(subscriber.getId());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +1,10 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
package eu.dnetlib.uoaadmintools.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CuratorDAO {
|
@Repository
|
||||||
|
public interface CuratorDAO extends MongoRepository<Curator, String> {}
|
||||||
List<Curator> findAll();
|
|
||||||
|
|
||||||
Curator findById(String Id);
|
|
||||||
|
|
||||||
Curator findByEmail(String email);
|
|
||||||
|
|
||||||
Curator save(Curator curator);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
package eu.dnetlib.uoaadmintools.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface LayoutDAO {
|
@Repository
|
||||||
List<Layout> findAll();
|
public interface LayoutDAO extends MongoRepository<Layout, String> {
|
||||||
|
Optional<Layout> findByPortalPid(String portalPid);
|
||||||
Layout findById(String Id);
|
|
||||||
|
|
||||||
List<Layout> findByPortalPid(String portalPid);
|
|
||||||
|
|
||||||
Layout save(Layout layout);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,14 @@ package eu.dnetlib.uoaadmintools.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
|
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface MenuDAO {
|
@Repository
|
||||||
List<Menu> findAll();
|
public interface MenuDAO extends MongoRepository<Menu, String> {
|
||||||
Menu findByPortalPid(String portalPid);
|
Optional<Menu> findByPortalPid(String portalPid);
|
||||||
|
|
||||||
Menu save(Menu menu);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
void deleteByPortalPid(String portalPid);
|
void deleteByPortalPid(String portalPid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
package eu.dnetlib.uoaadmintools.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface MenuItemDAO {
|
@Repository
|
||||||
List<MenuItem> findAll();
|
public interface MenuItemDAO extends MongoRepository<MenuItem, String> {
|
||||||
List<MenuItem> findByParentItemId(String parentId);
|
List<MenuItem> findByParentItemId(String parentId);
|
||||||
|
|
||||||
MenuItem findById(String Id);
|
|
||||||
|
|
||||||
List<MenuItem> findByPortalPid(String portalPid);
|
List<MenuItem> findByPortalPid(String portalPid);
|
||||||
List<MenuItem> findByParentItemIdAndPortalPid(String parentId, String portalPid);
|
List<MenuItem> findByParentItemIdAndPortalPid(String parentId, String portalPid);
|
||||||
|
|
||||||
MenuItem save(MenuItem menuItem);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.CuratorDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBCuratorDAO extends CuratorDAO, MongoRepository<Curator, String> {
|
|
||||||
|
|
||||||
List<Curator> findAll();
|
|
||||||
|
|
||||||
Curator findById(String Id);
|
|
||||||
|
|
||||||
Curator findByEmail(String email);
|
|
||||||
|
|
||||||
Curator save(Curator curator);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBLayoutDAO extends LayoutDAO, MongoRepository<Layout, String> {
|
|
||||||
|
|
||||||
List<Layout> findAll();
|
|
||||||
|
|
||||||
Layout findById(String Id);
|
|
||||||
|
|
||||||
List<Layout> findByPortalPid(String portalPid);
|
|
||||||
|
|
||||||
Layout save(Layout layout);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBMenuDAO extends MenuDAO, MongoRepository<Menu, String> {
|
|
||||||
List<Menu> findAll();
|
|
||||||
Menu findByPortalPid(String portalPid);
|
|
||||||
|
|
||||||
Menu save(Menu menu);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
void deleteByPortalPid(String portalPid);
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBMenuItemDAO extends MenuItemDAO, MongoRepository<MenuItem, String> {
|
|
||||||
List<MenuItem> findAll();
|
|
||||||
List<MenuItem> findByParentItemId(String parentId);
|
|
||||||
|
|
||||||
MenuItem findById(String Id);
|
|
||||||
|
|
||||||
List<MenuItem> findByPortalPid(String portalPid);
|
|
||||||
List<MenuItem> findByParentItemIdAndPortalPid(String parentId, String portalPid);
|
|
||||||
|
|
||||||
MenuItem save(MenuItem menuItem);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 6/7/2018.
|
|
||||||
*/
|
|
||||||
public interface MongoDBNotificationsDAO extends NotificationsDAO, MongoRepository<Notifications, String> {
|
|
||||||
List<Notifications> findAll();
|
|
||||||
|
|
||||||
Notifications findById(String Id);
|
|
||||||
|
|
||||||
Notifications findByManagerEmailAndPortalPid(String managerEmail, String portalPid);
|
|
||||||
List<Notifications> findByPortalPid(String portalPid);
|
|
||||||
|
|
||||||
Notifications save(Notifications entity);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBPortalSubscribersDAO extends PortalSubscribersDAO, MongoRepository<PortalSubscribers, String> {
|
|
||||||
|
|
||||||
List<PortalSubscribers> findAll();
|
|
||||||
|
|
||||||
PortalSubscribers findById(String Id);
|
|
||||||
|
|
||||||
PortalSubscribers findByPid(String Pid);
|
|
||||||
|
|
||||||
PortalSubscribers save(PortalSubscribers portalSubscribers);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.StatisticsDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBStatisticsDAO extends StatisticsDAO, MongoRepository<Statistics, String> {
|
|
||||||
List<Statistics> findAll();
|
|
||||||
|
|
||||||
Statistics findById(String Id);
|
|
||||||
|
|
||||||
Statistics findByPid(String Pid);
|
|
||||||
|
|
||||||
Statistics save(Statistics statistic);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber;
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MongoDBSubscriberDAO extends SubscriberDAO, MongoRepository<Subscriber, String> {
|
|
||||||
|
|
||||||
List<Subscriber> findAll();
|
|
||||||
|
|
||||||
Subscriber findById(String Id);
|
|
||||||
|
|
||||||
Subscriber findByEmail(String email);
|
|
||||||
|
|
||||||
Subscriber save(Subscriber subscriber);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,23 +1,14 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
package eu.dnetlib.uoaadmintools.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
@Repository
|
||||||
* Created by argirok on 6/7/2018.
|
public interface NotificationsDAO extends MongoRepository<Notifications, String> {
|
||||||
*/
|
Optional<Notifications> findByManagerEmailAndPortalPid(String managerEmail, String portalPid);
|
||||||
public interface NotificationsDAO {
|
|
||||||
List<Notifications> findAll();
|
|
||||||
|
|
||||||
Notifications findById(String Id);
|
|
||||||
|
|
||||||
Notifications findByManagerEmailAndPortalPid(String managerEmail, String portalPid);
|
|
||||||
List<Notifications> findByPortalPid(String portalPid);
|
List<Notifications> findByPortalPid(String portalPid);
|
||||||
|
|
||||||
Notifications save(Notifications entity);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface PortalSubscribersDAO {
|
|
||||||
|
|
||||||
List<PortalSubscribers> findAll();
|
|
||||||
|
|
||||||
PortalSubscribers findById(String Id);
|
|
||||||
|
|
||||||
PortalSubscribers findByPid(String Pid);
|
|
||||||
|
|
||||||
PortalSubscribers save(PortalSubscribers portalSubscribers);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
|
||||||
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 5/3/2018.
|
|
||||||
*/
|
|
||||||
public interface StatisticsDAO {
|
|
||||||
List<Statistics> findAll();
|
|
||||||
|
|
||||||
Statistics findById(String Id);
|
|
||||||
|
|
||||||
Statistics findByPid(String Pid);
|
|
||||||
|
|
||||||
Statistics save(Statistics statistic);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.dao;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface SubscriberDAO {
|
|
||||||
|
|
||||||
List<Subscriber> findAll();
|
|
||||||
|
|
||||||
Subscriber findById(String Id);
|
|
||||||
|
|
||||||
Subscriber findByEmail(String email);
|
|
||||||
|
|
||||||
Subscriber save(Subscriber subscriber);
|
|
||||||
|
|
||||||
void deleteAll();
|
|
||||||
|
|
||||||
void delete(String id);
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.dnetlib.uoaadmintools.entities;
|
||||||
|
|
||||||
|
public enum ManagerType {
|
||||||
|
EMAIL,
|
||||||
|
ID
|
||||||
|
}
|
|
@ -1,46 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 2/3/2018.
|
|
||||||
*/
|
|
||||||
public class Subscriber {
|
|
||||||
@Id
|
|
||||||
@JsonProperty("_id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public Subscriber() {}
|
|
||||||
public Subscriber(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Subscriber{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", email='" + email + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.statistics;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 15/3/2018.
|
|
||||||
*/
|
|
||||||
public class ChartsMap {
|
|
||||||
Map<String,StatisticsStatus> map = new HashMap<String, StatisticsStatus>();
|
|
||||||
public ChartsMap(){
|
|
||||||
map.put("timeline",new StatisticsStatus());
|
|
||||||
map.put("graph",new StatisticsStatus());
|
|
||||||
map.put("projectTable",new StatisticsStatus());
|
|
||||||
map.put("projectColumn",new StatisticsStatus());
|
|
||||||
map.put("projectPie",new StatisticsStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, StatisticsStatus> getMap() {
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMap(Map<String, StatisticsStatus> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ChartsMap{" +
|
|
||||||
"entities=" + map +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.statistics;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 15/3/2018.
|
|
||||||
*/
|
|
||||||
public class NumbersMap {
|
|
||||||
Map<String,StatisticsStatus> map = new HashMap<String, StatisticsStatus>();
|
|
||||||
public NumbersMap(){
|
|
||||||
map.put("total",new StatisticsStatus());
|
|
||||||
map.put("project",new StatisticsStatus());
|
|
||||||
map.put("open",new StatisticsStatus());
|
|
||||||
map.put("closed",new StatisticsStatus());
|
|
||||||
map.put("embargo",new StatisticsStatus());
|
|
||||||
map.put("restricted",new StatisticsStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, StatisticsStatus> getMap() {
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMap(Map<String, StatisticsStatus> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ChartsMap{" +
|
|
||||||
"entities=" + map +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,144 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.statistics;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 5/3/2018.
|
|
||||||
*/
|
|
||||||
public class Statistics {
|
|
||||||
@Id
|
|
||||||
@JsonProperty("_id")
|
|
||||||
private String id;
|
|
||||||
private String pid;
|
|
||||||
private boolean isActive = true;
|
|
||||||
Map<String,StatisticsEntity> entities = new HashMap<String, StatisticsEntity>();
|
|
||||||
public Statistics(String pid){
|
|
||||||
this.pid = pid;
|
|
||||||
this.isActive = true;
|
|
||||||
entities.put("publication",new StatisticsEntity());
|
|
||||||
entities.put("dataset",new StatisticsEntity());
|
|
||||||
entities.put("software",new StatisticsEntity());
|
|
||||||
entities.put("orp",new StatisticsEntity());
|
|
||||||
}
|
|
||||||
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 boolean getIsActive() {
|
|
||||||
return isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsActive(boolean isActive) {
|
|
||||||
this.isActive = isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, StatisticsEntity> getEntities() {
|
|
||||||
return entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEntities(Map<String, StatisticsEntity> entities) {
|
|
||||||
this.entities = entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Statistics{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", pid='" + pid + '\'' +
|
|
||||||
", isActive= "+isActive +
|
|
||||||
", entities=" + entities +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
// private Map<String, StatisticsStatus> statistics;
|
|
||||||
//
|
|
||||||
// public Statistics(String pid){
|
|
||||||
// this.setPid(pid);
|
|
||||||
// this.statistics = new HashMap<String, StatisticsStatus>();
|
|
||||||
//
|
|
||||||
// this.statistics.put("publicationsNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsProjectNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsOpenNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsClosedNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsEmbargoNumber", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// this.statistics.put("datasetsNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsProjectNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsOpenNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsClosedNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsEmbargoNumber", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// this.statistics.put("softwareNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareProjectNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareOpenNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareClosedNumber", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareEmbargoNumber", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// this.statistics.put("publicationsTimeline", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsTimeline", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareTimeline", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// this.statistics.put("publicationsProjectColumn", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsProjectPie", new StatisticsStatus());
|
|
||||||
// this.statistics.put("publicationsProjectTable", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// this.statistics.put("datasetsProjectColumn", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsProjectPie", new StatisticsStatus());
|
|
||||||
// this.statistics.put("datasetsProjectTable", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// this.statistics.put("softwareProjectColumn", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareProjectPie", new StatisticsStatus());
|
|
||||||
// this.statistics.put("softwareProjectTable", new StatisticsStatus());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// 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 Map<String, StatisticsStatus> getStatistics() {
|
|
||||||
// return statistics;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setStatistics(Map<String, StatisticsStatus> statistics) {
|
|
||||||
// this.statistics = statistics;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String toString() {
|
|
||||||
// return "Statistics{" +
|
|
||||||
// "id='" + id + '\'' +
|
|
||||||
// ", pid='" + pid + '\'' +
|
|
||||||
// ", statistics=" + statistics +
|
|
||||||
// '}';
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.statistics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 15/3/2018.
|
|
||||||
*/
|
|
||||||
public class StatisticsEntity {
|
|
||||||
private ChartsMap charts = new ChartsMap();
|
|
||||||
private NumbersMap numbers = new NumbersMap();
|
|
||||||
|
|
||||||
public ChartsMap getCharts() {
|
|
||||||
return charts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCharts(ChartsMap charts) {
|
|
||||||
this.charts = charts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NumbersMap getNumbers() {
|
|
||||||
return numbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumbers(NumbersMap numbers) {
|
|
||||||
this.numbers = numbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "StatisticsEntity{" +
|
|
||||||
"charts=" + charts +
|
|
||||||
", numbers=" + numbers +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.statistics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 5/3/2018.
|
|
||||||
*/
|
|
||||||
public class StatisticsStatus {
|
|
||||||
Boolean showInMonitor = true;
|
|
||||||
Boolean showInDashboard = false;
|
|
||||||
|
|
||||||
public Boolean getShowInMonitor() {
|
|
||||||
return showInMonitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShowInMonitor(Boolean showInMonitor) {
|
|
||||||
this.showInMonitor = showInMonitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getShowInDashboard() {
|
|
||||||
return showInDashboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShowInDashboard(Boolean showInDashboard) {
|
|
||||||
this.showInDashboard = showInDashboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "StatisticsStatus{" +
|
|
||||||
"showInMonitor=" + showInMonitor +
|
|
||||||
", showInDashboard=" + showInDashboard +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.subscriber;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 2/3/2018.
|
|
||||||
*/
|
|
||||||
public class PortalSubscribers {
|
|
||||||
@Id
|
|
||||||
@JsonProperty("_id")
|
|
||||||
private String id;
|
|
||||||
private String pid;
|
|
||||||
private List<Subscriber> subscribers = new ArrayList<Subscriber>();
|
|
||||||
private List<Subscriber> pendingSubscribers = new ArrayList<Subscriber>();
|
|
||||||
public PortalSubscribers(String pid){
|
|
||||||
this.pid=pid;
|
|
||||||
}
|
|
||||||
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 List<Subscriber> getSubscribers() {
|
|
||||||
return subscribers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscribers(List<Subscriber> subscribers) {
|
|
||||||
this.subscribers = subscribers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PortalSubscribers{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", pid='" + pid + '\'' +
|
|
||||||
", subscribers=" + subscribers +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.entities.subscriber;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by argirok on 2/3/2018.
|
|
||||||
*/
|
|
||||||
public class Subscriber {
|
|
||||||
@Id
|
|
||||||
@JsonProperty("_id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Subscriber() {}
|
|
||||||
public Subscriber(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Subscriber{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", email='" + email + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.GlobalVars;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.mongo.MongoConnection;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Managers;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Mongodb;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Properties;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdminToolsDeployService {
|
||||||
|
private final MongoConnection mongoConnection;
|
||||||
|
private final Mongodb mongodb;
|
||||||
|
private final Managers managers;
|
||||||
|
private final String cache;
|
||||||
|
private final GlobalVars globalVars;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminToolsDeployService(MongoConnection mongoConnection, Properties properties, GlobalVars globalVars) {
|
||||||
|
this.mongoConnection = mongoConnection;
|
||||||
|
this.mongodb = properties.getMongodb();
|
||||||
|
this.managers = properties.getManagers();
|
||||||
|
this.cache = properties.getCache();
|
||||||
|
this.globalVars = globalVars;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void checkProperties() {
|
||||||
|
if (mongodb.getHost() == null || mongodb.getHost().isEmpty()) {
|
||||||
|
throw new RuntimeException("admin-tools.mongodb.host is missing!");
|
||||||
|
} else if (mongodb.getDatabase() == null || mongodb.getDatabase().isEmpty()) {
|
||||||
|
throw new RuntimeException("admin-tools.mongodb.database is missing!");
|
||||||
|
} else if (managers.getId() == null || managers.getId().isEmpty()) {
|
||||||
|
throw new RuntimeException("admin-tools.managers.id is missing!");
|
||||||
|
} else if (managers.getEmail() == null || managers.getEmail().isEmpty()) {
|
||||||
|
throw new RuntimeException("admin-tools.managers.email is missing!");
|
||||||
|
} else if (cache == null || cache.isEmpty()) {
|
||||||
|
throw new RuntimeException("admin-tools.cache is missing!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getProperties() {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
||||||
|
Document ping = new Document("ping", 1);
|
||||||
|
try {
|
||||||
|
Document answer = mt.executeCommand(ping);
|
||||||
|
response.put("Mongo try: error", String.valueOf(answer.getDouble("ok") == 1.0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
response.put("Mongo catch: error", e.getMessage());
|
||||||
|
}
|
||||||
|
response.put("admin-tools.mongodb.database", mongodb.getDatabase());
|
||||||
|
response.put("admin-tools.mongodb.host", mongodb.getHost());
|
||||||
|
response.put("admin-tools.mongodb.port", mongodb.getPort() + "");
|
||||||
|
response.put("admin-tools.mongodb.username", mongodb.getUsername() == null ? null : "[unexposed value]");
|
||||||
|
response.put("admin-tools.mongodb.password", mongodb.getPassword() == null ? null : "[unexposed value]");
|
||||||
|
response.put("admin-tools.managers.id", managers.getId());
|
||||||
|
response.put("admin-tools.managers.email", managers.getEmail());
|
||||||
|
response.put("admin-tools.cache", cache);
|
||||||
|
|
||||||
|
response.put("Date of deploy", GlobalVars.date.toString());
|
||||||
|
if (globalVars.getBuildDate() != null) {
|
||||||
|
response.put("Date of build", globalVars.getBuildDate());
|
||||||
|
}
|
||||||
|
if (globalVars.getVersion() != null) {
|
||||||
|
response.put("Version", globalVars.getVersion());
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,10 @@ package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.CuratorDAO;
|
import eu.dnetlib.uoaadmintools.dao.CuratorDAO;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Manager;
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.ManagerType;
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -18,17 +20,19 @@ public class CuratorService {
|
||||||
|
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final CuratorDAO curatorDAO;
|
||||||
private CuratorDAO curatorDAO;
|
private final ManagerService managerService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ManagerService managerService;
|
public CuratorService(CuratorDAO curatorDAO, ManagerService managerService) {
|
||||||
|
this.curatorDAO = curatorDAO;
|
||||||
|
this.managerService = managerService;
|
||||||
|
}
|
||||||
|
|
||||||
public List<CuratorResponse> getCurators(String pid) {
|
public List<CuratorResponse> getCurators(String pid) {
|
||||||
List<CuratorResponse> curators = new ArrayList<>();
|
List<CuratorResponse> curators = new ArrayList<>();
|
||||||
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
|
for (Manager manager : managerService.getManagers(pid, ManagerType.ID)) {
|
||||||
Curator curator = curatorDAO.findById(parseId(manager.getId()));
|
Curator curator = curatorDAO.findById(parseId(manager.getId())).orElse(null);
|
||||||
if (curator != null && curator.isVisible()) {
|
if (curator != null && curator.isVisible()) {
|
||||||
curators.add(new CuratorResponse(curator));
|
curators.add(new CuratorResponse(curator));
|
||||||
}
|
}
|
||||||
|
@ -37,7 +41,7 @@ public class CuratorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Curator findById(String id) {
|
public Curator findById(String id) {
|
||||||
return curatorDAO.findById(id);
|
return curatorDAO.findById(id).orElseThrow(() -> new NotFoundException("Curator with id: " + id + " not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Curator save(Curator curator) {
|
public Curator save(Curator curator) {
|
||||||
|
@ -45,16 +49,12 @@ public class CuratorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteCurators(String pid) {
|
public void deleteCurators(String pid) {
|
||||||
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
|
for (Manager manager : managerService.getManagers(pid, ManagerType.ID)) {
|
||||||
Curator curator = curatorDAO.findById(parseId(manager.getId()));
|
curatorDAO.findById(parseId(manager.getId())).ifPresent(curatorDAO::delete);
|
||||||
if (curator != null) {
|
|
||||||
curatorDAO.delete(curator.getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseId(String id) {
|
private String parseId(String id) {
|
||||||
return id.substring(0 , id.indexOf("@"));
|
return id.substring(0 , id.indexOf("@"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -2,11 +2,11 @@ package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
|
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,53 +14,40 @@ import java.util.List;
|
||||||
public class LayoutService {
|
public class LayoutService {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
|
private final LayoutDAO layoutDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LayoutDAO layoutDAO;
|
public LayoutService(LayoutDAO layoutDAO) {
|
||||||
|
this.layoutDAO = layoutDAO;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Layout> findAll() {
|
public List<Layout> findAll() {
|
||||||
return this.layoutDAO.findAll();
|
return this.layoutDAO.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
|
||||||
log.debug("layout service: updatePid");
|
|
||||||
List<Layout> layouts = layoutDAO.findByPortalPid(old_pid);
|
|
||||||
for(Layout layout : layouts) {
|
|
||||||
log.debug("layout service: layout id: " + (layout != null ? layout.getId() : "not found"));
|
|
||||||
if (layout != null) {
|
|
||||||
layout.setPortalPid(new_pid);
|
|
||||||
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
|
|
||||||
layoutDAO.save(layout);
|
|
||||||
log.debug("layout saved!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteByPid(String pid) {
|
|
||||||
List<Layout> layouts = layoutDAO.findByPortalPid(pid);
|
|
||||||
for(Layout layout : layouts) {
|
|
||||||
if (layout != null) {
|
|
||||||
if(!pid.equals(layout.getPortalPid())) {
|
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("Delete layout by pid: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
|
|
||||||
}
|
|
||||||
layoutDAO.delete(layout.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Layout findByPid(String pid) {
|
public Layout findByPid(String pid) {
|
||||||
List<Layout> layouts = layoutDAO.findByPortalPid(pid);
|
return layoutDAO.findByPortalPid(pid).orElse(null);
|
||||||
if(layouts != null && layouts.size() > 0) {
|
}
|
||||||
return layouts.get(0);
|
|
||||||
|
public void updatePid(String oldPid, Portal portal) {
|
||||||
|
Layout layout = this.findByPid(oldPid);
|
||||||
|
if (layout != null) {
|
||||||
|
layout.setPortalPid(portal.getPid());
|
||||||
|
layoutDAO.save(layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteByPid(String pid) {
|
||||||
|
Layout layout = this.findByPid(pid);
|
||||||
|
if (layout != null) {
|
||||||
|
layoutDAO.delete(layout);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Layout save(Layout layout) {
|
public Layout save(Layout layout) {
|
||||||
List<Layout> oldLayouts = layoutDAO.findByPortalPid(layout.getPortalPid());
|
Layout old = this.findByPid(layout.getPortalPid());
|
||||||
if(oldLayouts != null && oldLayouts.size() == 1) {
|
if(old != null) {
|
||||||
layout.setId(oldLayouts.get(0).getId()); // set existing id to update layout for this pid
|
layout.setId(old.getId());
|
||||||
}
|
}
|
||||||
return layoutDAO.save(layout);
|
return layoutDAO.save(layout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package eu.dnetlib.uoaadmintools.services;
|
package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
|
import eu.dnetlib.uoaadmintools.configuration.properties.Managers;
|
||||||
|
import eu.dnetlib.uoaadmintools.configuration.properties.Properties;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Manager;
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
||||||
import eu.dnetlib.uoaadmintools.entities.curator.Response;
|
import eu.dnetlib.uoaadmintools.entities.ManagerType;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -13,29 +14,27 @@ import org.springframework.web.client.RestTemplate;
|
||||||
@Service
|
@Service
|
||||||
public class ManagerService {
|
public class ManagerService {
|
||||||
|
|
||||||
enum Type {
|
private final Managers config;
|
||||||
EMAIL,
|
private final RestTemplate restTemplate;
|
||||||
ID
|
|
||||||
|
@Autowired
|
||||||
|
public ManagerService(Properties properties, RestTemplate restTemplate) {
|
||||||
|
this.config = properties.getManagers();
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ManagersApiConfig config;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RestTemplate restTemplate;
|
|
||||||
|
|
||||||
public Manager[] getManagers(String pid) {
|
public Manager[] getManagers(String pid) {
|
||||||
return getManagers(pid, Type.EMAIL);
|
return getManagers(pid, ManagerType.EMAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Manager[] getManagers(String pid, Type type) {
|
public Manager[] getManagers(String pid, ManagerType type) {
|
||||||
String url = (type == Type.EMAIL)?config.getEmail():config.getId();
|
String url = (type == ManagerType.EMAIL)?config.getEmail():config.getId();
|
||||||
ResponseEntity<Manager[]> responseEntity = restTemplate.getForEntity(url.replace("{community}", pid), Manager[].class);
|
ResponseEntity<Manager[]> responseEntity = restTemplate.getForEntity(url.replace("{community}", pid), Manager[].class);
|
||||||
Manager[] managers = responseEntity.getBody();
|
Manager[] managers = responseEntity.getBody();
|
||||||
if (managers != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
if (managers != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
||||||
return managers;
|
return managers;
|
||||||
} else {
|
} else {
|
||||||
throw new ContentNotFoundException("No managers has been found for community " + pid);
|
throw new NotFoundException("No managers has been found for community " + pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@ package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
|
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
|
||||||
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
|
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.menu.*;
|
import eu.dnetlib.uoaadmintools.entities.menu.*;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
import eu.dnetlib.uoaadmintoolslibrary.utils.MismatchingContentException;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -13,44 +13,43 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MenuService {
|
public class MenuService {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final MenuDAO menuDAO;
|
||||||
private MenuDAO menuDAO;
|
private final MenuItemDAO menuItemDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MenuItemDAO menuItemDAO;
|
public MenuService(MenuDAO menuDAO, MenuItemDAO menuItemDAO) {
|
||||||
|
this.menuDAO = menuDAO;
|
||||||
|
this.menuItemDAO = menuItemDAO;
|
||||||
|
}
|
||||||
|
|
||||||
public MenuItem getMenuItem(String id) {
|
public MenuItem getMenuItem(String id) {
|
||||||
return menuItemDAO.findById(id);
|
return menuItemDAO.findById(id).orElseThrow(() -> new NotFoundException("Menu item with id: " + id + " not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuItemFull getMenuItemFull(String id) {
|
public MenuItemFull getMenuItemFull(String id) {
|
||||||
return this.getMenuItemFull(id, 1);
|
return this.getMenuItemFull(id, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuItemFull getMenuItemFull(String id, int maxDepth) {
|
public MenuItemFull getMenuItemFull(String id, int maxDepth) {
|
||||||
MenuItem menuItem = menuItemDAO.findById(id);
|
MenuItem menuItem = getMenuItem(id);
|
||||||
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
|
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
|
||||||
if(maxDepth == 0) {
|
if (maxDepth == 0) {
|
||||||
menuItemFull.setItems(new ArrayList<>());
|
menuItemFull.setItems(new ArrayList<>());
|
||||||
return menuItemFull;
|
} else {
|
||||||
|
menuItemFull.setItems(menuItem.getItems().stream().map(item -> this.getMenuItemFull(item, maxDepth - 1))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MenuItemFull> menuItemsFull = new ArrayList<>();
|
|
||||||
for(String menuItemString : menuItem.getItems()) {
|
|
||||||
menuItemsFull.add(this.getMenuItemFull(menuItemString, maxDepth-1));
|
|
||||||
}
|
|
||||||
menuItemFull.setItems(menuItemsFull);
|
|
||||||
|
|
||||||
return menuItemFull;
|
return menuItemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MenuItem> getMenuItemsByParent(String parentId, String portalPid) {
|
public List<MenuItem> getMenuItemsByParent(String parentId, String portalPid) {
|
||||||
if(portalPid != null) {
|
if (portalPid != null) {
|
||||||
return menuItemDAO.findByParentItemIdAndPortalPid(parentId, portalPid);
|
return menuItemDAO.findByParentItemIdAndPortalPid(parentId, portalPid);
|
||||||
} else {
|
} else {
|
||||||
return menuItemDAO.findByParentItemId(parentId);
|
return menuItemDAO.findByParentItemId(parentId);
|
||||||
|
@ -60,11 +59,11 @@ public class MenuService {
|
||||||
public List<MenuItemFull> getRootMenuItemsFull(String portalPid) {
|
public List<MenuItemFull> getRootMenuItemsFull(String portalPid) {
|
||||||
List<MenuItem> rootMenuItems = this.getMenuItemsByParent(null, portalPid);
|
List<MenuItem> rootMenuItems = this.getMenuItemsByParent(null, portalPid);
|
||||||
List<MenuItemFull> rootMenuItemsFull = new ArrayList<>();
|
List<MenuItemFull> rootMenuItemsFull = new ArrayList<>();
|
||||||
for(MenuItem rootMenuItem : rootMenuItems) {
|
for (MenuItem rootMenuItem : rootMenuItems) {
|
||||||
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
|
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
|
||||||
|
|
||||||
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
|
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
|
||||||
for(String childMenuItemString : rootMenuItem.getItems()) {
|
for (String childMenuItemString : rootMenuItem.getItems()) {
|
||||||
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
|
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
|
||||||
}
|
}
|
||||||
rootMenuItemFull.setItems(childrenMenuItemsFull);
|
rootMenuItemFull.setItems(childrenMenuItemsFull);
|
||||||
|
@ -76,103 +75,72 @@ public class MenuService {
|
||||||
|
|
||||||
public MenuFull getMenuFull(String portalPid) {
|
public MenuFull getMenuFull(String portalPid) {
|
||||||
MenuFull menuFull = new MenuFull();
|
MenuFull menuFull = new MenuFull();
|
||||||
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElse(null);
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
menuFull.setPortalPid(portalPid);
|
||||||
List<MenuItemFull> featuredMenuItems = new ArrayList<>();
|
if (menu == null) {
|
||||||
List<MenuItemFull> menuItems = new ArrayList<>();
|
|
||||||
|
|
||||||
if(menu == null) {
|
|
||||||
menuFull.setFeaturedMenuEnabled(true);
|
menuFull.setFeaturedMenuEnabled(true);
|
||||||
menuFull.setMenuEnabled(true);
|
menuFull.setMenuEnabled(true);
|
||||||
menuFull.setFeaturedAlignment(MenuAlignment.CENTER.name());
|
menuFull.setFeaturedAlignment(MenuAlignment.CENTER.name());
|
||||||
} else {
|
} else {
|
||||||
for (String menuItemId : menu.getFeaturedMenuItems()) {
|
menuFull.setFeaturedMenuItems(menu.getFeaturedMenuItems().stream().map(item -> getFullRootMenuItemById(item, portalPid, true)).collect(Collectors.toList()));
|
||||||
featuredMenuItems.add(getFullRootMenuItemById(menuItemId, portalPid, true));
|
menuFull.setMenuItems(menu.getMenuItems().stream().map(item -> getFullRootMenuItemById(item, portalPid, false)).collect(Collectors.toList()));
|
||||||
}
|
|
||||||
|
|
||||||
for (String menuItemId : menu.getMenuItems()) {
|
|
||||||
menuItems.add(getFullRootMenuItemById(menuItemId, portalPid, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
menuFull.setFeaturedMenuEnabled(menu.getIsFeaturedMenuEnabled());
|
menuFull.setFeaturedMenuEnabled(menu.getIsFeaturedMenuEnabled());
|
||||||
menuFull.setMenuEnabled(menu.getIsMenuEnabled());
|
menuFull.setMenuEnabled(menu.getIsMenuEnabled());
|
||||||
menuFull.setFeaturedAlignment(menu.getFeaturedAlignment());
|
menuFull.setFeaturedAlignment(menu.getFeaturedAlignment());
|
||||||
}
|
}
|
||||||
|
|
||||||
menuFull.setPortalPid(portalPid);
|
|
||||||
menuFull.setFeaturedMenuItems(featuredMenuItems);
|
|
||||||
menuFull.setMenuItems(menuItems);
|
|
||||||
|
|
||||||
return menuFull;
|
return menuFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MenuItemFull getFullRootMenuItemById(String menuItemId, String portalPid, Boolean isFeatured) {
|
private MenuItemFull getFullRootMenuItemById(String id, String portalPid, Boolean isFeatured) {
|
||||||
MenuItem rootMenuItem = menuItemDAO.findById(menuItemId);
|
MenuItem rootMenuItem = this.getMenuItem(id);
|
||||||
if(rootMenuItem.getIsFeatured() != isFeatured) {
|
if (rootMenuItem.getIsFeatured() != isFeatured) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should " + (isFeatured ? "" : "not ") + "be featured");
|
||||||
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should "+(isFeatured ? "" : "not ")+"be featured");
|
|
||||||
}
|
}
|
||||||
if(!rootMenuItem.getPortalPid().equals(portalPid)) {
|
if (!rootMenuItem.getPortalPid().equals(portalPid)) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("getFullRootMenuItemById: Menu item with id: " + rootMenuItem.getId() + " has portal pid: " + rootMenuItem.getPortalPid() + " instead of " + portalPid);
|
||||||
throw new MismatchingContentException("getFullRootMenuItemById: Menu item with id: "+rootMenuItem.getId()+" has portal pid: "+rootMenuItem.getPortalPid()+" instead of "+portalPid);
|
|
||||||
}
|
}
|
||||||
if(rootMenuItem.getParentItemId() != null) {
|
if (rootMenuItem.getParentItemId() != null) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should be root (no parentId), but instead parentId: " + rootMenuItem.getParentItemId());
|
||||||
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should be root (no parentId), but instead parentId: "+rootMenuItem.getParentItemId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
|
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
|
||||||
|
rootMenuItemFull.setItems(rootMenuItem.getItems().stream().map(this::getMenuItemFull).collect(Collectors.toList()));
|
||||||
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
|
|
||||||
for(String childMenuItemString : rootMenuItem.getItems()) {
|
|
||||||
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
|
|
||||||
}
|
|
||||||
rootMenuItemFull.setItems(childrenMenuItemsFull);
|
|
||||||
return rootMenuItemFull;
|
return rootMenuItemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MenuItemFull insertMenuItem(MenuItem menuItem, String portalPid) {
|
private MenuItemFull insertMenuItem(MenuItem menuItem, String portalPid) {
|
||||||
MenuItem parent = null;
|
MenuItem parent = null;
|
||||||
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
|
if (menuItem.getParentItemId() != null && !menuItem.getParentItemId().isEmpty()) {
|
||||||
parent = getMenuItem(menuItem.getParentItemId());
|
parent = getMenuItem(menuItem.getParentItemId());
|
||||||
if (!parent.getPortalPid().equals(portalPid)) {
|
if (!parent.getPortalPid().equals(portalPid)) {
|
||||||
// EXCEPTION - MismatchingContent
|
throw new MismatchingContentException("insertMenuItem: parent (" + parent.getParentItemId() + ") of MenuItem has portalPid: " + parent.getPortalPid() + " instead of " + portalPid);
|
||||||
throw new MismatchingContentException("insertMenuItem: parent ("+parent.getParentItemId()+") of MenuItem has portalPid: " + parent.getPortalPid() + " instead of " + portalPid);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
menuItem.setParentItemId(null);
|
menuItem.setParentItemId(null);
|
||||||
}
|
}
|
||||||
|
if (menuItem.getItems() == null) {
|
||||||
if(menuItem.getItems() == null) {
|
menuItem.setItems(new ArrayList<>());
|
||||||
List<String> menuItems = new ArrayList<String>();
|
|
||||||
menuItem.setItems(menuItems);
|
|
||||||
}
|
}
|
||||||
menuItemDAO.save(menuItem);
|
menuItemDAO.save(menuItem);
|
||||||
|
if (parent != null) {
|
||||||
if(parent != null) {
|
|
||||||
List<String> siblingsOfNew = parent.getItems();
|
List<String> siblingsOfNew = parent.getItems();
|
||||||
siblingsOfNew.add(menuItem.getId());
|
siblingsOfNew.add(menuItem.getId());
|
||||||
parent.setItems(siblingsOfNew);
|
parent.setItems(siblingsOfNew);
|
||||||
menuItemDAO.save(parent);
|
menuItemDAO.save(parent);
|
||||||
}
|
}
|
||||||
|
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
|
||||||
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
|
|
||||||
menuItemFull.setItems(new ArrayList<>());
|
menuItemFull.setItems(new ArrayList<>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return menuItemFull;
|
return menuItemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuItemFull insertMenuItemInMenu(MenuItem menuItem, String portalPid) {
|
public MenuItemFull insertMenuItemInMenu(MenuItem menuItem, String portalPid) {
|
||||||
MenuItemFull menuItemFull = insertMenuItem(menuItem, portalPid);
|
MenuItemFull menuItemFull = insertMenuItem(menuItem, portalPid);
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElse(null);
|
||||||
if(menu == null) {
|
if (menu == null) {
|
||||||
menu = new Menu(portalPid);
|
menu = new Menu(portalPid);
|
||||||
}
|
}
|
||||||
if(menuItem.getIsFeatured() && menuItem.getParentItemId() == null) {
|
if (menuItem.getIsFeatured() && menuItem.getParentItemId() == null) {
|
||||||
menu.getFeaturedMenuItems().add(menuItemFull.getId());
|
menu.getFeaturedMenuItems().add(menuItemFull.getId());
|
||||||
} else if(menuItem.getParentItemId() == null) {
|
} else if (menuItem.getParentItemId() == null) {
|
||||||
menu.getMenuItems().add(menuItemFull.getId());
|
menu.getMenuItems().add(menuItemFull.getId());
|
||||||
}
|
}
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
|
@ -195,80 +163,64 @@ public class MenuService {
|
||||||
|
|
||||||
public MenuItemFull updateMenu(MenuItemFull menuItemFull, String portalPid) {
|
public MenuItemFull updateMenu(MenuItemFull menuItemFull, String portalPid) {
|
||||||
menuItemFull = updateMenuItem(menuItemFull);
|
menuItemFull = updateMenuItem(menuItemFull);
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElseThrow(() -> new NotFoundException("updateMenu: No Menu found for portal pid: " + portalPid));
|
||||||
if(menu == null) {
|
|
||||||
// EXCEPTION - ContentNotFoundException
|
|
||||||
throw new ContentNotFoundException("updateMenu: No Menu found for portal pid: "+portalPid);
|
|
||||||
}
|
|
||||||
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
|
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
|
||||||
List<String> menuItems = menu.getMenuItems();
|
List<String> menuItems = menu.getMenuItems();
|
||||||
if (menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !featuredMenuItems.contains(menuItemFull.getId())) {
|
if (menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !featuredMenuItems.contains(menuItemFull.getId())) {
|
||||||
featuredMenuItems.add(menuItemFull.getId());
|
featuredMenuItems.add(menuItemFull.getId());
|
||||||
} else if ((!menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null) && featuredMenuItems.contains(menuItemFull.getId())) {
|
} else if ((!menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null) && featuredMenuItems.contains(menuItemFull.getId())) {
|
||||||
featuredMenuItems.remove(menuItemFull.getId());
|
featuredMenuItems.remove(menuItemFull.getId());
|
||||||
} else if(!menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !menuItems.contains(menuItemFull.getId())) {
|
} else if (!menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !menuItems.contains(menuItemFull.getId())) {
|
||||||
menuItems.add(menuItemFull.getId());
|
menuItems.add(menuItemFull.getId());
|
||||||
} else if ((menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null) && menuItems.contains(menuItemFull.getId())) {
|
} else if ((menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null)) {
|
||||||
menuItems.remove(menuItemFull.getId());
|
menuItems.remove(menuItemFull.getId());
|
||||||
}
|
}
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
|
|
||||||
return menuItemFull;
|
return menuItemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean deleteMenuItem(String id, String portalPid) throws Exception {
|
public Boolean deleteMenuItem(String id, String portalPid) throws Exception {
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElseThrow(() -> new NotFoundException("deleteMenuItem: No Menu found for portal pid: " + portalPid));
|
||||||
if(menu == null) {
|
|
||||||
// EXCEPTION - ContentNotFoundException
|
|
||||||
throw new ContentNotFoundException("deleteMenuItem: No Menu found for portal pid: "+portalPid);
|
|
||||||
}
|
|
||||||
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
|
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
|
||||||
List<String> menuItems = menu.getMenuItems();
|
List<String> menuItems = menu.getMenuItems();
|
||||||
if(featuredMenuItems.contains(id)) {
|
if (featuredMenuItems.contains(id)) {
|
||||||
featuredMenuItems.remove(id);
|
featuredMenuItems.remove(id);
|
||||||
} else if(menuItems.contains(id)) {
|
} else {
|
||||||
menuItems.remove(id);
|
menuItems.remove(id);
|
||||||
}
|
}
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
|
log.debug("delete menu item; " + id);
|
||||||
// menuItemDAO.delete(id);
|
|
||||||
log.debug("delete menu item; "+id);
|
|
||||||
List<String> menuItemsToDelete = new ArrayList<>();
|
List<String> menuItemsToDelete = new ArrayList<>();
|
||||||
menuItemsToDelete.add(id);
|
menuItemsToDelete.add(id);
|
||||||
return deleteMenuItems(menuItemsToDelete, portalPid);
|
return deleteMenuItems(menuItemsToDelete, portalPid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean deleteMenuItems(List<String> menuItems, String portalPid) throws Exception {
|
public Boolean deleteMenuItems(List<String> menuItems, String portalPid) throws Exception {
|
||||||
if(menuItems == null) {
|
if (menuItems == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (String id: menuItems) {
|
for (String id : menuItems) {
|
||||||
MenuItem menuItem = menuItemDAO.findById(id);
|
MenuItem menuItem = this.getMenuItem(id);
|
||||||
|
if (!portalPid.equals(menuItem.getPortalPid())) {
|
||||||
if(!portalPid.equals(menuItem.getPortalPid())) {
|
|
||||||
// EXCEPTION - MismatchingContent
|
// EXCEPTION - MismatchingContent
|
||||||
throw new MismatchingContentException("Delete Menu Items: MenuItem with id: "+id+" has portalPid: "+menuItem.getPortalPid()+" instead of "+portalPid);
|
throw new MismatchingContentException("Delete Menu Items: MenuItem with id: " + id + " has portalPid: " + menuItem.getPortalPid() + " instead of " + portalPid);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMenuItems(menuItem.getItems(), portalPid);
|
deleteMenuItems(menuItem.getItems(), portalPid);
|
||||||
|
if (menuItem.getParentItemId() != null && !menuItem.getParentItemId().isEmpty()) {
|
||||||
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
|
MenuItem parent = this.getMenuItem(menuItem.getParentItemId());
|
||||||
MenuItem parent = menuItemDAO.findById(menuItem.getParentItemId());
|
|
||||||
List<String> siblingsOfDeleted = parent.getItems();
|
List<String> siblingsOfDeleted = parent.getItems();
|
||||||
siblingsOfDeleted.remove(id);
|
siblingsOfDeleted.remove(id);
|
||||||
parent.setItems(siblingsOfDeleted);
|
parent.setItems(siblingsOfDeleted);
|
||||||
menuItemDAO.save(parent);
|
menuItemDAO.save(parent);
|
||||||
}
|
}
|
||||||
|
menuItemDAO.delete(menuItem);
|
||||||
menuItemDAO.delete(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean deleteMenuByPortalPid(String portalPid) throws Exception {
|
public Boolean deleteMenuByPortalPid(String portalPid) throws Exception {
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElse(null);
|
||||||
if(menu != null) {
|
if (menu != null) {
|
||||||
deleteMenuItems(menu.getMenuItems(), portalPid);
|
deleteMenuItems(menu.getMenuItems(), portalPid);
|
||||||
deleteMenuItems(menu.getFeaturedMenuItems(), portalPid);
|
deleteMenuItems(menu.getFeaturedMenuItems(), portalPid);
|
||||||
menuDAO.deleteByPortalPid(portalPid);
|
menuDAO.deleteByPortalPid(portalPid);
|
||||||
|
@ -276,60 +228,44 @@ public class MenuService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean reorderMenuItems(List<MenuItemFull> menuItemsFull, String portalPid) {
|
public Boolean reorderMenuItems(List<MenuItemFull> menuItemsFull, String portalPid) {
|
||||||
List<String> menuItemIds = new ArrayList<>();
|
List<String> menuItemIds = new ArrayList<>();
|
||||||
// menuItemIds = menuItemsFull.stream().map((MenuItem menuItem) -> menuItem.getId()).collect(Collectors.toList());
|
boolean isFeatured = menuItemsFull.get(0).getIsFeatured();
|
||||||
boolean isFeatured = menuItemsFull.get(0).getIsFeatured();
|
|
||||||
String parentId = menuItemsFull.get(0).getParentItemId();
|
String parentId = menuItemsFull.get(0).getParentItemId();
|
||||||
|
for (MenuItemFull menuItem : menuItemsFull) {
|
||||||
for (MenuItemFull menuItem: menuItemsFull) {
|
|
||||||
if (!portalPid.equals(menuItem.getPortalPid())) {
|
if (!portalPid.equals(menuItem.getPortalPid())) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same portalPid");
|
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same portalPid");
|
||||||
}
|
}
|
||||||
if(menuItem.getIsFeatured() != isFeatured) {
|
if (menuItem.getIsFeatured() != isFeatured) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same isFeatured");
|
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same isFeatured");
|
||||||
}
|
}
|
||||||
if((menuItem.getParentItemId() == null && parentId != null) || (parentId == null && menuItem.getParentItemId() != null) || (parentId != null && !menuItem.getParentItemId().equals(parentId))) {
|
if ((menuItem.getParentItemId() == null && parentId != null) || (parentId == null && menuItem.getParentItemId() != null) || (parentId != null && !menuItem.getParentItemId().equals(parentId))) {
|
||||||
// EXCEPTION - MismatchingContent
|
|
||||||
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same parentItemId");
|
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same parentItemId");
|
||||||
}
|
}
|
||||||
menuItemIds.add(menuItem.getId());
|
menuItemIds.add(menuItem.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (parentId != null) {
|
||||||
List<String> savedMenuItems;
|
MenuItem parent = this.getMenuItem(parentId);
|
||||||
if(parentId != null) {
|
this.addSavedMenuItems(parent.getItems(), menuItemIds);
|
||||||
MenuItem parent = menuItemDAO.findById(parentId);
|
|
||||||
savedMenuItems = parent.getItems();
|
|
||||||
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
|
|
||||||
parent.setItems(menuItemIds);
|
|
||||||
menuItemDAO.save(parent);
|
menuItemDAO.save(parent);
|
||||||
} else if(isFeatured) {
|
} else if (isFeatured) {
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElseThrow(() -> new NotFoundException("reorderMenuItems: No Menu found for portalPid: " + portalPid));
|
||||||
savedMenuItems = menu.getFeaturedMenuItems();
|
this.addSavedMenuItems(menu.getMenuItems(), menuItemIds);
|
||||||
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
|
|
||||||
menu.setFeaturedMenuItems(menuItemIds);
|
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
} else {
|
} else {
|
||||||
Menu menu = menuDAO.findByPortalPid(portalPid);
|
Menu menu = menuDAO.findByPortalPid(portalPid).orElseThrow(() -> new NotFoundException("reorderMenuItems: No Menu found for portalPid: " + portalPid));
|
||||||
savedMenuItems = menu.getMenuItems();
|
this.addSavedMenuItems(menu.getMenuItems(), menuItemIds);
|
||||||
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
|
|
||||||
menu.setMenuItems(menuItemIds);
|
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> addSavedMenuItems(List<String> savedMenuItems, List<String> menuItemIds, List<MenuItemFull> menuItemsFull) {
|
private void addSavedMenuItems(List<String> savedMenuItems, List<String> menuItemIds) {
|
||||||
for (String menuId : savedMenuItems) {
|
for (String menuId : savedMenuItems) {
|
||||||
if (!menuItemIds.contains(menuId)) {
|
if (!menuItemIds.contains(menuId)) {
|
||||||
menuItemIds.add(menuId);
|
menuItemIds.add(menuId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menuItemIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,22 +280,20 @@ public class MenuService {
|
||||||
menuItem.setPortalPid(menuItemFull.getPortalPid());
|
menuItem.setPortalPid(menuItemFull.getPortalPid());
|
||||||
menuItem.setParentItemId(menuItemFull.getParentItemId());
|
menuItem.setParentItemId(menuItemFull.getParentItemId());
|
||||||
menuItem.setIsFeatured(menuItemFull.getIsFeatured());
|
menuItem.setIsFeatured(menuItemFull.getIsFeatured());
|
||||||
|
|
||||||
List<MenuItemFull> menuItemsFull = menuItemFull.getItems();
|
List<MenuItemFull> menuItemsFull = menuItemFull.getItems();
|
||||||
List<String> menuItems = new ArrayList<String>();
|
List<String> menuItems = new ArrayList<String>();
|
||||||
if(menuItemsFull != null) {
|
if (menuItemsFull != null) {
|
||||||
for (MenuItemFull childMenuItemFull : menuItemsFull) {
|
for (MenuItemFull childMenuItemFull : menuItemsFull) {
|
||||||
menuItems.add(childMenuItemFull.getId());
|
menuItems.add(childMenuItemFull.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuItem.setItems(menuItems);
|
menuItem.setItems(menuItems);
|
||||||
|
|
||||||
return menuItem;
|
return menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Menu toggleMenu(String pid, String status, String isFeatured) throws Exception {
|
public Menu toggleMenu(String pid, String status, String isFeatured) {
|
||||||
Menu menu = menuDAO.findByPortalPid(pid);
|
Menu menu = menuDAO.findByPortalPid(pid).orElseThrow(() -> new NotFoundException("toggle Menu: No Menu found for portalPid: " + pid));
|
||||||
if(isFeatured != null && Boolean.parseBoolean(isFeatured)) {
|
if (Boolean.parseBoolean(isFeatured)) {
|
||||||
menu.setFeaturedMenuEnabled(Boolean.parseBoolean(status));
|
menu.setFeaturedMenuEnabled(Boolean.parseBoolean(status));
|
||||||
} else {
|
} else {
|
||||||
menu.setMenuEnabled(Boolean.parseBoolean(status));
|
menu.setMenuEnabled(Boolean.parseBoolean(status));
|
||||||
|
@ -368,28 +302,24 @@ public class MenuService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Menu alignMenu(String pid, String alignment) {
|
public Menu alignMenu(String pid, String alignment) {
|
||||||
Menu menu = menuDAO.findByPortalPid(pid);
|
Menu menu = menuDAO.findByPortalPid(pid).orElseThrow(() -> new NotFoundException("align Menu: No Menu found for portalPid: " + pid));
|
||||||
menu.setFeaturedAlignment(alignment);
|
menu.setFeaturedAlignment(alignment);
|
||||||
|
|
||||||
return menuDAO.save(menu);
|
return menuDAO.save(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
public void updatePid(String oldPid, Portal portal) {
|
||||||
log.debug("menu service: updatePid");
|
log.debug("menu service: updatePid");
|
||||||
Menu menu = menuDAO.findByPortalPid(old_pid);
|
Menu menu = menuDAO.findByPortalPid(oldPid).orElse(null);
|
||||||
if(menu != null) {
|
if (menu != null) {
|
||||||
menu.setPortalPid(new_pid);
|
menu.setPortalPid(portal.getPid());
|
||||||
menuDAO.save(menu);
|
menuDAO.save(menu);
|
||||||
log.debug("menu saved!");
|
log.debug("menu saved!");
|
||||||
}
|
}
|
||||||
|
List<MenuItem> menuItems = menuItemDAO.findByPortalPid(oldPid);
|
||||||
List<MenuItem> menuItems = menuItemDAO.findByPortalPid(old_pid);
|
menuItems.forEach(menuItem -> {
|
||||||
if(menuItems != null) {
|
menuItem.setPortalPid(portal.getPid());
|
||||||
menuItems.forEach(menuItem -> {
|
menuItemDAO.save(menuItem);
|
||||||
menuItem.setPortalPid(new_pid);
|
log.debug("menuItem saved!");
|
||||||
menuItemDAO.save(menuItem);
|
});
|
||||||
log.debug("menuItem saved!");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.utils.RolesUtils;
|
||||||
|
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -13,26 +16,56 @@ import java.util.List;
|
||||||
public class NotificationsService {
|
public class NotificationsService {
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
private final NotificationsDAO notificationsDAO;
|
||||||
private NotificationsDAO notificationsDAO;
|
private final RolesUtils rolesUtils;
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
@Autowired
|
||||||
log.debug("notifications service: updatePid");
|
public NotificationsService(NotificationsDAO notificationsDAO, RolesUtils rolesUtils) {
|
||||||
List<Notifications> notifications = notificationsDAO.findByPortalPid(old_pid);
|
this.notificationsDAO = notificationsDAO;
|
||||||
|
this.rolesUtils = rolesUtils;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notifications getUserNotifications(Portal portal) {
|
||||||
|
return this.notificationsDAO.findByManagerEmailAndPortalPid(rolesUtils.getEmail(), portal.getPid()).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Notifications> getAllNotifications(Portal portal) {
|
||||||
|
return this.notificationsDAO.findByPortalPid(portal.getPid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUserNotifications(Portal portal) {
|
||||||
|
Notifications notifications = getUserNotifications(portal);
|
||||||
if(notifications != null) {
|
if(notifications != null) {
|
||||||
|
notificationsDAO.delete(notifications);
|
||||||
|
} else {
|
||||||
|
throw new NotFoundException("Notifications settings for community with pid: " + portal.getPid() + " and user email: " + rolesUtils.getEmail() + " not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notifications save(Portal portal, Notifications notifications) {
|
||||||
|
Notifications saved = this.getUserNotifications(portal);
|
||||||
|
if(saved != null) {
|
||||||
|
notifications.setId(saved.getId());
|
||||||
|
}
|
||||||
|
notifications.setManagerEmail(this.rolesUtils.getEmail());
|
||||||
|
notifications.setAaiId(this.rolesUtils.getAaiId());
|
||||||
|
notifications.setPortalPid(portal.getPid());
|
||||||
|
return notificationsDAO.save(notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePid(String oldPid, Portal portal) {
|
||||||
|
log.debug("notifications service: updatePid");
|
||||||
|
List<Notifications> notifications = notificationsDAO.findByPortalPid(oldPid);
|
||||||
|
if (notifications != null) {
|
||||||
notifications.forEach(notification -> {
|
notifications.forEach(notification -> {
|
||||||
notification.setPortalPid(new_pid);
|
notification.setPortalPid(portal.getPid());
|
||||||
notificationsDAO.save(notification);
|
notificationsDAO.save(notification);
|
||||||
});
|
});
|
||||||
log.debug("notifications saved!");
|
log.debug("notifications saved!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByPid(String pid) {
|
public void deleteByPid(String pid) {
|
||||||
// TODO check maybe we can delete by portalId without find first
|
notificationsDAO.deleteAll(notificationsDAO.findByPortalPid(pid));
|
||||||
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid);
|
|
||||||
if(notifications != null) {
|
|
||||||
notifications.forEach(notification -> notificationsDAO.delete(notification.getId()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.services;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.StatisticsDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class StatisticsService {
|
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StatisticsDAO statisticsDAO;
|
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
|
||||||
log.debug("statistics service: updatePid");
|
|
||||||
Statistics statistics = statisticsDAO.findByPid(old_pid);
|
|
||||||
log.debug("statistics service: statistics id: "+(statistics != null ? statistics.getId() : "not found"));
|
|
||||||
if(statistics != null) {
|
|
||||||
statistics.setPid(new_pid);
|
|
||||||
log.debug("statistics service: new statistics pid: " + statistics.getPid());
|
|
||||||
statisticsDAO.save(statistics);
|
|
||||||
log.debug("statistics saved!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createPortalStatistics(String pid) {
|
|
||||||
Statistics statistics = new Statistics(pid);
|
|
||||||
statisticsDAO.save(statistics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteByPid(String pid) {
|
|
||||||
Statistics stats = statisticsDAO.findByPid(pid);
|
|
||||||
if(stats != null) {
|
|
||||||
statisticsDAO.delete(stats.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools.services;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SubscriberService {
|
|
||||||
private final Logger log = LogManager.getLogger(this.getClass());
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortalSubscribersDAO portalSubscribersDAO;
|
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
|
||||||
log.debug("subscriber service: updatePid");
|
|
||||||
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(old_pid);
|
|
||||||
log.debug("subscriber service: portalSubscribers id: "+(portalSubscribers != null ? portalSubscribers.getId() : "not found"));
|
|
||||||
if(portalSubscribers != null) {
|
|
||||||
portalSubscribers.setPid(new_pid);
|
|
||||||
log.debug("subscriber portalSubscribers: new portalSubscribers pid: " + portalSubscribers.getPid());
|
|
||||||
portalSubscribersDAO.save(portalSubscribers);
|
|
||||||
log.debug("portalSubscribers saved!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createPortalSubscribers(String pid) {
|
|
||||||
PortalSubscribers portalSubscribers = new PortalSubscribers(pid);
|
|
||||||
portalSubscribersDAO.save(portalSubscribers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePortalSubscribers(String pid) {
|
|
||||||
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(pid);
|
|
||||||
if(portalSubscribers != null) {
|
|
||||||
portalSubscribersDAO.delete(portalSubscribers.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +1,4 @@
|
||||||
#dev
|
|
||||||
#admintool.security.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
|
||||||
#admintool.security.originServer = .di.uoa.gr
|
|
||||||
#admintool.security.postsAllowed = /contact,/contact/
|
|
||||||
admintool.mail.host = smtp.gmail.com
|
|
||||||
admintool.mail.port = 587
|
|
||||||
admintool.mail.auth = true
|
|
||||||
admintool.mail.from = openaire.test@gmail.com
|
|
||||||
admintool.mail.username = openaire.test@gmail.com
|
|
||||||
admintool.mail.password =
|
|
||||||
admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
|
|
||||||
admintool.mongodb.host=localhost
|
|
||||||
admintool.mongodb.port=27017
|
|
||||||
admintool.mongodb.database=openaire_admin
|
|
||||||
admintool.managers.api.id = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/id
|
|
||||||
admintool.managers.api.email = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email
|
|
||||||
admintool.globalVars.buildDate=@timestamp@
|
|
||||||
admintool.globalVars.version=@project.version@
|
|
||||||
admintool.cache.url = https://beta.{community}.openaire.eu/purge/
|
|
||||||
|
|
||||||
#beta
|
|
||||||
#admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
|
|
||||||
#admintool.security.originServer = .openaire.eu
|
|
||||||
#admintool.security.postsAllowed = /contact,/contact/
|
|
||||||
#admintool.mail.host = bwnmail.icm.edu.pl
|
|
||||||
#admintool.mail.port = 25
|
|
||||||
#admintool.mail.auth = false
|
|
||||||
#admintool.mail.username = no-reply@openaire.eu
|
|
||||||
#admintool.mail.from = no-reply@beta.openaire.eu
|
|
||||||
#admintool.mail.password =
|
|
||||||
#admintool.google.secret = 6LezhVIUAAAAAP97HFoWsqU9R1zLKptnA4YBg8FX
|
|
||||||
#admintool.mongodb.host=beta.services.openaire.eu
|
|
||||||
#admintool.mongodb.port=27017
|
|
||||||
#admintool.mongodb.database=openaireconnect
|
|
||||||
|
|
||||||
|
|
||||||
#production
|
|
||||||
#admintool.security.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
|
|
||||||
#admintool.security.originServer = .openaire.eu
|
|
||||||
#admintool.security.postsAllowed = /contact,/contact/
|
|
||||||
#admintool.mail.host = bwnmail.icm.edu.pl
|
|
||||||
#admintool.mail.port = 25
|
|
||||||
#admintool.mail.auth = false
|
|
||||||
#admintool.mail.username = no-reply@openaire.eu
|
|
||||||
#admintool.mail.from = no-reply@www.openaire.eu
|
|
||||||
#admintool.mail.password =
|
|
||||||
#admintool.google.secret = 6LezhVIUAAAAAP97HFoWsqU9R1zLKptnA4YBg8FX
|
|
||||||
#admintool.mongodb.host=localhost
|
|
||||||
#admintool.mongodb.port=27017
|
|
||||||
#admintool.mongodb.database=openaireconnect
|
|
||||||
#admintool.mongodb.username=dnet8480
|
|
||||||
#admintool.mongodb.password=
|
|
||||||
|
|
||||||
#static properties
|
#static properties
|
||||||
api.title = Uoa Admin Tools Documentation Swagger
|
api.title = Uoa Admin Tools Documentation Swagger
|
||||||
api.description = Uoa Admin Tools is a service which is saving and serving helptexts and dynamic content
|
api.description = Uoa Admin Tools is a service which is saving and serving help-texts and dynamic content
|
||||||
api.version = ${project.version}
|
api.version = ${project.version}
|
||||||
|
|
|
@ -1,19 +1,2 @@
|
||||||
#mongodb
|
# temp until refactoring the code in admin tools library
|
||||||
#beta
|
spring.main.allow-circular-references=true
|
||||||
#spring.data.mongodb.host=beta.services.openaire.eu
|
|
||||||
#spring.data.mongodb.port=27017
|
|
||||||
#spring.data.mongodb.database=openaireconnect
|
|
||||||
|
|
||||||
#production
|
|
||||||
#spring.data.mongodb.host=localhost
|
|
||||||
#spring.data.mongodb.port=27017
|
|
||||||
#spring.data.mongodb.database=openaireconnect
|
|
||||||
#spring.data.mongodb.authentication-database=openaireconnect
|
|
||||||
#spring.data.mongodb.username=dnet8480
|
|
||||||
#spring.data.mongodb.password=...
|
|
||||||
|
|
||||||
|
|
||||||
#dev
|
|
||||||
#spring.data.mongodb.host=localhost
|
|
||||||
#spring.data.mongodb.port=27017
|
|
||||||
#spring.data.mongodb.database=openaire_admin
|
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.*;
|
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class NotificationsTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortalDAO communityDAO;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NotificationsDAO notificationsDAO;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
String mail = "sofie.mpl@gmail.com";
|
|
||||||
String id="ni";
|
|
||||||
System.out.println(notificationsDAO.findByPortalPid(id));
|
|
||||||
|
|
||||||
Notifications notifications = notificationsDAO.findByManagerEmailAndPortalPid(mail , id);
|
|
||||||
if(notifications == null){
|
|
||||||
notifications = new Notifications();
|
|
||||||
notifications.setPortalPid(id);
|
|
||||||
notifications.setManagerEmail(mail);
|
|
||||||
}
|
|
||||||
notifications.setNotifyForNewManagers(false);
|
|
||||||
notifications.setNotifyForNewSubscribers(false);
|
|
||||||
|
|
||||||
notificationsDAO.save(notifications);
|
|
||||||
System.out.println(notificationsDAO.findByPortalPid(id));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void remove() {
|
|
||||||
List <Portal> communities = communityDAO.findAll();
|
|
||||||
for(Portal com : communities){
|
|
||||||
List <Notifications> notificationsList = notificationsDAO.findByPortalPid(com.getPid());
|
|
||||||
for(Notifications notifications:notificationsList){
|
|
||||||
// notificationsDAO.delete(notifications.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,235 +0,0 @@
|
||||||
package eu.dnetlib.uoaadmintools;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.*;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.*;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class UoaAdminToolsApplicationTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortalDAO communityDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EntityDAO entityDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PageDAO pageDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PageHelpContentDAO pageHelpContentDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DivIdDAO divIdDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StatisticsDAO statisticsDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SubscriberDAO subscriberDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortalSubscribersDAO portalSubscribersDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailSender emailSender;
|
|
||||||
/*
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createAllEntities() {
|
|
||||||
Map<String, String> entities = new HashMap<>();
|
|
||||||
entities.put("Publication", "publication");
|
|
||||||
entities.put("Research Data", "dataset");
|
|
||||||
entiites.put("Software", "software");
|
|
||||||
entities.put("Project", "project");
|
|
||||||
entities.put("Organization", "organization");
|
|
||||||
entities.put("Content Provider", "datasource");
|
|
||||||
|
|
||||||
for(entry<String, String> entr : entities.entrySet()) {
|
|
||||||
Entity entity = new Entity();
|
|
||||||
entity.setName(entr.getKey());
|
|
||||||
entity.setPid(entr.getValue());
|
|
||||||
entityDAO.save(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createAllPages() {
|
|
||||||
String publication = entityDAO.findByPid("publication").getId();
|
|
||||||
String dataset = entityDAO.findByPid("dataset").getId();
|
|
||||||
String software = entityDAO.findByPid("software").getId();
|
|
||||||
String project = entityDAO.findByPid("project").getId();
|
|
||||||
String organization = entityDAO.findByPid("organization").getId();
|
|
||||||
String datasource = entityDAO.findByPid("datasource").getId();
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, List<String>> pages = new HashMap<>();
|
|
||||||
pages.put("Search Publications", new ArrayList<>());
|
|
||||||
pages.get("Search Publications").add()
|
|
||||||
|
|
||||||
//entities.add("5a300ee4c97a7d2c000b9e9d"); // Publication
|
|
||||||
entities.add("5a319f8bc97a7d241ebddf75"); // Research Data
|
|
||||||
|
|
||||||
|
|
||||||
Page page = new Page();
|
|
||||||
page.setName("Search Research Data");
|
|
||||||
page.setRoute("/search/find/datasets");
|
|
||||||
page.setType("search");
|
|
||||||
page.setEntities(entities);
|
|
||||||
pageDAO.save(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteAllEntities() {
|
|
||||||
List<Entity> entities = entityDAO.findAll();
|
|
||||||
for(Entity entity : entities) {
|
|
||||||
entityDAO.delete(entity.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteAllCommunities() {
|
|
||||||
List<Community> communities = communityDAO.findAll();
|
|
||||||
for(Community community : communities) {
|
|
||||||
communityDAO.delete(community.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteAllPages() {
|
|
||||||
List<Page> pages = pageDAO.findAll();
|
|
||||||
for(Page page : pages) {
|
|
||||||
pageDAO.delete(page.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteAllPageContents() {
|
|
||||||
List<PageHelpContent> pageHelpContents = pageHelpContentDAO.findAll();
|
|
||||||
for(PageHelpContent pageHelpContent : pageHelpContents) {
|
|
||||||
pageHelpContentDAO.delete(pageHelpContent.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createEntity() {
|
|
||||||
Entity entity = new Entity();
|
|
||||||
entity.setName("Publication");
|
|
||||||
entityDAO.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createPage() {
|
|
||||||
List<String> entities = new ArrayList<String>();
|
|
||||||
//entities.add("5a300ee4c97a7d2c000b9e9d"); // Publication
|
|
||||||
entities.add("5a319f8bc97a7d241ebddf75"); // Research Data
|
|
||||||
|
|
||||||
|
|
||||||
Page page = new Page();
|
|
||||||
page.setName("Search Research Data");
|
|
||||||
page.setRoute("/search/find/datasets");
|
|
||||||
page.setType("search");
|
|
||||||
page.setEntities(entities);
|
|
||||||
pageDAO.save(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createCommunity() {
|
|
||||||
Map<String, Boolean> entities = new HashMap<String, Boolean>();
|
|
||||||
//entities.put("5a300ee4c97a7d2c000b9e9d", true); // Publication
|
|
||||||
entities.put("5a319f8bc97a7d241ebddf75", false); // Research Data
|
|
||||||
//entities.put("5a3064f9c97a7d4964408ee0", false); // Software
|
|
||||||
//entities.put("5a30652ec97a7d4964408ee1", false); // Organization
|
|
||||||
//entities.put("5a306539c97a7d4964408ee2", false); // Project
|
|
||||||
//entities.put("5a30654dc97a7d4964408ee3", false); // Content Provider
|
|
||||||
|
|
||||||
Map<String, Boolean> pages = new HashMap<String, Boolean>();
|
|
||||||
//pages.put("5a30191ac97a7d3a7fa77362", true); // Search Publications
|
|
||||||
pages.put("5a31a4cac97a7d28468f0f5c", false); // Search Research Data
|
|
||||||
//pages.put("5a30657ac97a7d4964408ee4", false); // Search Software
|
|
||||||
//pages.put("5a30eeffc97a7d74234434ad", false); // Search Organizations
|
|
||||||
//pages.put("5a30efd9c97a7d7609b77ca5", false); // Search Projects
|
|
||||||
//pages.put("5a30f08bc97a7d7609b77ca7", false); // Search Content Providers
|
|
||||||
|
|
||||||
//pages.put("5a300f19c97a7d2c6e084b9f", false); // Test
|
|
||||||
|
|
||||||
Community community = new Community();
|
|
||||||
community.setName("Test Community");
|
|
||||||
community.setEntities(entities);
|
|
||||||
community.setPages(pages);
|
|
||||||
communityDAO.save(community);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void createStatistics() {
|
|
||||||
// statisticsDAO.deleteAll();
|
|
||||||
// List<Community> communities = communityDAO.findAll();
|
|
||||||
// for(Community c:communities){
|
|
||||||
//
|
|
||||||
// String pid = c.getPid();
|
|
||||||
// System.out.println("Community :" +pid);
|
|
||||||
// Statistics stats = statisticsDAO.findByPid(pid);
|
|
||||||
// if(stats == null){
|
|
||||||
// Statistics statistics = new Statistics(pid);
|
|
||||||
// statisticsDAO.save(statistics);
|
|
||||||
// System.out.println("Saved stats for :" +pid);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void deleteStatistics() {
|
|
||||||
// statisticsDAO.deleteAll();
|
|
||||||
// }
|
|
||||||
@Test
|
|
||||||
public void createCommunitySubscribers() {
|
|
||||||
|
|
||||||
// List<Community> communities = communityDAO.findAll();
|
|
||||||
// for(Community c:communities){
|
|
||||||
// String pid = c.getPid();
|
|
||||||
// System.out.println("Community :" +pid);
|
|
||||||
// PortalSubscribers communitySubscribers= portalSubscribersDAO.findByPid(pid);
|
|
||||||
// if(communitySubscribers == null){
|
|
||||||
// communitySubscribers = new PortalSubscribers(pid);
|
|
||||||
// portalSubscribersDAO.save(communitySubscribers);
|
|
||||||
// System.out.println("Saved community subscribers for :" +pid);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void testPages() {
|
|
||||||
//
|
|
||||||
// System.out.println( pageDAO.findByConnect(false).size());
|
|
||||||
// for (Page p: pageDAO.findByConnect(false) ){
|
|
||||||
// System.out.println(p.getRoute()+" Con: "+p.getConnect()+" Op: "+p.getOpenaire());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
String mail = "kgalouni@di.uoa.gr";
|
|
||||||
List<String> mails = new ArrayList<>();
|
|
||||||
mails.add(mail);
|
|
||||||
emailSender.send(mails, "Test Subject", "Test Body", false);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue