removing JHipster
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng;
|
||||
|
||||
import org.hostsharing.hsadminng.config.DefaultProfileUtil;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
/**
|
||||
* This is a helper Java class that provides an alternative to creating a web.xml.
|
||||
* This will be invoked only when the application is deployed to a Servlet container like Tomcat, JBoss etc.
|
||||
*/
|
||||
public class ApplicationWebXml extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
/**
|
||||
* set a default to use when no profile is configured.
|
||||
*/
|
||||
DefaultProfileUtil.addDefaultProfile(application.application());
|
||||
return application.sources(HsadminNgApp.class);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng;
|
||||
|
||||
import org.hostsharing.hsadminng.config.ApplicationProperties;
|
||||
import org.hostsharing.hsadminng.config.DefaultProfileUtil;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties({ LiquibaseProperties.class, ApplicationProperties.class })
|
||||
public class HsadminNgApp {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(HsadminNgApp.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public HsadminNgApp(Environment env) {
|
||||
this.env = env;
|
||||
|
||||
// TODO mhoennig rather use @PostConstruct or something more decentral
|
||||
Role.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes hsadminNg.
|
||||
* <p>
|
||||
* Spring profiles can be configured with a program argument --spring.profiles.active=your-active-profile
|
||||
* <p>
|
||||
* You can find more information on how profiles work with JHipster on
|
||||
* <a href="https://www.jhipster.tech/profiles/">https://www.jhipster.tech/profiles/</a>.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initApplication() {
|
||||
|
||||
Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
|
||||
if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
|
||||
&& activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
|
||||
log.error(
|
||||
"You have misconfigured your application! It should not run " +
|
||||
"with both the 'dev' and 'prod' profiles at the same time.");
|
||||
}
|
||||
if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
|
||||
&& activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_CLOUD)) {
|
||||
log.error(
|
||||
"You have misconfigured your application! It should not " +
|
||||
"run with both the 'dev' and 'cloud' profiles at the same time.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method, used to run the application.
|
||||
*
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(HsadminNgApp.class);
|
||||
DefaultProfileUtil.addDefaultProfile(app);
|
||||
Environment env = app.run(args).getEnvironment();
|
||||
logApplicationStartup(env);
|
||||
}
|
||||
|
||||
private static void logApplicationStartup(Environment env) {
|
||||
String protocol = "http";
|
||||
if (env.getProperty("server.ssl.key-store") != null) {
|
||||
protocol = "https";
|
||||
}
|
||||
String serverPort = env.getProperty("server.port");
|
||||
String contextPath = env.getProperty("server.servlet.context-path");
|
||||
if (StringUtils.isBlank(contextPath)) {
|
||||
contextPath = "/";
|
||||
}
|
||||
String hostAddress = "localhost";
|
||||
try {
|
||||
hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
log.warn("The host name could not be determined, using `localhost` as fallback");
|
||||
}
|
||||
log.info(
|
||||
"\n----------------------------------------------------------\n\t" +
|
||||
"Application '{}' is running! Access URLs:\n\t" +
|
||||
"Local: \t\t{}://localhost:{}{}\n\t" +
|
||||
"External: \t{}://{}:{}{}\n\t" +
|
||||
"Profile(s): \t{}\n----------------------------------------------------------",
|
||||
env.getProperty("spring.application.name"),
|
||||
protocol,
|
||||
serverPort,
|
||||
contextPath,
|
||||
protocol,
|
||||
hostAddress,
|
||||
serverPort,
|
||||
contextPath,
|
||||
env.getActiveProfiles());
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.aop.logging;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Aspect for logging execution of service and repository Spring components.
|
||||
*
|
||||
* By default, it only runs with the "dev" profile.
|
||||
*/
|
||||
@Aspect
|
||||
public class LoggingAspect {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public LoggingAspect(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointcut that matches all repositories, services and Web REST endpoints.
|
||||
*/
|
||||
@Pointcut("within(@org.springframework.stereotype.Repository *)" +
|
||||
" || within(@org.springframework.stereotype.Service *)" +
|
||||
" || within(@org.springframework.web.bind.annotation.RestController *)")
|
||||
public void springBeanPointcut() {
|
||||
// Method is empty as this is just a Pointcut, the implementations are in the advices.
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointcut that matches all Spring beans in the application's main packages.
|
||||
*/
|
||||
@Pointcut("within(org.hostsharing.hsadminng.repository..*)" +
|
||||
" || within(org.hostsharing.hsadminng.service..*)" +
|
||||
" || within(org.hostsharing.hsadminng.web.rest..*)")
|
||||
public void applicationPackagePointcut() {
|
||||
// Method is empty as this is just a Pointcut, the implementations are in the advices.
|
||||
}
|
||||
|
||||
/**
|
||||
* Advice that logs methods throwing exceptions.
|
||||
*
|
||||
* @param joinPoint join point for advice
|
||||
* @param e exception
|
||||
*/
|
||||
@AfterThrowing(pointcut = "applicationPackagePointcut() && springBeanPointcut()", throwing = "e")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
|
||||
log.error(
|
||||
"Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'",
|
||||
joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(),
|
||||
e.getCause() != null ? e.getCause() : "NULL",
|
||||
e.getMessage(),
|
||||
e);
|
||||
|
||||
} else {
|
||||
log.error(
|
||||
"Exception in {}.{}() with cause = {}",
|
||||
joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(),
|
||||
e.getCause() != null ? e.getCause() : "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Advice that logs when a method is entered and exited.
|
||||
*
|
||||
* @param joinPoint join point for advice
|
||||
* @return result
|
||||
* @throws Throwable throws IllegalArgumentException
|
||||
*/
|
||||
@Around("applicationPackagePointcut() && springBeanPointcut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"Enter: {}.{}() with argument[s] = {}",
|
||||
joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(),
|
||||
Arrays.toString(joinPoint.getArgs()));
|
||||
}
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"Exit: {}.{}() with result = {}",
|
||||
joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(),
|
||||
result);
|
||||
}
|
||||
return result;
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error(
|
||||
"Illegal argument: {} in {}.{}()",
|
||||
Arrays.toString(joinPoint.getArgs()),
|
||||
joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties specific to Hsadmin Ng.
|
||||
* <p>
|
||||
* Properties are configured in the application.yml file.
|
||||
* See {@link io.github.jhipster.config.JHipsterProperties} for a good example.
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
|
||||
public class ApplicationProperties {
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor;
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.*;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
public class AsyncConfiguration implements AsyncConfigurer, SchedulingConfigurer {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
public AsyncConfiguration(JHipsterProperties jHipsterProperties) {
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean(name = "taskExecutor")
|
||||
public Executor getAsyncExecutor() {
|
||||
log.debug("Creating Async Task Executor");
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
|
||||
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
|
||||
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
|
||||
executor.setThreadNamePrefix("hsadmin-ng-Executor-");
|
||||
return new ExceptionHandlingAsyncTaskExecutor(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return new SimpleAsyncUncaughtExceptionHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.setScheduler(scheduledTaskExecutor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Executor scheduledTaskExecutor() {
|
||||
return Executors.newScheduledThreadPool(jHipsterProperties.getAsync().getCorePoolSize());
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
|
||||
import org.ehcache.config.builders.*;
|
||||
import org.ehcache.jsr107.Eh107Configuration;
|
||||
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CacheConfiguration {
|
||||
|
||||
private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;
|
||||
|
||||
public CacheConfiguration(JHipsterProperties jHipsterProperties) {
|
||||
JHipsterProperties.Cache.Ehcache ehcache = jHipsterProperties.getCache().getEhcache();
|
||||
|
||||
jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(
|
||||
CacheConfigurationBuilder.newCacheConfigurationBuilder(
|
||||
Object.class,
|
||||
Object.class,
|
||||
ResourcePoolsBuilder.heap(ehcache.getMaxEntries()))
|
||||
.withExpiry(
|
||||
ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(ehcache.getTimeToLiveSeconds())))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JCacheManagerCustomizer cacheManagerCustomizer() {
|
||||
return cm -> {
|
||||
cm.createCache(org.hostsharing.hsadminng.repository.UserRepository.USERS_BY_LOGIN_CACHE, jcacheConfiguration);
|
||||
cm.createCache(org.hostsharing.hsadminng.repository.UserRepository.USERS_BY_EMAIL_CACHE, jcacheConfiguration);
|
||||
// jhipster-needle-ehcache-add-entry
|
||||
|
||||
cm.createCache(
|
||||
org.hostsharing.hsadminng.repository.UserRoleAssignmentRepository.CURRENT_USER_ROLE_ASSIGNMENTS_CACHE,
|
||||
jcacheConfiguration);
|
||||
};
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.config.java.AbstractCloudConfig;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Profile(JHipsterConstants.SPRING_PROFILE_CLOUD)
|
||||
public class CloudDatabaseConfiguration extends AbstractCloudConfig {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CloudDatabaseConfiguration.class);
|
||||
|
||||
private static final String CLOUD_CONFIGURATION_HIKARI_PREFIX = "spring.datasource.hikari";
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(CLOUD_CONFIGURATION_HIKARI_PREFIX)
|
||||
public DataSource dataSource() {
|
||||
log.info("Configuring JDBC datasource from a cloud provider");
|
||||
return connectionFactory().dataSource();
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
/**
|
||||
* Application constants.
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
// Regex for acceptable logins
|
||||
public static final String LOGIN_REGEX = "^[_.@A-Za-z0-9-]*$";
|
||||
|
||||
public static final String SYSTEM_ACCOUNT = "system";
|
||||
public static final String ANONYMOUS_USER = "anonymoususer";
|
||||
public static final String DEFAULT_LANGUAGE = "de";
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
import io.github.jhipster.config.h2.H2ConfigurationHelper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories("org.hostsharing.hsadminng.repository")
|
||||
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
|
||||
@EnableTransactionManagement
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public DatabaseConfiguration(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the TCP port for the H2 database, so it is available remotely.
|
||||
*
|
||||
* @return the H2 database TCP server
|
||||
* @throws SQLException if the server failed to start
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
|
||||
public Object h2TCPServer() throws SQLException {
|
||||
String port = getValidPortForH2();
|
||||
log.debug("H2 database is available on port {}", port);
|
||||
return H2ConfigurationHelper.createServer(port);
|
||||
}
|
||||
|
||||
private String getValidPortForH2() {
|
||||
int port = Integer.parseInt(env.getProperty("server.port"));
|
||||
if (port < 10000) {
|
||||
port = 10000 + port;
|
||||
} else {
|
||||
if (port < 63536) {
|
||||
port = port + 2000;
|
||||
} else {
|
||||
port = port - 2000;
|
||||
}
|
||||
}
|
||||
return String.valueOf(port);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Configure the converters to use the ISO format for dates by default.
|
||||
*/
|
||||
@Configuration
|
||||
public class DateTimeFormatConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
|
||||
registrar.setUseIsoFormat(true);
|
||||
registrar.registerFormatters(registry);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Utility class to load a Spring profile to be used as default
|
||||
* when there is no <code>spring.profiles.active</code> set in the environment or as command line argument.
|
||||
* If the value is not available in <code>application.yml</code> then <code>dev</code> profile will be used as default.
|
||||
*/
|
||||
public final class DefaultProfileUtil {
|
||||
|
||||
private static final String SPRING_PROFILE_DEFAULT = "spring.profiles.default";
|
||||
|
||||
private DefaultProfileUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a default to use when no profile is configured.
|
||||
*
|
||||
* @param app the Spring application
|
||||
*/
|
||||
public static void addDefaultProfile(SpringApplication app) {
|
||||
Map<String, Object> defProperties = new HashMap<>();
|
||||
/*
|
||||
* The default profile to use when no other profiles are defined
|
||||
* This cannot be set in the <code>application.yml</code> file.
|
||||
* See https://github.com/spring-projects/spring-boot/issues/1219
|
||||
*/
|
||||
defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
|
||||
app.setDefaultProperties(defProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profiles that are applied else get default profiles.
|
||||
*
|
||||
* @param env spring environment
|
||||
* @return profiles
|
||||
*/
|
||||
public static String[] getActiveProfiles(Environment env) {
|
||||
String[] profiles = env.getActiveProfiles();
|
||||
if (profiles.length == 0) {
|
||||
return env.getDefaultProfiles();
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.zalando.problem.ProblemModule;
|
||||
import org.zalando.problem.violations.ConstraintViolationProblemModule;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfiguration {
|
||||
|
||||
/**
|
||||
* Support for Java date and time API.
|
||||
*
|
||||
* @return the corresponding Jackson module.
|
||||
*/
|
||||
@Bean
|
||||
public JavaTimeModule javaTimeModule() {
|
||||
return new JavaTimeModule();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jdk8Module jdk8TimeModule() {
|
||||
return new Jdk8Module();
|
||||
}
|
||||
|
||||
/*
|
||||
* Support for Hibernate types in Jackson.
|
||||
*/
|
||||
@Bean
|
||||
public Hibernate5Module hibernate5Module() {
|
||||
return new Hibernate5Module();
|
||||
}
|
||||
|
||||
/*
|
||||
* Jackson Afterburner module to speed up serialization/deserialization.
|
||||
*/
|
||||
@Bean
|
||||
public AfterburnerModule afterburnerModule() {
|
||||
return new AfterburnerModule();
|
||||
}
|
||||
|
||||
/*
|
||||
* Module for serialization/deserialization of RFC7807 Problem.
|
||||
*/
|
||||
@Bean
|
||||
ProblemModule problemModule() {
|
||||
return new ProblemModule();
|
||||
}
|
||||
|
||||
/*
|
||||
* Module for serialization/deserialization of ConstraintViolationProblem.
|
||||
*/
|
||||
@Bean
|
||||
ConstraintViolationProblemModule constraintViolationProblemModule() {
|
||||
return new ConstraintViolationProblemModule();
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
import io.github.jhipster.config.liquibase.AsyncSpringLiquibase;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class LiquibaseConfiguration {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(LiquibaseConfiguration.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public LiquibaseConfiguration(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SpringLiquibase liquibase(
|
||||
@Qualifier("taskExecutor") TaskExecutor taskExecutor,
|
||||
DataSource dataSource,
|
||||
LiquibaseProperties liquibaseProperties) {
|
||||
|
||||
// Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start asynchronously
|
||||
SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
|
||||
liquibase.setDataSource(dataSource);
|
||||
liquibase.setChangeLog("classpath:config/liquibase/master.xml");
|
||||
liquibase.setContexts(liquibaseProperties.getContexts());
|
||||
liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
|
||||
liquibase.setDropFirst(liquibaseProperties.isDropFirst());
|
||||
liquibase.setChangeLogParameters(liquibaseProperties.getParameters());
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) {
|
||||
liquibase.setShouldRun(false);
|
||||
} else {
|
||||
liquibase.setShouldRun(liquibaseProperties.isEnabled());
|
||||
log.debug("Configuring Liquibase");
|
||||
}
|
||||
return liquibase;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import io.github.jhipster.config.locale.AngularCookieLocaleResolver;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||
|
||||
@Configuration
|
||||
public class LocaleConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean(name = "localeResolver")
|
||||
public LocaleResolver localeResolver() {
|
||||
AngularCookieLocaleResolver cookieLocaleResolver = new AngularCookieLocaleResolver();
|
||||
cookieLocaleResolver.setCookieName("NG_TRANSLATE_LANG_KEY");
|
||||
return cookieLocaleResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
|
||||
localeChangeInterceptor.setParamName("language");
|
||||
registry.addInterceptor(localeChangeInterceptor);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import org.hostsharing.hsadminng.aop.logging.LoggingAspect;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@Configuration
|
||||
@EnableAspectJAutoProxy
|
||||
public class LoggingAspectConfiguration {
|
||||
|
||||
@Bean
|
||||
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
|
||||
public LoggingAspect loggingAspect(Environment env) {
|
||||
return new LoggingAspect(env);
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import ch.qos.logback.classic.AsyncAppender;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.boolex.OnMarkerEvaluator;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.spi.LoggerContextListener;
|
||||
import ch.qos.logback.core.Appender;
|
||||
import ch.qos.logback.core.filter.EvaluatorFilter;
|
||||
import ch.qos.logback.core.spi.ContextAwareBase;
|
||||
import ch.qos.logback.core.spi.FilterReply;
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
import net.logstash.logback.appender.LogstashTcpSocketAppender;
|
||||
import net.logstash.logback.encoder.LogstashEncoder;
|
||||
import net.logstash.logback.stacktrace.ShortenedThrowableConverter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Iterator;
|
||||
|
||||
@Configuration
|
||||
public class LoggingConfiguration {
|
||||
|
||||
private static final String LOGSTASH_APPENDER_NAME = "LOGSTASH";
|
||||
|
||||
private static final String ASYNC_LOGSTASH_APPENDER_NAME = "ASYNC_LOGSTASH";
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(LoggingConfiguration.class);
|
||||
|
||||
private LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
|
||||
private final String appName;
|
||||
|
||||
private final String serverPort;
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
public LoggingConfiguration(
|
||||
@Value("${spring.application.name}") String appName,
|
||||
@Value("${server.port}") String serverPort,
|
||||
JHipsterProperties jHipsterProperties) {
|
||||
this.appName = appName;
|
||||
this.serverPort = serverPort;
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
if (jHipsterProperties.getLogging().getLogstash().isEnabled()) {
|
||||
addLogstashAppender(context);
|
||||
addContextListener(context);
|
||||
}
|
||||
if (jHipsterProperties.getMetrics().getLogs().isEnabled()) {
|
||||
setMetricsMarkerLogbackFilter(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void addContextListener(LoggerContext context) {
|
||||
LogbackLoggerContextListener loggerContextListener = new LogbackLoggerContextListener();
|
||||
loggerContextListener.setContext(context);
|
||||
context.addListener(loggerContextListener);
|
||||
}
|
||||
|
||||
private void addLogstashAppender(LoggerContext context) {
|
||||
log.info("Initializing Logstash logging");
|
||||
|
||||
LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
|
||||
logstashAppender.setName(LOGSTASH_APPENDER_NAME);
|
||||
logstashAppender.setContext(context);
|
||||
String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";
|
||||
|
||||
// More documentation is available at: https://github.com/logstash/logstash-logback-encoder
|
||||
LogstashEncoder logstashEncoder = new LogstashEncoder();
|
||||
// Set the Logstash appender config from JHipster properties
|
||||
logstashAppender.addDestinations(
|
||||
new InetSocketAddress(
|
||||
jHipsterProperties.getLogging().getLogstash().getHost(),
|
||||
jHipsterProperties.getLogging().getLogstash().getPort()));
|
||||
|
||||
ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
|
||||
throwableConverter.setRootCauseFirst(true);
|
||||
logstashEncoder.setThrowableConverter(throwableConverter);
|
||||
logstashEncoder.setCustomFields(customFields);
|
||||
|
||||
logstashAppender.setEncoder(logstashEncoder);
|
||||
logstashAppender.start();
|
||||
|
||||
// Wrap the appender in an Async appender for performance
|
||||
AsyncAppender asyncLogstashAppender = new AsyncAppender();
|
||||
asyncLogstashAppender.setContext(context);
|
||||
asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
|
||||
asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
|
||||
asyncLogstashAppender.addAppender(logstashAppender);
|
||||
asyncLogstashAppender.start();
|
||||
|
||||
context.getLogger("ROOT").addAppender(asyncLogstashAppender);
|
||||
}
|
||||
|
||||
// Configure a log filter to remove "metrics" logs from all appenders except the "LOGSTASH" appender
|
||||
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
|
||||
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
|
||||
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
|
||||
onMarkerMetricsEvaluator.setContext(context);
|
||||
onMarkerMetricsEvaluator.addMarker("metrics");
|
||||
onMarkerMetricsEvaluator.start();
|
||||
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
|
||||
metricsFilter.setContext(context);
|
||||
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
|
||||
metricsFilter.setOnMatch(FilterReply.DENY);
|
||||
metricsFilter.start();
|
||||
|
||||
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
|
||||
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
|
||||
Appender<ILoggingEvent> appender = it.next();
|
||||
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
|
||||
log.debug("Filter metrics logs from the {} appender", appender.getName());
|
||||
appender.setContext(context);
|
||||
appender.addFilter(metricsFilter);
|
||||
appender.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logback configuration is achieved by configuration file and API.
|
||||
* When configuration file change is detected, the configuration is reset.
|
||||
* This listener ensures that the programmatic configuration is also re-applied after reset.
|
||||
*/
|
||||
class LogbackLoggerContextListener extends ContextAwareBase implements LoggerContextListener {
|
||||
|
||||
@Override
|
||||
public boolean isResetResistant() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(LoggerContext context) {
|
||||
addLogstashAppender(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset(LoggerContext context) {
|
||||
addLogstashAppender(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(LoggerContext context) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLevelChange(ch.qos.logback.classic.Logger logger, Level level) {
|
||||
// Nothing to do.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import org.hostsharing.hsadminng.security.*;
|
||||
import org.hostsharing.hsadminng.security.jwt.*;
|
||||
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
|
||||
@Import(SecurityProblemSupport.class)
|
||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
||||
|
||||
private final UserDetailsService userDetailsService;
|
||||
|
||||
private final TokenProvider tokenProvider;
|
||||
|
||||
private final CorsFilter corsFilter;
|
||||
|
||||
private final SecurityProblemSupport problemSupport;
|
||||
|
||||
public SecurityConfiguration(
|
||||
AuthenticationManagerBuilder authenticationManagerBuilder,
|
||||
UserDetailsService userDetailsService,
|
||||
TokenProvider tokenProvider,
|
||||
CorsFilter corsFilter,
|
||||
SecurityProblemSupport problemSupport) {
|
||||
this.authenticationManagerBuilder = authenticationManagerBuilder;
|
||||
this.userDetailsService = userDetailsService;
|
||||
this.tokenProvider = tokenProvider;
|
||||
this.corsFilter = corsFilter;
|
||||
this.problemSupport = problemSupport;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
authenticationManagerBuilder
|
||||
.userDetailsService(userDetailsService)
|
||||
.passwordEncoder(passwordEncoder());
|
||||
} catch (Exception e) {
|
||||
throw new BeanInitializationException("Security configuration failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||
return super.authenticationManagerBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
web.ignoring()
|
||||
.antMatchers(HttpMethod.OPTIONS, "/**")
|
||||
.antMatchers("/app/**/*.{js,html}")
|
||||
.antMatchers("/i18n/**")
|
||||
.antMatchers("/content/**")
|
||||
.antMatchers("/h2-console/**")
|
||||
.antMatchers("/swagger-ui/index.html")
|
||||
.antMatchers("/test/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.csrf()
|
||||
.disable()
|
||||
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(problemSupport)
|
||||
.accessDeniedHandler(problemSupport)
|
||||
.and()
|
||||
.headers()
|
||||
.frameOptions()
|
||||
.disable()
|
||||
.and()
|
||||
.sessionManagement()
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/api/register").permitAll()
|
||||
.antMatchers("/api/activate").permitAll()
|
||||
.antMatchers("/api/authenticate").permitAll()
|
||||
.antMatchers("/api/account/reset-password/init").permitAll()
|
||||
.antMatchers("/api/account/reset-password/finish").permitAll()
|
||||
.antMatchers("/api/**").authenticated()
|
||||
.antMatchers("/management/health").permitAll()
|
||||
.antMatchers("/management/info").permitAll()
|
||||
.antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
|
||||
.and()
|
||||
.apply(securityConfigurerAdapter());
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
private JWTConfigurer securityConfigurerAdapter() {
|
||||
return new JWTConfigurer(tokenProvider);
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config;
|
||||
|
||||
import static java.net.URLDecoder.decode;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
import io.github.jhipster.config.h2.H2ConfigurationHelper;
|
||||
import io.github.jhipster.web.filter.CachingHttpHeadersFilter;
|
||||
import io.undertow.UndertowOptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.*;
|
||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.*;
|
||||
|
||||
/**
|
||||
* Configuration of web application with Servlet 3.0 APIs.
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfigurer implements ServletContextInitializer, WebServerFactoryCustomizer<WebServerFactory> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(WebConfigurer.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
public WebConfigurer(Environment env, JHipsterProperties jHipsterProperties) {
|
||||
|
||||
this.env = env;
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
if (env.getActiveProfiles().length != 0) {
|
||||
log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles());
|
||||
}
|
||||
EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
|
||||
initCachingHttpHeadersFilter(servletContext, disps);
|
||||
}
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
|
||||
initH2Console(servletContext);
|
||||
}
|
||||
log.info("Web application fully configured");
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize the Servlet engine: Mime types, the document root, the cache.
|
||||
*/
|
||||
@Override
|
||||
public void customize(WebServerFactory server) {
|
||||
setMimeMappings(server);
|
||||
// When running in an IDE or with ./gradlew bootRun, set location of the static web assets.
|
||||
setLocationForStaticAssets(server);
|
||||
|
||||
/*
|
||||
* Enable HTTP/2 for Undertow - https://twitter.com/ankinson/status/829256167700492288
|
||||
* HTTP/2 requires HTTPS, so HTTP requests will fallback to HTTP/1.1.
|
||||
* See the JHipsterProperties class and your application-*.yml configuration files
|
||||
* for more information.
|
||||
*/
|
||||
if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) &&
|
||||
server instanceof UndertowServletWebServerFactory) {
|
||||
|
||||
((UndertowServletWebServerFactory) server)
|
||||
.addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
|
||||
}
|
||||
}
|
||||
|
||||
private void setMimeMappings(WebServerFactory server) {
|
||||
if (server instanceof ConfigurableServletWebServerFactory) {
|
||||
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
|
||||
// IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
|
||||
mappings.add("html", MediaType.TEXT_HTML_VALUE + ";charset=" + StandardCharsets.UTF_8.name().toLowerCase());
|
||||
// CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
|
||||
mappings.add("json", MediaType.TEXT_HTML_VALUE + ";charset=" + StandardCharsets.UTF_8.name().toLowerCase());
|
||||
ConfigurableServletWebServerFactory servletWebServer = (ConfigurableServletWebServerFactory) server;
|
||||
servletWebServer.setMimeMappings(mappings);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLocationForStaticAssets(WebServerFactory server) {
|
||||
if (server instanceof ConfigurableServletWebServerFactory) {
|
||||
ConfigurableServletWebServerFactory servletWebServer = (ConfigurableServletWebServerFactory) server;
|
||||
File root;
|
||||
String prefixPath = resolvePathPrefix();
|
||||
root = new File(prefixPath + "build/www/");
|
||||
if (root.exists() && root.isDirectory()) {
|
||||
servletWebServer.setDocumentRoot(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve path prefix to static resources.
|
||||
*/
|
||||
private String resolvePathPrefix() {
|
||||
String fullExecutablePath;
|
||||
try {
|
||||
fullExecutablePath = decode(this.getClass().getResource("").getPath(), StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
/* try without decoding if this ever happens */
|
||||
fullExecutablePath = this.getClass().getResource("").getPath();
|
||||
}
|
||||
String rootPath = Paths.get(".").toUri().normalize().getPath();
|
||||
String extractedPath = fullExecutablePath.replace(rootPath, "");
|
||||
int extractionEndIndex = extractedPath.indexOf("build/");
|
||||
if (extractionEndIndex <= 0) {
|
||||
return "";
|
||||
}
|
||||
return extractedPath.substring(0, extractionEndIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the caching HTTP Headers Filter.
|
||||
*/
|
||||
private void initCachingHttpHeadersFilter(
|
||||
ServletContext servletContext,
|
||||
EnumSet<DispatcherType> disps) {
|
||||
log.debug("Registering Caching HTTP Headers Filter");
|
||||
FilterRegistration.Dynamic cachingHttpHeadersFilter = servletContext.addFilter(
|
||||
"cachingHttpHeadersFilter",
|
||||
new CachingHttpHeadersFilter(jHipsterProperties));
|
||||
|
||||
cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/i18n/*");
|
||||
cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/content/*");
|
||||
cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/app/*");
|
||||
cachingHttpHeadersFilter.setAsyncSupported(true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = jHipsterProperties.getCors();
|
||||
if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
|
||||
log.debug("Registering CORS filter");
|
||||
source.registerCorsConfiguration("/api/**", config);
|
||||
source.registerCorsConfiguration("/management/**", config);
|
||||
source.registerCorsConfiguration("/v2/api-docs", config);
|
||||
}
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes H2 console.
|
||||
*/
|
||||
private void initH2Console(ServletContext servletContext) {
|
||||
log.debug("Initialize H2 console");
|
||||
H2ConfigurationHelper.initH2Console(servletContext);
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.config.audit;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.PersistentAuditEvent;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEvent;
|
||||
import org.springframework.security.web.authentication.WebAuthenticationDetails;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class AuditEventConverter {
|
||||
|
||||
/**
|
||||
* Convert a list of PersistentAuditEvent to a list of AuditEvent
|
||||
*
|
||||
* @param persistentAuditEvents the list to convert
|
||||
* @return the converted list.
|
||||
*/
|
||||
public List<AuditEvent> convertToAuditEvent(Iterable<PersistentAuditEvent> persistentAuditEvents) {
|
||||
if (persistentAuditEvents == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<AuditEvent> auditEvents = new ArrayList<>();
|
||||
for (PersistentAuditEvent persistentAuditEvent : persistentAuditEvents) {
|
||||
auditEvents.add(convertToAuditEvent(persistentAuditEvent));
|
||||
}
|
||||
return auditEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a PersistentAuditEvent to an AuditEvent
|
||||
*
|
||||
* @param persistentAuditEvent the event to convert
|
||||
* @return the converted list.
|
||||
*/
|
||||
public AuditEvent convertToAuditEvent(PersistentAuditEvent persistentAuditEvent) {
|
||||
if (persistentAuditEvent == null) {
|
||||
return null;
|
||||
}
|
||||
return new AuditEvent(
|
||||
persistentAuditEvent.getAuditEventDate(),
|
||||
persistentAuditEvent.getPrincipal(),
|
||||
persistentAuditEvent.getAuditEventType(),
|
||||
convertDataToObjects(persistentAuditEvent.getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal conversion. This is needed to support the current SpringBoot actuator AuditEventRepository interface
|
||||
*
|
||||
* @param data the data to convert
|
||||
* @return a map of String, Object
|
||||
*/
|
||||
public Map<String, Object> convertDataToObjects(Map<String, String> data) {
|
||||
Map<String, Object> results = new HashMap<>();
|
||||
|
||||
if (data != null) {
|
||||
for (Map.Entry<String, String> entry : data.entrySet()) {
|
||||
results.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal conversion. This method will allow to save additional data.
|
||||
* By default, it will save the object as string
|
||||
*
|
||||
* @param data the data to convert
|
||||
* @return a map of String, String
|
||||
*/
|
||||
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
|
||||
Map<String, String> results = new HashMap<>();
|
||||
|
||||
if (data != null) {
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
// Extract the data that will be saved.
|
||||
if (entry.getValue() instanceof WebAuthenticationDetails) {
|
||||
WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) entry.getValue();
|
||||
results.put("remoteAddress", authenticationDetails.getRemoteAddress());
|
||||
results.put("sessionId", authenticationDetails.getSessionId());
|
||||
} else {
|
||||
results.put(entry.getKey(), Objects.toString(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Audit specific code.
|
||||
*/
|
||||
package org.hostsharing.hsadminng.config.audit;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Spring Framework configuration files.
|
||||
*/
|
||||
package org.hostsharing.hsadminng.config;
|
@ -1,82 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* Base abstract class for entities which will hold definitions for created, last modified by and created,
|
||||
* last modified by date.
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Audited
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public abstract class AbstractAuditingEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@CreatedBy
|
||||
@Column(name = "created_by", nullable = false, length = 50, updatable = false)
|
||||
@JsonIgnore
|
||||
private String createdBy;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_date", updatable = false)
|
||||
@JsonIgnore
|
||||
private Instant createdDate = Instant.now();
|
||||
|
||||
@LastModifiedBy
|
||||
@Column(name = "last_modified_by", length = 50)
|
||||
@JsonIgnore
|
||||
private String lastModifiedBy;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "last_modified_date")
|
||||
@JsonIgnore
|
||||
private Instant lastModifiedDate = Instant.now();
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Instant getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Instant createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getLastModifiedBy() {
|
||||
return lastModifiedBy;
|
||||
}
|
||||
|
||||
public void setLastModifiedBy(String lastModifiedBy) {
|
||||
this.lastModifiedBy = lastModifiedBy;
|
||||
}
|
||||
|
||||
public Instant getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
public void setLastModifiedDate(Instant lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A Asset.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "asset")
|
||||
public class Asset implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_NAME = "asset";
|
||||
public static final String ENTITY_TYPE_ID = "customer.asset";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "document_date", nullable = false)
|
||||
private LocalDate documentDate;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "value_date", nullable = false)
|
||||
private LocalDate valueDate;
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "action", nullable = false)
|
||||
private AssetAction action;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "amount", precision = 10, scale = 2, nullable = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
@Size(max = 160)
|
||||
@Column(name = "remark", length = 160)
|
||||
private String remark;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@NotNull
|
||||
@JsonIgnoreProperties("assets")
|
||||
private Membership membership;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Asset id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public Asset documentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public Asset valueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public AssetAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Asset action(AssetAction action) {
|
||||
this.action = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAction(AssetAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Asset amount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public Asset remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Membership getMembership() {
|
||||
return membership;
|
||||
}
|
||||
|
||||
public Asset membership(Membership membership) {
|
||||
this.membership = membership;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMembership(Membership membership) {
|
||||
this.membership = membership;
|
||||
}
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Asset asset = (Asset) o;
|
||||
if (asset.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), asset.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Asset{" +
|
||||
"id=" + getId() +
|
||||
", documentDate='" + getDocumentDate() + "'" +
|
||||
", valueDate='" + getValueDate() + "'" +
|
||||
", action='" + getAction() + "'" +
|
||||
", amount=" + getAmount() +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* An authority (a security role) used by Spring Security.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "jhi_authority")
|
||||
public class Authority implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 50)
|
||||
@Id
|
||||
@Column(length = 50)
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Authority authority = (Authority) o;
|
||||
|
||||
return !(name != null ? !name.equals(authority.name) : authority.name != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name != null ? name.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Authority{" +
|
||||
"name='" + name + '\'' +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,408 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.CustomerKind;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.VatRegion;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* A Customer.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "customer")
|
||||
public class Customer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_TYPE_ID = "customer.Customer";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Min(value = 10000)
|
||||
@Max(value = 99999)
|
||||
@Column(name = "reference", nullable = false, unique = true)
|
||||
private Integer reference;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 3)
|
||||
@Pattern(regexp = "[a-z][a-z0-9]+")
|
||||
@Column(name = "prefix", length = 3, nullable = false, unique = true)
|
||||
private String prefix;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 80)
|
||||
@Column(name = "name", length = 80, nullable = false)
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "kind", nullable = false)
|
||||
private CustomerKind kind;
|
||||
|
||||
@Column(name = "birth_date")
|
||||
private LocalDate birthDate;
|
||||
|
||||
@Size(max = 80)
|
||||
@Column(name = "birth_place", length = 80)
|
||||
private String birthPlace;
|
||||
|
||||
@Size(max = 80)
|
||||
@Column(name = "registration_court", length = 80)
|
||||
private String registrationCourt;
|
||||
|
||||
@Size(max = 80)
|
||||
@Column(name = "registration_number", length = 80)
|
||||
private String registrationNumber;
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "vat_region", nullable = false)
|
||||
private VatRegion vatRegion;
|
||||
|
||||
@Size(max = 40)
|
||||
@Column(name = "vat_number", length = 40)
|
||||
private String vatNumber;
|
||||
|
||||
@Size(max = 80)
|
||||
@Column(name = "contractual_salutation", length = 80)
|
||||
private String contractualSalutation;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 400)
|
||||
@Column(name = "contractual_address", length = 400, nullable = false)
|
||||
private String contractualAddress;
|
||||
|
||||
@Size(max = 80)
|
||||
@Column(name = "billing_salutation", length = 80)
|
||||
private String billingSalutation;
|
||||
|
||||
@Size(max = 400)
|
||||
@Column(name = "billing_address", length = 400)
|
||||
private String billingAddress;
|
||||
|
||||
@Size(max = 160)
|
||||
@Column(name = "remark", length = 160)
|
||||
private String remark;
|
||||
|
||||
@OneToMany(mappedBy = "customer")
|
||||
private Set<Membership> memberships = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "customer")
|
||||
private Set<SepaMandate> sepamandates = new HashSet<>();
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Customer id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public Customer reference(Integer reference) {
|
||||
this.reference = reference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setReference(Integer reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public Customer prefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Customer name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CustomerKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public Customer kind(CustomerKind kind) {
|
||||
this.kind = kind;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setKind(CustomerKind kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public Customer birthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getBirthPlace() {
|
||||
return birthPlace;
|
||||
}
|
||||
|
||||
public Customer birthPlace(String birthPlace) {
|
||||
this.birthPlace = birthPlace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setBirthPlace(String birthPlace) {
|
||||
this.birthPlace = birthPlace;
|
||||
}
|
||||
|
||||
public String getRegistrationCourt() {
|
||||
return registrationCourt;
|
||||
}
|
||||
|
||||
public Customer registrationCourt(String registrationCourt) {
|
||||
this.registrationCourt = registrationCourt;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRegistrationCourt(String registrationCourt) {
|
||||
this.registrationCourt = registrationCourt;
|
||||
}
|
||||
|
||||
public String getRegistrationNumber() {
|
||||
return registrationNumber;
|
||||
}
|
||||
|
||||
public Customer registrationNumber(String registrationNumber) {
|
||||
this.registrationNumber = registrationNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRegistrationNumber(String registrationNumber) {
|
||||
this.registrationNumber = registrationNumber;
|
||||
}
|
||||
|
||||
public VatRegion getVatRegion() {
|
||||
return vatRegion;
|
||||
}
|
||||
|
||||
public Customer vatRegion(VatRegion vatRegion) {
|
||||
this.vatRegion = vatRegion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVatRegion(VatRegion vatRegion) {
|
||||
this.vatRegion = vatRegion;
|
||||
}
|
||||
|
||||
public String getVatNumber() {
|
||||
return vatNumber;
|
||||
}
|
||||
|
||||
public Customer vatNumber(String vatNumber) {
|
||||
this.vatNumber = vatNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVatNumber(String vatNumber) {
|
||||
this.vatNumber = vatNumber;
|
||||
}
|
||||
|
||||
public String getContractualSalutation() {
|
||||
return contractualSalutation;
|
||||
}
|
||||
|
||||
public Customer contractualSalutation(String contractualSalutation) {
|
||||
this.contractualSalutation = contractualSalutation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setContractualSalutation(String contractualSalutation) {
|
||||
this.contractualSalutation = contractualSalutation;
|
||||
}
|
||||
|
||||
public String getContractualAddress() {
|
||||
return contractualAddress;
|
||||
}
|
||||
|
||||
public Customer contractualAddress(String contractualAddress) {
|
||||
this.contractualAddress = contractualAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setContractualAddress(String contractualAddress) {
|
||||
this.contractualAddress = contractualAddress;
|
||||
}
|
||||
|
||||
public String getBillingSalutation() {
|
||||
return billingSalutation;
|
||||
}
|
||||
|
||||
public Customer billingSalutation(String billingSalutation) {
|
||||
this.billingSalutation = billingSalutation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setBillingSalutation(String billingSalutation) {
|
||||
this.billingSalutation = billingSalutation;
|
||||
}
|
||||
|
||||
public String getBillingAddress() {
|
||||
return billingAddress;
|
||||
}
|
||||
|
||||
public Customer billingAddress(String billingAddress) {
|
||||
this.billingAddress = billingAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setBillingAddress(String billingAddress) {
|
||||
this.billingAddress = billingAddress;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public Customer remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Set<Membership> getMemberships() {
|
||||
return memberships;
|
||||
}
|
||||
|
||||
public Customer memberships(Set<Membership> memberships) {
|
||||
this.memberships = memberships;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Customer addMembership(Membership membership) {
|
||||
this.memberships.add(membership);
|
||||
membership.setCustomer(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Customer removeMembership(Membership membership) {
|
||||
this.memberships.remove(membership);
|
||||
membership.setCustomer(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMemberships(Set<Membership> memberships) {
|
||||
this.memberships = memberships;
|
||||
}
|
||||
|
||||
public Set<SepaMandate> getSepamandates() {
|
||||
return sepamandates;
|
||||
}
|
||||
|
||||
public Customer sepamandates(Set<SepaMandate> sepaMandates) {
|
||||
this.sepamandates = sepaMandates;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Customer addSepamandate(SepaMandate sepaMandate) {
|
||||
this.sepamandates.add(sepaMandate);
|
||||
sepaMandate.setCustomer(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Customer removeSepamandate(SepaMandate sepaMandate) {
|
||||
this.sepamandates.remove(sepaMandate);
|
||||
sepaMandate.setCustomer(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setSepamandates(Set<SepaMandate> sepaMandates) {
|
||||
this.sepamandates = sepaMandates;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Customer customer = (Customer) o;
|
||||
if (customer.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), customer.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Customer{" +
|
||||
"id=" + getId() +
|
||||
", reference=" + getReference() +
|
||||
", prefix='" + getPrefix() + "'" +
|
||||
", name='" + getName() + "'" +
|
||||
", kind='" + getKind() + "'" +
|
||||
", birthDate='" + getBirthDate() + "'" +
|
||||
", birthPlace='" + getBirthPlace() + "'" +
|
||||
", registrationCourt='" + getRegistrationCourt() + "'" +
|
||||
", registrationNumber='" + getRegistrationNumber() + "'" +
|
||||
", vatRegion='" + getVatRegion() + "'" +
|
||||
", vatNumber='" + getVatNumber() + "'" +
|
||||
", contractualSalutation='" + getContractualSalutation() + "'" +
|
||||
", contractualAddress='" + getContractualAddress() + "'" +
|
||||
", billingSalutation='" + getBillingSalutation() + "'" +
|
||||
", billingAddress='" + getBillingAddress() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,238 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A Membership.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "membership")
|
||||
public class Membership implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_NAME = "membership";
|
||||
public static final String ENTITY_TYPE_ID = "customer.Membership";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "admission_document_date", nullable = false)
|
||||
private LocalDate admissionDocumentDate;
|
||||
|
||||
@Column(name = "cancellation_document_date")
|
||||
private LocalDate cancellationDocumentDate;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "member_from_date", nullable = false)
|
||||
private LocalDate memberFromDate;
|
||||
|
||||
@Column(name = "member_until_date")
|
||||
private LocalDate memberUntilDate;
|
||||
|
||||
@Size(max = 160)
|
||||
@Column(name = "remark", length = 160)
|
||||
private String remark;
|
||||
|
||||
@OneToMany(mappedBy = "membership")
|
||||
private Set<Share> shares = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "membership")
|
||||
private Set<Asset> assets = new HashSet<>();
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@NotNull
|
||||
@JsonIgnoreProperties("memberships")
|
||||
private Customer customer;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Membership id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getAdmissionDocumentDate() {
|
||||
return admissionDocumentDate;
|
||||
}
|
||||
|
||||
public Membership admissionDocumentDate(LocalDate admissionDocumentDate) {
|
||||
this.admissionDocumentDate = admissionDocumentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAdmissionDocumentDate(LocalDate admissionDocumentDate) {
|
||||
this.admissionDocumentDate = admissionDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getCancellationDocumentDate() {
|
||||
return cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public Membership cancellationDocumentDate(LocalDate cancellationDocumentDate) {
|
||||
this.cancellationDocumentDate = cancellationDocumentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setCancellationDocumentDate(LocalDate cancellationDocumentDate) {
|
||||
this.cancellationDocumentDate = cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getMemberFromDate() {
|
||||
return memberFromDate;
|
||||
}
|
||||
|
||||
public Membership memberFromDate(LocalDate memberFromDate) {
|
||||
this.memberFromDate = memberFromDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMemberFromDate(LocalDate memberFromDate) {
|
||||
this.memberFromDate = memberFromDate;
|
||||
}
|
||||
|
||||
public LocalDate getMemberUntilDate() {
|
||||
return memberUntilDate;
|
||||
}
|
||||
|
||||
public Membership memberUntilDate(LocalDate memberUntilDate) {
|
||||
this.memberUntilDate = memberUntilDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMemberUntilDate(LocalDate memberUntilDate) {
|
||||
this.memberUntilDate = memberUntilDate;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public Membership remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Set<Share> getShares() {
|
||||
return shares;
|
||||
}
|
||||
|
||||
public Membership shares(Set<Share> shares) {
|
||||
this.shares = shares;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Membership addShare(Share share) {
|
||||
this.shares.add(share);
|
||||
share.setMembership(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Membership removeShare(Share share) {
|
||||
this.shares.remove(share);
|
||||
share.setMembership(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setShares(Set<Share> shares) {
|
||||
this.shares = shares;
|
||||
}
|
||||
|
||||
public Set<Asset> getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
public Membership assets(Set<Asset> assets) {
|
||||
this.assets = assets;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Membership addAsset(Asset asset) {
|
||||
this.assets.add(asset);
|
||||
asset.setMembership(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Membership removeAsset(Asset asset) {
|
||||
this.assets.remove(asset);
|
||||
asset.setMembership(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAssets(Set<Asset> assets) {
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public Membership customer(Customer customer) {
|
||||
this.customer = customer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Membership membership = (Membership) o;
|
||||
if (membership.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), membership.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Membership{" +
|
||||
"id=" + getId() +
|
||||
", admissionDocumentDate='" + getAdmissionDocumentDate() + "'" +
|
||||
", cancellationDocumentDate='" + getCancellationDocumentDate() + "'" +
|
||||
", memberFromDate='" + getMemberFromDate() + "'" +
|
||||
", memberUntilDate='" + getMemberUntilDate() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Persist AuditEvent managed by the Spring Boot actuator.
|
||||
*
|
||||
* @see org.springframework.boot.actuate.audit.AuditEvent
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "jhi_persistent_audit_event")
|
||||
public class PersistentAuditEvent implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
@Column(name = "event_id")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(nullable = false)
|
||||
private String principal;
|
||||
|
||||
@Column(name = "event_date")
|
||||
private Instant auditEventDate;
|
||||
|
||||
@Column(name = "event_type")
|
||||
private String auditEventType;
|
||||
|
||||
@ElementCollection
|
||||
@MapKeyColumn(name = "name")
|
||||
@Column(name = "value")
|
||||
@CollectionTable(name = "jhi_persistent_audit_evt_data", joinColumns = @JoinColumn(name = "event_id"))
|
||||
private Map<String, String> data = new HashMap<>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPrincipal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPrincipal(String principal) {
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public Instant getAuditEventDate() {
|
||||
return auditEventDate;
|
||||
}
|
||||
|
||||
public void setAuditEventDate(Instant auditEventDate) {
|
||||
this.auditEventDate = auditEventDate;
|
||||
}
|
||||
|
||||
public String getAuditEventType() {
|
||||
return auditEventType;
|
||||
}
|
||||
|
||||
public void setAuditEventType(String auditEventType) {
|
||||
this.auditEventType = auditEventType;
|
||||
}
|
||||
|
||||
public Map<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, String> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentAuditEvent persistentAuditEvent = (PersistentAuditEvent) o;
|
||||
return !(persistentAuditEvent.getId() == null || getId() == null)
|
||||
&& Objects.equals(getId(), persistentAuditEvent.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PersistentAuditEvent{" +
|
||||
"principal='" + principal + '\'' +
|
||||
", auditEventDate=" + auditEventDate +
|
||||
", auditEventType='" + auditEventType + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,250 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A SepaMandate.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "sepa_mandate")
|
||||
public class SepaMandate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_TYPE_ID = "customer.SepaMandate";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 40)
|
||||
@Column(name = "reference", length = 40, nullable = false, unique = true)
|
||||
private String reference;
|
||||
|
||||
@Size(max = 34)
|
||||
@Column(name = "iban", length = 34)
|
||||
private String iban;
|
||||
|
||||
@Size(max = 11)
|
||||
@Column(name = "bic", length = 11)
|
||||
private String bic;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "granting_document_date", nullable = false)
|
||||
private LocalDate grantingDocumentDate;
|
||||
|
||||
@Column(name = "revokation_document_date")
|
||||
private LocalDate revokationDocumentDate;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "valid_from_date", nullable = false)
|
||||
private LocalDate validFromDate;
|
||||
|
||||
@Column(name = "valid_until_date")
|
||||
private LocalDate validUntilDate;
|
||||
|
||||
@Column(name = "last_used_date")
|
||||
private LocalDate lastUsedDate;
|
||||
|
||||
@Size(max = 160)
|
||||
@Column(name = "remark", length = 160)
|
||||
private String remark;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@NotNull
|
||||
@JsonIgnoreProperties("sepamandates")
|
||||
private Customer customer;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public SepaMandate id(final Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public SepaMandate reference(String reference) {
|
||||
this.reference = reference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getIban() {
|
||||
return iban;
|
||||
}
|
||||
|
||||
public SepaMandate iban(String iban) {
|
||||
this.iban = iban;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setIban(String iban) {
|
||||
this.iban = iban;
|
||||
}
|
||||
|
||||
public String getBic() {
|
||||
return bic;
|
||||
}
|
||||
|
||||
public SepaMandate bic(String bic) {
|
||||
this.bic = bic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setBic(String bic) {
|
||||
this.bic = bic;
|
||||
}
|
||||
|
||||
public LocalDate getGrantingDocumentDate() {
|
||||
return grantingDocumentDate;
|
||||
}
|
||||
|
||||
public SepaMandate grantingDocumentDate(LocalDate grantingDocumentDate) {
|
||||
this.grantingDocumentDate = grantingDocumentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setGrantingDocumentDate(LocalDate grantingDocumentDate) {
|
||||
this.grantingDocumentDate = grantingDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getRevokationDocumentDate() {
|
||||
return revokationDocumentDate;
|
||||
}
|
||||
|
||||
public SepaMandate revokationDocumentDate(LocalDate revokationDocumentDate) {
|
||||
this.revokationDocumentDate = revokationDocumentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRevokationDocumentDate(LocalDate revokationDocumentDate) {
|
||||
this.revokationDocumentDate = revokationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValidFromDate() {
|
||||
return validFromDate;
|
||||
}
|
||||
|
||||
public SepaMandate validFromDate(LocalDate validFromDate) {
|
||||
this.validFromDate = validFromDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setValidFromDate(LocalDate validFromDate) {
|
||||
this.validFromDate = validFromDate;
|
||||
}
|
||||
|
||||
public LocalDate getValidUntilDate() {
|
||||
return validUntilDate;
|
||||
}
|
||||
|
||||
public SepaMandate validUntilDate(LocalDate validUntilDate) {
|
||||
this.validUntilDate = validUntilDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setValidUntilDate(LocalDate validUntilDate) {
|
||||
this.validUntilDate = validUntilDate;
|
||||
}
|
||||
|
||||
public LocalDate getLastUsedDate() {
|
||||
return lastUsedDate;
|
||||
}
|
||||
|
||||
public SepaMandate lastUsedDate(LocalDate lastUsedDate) {
|
||||
this.lastUsedDate = lastUsedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setLastUsedDate(LocalDate lastUsedDate) {
|
||||
this.lastUsedDate = lastUsedDate;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public SepaMandate remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public SepaMandate customer(Customer customer) {
|
||||
this.customer = customer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SepaMandate sepaMandate = (SepaMandate) o;
|
||||
if (sepaMandate.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), sepaMandate.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SepaMandate{" +
|
||||
"id=" + getId() +
|
||||
", reference='" + getReference() + "'" +
|
||||
", iban='" + getIban() + "'" +
|
||||
", bic='" + getBic() + "'" +
|
||||
", grantingDocumentDate='" + getGrantingDocumentDate() + "'" +
|
||||
", revokationDocumentDate='" + getRevokationDocumentDate() + "'" +
|
||||
", validFromDate='" + getValidFromDate() + "'" +
|
||||
", validUntilDate='" + getValidUntilDate() + "'" +
|
||||
", lastUsedDate='" + getLastUsedDate() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A Share.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "share")
|
||||
public class Share implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENTITY_NAME = "share";
|
||||
public static final String ENTITY_TYPE_ID = "customer.share";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "document_date", nullable = false)
|
||||
private LocalDate documentDate;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "value_date", nullable = false)
|
||||
private LocalDate valueDate;
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "action", nullable = false)
|
||||
private ShareAction action;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "quantity", nullable = false)
|
||||
private Integer quantity;
|
||||
|
||||
@Size(max = 160)
|
||||
@Column(name = "remark", length = 160)
|
||||
private String remark;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@NotNull
|
||||
@JsonIgnoreProperties("shares")
|
||||
private Membership membership;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Share id(final Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public Share documentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public Share valueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public ShareAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Share action(ShareAction action) {
|
||||
this.action = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAction(ShareAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public Share quantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public Share remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Membership getMembership() {
|
||||
return membership;
|
||||
}
|
||||
|
||||
public Share membership(Membership membership) {
|
||||
this.membership = membership;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMembership(Membership membership) {
|
||||
this.membership = membership;
|
||||
}
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Share share = (Share) o;
|
||||
if (share.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), share.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Share{" +
|
||||
"id=" + getId() +
|
||||
", documentDate='" + getDocumentDate() + "'" +
|
||||
", valueDate='" + getValueDate() + "'" +
|
||||
", action='" + getAction() + "'" +
|
||||
", quantity=" + getQuantity() +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,240 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import org.hostsharing.hsadminng.config.Constants;
|
||||
import org.hostsharing.hsadminng.service.dto.FluentBuilder;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.annotations.BatchSize;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A user.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "jhi_user")
|
||||
|
||||
public class User extends AbstractAuditingEntity implements FluentBuilder<User>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Pattern(regexp = Constants.LOGIN_REGEX)
|
||||
@Size(min = 1, max = 50)
|
||||
@Column(length = 50, unique = true, nullable = false)
|
||||
private String login;
|
||||
|
||||
@JsonIgnore
|
||||
@NotNull
|
||||
@Size(min = 60, max = 60)
|
||||
@Column(name = "password_hash", length = 60, nullable = false)
|
||||
private String password;
|
||||
|
||||
@Size(max = 50)
|
||||
@Column(name = "first_name", length = 50)
|
||||
private String firstName;
|
||||
|
||||
@Size(max = 50)
|
||||
@Column(name = "last_name", length = 50)
|
||||
private String lastName;
|
||||
|
||||
@Email
|
||||
@Size(min = 5, max = 254)
|
||||
@Column(length = 254, unique = true)
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
@Column(nullable = false)
|
||||
private boolean activated = false;
|
||||
|
||||
@Size(min = 2, max = 6)
|
||||
@Column(name = "lang_key", length = 6)
|
||||
private String langKey;
|
||||
|
||||
@Size(max = 256)
|
||||
@Column(name = "image_url", length = 256)
|
||||
private String imageUrl;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "activation_key", length = 20)
|
||||
@JsonIgnore
|
||||
private String activationKey;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "reset_key", length = 20)
|
||||
@JsonIgnore
|
||||
private String resetKey;
|
||||
|
||||
@Column(name = "reset_date")
|
||||
private Instant resetDate = null;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "jhi_user_authority",
|
||||
joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") },
|
||||
inverseJoinColumns = { @JoinColumn(name = "authority_name", referencedColumnName = "name") })
|
||||
@BatchSize(size = 20)
|
||||
private Set<Authority> authorities = new HashSet<>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public User id(final long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
// Lowercase the login before saving it in database
|
||||
public void setLogin(String login) {
|
||||
this.login = StringUtils.lowerCase(login, Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public boolean getActivated() {
|
||||
return activated;
|
||||
}
|
||||
|
||||
public void setActivated(boolean activated) {
|
||||
this.activated = activated;
|
||||
}
|
||||
|
||||
public String getActivationKey() {
|
||||
return activationKey;
|
||||
}
|
||||
|
||||
public void setActivationKey(String activationKey) {
|
||||
this.activationKey = activationKey;
|
||||
}
|
||||
|
||||
public String getResetKey() {
|
||||
return resetKey;
|
||||
}
|
||||
|
||||
public void setResetKey(String resetKey) {
|
||||
this.resetKey = resetKey;
|
||||
}
|
||||
|
||||
public Instant getResetDate() {
|
||||
return resetDate;
|
||||
}
|
||||
|
||||
public void setResetDate(Instant resetDate) {
|
||||
this.resetDate = resetDate;
|
||||
}
|
||||
|
||||
public String getLangKey() {
|
||||
return langKey;
|
||||
}
|
||||
|
||||
public void setLangKey(String langKey) {
|
||||
this.langKey = langKey;
|
||||
}
|
||||
|
||||
public Set<Authority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public void setAuthorities(Set<Authority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
User user = (User) o;
|
||||
return !(user.getId() == null || getId() == null) && Objects.equals(getId(), user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"login='" + login + '\'' +
|
||||
", firstName='" + firstName + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", imageUrl='" + imageUrl + '\'' +
|
||||
", activated='" + activated + '\'' +
|
||||
", langKey='" + langKey + '\'' +
|
||||
", activationKey='" + activationKey + '\'' +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
import static org.hostsharing.hsadminng.service.util.ReflectionUtil.of;
|
||||
|
||||
import org.hostsharing.hsadminng.repository.UserRepository;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.Admin;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.Supporter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A UserRoleAssignment.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "user_role_assignment")
|
||||
@EntityTypeId(UserRoleAssignment.ENTITY_TYPE_ID)
|
||||
@JsonAutoDetect(
|
||||
fieldVisibility = JsonAutoDetect.Visibility.ANY,
|
||||
getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
setterVisibility = JsonAutoDetect.Visibility.NONE)
|
||||
public class UserRoleAssignment implements AccessMappings {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String USER_FIELD_NAME = "user";
|
||||
|
||||
public static final String ENTITY_TYPE_ID = "rights.UserRoleAssignment";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
@SelfId(resolver = UserRoleAssignmentService.class)
|
||||
@AccessFor(read = Supporter.class)
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 32)
|
||||
@Column(name = "entity_type_id", length = 32, nullable = false)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private String entityTypeId;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "entity_object_id", nullable = false)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private Long entityObjectId;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "assigned_role", nullable = false)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private String assignedRole;
|
||||
|
||||
@ManyToOne
|
||||
@JsonIgnoreProperties("requireds")
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private User user;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserRoleAssignment id(final long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEntityTypeId() {
|
||||
return entityTypeId;
|
||||
}
|
||||
|
||||
public UserRoleAssignment entityTypeId(String entityTypeId) {
|
||||
this.entityTypeId = entityTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setEntityTypeId(String entityTypeId) {
|
||||
this.entityTypeId = entityTypeId;
|
||||
}
|
||||
|
||||
public Long getEntityObjectId() {
|
||||
return entityObjectId;
|
||||
}
|
||||
|
||||
public UserRoleAssignment entityObjectId(Long entityObjectId) {
|
||||
this.entityObjectId = entityObjectId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setEntityObjectId(Long entityObjectId) {
|
||||
this.entityObjectId = entityObjectId;
|
||||
}
|
||||
|
||||
public Role getAssignedRole() {
|
||||
return assignedRole != null ? Role.of(assignedRole) : null;
|
||||
}
|
||||
|
||||
public UserRoleAssignment assignedRole(Role assignedRole) {
|
||||
this.assignedRole = of(assignedRole, Role::name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAssignedRole(Role assignedRole) {
|
||||
this.assignedRole = of(assignedRole, Role::name);
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public UserRoleAssignment user(User user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
UserRoleAssignment userRoleAssignment = (UserRoleAssignment) o;
|
||||
if (userRoleAssignment.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), userRoleAssignment.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserRoleAssignment{" +
|
||||
"id=" + getId() +
|
||||
", entityTypeId='" + entityTypeId + "'" +
|
||||
", entityObjectId=" + entityObjectId +
|
||||
", assignedRole='" + assignedRole + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class UserRoleAssignmentJsonSerializer extends JsonSerializerWithAccessFilter<UserRoleAssignment> {
|
||||
|
||||
public UserRoleAssignmentJsonSerializer(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSonFieldWriter<UserRoleAssignment> jsonFieldWriter(final Field field) {
|
||||
if (USER_FIELD_NAME.equals(field.getName())) {
|
||||
return (final UserRoleAssignment dto, final JsonGenerator jsonGenerator) -> jsonGenerator
|
||||
.writeNumberField(USER_FIELD_NAME, dto.getUser().getId());
|
||||
}
|
||||
return super.jsonFieldWriter(field);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class UserRoleAssignmentJsonDeserializer extends JsonDeserializerWithAccessFilter<UserRoleAssignment> {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserRoleAssignmentJsonDeserializer(
|
||||
final UserRepository userRepository,
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSonFieldReader<UserRoleAssignment> jsonFieldReader(final TreeNode treeNode, final Field field) {
|
||||
if ("user".equals(field.getName())) {
|
||||
return (final UserRoleAssignment target) -> target
|
||||
.setUser(userRepository.getOne(getSubNode(treeNode, "id").asLong()));
|
||||
}
|
||||
|
||||
return super.jsonFieldReader(treeNode, field);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain.enumeration;
|
||||
|
||||
/**
|
||||
* The AssetAction enumeration.
|
||||
*/
|
||||
public enum AssetAction {
|
||||
PAYMENT,
|
||||
HANDOVER,
|
||||
ADOPTION,
|
||||
LOSS,
|
||||
CLEARING,
|
||||
PAYBACK
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain.enumeration;
|
||||
|
||||
/**
|
||||
* The CustomerKind enumeration.
|
||||
*/
|
||||
public enum CustomerKind {
|
||||
NATURAL,
|
||||
LEGAL
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain.enumeration;
|
||||
|
||||
/**
|
||||
* The ShareAction enumeration.
|
||||
*/
|
||||
public enum ShareAction {
|
||||
SUBSCRIPTION,
|
||||
CANCELLATION
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.domain.enumeration;
|
||||
|
||||
/**
|
||||
* The VatRegion enumeration.
|
||||
*/
|
||||
public enum VatRegion {
|
||||
DOMESTIC,
|
||||
EU,
|
||||
OTHER
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* JPA domain objects.
|
||||
*/
|
||||
package org.hostsharing.hsadminng.domain;
|
@ -1,98 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.liquibase;
|
||||
|
||||
import static com.google.common.base.Verify.verify;
|
||||
|
||||
import liquibase.change.custom.CustomTaskChange;
|
||||
import liquibase.database.Database;
|
||||
import liquibase.database.jvm.JdbcConnection;
|
||||
import liquibase.exception.CustomChangeException;
|
||||
import liquibase.exception.DatabaseException;
|
||||
import liquibase.exception.SetupException;
|
||||
import liquibase.exception.ValidationErrors;
|
||||
import liquibase.resource.ResourceAccessor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Used in Liquibase <customChange/> for database-independent search and replace with special characters.
|
||||
*/
|
||||
public class ReplaceCustomChange implements CustomTaskChange {
|
||||
|
||||
private String tableName;
|
||||
private String columnNames;
|
||||
private String searchFor;
|
||||
private String replaceWith;
|
||||
|
||||
@Override
|
||||
public void execute(final Database database) throws CustomChangeException {
|
||||
final JdbcConnection conn = (JdbcConnection) database.getConnection();
|
||||
final boolean isH2 = "H2".equals(database.getDatabaseProductName());
|
||||
try {
|
||||
verify(!conn.getAutoCommit(), "assuming auto commit to be off in Liquibase changeset");
|
||||
final Statement statement = conn.createStatement();
|
||||
for (String columnName : columnNames.split(",")) {
|
||||
final String sql = "UPDATE " + tableName + " SET " + columnName + "= replace(" + columnName + ", '" + searchFor
|
||||
+ "', " +
|
||||
(isH2 ? "STRINGDECODE('" + replaceWith + "')" : "E'" + replaceWith + "'") + ")";
|
||||
statement.executeUpdate(sql);
|
||||
}
|
||||
} catch (DatabaseException | SQLException e) {
|
||||
throw new CustomChangeException("cannot perform search&replace", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfirmationMessage() {
|
||||
return "in table " + tableName + " / columns " + columnNames + ": replaced all '" + searchFor + "' to '" + replaceWith
|
||||
+ "'";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws SetupException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFileOpener(final ResourceAccessor resourceAccessor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationErrors validate(final Database database) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// public String getTableName() {
|
||||
// return tableName;
|
||||
// }
|
||||
|
||||
public void setTableName(final String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
// public String getColumnNames() {
|
||||
// return columnNames;
|
||||
// }
|
||||
|
||||
public void setColumnNames(final String columns) {
|
||||
this.columnNames = columns;
|
||||
}
|
||||
|
||||
// public String getSearchFor() {
|
||||
// return searchFor;
|
||||
// }
|
||||
|
||||
public void setSearchFor(final String searchFor) {
|
||||
this.searchFor = searchFor;
|
||||
}
|
||||
|
||||
// public String getReplaceWith() {
|
||||
// return replaceWith;
|
||||
// }
|
||||
|
||||
public void setReplaceWith(final String replaceWith) {
|
||||
this.replaceWith = replaceWith;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the Asset entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface AssetRepository extends JpaRepository<Asset, Long>, JpaSpecificationExecutor<Asset> {
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Authority;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the Authority entity.
|
||||
*/
|
||||
public interface AuthorityRepository extends JpaRepository<Authority, String> {
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.config.Constants;
|
||||
import org.hostsharing.hsadminng.config.audit.AuditEventConverter;
|
||||
import org.hostsharing.hsadminng.domain.PersistentAuditEvent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.actuate.audit.AuditEvent;
|
||||
import org.springframework.boot.actuate.audit.AuditEventRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An implementation of Spring Boot's AuditEventRepository.
|
||||
*/
|
||||
@Repository
|
||||
public class CustomAuditEventRepository implements AuditEventRepository {
|
||||
|
||||
private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";
|
||||
|
||||
/**
|
||||
* Should be the same as in Liquibase migration.
|
||||
*/
|
||||
protected static final int EVENT_DATA_COLUMN_MAX_LENGTH = 255;
|
||||
|
||||
private final PersistenceAuditEventRepository persistenceAuditEventRepository;
|
||||
|
||||
private final AuditEventConverter auditEventConverter;
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public CustomAuditEventRepository(
|
||||
PersistenceAuditEventRepository persistenceAuditEventRepository,
|
||||
AuditEventConverter auditEventConverter) {
|
||||
|
||||
this.persistenceAuditEventRepository = persistenceAuditEventRepository;
|
||||
this.auditEventConverter = auditEventConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AuditEvent> find(String principal, Instant after, String type) {
|
||||
Iterable<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository
|
||||
.findByPrincipalAndAuditEventDateAfterAndAuditEventType(principal, after, type);
|
||||
return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void add(AuditEvent event) {
|
||||
if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
|
||||
!Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {
|
||||
|
||||
PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
|
||||
persistentAuditEvent.setPrincipal(event.getPrincipal());
|
||||
persistentAuditEvent.setAuditEventType(event.getType());
|
||||
persistentAuditEvent.setAuditEventDate(event.getTimestamp());
|
||||
Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
|
||||
persistentAuditEvent.setData(truncate(eventData));
|
||||
persistenceAuditEventRepository.save(persistentAuditEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate event data that might exceed column length.
|
||||
*/
|
||||
private Map<String, String> truncate(Map<String, String> data) {
|
||||
Map<String, String> results = new HashMap<>();
|
||||
|
||||
if (data != null) {
|
||||
for (Map.Entry<String, String> entry : data.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
int length = value.length();
|
||||
if (length > EVENT_DATA_COLUMN_MAX_LENGTH) {
|
||||
value = value.substring(0, EVENT_DATA_COLUMN_MAX_LENGTH);
|
||||
log.warn(
|
||||
"Event data for {} too long ({}) has been truncated to {}. Consider increasing column width.",
|
||||
entry.getKey(),
|
||||
length,
|
||||
EVENT_DATA_COLUMN_MAX_LENGTH);
|
||||
}
|
||||
}
|
||||
results.put(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer;
|
||||
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the Customer entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface CustomerRepository extends JpaRepository<Customer, Long>, JpaSpecificationExecutor<Customer> {
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Membership;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the Membership entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface MembershipRepository extends JpaRepository<Membership, Long>, JpaSpecificationExecutor<Membership> {
|
||||
|
||||
@Query("SELECT CASE WHEN COUNT(m)> 0 THEN TRUE ELSE FALSE END " +
|
||||
" FROM Membership m WHERE m.customer.id=:customerId AND m.memberUntilDate IS NULL")
|
||||
boolean hasUncancelledMembershipForCustomer(@Param("customerId") final long customerId);
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.PersistentAuditEvent;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the PersistentAuditEvent entity.
|
||||
*/
|
||||
public interface PersistenceAuditEventRepository extends JpaRepository<PersistentAuditEvent, Long> {
|
||||
|
||||
List<PersistentAuditEvent> findByPrincipal(String principal);
|
||||
|
||||
List<PersistentAuditEvent> findByAuditEventDateAfter(Instant after);
|
||||
|
||||
List<PersistentAuditEvent> findByPrincipalAndAuditEventDateAfter(String principal, Instant after);
|
||||
|
||||
List<PersistentAuditEvent> findByPrincipalAndAuditEventDateAfterAndAuditEventType(
|
||||
String principal,
|
||||
Instant after,
|
||||
String type);
|
||||
|
||||
Page<PersistentAuditEvent> findAllByAuditEventDateBetween(Instant fromDate, Instant toDate, Pageable pageable);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate;
|
||||
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the SepaMandate entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface SepaMandateRepository extends JpaRepository<SepaMandate, Long>, JpaSpecificationExecutor<SepaMandate> {
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the Share entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface ShareRepository extends JpaRepository<Share, Long>, JpaSpecificationExecutor<Share> {
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the User entity.
|
||||
*/
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
String USERS_BY_LOGIN_CACHE = "usersByLogin";
|
||||
|
||||
String USERS_BY_EMAIL_CACHE = "usersByEmail";
|
||||
|
||||
Optional<User> findOneByActivationKey(String activationKey);
|
||||
|
||||
List<User> findAllByActivatedIsFalseAndCreatedDateBefore(Instant dateTime);
|
||||
|
||||
Optional<User> findOneByResetKey(String resetKey);
|
||||
|
||||
Optional<User> findOneByEmailIgnoreCase(String email);
|
||||
|
||||
Optional<User> findOneByLogin(String login);
|
||||
|
||||
@EntityGraph(attributePaths = "authorities")
|
||||
Optional<User> findOneWithAuthoritiesById(Long id);
|
||||
|
||||
@EntityGraph(attributePaths = "authorities")
|
||||
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
|
||||
Optional<User> findOneWithAuthoritiesByLogin(String login);
|
||||
|
||||
@EntityGraph(attributePaths = "authorities")
|
||||
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
|
||||
Optional<User> findOneWithAuthoritiesByEmail(String email);
|
||||
|
||||
Page<User> findAllByLoginNot(Pageable pageable, String login);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.repository;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.UserRoleAssignment;
|
||||
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Spring Data repository for the UserRoleAssignment entity.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Repository
|
||||
public interface UserRoleAssignmentRepository
|
||||
extends JpaRepository<UserRoleAssignment, Long>, JpaSpecificationExecutor<UserRoleAssignment> {
|
||||
|
||||
String CURRENT_USER_ROLE_ASSIGNMENTS_CACHE = "currentUserRoleAssignments";
|
||||
|
||||
// TODO mhoennig: optimize with query by id
|
||||
@Cacheable(CURRENT_USER_ROLE_ASSIGNMENTS_CACHE)
|
||||
@Query("select user_role_assignment from UserRoleAssignment user_role_assignment where user_role_assignment.user.login = :login")
|
||||
List<UserRoleAssignment> findByLogin(@Param("login") final String login);
|
||||
|
||||
@CacheEvict(value = CURRENT_USER_ROLE_ASSIGNMENTS_CACHE, allEntries = true)
|
||||
default void evictCache() {
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Spring Data JPA repositories.
|
||||
*/
|
||||
package org.hostsharing.hsadminng.repository;
|
@ -1,21 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security;
|
||||
|
||||
/**
|
||||
* Constants for Spring Security authorities.
|
||||
*/
|
||||
public final class AuthoritiesConstants {
|
||||
|
||||
public static final String HOSTMASTER = "ROLE_HOSTMASTER";
|
||||
|
||||
public static final String ADMIN = "ROLE_ADMIN";
|
||||
|
||||
public static final String SUPPORTER = "ROLE_SUPPORTER";
|
||||
|
||||
public static final String USER = "ROLE_USER";
|
||||
|
||||
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
|
||||
|
||||
private AuthoritiesConstants() {
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
import org.hostsharing.hsadminng.repository.UserRepository;
|
||||
|
||||
import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Authenticate a user from the database.
|
||||
*/
|
||||
@Component("userDetailsService")
|
||||
public class DomainUserDetailsService implements UserDetailsService {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(DomainUserDetailsService.class);
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public DomainUserDetailsService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public UserDetails loadUserByUsername(final String login) {
|
||||
log.debug("Authenticating {}", login);
|
||||
|
||||
if (new EmailValidator().isValid(login, null)) {
|
||||
return userRepository.findOneWithAuthoritiesByEmail(login)
|
||||
.map(user -> createSpringSecurityUser(login, user))
|
||||
.orElseThrow(
|
||||
() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
|
||||
}
|
||||
|
||||
String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
|
||||
return userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin)
|
||||
.map(user -> createSpringSecurityUser(lowercaseLogin, user))
|
||||
.orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
|
||||
|
||||
}
|
||||
|
||||
private org.springframework.security.core.userdetails.User createSpringSecurityUser(String lowercaseLogin, User user) {
|
||||
if (!user.getActivated()) {
|
||||
throw new UserNotActivatedException("User " + lowercaseLogin + " was not activated");
|
||||
}
|
||||
List<GrantedAuthority> grantedAuthorities = user.getAuthorities()
|
||||
.stream()
|
||||
.map(authority -> new SimpleGrantedAuthority(authority.getName()))
|
||||
.collect(Collectors.toList());
|
||||
return new org.springframework.security.core.userdetails.User(
|
||||
user.getLogin(),
|
||||
user.getPassword(),
|
||||
grantedAuthorities);
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Utility class for Spring Security.
|
||||
*/
|
||||
public final class SecurityUtils {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SecurityUtils.class);
|
||||
|
||||
private SecurityUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the login of the current user.
|
||||
*
|
||||
* @return the login of the current user
|
||||
*/
|
||||
public static Optional<String> getCurrentUserLogin() {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
return Optional.ofNullable(securityContext.getAuthentication())
|
||||
.map(authentication -> {
|
||||
if (authentication.getPrincipal() instanceof UserDetails) {
|
||||
UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
|
||||
return springSecurityUser.getUsername();
|
||||
} else if (authentication.getPrincipal() instanceof String) {
|
||||
return (String) authentication.getPrincipal();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JWT of the current user.
|
||||
*
|
||||
* @return the JWT of the current user
|
||||
*/
|
||||
public static Optional<String> getCurrentUserJWT() {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
return Optional.ofNullable(securityContext.getAuthentication())
|
||||
.filter(authentication -> authentication.getCredentials() instanceof String)
|
||||
.map(authentication -> (String) authentication.getCredentials());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user is authenticated.
|
||||
*
|
||||
* @return true if the user is authenticated, false otherwise
|
||||
*/
|
||||
public static boolean isAuthenticated() {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
return Optional.ofNullable(securityContext.getAuthentication())
|
||||
.map(
|
||||
authentication -> authentication.getAuthorities()
|
||||
.stream()
|
||||
.noneMatch(
|
||||
grantedAuthority -> grantedAuthority.getAuthority()
|
||||
.equals(AuthoritiesConstants.ANONYMOUS)))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the current user has a specific authority (security role).
|
||||
* <p>
|
||||
* The name of this method comes from the isUserInRole() method in the Servlet API
|
||||
*
|
||||
* @param authority the authority to check
|
||||
* @return true if the current user has the authority, false otherwise
|
||||
*/
|
||||
public static boolean isCurrentUserInRole(String authority) {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
final Boolean isCurrentUserInRole = Optional.ofNullable(securityContext.getAuthentication())
|
||||
.map(
|
||||
authentication -> authentication.getAuthorities()
|
||||
.stream()
|
||||
.anyMatch(grantedAuthority -> grantedAuthority.getAuthority().equals(authority)))
|
||||
.orElse(false);
|
||||
return isCurrentUserInRole;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security;
|
||||
|
||||
import org.hostsharing.hsadminng.config.Constants;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Implementation of AuditorAware based on Spring Security.
|
||||
*/
|
||||
@Component
|
||||
public class SpringSecurityAuditorAware implements AuditorAware<String> {
|
||||
|
||||
@Override
|
||||
public Optional<String> getCurrentAuditor() {
|
||||
return Optional.of(SecurityUtils.getCurrentUserLogin().orElse(Constants.SYSTEM_ACCOUNT));
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
/**
|
||||
* This exception is thrown in case of a not activated user trying to authenticate.
|
||||
*/
|
||||
public class UserNotActivatedException extends AuthenticationException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserNotActivatedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UserNotActivatedException(String message, Throwable t) {
|
||||
super(message, t);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security.jwt;
|
||||
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.DefaultSecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
public class JWTConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
|
||||
private TokenProvider tokenProvider;
|
||||
|
||||
public JWTConfigurer(TokenProvider tokenProvider) {
|
||||
this.tokenProvider = tokenProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
JWTFilter customFilter = new JWTFilter(tokenProvider);
|
||||
http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security.jwt;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Filters incoming requests and installs a Spring Security principal if a header corresponding to a valid user is
|
||||
* found.
|
||||
*/
|
||||
public class JWTFilter extends GenericFilterBean {
|
||||
|
||||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
private TokenProvider tokenProvider;
|
||||
|
||||
public JWTFilter(TokenProvider tokenProvider) {
|
||||
this.tokenProvider = tokenProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||
String jwt = resolveToken(httpServletRequest);
|
||||
if (StringUtils.hasText(jwt) && this.tokenProvider.validateToken(jwt)) {
|
||||
Authentication authentication = this.tokenProvider.getAuthentication(jwt);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
private String resolveToken(HttpServletRequest request) {
|
||||
String bearerToken = request.getHeader(AUTHORIZATION_HEADER);
|
||||
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
|
||||
return bearerToken.substring(7);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.security.jwt;
|
||||
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
import io.jsonwebtoken.*;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Key;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
public class TokenProvider {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(TokenProvider.class);
|
||||
|
||||
private static final String AUTHORITIES_KEY = "auth";
|
||||
|
||||
private Key key;
|
||||
|
||||
private long tokenValidityInMilliseconds;
|
||||
|
||||
private long tokenValidityInMillisecondsForRememberMe;
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
public TokenProvider(JHipsterProperties jHipsterProperties) {
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
byte[] keyBytes;
|
||||
String secret = jHipsterProperties.getSecurity().getAuthentication().getJwt().getSecret();
|
||||
if (!StringUtils.isEmpty(secret)) {
|
||||
log.warn(
|
||||
"Warning: the JWT key used is not Base64-encoded. " +
|
||||
"We recommend using the `jhipster.security.authentication.jwt.base64-secret` key for optimum security.");
|
||||
keyBytes = secret.getBytes(StandardCharsets.UTF_8);
|
||||
} else {
|
||||
log.debug("Using a Base64-encoded JWT secret key");
|
||||
keyBytes = Decoders.BASE64.decode(jHipsterProperties.getSecurity().getAuthentication().getJwt().getBase64Secret());
|
||||
}
|
||||
this.key = Keys.hmacShaKeyFor(keyBytes);
|
||||
this.tokenValidityInMilliseconds = 1000
|
||||
* jHipsterProperties.getSecurity().getAuthentication().getJwt().getTokenValidityInSeconds();
|
||||
this.tokenValidityInMillisecondsForRememberMe = 1000 * jHipsterProperties.getSecurity()
|
||||
.getAuthentication()
|
||||
.getJwt()
|
||||
.getTokenValidityInSecondsForRememberMe();
|
||||
}
|
||||
|
||||
public String createToken(Authentication authentication, boolean rememberMe) {
|
||||
String authorities = authentication.getAuthorities()
|
||||
.stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
long now = (new Date()).getTime();
|
||||
Date validity;
|
||||
if (rememberMe) {
|
||||
validity = new Date(now + this.tokenValidityInMillisecondsForRememberMe);
|
||||
} else {
|
||||
validity = new Date(now + this.tokenValidityInMilliseconds);
|
||||
}
|
||||
|
||||
return Jwts.builder()
|
||||
.setSubject(authentication.getName())
|
||||
.claim(AUTHORITIES_KEY, authorities)
|
||||
.signWith(key, SignatureAlgorithm.HS512)
|
||||
.setExpiration(validity)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public Authentication getAuthentication(String token) {
|
||||
Claims claims = Jwts.parser()
|
||||
.setSigningKey(key)
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
|
||||
Collection<? extends GrantedAuthority> authorities = Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
User principal = new User(claims.getSubject(), "", authorities);
|
||||
|
||||
return new UsernamePasswordAuthenticationToken(principal, token, authorities);
|
||||
}
|
||||
|
||||
public boolean validateToken(String authToken) {
|
||||
try {
|
||||
Jwts.parser().setSigningKey(key).parseClaimsJws(authToken);
|
||||
return true;
|
||||
} catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) {
|
||||
log.info("Invalid JWT signature.");
|
||||
log.trace("Invalid JWT signature trace: {}", e);
|
||||
} catch (ExpiredJwtException e) {
|
||||
log.info("Expired JWT token.");
|
||||
log.trace("Expired JWT token trace: {}", e);
|
||||
} catch (UnsupportedJwtException e) {
|
||||
log.info("Unsupported JWT token.");
|
||||
log.trace("Unsupported JWT token trace: {}", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.info("JWT token compact of handler are invalid.");
|
||||
log.trace("JWT token compact of handler are invalid trace: {}", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Spring Security configuration.
|
||||
*/
|
||||
package org.hostsharing.hsadminng.security;
|
@ -1,120 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.*;
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
import org.hostsharing.hsadminng.repository.AssetRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.AssetCriteria;
|
||||
import org.hostsharing.hsadminng.service.dto.AssetDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.AssetMapper;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for Asset entities in the database.
|
||||
* The main input is a {@link AssetCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link AssetDTO} or a {@link Page} of {@link AssetDTO} which fulfills the criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class AssetQueryService extends QueryService<Asset> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AssetQueryService.class);
|
||||
|
||||
private final AssetRepository assetRepository;
|
||||
|
||||
private final AssetMapper assetMapper;
|
||||
|
||||
public AssetQueryService(AssetRepository assetRepository, AssetMapper assetMapper) {
|
||||
this.assetRepository = assetRepository;
|
||||
this.assetMapper = assetMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link AssetDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<AssetDTO> findByCriteria(AssetCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<Asset> specification = createSpecification(criteria);
|
||||
return assetMapper.toDto(assetRepository.findAll(specification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link AssetDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<AssetDTO> findByCriteria(AssetCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<Asset> specification = createSpecification(criteria);
|
||||
return assetRepository.findAll(specification, page)
|
||||
.map(assetMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(AssetCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<Asset> specification = createSpecification(criteria);
|
||||
return assetRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert AssetCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<Asset> createSpecification(AssetCriteria criteria) {
|
||||
Specification<Asset> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), Asset_.id));
|
||||
}
|
||||
if (criteria.getDocumentDate() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getDocumentDate(), Asset_.documentDate));
|
||||
}
|
||||
if (criteria.getValueDate() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getValueDate(), Asset_.valueDate));
|
||||
}
|
||||
if (criteria.getAction() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getAction(), Asset_.action));
|
||||
}
|
||||
if (criteria.getAmount() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getAmount(), Asset_.amount));
|
||||
}
|
||||
if (criteria.getRemark() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getRemark(), Asset_.remark));
|
||||
}
|
||||
if (criteria.getMembershipId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getMembershipId(),
|
||||
root -> root.join(Asset_.membership, JoinType.LEFT).get(Membership_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
import org.hostsharing.hsadminng.repository.AssetRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.AssetDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.AssetMapper;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing Asset.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class AssetService implements IdToDtoResolver<AssetDTO> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AssetService.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final AssetRepository assetRepository;
|
||||
|
||||
private final AssetMapper assetMapper;
|
||||
private final AssetValidator assetValidator;
|
||||
|
||||
public AssetService(
|
||||
final EntityManager em,
|
||||
final AssetRepository assetRepository,
|
||||
final AssetMapper assetMapper,
|
||||
final AssetValidator assetValidator) {
|
||||
this.em = em;
|
||||
this.assetRepository = assetRepository;
|
||||
this.assetMapper = assetMapper;
|
||||
this.assetValidator = assetValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a asset.
|
||||
*
|
||||
* @param assetDTO the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public AssetDTO save(AssetDTO assetDTO) {
|
||||
log.debug("Request to save Asset : {}", assetDTO);
|
||||
assetValidator.validate(assetDTO);
|
||||
Asset asset = assetMapper.toEntity(assetDTO);
|
||||
asset = assetRepository.save(asset);
|
||||
em.flush();
|
||||
em.refresh(asset);
|
||||
return assetMapper.toDto(asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the assets.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<AssetDTO> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all Assets");
|
||||
return assetRepository.findAll(pageable)
|
||||
.map(assetMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one asset by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<AssetDTO> findOne(Long id) {
|
||||
log.debug("Request to get Asset : {}", id);
|
||||
return assetRepository.findById(id)
|
||||
.map(assetMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the asset by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete Asset : {}", id);
|
||||
|
||||
throw new BadRequestAlertException("Asset transactions are immutable", Asset.ENTITY_NAME, "assetTransactionImmutable");
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
import org.hostsharing.hsadminng.service.dto.AssetDTO;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class AssetValidator {
|
||||
|
||||
public void validate(final AssetDTO assetDTO) {
|
||||
if (assetDTO.getId() != null) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset transactions are immutable",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetTransactionImmutable");
|
||||
}
|
||||
|
||||
if (assetDTO.getDocumentDate().isAfter(assetDTO.getValueDate())) {
|
||||
throw new BadRequestAlertException(
|
||||
"Document date may not be after value date",
|
||||
Asset.ENTITY_NAME,
|
||||
"documentDateMayNotBeAfterValueDate");
|
||||
}
|
||||
|
||||
if ((assetDTO.getAction() == AssetAction.PAYMENT) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) <= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset payments require a positive amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetPaymentsPositiveAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.ADOPTION) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) <= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset adoptions require a positive amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetAdoptionsPositiveAmount");
|
||||
}
|
||||
|
||||
if ((assetDTO.getAction() == AssetAction.PAYBACK) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset paybacks require a negative amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetPaybacksNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.HANDOVER) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset handovers require a negative amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetHandoversNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.LOSS) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset losses require a negative amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetLossesNegativeAmount");
|
||||
}
|
||||
if ((assetDTO.getAction() == AssetAction.CLEARING) && (assetDTO.getAmount().compareTo(BigDecimal.valueOf(0)) >= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Asset clearings require a negative amount",
|
||||
Asset.ENTITY_NAME,
|
||||
"assetClearingsNegativeAmount");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.config.audit.AuditEventConverter;
|
||||
import org.hostsharing.hsadminng.repository.PersistenceAuditEventRepository;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEvent;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Service for managing audit events.
|
||||
* <p>
|
||||
* This is the default implementation to support SpringBoot Actuator AuditEventRepository
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class AuditEventService {
|
||||
|
||||
private final PersistenceAuditEventRepository persistenceAuditEventRepository;
|
||||
|
||||
private final AuditEventConverter auditEventConverter;
|
||||
|
||||
public AuditEventService(
|
||||
PersistenceAuditEventRepository persistenceAuditEventRepository,
|
||||
AuditEventConverter auditEventConverter) {
|
||||
|
||||
this.persistenceAuditEventRepository = persistenceAuditEventRepository;
|
||||
this.auditEventConverter = auditEventConverter;
|
||||
}
|
||||
|
||||
public Page<AuditEvent> findAll(Pageable pageable) {
|
||||
return persistenceAuditEventRepository.findAll(pageable)
|
||||
.map(auditEventConverter::convertToAuditEvent);
|
||||
}
|
||||
|
||||
public Page<AuditEvent> findByDates(Instant fromDate, Instant toDate, Pageable pageable) {
|
||||
return persistenceAuditEventRepository.findAllByAuditEventDateBetween(fromDate, toDate, pageable)
|
||||
.map(auditEventConverter::convertToAuditEvent);
|
||||
}
|
||||
|
||||
public Optional<AuditEvent> find(Long id) {
|
||||
return Optional.ofNullable(persistenceAuditEventRepository.findById(id))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(auditEventConverter::convertToAuditEvent);
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer;
|
||||
import org.hostsharing.hsadminng.domain.Customer_;
|
||||
import org.hostsharing.hsadminng.domain.Membership_;
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate_;
|
||||
import org.hostsharing.hsadminng.repository.CustomerRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.CustomerCriteria;
|
||||
import org.hostsharing.hsadminng.service.dto.CustomerDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.CustomerMapper;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for Customer entities in the database.
|
||||
* The main input is a {@link CustomerCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link CustomerDTO} or a {@link Page} of {@link CustomerDTO} which fulfills the criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class CustomerQueryService extends QueryService<Customer> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CustomerQueryService.class);
|
||||
|
||||
private final CustomerRepository customerRepository;
|
||||
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
public CustomerQueryService(CustomerRepository customerRepository, CustomerMapper customerMapper) {
|
||||
this.customerRepository = customerRepository;
|
||||
this.customerMapper = customerMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link CustomerDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<CustomerDTO> findByCriteria(CustomerCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<Customer> specification = createSpecification(criteria);
|
||||
return customerMapper.toDto(customerRepository.findAll(specification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link CustomerDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<CustomerDTO> findByCriteria(CustomerCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<Customer> specification = createSpecification(criteria);
|
||||
return customerRepository.findAll(specification, page)
|
||||
.map(customerMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(CustomerCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<Customer> specification = createSpecification(criteria);
|
||||
return customerRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert CustomerCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<Customer> createSpecification(CustomerCriteria criteria) {
|
||||
Specification<Customer> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), Customer_.id));
|
||||
}
|
||||
if (criteria.getReference() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getReference(), Customer_.reference));
|
||||
}
|
||||
if (criteria.getPrefix() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getPrefix(), Customer_.prefix));
|
||||
}
|
||||
if (criteria.getName() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getName(), Customer_.name));
|
||||
}
|
||||
if (criteria.getKind() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getKind(), Customer_.kind));
|
||||
}
|
||||
if (criteria.getBirthDate() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getBirthDate(), Customer_.birthDate));
|
||||
}
|
||||
if (criteria.getBirthPlace() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getBirthPlace(), Customer_.birthPlace));
|
||||
}
|
||||
if (criteria.getRegistrationCourt() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getRegistrationCourt(), Customer_.registrationCourt));
|
||||
}
|
||||
if (criteria.getRegistrationNumber() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getRegistrationNumber(), Customer_.registrationNumber));
|
||||
}
|
||||
if (criteria.getVatRegion() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getVatRegion(), Customer_.vatRegion));
|
||||
}
|
||||
if (criteria.getVatNumber() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getVatNumber(), Customer_.vatNumber));
|
||||
}
|
||||
if (criteria.getContractualSalutation() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getContractualSalutation(), Customer_.contractualSalutation));
|
||||
}
|
||||
if (criteria.getContractualAddress() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getContractualAddress(), Customer_.contractualAddress));
|
||||
}
|
||||
if (criteria.getBillingSalutation() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getBillingSalutation(), Customer_.billingSalutation));
|
||||
}
|
||||
if (criteria.getBillingAddress() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getBillingAddress(), Customer_.billingAddress));
|
||||
}
|
||||
if (criteria.getRemark() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getRemark(), Customer_.remark));
|
||||
}
|
||||
if (criteria.getMembershipId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getMembershipId(),
|
||||
root -> root.join(Customer_.memberships, JoinType.LEFT).get(Membership_.id)));
|
||||
}
|
||||
if (criteria.getSepamandateId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getSepamandateId(),
|
||||
root -> root.join(Customer_.sepamandates, JoinType.LEFT).get(SepaMandate_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer;
|
||||
import org.hostsharing.hsadminng.repository.CustomerRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.CustomerDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.CustomerMapper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing Customer.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class CustomerService implements IdToDtoResolver<CustomerDTO> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CustomerService.class);
|
||||
|
||||
private final CustomerRepository customerRepository;
|
||||
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
public CustomerService(CustomerRepository customerRepository, CustomerMapper customerMapper) {
|
||||
this.customerRepository = customerRepository;
|
||||
this.customerMapper = customerMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a customer.
|
||||
*
|
||||
* @param customerDTO the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public CustomerDTO save(CustomerDTO customerDTO) {
|
||||
log.debug("Request to save Customer : {}", customerDTO);
|
||||
Customer customer = customerMapper.toEntity(customerDTO);
|
||||
customer = customerRepository.save(customer);
|
||||
return customerMapper.toDto(customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the customers.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<CustomerDTO> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all Customers");
|
||||
return customerRepository.findAll(pageable)
|
||||
.map(customerMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one customer by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<CustomerDTO> findOne(Long id) {
|
||||
log.debug("Request to get Customer : {}", id);
|
||||
return customerRepository.findById(id)
|
||||
.map(customerMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the customer by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete Customer : {}", id);
|
||||
customerRepository.deleteById(id);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IdToDtoResolver<T> {
|
||||
|
||||
Optional<T> findOne(Long id);
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thymeleaf.context.Context;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
/**
|
||||
* Service for sending emails.
|
||||
* <p>
|
||||
* We use the @Async annotation to send emails asynchronously.
|
||||
*/
|
||||
@Service
|
||||
public class MailService {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(MailService.class);
|
||||
|
||||
private static final String USER = "user";
|
||||
|
||||
private static final String BASE_URL = "baseUrl";
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
private final JavaMailSender javaMailSender;
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final SpringTemplateEngine templateEngine;
|
||||
|
||||
public MailService(
|
||||
JHipsterProperties jHipsterProperties,
|
||||
JavaMailSender javaMailSender,
|
||||
MessageSource messageSource,
|
||||
SpringTemplateEngine templateEngine) {
|
||||
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
this.javaMailSender = javaMailSender;
|
||||
this.messageSource = messageSource;
|
||||
this.templateEngine = templateEngine;
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
|
||||
log.debug(
|
||||
"Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
|
||||
isMultipart,
|
||||
isHtml,
|
||||
to,
|
||||
subject,
|
||||
content);
|
||||
|
||||
// Prepare message using a Spring helper
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
try {
|
||||
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
|
||||
message.setTo(to);
|
||||
message.setFrom(jHipsterProperties.getMail().getFrom());
|
||||
message.setSubject(subject);
|
||||
message.setText(content, isHtml);
|
||||
javaMailSender.send(mimeMessage);
|
||||
log.debug("Sent email to User '{}'", to);
|
||||
} catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.warn("Email could not be sent to user '{}'", to, e);
|
||||
} else {
|
||||
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
|
||||
Locale locale = Locale.forLanguageTag(user.getLangKey());
|
||||
Context context = new Context(locale);
|
||||
context.setVariable(USER, user);
|
||||
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
|
||||
String content = templateEngine.process(templateName, context);
|
||||
String subject = messageSource.getMessage(titleKey, null, locale);
|
||||
sendEmail(user.getEmail(), subject, content, false, true);
|
||||
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendActivationEmail(User user) {
|
||||
log.debug("Sending activation email to '{}'", user.getEmail());
|
||||
sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title");
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendCreationEmail(User user) {
|
||||
log.debug("Sending creation email to '{}'", user.getEmail());
|
||||
sendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title");
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendPasswordResetMail(User user) {
|
||||
log.debug("Sending password reset email to '{}'", user.getEmail());
|
||||
sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title");
|
||||
}
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.*;
|
||||
import org.hostsharing.hsadminng.repository.MembershipRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipCriteria;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.MembershipMapper;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for Membership entities in the database.
|
||||
* The main input is a {@link MembershipCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link MembershipDTO} or a {@link Page} of {@link MembershipDTO} which fulfills the criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class MembershipQueryService extends QueryService<Membership> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(MembershipQueryService.class);
|
||||
|
||||
private final MembershipRepository membershipRepository;
|
||||
|
||||
private final MembershipMapper membershipMapper;
|
||||
|
||||
public MembershipQueryService(MembershipRepository membershipRepository, MembershipMapper membershipMapper) {
|
||||
this.membershipRepository = membershipRepository;
|
||||
this.membershipMapper = membershipMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link MembershipDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<MembershipDTO> findByCriteria(MembershipCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<Membership> specification = createSpecification(criteria);
|
||||
return membershipMapper.toDto(membershipRepository.findAll(specification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link MembershipDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<MembershipDTO> findByCriteria(MembershipCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<Membership> specification = createSpecification(criteria);
|
||||
return membershipRepository.findAll(specification, page)
|
||||
.map(membershipMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(MembershipCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<Membership> specification = createSpecification(criteria);
|
||||
return membershipRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert MembershipCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<Membership> createSpecification(MembershipCriteria criteria) {
|
||||
Specification<Membership> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), Membership_.id));
|
||||
}
|
||||
if (criteria.getAdmissionDocumentDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getAdmissionDocumentDate(), Membership_.admissionDocumentDate));
|
||||
}
|
||||
if (criteria.getCancellationDocumentDate() != null) {
|
||||
specification = specification.and(
|
||||
buildRangeSpecification(criteria.getCancellationDocumentDate(), Membership_.cancellationDocumentDate));
|
||||
}
|
||||
if (criteria.getMemberFromDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getMemberFromDate(), Membership_.memberFromDate));
|
||||
}
|
||||
if (criteria.getMemberUntilDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getMemberUntilDate(), Membership_.memberUntilDate));
|
||||
}
|
||||
if (criteria.getRemark() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getRemark(), Membership_.remark));
|
||||
}
|
||||
if (criteria.getShareId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getShareId(),
|
||||
root -> root.join(Membership_.shares, JoinType.LEFT).get(Share_.id)));
|
||||
}
|
||||
if (criteria.getAssetId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getAssetId(),
|
||||
root -> root.join(Membership_.assets, JoinType.LEFT).get(Asset_.id)));
|
||||
}
|
||||
if (criteria.getCustomerId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getCustomerId(),
|
||||
root -> root.join(Membership_.customer, JoinType.LEFT).get(Customer_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Membership;
|
||||
import org.hostsharing.hsadminng.repository.MembershipRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.MembershipMapper;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing Membership.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class MembershipService implements IdToDtoResolver<MembershipDTO> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(MembershipService.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final MembershipValidator membershipValidator;
|
||||
|
||||
private final MembershipRepository membershipRepository;
|
||||
|
||||
private final MembershipMapper membershipMapper;
|
||||
|
||||
public MembershipService(
|
||||
final EntityManager em,
|
||||
final MembershipValidator membershipValidator,
|
||||
final MembershipRepository membershipRepository,
|
||||
final MembershipMapper membershipMapper) {
|
||||
this.em = em;
|
||||
this.membershipValidator = membershipValidator;
|
||||
this.membershipRepository = membershipRepository;
|
||||
this.membershipMapper = membershipMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a membership.
|
||||
*
|
||||
* @param membershipDTO the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public MembershipDTO save(MembershipDTO membershipDTO) {
|
||||
log.debug("Request to save Membership : {}", membershipDTO);
|
||||
|
||||
membershipValidator.validate(membershipDTO);
|
||||
|
||||
Membership membership = membershipMapper.toEntity(membershipDTO);
|
||||
membership = membershipRepository.save(membership);
|
||||
em.flush();
|
||||
em.refresh(membership);
|
||||
return membershipMapper.toDto(membership);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the memberships.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<MembershipDTO> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all Memberships");
|
||||
return membershipRepository.findAll(pageable)
|
||||
.map(membershipMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one membership by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<MembershipDTO> findOne(Long id) {
|
||||
log.debug("Request to get Membership : {}", id);
|
||||
return membershipRepository.findById(id)
|
||||
.map(membershipMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent deleting a membership by id via service call.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete Membership : {}", id);
|
||||
throw new BadRequestAlertException("Membership cannot be deleted", Membership.ENTITY_NAME, "membershipNotDeletable");
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Membership;
|
||||
import org.hostsharing.hsadminng.repository.MembershipRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MembershipValidator {
|
||||
|
||||
@Autowired
|
||||
private MembershipRepository membershipRepository;
|
||||
|
||||
public void validate(final MembershipDTO membershipDTO) {
|
||||
if (membershipDTO.getMemberUntilDate() != null
|
||||
&& !membershipDTO.getMemberUntilDate().isAfter(membershipDTO.getMemberFromDate())) {
|
||||
throw new BadRequestAlertException("Invalid untilDate", Membership.ENTITY_NAME, "untilDateMustBeAfterSinceDate");
|
||||
}
|
||||
|
||||
// It's known that this validation can cause a race condition if two memberships of the same customer are saved at
|
||||
// same time (overlapping transactions). This is ignored in this case because it's too unlikely to be worth the effort.
|
||||
if (membershipRepository.hasUncancelledMembershipForCustomer(membershipDTO.getCustomerId())) {
|
||||
throw new BadRequestAlertException(
|
||||
"Another uncancelled membership exists",
|
||||
Membership.ENTITY_NAME,
|
||||
"anotherUncancelledMembershipExists");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer_;
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate;
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate_;
|
||||
import org.hostsharing.hsadminng.repository.SepaMandateRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.SepaMandateCriteria;
|
||||
import org.hostsharing.hsadminng.service.dto.SepaMandateDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.SepaMandateMapper;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for SepaMandate entities in the database.
|
||||
* The main input is a {@link SepaMandateCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link SepaMandateDTO} or a {@link Page} of {@link SepaMandateDTO} which fulfills the criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class SepaMandateQueryService extends QueryService<SepaMandate> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(SepaMandateQueryService.class);
|
||||
|
||||
private final SepaMandateRepository sepaMandateRepository;
|
||||
|
||||
private final SepaMandateMapper sepaMandateMapper;
|
||||
|
||||
public SepaMandateQueryService(SepaMandateRepository sepaMandateRepository, SepaMandateMapper sepaMandateMapper) {
|
||||
this.sepaMandateRepository = sepaMandateRepository;
|
||||
this.sepaMandateMapper = sepaMandateMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link SepaMandateDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<SepaMandateDTO> findByCriteria(SepaMandateCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<SepaMandate> specification = createSpecification(criteria);
|
||||
return sepaMandateMapper.toDto(sepaMandateRepository.findAll(specification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link SepaMandateDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<SepaMandateDTO> findByCriteria(SepaMandateCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<SepaMandate> specification = createSpecification(criteria);
|
||||
return sepaMandateRepository.findAll(specification, page)
|
||||
.map(sepaMandateMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(SepaMandateCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<SepaMandate> specification = createSpecification(criteria);
|
||||
return sepaMandateRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert SepaMandateCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<SepaMandate> createSpecification(SepaMandateCriteria criteria) {
|
||||
Specification<SepaMandate> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), SepaMandate_.id));
|
||||
}
|
||||
if (criteria.getReference() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getReference(), SepaMandate_.reference));
|
||||
}
|
||||
if (criteria.getIban() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getIban(), SepaMandate_.iban));
|
||||
}
|
||||
if (criteria.getBic() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getBic(), SepaMandate_.bic));
|
||||
}
|
||||
if (criteria.getGrantingDocumentDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getGrantingDocumentDate(), SepaMandate_.grantingDocumentDate));
|
||||
}
|
||||
if (criteria.getRevokationDocumentDate() != null) {
|
||||
specification = specification.and(
|
||||
buildRangeSpecification(criteria.getRevokationDocumentDate(), SepaMandate_.revokationDocumentDate));
|
||||
}
|
||||
if (criteria.getValidFromDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getValidFromDate(), SepaMandate_.validFromDate));
|
||||
}
|
||||
if (criteria.getValidUntilDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getValidUntilDate(), SepaMandate_.validUntilDate));
|
||||
}
|
||||
if (criteria.getLastUsedDate() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getLastUsedDate(), SepaMandate_.lastUsedDate));
|
||||
}
|
||||
if (criteria.getRemark() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getRemark(), SepaMandate_.remark));
|
||||
}
|
||||
if (criteria.getCustomerId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getCustomerId(),
|
||||
root -> root.join(SepaMandate_.customer, JoinType.LEFT).get(Customer_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate;
|
||||
import org.hostsharing.hsadminng.repository.SepaMandateRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.SepaMandateDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.SepaMandateMapper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing SepaMandate.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class SepaMandateService implements IdToDtoResolver<SepaMandateDTO> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(SepaMandateService.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final SepaMandateRepository sepaMandateRepository;
|
||||
|
||||
private final SepaMandateMapper sepaMandateMapper;
|
||||
|
||||
public SepaMandateService(
|
||||
final EntityManager em,
|
||||
final SepaMandateRepository sepaMandateRepository,
|
||||
final SepaMandateMapper sepaMandateMapper) {
|
||||
this.em = em;
|
||||
this.sepaMandateRepository = sepaMandateRepository;
|
||||
this.sepaMandateMapper = sepaMandateMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a sepaMandate.
|
||||
*
|
||||
* @param sepaMandateDTO the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public SepaMandateDTO save(SepaMandateDTO sepaMandateDTO) {
|
||||
log.debug("Request to save SepaMandate : {}", sepaMandateDTO);
|
||||
SepaMandate sepaMandate = sepaMandateMapper.toEntity(sepaMandateDTO);
|
||||
sepaMandate = sepaMandateRepository.save(sepaMandate);
|
||||
em.flush();
|
||||
em.refresh(sepaMandate);
|
||||
return sepaMandateMapper.toDto(sepaMandate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the sepaMandates.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<SepaMandateDTO> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all SepaMandates");
|
||||
return sepaMandateRepository.findAll(pageable)
|
||||
.map(sepaMandateMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one sepaMandate by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<SepaMandateDTO> findOne(Long id) {
|
||||
log.debug("Request to get SepaMandate : {}", id);
|
||||
return sepaMandateRepository.findById(id)
|
||||
.map(sepaMandateMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the sepaMandate by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete SepaMandate : {}", id);
|
||||
sepaMandateRepository.deleteById(id);
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.*;
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
import org.hostsharing.hsadminng.repository.ShareRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.ShareCriteria;
|
||||
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.ShareMapper;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for Share entities in the database.
|
||||
* The main input is a {@link ShareCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link ShareDTO} or a {@link Page} of {@link ShareDTO} which fulfills the criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class ShareQueryService extends QueryService<Share> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ShareQueryService.class);
|
||||
|
||||
private final ShareRepository shareRepository;
|
||||
|
||||
private final ShareMapper shareMapper;
|
||||
|
||||
public ShareQueryService(ShareRepository shareRepository, ShareMapper shareMapper) {
|
||||
this.shareRepository = shareRepository;
|
||||
this.shareMapper = shareMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link ShareDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<ShareDTO> findByCriteria(ShareCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<Share> specification = createSpecification(criteria);
|
||||
return shareMapper.toDto(shareRepository.findAll(specification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link ShareDTO} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<ShareDTO> findByCriteria(ShareCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<Share> specification = createSpecification(criteria);
|
||||
return shareRepository.findAll(specification, page)
|
||||
.map(shareMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(ShareCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<Share> specification = createSpecification(criteria);
|
||||
return shareRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert ShareCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<Share> createSpecification(ShareCriteria criteria) {
|
||||
Specification<Share> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), Share_.id));
|
||||
}
|
||||
if (criteria.getDocumentDate() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getDocumentDate(), Share_.documentDate));
|
||||
}
|
||||
if (criteria.getValueDate() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getValueDate(), Share_.valueDate));
|
||||
}
|
||||
if (criteria.getAction() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getAction(), Share_.action));
|
||||
}
|
||||
if (criteria.getQuantity() != null) {
|
||||
specification = specification.and(buildRangeSpecification(criteria.getQuantity(), Share_.quantity));
|
||||
}
|
||||
if (criteria.getRemark() != null) {
|
||||
specification = specification.and(buildStringSpecification(criteria.getRemark(), Share_.remark));
|
||||
}
|
||||
if (criteria.getMembershipId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getMembershipId(),
|
||||
root -> root.join(Share_.membership, JoinType.LEFT).get(Membership_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
import org.hostsharing.hsadminng.repository.ShareRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.ShareMapper;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing Share.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class ShareService implements IdToDtoResolver<ShareDTO> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ShareService.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final ShareRepository shareRepository;
|
||||
|
||||
private final ShareMapper shareMapper;
|
||||
|
||||
private final ShareValidator shareValidator;
|
||||
|
||||
public ShareService(
|
||||
final EntityManager em,
|
||||
final ShareRepository shareRepository,
|
||||
final ShareMapper shareMapper,
|
||||
final ShareValidator shareValidator) {
|
||||
this.em = em;
|
||||
this.shareRepository = shareRepository;
|
||||
this.shareMapper = shareMapper;
|
||||
this.shareValidator = shareValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a share.
|
||||
*
|
||||
* @param shareDTO the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public ShareDTO save(ShareDTO shareDTO) {
|
||||
log.debug("Request to save Share : {}", shareDTO);
|
||||
|
||||
shareValidator.validate(shareDTO);
|
||||
|
||||
Share share = shareMapper.toEntity(shareDTO);
|
||||
share = shareRepository.save(share);
|
||||
em.flush();
|
||||
em.refresh(share);
|
||||
return shareMapper.toDto(share);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the shares.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<ShareDTO> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all Shares");
|
||||
return shareRepository.findAll(pageable)
|
||||
.map(shareMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one share by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<ShareDTO> findOne(Long id) {
|
||||
log.debug("Request to get Share : {}", id);
|
||||
return shareRepository.findById(id)
|
||||
.map(shareMapper::toDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent deleting a share transaction by id via service call
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete Share : {}", id);
|
||||
|
||||
throw new BadRequestAlertException("Share transactions are immutable", Share.ENTITY_NAME, "shareTransactionImmutable");
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ShareValidator {
|
||||
|
||||
public void validate(final ShareDTO shareDTO) {
|
||||
if (shareDTO.getId() != null) {
|
||||
throw new BadRequestAlertException(
|
||||
"Share transactions are immutable",
|
||||
Share.ENTITY_NAME,
|
||||
"shareTransactionImmutable");
|
||||
}
|
||||
|
||||
if (shareDTO.getDocumentDate().isAfter(shareDTO.getValueDate())) {
|
||||
throw new BadRequestAlertException(
|
||||
"Document date may not be after value date",
|
||||
Share.ENTITY_NAME,
|
||||
"documentDateMayNotBeAfterValueDate");
|
||||
}
|
||||
|
||||
if ((shareDTO.getAction() == ShareAction.SUBSCRIPTION) && (shareDTO.getQuantity() <= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Share subscriptions require a positive quantity",
|
||||
Share.ENTITY_NAME,
|
||||
"shareSubscriptionPositiveQuantity");
|
||||
}
|
||||
|
||||
if ((shareDTO.getAction() == ShareAction.CANCELLATION) && (shareDTO.getQuantity() >= 0)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Share cancellations require a negative quantity",
|
||||
Share.ENTITY_NAME,
|
||||
"shareCancellationNegativeQuantity");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.*;
|
||||
import org.hostsharing.hsadminng.domain.UserRoleAssignment;
|
||||
import org.hostsharing.hsadminng.repository.UserRoleAssignmentRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.UserRoleAssignmentCriteria;
|
||||
|
||||
import io.github.jhipster.service.QueryService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
||||
/**
|
||||
* Service for executing complex queries for UserRoleAssignment entities in the database.
|
||||
* The main input is a {@link UserRoleAssignmentCriteria} which gets converted to {@link Specification},
|
||||
* in a way that all the filters must apply.
|
||||
* It returns a {@link List} of {@link UserRoleAssignment} or a {@link Page} of {@link UserRoleAssignment} which fulfills the
|
||||
* criteria.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class UserRoleAssignmentQueryService extends QueryService<UserRoleAssignment> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(UserRoleAssignmentQueryService.class);
|
||||
|
||||
private final UserRoleAssignmentRepository userRoleAssignmentRepository;
|
||||
|
||||
public UserRoleAssignmentQueryService(UserRoleAssignmentRepository userRoleAssignmentRepository) {
|
||||
this.userRoleAssignmentRepository = userRoleAssignmentRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link List} of {@link UserRoleAssignment} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<UserRoleAssignment> findByCriteria(UserRoleAssignmentCriteria criteria) {
|
||||
log.debug("find by criteria : {}", criteria);
|
||||
final Specification<UserRoleAssignment> specification = createSpecification(criteria);
|
||||
return userRoleAssignmentRepository.findAll(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link Page} of {@link UserRoleAssignment} which matches the criteria from the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @param page The page, which should be returned.
|
||||
* @return the matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<UserRoleAssignment> findByCriteria(UserRoleAssignmentCriteria criteria, Pageable page) {
|
||||
log.debug("find by criteria : {}, page: {}", criteria, page);
|
||||
final Specification<UserRoleAssignment> specification = createSpecification(criteria);
|
||||
return userRoleAssignmentRepository.findAll(specification, page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of matching entities in the database
|
||||
*
|
||||
* @param criteria The object which holds all the filters, which the entities should match.
|
||||
* @return the number of matching entities.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public long countByCriteria(UserRoleAssignmentCriteria criteria) {
|
||||
log.debug("count by criteria : {}", criteria);
|
||||
final Specification<UserRoleAssignment> specification = createSpecification(criteria);
|
||||
return userRoleAssignmentRepository.count(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert UserRoleAssignmentCriteria to a {@link Specification}
|
||||
*/
|
||||
private Specification<UserRoleAssignment> createSpecification(UserRoleAssignmentCriteria criteria) {
|
||||
Specification<UserRoleAssignment> specification = Specification.where(null);
|
||||
if (criteria != null) {
|
||||
if (criteria.getId() != null) {
|
||||
specification = specification.and(buildSpecification(criteria.getId(), UserRoleAssignment_.id));
|
||||
}
|
||||
if (criteria.getEntityTypeId() != null) {
|
||||
specification = specification
|
||||
.and(buildStringSpecification(criteria.getEntityTypeId(), UserRoleAssignment_.entityTypeId));
|
||||
}
|
||||
if (criteria.getEntityObjectId() != null) {
|
||||
specification = specification
|
||||
.and(buildRangeSpecification(criteria.getEntityObjectId(), UserRoleAssignment_.entityObjectId));
|
||||
}
|
||||
if (criteria.getAssignedRole() != null) {
|
||||
specification = specification
|
||||
.and(buildSpecification(criteria.getAssignedRole(), UserRoleAssignment_.assignedRole));
|
||||
}
|
||||
if (criteria.getUserId() != null) {
|
||||
specification = specification.and(
|
||||
buildSpecification(
|
||||
criteria.getUserId(),
|
||||
root -> root.join(UserRoleAssignment_.user, JoinType.LEFT).get(User_.id)));
|
||||
}
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import static com.google.common.base.Verify.verify;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.UserRoleAssignment;
|
||||
import org.hostsharing.hsadminng.repository.UserRepository;
|
||||
import org.hostsharing.hsadminng.repository.UserRoleAssignmentRepository;
|
||||
import org.hostsharing.hsadminng.security.SecurityUtils;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Service Implementation for managing UserRoleAssignment.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class UserRoleAssignmentService implements IdToDtoResolver<UserRoleAssignment> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(UserRoleAssignmentService.class);
|
||||
|
||||
private final UserRoleAssignmentRepository userRoleAssignmentRepository;
|
||||
|
||||
public UserRoleAssignmentService(
|
||||
final UserRepository userRepository,
|
||||
final UserRoleAssignmentRepository userRoleAssignmentRepository) {
|
||||
this.userRoleAssignmentRepository = userRoleAssignmentRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a userRoleAssignment.
|
||||
*
|
||||
* @param userRoleAssignment the entity to save
|
||||
* @return the persisted entity
|
||||
*/
|
||||
public UserRoleAssignment save(UserRoleAssignment userRoleAssignment) {
|
||||
log.debug("Request to save UserRoleAssignment : {}", userRoleAssignment);
|
||||
return userRoleAssignmentRepository.save(userRoleAssignment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the userRoleAssignments.
|
||||
*
|
||||
* @param pageable the pagination information
|
||||
* @return the list of entities
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Page<UserRoleAssignment> findAll(Pageable pageable) {
|
||||
log.debug("Request to get all UserRoleAssignments");
|
||||
return userRoleAssignmentRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one userRoleAssignment by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
* @return the entity
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<UserRoleAssignment> findOne(Long id) {
|
||||
log.debug("Request to get UserRoleAssignment : {}", id);
|
||||
return userRoleAssignmentRepository.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the userRoleAssignment by id.
|
||||
*
|
||||
* @param id the id of the entity
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete UserRoleAssignment : {}", id);
|
||||
userRoleAssignmentRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all roles assigned to the current login user for the specified entity.
|
||||
*
|
||||
* @param entityTypeId the type id of the entity, e.g. "customer.Customer", not null
|
||||
* @param entityObjectId id of entity instance in given entity type
|
||||
* @return a set of all roles assigned to the current login user
|
||||
*/
|
||||
public Set<Role> getEffectiveRoleOfCurrentUser(final String entityTypeId, final long entityObjectId) {
|
||||
verify(entityTypeId != null);
|
||||
|
||||
// findByLogin is cached, thus I presume this is faster more specific query which would result in many DB roundtrips
|
||||
final Set<Role> roles = SecurityUtils.getCurrentUserLogin()
|
||||
.map(
|
||||
login -> userRoleAssignmentRepository.findByLogin(login)
|
||||
.stream()
|
||||
.filter(ura -> matches(entityTypeId, entityObjectId, ura))
|
||||
.map(UserRoleAssignment::getAssignedRole)
|
||||
.collect(Collectors.toSet()))
|
||||
.orElse(Collections.emptySet());
|
||||
return roles;
|
||||
}
|
||||
|
||||
private static boolean matches(final String entityTypeId, final long entityObjectId, final UserRoleAssignment ura) {
|
||||
return ura.getEntityTypeId().equals(entityTypeId) && ura.getEntityObjectId().equals(entityObjectId);
|
||||
}
|
||||
}
|
@ -1,302 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service;
|
||||
|
||||
import org.hostsharing.hsadminng.config.Constants;
|
||||
import org.hostsharing.hsadminng.domain.Authority;
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
import org.hostsharing.hsadminng.repository.AuthorityRepository;
|
||||
import org.hostsharing.hsadminng.repository.UserRepository;
|
||||
import org.hostsharing.hsadminng.security.AuthoritiesConstants;
|
||||
import org.hostsharing.hsadminng.security.SecurityUtils;
|
||||
import org.hostsharing.hsadminng.service.dto.UserDTO;
|
||||
import org.hostsharing.hsadminng.service.util.RandomUtil;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Service class for managing users.
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class UserService {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
private final AuthorityRepository authorityRepository;
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
public UserService(
|
||||
UserRepository userRepository,
|
||||
PasswordEncoder passwordEncoder,
|
||||
AuthorityRepository authorityRepository,
|
||||
CacheManager cacheManager) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.authorityRepository = authorityRepository;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
public Optional<User> activateRegistration(String key) {
|
||||
log.debug("Activating user for activation key {}", key);
|
||||
return userRepository.findOneByActivationKey(key)
|
||||
.map(user -> {
|
||||
// activate given user for the registration key.
|
||||
user.setActivated(true);
|
||||
user.setActivationKey(null);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Activated user: {}", user);
|
||||
return user;
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<User> completePasswordReset(String newPassword, String key) {
|
||||
log.debug("Reset user password for reset key {}", key);
|
||||
return userRepository.findOneByResetKey(key)
|
||||
.filter(user -> user.getResetDate().isAfter(Instant.now().minusSeconds(86400)))
|
||||
.map(user -> {
|
||||
user.setPassword(passwordEncoder.encode(newPassword));
|
||||
user.setResetKey(null);
|
||||
user.setResetDate(null);
|
||||
this.clearUserCaches(user);
|
||||
return user;
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<User> requestPasswordReset(String mail) {
|
||||
return userRepository.findOneByEmailIgnoreCase(mail)
|
||||
.filter(User::getActivated)
|
||||
.map(user -> {
|
||||
user.setResetKey(RandomUtil.generateResetKey());
|
||||
user.setResetDate(Instant.now());
|
||||
this.clearUserCaches(user);
|
||||
return user;
|
||||
});
|
||||
}
|
||||
|
||||
public User registerUser(UserDTO userDTO, String password) {
|
||||
userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()).ifPresent(existingUser -> {
|
||||
boolean removed = removeNonActivatedUser(existingUser);
|
||||
if (!removed) {
|
||||
throw new LoginAlreadyUsedException();
|
||||
}
|
||||
});
|
||||
userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).ifPresent(existingUser -> {
|
||||
boolean removed = removeNonActivatedUser(existingUser);
|
||||
if (!removed) {
|
||||
throw new EmailAlreadyUsedException();
|
||||
}
|
||||
});
|
||||
User newUser = new User();
|
||||
String encryptedPassword = passwordEncoder.encode(password);
|
||||
newUser.setLogin(userDTO.getLogin().toLowerCase());
|
||||
// new user gets initially a generated password
|
||||
newUser.setPassword(encryptedPassword);
|
||||
newUser.setFirstName(userDTO.getFirstName());
|
||||
newUser.setLastName(userDTO.getLastName());
|
||||
newUser.setEmail(userDTO.getEmail().toLowerCase());
|
||||
newUser.setImageUrl(userDTO.getImageUrl());
|
||||
newUser.setLangKey(userDTO.getLangKey());
|
||||
// new user is not active
|
||||
newUser.setActivated(false);
|
||||
// new user gets registration key
|
||||
newUser.setActivationKey(RandomUtil.generateActivationKey());
|
||||
Set<Authority> authorities = new HashSet<>();
|
||||
authorityRepository.findById(AuthoritiesConstants.USER).ifPresent(authorities::add);
|
||||
newUser.setAuthorities(authorities);
|
||||
userRepository.save(newUser);
|
||||
this.clearUserCaches(newUser);
|
||||
log.debug("Created Information for User: {}", newUser);
|
||||
return newUser;
|
||||
}
|
||||
|
||||
private boolean removeNonActivatedUser(User existingUser) {
|
||||
if (existingUser.getActivated()) {
|
||||
return false;
|
||||
}
|
||||
userRepository.delete(existingUser);
|
||||
userRepository.flush();
|
||||
this.clearUserCaches(existingUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
public User createUser(UserDTO userDTO) {
|
||||
User user = new User();
|
||||
user.setLogin(userDTO.getLogin().toLowerCase());
|
||||
user.setFirstName(userDTO.getFirstName());
|
||||
user.setLastName(userDTO.getLastName());
|
||||
user.setEmail(userDTO.getEmail().toLowerCase());
|
||||
user.setImageUrl(userDTO.getImageUrl());
|
||||
if (userDTO.getLangKey() == null) {
|
||||
user.setLangKey(Constants.DEFAULT_LANGUAGE); // default language
|
||||
} else {
|
||||
user.setLangKey(userDTO.getLangKey());
|
||||
}
|
||||
String encryptedPassword = passwordEncoder.encode(RandomUtil.generatePassword());
|
||||
user.setPassword(encryptedPassword);
|
||||
user.setResetKey(RandomUtil.generateResetKey());
|
||||
user.setResetDate(Instant.now());
|
||||
user.setActivated(true);
|
||||
if (userDTO.getAuthorities() != null) {
|
||||
Set<Authority> authorities = userDTO.getAuthorities()
|
||||
.stream()
|
||||
.map(authorityRepository::findById)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toSet());
|
||||
user.setAuthorities(authorities);
|
||||
}
|
||||
userRepository.save(user);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Created Information for User: {}", user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update basic information (first name, last name, email, language) for the current user.
|
||||
*
|
||||
* @param firstName first name of user
|
||||
* @param lastName last name of user
|
||||
* @param email email id of user
|
||||
* @param langKey language key
|
||||
* @param imageUrl image URL of user
|
||||
*/
|
||||
public void updateUser(String firstName, String lastName, String email, String langKey, String imageUrl) {
|
||||
SecurityUtils.getCurrentUserLogin()
|
||||
.flatMap(userRepository::findOneByLogin)
|
||||
.ifPresent(user -> {
|
||||
user.setFirstName(firstName);
|
||||
user.setLastName(lastName);
|
||||
user.setEmail(email.toLowerCase());
|
||||
user.setLangKey(langKey);
|
||||
user.setImageUrl(imageUrl);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Changed Information for User: {}", user);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all information for a specific user, and return the modified user.
|
||||
*
|
||||
* @param userDTO user to update
|
||||
* @return updated user
|
||||
*/
|
||||
public Optional<UserDTO> updateUser(UserDTO userDTO) {
|
||||
return Optional.of(
|
||||
userRepository
|
||||
.findById(userDTO.getId()))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(user -> {
|
||||
this.clearUserCaches(user);
|
||||
user.setLogin(userDTO.getLogin().toLowerCase());
|
||||
user.setFirstName(userDTO.getFirstName());
|
||||
user.setLastName(userDTO.getLastName());
|
||||
user.setEmail(userDTO.getEmail().toLowerCase());
|
||||
user.setImageUrl(userDTO.getImageUrl());
|
||||
user.setActivated(userDTO.isActivated());
|
||||
user.setLangKey(userDTO.getLangKey());
|
||||
Set<Authority> managedAuthorities = user.getAuthorities();
|
||||
managedAuthorities.clear();
|
||||
userDTO.getAuthorities()
|
||||
.stream()
|
||||
.map(authorityRepository::findById)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.forEach(managedAuthorities::add);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Changed Information for User: {}", user);
|
||||
return user;
|
||||
})
|
||||
.map(UserDTO::new);
|
||||
}
|
||||
|
||||
public void deleteUser(String login) {
|
||||
userRepository.findOneByLogin(login).ifPresent(user -> {
|
||||
userRepository.delete(user);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Deleted User: {}", user);
|
||||
});
|
||||
}
|
||||
|
||||
public void changePassword(String currentClearTextPassword, String newPassword) {
|
||||
SecurityUtils.getCurrentUserLogin()
|
||||
.flatMap(userRepository::findOneByLogin)
|
||||
.ifPresent(user -> {
|
||||
String currentEncryptedPassword = user.getPassword();
|
||||
if (!passwordEncoder.matches(currentClearTextPassword, currentEncryptedPassword)) {
|
||||
throw new InvalidPasswordException();
|
||||
}
|
||||
String encryptedPassword = passwordEncoder.encode(newPassword);
|
||||
user.setPassword(encryptedPassword);
|
||||
this.clearUserCaches(user);
|
||||
log.debug("Changed password for User: {}", user);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<UserDTO> getAllManagedUsers(Pageable pageable) {
|
||||
return userRepository.findAllByLoginNot(pageable, Constants.ANONYMOUS_USER).map(UserDTO::new);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<User> getUserWithAuthoritiesByLogin(String login) {
|
||||
return userRepository.findOneWithAuthoritiesByLogin(login);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<User> getUserWithAuthorities(Long id) {
|
||||
return userRepository.findOneWithAuthoritiesById(id);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<User> getUserWithAuthorities() {
|
||||
return SecurityUtils.getCurrentUserLogin().flatMap(userRepository::findOneWithAuthoritiesByLogin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not activated users should be automatically deleted after 3 days.
|
||||
* <p>
|
||||
* This is scheduled to get fired everyday, at 01:00 (am).
|
||||
*/
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void removeNotActivatedUsers() {
|
||||
userRepository
|
||||
.findAllByActivatedIsFalseAndCreatedDateBefore(Instant.now().minus(3, ChronoUnit.DAYS))
|
||||
.forEach(user -> {
|
||||
log.debug("Deleting not activated user {}", user.getLogin());
|
||||
userRepository.delete(user);
|
||||
this.clearUserCaches(user);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of all the authorities
|
||||
*/
|
||||
public List<String> getAuthorities() {
|
||||
return authorityRepository.findAll().stream().map(Authority::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void clearUserCaches(User user) {
|
||||
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)).evict(user.getLogin());
|
||||
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_EMAIL_CACHE)).evict(user.getEmail());
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.Nobody;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Documented
|
||||
@Target({ ElementType.FIELD, ElementType.TYPE_USE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AccessFor {
|
||||
|
||||
Class<? extends Role>[] init() default Nobody.class;
|
||||
|
||||
Class<? extends Role>[] update() default Nobody.class;
|
||||
|
||||
Class<? extends Role>[] read() default Nobody.class;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A marker interface for DTO classes which can be used by {@link JsonSerializerWithAccessFilter} and
|
||||
* {@link JsonDeserializerWithAccessFilter}.
|
||||
*/
|
||||
public interface AccessMappings extends Serializable {
|
||||
|
||||
Long getId();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Specifies the entityTypeId to be used in UserRoleAssignment.
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.FIELD, ElementType.TYPE_USE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EntityTypeId {
|
||||
|
||||
/**
|
||||
* The ID of the entity type, max length: 32.
|
||||
*
|
||||
* Pattern: "module.Entity", e.g. "customer.Membership"
|
||||
*/
|
||||
String value();
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import static com.google.common.base.Verify.verify;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static java.util.Collections.EMPTY_SET;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
import org.hostsharing.hsadminng.security.SecurityUtils;
|
||||
import org.hostsharing.hsadminng.service.IdToDtoResolver;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
|
||||
import org.hostsharing.hsadminng.service.util.ReflectionUtil;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
abstract class JSonAccessFilter<T extends AccessMappings> {
|
||||
|
||||
private final ApplicationContext ctx;
|
||||
private final UserRoleAssignmentService userRoleAssignmentService;
|
||||
|
||||
final T dto;
|
||||
final Field selfIdField;
|
||||
final Field parentIdField;
|
||||
|
||||
JSonAccessFilter(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService, final T dto) {
|
||||
this.ctx = ctx;
|
||||
this.userRoleAssignmentService = userRoleAssignmentService;
|
||||
this.dto = dto;
|
||||
this.selfIdField = determineFieldWithAnnotation(dto.getClass(), SelfId.class);
|
||||
this.parentIdField = determineFieldWithAnnotation(dto.getClass(), ParentId.class);
|
||||
}
|
||||
|
||||
Long getId() {
|
||||
if (selfIdField == null) {
|
||||
return null;
|
||||
}
|
||||
return (Long) ReflectionUtil.getValue(dto, selfIdField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param field to get a display representation for
|
||||
* @return a simplified, decently user readable, display representation of the given field
|
||||
*/
|
||||
String toDisplay(final Field field) {
|
||||
return field.getDeclaringClass().getSimpleName() + "." + field.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all roles of the login user in relation to the dto, for which this filter is created.
|
||||
*/
|
||||
Set<Role> getLoginUserRoles() {
|
||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
return emptySet();
|
||||
}
|
||||
final Set<Role> independentRoles = authentication
|
||||
.getAuthorities()
|
||||
.stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.map(Role::of)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final Set<Role> rolesOnThis = getId() != null ? getLoginUserDirectRolesFor(dto.getClass(), getId()) : EMPTY_SET;
|
||||
return union(independentRoles, union(rolesOnThis, getLoginUserRoleOnAncestorIfHigher(dto)));
|
||||
}
|
||||
|
||||
private Set<Role> getLoginUserRoleOnAncestorIfHigher(final Object dto) {
|
||||
final Field parentIdField = determineFieldWithAnnotation(dto.getClass(), ParentId.class);
|
||||
|
||||
if (parentIdField == null) {
|
||||
return emptySet();
|
||||
}
|
||||
|
||||
final ParentId parentIdAnnot = parentIdField.getAnnotation(ParentId.class);
|
||||
final Class<? extends IdToDtoResolver> parentDtoLoader = parentIdAnnot.resolver();
|
||||
final Class<IdToDtoResolver> rawType = IdToDtoResolver.class;
|
||||
|
||||
final Class<?> parentDtoClass = ReflectionUtil.<T> determineGenericInterfaceParameter(parentDtoLoader, rawType, 0);
|
||||
final Object parent = ReflectionUtil.getValue(dto, parentIdField);
|
||||
if (parent == null) {
|
||||
return emptySet();
|
||||
}
|
||||
final Long parentId = parent instanceof AccessMappings ? (((AccessMappings) parent).getId()) : (Long) parent;
|
||||
final Set<Role> rolesOnParent = getLoginUserDirectRolesFor(parentDtoClass, parentId);
|
||||
|
||||
final Object parentEntity = loadDto(parentDtoLoader, parentId);
|
||||
return union(rolesOnParent, getLoginUserRoleOnAncestorIfHigher(parentEntity));
|
||||
}
|
||||
|
||||
private Set<Role> getLoginUserDirectRolesFor(final Class<?> dtoClass, final long id) {
|
||||
verify(SecurityUtils.isAuthenticated());
|
||||
|
||||
final EntityTypeId entityTypeId = dtoClass.getAnnotation(EntityTypeId.class);
|
||||
verify(entityTypeId != null, "@" + EntityTypeId.class.getSimpleName() + " missing on " + dtoClass.getName());
|
||||
|
||||
return userRoleAssignmentService.getEffectiveRoleOfCurrentUser(entityTypeId.value(), id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object loadDto(final Class<? extends IdToDtoResolver> resolverClass, final Long id) {
|
||||
verify(id != null, "id must not be null for " + resolverClass.getSimpleName());
|
||||
|
||||
final AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory();
|
||||
verify(
|
||||
beanFactory != null,
|
||||
"no bean factory found, probably missing mock configuration for ApplicationContext, e.g. given(...)");
|
||||
|
||||
final IdToDtoResolver<MembershipDTO> resolverBean = beanFactory.createBean(resolverClass);
|
||||
verify(
|
||||
resolverBean != null,
|
||||
"no " + resolverClass.getSimpleName()
|
||||
+ " bean created, probably missing mock configuration for AutowireCapableBeanFactory, e.g. given(...)");
|
||||
|
||||
return resolverBean.findOne(id)
|
||||
.orElseThrow(
|
||||
() -> new BadRequestAlertException(
|
||||
"Can't resolve entity ID " + id + " via " + resolverClass,
|
||||
resolverClass.getSimpleName(),
|
||||
"isNotFound"));
|
||||
}
|
||||
|
||||
private static Field determineFieldWithAnnotation(
|
||||
final Class<?> dtoClass,
|
||||
final Class<? extends Annotation> idAnnotationClass) {
|
||||
Field parentIdField = null;
|
||||
for (Field field : dtoClass.getDeclaredFields()) {
|
||||
if (field.isAnnotationPresent(idAnnotationClass)) {
|
||||
if (parentIdField != null) {
|
||||
throw new AssertionError(
|
||||
"multiple @" + idAnnotationClass.getSimpleName() + " detected in "
|
||||
+ field.getDeclaringClass().getSimpleName());
|
||||
}
|
||||
parentIdField = field;
|
||||
}
|
||||
}
|
||||
return parentIdField;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
/**
|
||||
* Reads a JSON node value.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface JSonFieldReader<T extends AccessMappings> {
|
||||
|
||||
/**
|
||||
* Reads a JSON node value.
|
||||
*
|
||||
* @param target your target entity or DTO type
|
||||
*
|
||||
*/
|
||||
void readInto(T target);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Similar to a BiConsumer<T, JsonGenerator>, but declaring IOException as needed by JsonGenerator.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface JSonFieldWriter<T extends AccessMappings> {
|
||||
|
||||
/**
|
||||
* Writes a JSON field and value.
|
||||
*
|
||||
* @param object your entity or DTO type
|
||||
* @param jsonGenerator provides low level methods for writing JSON fields
|
||||
*/
|
||||
void write(T object, JsonGenerator jsonGenerator) throws IOException;
|
||||
}
|
@ -1,288 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import static com.google.common.base.Verify.verify;
|
||||
import static org.hostsharing.hsadminng.service.util.ReflectionUtil.unchecked;
|
||||
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.util.ReflectionUtil;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.*;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class JsonDeserializerWithAccessFilter<T extends AccessMappings> extends JsonDeserializer<T> {
|
||||
|
||||
private final ApplicationContext ctx;
|
||||
private final UserRoleAssignmentService userRoleAssignmentService;
|
||||
|
||||
public JsonDeserializerWithAccessFilter(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
this.ctx = ctx;
|
||||
this.userRoleAssignmentService = userRoleAssignmentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(
|
||||
final JsonParser jsonParser,
|
||||
final DeserializationContext deserializationContext) {
|
||||
|
||||
final Class<T> dtoClass = ReflectionUtil
|
||||
.determineGenericClassParameter(this.getClass(), JsonDeserializerWithAccessFilter.class, 0);
|
||||
// @formatter:off
|
||||
return new JSonDeserializationWithAccessFilter(
|
||||
this, ctx, userRoleAssignmentService, jsonParser, deserializationContext, dtoClass)
|
||||
.deserialize();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
protected JSonFieldReader<T> jsonFieldReader(final TreeNode treeNode, final Field field) {
|
||||
return (final T object) -> {
|
||||
final Object newValue = readValueFromJSon(treeNode, field);
|
||||
writeValueToDto(object, field, newValue);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the named subnode of the given node.
|
||||
* <p>
|
||||
* If entities are used instead of DTOs, JHipster will generate code which sends
|
||||
* complete entity trees to the REST endpoint. In most cases, we only need the "id",
|
||||
* though.
|
||||
* </p>
|
||||
*
|
||||
* @param node the JSON node of which a subnode is to be returned
|
||||
* @param name the name of the subnode within 'node'
|
||||
* @return the subnode of 'node' with the given 'name'
|
||||
*/
|
||||
protected final JsonNode getSubNode(final TreeNode node, final String name) {
|
||||
verify(node.isObject(), node + " is not a JSON object");
|
||||
final ObjectNode objectNode = (ObjectNode) node;
|
||||
final JsonNode subNode = objectNode.get(name);
|
||||
verify(subNode.isNumber(), node + "." + name + " is not a number");
|
||||
return subNode;
|
||||
}
|
||||
|
||||
private Object readValueFromJSon(final TreeNode treeNode, final Field field) {
|
||||
return readValueFromJSon(treeNode, field.getName(), field.getType());
|
||||
}
|
||||
|
||||
private Object readValueFromJSon(final TreeNode treeNode, final String fieldName, final Class<?> fieldClass) {
|
||||
// FIXME can be removed? final TreeNode fieldNode = treeNode.get(fieldName);
|
||||
if (treeNode instanceof NullNode) {
|
||||
return null;
|
||||
}
|
||||
if (treeNode instanceof TextNode) {
|
||||
return ((TextNode) treeNode).asText();
|
||||
}
|
||||
if (treeNode instanceof IntNode) {
|
||||
return ((IntNode) treeNode).asInt();
|
||||
}
|
||||
if (treeNode instanceof LongNode) {
|
||||
return ((LongNode) treeNode).asLong();
|
||||
}
|
||||
if (treeNode instanceof DoubleNode) {
|
||||
// TODO: we need to figure out, why DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS does not work
|
||||
return ((DoubleNode) treeNode).asDouble();
|
||||
}
|
||||
if (treeNode instanceof ArrayNode && LocalDate.class.isAssignableFrom(fieldClass)) {
|
||||
return LocalDate.of(
|
||||
((ArrayNode) treeNode).get(0).asInt(),
|
||||
((ArrayNode) treeNode).get(1).asInt(),
|
||||
((ArrayNode) treeNode).get(2).asInt());
|
||||
}
|
||||
throw new NotImplementedException(
|
||||
"JSon node type not implemented: " + treeNode.getClass() + " -> " + fieldName + ": " + fieldClass);
|
||||
}
|
||||
|
||||
private void writeValueToDto(final T dto, final Field field, final Object value) {
|
||||
if (value == null) {
|
||||
ReflectionUtil.setValue(dto, field, null);
|
||||
} else if (field.getType().isAssignableFrom(value.getClass())) {
|
||||
ReflectionUtil.setValue(dto, field, value);
|
||||
} else if (int.class.isAssignableFrom(field.getType())) {
|
||||
ReflectionUtil.setValue(dto, field, ((Number) value).intValue());
|
||||
} else if (Long.class.isAssignableFrom(field.getType()) || long.class.isAssignableFrom(field.getType())) {
|
||||
ReflectionUtil.setValue(dto, field, ((Number) value).longValue());
|
||||
} else if (BigDecimal.class.isAssignableFrom(field.getType())) {
|
||||
ReflectionUtil.setValue(dto, field, new BigDecimal(value.toString()));
|
||||
} else if (Boolean.class.isAssignableFrom(field.getType()) || boolean.class.isAssignableFrom(field.getType())) {
|
||||
ReflectionUtil.setValue(dto, field, Boolean.valueOf(value.toString()));
|
||||
} else if (field.getType().isEnum()) {
|
||||
ReflectionUtil.setValue(dto, field, ReflectionUtil.asEnumValue(field.getType(), value));
|
||||
} else if (LocalDate.class.isAssignableFrom(field.getType())) {
|
||||
ReflectionUtil.setValue(dto, field, LocalDate.parse(value.toString()));
|
||||
} else {
|
||||
throw new NotImplementedException("property type not yet implemented: " + field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of JSON deserialization, where {@link JsonDeserializerWithAccessFilter}
|
||||
* is a stateless bean, this inner class exists only during the actual deserialization and contains
|
||||
* the deserialization state.
|
||||
*/
|
||||
private class JSonDeserializationWithAccessFilter extends JSonAccessFilter<T> {
|
||||
|
||||
private final TreeNode treeNode;
|
||||
private final Set<Field> updatingFields = new HashSet<>();
|
||||
|
||||
public JSonDeserializationWithAccessFilter(
|
||||
final JsonDeserializerWithAccessFilter deserializer,
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService,
|
||||
final JsonParser jsonParser,
|
||||
final DeserializationContext deserializationContext,
|
||||
Class<T> dtoClass) {
|
||||
super(ctx, userRoleAssignmentService, unchecked(dtoClass::newInstance));
|
||||
this.treeNode = unchecked(() -> jsonParser.getCodec().readTree(jsonParser));
|
||||
}
|
||||
|
||||
// Jackson deserializes from the JsonParser, thus no input parameter needed.
|
||||
public T deserialize() {
|
||||
deserializeValues();
|
||||
final T currentDto = loadCurrentDto(getId());
|
||||
overwriteUnmodifiedFieldsWithCurrentValues(currentDto);
|
||||
checkAccessToWrittenFields(currentDto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private void deserializeValues() {
|
||||
treeNode.fieldNames().forEachRemaining(fieldName -> {
|
||||
try {
|
||||
final Field field = dto.getClass().getDeclaredField(fieldName);
|
||||
final TreeNode node = treeNode.get(fieldName);
|
||||
jsonFieldReader(node, field).readInto(dto);
|
||||
updatingFields.add(field);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new BadRequestAlertException("Unknown property", fieldName, "unknownProperty");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private T loadCurrentDto(final Long id) {
|
||||
if (id != null) {
|
||||
return (T) loadDto(selfIdField.getAnnotation(SelfId.class).resolver(), id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void overwriteUnmodifiedFieldsWithCurrentValues(final T currentDto) {
|
||||
if (currentDto == null) {
|
||||
return;
|
||||
}
|
||||
for (Field field : currentDto.getClass().getDeclaredFields()) {
|
||||
if (field.isAnnotationPresent(AccessFor.class)) {
|
||||
boolean updatingField = updatingFields.contains(field);
|
||||
if (updatingField && !isActuallyUpdated(field, dto, currentDto)) {
|
||||
updatingFields.remove(field);
|
||||
updatingField = false;
|
||||
}
|
||||
if (!updatingField) {
|
||||
final Object value = ReflectionUtil.getValue(currentDto, field);
|
||||
ReflectionUtil.setValue(dto, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAccessToWrittenFields(final T currentDto) {
|
||||
updatingFields.forEach(
|
||||
field -> {
|
||||
final Set<Role> roles = getLoginUserRoles();
|
||||
if (isInitAccess()) {
|
||||
validateInitAccess(field, roles);
|
||||
} else {
|
||||
validateUpdateAccess(field, roles);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void validateInitAccess(Field field, Set<Role> roles) {
|
||||
if (!Role.toBeIgnoredForUpdates(field) && !isAllowedToInit(roles, field)) {
|
||||
if (!field.equals(parentIdField)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Initialization of field " + toDisplay(field)
|
||||
+ " prohibited for current user role(s): "
|
||||
+ asString(roles),
|
||||
toDisplay(field),
|
||||
"initializationProhibited");
|
||||
} else {
|
||||
throw new BadRequestAlertException(
|
||||
"Referencing field " + toDisplay(field)
|
||||
+ " prohibited for current user role(s): "
|
||||
+ asString(roles),
|
||||
toDisplay(field),
|
||||
"referencingProhibited");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String asString(Set<Role> roles) {
|
||||
return Joiner.on("+").join(roles.stream().map(Role::name).toArray());
|
||||
}
|
||||
|
||||
private void validateUpdateAccess(Field field, Set<Role> roles) {
|
||||
if (!Role.toBeIgnoredForUpdates(field) && !isAllowedToUpdate(getLoginUserRoles(), field)) {
|
||||
throw new BadRequestAlertException(
|
||||
"Update of field " + toDisplay(field) + " prohibited for current user role(s): "
|
||||
+ asString(roles),
|
||||
toDisplay(field),
|
||||
"updateProhibited");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAllowedToInit(final Set<Role> roles, final Field field) {
|
||||
for (Role role : roles) {
|
||||
if (role.isAllowedToInit(field)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isAllowedToUpdate(final Set<Role> roles, final Field field) {
|
||||
for (Role role : roles) {
|
||||
if (role.isAllowedToUpdate(field)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isInitAccess() {
|
||||
return getId() == null;
|
||||
}
|
||||
|
||||
private <F> boolean isActuallyUpdated(final Field field, final T dto, T currentDto) {
|
||||
final Object o1 = ReflectionUtil.getValue(dto, field);
|
||||
final Object o2 = ReflectionUtil.getValue(currentDto, field);
|
||||
|
||||
if (o1 instanceof Comparable && o2 instanceof Comparable) {
|
||||
verify(
|
||||
o2 instanceof Comparable,
|
||||
"either neither or both objects must implement Comparable"); // $COVERAGE-IGNORE$
|
||||
return 0 != ((Comparable) o1).compareTo(o2);
|
||||
}
|
||||
return ObjectUtils.notEqual(o1, o2);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.util.ReflectionUtil;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A base class for a Spring bean for JSON serialization with field-based access filters.
|
||||
* Where {@link JSonSerializationWithAccessFilter} is the actual stateful implementation and
|
||||
* it's instances only exist during the process of serialization, this class is a stateless just
|
||||
* used for service and context injection.
|
||||
*
|
||||
* @param <T> DTO class to serialize
|
||||
*/
|
||||
public abstract class JsonSerializerWithAccessFilter<T extends AccessMappings> extends JsonSerializer<T> {
|
||||
|
||||
protected final ApplicationContext ctx;
|
||||
protected final UserRoleAssignmentService userRoleAssignmentService;
|
||||
|
||||
public JsonSerializerWithAccessFilter(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
this.ctx = ctx;
|
||||
this.userRoleAssignmentService = userRoleAssignmentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(
|
||||
final T dto,
|
||||
final JsonGenerator jsonGenerator,
|
||||
final SerializerProvider serializerProvider) throws IOException {
|
||||
|
||||
new JSonSerializationWithAccessFilter(this, ctx, userRoleAssignmentService, jsonGenerator, serializerProvider, dto)
|
||||
.serialize();
|
||||
}
|
||||
|
||||
protected JSonFieldWriter<T> jsonFieldWriter(final Field field) {
|
||||
|
||||
return (final T dto, final JsonGenerator jsonGenerator) -> {
|
||||
final String fieldName = field.getName();
|
||||
final Object fieldValue = ReflectionUtil.getValue(dto, field);
|
||||
// TODO mhoennig turn this into a dispatch table?
|
||||
// TODO mhoennig: or maybe replace by serializerProvider.defaultSerialize...()?
|
||||
// But the latter makes it difficult for parallel structure with the deserializer (clumsy API).
|
||||
// Alternatively extract the supported types to subclasses of some abstract class and
|
||||
// here as well as in the deserializer just access the matching implementation through a map.
|
||||
// Or even completely switch from Jackson to GSON?
|
||||
|
||||
if (fieldValue == null) {
|
||||
jsonGenerator.writeNullField(fieldName);
|
||||
} else if (String.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeStringField(fieldName, (String) fieldValue);
|
||||
} else if (Integer.class.isAssignableFrom(field.getType()) || int.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeNumberField(fieldName, (int) fieldValue);
|
||||
} else if (Long.class.isAssignableFrom(field.getType()) || long.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeNumberField(fieldName, (long) fieldValue);
|
||||
} else if (LocalDate.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeStringField(fieldName, fieldValue.toString());
|
||||
} else if (Enum.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeStringField(fieldName, ((Enum) fieldValue).name());
|
||||
} else if (Boolean.class.isAssignableFrom(field.getType()) || boolean.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeBooleanField(fieldName, (Boolean) fieldValue);
|
||||
} else if (BigDecimal.class.isAssignableFrom(field.getType())) {
|
||||
jsonGenerator.writeNumberField(fieldName, (BigDecimal) fieldValue);
|
||||
} else {
|
||||
throw new NotImplementedException("property type not yet implemented: " + field);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL implementation of JSON serialization, where {@link JsonSerializerWithAccessFilter}
|
||||
* is a stateless bean, this inner class exists only during the actual serialization and
|
||||
* contains a serialization state.
|
||||
*/
|
||||
private class JSonSerializationWithAccessFilter extends JSonAccessFilter<T> {
|
||||
|
||||
private final JsonSerializerWithAccessFilter serializer;
|
||||
private final JsonGenerator jsonGenerator;
|
||||
private final SerializerProvider serializerProvider;
|
||||
|
||||
public JSonSerializationWithAccessFilter(
|
||||
final JsonSerializerWithAccessFilter serializer,
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService,
|
||||
final JsonGenerator jsonGenerator,
|
||||
final SerializerProvider serializerProvider,
|
||||
final T dto) {
|
||||
super(ctx, userRoleAssignmentService, dto);
|
||||
this.serializer = serializer;
|
||||
this.jsonGenerator = jsonGenerator;
|
||||
this.serializerProvider = serializerProvider;
|
||||
}
|
||||
|
||||
// Jackson serializes into the JsonGenerator, thus no return value needed.
|
||||
public void serialize() throws IOException {
|
||||
|
||||
jsonGenerator.writeStartObject();
|
||||
for (Field field : dto.getClass().getDeclaredFields()) {
|
||||
toJSon(dto, jsonGenerator, field);
|
||||
}
|
||||
jsonGenerator.writeEndObject();
|
||||
}
|
||||
|
||||
protected void writeJSonField(final T dto, final Field field, final JsonGenerator jsonGenerator) throws IOException {
|
||||
serializer.jsonFieldWriter(field).write(dto, jsonGenerator);
|
||||
}
|
||||
|
||||
private void toJSon(final T dto, final JsonGenerator jsonGenerator, final Field field) throws IOException {
|
||||
if (isAllowedToRead(getLoginUserRoles(), field)) {
|
||||
writeJSonField(dto, field, jsonGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAllowedToRead(final Set<Role> roles, final Field field) {
|
||||
for (Role role : roles) {
|
||||
if (role.isAllowedToRead(field)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return ReflectionUtil.newInstance(Role.Anybody.class).isAllowedToRead(field); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import org.hostsharing.hsadminng.service.IdToDtoResolver;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Used to mark a field within a DTO as containing the id of a referenced entity,
|
||||
* it's needed to determine access rights for entity creation.
|
||||
*
|
||||
* @see AccessFor
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ParentId {
|
||||
|
||||
/// The service which can load the referenced DTO.
|
||||
Class<? extends IdToDtoResolver<?>> resolver();
|
||||
}
|
@ -1,437 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import static com.google.common.base.Verify.verify;
|
||||
import static org.hostsharing.hsadminng.service.util.ReflectionUtil.initialize;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer;
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
import org.hostsharing.hsadminng.domain.UserRoleAssignment;
|
||||
import org.hostsharing.hsadminng.security.AuthoritiesConstants;
|
||||
import org.hostsharing.hsadminng.service.util.ReflectionUtil;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* These enum values are used to specify the minimum role required to grant access to resources,
|
||||
* see usages of {@link AccessFor}.
|
||||
* Also they can be assigned to users via {@link UserRoleAssignment}.
|
||||
* Some of the concrete values make only sense in one of these contexts.
|
||||
* <p>
|
||||
* There are two kinds of roles: independent and dependent.
|
||||
* Independent roles like {@link Hostmaster} are absolute roles which means unrelated to any concrete entity.
|
||||
* Dependent roles like {@link CustomerContractualContact} are relative to a specific entity,
|
||||
* in this case to a specific {@link Customer}.
|
||||
* <p>
|
||||
* <p>
|
||||
* Separate classes are used to make it possible to use roles in Java annotations
|
||||
* and also make it possible to have roles spread over multiple modules.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class Role {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Role.class);
|
||||
|
||||
// TODO mhoennig: We need to make sure that the classes are loaded
|
||||
// and thus the static initializers were called
|
||||
// before these maps are used in production code.
|
||||
private static Map<Class<? extends Role>, Role> rolesByClass = new HashMap<>();
|
||||
private static Map<String, Role> rolesByName = new HashMap<>();
|
||||
|
||||
private final String authority;
|
||||
private final LazyRoles comprises;
|
||||
|
||||
Role() {
|
||||
this.authority = AuthoritiesConstants.USER;
|
||||
// noinspection unchecked
|
||||
this.comprises = new LazyRoles();
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
Role(final Class<? extends Role>... comprisedRoleClasses) {
|
||||
this.authority = AuthoritiesConstants.USER;
|
||||
// noinspection unchecked
|
||||
this.comprises = new LazyRoles(comprisedRoleClasses);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
Role(final String authority, final Class<? extends Role>... comprisedRoleClasses) {
|
||||
this.authority = authority;
|
||||
// noinspection unchecked
|
||||
this.comprises = new LazyRoles(comprisedRoleClasses);
|
||||
}
|
||||
|
||||
public static Role of(final String authority) {
|
||||
final Role role = rolesByName.get(authority);
|
||||
verify(
|
||||
role != null,
|
||||
"unknown authority: %s, available authorities: ",
|
||||
authority,
|
||||
ArrayUtils.toString(rolesByName.keySet()));
|
||||
return role;
|
||||
}
|
||||
|
||||
public static <T extends Role> T of(final Class<T> roleClass) {
|
||||
// prevent initialization and thus recursive call to `Role.of(...)` within `newInstance(...)`
|
||||
final Class<T> initializedRoleClass = initialize(roleClass);
|
||||
{
|
||||
final T role = (T) rolesByClass.get(initializedRoleClass);
|
||||
if (role != null) {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
{
|
||||
T newRole = (T) ReflectionUtil.newInstance(initializedRoleClass);
|
||||
rolesByClass.put(initializedRoleClass, newRole);
|
||||
rolesByName.put(newRole.name(), newRole);
|
||||
log.info("Role registered: {} as {}", initializedRoleClass, newRole.name());
|
||||
return newRole;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Role.of(Anybody.class);
|
||||
Role.of(Hostmaster.class);
|
||||
Role.of(Admin.class);
|
||||
Role.of(Supporter.class);
|
||||
Role.of(AnyCustomerContact.class);
|
||||
Role.of(CustomerContractualContact.class);
|
||||
Role.of(CustomerTechnicalContact.class);
|
||||
Role.of(CustomerFinancialContact.class);
|
||||
Role.of(AnyCustomerUser.class);
|
||||
Role.of(ActualCustomerUser.class);
|
||||
Role.of(Ignored.class);
|
||||
Role.of(Nobody.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "(" + name() + ")";
|
||||
}
|
||||
|
||||
public abstract String name();
|
||||
|
||||
public static class IndependentRole extends Role {
|
||||
|
||||
@SafeVarargs
|
||||
IndependentRole(final String authority, final Class<? extends Role>... comprisedRoleClasses) {
|
||||
super(authority, comprisedRoleClasses);
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return authority();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DependentRole extends Role {
|
||||
|
||||
DependentRole() {
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
DependentRole(final Class<? extends Role>... comprisedRoleClasses) {
|
||||
super(AuthoritiesConstants.USER, comprisedRoleClasses);
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return getClass().getSimpleName(); // TODO: decide if it's ok for use in the DB table
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default for access rights requirement. You can read it as: 'Nobody is allowed to ...'.
|
||||
* This is usually used for fields which are managed by hsadminNg itself.
|
||||
* <p>
|
||||
* This role cannot be assigned to a user.
|
||||
* </p>
|
||||
*/
|
||||
public static class Nobody extends DependentRole {
|
||||
|
||||
public static final Nobody ROLE = Role.of(Nobody.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hostmasters are initialize/update/read and field which, except where NOBODY is allowed to.
|
||||
*/
|
||||
public static class Hostmaster extends IndependentRole {
|
||||
|
||||
/**
|
||||
* Hostmasters role to be assigned to users via via {@link User#setAuthorities}.
|
||||
*/
|
||||
public static final Hostmaster ROLE = Role.of(Hostmaster.class);
|
||||
|
||||
Hostmaster() {
|
||||
super(AuthoritiesConstants.HOSTMASTER, Admin.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Admin extends IndependentRole {
|
||||
|
||||
public static final Admin ROLE = Role.of(Admin.class);
|
||||
|
||||
Admin() {
|
||||
super(AuthoritiesConstants.ADMIN, Supporter.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Supporter extends IndependentRole {
|
||||
|
||||
public static final Supporter ROLE = Role.of(Supporter.class);
|
||||
|
||||
Supporter() {
|
||||
super(AuthoritiesConstants.SUPPORTER, CustomerContractualContact.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This role is for contractual contacts of a customer, like a director of the company.
|
||||
* <p>
|
||||
* Who has this role, has the broadest access to all resources which belong to this customer.
|
||||
* Everything which relates to the contract with the customer, needs this role.
|
||||
* <p>
|
||||
* This role can be assigned to a user via {@link UserRoleAssignment}.
|
||||
* </p>
|
||||
*/
|
||||
public static class CustomerContractualContact extends DependentRole {
|
||||
|
||||
public static final CustomerContractualContact ROLE = Role.of(CustomerContractualContact.class);
|
||||
|
||||
CustomerContractualContact() {
|
||||
super(CustomerFinancialContact.class, CustomerTechnicalContact.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomerFinancialContact extends DependentRole {
|
||||
|
||||
public static final CustomerFinancialContact ROLE = Role.of(CustomerFinancialContact.class);
|
||||
|
||||
CustomerFinancialContact() {
|
||||
super(AnyCustomerContact.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomerTechnicalContact extends DependentRole {
|
||||
|
||||
public static final CustomerTechnicalContact ROLE = Role.of(CustomerTechnicalContact.class);
|
||||
|
||||
CustomerTechnicalContact() {
|
||||
super(
|
||||
AnyCustomerContact.class,
|
||||
AnyCustomerUser.class); // TODO mhoennig: how to add roles of other modules?
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnyCustomerContact extends DependentRole {
|
||||
|
||||
public static final AnyCustomerContact ROLE = Role.of(AnyCustomerContact.class);
|
||||
|
||||
AnyCustomerContact() {
|
||||
super(Anybody.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActualCustomerUser extends DependentRole {
|
||||
|
||||
public static final ActualCustomerUser ROLE = Role.of(ActualCustomerUser.class);
|
||||
|
||||
ActualCustomerUser() {
|
||||
super(AnyCustomerUser.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnyCustomerUser extends IndependentRole {
|
||||
|
||||
public static final Role ROLE = Role.of(AnyCustomerUser.class);
|
||||
|
||||
AnyCustomerUser() {
|
||||
super(AuthoritiesConstants.USER, Anybody.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This role is meant to specify that a resources can be accessed by anybody, even without login.
|
||||
* <p>
|
||||
* It can be used to specify to grant rights to any use, even if unauthorized.
|
||||
* </p>
|
||||
*/
|
||||
public static class Anybody extends IndependentRole {
|
||||
|
||||
public static final Role ROLE = Role.of(Anybody.class);
|
||||
|
||||
Anybody() {
|
||||
super(AuthoritiesConstants.ANONYMOUS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pseudo-role to mark init/update access as ignored because the field is display-only.
|
||||
* <p>
|
||||
* This allows REST clients to send the whole response back as a new update request.
|
||||
* This role is not covered by any and covers itself no role.
|
||||
* <p>
|
||||
* It's only used to ignore the field.
|
||||
* </p>
|
||||
*/
|
||||
public static class Ignored extends DependentRole {
|
||||
|
||||
public static final Role ROLE = Role.of(Ignored.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param field a field of a DTO with AccessMappings
|
||||
* @return true if update access can be ignored because the field is just for display anyway
|
||||
*/
|
||||
public static boolean toBeIgnoredForUpdates(final Field field) {
|
||||
final AccessFor accessForAnnot = field.getAnnotation(AccessFor.class);
|
||||
if (accessForAnnot == null) {
|
||||
return true;
|
||||
}
|
||||
final Class<? extends Role>[] updateAccessFor = field.getAnnotation(AccessFor.class).update();
|
||||
return updateAccessFor.length == 1 && updateAccessFor[0] == Ignored.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the independent authority related 1:1 to this Role or empty if no independent authority is related 1:1
|
||||
* @see AuthoritiesConstants
|
||||
*/
|
||||
public String authority() {
|
||||
return authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the role with the broadest access rights
|
||||
*/
|
||||
public static Role broadest(final Role role, final Role... roles) {
|
||||
Role broadests = role;
|
||||
for (Role r : roles) {
|
||||
if (r.covers(broadests.getClass())) {
|
||||
broadests = r;
|
||||
}
|
||||
}
|
||||
return broadests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if 'this' actual role covered the given required role.
|
||||
* <p>
|
||||
* Where 'this' means the Java instance itself as a role of a system user.
|
||||
* <p>
|
||||
* {@code
|
||||
* AssignedHostmaster.ROLE.covers(AssignedRole.ANY_CUSTOMER_USER) == true
|
||||
* }
|
||||
*
|
||||
* @param roleClass The required role for a resource.
|
||||
* @return whether this role comprises the given role
|
||||
*/
|
||||
public boolean covers(final Class<? extends Role> roleClass) {
|
||||
if (getClass() == Ignored.class || roleClass == Ignored.class) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() == roleClass) {
|
||||
return true;
|
||||
}
|
||||
for (Role role : comprises.get()) {
|
||||
if (role.covers(roleClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if 'this' actual role covers any of the given required roles.
|
||||
* <p>
|
||||
* Where 'this' means the Java instance itself as a role of a system user.
|
||||
* <p>
|
||||
* {@code
|
||||
* AssignedHostmaster.ROLE.coversAny(AssignedRole.CUSTOMER_CONTRACTUAL_CONTACT, AssignedRole.CUSTOMER_FINANCIAL_CONTACT) == true
|
||||
* }
|
||||
*
|
||||
* @param roleClasses The alternatively required roles for a resource. Must be at least one.
|
||||
* @return whether this role comprises any of the given roles
|
||||
*/
|
||||
public boolean coversAny(final Class<? extends Role>... roleClasses) {
|
||||
verify(roleClasses != null && roleClasses.length > 0, "role classes expected");
|
||||
|
||||
for (Class<? extends Role> roleClass : roleClasses) {
|
||||
if (this.covers(roleClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this role of a user allows to initialize the given field when creating the resource.
|
||||
*
|
||||
* @param field a field of the DTO of a resource
|
||||
* @return true if allowed
|
||||
*/
|
||||
public boolean isAllowedToInit(final Field field) {
|
||||
|
||||
final AccessFor accessFor = field.getAnnotation(AccessFor.class);
|
||||
if (accessFor == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return coversAny(accessFor.init());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this role of a user allows to update the given field.
|
||||
*
|
||||
* @param field a field of the DTO of a resource
|
||||
* @return true if allowed
|
||||
*/
|
||||
public boolean isAllowedToUpdate(final Field field) {
|
||||
|
||||
final AccessFor accessFor = field.getAnnotation(AccessFor.class);
|
||||
if (accessFor == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return coversAny(accessFor.update());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this role of a user allows to read the given field.
|
||||
*
|
||||
* @param field a field of the DTO of a resource
|
||||
* @return true if allowed
|
||||
*/
|
||||
public boolean isAllowedToRead(final Field field) {
|
||||
|
||||
final AccessFor accessFor = field.getAnnotation(AccessFor.class);
|
||||
if (accessFor == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return coversAny(accessFor.read());
|
||||
}
|
||||
}
|
||||
|
||||
class LazyRoles {
|
||||
|
||||
private final Class<? extends Role>[] comprisedRoleClasses;
|
||||
private Role[] comprisedRoles = null;
|
||||
|
||||
LazyRoles(Class<? extends Role>... comprisedRoleClasses) {
|
||||
this.comprisedRoleClasses = comprisedRoleClasses;
|
||||
}
|
||||
|
||||
Role[] get() {
|
||||
if (comprisedRoles == null) {
|
||||
comprisedRoles = new Role[comprisedRoleClasses.length];
|
||||
for (int n = 0; n < comprisedRoleClasses.length; ++n) {
|
||||
comprisedRoles[n] = Role.of(comprisedRoleClasses[n]);
|
||||
}
|
||||
}
|
||||
return comprisedRoles;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.accessfilter;
|
||||
|
||||
import org.hostsharing.hsadminng.service.IdToDtoResolver;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Used to mark a field within a DTO as containing the own id,
|
||||
* it's needed to identify an existing entity for update functions.
|
||||
* Initialization and update rights have no meaning for such fields,
|
||||
* its initialized automatically and never updated.
|
||||
*
|
||||
* @see AccessFor
|
||||
*/
|
||||
@Documented
|
||||
@Target({ ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SelfId {
|
||||
|
||||
/// The service which can load the referenced DTO.
|
||||
Class<? extends IdToDtoResolver<?>> resolver();
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
|
||||
import io.github.jhipster.service.filter.BigDecimalFilter;
|
||||
import io.github.jhipster.service.filter.Filter;
|
||||
import io.github.jhipster.service.filter.LocalDateFilter;
|
||||
import io.github.jhipster.service.filter.LongFilter;
|
||||
import io.github.jhipster.service.filter.StringFilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Criteria class for the Asset entity. This class is used in AssetResource to
|
||||
* receive all the possible filtering options from the Http GET request parameters.
|
||||
* For example the following could be a valid requests:
|
||||
* <code> /assets?id.greaterThan=5&attr1.contains=something&attr2.specified=false</code>
|
||||
* As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use
|
||||
* fix type specific filters.
|
||||
*/
|
||||
public class AssetCriteria implements Serializable {
|
||||
|
||||
/**
|
||||
* Class for filtering AssetAction
|
||||
*/
|
||||
public static class AssetActionFilter extends Filter<AssetAction> {
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private LongFilter id;
|
||||
|
||||
private LocalDateFilter documentDate;
|
||||
|
||||
private LocalDateFilter valueDate;
|
||||
|
||||
private AssetActionFilter action;
|
||||
|
||||
private BigDecimalFilter amount;
|
||||
|
||||
private StringFilter remark;
|
||||
|
||||
private LongFilter membershipId;
|
||||
|
||||
public LongFilter getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LongFilter id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateFilter getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDateFilter documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDateFilter valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public AssetActionFilter getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(AssetActionFilter action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public BigDecimalFilter getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimalFilter amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public StringFilter getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(StringFilter remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public LongFilter getMembershipId() {
|
||||
return membershipId;
|
||||
}
|
||||
|
||||
public void setMembershipId(LongFilter membershipId) {
|
||||
this.membershipId = membershipId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AssetCriteria that = (AssetCriteria) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(documentDate, that.documentDate) &&
|
||||
Objects.equals(valueDate, that.valueDate) &&
|
||||
Objects.equals(action, that.action) &&
|
||||
Objects.equals(amount, that.amount) &&
|
||||
Objects.equals(remark, that.remark) &&
|
||||
Objects.equals(membershipId, that.membershipId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
documentDate,
|
||||
valueDate,
|
||||
action,
|
||||
amount,
|
||||
remark,
|
||||
membershipId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AssetCriteria{" +
|
||||
(id != null ? "id=" + id + ", " : "") +
|
||||
(documentDate != null ? "documentDate=" + documentDate + ", " : "") +
|
||||
(valueDate != null ? "valueDate=" + valueDate + ", " : "") +
|
||||
(action != null ? "action=" + action + ", " : "") +
|
||||
(amount != null ? "amount=" + amount + ", " : "") +
|
||||
(remark != null ? "remark=" + remark + ", " : "") +
|
||||
(membershipId != null ? "membershipId=" + membershipId + ", " : "") +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Asset;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
|
||||
import org.hostsharing.hsadminng.service.AssetService;
|
||||
import org.hostsharing.hsadminng.service.MembershipService;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.*;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A DTO for the Asset entity.
|
||||
*/
|
||||
@EntityTypeId(Asset.ENTITY_TYPE_ID)
|
||||
public class AssetDTO implements Serializable, AccessMappings {
|
||||
|
||||
@SelfId(resolver = AssetService.class)
|
||||
@AccessFor(read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate documentDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate valueDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private AssetAction action;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private BigDecimal amount;
|
||||
|
||||
@Size(max = 160)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private String remark;
|
||||
|
||||
@ParentId(resolver = MembershipService.class)
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long membershipId;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String membershipDisplayLabel;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public AssetAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(AssetAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getMembershipId() {
|
||||
return membershipId;
|
||||
}
|
||||
|
||||
public void setMembershipId(Long membershipId) {
|
||||
this.membershipId = membershipId;
|
||||
}
|
||||
|
||||
public String getMembershipDisplayLabel() {
|
||||
return membershipDisplayLabel;
|
||||
}
|
||||
|
||||
public void setMembershipDisplayLabel(String membershipDisplayLabel) {
|
||||
this.membershipDisplayLabel = membershipDisplayLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AssetDTO assetDTO = (AssetDTO) o;
|
||||
if (assetDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), assetDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AssetDTO{" +
|
||||
"id=" + getId() +
|
||||
", documentDate='" + getDocumentDate() + "'" +
|
||||
", valueDate='" + getValueDate() + "'" +
|
||||
", action='" + getAction() + "'" +
|
||||
", amount=" + getAmount() +
|
||||
", remark='" + getRemark() + "'" +
|
||||
", membership=" + getMembershipId() +
|
||||
", membershipDisplayLabel='" + getMembershipDisplayLabel() + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonSerializer extends JsonSerializerWithAccessFilter<AssetDTO> {
|
||||
|
||||
public JsonSerializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonDeserializer extends JsonDeserializerWithAccessFilter<AssetDTO> {
|
||||
|
||||
public JsonDeserializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,292 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.CustomerKind;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.VatRegion;
|
||||
|
||||
import io.github.jhipster.service.filter.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Criteria class for the Customer entity. This class is used in CustomerResource to
|
||||
* receive all the possible filtering options from the Http GET request parameters.
|
||||
* For example the following could be a valid requests:
|
||||
* <code> /customers?id.greaterThan=5&attr1.contains=something&attr2.specified=false</code>
|
||||
* As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use
|
||||
* fix type specific filters.
|
||||
*/
|
||||
public class CustomerCriteria implements Serializable {
|
||||
|
||||
/**
|
||||
* Class for filtering CustomerKind
|
||||
*/
|
||||
public static class CustomerKindFilter extends Filter<CustomerKind> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for filtering VatRegion
|
||||
*/
|
||||
public static class VatRegionFilter extends Filter<VatRegion> {
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private LongFilter id;
|
||||
|
||||
private IntegerFilter reference;
|
||||
|
||||
private StringFilter prefix;
|
||||
|
||||
private StringFilter name;
|
||||
|
||||
private CustomerKindFilter kind;
|
||||
|
||||
private LocalDateFilter birthDate;
|
||||
|
||||
private StringFilter birthPlace;
|
||||
|
||||
private StringFilter registrationCourt;
|
||||
|
||||
private StringFilter registrationNumber;
|
||||
|
||||
private VatRegionFilter vatRegion;
|
||||
|
||||
private StringFilter vatNumber;
|
||||
|
||||
private StringFilter contractualSalutation;
|
||||
|
||||
private StringFilter contractualAddress;
|
||||
|
||||
private StringFilter billingSalutation;
|
||||
|
||||
private StringFilter billingAddress;
|
||||
|
||||
private StringFilter remark;
|
||||
|
||||
private LongFilter membershipId;
|
||||
|
||||
private LongFilter sepamandateId;
|
||||
|
||||
public LongFilter getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LongFilter id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public IntegerFilter getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(IntegerFilter reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public StringFilter getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(StringFilter prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public StringFilter getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(StringFilter name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CustomerKindFilter getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setKind(CustomerKindFilter kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public LocalDateFilter getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDateFilter birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public StringFilter getBirthPlace() {
|
||||
return birthPlace;
|
||||
}
|
||||
|
||||
public void setBirthPlace(StringFilter birthPlace) {
|
||||
this.birthPlace = birthPlace;
|
||||
}
|
||||
|
||||
public StringFilter getRegistrationCourt() {
|
||||
return registrationCourt;
|
||||
}
|
||||
|
||||
public void setRegistrationCourt(StringFilter registrationCourt) {
|
||||
this.registrationCourt = registrationCourt;
|
||||
}
|
||||
|
||||
public StringFilter getRegistrationNumber() {
|
||||
return registrationNumber;
|
||||
}
|
||||
|
||||
public void setRegistrationNumber(StringFilter registrationNumber) {
|
||||
this.registrationNumber = registrationNumber;
|
||||
}
|
||||
|
||||
public VatRegionFilter getVatRegion() {
|
||||
return vatRegion;
|
||||
}
|
||||
|
||||
public void setVatRegion(VatRegionFilter vatRegion) {
|
||||
this.vatRegion = vatRegion;
|
||||
}
|
||||
|
||||
public StringFilter getVatNumber() {
|
||||
return vatNumber;
|
||||
}
|
||||
|
||||
public void setVatNumber(StringFilter vatNumber) {
|
||||
this.vatNumber = vatNumber;
|
||||
}
|
||||
|
||||
public StringFilter getContractualSalutation() {
|
||||
return contractualSalutation;
|
||||
}
|
||||
|
||||
public void setContractualSalutation(StringFilter contractualSalutation) {
|
||||
this.contractualSalutation = contractualSalutation;
|
||||
}
|
||||
|
||||
public StringFilter getContractualAddress() {
|
||||
return contractualAddress;
|
||||
}
|
||||
|
||||
public void setContractualAddress(StringFilter contractualAddress) {
|
||||
this.contractualAddress = contractualAddress;
|
||||
}
|
||||
|
||||
public StringFilter getBillingSalutation() {
|
||||
return billingSalutation;
|
||||
}
|
||||
|
||||
public void setBillingSalutation(StringFilter billingSalutation) {
|
||||
this.billingSalutation = billingSalutation;
|
||||
}
|
||||
|
||||
public StringFilter getBillingAddress() {
|
||||
return billingAddress;
|
||||
}
|
||||
|
||||
public void setBillingAddress(StringFilter billingAddress) {
|
||||
this.billingAddress = billingAddress;
|
||||
}
|
||||
|
||||
public StringFilter getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(StringFilter remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public LongFilter getMembershipId() {
|
||||
return membershipId;
|
||||
}
|
||||
|
||||
public void setMembershipId(LongFilter membershipId) {
|
||||
this.membershipId = membershipId;
|
||||
}
|
||||
|
||||
public LongFilter getSepamandateId() {
|
||||
return sepamandateId;
|
||||
}
|
||||
|
||||
public void setSepamandateId(LongFilter sepamandateId) {
|
||||
this.sepamandateId = sepamandateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CustomerCriteria that = (CustomerCriteria) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(reference, that.reference) &&
|
||||
Objects.equals(prefix, that.prefix) &&
|
||||
Objects.equals(name, that.name) &&
|
||||
Objects.equals(kind, that.kind) &&
|
||||
Objects.equals(birthDate, that.birthDate) &&
|
||||
Objects.equals(birthPlace, that.birthPlace) &&
|
||||
Objects.equals(registrationCourt, that.registrationCourt) &&
|
||||
Objects.equals(registrationNumber, that.registrationNumber) &&
|
||||
Objects.equals(vatRegion, that.vatRegion) &&
|
||||
Objects.equals(vatNumber, that.vatNumber) &&
|
||||
Objects.equals(contractualSalutation, that.contractualSalutation) &&
|
||||
Objects.equals(contractualAddress, that.contractualAddress) &&
|
||||
Objects.equals(billingSalutation, that.billingSalutation) &&
|
||||
Objects.equals(billingAddress, that.billingAddress) &&
|
||||
Objects.equals(remark, that.remark) &&
|
||||
Objects.equals(membershipId, that.membershipId) &&
|
||||
Objects.equals(sepamandateId, that.sepamandateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
reference,
|
||||
prefix,
|
||||
name,
|
||||
kind,
|
||||
birthDate,
|
||||
birthPlace,
|
||||
registrationCourt,
|
||||
registrationNumber,
|
||||
vatRegion,
|
||||
vatNumber,
|
||||
contractualSalutation,
|
||||
contractualAddress,
|
||||
billingSalutation,
|
||||
billingAddress,
|
||||
remark,
|
||||
membershipId,
|
||||
sepamandateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomerCriteria{" +
|
||||
(id != null ? "id=" + id + ", " : "") +
|
||||
(reference != null ? "reference=" + reference + ", " : "") +
|
||||
(prefix != null ? "prefix=" + prefix + ", " : "") +
|
||||
(name != null ? "name=" + name + ", " : "") +
|
||||
(kind != null ? "kind=" + kind + ", " : "") +
|
||||
(birthDate != null ? "birthDate=" + birthDate + ", " : "") +
|
||||
(birthPlace != null ? "birthPlace=" + birthPlace + ", " : "") +
|
||||
(registrationCourt != null ? "registrationCourt=" + registrationCourt + ", " : "") +
|
||||
(registrationNumber != null ? "registrationNumber=" + registrationNumber + ", " : "") +
|
||||
(vatRegion != null ? "vatRegion=" + vatRegion + ", " : "") +
|
||||
(vatNumber != null ? "vatNumber=" + vatNumber + ", " : "") +
|
||||
(contractualSalutation != null ? "contractualSalutation=" + contractualSalutation + ", " : "") +
|
||||
(contractualAddress != null ? "contractualAddress=" + contractualAddress + ", " : "") +
|
||||
(billingSalutation != null ? "billingSalutation=" + billingSalutation + ", " : "") +
|
||||
(billingAddress != null ? "billingAddress=" + billingAddress + ", " : "") +
|
||||
(remark != null ? "remark=" + remark + ", " : "") +
|
||||
(membershipId != null ? "membershipId=" + membershipId + ", " : "") +
|
||||
(sepamandateId != null ? "sepamandateId=" + sepamandateId + ", " : "") +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
@ -1,319 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import static org.hostsharing.hsadminng.service.accessfilter.Role.*;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Customer;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.CustomerKind;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.VatRegion;
|
||||
import org.hostsharing.hsadminng.service.CustomerService;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* A DTO for the Customer entity.
|
||||
*/
|
||||
@EntityTypeId(Customer.ENTITY_TYPE_ID)
|
||||
public class CustomerDTO implements AccessMappings, FluentBuilder<CustomerDTO> {
|
||||
|
||||
@SelfId(resolver = CustomerService.class)
|
||||
@AccessFor(read = AnyCustomerUser.class)
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Min(value = 10000)
|
||||
@Max(value = 99999)
|
||||
@AccessFor(init = Admin.class, read = AnyCustomerUser.class)
|
||||
private Integer reference;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 3)
|
||||
@Pattern(regexp = "[a-z][a-z0-9]+")
|
||||
@AccessFor(init = Admin.class, read = AnyCustomerUser.class)
|
||||
private String prefix;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 80)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = AnyCustomerUser.class)
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = CustomerContractualContact.class)
|
||||
private CustomerKind kind;
|
||||
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate birthDate;
|
||||
|
||||
@Size(max = 80)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String birthPlace;
|
||||
|
||||
@Size(max = 80)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String registrationCourt;
|
||||
|
||||
@Size(max = 80)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String registrationNumber;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private VatRegion vatRegion;
|
||||
|
||||
@Size(max = 40)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String vatNumber;
|
||||
|
||||
@Size(max = 80)
|
||||
@AccessFor(init = Admin.class, update = CustomerContractualContact.class, read = CustomerContractualContact.class)
|
||||
private String contractualSalutation;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 400)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = CustomerContractualContact.class)
|
||||
private String contractualAddress;
|
||||
|
||||
@Size(max = 80)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = CustomerContractualContact.class)
|
||||
private String billingSalutation;
|
||||
|
||||
@Size(max = 400)
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String billingAddress;
|
||||
|
||||
@Size(max = 160)
|
||||
@AccessFor(init = Admin.class, update = Supporter.class, read = Supporter.class)
|
||||
private String remark;
|
||||
|
||||
@AccessFor(init = Anybody.class, update = Anybody.class, read = AnyCustomerUser.class)
|
||||
private String displayLabel;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(Integer reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CustomerKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setKind(CustomerKind kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getBirthPlace() {
|
||||
return birthPlace;
|
||||
}
|
||||
|
||||
public void setBirthPlace(String birthPlace) {
|
||||
this.birthPlace = birthPlace;
|
||||
}
|
||||
|
||||
public String getRegistrationCourt() {
|
||||
return registrationCourt;
|
||||
}
|
||||
|
||||
public void setRegistrationCourt(String registrationCourt) {
|
||||
this.registrationCourt = registrationCourt;
|
||||
}
|
||||
|
||||
public String getRegistrationNumber() {
|
||||
return registrationNumber;
|
||||
}
|
||||
|
||||
public void setRegistrationNumber(String registrationNumber) {
|
||||
this.registrationNumber = registrationNumber;
|
||||
}
|
||||
|
||||
public VatRegion getVatRegion() {
|
||||
return vatRegion;
|
||||
}
|
||||
|
||||
public void setVatRegion(VatRegion vatRegion) {
|
||||
this.vatRegion = vatRegion;
|
||||
}
|
||||
|
||||
public String getVatNumber() {
|
||||
return vatNumber;
|
||||
}
|
||||
|
||||
public void setVatNumber(String vatNumber) {
|
||||
this.vatNumber = vatNumber;
|
||||
}
|
||||
|
||||
public String getContractualSalutation() {
|
||||
return contractualSalutation;
|
||||
}
|
||||
|
||||
public void setContractualSalutation(String contractualSalutation) {
|
||||
this.contractualSalutation = contractualSalutation;
|
||||
}
|
||||
|
||||
public String getContractualAddress() {
|
||||
return contractualAddress;
|
||||
}
|
||||
|
||||
public void setContractualAddress(String contractualAddress) {
|
||||
this.contractualAddress = contractualAddress;
|
||||
}
|
||||
|
||||
public String getBillingSalutation() {
|
||||
return billingSalutation;
|
||||
}
|
||||
|
||||
public void setBillingSalutation(String billingSalutation) {
|
||||
this.billingSalutation = billingSalutation;
|
||||
}
|
||||
|
||||
public String getBillingAddress() {
|
||||
return billingAddress;
|
||||
}
|
||||
|
||||
public void setBillingAddress(String billingAddress) {
|
||||
this.billingAddress = billingAddress;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getDisplayLabel() {
|
||||
return displayLabel;
|
||||
}
|
||||
|
||||
public void setDisplayLabel(final String displayLabel) {
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomerDTO customerDTO = (CustomerDTO) o;
|
||||
if (customerDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), customerDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomerDTO{" +
|
||||
"id=" + getId() +
|
||||
", reference=" + getReference() +
|
||||
", prefix='" + getPrefix() + "'" +
|
||||
", name='" + getName() + "'" +
|
||||
", kind='" + getKind() + "'" +
|
||||
", birthDate='" + getBirthDate() + "'" +
|
||||
", birthPlace='" + getBirthPlace() + "'" +
|
||||
", registrationCourt='" + getRegistrationCourt() + "'" +
|
||||
", registrationNumber='" + getRegistrationNumber() + "'" +
|
||||
", vatRegion='" + getVatRegion() + "'" +
|
||||
", vatNumber='" + getVatNumber() + "'" +
|
||||
", contractualSalutation='" + getContractualSalutation() + "'" +
|
||||
", contractualAddress='" + getContractualAddress() + "'" +
|
||||
", billingSalutation='" + getBillingSalutation() + "'" +
|
||||
", billingAddress='" + getBillingAddress() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class CustomerJsonSerializer extends JsonSerializerWithAccessFilter<CustomerDTO> {
|
||||
|
||||
public CustomerJsonSerializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class CustomerJsonDeserializer extends JsonDeserializerWithAccessFilter<CustomerDTO> {
|
||||
|
||||
public CustomerJsonDeserializer(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Just 'implement' this interface in your class to get a pseudo fluent builder, no more code needed.
|
||||
*
|
||||
* @param <T> class to be build (same as to which the interface was added)
|
||||
*/
|
||||
public interface FluentBuilder<T> {
|
||||
|
||||
/**
|
||||
* Allows statements on the target instance possible as expression.
|
||||
*
|
||||
* This allows creating nested object structures, e.g. for test data
|
||||
* in a much more readable way.
|
||||
*
|
||||
* <h3>Example</h3>
|
||||
* {code
|
||||
* // adding a fluent builder to your class
|
||||
* class YourClass implements FluentBuilder<YourClass> {
|
||||
* public int someField;
|
||||
* public String anotherField;
|
||||
* // ...
|
||||
* }
|
||||
*
|
||||
* // using the fluent builder somewhere else
|
||||
* someMethod( new YourClass().with( it -> {
|
||||
* it.someField = 5;
|
||||
* it.anotherField = "Hello";
|
||||
* }));
|
||||
* }
|
||||
*
|
||||
* @param builderFunction statements to apply to 'this'
|
||||
*
|
||||
* @return the instance on which 'with(...)' was executed.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default T with(
|
||||
Consumer<T> builderFunction) {
|
||||
builderFunction.accept((T) this);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import io.github.jhipster.service.filter.Filter;
|
||||
import io.github.jhipster.service.filter.LocalDateFilter;
|
||||
import io.github.jhipster.service.filter.LongFilter;
|
||||
import io.github.jhipster.service.filter.StringFilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Criteria class for the Membership entity. This class is used in MembershipResource to
|
||||
* receive all the possible filtering options from the Http GET request parameters.
|
||||
* For example the following could be a valid requests:
|
||||
* <code> /memberships?id.greaterThan=5&attr1.contains=something&attr2.specified=false</code>
|
||||
* As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use
|
||||
* fix type specific filters.
|
||||
*/
|
||||
public class MembershipCriteria implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private LongFilter id;
|
||||
|
||||
private LocalDateFilter admissionDocumentDate;
|
||||
|
||||
private LocalDateFilter cancellationDocumentDate;
|
||||
|
||||
private LocalDateFilter memberFromDate;
|
||||
|
||||
private LocalDateFilter memberUntilDate;
|
||||
|
||||
private StringFilter remark;
|
||||
|
||||
private LongFilter shareId;
|
||||
|
||||
private LongFilter assetId;
|
||||
|
||||
private LongFilter customerId;
|
||||
|
||||
public LongFilter getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LongFilter id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateFilter getAdmissionDocumentDate() {
|
||||
return admissionDocumentDate;
|
||||
}
|
||||
|
||||
public void setAdmissionDocumentDate(LocalDateFilter admissionDocumentDate) {
|
||||
this.admissionDocumentDate = admissionDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getCancellationDocumentDate() {
|
||||
return cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public void setCancellationDocumentDate(LocalDateFilter cancellationDocumentDate) {
|
||||
this.cancellationDocumentDate = cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getMemberFromDate() {
|
||||
return memberFromDate;
|
||||
}
|
||||
|
||||
public void setMemberFromDate(LocalDateFilter memberFromDate) {
|
||||
this.memberFromDate = memberFromDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getMemberUntilDate() {
|
||||
return memberUntilDate;
|
||||
}
|
||||
|
||||
public void setMemberUntilDate(LocalDateFilter memberUntilDate) {
|
||||
this.memberUntilDate = memberUntilDate;
|
||||
}
|
||||
|
||||
public StringFilter getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(StringFilter remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public LongFilter getShareId() {
|
||||
return shareId;
|
||||
}
|
||||
|
||||
public void setShareId(LongFilter shareId) {
|
||||
this.shareId = shareId;
|
||||
}
|
||||
|
||||
public LongFilter getAssetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public void setAssetId(LongFilter assetId) {
|
||||
this.assetId = assetId;
|
||||
}
|
||||
|
||||
public LongFilter getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(LongFilter customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final MembershipCriteria that = (MembershipCriteria) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(admissionDocumentDate, that.admissionDocumentDate) &&
|
||||
Objects.equals(cancellationDocumentDate, that.cancellationDocumentDate) &&
|
||||
Objects.equals(memberFromDate, that.memberFromDate) &&
|
||||
Objects.equals(memberUntilDate, that.memberUntilDate) &&
|
||||
Objects.equals(remark, that.remark) &&
|
||||
Objects.equals(shareId, that.shareId) &&
|
||||
Objects.equals(assetId, that.assetId) &&
|
||||
Objects.equals(customerId, that.customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
admissionDocumentDate,
|
||||
cancellationDocumentDate,
|
||||
memberFromDate,
|
||||
memberUntilDate,
|
||||
remark,
|
||||
shareId,
|
||||
assetId,
|
||||
customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MembershipCriteria{" +
|
||||
(id != null ? "id=" + id + ", " : "") +
|
||||
(admissionDocumentDate != null ? "admissionDocumentDate=" + admissionDocumentDate + ", " : "") +
|
||||
(cancellationDocumentDate != null ? "cancellationDocumentDate=" + cancellationDocumentDate + ", " : "") +
|
||||
(memberFromDate != null ? "memberFromDate=" + memberFromDate + ", " : "") +
|
||||
(memberUntilDate != null ? "memberUntilDate=" + memberUntilDate + ", " : "") +
|
||||
(remark != null ? "remark=" + remark + ", " : "") +
|
||||
(shareId != null ? "shareId=" + shareId + ", " : "") +
|
||||
(assetId != null ? "assetId=" + assetId + ", " : "") +
|
||||
(customerId != null ? "customerId=" + customerId + ", " : "") +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
@ -1,203 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Membership;
|
||||
import org.hostsharing.hsadminng.service.CustomerService;
|
||||
import org.hostsharing.hsadminng.service.MembershipService;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.*;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A DTO for the Membership entity.
|
||||
*/
|
||||
@EntityTypeId(Membership.ENTITY_TYPE_ID)
|
||||
public class MembershipDTO implements AccessMappings, FluentBuilder<MembershipDTO> {
|
||||
|
||||
@SelfId(resolver = MembershipService.class)
|
||||
@AccessFor(read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate admissionDocumentDate;
|
||||
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate cancellationDocumentDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate memberFromDate;
|
||||
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate memberUntilDate;
|
||||
|
||||
@Size(max = 160)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private String remark;
|
||||
|
||||
@ParentId(resolver = CustomerService.class)
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long customerId;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String customerPrefix;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = CustomerFinancialContact.class)
|
||||
private String customerDisplayLabel;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = CustomerFinancialContact.class)
|
||||
private String displayLabel;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getAdmissionDocumentDate() {
|
||||
return admissionDocumentDate;
|
||||
}
|
||||
|
||||
public void setAdmissionDocumentDate(LocalDate admissionDocumentDate) {
|
||||
this.admissionDocumentDate = admissionDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getCancellationDocumentDate() {
|
||||
return cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public void setCancellationDocumentDate(LocalDate cancellationDocumentDate) {
|
||||
this.cancellationDocumentDate = cancellationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getMemberFromDate() {
|
||||
return memberFromDate;
|
||||
}
|
||||
|
||||
public void setMemberFromDate(LocalDate memberFromDate) {
|
||||
this.memberFromDate = memberFromDate;
|
||||
}
|
||||
|
||||
public LocalDate getMemberUntilDate() {
|
||||
return memberUntilDate;
|
||||
}
|
||||
|
||||
public void setMemberUntilDate(LocalDate memberUntilDate) {
|
||||
this.memberUntilDate = memberUntilDate;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(Long customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getCustomerPrefix() {
|
||||
return customerPrefix;
|
||||
}
|
||||
|
||||
public void setCustomerPrefix(String customerPrefix) {
|
||||
this.customerPrefix = customerPrefix;
|
||||
}
|
||||
|
||||
public String getCustomerDisplayLabel() {
|
||||
return customerDisplayLabel;
|
||||
}
|
||||
|
||||
public void setCustomerDisplayLabel(final String customerDisplayLabel) {
|
||||
this.customerDisplayLabel = customerDisplayLabel;
|
||||
}
|
||||
|
||||
public String getDisplayLabel() {
|
||||
return displayLabel;
|
||||
}
|
||||
|
||||
public void setDisplayLabel(final String displayLabel) {
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MembershipDTO membershipDTO = (MembershipDTO) o;
|
||||
if (membershipDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), membershipDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MembershipDTO{" +
|
||||
"id=" + getId() +
|
||||
", admissionDocumentDate='" + getAdmissionDocumentDate() + "'" +
|
||||
", cancellationDocumentDate='" + getCancellationDocumentDate() + "'" +
|
||||
", memberFromDate='" + getMemberFromDate() + "'" +
|
||||
", memberUntilDate='" + getMemberUntilDate() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
", customer=" + getCustomerId() +
|
||||
", customerPrefix='" + getCustomerPrefix() + "'" +
|
||||
", customerDisplayLabel='" + getCustomerDisplayLabel() + "'" +
|
||||
", displayLabel='" + getDisplayLabel() + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonSerializer extends JsonSerializerWithAccessFilter<MembershipDTO> {
|
||||
|
||||
public JsonSerializer(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonDeserializer extends JsonDeserializerWithAccessFilter<MembershipDTO> {
|
||||
|
||||
public JsonDeserializer(
|
||||
final ApplicationContext ctx,
|
||||
final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
/**
|
||||
* A DTO representing a password change required data - current and new password.
|
||||
*/
|
||||
public class PasswordChangeDTO {
|
||||
|
||||
private String currentPassword;
|
||||
private String newPassword;
|
||||
|
||||
public PasswordChangeDTO() {
|
||||
// Empty constructor needed for Jackson.
|
||||
}
|
||||
|
||||
public PasswordChangeDTO(String currentPassword, String newPassword) {
|
||||
this.currentPassword = currentPassword;
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
|
||||
public String getCurrentPassword() {
|
||||
|
||||
return currentPassword;
|
||||
}
|
||||
|
||||
public void setCurrentPassword(String currentPassword) {
|
||||
this.currentPassword = currentPassword;
|
||||
}
|
||||
|
||||
public String getNewPassword() {
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public void setNewPassword(String newPassword) {
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
}
|
@ -1,189 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import io.github.jhipster.service.filter.Filter;
|
||||
import io.github.jhipster.service.filter.LocalDateFilter;
|
||||
import io.github.jhipster.service.filter.LongFilter;
|
||||
import io.github.jhipster.service.filter.StringFilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Criteria class for the SepaMandate entity. This class is used in SepaMandateResource to
|
||||
* receive all the possible filtering options from the Http GET request parameters.
|
||||
* For example the following could be a valid requests:
|
||||
* <code> /sepa-mandates?id.greaterThan=5&attr1.contains=something&attr2.specified=false</code>
|
||||
* As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use
|
||||
* fix type specific filters.
|
||||
*/
|
||||
public class SepaMandateCriteria implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private LongFilter id;
|
||||
|
||||
private StringFilter reference;
|
||||
|
||||
private StringFilter iban;
|
||||
|
||||
private StringFilter bic;
|
||||
|
||||
private LocalDateFilter grantingDocumentDate;
|
||||
|
||||
private LocalDateFilter revokationDocumentDate;
|
||||
|
||||
private LocalDateFilter validFromDate;
|
||||
|
||||
private LocalDateFilter validUntilDate;
|
||||
|
||||
private LocalDateFilter lastUsedDate;
|
||||
|
||||
private StringFilter remark;
|
||||
|
||||
private LongFilter customerId;
|
||||
|
||||
public LongFilter getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LongFilter id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public StringFilter getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(StringFilter reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public StringFilter getIban() {
|
||||
return iban;
|
||||
}
|
||||
|
||||
public void setIban(StringFilter iban) {
|
||||
this.iban = iban;
|
||||
}
|
||||
|
||||
public StringFilter getBic() {
|
||||
return bic;
|
||||
}
|
||||
|
||||
public void setBic(StringFilter bic) {
|
||||
this.bic = bic;
|
||||
}
|
||||
|
||||
public LocalDateFilter getGrantingDocumentDate() {
|
||||
return grantingDocumentDate;
|
||||
}
|
||||
|
||||
public void setGrantingDocumentDate(LocalDateFilter grantingDocumentDate) {
|
||||
this.grantingDocumentDate = grantingDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getRevokationDocumentDate() {
|
||||
return revokationDocumentDate;
|
||||
}
|
||||
|
||||
public void setRevokationDocumentDate(LocalDateFilter revokationDocumentDate) {
|
||||
this.revokationDocumentDate = revokationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getValidFromDate() {
|
||||
return validFromDate;
|
||||
}
|
||||
|
||||
public void setValidFromDate(LocalDateFilter validFromDate) {
|
||||
this.validFromDate = validFromDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getValidUntilDate() {
|
||||
return validUntilDate;
|
||||
}
|
||||
|
||||
public void setValidUntilDate(LocalDateFilter validUntilDate) {
|
||||
this.validUntilDate = validUntilDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getLastUsedDate() {
|
||||
return lastUsedDate;
|
||||
}
|
||||
|
||||
public void setLastUsedDate(LocalDateFilter lastUsedDate) {
|
||||
this.lastUsedDate = lastUsedDate;
|
||||
}
|
||||
|
||||
public StringFilter getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(StringFilter remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public LongFilter getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(LongFilter customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final SepaMandateCriteria that = (SepaMandateCriteria) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(reference, that.reference) &&
|
||||
Objects.equals(iban, that.iban) &&
|
||||
Objects.equals(bic, that.bic) &&
|
||||
Objects.equals(grantingDocumentDate, that.grantingDocumentDate) &&
|
||||
Objects.equals(revokationDocumentDate, that.revokationDocumentDate) &&
|
||||
Objects.equals(validFromDate, that.validFromDate) &&
|
||||
Objects.equals(validUntilDate, that.validUntilDate) &&
|
||||
Objects.equals(lastUsedDate, that.lastUsedDate) &&
|
||||
Objects.equals(remark, that.remark) &&
|
||||
Objects.equals(customerId, that.customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
reference,
|
||||
iban,
|
||||
bic,
|
||||
grantingDocumentDate,
|
||||
revokationDocumentDate,
|
||||
validFromDate,
|
||||
validUntilDate,
|
||||
lastUsedDate,
|
||||
remark,
|
||||
customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SepaMandateCriteria{" +
|
||||
(id != null ? "id=" + id + ", " : "") +
|
||||
(reference != null ? "reference=" + reference + ", " : "") +
|
||||
(iban != null ? "iban=" + iban + ", " : "") +
|
||||
(bic != null ? "bic=" + bic + ", " : "") +
|
||||
(grantingDocumentDate != null ? "grantingDocumentDate=" + grantingDocumentDate + ", " : "") +
|
||||
(revokationDocumentDate != null ? "revokationDocumentDate=" + revokationDocumentDate + ", " : "") +
|
||||
(validFromDate != null ? "validFromDate=" + validFromDate + ", " : "") +
|
||||
(validUntilDate != null ? "validUntilDate=" + validUntilDate + ", " : "") +
|
||||
(lastUsedDate != null ? "lastUsedDate=" + lastUsedDate + ", " : "") +
|
||||
(remark != null ? "remark=" + remark + ", " : "") +
|
||||
(customerId != null ? "customerId=" + customerId + ", " : "") +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.SepaMandate;
|
||||
import org.hostsharing.hsadminng.service.CustomerService;
|
||||
import org.hostsharing.hsadminng.service.SepaMandateService;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.*;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A DTO for the SepaMandate entity.
|
||||
*/
|
||||
@EntityTypeId(SepaMandate.ENTITY_TYPE_ID)
|
||||
public class SepaMandateDTO implements AccessMappings, FluentBuilder<SepaMandateDTO> {
|
||||
|
||||
@SelfId(resolver = SepaMandateService.class)
|
||||
@AccessFor(read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 40)
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String reference;
|
||||
|
||||
@Size(max = 34)
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String iban;
|
||||
|
||||
@Size(max = 11)
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String bic;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate grantingDocumentDate;
|
||||
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate revokationDocumentDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate validFromDate;
|
||||
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
update = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate validUntilDate;
|
||||
|
||||
@AccessFor(
|
||||
init = Admin.class,
|
||||
update = Admin.class,
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate lastUsedDate;
|
||||
|
||||
@Size(max = 160)
|
||||
@AccessFor(init = Admin.class, update = Supporter.class, read = Supporter.class)
|
||||
private String remark;
|
||||
|
||||
@ParentId(resolver = CustomerService.class)
|
||||
@AccessFor(
|
||||
init = { CustomerContractualContact.class, CustomerFinancialContact.class },
|
||||
read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long customerId;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String customerDisplayLabel;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getIban() {
|
||||
return iban;
|
||||
}
|
||||
|
||||
public void setIban(String iban) {
|
||||
this.iban = iban;
|
||||
}
|
||||
|
||||
public String getBic() {
|
||||
return bic;
|
||||
}
|
||||
|
||||
public void setBic(String bic) {
|
||||
this.bic = bic;
|
||||
}
|
||||
|
||||
public LocalDate getGrantingDocumentDate() {
|
||||
return grantingDocumentDate;
|
||||
}
|
||||
|
||||
public void setGrantingDocumentDate(LocalDate grantingDocumentDate) {
|
||||
this.grantingDocumentDate = grantingDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getRevokationDocumentDate() {
|
||||
return revokationDocumentDate;
|
||||
}
|
||||
|
||||
public void setRevokationDocumentDate(LocalDate revokationDocumentDate) {
|
||||
this.revokationDocumentDate = revokationDocumentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValidFromDate() {
|
||||
return validFromDate;
|
||||
}
|
||||
|
||||
public void setValidFromDate(LocalDate validFromDate) {
|
||||
this.validFromDate = validFromDate;
|
||||
}
|
||||
|
||||
public LocalDate getValidUntilDate() {
|
||||
return validUntilDate;
|
||||
}
|
||||
|
||||
public void setValidUntilDate(LocalDate validUntilDate) {
|
||||
this.validUntilDate = validUntilDate;
|
||||
}
|
||||
|
||||
public LocalDate getLastUsedDate() {
|
||||
return lastUsedDate;
|
||||
}
|
||||
|
||||
public void setLastUsedDate(LocalDate lastUsedDate) {
|
||||
this.lastUsedDate = lastUsedDate;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(Long customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getCustomerDisplayLabel() {
|
||||
return customerDisplayLabel;
|
||||
}
|
||||
|
||||
public void setCustomerDisplayLabel(String customerDisplayLabel) {
|
||||
this.customerDisplayLabel = customerDisplayLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SepaMandateDTO sepaMandateDTO = (SepaMandateDTO) o;
|
||||
if (sepaMandateDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), sepaMandateDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SepaMandateDTO{" +
|
||||
"id=" + getId() +
|
||||
", reference='" + getReference() + "'" +
|
||||
", iban='" + getIban() + "'" +
|
||||
", bic='" + getBic() + "'" +
|
||||
", grantingDocumentDate='" + getGrantingDocumentDate() + "'" +
|
||||
", revokationDocumentDate='" + getRevokationDocumentDate() + "'" +
|
||||
", validFromDate='" + getValidFromDate() + "'" +
|
||||
", validUntilDate='" + getValidUntilDate() + "'" +
|
||||
", lastUsedDate='" + getLastUsedDate() + "'" +
|
||||
", remark='" + getRemark() + "'" +
|
||||
", customer=" + getCustomerId() +
|
||||
", customerDisplayLabel='" + getCustomerDisplayLabel() + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonSerializer extends JsonSerializerWithAccessFilter<SepaMandateDTO> {
|
||||
|
||||
public JsonSerializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonDeserializer extends JsonDeserializerWithAccessFilter<SepaMandateDTO> {
|
||||
|
||||
public JsonDeserializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||
|
||||
import io.github.jhipster.service.filter.Filter;
|
||||
import io.github.jhipster.service.filter.IntegerFilter;
|
||||
import io.github.jhipster.service.filter.LocalDateFilter;
|
||||
import io.github.jhipster.service.filter.LongFilter;
|
||||
import io.github.jhipster.service.filter.StringFilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Criteria class for the Share entity. This class is used in ShareResource to
|
||||
* receive all the possible filtering options from the Http GET request parameters.
|
||||
* For example the following could be a valid requests:
|
||||
* <code> /shares?id.greaterThan=5&attr1.contains=something&attr2.specified=false</code>
|
||||
* As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use
|
||||
* fix type specific filters.
|
||||
*/
|
||||
public class ShareCriteria implements Serializable {
|
||||
|
||||
/**
|
||||
* Class for filtering ShareAction
|
||||
*/
|
||||
public static class ShareActionFilter extends Filter<ShareAction> {
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private LongFilter id;
|
||||
|
||||
private LocalDateFilter documentDate;
|
||||
|
||||
private LocalDateFilter valueDate;
|
||||
|
||||
private ShareActionFilter action;
|
||||
|
||||
private IntegerFilter quantity;
|
||||
|
||||
private StringFilter remark;
|
||||
|
||||
private LongFilter membershipId;
|
||||
|
||||
public LongFilter getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LongFilter id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateFilter getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDateFilter documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDateFilter getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDateFilter valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public ShareActionFilter getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(ShareActionFilter action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public IntegerFilter getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(IntegerFilter quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public StringFilter getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(StringFilter remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public LongFilter getMembershipId() {
|
||||
return membershipId;
|
||||
}
|
||||
|
||||
public void setMembershipId(LongFilter membershipId) {
|
||||
this.membershipId = membershipId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ShareCriteria that = (ShareCriteria) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(documentDate, that.documentDate) &&
|
||||
Objects.equals(valueDate, that.valueDate) &&
|
||||
Objects.equals(action, that.action) &&
|
||||
Objects.equals(quantity, that.quantity) &&
|
||||
Objects.equals(remark, that.remark) &&
|
||||
Objects.equals(membershipId, that.membershipId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
documentDate,
|
||||
valueDate,
|
||||
action,
|
||||
quantity,
|
||||
remark,
|
||||
membershipId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShareCriteria{" +
|
||||
(id != null ? "id=" + id + ", " : "") +
|
||||
(documentDate != null ? "documentDate=" + documentDate + ", " : "") +
|
||||
(valueDate != null ? "valueDate=" + valueDate + ", " : "") +
|
||||
(action != null ? "action=" + action + ", " : "") +
|
||||
(quantity != null ? "quantity=" + quantity + ", " : "") +
|
||||
(remark != null ? "remark=" + remark + ", " : "") +
|
||||
(membershipId != null ? "membershipId=" + membershipId + ", " : "") +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.domain.Share;
|
||||
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||
import org.hostsharing.hsadminng.service.MembershipService;
|
||||
import org.hostsharing.hsadminng.service.ShareService;
|
||||
import org.hostsharing.hsadminng.service.UserRoleAssignmentService;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.*;
|
||||
import org.hostsharing.hsadminng.service.accessfilter.Role.*;
|
||||
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* A DTO for the Share entity.
|
||||
*/
|
||||
@EntityTypeId(Share.ENTITY_TYPE_ID)
|
||||
public class ShareDTO implements Serializable, AccessMappings {
|
||||
|
||||
@SelfId(resolver = ShareService.class)
|
||||
@AccessFor(read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate documentDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private LocalDate valueDate;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private ShareAction action;
|
||||
|
||||
@NotNull
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Integer quantity;
|
||||
|
||||
@Size(max = 160)
|
||||
@AccessFor(init = Admin.class, update = Admin.class, read = Supporter.class)
|
||||
private String remark;
|
||||
|
||||
@ParentId(resolver = MembershipService.class)
|
||||
@AccessFor(init = Admin.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private Long membershipId;
|
||||
|
||||
@AccessFor(update = Ignored.class, read = { CustomerContractualContact.class, CustomerFinancialContact.class })
|
||||
private String membershipDisplayLabel;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getDocumentDate() {
|
||||
return documentDate;
|
||||
}
|
||||
|
||||
public void setDocumentDate(LocalDate documentDate) {
|
||||
this.documentDate = documentDate;
|
||||
}
|
||||
|
||||
public LocalDate getValueDate() {
|
||||
return valueDate;
|
||||
}
|
||||
|
||||
public void setValueDate(LocalDate valueDate) {
|
||||
this.valueDate = valueDate;
|
||||
}
|
||||
|
||||
public ShareAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(ShareAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getMembershipId() {
|
||||
return membershipId;
|
||||
}
|
||||
|
||||
public void setMembershipId(Long membershipId) {
|
||||
this.membershipId = membershipId;
|
||||
}
|
||||
|
||||
public String getMembershipDisplayLabel() {
|
||||
return membershipDisplayLabel;
|
||||
}
|
||||
|
||||
public void setMembershipDisplayLabel(String membershipDisplayLabel) {
|
||||
this.membershipDisplayLabel = membershipDisplayLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShareDTO shareDTO = (ShareDTO) o;
|
||||
if (shareDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(getId(), shareDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShareDTO{" +
|
||||
"id=" + getId() +
|
||||
", documentDate='" + getDocumentDate() + "'" +
|
||||
", valueDate='" + getValueDate() + "'" +
|
||||
", action='" + getAction() + "'" +
|
||||
", quantity=" + getQuantity() +
|
||||
", remark='" + getRemark() + "'" +
|
||||
", membership=" + getMembershipId() +
|
||||
", membershipDisplayLabel='" + getMembershipDisplayLabel() + "'" +
|
||||
"}";
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonSerializer extends JsonSerializerWithAccessFilter<ShareDTO> {
|
||||
|
||||
public JsonSerializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonComponent
|
||||
public static class JsonDeserializer extends JsonDeserializerWithAccessFilter<ShareDTO> {
|
||||
|
||||
public JsonDeserializer(final ApplicationContext ctx, final UserRoleAssignmentService userRoleAssignmentService) {
|
||||
super(ctx, userRoleAssignmentService);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,200 +0,0 @@
|
||||
// Licensed under Apache-2.0
|
||||
package org.hostsharing.hsadminng.service.dto;
|
||||
|
||||
import org.hostsharing.hsadminng.config.Constants;
|
||||
import org.hostsharing.hsadminng.domain.Authority;
|
||||
import org.hostsharing.hsadminng.domain.User;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* A DTO representing a user, with his authorities.
|
||||
*/
|
||||
public class UserDTO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
@Pattern(regexp = Constants.LOGIN_REGEX)
|
||||
@Size(min = 1, max = 50)
|
||||
private String login;
|
||||
|
||||
@Size(max = 50)
|
||||
private String firstName;
|
||||
|
||||
@Size(max = 50)
|
||||
private String lastName;
|
||||
|
||||
@Email
|
||||
@Size(min = 5, max = 254)
|
||||
private String email;
|
||||
|
||||
@Size(max = 256)
|
||||
private String imageUrl;
|
||||
|
||||
private boolean activated = false;
|
||||
|
||||
@Size(min = 2, max = 6)
|
||||
private String langKey;
|
||||
|
||||
private String createdBy;
|
||||
|
||||
private Instant createdDate;
|
||||
|
||||
private String lastModifiedBy;
|
||||
|
||||
private Instant lastModifiedDate;
|
||||
|
||||
private Set<String> authorities;
|
||||
|
||||
public UserDTO() {
|
||||
// Empty constructor needed for Jackson.
|
||||
}
|
||||
|
||||
public UserDTO(User user) {
|
||||
this.id = user.getId();
|
||||
this.login = user.getLogin();
|
||||
this.firstName = user.getFirstName();
|
||||
this.lastName = user.getLastName();
|
||||
this.email = user.getEmail();
|
||||
this.activated = user.getActivated();
|
||||
this.imageUrl = user.getImageUrl();
|
||||
this.langKey = user.getLangKey();
|
||||
this.createdBy = user.getCreatedBy();
|
||||
this.createdDate = user.getCreatedDate();
|
||||
this.lastModifiedBy = user.getLastModifiedBy();
|
||||
this.lastModifiedDate = user.getLastModifiedDate();
|
||||
this.authorities = user.getAuthorities()
|
||||
.stream()
|
||||
.map(Authority::getName)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public boolean isActivated() {
|
||||
return activated;
|
||||
}
|
||||
|
||||
public void setActivated(boolean activated) {
|
||||
this.activated = activated;
|
||||
}
|
||||
|
||||
public String getLangKey() {
|
||||
return langKey;
|
||||
}
|
||||
|
||||
public void setLangKey(String langKey) {
|
||||
this.langKey = langKey;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Instant getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Instant createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getLastModifiedBy() {
|
||||
return lastModifiedBy;
|
||||
}
|
||||
|
||||
public void setLastModifiedBy(String lastModifiedBy) {
|
||||
this.lastModifiedBy = lastModifiedBy;
|
||||
}
|
||||
|
||||
public Instant getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
public void setLastModifiedDate(Instant lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
|
||||
public Set<String> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public void setAuthorities(Set<String> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDTO{" +
|
||||
"login='" + login + '\'' +
|
||||
", firstName='" + firstName + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", imageUrl='" + imageUrl + '\'' +
|
||||
", activated=" + activated +
|
||||
", langKey='" + langKey + '\'' +
|
||||
", createdBy=" + createdBy +
|
||||
", createdDate=" + createdDate +
|
||||
", lastModifiedBy='" + lastModifiedBy + '\'' +
|
||||
", lastModifiedDate=" + lastModifiedDate +
|
||||
", authorities=" + authorities +
|
||||
"}";
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user