Merge pull request #3 from Kitzanos/feature/GEPAFINBE-3
GEPAFINBE-3(User management)
This commit is contained in:
56
.gitignore
vendored
56
.gitignore
vendored
@@ -1,24 +1,42 @@
|
|||||||
# Compiled class file
|
HELP.md
|
||||||
*.class
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
### DS_Store ###
|
||||||
|
.DS_Store
|
||||||
|
/bin/
|
||||||
|
|
||||||
|
|
||||||
# Log file
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# BlueJ files
|
|
||||||
*.ctxt
|
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
|
||||||
hs_err_pid*
|
|
||||||
replay_pid*
|
|
||||||
|
|||||||
137
pom.xml
137
pom.xml
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -13,42 +12,148 @@
|
|||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>tendermanagement</name>
|
<name>tendermanagement</name>
|
||||||
<description>Tender Management project</description>
|
<description>Tender Management project</description>
|
||||||
<url/>
|
|
||||||
<licenses>
|
|
||||||
<license/>
|
|
||||||
</licenses>
|
|
||||||
<developers>
|
|
||||||
<developer/>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<connection/>
|
|
||||||
<developerConnection/>
|
|
||||||
<tag/>
|
|
||||||
<url/>
|
|
||||||
</scm>
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
|
<mapstruct.version>1.5.5.Final</mapstruct.version> <!-- MapStruct version -->
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Spring Boot Starter Web for REST API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Lombok for reducing boilerplate code -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- H2 Database for in-memory testing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- PostgreSQL Database -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Starter Data JPA for JPA and Hibernate -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Springdoc OpenAPI for API Documentation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MapStruct for object mapping -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>${mapstruct.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>${mapstruct.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.liquibase</groupId>
|
||||||
|
<artifactId>liquibase-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Starter Test for unit and integration tests -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-s3</artifactId>
|
||||||
|
<version>1.12.312</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-core</artifactId>
|
||||||
|
<version>1.12.341</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-api</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-impl</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-jackson</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.validation</groupId>
|
||||||
|
<artifactId>jakarta.validation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.validator</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.10.1</version> <!-- or the latest version -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.liquibase</groupId>
|
||||||
|
<artifactId>liquibase-maven-plugin</artifactId>
|
||||||
|
<version>4.20.0</version>
|
||||||
|
<configuration>
|
||||||
|
<propertyFile>src/main/resources/application.properties</propertyFile>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -2,12 +2,21 @@ package net.gepafin.tendermanagement;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
@EnableScheduling
|
||||||
|
@ComponentScan(basePackages = {"net.gepafin.tendermanagement"})
|
||||||
|
@EnableJpaRepositories(basePackages = {"net.gepafin.tendermanagement"})
|
||||||
|
@EntityScan(basePackages = {"net.gepafin.tendermanagement"})
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class TendermanagementApplication {
|
public class TendermanagementApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(TendermanagementApplication.class, args);
|
SpringApplication.run(TendermanagementApplication.class, args);
|
||||||
|
System.out.println("Spring Boot started");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import com.amazonaws.auth.AWSCredentials;
|
||||||
|
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||||
|
import com.amazonaws.auth.BasicAWSCredentials;
|
||||||
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class AmazonConfig {
|
||||||
|
|
||||||
|
@Value("${aws.access.key.id}")
|
||||||
|
private String accessKey;
|
||||||
|
|
||||||
|
@Value("${aws.secret.access.key}")
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
@Value("${aws.s3.region}")
|
||||||
|
private String region;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AmazonS3 mementoBucket() {
|
||||||
|
AWSCredentials awsCredentials =
|
||||||
|
new BasicAWSCredentials(accessKey, secretKey);
|
||||||
|
return AmazonS3ClientBuilder
|
||||||
|
.standard()
|
||||||
|
.withRegion(region)
|
||||||
|
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MessageSourceConfig {
|
||||||
|
@Bean(name = "defaultMessageSource")
|
||||||
|
public ResourceBundleMessageSource messageSource() {
|
||||||
|
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||||
|
messageSource.setBasenames("message");
|
||||||
|
messageSource.setDefaultEncoding("UTF-8");
|
||||||
|
messageSource.setUseCodeAsDefaultMessage(true);
|
||||||
|
return messageSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import liquibase.change.DatabaseChange;
|
||||||
|
import liquibase.integration.spring.SpringLiquibase;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({ SpringLiquibase.class, DatabaseChange.class })
|
||||||
|
@ConditionalOnProperty(prefix = "spring.liquibase", name = "enabled", matchIfMissing = true)
|
||||||
|
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
|
||||||
|
@Import({SchemaInit.SpringLiquibaseDependsOnPostProcessor.class})
|
||||||
|
public class SchemaInit {
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConditionalOnProperty(prefix = "spring.liquibase", name = "enabled", matchIfMissing = true)
|
||||||
|
public static class SchemaInitBean implements InitializingBean {
|
||||||
|
|
||||||
|
private final DataSource dataSource;
|
||||||
|
private final String schemaName;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SchemaInitBean(DataSource dataSource, @Value("${spring.liquibase.default-schema}") String schemaName) {
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
this.schemaName = schemaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() {
|
||||||
|
try (Connection conn = dataSource.getConnection();
|
||||||
|
Statement statement = conn.createStatement()) {
|
||||||
|
log.info("Going to create DB schema '{}' if not exists.", schemaName);
|
||||||
|
String query = "create schema if not exists " + schemaName;
|
||||||
|
statement.execute(query);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException("Failed to create schema '" + schemaName + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ConditionalOnBean(SchemaInitBean.class)
|
||||||
|
static class SpringLiquibaseDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||||
|
|
||||||
|
SpringLiquibaseDependsOnPostProcessor() {
|
||||||
|
// Configure the 3rd party SpringLiquibase bean to depend on our SchemaInitBean
|
||||||
|
super(SpringLiquibase.class, SchemaInitBean.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.Components;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
|
import io.swagger.v3.oas.models.servers.Server;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.JWTConfigurer;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.JWTFilter;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||||
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
public class SecurityConfig {
|
||||||
|
|
||||||
|
private final TokenProvider tokenProvider;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SecurityConfig(TokenProvider tokenProvider) {
|
||||||
|
this.tokenProvider = tokenProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
|
||||||
|
return config.getAuthenticationManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) {
|
||||||
|
return new MvcRequestMatcher.Builder(introspector);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebSecurityCustomizer webSecurityCustomizer(MvcRequestMatcher.Builder mvc) {
|
||||||
|
return (web) -> web.ignoring()
|
||||||
|
.requestMatchers(mvc.pattern(HttpMethod.OPTIONS, "/**"))
|
||||||
|
.requestMatchers(new AntPathRequestMatcher("/i18n/**"))
|
||||||
|
.requestMatchers(new AntPathRequestMatcher("/content/**"))
|
||||||
|
.requestMatchers(new AntPathRequestMatcher("/swagger-ui/index.html"))
|
||||||
|
.requestMatchers(new AntPathRequestMatcher("/swagger-ui/**"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
config.addAllowedOrigin("*");
|
||||||
|
config.addAllowedHeader("*");
|
||||||
|
config.addAllowedMethod("*");
|
||||||
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception {
|
||||||
|
http
|
||||||
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
.requestMatchers(mvc.pattern(HttpMethod.POST, "/v1/user/login")).permitAll()
|
||||||
|
.requestMatchers(mvc.pattern(HttpMethod.POST, "/v1/user")).permitAll()
|
||||||
|
.requestMatchers("/swagger-ui/**").permitAll()
|
||||||
|
.requestMatchers("/v1/api-docs/**").permitAll()
|
||||||
|
.anyRequest().authenticated()
|
||||||
|
)
|
||||||
|
.sessionManagement(session -> session
|
||||||
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
|
)
|
||||||
|
.apply(new JWTConfigurer(tokenProvider))
|
||||||
|
.and()
|
||||||
|
.addFilterBefore(new JWTFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI customOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.addServersItem(new Server().url("/"))
|
||||||
|
.addSecurityItem(new SecurityRequirement().addList("bearer-key"))
|
||||||
|
.components(new Components().addSecuritySchemes("bearer-key",
|
||||||
|
new SecurityScheme().type(SecurityScheme.Type.HTTP)
|
||||||
|
.scheme("bearer").bearerFormat("JWT")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Translator {
|
||||||
|
|
||||||
|
private static ResourceBundleMessageSource messageSource;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Translator(ResourceBundleMessageSource messageSource) {
|
||||||
|
Translator.messageSource = messageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toLocale(String msgCode) {
|
||||||
|
// LocaleContextHolder.setDefaultLocale(Locale.ITALIAN);
|
||||||
|
Locale locale = LocaleContextHolder.getLocale();
|
||||||
|
return messageSource.getMessage(msgCode, null, locale);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.config.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> {
|
||||||
|
|
||||||
|
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package net.gepafin.tendermanagement.config.jwt;
|
||||||
|
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.ServletRequest;
|
||||||
|
import jakarta.servlet.ServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class JWTFilter extends GenericFilterBean {
|
||||||
|
|
||||||
|
private final 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 token = resolveToken(httpServletRequest);
|
||||||
|
|
||||||
|
if (StringUtils.hasText(token) && tokenProvider.validateToken(token)) {
|
||||||
|
Authentication authentication = tokenProvider.getAuthentication(token);
|
||||||
|
if (authentication != null) {
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveToken(HttpServletRequest request) {
|
||||||
|
String bearerToken = request.getHeader("Authorization");
|
||||||
|
return StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ") ? bearerToken.substring(7) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
package net.gepafin.tendermanagement.config.jwt;
|
||||||
|
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import io.jsonwebtoken.security.Keys;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
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.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import static io.micrometer.common.util.StringUtils.isEmpty;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TokenProvider {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(TokenProvider.class);
|
||||||
|
|
||||||
|
@Value("${security.authentication.jwt.secret}")
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
@Value("${security.authentication.jwt.token-validity-in-seconds}")
|
||||||
|
private long tokenValidityInSeconds;
|
||||||
|
|
||||||
|
private SecretKey key;
|
||||||
|
|
||||||
|
private static final String AUTHORITIES_KEY = "auth";
|
||||||
|
private static final String MERCHANTID="merchantId";
|
||||||
|
|
||||||
|
public static final String INVALID_USER = "invalid_user";
|
||||||
|
static final String AUTH_SECRET = "X-Api-Secret";
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
this.key = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
|
||||||
|
log.info("JWT Secret Key initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createToken(Authentication authentication, Boolean rememberMe, UserEntity user) {
|
||||||
|
String authorities = authentication.getAuthorities().stream()
|
||||||
|
.map(GrantedAuthority::getAuthority)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
Long now;
|
||||||
|
Date validity;
|
||||||
|
|
||||||
|
if (Boolean.TRUE.equals(rememberMe)) {
|
||||||
|
now = DateUtils.addMonths(new Date(), 2).getTime();
|
||||||
|
validity = new Date(now);
|
||||||
|
log.info("Creating token with extended validity for 2 months.");
|
||||||
|
} else {
|
||||||
|
now = (new Date()).getTime();
|
||||||
|
validity = new Date(now + (this.tokenValidityInSeconds * 1000));
|
||||||
|
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
String payload = authentication.getName();
|
||||||
|
if(user != null) {
|
||||||
|
payload += ":"+user.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
String token = Jwts.builder()
|
||||||
|
.setSubject(payload)
|
||||||
|
.claim("auth", authorities)
|
||||||
|
.signWith(key, SignatureAlgorithm.HS512)
|
||||||
|
.setExpiration(validity)
|
||||||
|
.compact();
|
||||||
|
|
||||||
|
log.debug("Generated token: {}", token);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Authentication getAuthentication(String token) {
|
||||||
|
Claims claims = Jwts.parserBuilder()
|
||||||
|
.setSigningKey(key)
|
||||||
|
.build()
|
||||||
|
.parseClaimsJws(token)
|
||||||
|
.getBody();
|
||||||
|
|
||||||
|
UserDetails principal = new User(claims.getSubject(), "", Collections.emptyList());
|
||||||
|
log.info("Authenticated user: {}", claims.getSubject());
|
||||||
|
|
||||||
|
return new UsernamePasswordAuthenticationToken(principal, token, ClaimsToAuthorities(claims.get("auth")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<? extends GrantedAuthority> ClaimsToAuthorities(Object authClaim) {
|
||||||
|
Collection<? extends GrantedAuthority> authorities = authClaim == null || ((String) authClaim).isEmpty() ?
|
||||||
|
Collections.emptyList() :
|
||||||
|
Arrays.stream(((String) authClaim).split(","))
|
||||||
|
.map(SimpleGrantedAuthority::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.debug("Converted authorities from claims: {}", authorities);
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateToken(String authToken) {
|
||||||
|
try {
|
||||||
|
Jwts.parserBuilder()
|
||||||
|
.setSigningKey(key)
|
||||||
|
.build()
|
||||||
|
.parseClaimsJws(authToken);
|
||||||
|
log.info("Token is valid.");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Token validation failed: {}", e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Map<String, Object> getUserInfoAndUserIdFromToken(HttpServletRequest request) {
|
||||||
|
Map<String, Object> userInfo = new HashMap<>();
|
||||||
|
String authSecretHeader=request.getHeader(AUTH_SECRET);
|
||||||
|
// userInfo.put(MERCHANTID, null);
|
||||||
|
String bearerToken = request.getHeader("Authorization");
|
||||||
|
String token = "";
|
||||||
|
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
|
||||||
|
token = bearerToken.substring(7, bearerToken.length());
|
||||||
|
}
|
||||||
|
extractDetailsFromTheToken(userInfo, authSecretHeader, token);
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
public Map<String, Object> extractDetailsFromTheToken(Map<String, Object> userInfo, String authSecretHeader,
|
||||||
|
String token) {
|
||||||
|
String payload = null;
|
||||||
|
Boolean isSuperAdmin = false;
|
||||||
|
// if (StringUtils.hasText(token) && token.endsWith("_superKey" + getSuperUserToken())) {
|
||||||
|
// Map<String, Object> payloadMap = getUserDetailsForSuperUser(token);
|
||||||
|
// payload = payloadMap.get("sub").toString();
|
||||||
|
// isSuperAdmin = true;
|
||||||
|
//
|
||||||
|
// } else
|
||||||
|
if (!isEmpty(authSecretHeader)) {
|
||||||
|
String secret = Utils.decodeBase64String(authSecretHeader);
|
||||||
|
String[] tokenArr = secret.split("\\.", 2);
|
||||||
|
String[] merchant = tokenArr[0].split("-");
|
||||||
|
if (ArrayUtils.isNotEmpty(merchant) && 2 <= merchant.length) {
|
||||||
|
userInfo.put(MERCHANTID, merchant[1]);
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
payload = getUserDetails(token);
|
||||||
|
}
|
||||||
|
if (payload != null && !isSuperAdmin) {
|
||||||
|
String[] payloadString = payload.split(":");{
|
||||||
|
|
||||||
|
if (payloadString.length > 1) {
|
||||||
|
// userInfo.put(MERCHANTID, payloadString[1]);
|
||||||
|
// userInfo.put("associatedTags", payloadString[2]);
|
||||||
|
userInfo.put("userId", payloadString[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payloadString.length > 1) {
|
||||||
|
// userInfo.put(MERCHANTID, payloadString[1]);
|
||||||
|
// userInfo.put("associatedTags", payloadString[2]);
|
||||||
|
userInfo.put("userId", payloadString[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String[] payloadString = payload.split(":");
|
||||||
|
|
||||||
|
if (payloadString.length > 1) {
|
||||||
|
userInfo.put("userId", payloadString[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
public Map<String, Object> getUserDetailsForSuperUser(String token) {
|
||||||
|
Base64.Decoder decoder = Base64.getUrlDecoder();
|
||||||
|
String[] parts = token.split("\\."); // Splitting header, payload and signature
|
||||||
|
Gson g = new Gson();
|
||||||
|
return g.fromJson(new String(decoder.decode(parts[1])), Map.class);
|
||||||
|
}
|
||||||
|
// public String getSuperUserToken() {
|
||||||
|
// return superUserToken;
|
||||||
|
// }
|
||||||
|
public String getUserDetails(String token) {
|
||||||
|
Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
|
||||||
|
return claims.getSubject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package net.gepafin.tendermanagement.constants;
|
||||||
|
|
||||||
|
public class GepafinConstant {
|
||||||
|
|
||||||
|
public static final String USER_CREATED_SUCCESS_MSG = "user.created.success";
|
||||||
|
public static final String USER_UPDATED_SUCCESS_MSG = "user.updated.success";
|
||||||
|
public static final String USER_DELETED_SUCCESS_MSG = "user.deleted.success";
|
||||||
|
public static final String USER_NOT_FOUND_MSG = "user.not.found";
|
||||||
|
public static final String CREATE_USER_ERROR_MSG = "create_user_error_msg";
|
||||||
|
public static final String UPDATE_USER_ERROR_MSG = "update_user_error_msg";
|
||||||
|
public static final String DELETE_USER_ERROR_MSG = "delete_user_error_msg";
|
||||||
|
public static final String GET_USER_SUCCESS_MSG = "get_user_success_msg";
|
||||||
|
|
||||||
|
public static final String ROLE_CREATED_SUCCESS_MSG = "role.created.success";
|
||||||
|
public static final String ROLE_UPDATED_SUCCESS_MSG = "role.updated.success";
|
||||||
|
public static final String ROLE_DELETED_SUCCESS_MSG = "role.deleted.success";
|
||||||
|
public static final String ROLE_FETCH_SUCCESS_MSG = "role.fetch.success";
|
||||||
|
public static final String ROLE_NOT_FOUND = "role.not.found";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String REGION_CREATED_SUCCESS_MSG = "region.created.success";
|
||||||
|
public static final String REGION_UPDATED_SUCCESS_MSG = "region.updated.success";
|
||||||
|
public static final String GET_REGION_SUCCESS_MSG = "get.region.success";
|
||||||
|
public static final String DELETE_REGION_SUCCESS_MSG = "delete.region.success";
|
||||||
|
public static final String REGION_NOT_FOUND_MSG = "user.region.not.found";
|
||||||
|
public static final String PASSWORD_DOESNT_MATCH ="password.doesnt.match";
|
||||||
|
public static final String USER_NOT_EXIST_MSG = "user.not.exist";
|
||||||
|
public static final String REGION_NOT_FOUND = "region.not.found";
|
||||||
|
public static final String USER_ID_NOT_NULL_MSG = "user.id.not.null";
|
||||||
|
public static final String QUESTION_NOT_EMPTY_MSG = "question.not.empty";
|
||||||
|
public static final String NAME_NOT_EMPTY_MSG = "name.not.empty";
|
||||||
|
public static final String TYPE_NOT_EMPTY_MSG = "type.not.empty";
|
||||||
|
public static final String REGION_NOT_NULL_MSG = "region.not.null";
|
||||||
|
public static final String AMOUNT_GREATER_THAN_ZERO_MSG = "amount.greater.than.zero";
|
||||||
|
public static final String LOOK_UP_DATA_NOT_VALID_MSG = "look.up.data.not.valid";
|
||||||
|
public static final String FILES_UPLOADED_MSG = "files.uploaded";
|
||||||
|
public static final String CALL_CREATED_SUCCESSFULLY_MSG = "call.created.successfully";
|
||||||
|
public static final String FILE_DELETED_SUCCESSFULLY_MSG="file.deleted.successfully";
|
||||||
|
public static final String DOCUMENT_NOT_FOUND="document.not.found";
|
||||||
|
public static final String LOGIN_SUCCESS_MSG="login.successfully";
|
||||||
|
public static final String PASSWORD_MIN_LEN ="pass.min.len.msg";
|
||||||
|
public static final String EMAIL_ALREADY_EXISTS = "email.already.exists";
|
||||||
|
|
||||||
|
}
|
||||||
325
src/main/java/net/gepafin/tendermanagement/dao/CallDao.java
Normal file
325
src/main/java/net/gepafin/tendermanagement/dao/CallDao.java
Normal file
@@ -0,0 +1,325 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.enums.CallTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.*;
|
||||||
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CallDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallRepository callRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentRepository documentRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EvaluationCriteriaRepository evaluationCriteriaRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FaqRepository faqRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionRepository regionRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LookUpDataRepository lookUpDataRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
public CreateCallResponseBean createCall(CreateCallRequest createCallRequest, Long userId) {
|
||||||
|
try {
|
||||||
|
CreateCallResponseBean createCallResponseBean=null;
|
||||||
|
CallEntity callEntity = convertToCallEntity(createCallRequest);
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = convertToEvaluationCriteriaEntities(createCallRequest.getCriteria(), callEntity);
|
||||||
|
List<DocumentEntity> documentEntities = convertToDocumentEntities(createCallRequest.getDocs(), callEntity);
|
||||||
|
List<DocumentEntity> imageEntities=convertToDocumentEntities(createCallRequest.getImages(),callEntity);
|
||||||
|
List<FaqEntity> faqEntities = convertToFaqEntities(createCallRequest.getFaq(), callEntity, userId);
|
||||||
|
List<LookUpDataResponse> amiedTo=convertLookUpDataEntities(createCallRequest.getAimedTo(),callEntity,LookUpDataTypeEnum.AIMED_TO);
|
||||||
|
List<LookUpDataResponse> checkList=convertLookUpDataEntities(createCallRequest.getAimedTo(),callEntity,LookUpDataTypeEnum.CHECKLIST);
|
||||||
|
createCallResponseBean= assembleCreateCallResponseBean(callEntity, evaluationCriteriaEntities, documentEntities, faqEntities,imageEntities);
|
||||||
|
createCallResponseBean.setAimedTo(amiedTo);
|
||||||
|
createCallResponseBean.setCheckList(checkList);
|
||||||
|
return createCallResponseBean;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Error processing create call request", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CallEntity convertToCallEntity(CreateCallRequest createCallRequest) {
|
||||||
|
CallEntity callEntity = new CallEntity();
|
||||||
|
validateCallEntity(createCallRequest.getRegionId(), createCallRequest.getAmount());
|
||||||
|
RegionEntity region = regionRepository.findById(createCallRequest.getRegionId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND)));
|
||||||
|
callEntity.setRegion(region);
|
||||||
|
callEntity.setName(createCallRequest.getName());
|
||||||
|
callEntity.setDescriptionShort(createCallRequest.getDescriptionShort());
|
||||||
|
callEntity.setDescriptionLong(createCallRequest.getDescriptionLong());
|
||||||
|
callEntity.setStartDate(createCallRequest.getStartDate());
|
||||||
|
callEntity.setEndDate(createCallRequest.getEndDate());
|
||||||
|
callEntity.setStatus(String.valueOf(createCallRequest.getStatus()));
|
||||||
|
callEntity.setAmountMax(createCallRequest.getAmountMax());
|
||||||
|
callEntity.setAmount(createCallRequest.getAmountMax());
|
||||||
|
callEntity.setThreshold(createCallRequest.getThreshold());
|
||||||
|
callEntity.setConfidi(false);
|
||||||
|
if(createCallRequest.getConfidi()!=null){
|
||||||
|
callEntity.setConfidi(createCallRequest.getConfidi());
|
||||||
|
}
|
||||||
|
callEntity.setDocumentation_requested(createCallRequest.getDocumentationRequested());
|
||||||
|
callEntity = callRepository.save(callEntity);
|
||||||
|
return callEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EvaluationCriteriaEntity> convertToEvaluationCriteriaEntities(List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = criteriaReqList.stream().map(req -> convertToEvaluationCriteriaEntity(req, callEntity)).collect(Collectors.toList());
|
||||||
|
evaluationCriteriaRepository.saveAll(evaluationCriteriaEntities);
|
||||||
|
return evaluationCriteriaEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EvaluationCriteriaEntity convertToEvaluationCriteriaEntity(EvaluationCriteriaReq criteriaReq, CallEntity callEntity) {
|
||||||
|
EvaluationCriteriaEntity criteriaEntity = new EvaluationCriteriaEntity();
|
||||||
|
validateEvolutionCrieteriaEntity(criteriaReq.getName());
|
||||||
|
criteriaEntity.setName(criteriaReq.getName());
|
||||||
|
criteriaEntity.setDescription(criteriaReq.getValue());
|
||||||
|
criteriaEntity.setScore(criteriaReq.getScore());
|
||||||
|
criteriaEntity.setCall(callEntity);
|
||||||
|
return criteriaEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<DocumentEntity> convertToDocumentEntities(List<DocumentReq> documentReqList, CallEntity callEntity) {
|
||||||
|
List<DocumentEntity> documentEntities = documentReqList.stream().map(req -> convertToDocumentEntity(req, callEntity)).collect(Collectors.toList());
|
||||||
|
documentRepository.saveAll(documentEntities);
|
||||||
|
return documentEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DocumentEntity convertToDocumentEntity(DocumentReq documentReq, CallEntity callEntity) {
|
||||||
|
DocumentEntity documentEntity = new DocumentEntity();
|
||||||
|
validateDocumentEntity(documentReq.getFileName());
|
||||||
|
documentEntity.setFileName(documentReq.getFileName());
|
||||||
|
documentEntity.setFilePath(documentReq.getUrl());
|
||||||
|
documentEntity.setCall(callEntity);
|
||||||
|
return documentEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<FaqEntity> convertToFaqEntities(List<FaqReq> faqReqList, CallEntity callEntity, Long userId) {
|
||||||
|
List<FaqEntity> faqEntities = faqReqList.stream().map(req -> convertToFaqEntity(req, callEntity, userId)).collect(Collectors.toList());
|
||||||
|
faqRepository.saveAll(faqEntities);
|
||||||
|
return faqEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FaqEntity convertToFaqEntity(FaqReq faqReq, CallEntity callEntity, Long userId) {
|
||||||
|
FaqEntity faqEntity = new FaqEntity();
|
||||||
|
validateFaqEntity(faqReq.getQuestion());
|
||||||
|
UserEntity userEntity= userRepository.findById(userId)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||||
|
faqEntity.setUser(userEntity);
|
||||||
|
faqEntity.setIsVisible(true);
|
||||||
|
if(faqReq.getIsVisible()!=null){
|
||||||
|
faqEntity.setIsVisible(faqReq.getIsVisible());
|
||||||
|
}
|
||||||
|
faqEntity.setQuestionShort(faqReq.getQuestionShort());
|
||||||
|
faqEntity.setQuestion(faqReq.getQuestion());
|
||||||
|
if(faqReq.getResponse()!=null ||faqReq.getResponseShort()!=null){
|
||||||
|
faqEntity.setResponseDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
}
|
||||||
|
faqEntity.setResponseShort(faqReq.getResponseShort());
|
||||||
|
faqEntity.setResponse(faqReq.getResponse());
|
||||||
|
faqEntity.setCall(callEntity);
|
||||||
|
return faqEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateFaqEntity( String question) {
|
||||||
|
if (!StringUtils.hasText(question)) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.QUESTION_NOT_EMPTY_MSG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateDocumentEntity(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateEvolutionCrieteriaEntity(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateCallEntity(Long regionId, BigDecimal fundingAmount) {
|
||||||
|
if (regionId == null) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fundingAmount == null || fundingAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) {
|
||||||
|
CreateCallResponseBean createCallResponseBean = new CreateCallResponseBean();
|
||||||
|
createCallResponseBean.setId(callEntity.getId());
|
||||||
|
createCallResponseBean.setName(callEntity.getName());
|
||||||
|
createCallResponseBean.setDates(List.of(callEntity.getStartDate(), callEntity.getEndDate()));
|
||||||
|
createCallResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
|
||||||
|
createCallResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
|
||||||
|
createCallResponseBean.setStatus(CallTypeEnum.valueOf(callEntity.getStatus()));
|
||||||
|
createCallResponseBean.setRegionId(callEntity.getRegion().getId());
|
||||||
|
createCallResponseBean.setAmount(callEntity.getAmount());
|
||||||
|
createCallResponseBean.setAmountMax(callEntity.getAmountMax());
|
||||||
|
createCallResponseBean.setContactInfo(callEntity.getContactInfo());
|
||||||
|
createCallResponseBean.setSubmissionMethod(callEntity.getSubmissionMethod());
|
||||||
|
createCallResponseBean.setThreshold(callEntity.getThreshold());
|
||||||
|
createCallResponseBean.setDocumentationReqested(callEntity.getDocumentation_requested());
|
||||||
|
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
||||||
|
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||||
|
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||||
|
return createCallResponseBean;
|
||||||
|
}
|
||||||
|
public EvaluationCriteriaResponseBean convertToEvaluationCriteriaResponseBean(EvaluationCriteriaEntity entity) {
|
||||||
|
EvaluationCriteriaResponseBean responseBean = new EvaluationCriteriaResponseBean();
|
||||||
|
responseBean.setId(entity.getId());
|
||||||
|
responseBean.setName(entity.getName());
|
||||||
|
responseBean.setDescription(entity.getDescription());
|
||||||
|
responseBean.setScore(entity.getScore());
|
||||||
|
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
return responseBean;
|
||||||
|
}
|
||||||
|
public DocumentResponseBean convertToDocumentResponseBean(DocumentEntity entity) {
|
||||||
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
|
responseBean.setId(entity.getId());
|
||||||
|
responseBean.setName(entity.getFileName());
|
||||||
|
responseBean.setDescription(entity.getDescription());
|
||||||
|
responseBean.setFilePath(entity.getFilePath());
|
||||||
|
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
return responseBean;
|
||||||
|
}
|
||||||
|
public FaqResponseBean convertToFaqResponseBean(FaqEntity entity) {
|
||||||
|
FaqResponseBean responseBean = new FaqResponseBean();
|
||||||
|
responseBean.setId(entity.getId());
|
||||||
|
responseBean.setQuestionShort(entity.getQuestionShort());
|
||||||
|
responseBean.setResponseShort(entity.getResponseShort());
|
||||||
|
responseBean.setResponse(entity.getResponse());
|
||||||
|
responseBean.setQuestion(entity.getQuestion());
|
||||||
|
responseBean.setUserId(entity.getUser().getId());
|
||||||
|
responseBean.setIsVisible(entity.getIsVisible());
|
||||||
|
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
return responseBean;
|
||||||
|
}
|
||||||
|
public CreateCallResponseBean assembleCreateCallResponseBean(
|
||||||
|
CallEntity callEntity,
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriteriaEntities,
|
||||||
|
List<DocumentEntity> documentEntities,
|
||||||
|
List<FaqEntity> faqEntities,List<DocumentEntity> images) {
|
||||||
|
|
||||||
|
CreateCallResponseBean callResponseBean = convertToCallResponseBean(callEntity);
|
||||||
|
|
||||||
|
List<EvaluationCriteriaResponseBean> evaluationCriteriaResponseBeans = evaluationCriteriaEntities.stream()
|
||||||
|
.map(this::convertToEvaluationCriteriaResponseBean)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = documentEntities.stream()
|
||||||
|
.map(this::convertToDocumentResponseBean)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<FaqResponseBean> faqResponseBeans = faqEntities.stream()
|
||||||
|
.map(this::convertToFaqResponseBean)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<DocumentResponseBean> imagesResponseBean = images.stream()
|
||||||
|
.map(this::convertToDocumentResponseBean)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
CreateCallResponseBean createCallResponseBean =callResponseBean;
|
||||||
|
createCallResponseBean.setCriteria(evaluationCriteriaResponseBeans);
|
||||||
|
createCallResponseBean.setDocs(documentResponseBeans);
|
||||||
|
createCallResponseBean.setFaq(faqResponseBeans);
|
||||||
|
createCallResponseBean.setImages(imagesResponseBean);
|
||||||
|
return createCallResponseBean;
|
||||||
|
}
|
||||||
|
public List<LookUpDataResponse> convertLookUpDataEntities(List<LookUpDataReq> lookUpData, CallEntity callEntity, LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||||
|
List<LookUpDataEntity> lookUpDataEntities = lookUpData.stream()
|
||||||
|
.map(req -> convertLookUpDataRequestIntoLookUpDataEntity(req, type))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
lookUpDataRepository.saveAll(lookUpDataEntities);
|
||||||
|
|
||||||
|
return createCallTargetAudienceCheckList(callEntity, lookUpDataEntities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LookUpDataResponse> createCallTargetAudienceCheckList(CallEntity callEntity, List<LookUpDataEntity> lookUpDataEntities) {
|
||||||
|
List<LookUpDataResponse> lookUpDataResponses=new ArrayList<>();
|
||||||
|
List<CallTargetAudienceChecklistEntity> callTargetAudienceChecklistEntities=new ArrayList<>();
|
||||||
|
for(LookUpDataEntity lookUpDataEntity:lookUpDataEntities){
|
||||||
|
CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity=new CallTargetAudienceChecklistEntity();
|
||||||
|
callTargetAudienceChecklistEntity.setIsValidated(false);
|
||||||
|
callTargetAudienceChecklistEntity.setLookupData(lookUpDataEntity);
|
||||||
|
callTargetAudienceChecklistEntity.setCall(callEntity);
|
||||||
|
callTargetAudienceChecklistEntities.add(callTargetAudienceChecklistEntity);
|
||||||
|
lookUpDataResponses.add(convertToLookUpDataResponseBean(lookUpDataEntity,callTargetAudienceChecklistEntity));
|
||||||
|
}
|
||||||
|
callTargetAudienceChecklistRepository.saveAll(callTargetAudienceChecklistEntities);
|
||||||
|
return lookUpDataResponses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LookUpDataEntity convertLookUpDataRequestIntoLookUpDataEntity(LookUpDataReq req, LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||||
|
if (req.getLookUpDataId() == null || req.getLookUpDataId().equals(BigDecimal.ZERO)) {
|
||||||
|
LookUpDataEntity newEntity = new LookUpDataEntity();
|
||||||
|
newEntity.setValue(req.getValue());
|
||||||
|
newEntity.setType(type.getValue());
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lookUpDataRepository.findById(req.getLookUpDataId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CallTargetAudienceChecklistEntity createChecklistEntity(CallEntity callEntity, LookUpDataEntity lookUpDataEntity) {
|
||||||
|
CallTargetAudienceChecklistEntity checklistEntity = new CallTargetAudienceChecklistEntity();
|
||||||
|
checklistEntity.setCall(callEntity);
|
||||||
|
checklistEntity.setLookupData(lookUpDataEntity);
|
||||||
|
checklistEntity.setIsValidated(false);
|
||||||
|
return checklistEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LookUpDataResponse convertToLookUpDataResponseBean(LookUpDataEntity lookUpDataEntity,CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity) {
|
||||||
|
LookUpDataResponse lookUpDataResponse = new LookUpDataResponse();
|
||||||
|
lookUpDataResponse.setId(callTargetAudienceChecklistEntity.getId());
|
||||||
|
lookUpDataResponse.setLookUpDataId(lookUpDataEntity.getId());
|
||||||
|
lookUpDataResponse.setValue(lookUpDataEntity.getValue());
|
||||||
|
lookUpDataResponse.setTitle(lookUpDataEntity.getTitle());
|
||||||
|
lookUpDataResponse.setCreatedDate(lookUpDataEntity.getCreatedDate());
|
||||||
|
lookUpDataResponse.setUpdatedDate(lookUpDataEntity.getUpdatedDate());
|
||||||
|
return lookUpDataResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DocumentDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Service amazonS3Service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentRepository documentRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallDao callDao;
|
||||||
|
|
||||||
|
@Value("${aws.s3.bucket.name}")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url.folder}")
|
||||||
|
private String s3Folder;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url}")
|
||||||
|
private String s3Url;
|
||||||
|
|
||||||
|
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||||
|
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||||
|
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
try {
|
||||||
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
|
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
|
||||||
|
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||||
|
fileName = (firstNameContain + "." + extension);
|
||||||
|
String filepath = amazonS3Service.upload(fileName,file);
|
||||||
|
DocumentEntity documentEntity = new DocumentEntity();
|
||||||
|
documentEntity.setFileName(fileName);
|
||||||
|
documentEntity.setType(fileType.getValue());
|
||||||
|
documentEntity.setFilePath(filepath);
|
||||||
|
documentEntities.add(documentEntity);
|
||||||
|
} catch (IOException e) {}
|
||||||
|
}
|
||||||
|
documentRepository.saveAll(documentEntities);
|
||||||
|
return documentEntities.stream()
|
||||||
|
.map(callDao::convertToDocumentResponseBean)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
public Void deleteFile(Long documentId){
|
||||||
|
DocumentEntity documentEntity= documentRepository.findById(documentId);
|
||||||
|
if(documentEntity==null){
|
||||||
|
new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||||
|
}
|
||||||
|
String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||||
|
try {
|
||||||
|
amazonS3Service.delete(bucketName, fileName);
|
||||||
|
documentRepository.delete(documentEntity);
|
||||||
|
}catch (Exception e){}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
127
src/main/java/net/gepafin/tendermanagement/dao/RegionDao.java
Normal file
127
src/main/java/net/gepafin/tendermanagement/dao/RegionDao.java
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.RegionRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.util.ObjectUtils.setIfUpdated;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class RegionDao {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(RegionDao.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionRepository regionRepository;
|
||||||
|
|
||||||
|
public RegionResponseBean createRegion(RegionReq regionReq) {
|
||||||
|
log.info("Creating new region with details: {}", regionReq);
|
||||||
|
RegionEntity regionEntity = convertRegionRequestToRegionEntity(regionReq);
|
||||||
|
regionEntity = regionRepository.save(regionEntity);
|
||||||
|
log.info("Region created with ID: {}", regionEntity.getId());
|
||||||
|
return convertRegionEntityToRegionResponse(regionEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RegionEntity convertRegionRequestToRegionEntity(RegionReq regionReq) {
|
||||||
|
RegionEntity regionEntity = new RegionEntity();
|
||||||
|
regionEntity.setCountry(regionReq.getCountry());
|
||||||
|
regionEntity.setDescription(regionReq.getDescription());
|
||||||
|
regionEntity.setGdp(regionReq.getGdp());
|
||||||
|
regionEntity.setRegionName(regionReq.getRegionName());
|
||||||
|
regionEntity.setAreaSize(regionReq.getAreaSize());
|
||||||
|
regionEntity.setPopulation(regionReq.getPopulation());
|
||||||
|
regionEntity.setEnvironmentalScore(regionReq.getEnvironmentalScore());
|
||||||
|
regionEntity.setStatus(regionReq.getStatus());
|
||||||
|
regionEntity.setHealthcareAccess(regionReq.getHealthcareAccess());
|
||||||
|
regionEntity.setInfrastructureScore(regionReq.getInfrastructureScore());
|
||||||
|
regionEntity.setPriorityArea(regionReq.getPriorityArea());
|
||||||
|
regionEntity.setUnemploymentRate(regionReq.getUnemploymentRate());
|
||||||
|
regionEntity.setEducationLevel(regionReq.getEducationLevel());
|
||||||
|
return regionEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionResponseBean convertRegionEntityToRegionResponse(RegionEntity regionEntity) {
|
||||||
|
RegionResponseBean regionResponseBean = new RegionResponseBean();
|
||||||
|
regionResponseBean.setId(regionEntity.getId());
|
||||||
|
regionResponseBean.setCreatedDate(regionEntity.getCreatedDate());
|
||||||
|
regionResponseBean.setUpdatedDate(regionEntity.getUpdatedDate());
|
||||||
|
regionResponseBean.setCountry(regionEntity.getCountry());
|
||||||
|
regionResponseBean.setDescription(regionEntity.getDescription());
|
||||||
|
regionResponseBean.setGdp(regionEntity.getGdp());
|
||||||
|
regionResponseBean.setRegionName(regionEntity.getRegionName());
|
||||||
|
regionResponseBean.setAreaSize(regionEntity.getAreaSize());
|
||||||
|
regionResponseBean.setPopulation(regionEntity.getPopulation());
|
||||||
|
regionResponseBean.setEnvironmentalScore(regionEntity.getEnvironmentalScore());
|
||||||
|
regionResponseBean.setStatus(regionEntity.getStatus());
|
||||||
|
regionResponseBean.setHealthcareAccess(regionEntity.getHealthcareAccess());
|
||||||
|
regionResponseBean.setInfrastructureScore(regionEntity.getInfrastructureScore());
|
||||||
|
regionResponseBean.setPriorityArea(regionEntity.getPriorityArea());
|
||||||
|
regionResponseBean.setUnemploymentRate(regionEntity.getUnemploymentRate());
|
||||||
|
regionResponseBean.setEducationLevel(regionEntity.getEducationLevel());
|
||||||
|
return regionResponseBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionResponseBean updateRegion(Long id, RegionReq regionReq) {
|
||||||
|
log.info("Updating region with ID: {}", id);
|
||||||
|
RegionEntity existingRegion = getRegionById(id);
|
||||||
|
log.info("Current region details: {}", existingRegion);
|
||||||
|
log.info("New region details: {}", regionReq);
|
||||||
|
|
||||||
|
setIfUpdated(existingRegion::getRegionName, existingRegion::setRegionName, regionReq.getRegionName());
|
||||||
|
setIfUpdated(existingRegion::getDescription, existingRegion::setDescription, regionReq.getDescription());
|
||||||
|
setIfUpdated(existingRegion::getCountry, existingRegion::setCountry, regionReq.getCountry());
|
||||||
|
setIfUpdated(existingRegion::getStatus, existingRegion::setStatus, regionReq.getStatus());
|
||||||
|
setIfUpdated(existingRegion::getPriorityArea, existingRegion::setPriorityArea, regionReq.getPriorityArea());
|
||||||
|
setIfUpdated(existingRegion::getPopulation, existingRegion::setPopulation, regionReq.getPopulation());
|
||||||
|
setIfUpdated(existingRegion::getAreaSize, existingRegion::setAreaSize, regionReq.getAreaSize());
|
||||||
|
setIfUpdated(existingRegion::getGdp, existingRegion::setGdp, regionReq.getGdp());
|
||||||
|
setIfUpdated(existingRegion::getUnemploymentRate, existingRegion::setUnemploymentRate, regionReq.getUnemploymentRate());
|
||||||
|
setIfUpdated(existingRegion::getInfrastructureScore, existingRegion::setInfrastructureScore, regionReq.getInfrastructureScore());
|
||||||
|
setIfUpdated(existingRegion::getEducationLevel, existingRegion::setEducationLevel, regionReq.getEducationLevel());
|
||||||
|
setIfUpdated(existingRegion::getHealthcareAccess, existingRegion::setHealthcareAccess, regionReq.getHealthcareAccess());
|
||||||
|
setIfUpdated(existingRegion::getEnvironmentalScore, existingRegion::setEnvironmentalScore, regionReq.getEnvironmentalScore());
|
||||||
|
|
||||||
|
existingRegion = regionRepository.save(existingRegion);
|
||||||
|
|
||||||
|
log.info("Region updated with ID: {}", existingRegion.getId());
|
||||||
|
return Utils.convertObject(existingRegion, RegionResponseBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionEntity getRegionById(Long id) {
|
||||||
|
log.info("Fetching region with ID: {}", id);
|
||||||
|
RegionEntity regionEntity = regionRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
||||||
|
log.info("Region found: {}", regionEntity);
|
||||||
|
return regionEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(Long id) {
|
||||||
|
log.info("Deleting region with ID: {}", id);
|
||||||
|
regionRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
||||||
|
regionRepository.deleteById(id);
|
||||||
|
log.info("Region deleted with ID: {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RegionResponseBean> getAllRegions() {
|
||||||
|
log.info("Fetching all regions");
|
||||||
|
List<RegionResponseBean> regions = regionRepository.findAll()
|
||||||
|
.stream()
|
||||||
|
.map(regionEntity -> Utils.convertObject(regionEntity, RegionResponseBean.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.info("Total regions found: {}", regions.size());
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
}
|
||||||
110
src/main/java/net/gepafin/tendermanagement/dao/RoleDao.java
Normal file
110
src/main/java/net/gepafin/tendermanagement/dao/RoleDao.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.RoleRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.RegionService;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.util.ObjectUtils.setIfUpdated;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RoleDao {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(RoleDao.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionService regionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionDao regionDao;
|
||||||
|
|
||||||
|
public RoleResponseBean createRole(RoleReq roleReq) {
|
||||||
|
log.info("Creating new role with details: {}", roleReq);
|
||||||
|
RoleEntity roleEntity = convertRoleRequestToRoleEntity(roleReq);
|
||||||
|
roleEntity = roleRepository.save(roleEntity);
|
||||||
|
log.info("Role created with ID: {}", roleEntity.getId());
|
||||||
|
return convertRoleEntityToRoleResponse(roleEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RoleEntity convertRoleRequestToRoleEntity(RoleReq roleReq) {
|
||||||
|
RoleEntity roleEntity = new RoleEntity();
|
||||||
|
roleEntity.setRoleName(roleReq.getRoleName());
|
||||||
|
roleEntity.setPermissions(roleReq.getPermissions());
|
||||||
|
roleEntity.setDescription(roleReq.getDescription());
|
||||||
|
roleEntity.setRegion(regionService.getRegionById(roleReq.getRegionId()));
|
||||||
|
return roleEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleResponseBean convertRoleEntityToRoleResponse(RoleEntity roleEntity) {
|
||||||
|
RoleResponseBean roleResponseBean = new RoleResponseBean();
|
||||||
|
roleResponseBean.setId(roleEntity.getId());
|
||||||
|
roleResponseBean.setCreatedDate(roleEntity.getCreatedDate());
|
||||||
|
roleResponseBean.setUpdatedDate(roleEntity.getUpdatedDate());
|
||||||
|
roleResponseBean.setRoleName(roleEntity.getRoleName());
|
||||||
|
roleResponseBean.setDescription(roleEntity.getDescription());
|
||||||
|
roleResponseBean.setPermissions(roleEntity.getPermissions());
|
||||||
|
RegionResponseBean regionResponseBean = regionDao.convertRegionEntityToRegionResponse(roleEntity.getRegion());
|
||||||
|
roleResponseBean.setRegion(regionResponseBean);
|
||||||
|
return roleResponseBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleResponseBean updateRole(Long id, RoleReq roleReq) {
|
||||||
|
log.info("Updating role with ID: {}", id);
|
||||||
|
RoleEntity existingRole = getRoleById(id);
|
||||||
|
|
||||||
|
// Log changes before update
|
||||||
|
log.info("Current role details: {}", existingRole);
|
||||||
|
log.info("New role details: {}", roleReq);
|
||||||
|
|
||||||
|
setIfUpdated(existingRole::getRoleName, existingRole::setRoleName, roleReq.getRoleName());
|
||||||
|
setIfUpdated(existingRole::getDescription, existingRole::setDescription, roleReq.getDescription());
|
||||||
|
setIfUpdated(existingRole::getPermissions, existingRole::setPermissions, roleReq.getPermissions());
|
||||||
|
|
||||||
|
existingRole = roleRepository.save(existingRole);
|
||||||
|
|
||||||
|
log.info("Role updated with ID: {}", existingRole.getId());
|
||||||
|
return Utils.convertObject(existingRole, RoleResponseBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleEntity getRoleById(Long id) {
|
||||||
|
log.info("Fetching role with ID: {}", id);
|
||||||
|
RoleEntity roleEntity = roleRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
|
||||||
|
log.info("Role found: {}", roleEntity);
|
||||||
|
return roleEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(Long id) {
|
||||||
|
log.info("Deleting role with ID: {}", id);
|
||||||
|
roleRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
|
||||||
|
roleRepository.deleteById(id);
|
||||||
|
log.info("Role deleted with ID: {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RoleResponseBean> getAllRoles() {
|
||||||
|
log.info("Fetching all roles");
|
||||||
|
List<RoleResponseBean> roles = roleRepository.findAll()
|
||||||
|
.stream()
|
||||||
|
.map(roleEntity -> Utils.convertObject(roleEntity, RoleResponseBean.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.info("Total roles found: {}", roles.size());
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
}
|
||||||
145
src/main/java/net/gepafin/tendermanagement/dao/UserDao.java
Normal file
145
src/main/java/net/gepafin/tendermanagement/dao/UserDao.java
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.RoleService;
|
||||||
|
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.util.ObjectUtils.setIfUpdated;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class UserDao {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(UserDao.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthenticationService authService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleService roleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleDao roleDao;
|
||||||
|
|
||||||
|
public UserResponseBean createUser(UserReq userReq) {
|
||||||
|
log.info("Creating user with email: {}", userReq.getEmail());
|
||||||
|
if (userRepository.existsByEmail(userReq.getEmail())) {
|
||||||
|
log.error("User creation failed: Email {} already exists", userReq.getEmail());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||||
|
}
|
||||||
|
if (!userReq.getPassword().equals(userReq.getConfPassword())) {
|
||||||
|
log.error("User creation failed: Passwords do not match for email {}", userReq.getEmail());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
||||||
|
}
|
||||||
|
if (userReq.getPassword().length() < 8) {
|
||||||
|
log.error("User creation failed: Password length is less than 8 characters for email {}", userReq.getEmail());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_MIN_LEN));
|
||||||
|
}
|
||||||
|
UserEntity userEntity = convertUserRequestToUserEntity(userReq);
|
||||||
|
userEntity = userRepository.save(userEntity);
|
||||||
|
log.info("User created with ID: {}", userEntity.getId());
|
||||||
|
return convertUserEntityToUserResponse(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||||
|
log.info("Updating user with ID: {}", userId);
|
||||||
|
UserEntity userEntity = userRepository.findById(userId)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
||||||
|
log.info("Current user details: {}", userEntity);
|
||||||
|
log.info("New user details: {}", userReq);
|
||||||
|
|
||||||
|
setIfUpdated(userEntity::getStatus, userEntity::setStatus, userReq.getStatus());
|
||||||
|
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
|
||||||
|
setIfUpdated(userEntity::getLastName, userEntity::setLastName, userReq.getLastName());
|
||||||
|
setIfUpdated(userEntity::getOrganization, userEntity::setOrganization, userReq.getOrganization());
|
||||||
|
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
|
||||||
|
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
|
||||||
|
if (userReq.getRoleId() != null) {
|
||||||
|
RoleEntity roleEntity = roleService.getRoleById(userReq.getRoleId());
|
||||||
|
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
||||||
|
}
|
||||||
|
userEntity = userRepository.save(userEntity);
|
||||||
|
log.info("User updated with ID: {}", userEntity.getId());
|
||||||
|
return convertUserEntityToUserResponse(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserEntity convertUserRequestToUserEntity(UserReq userReq) {
|
||||||
|
UserEntity userEntity = new UserEntity();
|
||||||
|
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
|
||||||
|
userEntity.setEmail(userReq.getEmail());
|
||||||
|
userEntity.setFirstName(userReq.getFirstName());
|
||||||
|
userEntity.setStatus(userReq.getStatus());
|
||||||
|
userEntity.setLastName(userReq.getLastName());
|
||||||
|
userEntity.setOrganization(userReq.getOrganization());
|
||||||
|
userEntity.setAddress(userReq.getAddress());
|
||||||
|
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||||
|
userEntity.setRoleEntity(roleService.getRoleById(userReq.getRoleId()));
|
||||||
|
return userEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserResponseBean convertUserEntityToUserResponse(UserEntity userEntity) {
|
||||||
|
UserResponseBean userResponseBean = new UserResponseBean();
|
||||||
|
userResponseBean.setId(userEntity.getId());
|
||||||
|
userResponseBean.setCreatedDate(userEntity.getCreatedDate());
|
||||||
|
userResponseBean.setUpdatedDate(userEntity.getUpdatedDate());
|
||||||
|
userResponseBean.setEmail(userEntity.getEmail());
|
||||||
|
userResponseBean.setFirstName(userEntity.getFirstName());
|
||||||
|
userResponseBean.setLastName(userEntity.getLastName());
|
||||||
|
userResponseBean.setPhoneNumber(userEntity.getPhoneNumber());
|
||||||
|
userResponseBean.setOrganization(userEntity.getOrganization());
|
||||||
|
userResponseBean.setAddress(userEntity.getAddress());
|
||||||
|
userResponseBean.setCity(userEntity.getCity());
|
||||||
|
userResponseBean.setCountry(userEntity.getCountry());
|
||||||
|
userResponseBean.setStatus(userEntity.getStatus());
|
||||||
|
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(userEntity.getRoleEntity());
|
||||||
|
userResponseBean.setRole(roleResponseBean);
|
||||||
|
userResponseBean.setLastLogin(userEntity.getLastLogin());
|
||||||
|
return userResponseBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserResponseBean getUserById(Long id) {
|
||||||
|
log.info("Fetching user with ID: {}", id);
|
||||||
|
UserEntity userEntity = userRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
|
log.info("User found: {}", userEntity);
|
||||||
|
return convertUserEntityToUserResponse(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUser(Long id) {
|
||||||
|
log.info("Deleting user with ID: {}", id);
|
||||||
|
userRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
|
userRepository.deleteById(id);
|
||||||
|
log.info("User deleted with ID: {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JWTToken login(LoginReq loginReq) {
|
||||||
|
log.info("User login attempt for email: {}", loginReq.getEmail());
|
||||||
|
JWTToken jwtToken = authService.login(loginReq);
|
||||||
|
log.info("Login successful for email: {}", loginReq.getEmail());
|
||||||
|
return jwtToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
@Data
|
||||||
|
public class BaseEntity {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "ID", unique = true)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
|
@Column(name = "CREATED_DATE", updatable = false)
|
||||||
|
LocalDateTime createdDate;
|
||||||
|
|
||||||
|
@Column(name = "UPDATED_DATE")
|
||||||
|
LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void setCreatedDate() {
|
||||||
|
this.createdDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
this.updatedDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
@PreUpdate
|
||||||
|
public void setUpdatedDate() {
|
||||||
|
this.updatedDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "CALL")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class CallEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "NAME", nullable = false, length = 255)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION_SHORT", columnDefinition = "TEXT")
|
||||||
|
private String descriptionShort;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION_LONG", columnDefinition = "TEXT")
|
||||||
|
private String descriptionLong;
|
||||||
|
|
||||||
|
@Column(name = "START_DATE", nullable = false)
|
||||||
|
private LocalDateTime startDate;
|
||||||
|
|
||||||
|
@Column(name = "END_DATE", nullable = false)
|
||||||
|
private LocalDateTime endDate;
|
||||||
|
|
||||||
|
@Column(name = "STATUS", nullable = false, length = 255)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "REGION_ID", nullable = false, foreignKey = @ForeignKey(name = "fk_region_call"))
|
||||||
|
private RegionEntity region;
|
||||||
|
|
||||||
|
@Column(name = "AMOUNT", nullable = false)
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
@Column(name = "AMOUNT_MAX", nullable = false)
|
||||||
|
private BigDecimal amountMax;
|
||||||
|
|
||||||
|
@Column(name = "CONTACT_INFO", columnDefinition = "TEXT")
|
||||||
|
private String contactInfo;
|
||||||
|
|
||||||
|
@Column(name = "SUBMISSION_METHOD", columnDefinition = "TEXT")
|
||||||
|
private String submissionMethod;
|
||||||
|
|
||||||
|
@Column(name = "THRESHOLD", nullable = false)
|
||||||
|
private Integer threshold;
|
||||||
|
|
||||||
|
@Column(name="DOCUMENTATION_REQUESTED",columnDefinition = "TEXT")
|
||||||
|
private String documentation_requested;
|
||||||
|
|
||||||
|
@Column(name = "PRIORITY_AREA", columnDefinition = "TEXT")
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
@Column(name = "CONFIDI")
|
||||||
|
private Boolean confidi;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "CALL_TARGET_AUDIENCE_CHECKLIST")
|
||||||
|
@Data
|
||||||
|
public class CallTargetAudienceChecklistEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "CALL_ID")
|
||||||
|
private CallEntity call;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "LOOKUP_DATA_ID")
|
||||||
|
private LookUpDataEntity lookupData;
|
||||||
|
|
||||||
|
@Column(name = "IS_VALIDATED")
|
||||||
|
private Boolean isValidated;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "DOCUMENT")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class DocumentEntity extends BaseEntity{
|
||||||
|
@Column(name = "FILE_NAME", length = 255)
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "FILE_PATH", length = 255)
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(name="TYPE")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "CALL_ID")
|
||||||
|
private CallEntity call;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION", columnDefinition = "TEXT")
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "EVALUATION_CRITERIA")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class EvaluationCriteriaEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "CALL_ID", nullable = false)
|
||||||
|
private CallEntity call;
|
||||||
|
|
||||||
|
@Column(name = "NAME", nullable = false, columnDefinition = "TEXT")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION", columnDefinition = "TEXT")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "SCORE", nullable = false)
|
||||||
|
private Integer score;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "FAQ")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FaqEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "CALL_ID", nullable = false)
|
||||||
|
private CallEntity call;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_ID", nullable = false, foreignKey = @ForeignKey(name = "fk_user_faq"))
|
||||||
|
private UserEntity user;
|
||||||
|
|
||||||
|
@Column(name = "IS_VISIBLE", nullable = false)
|
||||||
|
private Boolean isVisible;
|
||||||
|
|
||||||
|
@Column(name = "QUESTION_SHORT", length = 255)
|
||||||
|
private String questionShort;
|
||||||
|
|
||||||
|
@Column(name = "QUESTION", columnDefinition = "TEXT")
|
||||||
|
private String question;
|
||||||
|
|
||||||
|
@Column(name = "RESPONSE_SHORT", length = 255)
|
||||||
|
private String responseShort;
|
||||||
|
|
||||||
|
@Column(name = "RESPONSE", columnDefinition = "TEXT")
|
||||||
|
private String response;
|
||||||
|
|
||||||
|
@Column(name = "RESPONSE_DATE")
|
||||||
|
private LocalDateTime responseDate;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "LOOKUP_DATA")
|
||||||
|
@Data
|
||||||
|
public class LookUpDataEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Column(name = "TITLE", length = 255, nullable = true)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name = "TYPE", length = 255, nullable = false)
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Column(name = "VALUE", columnDefinition = "TEXT", nullable = true)
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public enum LookUpDataTypeEnum {
|
||||||
|
CHECKLIST("CHECKLIST"),
|
||||||
|
AIMED_TO("AIMED_TO"),
|
||||||
|
EVALUATION_CRITERIA("EVALUATION_CRITERIA");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
LookUpDataTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "REGION")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class RegionEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "REGION_NAME", length = 255, nullable = true)
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION", length = 255, nullable = true)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "COUNTRY", length = 50, nullable = true)
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@Column(name = "STATUS", length = 30, nullable = true)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@Column(name = "PRIORITY_AREA", length = 255, nullable = true)
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
@Column(name = "POPULATION", nullable = true)
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
@Column(name = "AREA_SIZE", nullable = true)
|
||||||
|
private BigDecimal areaSize;
|
||||||
|
|
||||||
|
@Column(name = "GDP", nullable = true)
|
||||||
|
private BigDecimal gdp;
|
||||||
|
|
||||||
|
@Column(name = "UNEMPLOYMENT_RATE", nullable = true)
|
||||||
|
private BigDecimal unemploymentRate;
|
||||||
|
|
||||||
|
@Column(name = "INFRASTRUCTURE_SCORE", nullable = true)
|
||||||
|
private BigDecimal infrastructureScore;
|
||||||
|
|
||||||
|
@Column(name = "EDUCATION_LEVEL", nullable = true)
|
||||||
|
private BigDecimal educationLevel;
|
||||||
|
|
||||||
|
@Column(name = "HEALTHCARE_ACCESS", nullable = true)
|
||||||
|
private BigDecimal healthcareAccess;
|
||||||
|
|
||||||
|
@Column(name = "ENVIRONMENTAL_SCORE", nullable = true)
|
||||||
|
private BigDecimal environmentalScore;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "ROLE")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class RoleEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "ROLE_NAME", length = 50, nullable = true)
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@Column(name = "DESCRIPTION", length = 255, nullable = true)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "PERMISSIONS", length = 255, nullable = true)
|
||||||
|
private String permissions;
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "REGION_ID", nullable = true)
|
||||||
|
private RegionEntity region;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "GEPAFIN_USER")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "PASSWORD", columnDefinition = "TEXT",nullable = false)
|
||||||
|
@JsonIgnore
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Email
|
||||||
|
@Column(name = "EMAIL", length = 255, unique = true, nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "ROLE_ID")
|
||||||
|
@JsonIgnore
|
||||||
|
private RoleEntity roleEntity;
|
||||||
|
|
||||||
|
|
||||||
|
@Column(name = "LAST_LOGIN")
|
||||||
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
|
@Column(name = "STATUS", length = 30, nullable = true)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@Column(name = "FIRST_NAME", length = 50, nullable = true)
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "LAST_NAME", length = 50, nullable = true)
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@Column(name = "PHONE_NUMBER", length = 15, nullable = true)
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@Column(name = "ORGANIZATION", length = 255, nullable = true)
|
||||||
|
private String organization;
|
||||||
|
|
||||||
|
@Column(name = "ADDRESS", length = 255, nullable = true)
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Column(name = "CITY", length = 50, nullable = true)
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@Column(name = "COUNTRY", length = 50, nullable = true)
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
public enum UserStatusEnum {
|
||||||
|
ACTIVE("ACTIVE"),
|
||||||
|
INACTIVE("INACTIVE");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
UserStatusEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum CallTypeEnum {
|
||||||
|
|
||||||
|
DRAFT("DRAFT"),
|
||||||
|
PUBLISH("PUBLISH"),
|
||||||
|
EXPIRE("EXPIRE");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
CallTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum DocumentTypeEnum {
|
||||||
|
|
||||||
|
DOCUMENT("DOCUMENT"),
|
||||||
|
IMAGES("IMAGES");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
DocumentTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.model;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BaseBean {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package net.gepafin.tendermanagement.model;
|
|
||||||
|
|
||||||
public class User {
|
|
||||||
private Long id;
|
|
||||||
private String name;
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public User() {}
|
|
||||||
|
|
||||||
public User(Long id, String name, String email) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.CallTypeEnum;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateCallRequest {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String descriptionShort;
|
||||||
|
|
||||||
|
private String descriptionLong;
|
||||||
|
|
||||||
|
private LocalDateTime startDate;
|
||||||
|
|
||||||
|
private LocalDateTime endDate;
|
||||||
|
|
||||||
|
private Long regionId;
|
||||||
|
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
private BigDecimal amountMax;
|
||||||
|
|
||||||
|
private List<LookUpDataReq> aimedTo;
|
||||||
|
|
||||||
|
private String documentationRequested;
|
||||||
|
|
||||||
|
private Integer threshold;
|
||||||
|
|
||||||
|
private Boolean Confidi;
|
||||||
|
|
||||||
|
List<EvaluationCriteriaReq> criteria;
|
||||||
|
|
||||||
|
private List<FaqReq> faq;
|
||||||
|
|
||||||
|
private List<LookUpDataReq> checkList;
|
||||||
|
|
||||||
|
private List<DocumentReq> docs;
|
||||||
|
|
||||||
|
private List<DocumentReq> images;
|
||||||
|
|
||||||
|
private CallTypeEnum status;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DocumentReq {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String url;
|
||||||
|
private String fileName;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EvaluationCriteriaReq {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private Integer score;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FaqReq {
|
||||||
|
|
||||||
|
private Boolean isVisible;
|
||||||
|
private String questionShort;
|
||||||
|
private String question;
|
||||||
|
private String responseShort;
|
||||||
|
private String response;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class LoginReq {
|
||||||
|
@NotBlank(message = "{email.not.blank}")
|
||||||
|
@Email(message = "{email.invalid}")
|
||||||
|
private String email;
|
||||||
|
@NotEmpty
|
||||||
|
private String password;
|
||||||
|
private Boolean rememberMe;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LookUpDataReq {
|
||||||
|
|
||||||
|
private Long lookUpDataId;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class RegionReq {
|
||||||
|
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
private BigDecimal areaSize;
|
||||||
|
|
||||||
|
private BigDecimal gdp;
|
||||||
|
|
||||||
|
private BigDecimal unemploymentRate;
|
||||||
|
|
||||||
|
private BigDecimal infrastructureScore;
|
||||||
|
|
||||||
|
private BigDecimal educationLevel;
|
||||||
|
|
||||||
|
private BigDecimal healthcareAccess;
|
||||||
|
|
||||||
|
private BigDecimal environmentalScore;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class RoleReq {
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String permissions;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private Long regionId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UpdateRegionReq {
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
private Double areaSize;
|
||||||
|
|
||||||
|
private Double gdp;
|
||||||
|
|
||||||
|
private Double unemploymentRate;
|
||||||
|
|
||||||
|
private Double infrastructureScore;
|
||||||
|
|
||||||
|
private Double educationLevel;
|
||||||
|
|
||||||
|
private Double healthcareAccess;
|
||||||
|
|
||||||
|
private Double environmentalScore;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UpdateUserReq {
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String phoneNumber;
|
||||||
|
private Long roleId;
|
||||||
|
private String organization;
|
||||||
|
private String address;
|
||||||
|
private String city;
|
||||||
|
private String status;
|
||||||
|
private String country;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserReq {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Email
|
||||||
|
private String email;
|
||||||
|
@NotEmpty
|
||||||
|
private String password;
|
||||||
|
@NotEmpty
|
||||||
|
private String confPassword;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
private String organization;
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CallResponseBean {
|
||||||
|
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private LocalDateTime startDate;
|
||||||
|
|
||||||
|
private LocalDateTime endDate;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private RegionResponseBean region;
|
||||||
|
|
||||||
|
private BigDecimal fundingAmount;
|
||||||
|
|
||||||
|
private String contactInfo;
|
||||||
|
|
||||||
|
private String submissionMethod;
|
||||||
|
|
||||||
|
private Integer totalScore;
|
||||||
|
|
||||||
|
private Integer minimumScore;
|
||||||
|
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.CallTypeEnum;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateCallResponseBean {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String descriptionShort;
|
||||||
|
|
||||||
|
private String descriptionLong;
|
||||||
|
|
||||||
|
private List<LocalDateTime> dates;
|
||||||
|
|
||||||
|
private CallTypeEnum status;
|
||||||
|
|
||||||
|
private Long regionId;
|
||||||
|
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
private BigDecimal amountMax;
|
||||||
|
|
||||||
|
private String contactInfo;
|
||||||
|
|
||||||
|
private String submissionMethod;
|
||||||
|
|
||||||
|
private Integer threshold;
|
||||||
|
|
||||||
|
private String priorityArea;
|
||||||
|
|
||||||
|
private String documentationReqested;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
private List<LookUpDataResponse> aimedTo;
|
||||||
|
|
||||||
|
private List<EvaluationCriteriaResponseBean> criteria;
|
||||||
|
|
||||||
|
private List<DocumentResponseBean> docs;
|
||||||
|
|
||||||
|
private List<FaqResponseBean> faq;
|
||||||
|
|
||||||
|
private List<DocumentResponseBean> images;
|
||||||
|
|
||||||
|
private List<LookUpDataResponse> checkList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DocumentResponseBean {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EvaluationCriteriaResponseBean {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private Integer score;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FaqResponseBean {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private Boolean isVisible;
|
||||||
|
|
||||||
|
private String questionShort;
|
||||||
|
|
||||||
|
private String question;
|
||||||
|
|
||||||
|
private String responseShort;
|
||||||
|
|
||||||
|
private String response;
|
||||||
|
|
||||||
|
private LocalDateTime responseDate;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LoginResponse {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private RoleResponseBean role;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private String organization;
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LookUpDataResponse {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long lookUpDataId;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class RegionResponseBean extends BaseBean {
|
||||||
|
private String regionName;
|
||||||
|
private String description;
|
||||||
|
private String country;
|
||||||
|
private String status;
|
||||||
|
private String priorityArea;
|
||||||
|
private Long population;
|
||||||
|
private BigDecimal areaSize;
|
||||||
|
private BigDecimal gdp;
|
||||||
|
private BigDecimal unemploymentRate;
|
||||||
|
private BigDecimal infrastructureScore;
|
||||||
|
private BigDecimal educationLevel;
|
||||||
|
private BigDecimal healthcareAccess;
|
||||||
|
private BigDecimal environmentalScore;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RoleResponseBean extends BaseBean {
|
||||||
|
private String roleName;
|
||||||
|
private String description;
|
||||||
|
private String permissions;
|
||||||
|
private RegionResponseBean region;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserResponseBean extends BaseBean {
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private RoleResponseBean role;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private String organization;
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.model.response.LoginResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWTToken
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class JWTToken {
|
||||||
|
@JsonProperty("token")
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
@JsonProperty("user")
|
||||||
|
private LoginResponse loginResponse;
|
||||||
|
public JWTToken(String token, LoginResponse loginResponse) {
|
||||||
|
this.token = token;
|
||||||
|
this.loginResponse = loginResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic response class used for API responses.
|
||||||
|
*
|
||||||
|
* @param <T> the type of the response data
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Response<T> implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private T data; // The response data
|
||||||
|
private Status status; // The status of the response
|
||||||
|
private String message; // Additional message or error description
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface CallRepository extends JpaRepository<CallEntity, Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.CallTargetAudienceChecklistEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface CallTargetAudienceChecklistRepository extends JpaRepository<CallTargetAudienceChecklistEntity,Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface DocumentRepository extends JpaRepository<DocumentEntity, Integer> {
|
||||||
|
|
||||||
|
DocumentEntity findById(Long id);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.EvaluationCriteriaEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface EvaluationCriteriaRepository extends JpaRepository<EvaluationCriteriaEntity, Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.FaqEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface FaqRepository extends JpaRepository<FaqEntity, Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.LookUpDataEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface LookUpDataRepository extends JpaRepository<LookUpDataEntity,Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RegionRepository extends JpaRepository<RegionEntity, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RoleRepository extends JpaRepository<RoleEntity, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||||
|
UserEntity findByEmail(String email);
|
||||||
|
boolean existsByEmail(String email);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface AmazonS3Service {
|
||||||
|
|
||||||
|
|
||||||
|
public String upload(String fileName,
|
||||||
|
MultipartFile file) throws IOException;
|
||||||
|
|
||||||
|
public Boolean delete(String bucketName ,String fileName);
|
||||||
|
|
||||||
|
InputStream getFile(String filePath) throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CreateCallRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CreateCallResponseBean;
|
||||||
|
|
||||||
|
public interface CallService {
|
||||||
|
|
||||||
|
CreateCallResponseBean createCall(HttpServletRequest request, CreateCallRequest createCallRequest);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DocumentService {
|
||||||
|
|
||||||
|
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files, DocumentTypeEnum fileType);
|
||||||
|
|
||||||
|
public Void deleteFile(Long documentId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface RegionService {
|
||||||
|
|
||||||
|
RegionResponseBean createRegion(RegionReq regionReq);
|
||||||
|
|
||||||
|
RegionResponseBean updateRegion(Long regionId, RegionReq regionReq);
|
||||||
|
|
||||||
|
RegionEntity getRegionById(Long regionId);
|
||||||
|
|
||||||
|
void deleteRegion(Long regionId);
|
||||||
|
|
||||||
|
List<RegionResponseBean> getAllRegions();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface RoleService {
|
||||||
|
RoleResponseBean createRole(RoleReq roleReq);
|
||||||
|
|
||||||
|
RoleResponseBean updateRole(Long roleId, RoleReq roleReq);
|
||||||
|
|
||||||
|
RoleEntity getRoleById(Long roleId);
|
||||||
|
|
||||||
|
void deleteRole(Long roleId);
|
||||||
|
|
||||||
|
List<RoleResponseBean> getAllRoles();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.gepafin.tendermanagement.service;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
UserResponseBean createUser(UserReq userReq);
|
||||||
|
|
||||||
|
UserResponseBean updateUser(Long userId, UpdateUserReq userReq);
|
||||||
|
|
||||||
|
UserResponseBean getUserById(Long userId);
|
||||||
|
|
||||||
|
void deleteUser(Long userId);
|
||||||
|
|
||||||
|
JWTToken login(LoginReq loginReq);
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
|
import com.amazonaws.services.s3.model.*;
|
||||||
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AmazonS3ServiceImpl implements AmazonS3Service {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3 amazonS3;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Value("${aws.s3.bucket.name}")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url.folder}")
|
||||||
|
private String s3Folder;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url}")
|
||||||
|
private String s3Url;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String upload(String fileName,
|
||||||
|
MultipartFile file) throws IOException {
|
||||||
|
|
||||||
|
String path = bucketName+"/"+s3Folder;
|
||||||
|
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
|
||||||
|
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||||
|
Map<String, String> metadata = new HashMap<>();
|
||||||
|
metadata.put("Content-Type", file.getContentType());
|
||||||
|
metadata.put("Content-Length", String.valueOf(file.getSize()));
|
||||||
|
|
||||||
|
Optional<Map<String, String>> optionalMetaData = Optional.of(metadata);
|
||||||
|
optionalMetaData.ifPresent(map -> {
|
||||||
|
if (!map.isEmpty()) {
|
||||||
|
map.forEach(objectMetadata::addUserMetadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(Boolean.FALSE.equals(isTestProfileActivated())) {
|
||||||
|
amazonS3.putObject(path, fileName, inputStream, objectMetadata);
|
||||||
|
}
|
||||||
|
return s3Url + s3Folder +"/"+ fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delete(String bucketName,String fileName) {
|
||||||
|
|
||||||
|
final DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, fileName);
|
||||||
|
if(Boolean.FALSE.equals(isTestProfileActivated())) {
|
||||||
|
amazonS3.deleteObject(deleteObjectRequest);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isTestProfileActivated() {
|
||||||
|
String[] activeProfiles = environment.getActiveProfiles();
|
||||||
|
return Arrays.stream(activeProfiles).anyMatch("test"::equals);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getFile(String filePath) throws IOException {
|
||||||
|
try {
|
||||||
|
String path = bucketName+ s3Folder +"/";
|
||||||
|
GetObjectRequest getObjectRequest = new GetObjectRequest(path, filePath);
|
||||||
|
S3Object s3Object = amazonS3.getObject(getObjectRequest);
|
||||||
|
return s3Object.getObjectContent();
|
||||||
|
} catch (AmazonS3Exception e) {
|
||||||
|
throw new IOException("Error getting file from Amazon S3", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.dao.RoleDao;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.LoginResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AuthenticationService {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(AuthenticationService.class);
|
||||||
|
|
||||||
|
private final TokenProvider tokenProvider;
|
||||||
|
private final AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleDao roleDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AuthenticationService(TokenProvider tokenProvider, AuthenticationManager authenticationManager) {
|
||||||
|
this.tokenProvider = tokenProvider;
|
||||||
|
this.authenticationManager = authenticationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JWTToken login(LoginReq loginReq) {
|
||||||
|
log.info("Attempting login for email: {}", loginReq.getEmail());
|
||||||
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginReq.getEmail(), loginReq.getPassword());
|
||||||
|
Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
|
log.info("Authentication successful for email: {}", loginReq.getEmail());
|
||||||
|
UserEntity user = userRepository.findByEmail(loginReq.getEmail());
|
||||||
|
if (user == null) {
|
||||||
|
log.error("User not found for email: {}", loginReq.getEmail());
|
||||||
|
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||||
|
}
|
||||||
|
String token = tokenProvider.createToken(authentication, loginReq.getRememberMe(), user);
|
||||||
|
log.info("JWT token generated for email: {}", loginReq.getEmail());
|
||||||
|
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(user.getRoleEntity());
|
||||||
|
JWTToken jwtToken = new JWTToken(token, new LoginResponse(user.getId(), user.getEmail(), user.getFirstName(),
|
||||||
|
user.getLastName(), roleResponseBean, user.getPhoneNumber(), user.getAddress(), user.getOrganization(),
|
||||||
|
user.getCountry(), user.getStatus(), user.getCity(), user.getLastLogin(), user.getCreatedDate(),
|
||||||
|
user.getUpdatedDate()));
|
||||||
|
|
||||||
|
log.info("Login successful for email: {}", loginReq.getEmail());
|
||||||
|
return jwtToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
|
import net.gepafin.tendermanagement.dao.CallDao;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CreateCallRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CreateCallResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CallServiceImpl implements CallService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallDao callDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenProvider tokenProvider;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CreateCallResponseBean createCall(HttpServletRequest request, CreateCallRequest createCallRequest) {
|
||||||
|
Map<String, Object> userInfo= tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||||
|
return callDao.createCall(createCallRequest, Long.parseLong(userInfo.get("userId").toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.dao.DocumentDao;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DocumentServiceImpl implements DocumentService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentDao fileDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||||
|
return fileDao.uploadFiles(files,fileType);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Void deleteFile(Long documentId){
|
||||||
|
return fileDao.deleteFile(documentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.dao.RegionDao;
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
|
||||||
|
import net.gepafin.tendermanagement.service.RegionService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RegionServiceImpl implements RegionService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionDao regionDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public RegionResponseBean createRegion(RegionReq regionReq) {
|
||||||
|
return regionDao.createRegion(regionReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public RegionResponseBean updateRegion(Long regionId, RegionReq regionReq) {
|
||||||
|
return regionDao.updateRegion(regionId,regionReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public RegionEntity getRegionById(Long regionId) {
|
||||||
|
return regionDao.getRegionById(regionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteRegion(Long regionId) {
|
||||||
|
regionDao.deleteById(regionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<RegionResponseBean> getAllRegions() {
|
||||||
|
return regionDao.getAllRegions();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.dao.RoleDao;
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.service.RoleService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RoleServiceImpl implements RoleService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleDao roleDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public RoleResponseBean createRole(RoleReq roleReq) {
|
||||||
|
return roleDao.createRole(roleReq);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public RoleResponseBean updateRole(Long roleId, RoleReq roleReq) {
|
||||||
|
return roleDao.updateRole(roleId,roleReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public RoleEntity getRoleById(Long roleId) {
|
||||||
|
return roleDao.getRoleById(roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteRole(Long roleId) {
|
||||||
|
roleDao.deleteById(roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<RoleResponseBean> getAllRoles() {
|
||||||
|
return roleDao.getAllRoles();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.dao.UserDao;
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.LoginResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public UserResponseBean createUser(UserReq userReq) {
|
||||||
|
return userDao.createUser(userReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||||
|
return userDao.updateUser(userId, userReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public UserResponseBean getUserById(Long userId) {
|
||||||
|
return userDao.getUserById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteUser(Long userId) {
|
||||||
|
userDao.deleteUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JWTToken login(LoginReq loginReq) {
|
||||||
|
return userDao.login(loginReq);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package net.gepafin.tendermanagement.util;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DateTimeUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static LocalDateTime DateServerToUTC(LocalDateTime systemDate) {
|
||||||
|
|
||||||
|
ZonedDateTime ldtZoned = systemDate.atZone(ZoneId.systemDefault());
|
||||||
|
LocalDateTime localDatetime = ldtZoned.withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime();
|
||||||
|
return localDatetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime getPreviousMonthDate(int month) {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.MONTH, -month);
|
||||||
|
LocalDateTime conv = LocalDateTime.ofInstant(c.getTime().toInstant(), ZoneId.systemDefault());
|
||||||
|
return conv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Date getDateWithoutTime(LocalDateTime systemDate) {
|
||||||
|
ZonedDateTime zdt = systemDate.atZone(ZoneId.systemDefault());
|
||||||
|
Date date = Date.from(zdt.toInstant());
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime convertDateToLocalDateTime(Date date) {
|
||||||
|
LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(),
|
||||||
|
ZoneId.systemDefault());
|
||||||
|
return ldt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Date convertLocalDateTimeToDateUsingInstant(LocalDateTime localDateTime) {
|
||||||
|
return Date
|
||||||
|
.from(localDateTime.atZone(ZoneId.systemDefault())
|
||||||
|
.toInstant());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.gepafin.tendermanagement.util;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ObjectUtils {
|
||||||
|
|
||||||
|
public static <T> void setIfNotNull(Consumer<T> setter, T value) {
|
||||||
|
if (value != null) {
|
||||||
|
setter.accept(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static <T> void setIfUpdated(Supplier<T> getter, Consumer<T> setter, T newValue) {
|
||||||
|
T currentValue = getter.get();
|
||||||
|
if (newValue != null && !newValue.equals(currentValue)) {
|
||||||
|
setter.accept(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
72
src/main/java/net/gepafin/tendermanagement/util/Utils.java
Normal file
72
src/main/java/net/gepafin/tendermanagement/util/Utils.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package net.gepafin.tendermanagement.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import io.micrometer.common.util.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||||
|
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper()
|
||||||
|
.registerModule(new JavaTimeModule())
|
||||||
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
|
public static <T, U> U convertObject(T source, Class<U> destinationClass) {
|
||||||
|
try {
|
||||||
|
return mapper.convertValue(source, destinationClass);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error converting object: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, U> List<U> convertSourceListToDestinationList(List<T> sourceList, Class<U> destinationClass) {
|
||||||
|
try {
|
||||||
|
return sourceList.stream()
|
||||||
|
.map(source -> mapper.convertValue(source, destinationClass))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error converting list: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, U> List<U> convertSourceToList(T source, Class<U> destinationClass) {
|
||||||
|
try {
|
||||||
|
// Convert single source object to a single-element list of destination type
|
||||||
|
return List.of(mapper.convertValue(source, destinationClass));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error converting single object to list: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static String extractFileName(String filePath) {
|
||||||
|
if (filePath == null || filePath.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int lastSlashIndex = filePath.lastIndexOf('/');
|
||||||
|
|
||||||
|
if (lastSlashIndex >= 0 && lastSlashIndex < filePath.length() - 1) {
|
||||||
|
return filePath.substring(lastSlashIndex + 1);
|
||||||
|
} else {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String decodeBase64String(String decodedString) {
|
||||||
|
if (StringUtils.isBlank(decodedString)) {
|
||||||
|
return decodedString;
|
||||||
|
}
|
||||||
|
byte[] decode = Base64.getDecoder().decode(decodedString.getBytes(StandardCharsets.UTF_8));
|
||||||
|
return new String(decode, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CreateCallRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CreateCallResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
|
||||||
|
public interface CallApi {
|
||||||
|
|
||||||
|
@Operation(summary = "API to create call",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||||
|
})
|
||||||
|
@PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public ResponseEntity<Response<CreateCallResponseBean>> createCall(HttpServletRequest request,
|
||||||
|
@Parameter(description = "Call request object", required = true)
|
||||||
|
@Valid @RequestBody CreateCallRequest createCallRequest);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DocumentApi {
|
||||||
|
|
||||||
|
@Operation(summary = "Api to upload a file",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||||
|
})
|
||||||
|
@PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest,
|
||||||
|
@RequestParam("file") List<MultipartFile> files,
|
||||||
|
@RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
@Operation(summary = "API to delete a file by document id",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "File deleted successfully"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||||
|
})
|
||||||
|
@DeleteMapping(value = "/deleteFile")
|
||||||
|
default ResponseEntity<Response<Void>> deleteFile(HttpServletRequest httpServletRequest,
|
||||||
|
@RequestParam( "id") Long id) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Validated
|
||||||
|
@RequestMapping("/region")
|
||||||
|
public interface RegionApi {
|
||||||
|
|
||||||
|
@Operation(summary = "Api to create region",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@PostMapping(value = "",produces = "application/json")
|
||||||
|
ResponseEntity<Response<RegionResponseBean>> createRegion(
|
||||||
|
@Parameter(description = "Region request object", required = true) @Valid @RequestBody RegionReq regionReq);
|
||||||
|
|
||||||
|
@Operation(summary = "Api to update region",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@PutMapping(value = "/{regionId}", produces = "application/json")
|
||||||
|
ResponseEntity<Response<RegionResponseBean>> updateRegion(
|
||||||
|
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId,
|
||||||
|
@Parameter(description = "Region request object", required = true) @Valid @RequestBody RegionReq regionReq);
|
||||||
|
|
||||||
|
@Operation(summary = "Api to get a region by id",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@GetMapping(value = "/{regionId}", produces = "application/json")
|
||||||
|
ResponseEntity<Response<RegionEntity>> getRegionById(
|
||||||
|
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId);
|
||||||
|
|
||||||
|
@Operation(summary = "Api to get all regions",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@GetMapping(value = "",
|
||||||
|
produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<List<RegionResponseBean>>> getAllRegions();
|
||||||
|
@Operation(summary = "Api to delete region",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@DeleteMapping(value = "/{regionId}")
|
||||||
|
ResponseEntity<Response<Void>> deleteRegion(
|
||||||
|
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Validated
|
||||||
|
public interface RoleApi {
|
||||||
|
|
||||||
|
@Operation(summary = "API to create role",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@PostMapping(value = "",
|
||||||
|
produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<RoleResponseBean>> createRole(
|
||||||
|
@Parameter(description = " Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "API to update role",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@PutMapping(value = "/{roleId}",
|
||||||
|
produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<RoleResponseBean>> updateRole(
|
||||||
|
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId,
|
||||||
|
@Parameter(description = "Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
|
||||||
|
|
||||||
|
@Operation(summary = "API to get role by id",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@GetMapping(value = "/{roleId}",
|
||||||
|
produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<RoleEntity>> getRoleById(
|
||||||
|
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
|
||||||
|
|
||||||
|
@Operation(summary = "API to get all roles",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@GetMapping(value = "",
|
||||||
|
produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles();
|
||||||
|
|
||||||
|
@Operation(summary = "API to delete role",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@DeleteMapping(value = "/{roleId}")
|
||||||
|
ResponseEntity<Response<Void>> deleteRole(
|
||||||
|
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
|
||||||
|
}
|
||||||
@@ -1,8 +1,106 @@
|
|||||||
package net.gepafin.tendermanagement.web.rest.api;
|
package net.gepafin.tendermanagement.web.rest.api;
|
||||||
import net.gepafin.tendermanagement.model.User;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
@Validated
|
||||||
public interface UserApi {
|
public interface UserApi {
|
||||||
@GetMapping("")
|
|
||||||
User getUser();
|
@Operation(summary = "Api to create user",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
|
@RequestMapping(value = "",
|
||||||
|
produces = {"application/json"},
|
||||||
|
method = RequestMethod.POST)
|
||||||
|
default ResponseEntity<Response<UserResponseBean>> createUser(
|
||||||
|
@Parameter(description = "User request object", required = true) @Validated @RequestBody UserReq userReq) {
|
||||||
|
return new ResponseEntity<Response<UserResponseBean>>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Api to update user",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
|
@RequestMapping(value = "/{userId}",
|
||||||
|
produces = {"application/json"},
|
||||||
|
method = RequestMethod.PUT)
|
||||||
|
default ResponseEntity<Response<UserResponseBean>> updateUser(
|
||||||
|
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
|
||||||
|
@Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Api to get user by id",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
|
@RequestMapping(value = "/{userId}",
|
||||||
|
produces = {"application/json"},
|
||||||
|
method = RequestMethod.GET)
|
||||||
|
default ResponseEntity<Response<UserResponseBean>> getUserById(
|
||||||
|
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Api to delete user",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
|
@RequestMapping(value = "/{userId}",
|
||||||
|
method = RequestMethod.DELETE)
|
||||||
|
default ResponseEntity<Response<Void>> deleteUser(
|
||||||
|
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Api to login user",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request"),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized")})
|
||||||
|
@RequestMapping(value = "/login",
|
||||||
|
produces = {"application/json"},
|
||||||
|
method = RequestMethod.POST)
|
||||||
|
ResponseEntity<Response<JWTToken>> login(
|
||||||
|
@Parameter(description = "Login request object", required = true) @Valid @RequestBody LoginReq loginReq);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||||
|
|
||||||
|
public class CustomValidationException extends RuntimeException {
|
||||||
|
|
||||||
|
private final Status status;
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomValidationException(Status status, String message) {
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public final class ErrorConstants {
|
||||||
|
|
||||||
|
public static final String ERR_CONCURRENCY_FAILURE = "error.concurrencyFailure";
|
||||||
|
public static final String ERR_VALIDATION = "error.validation";
|
||||||
|
public static final String PROBLEM_BASE_URL = "https://www.jhipster.tech/problem";
|
||||||
|
public static final URI DEFAULT_TYPE = URI.create(PROBLEM_BASE_URL + "/problem-with-message");
|
||||||
|
public static final URI CONSTRAINT_VIOLATION_TYPE = URI.create(PROBLEM_BASE_URL + "/constraint-violation");
|
||||||
|
public static final URI INVALID_PASSWORD_TYPE = URI.create(PROBLEM_BASE_URL + "/invalid-password");
|
||||||
|
public static final URI EMAIL_ALREADY_USED_TYPE = URI.create(PROBLEM_BASE_URL + "/email-already-used");
|
||||||
|
public static final URI LOGIN_ALREADY_USED_TYPE = URI.create(PROBLEM_BASE_URL + "/login-already-used");
|
||||||
|
|
||||||
|
public static final String BADREQUEST_ERROR_EXAMPLE="{\"data\": null,"
|
||||||
|
+"\"status\": \"VALIDATION_ERROR\",\"message\": \"string\""
|
||||||
|
+ "}";
|
||||||
|
public static final String NOTFOUND_ERROR_EXAMPLE="{\"data\": null,"
|
||||||
|
+"\"status\": \"NOT_FOUND\",\"message\": \"string\""
|
||||||
|
+ "}";
|
||||||
|
public static final String UNAUTHORIZED_ERROR_EXAMPLE="{\"data\": null,"
|
||||||
|
+"\"status\": \"UNAUTHORIZED\",\"message\": \"string\""
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
private ErrorConstants() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(CustomValidationException.class)
|
||||||
|
public ResponseEntity<Response<Void>> handleCustomValidationException(CustomValidationException ex) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.body(new Response<>(null, ex.getStatus(), ex.getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(ResourceNotFoundException.class)
|
||||||
|
public ResponseEntity<Response<Void>> handleResourceNotFoundException(ResourceNotFoundException ex) {
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||||
|
.body(new Response<>(null, ex.getStatus(), ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||||
|
public class ResourceNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final Status status;
|
||||||
|
|
||||||
|
public ResourceNotFoundException(Status status, String message) {
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
SUCCESS("1"), VALIDATION_ERROR("2"), EXCEPTION_ERROR("3") , NOT_FOUND("4") , BAD_REQUEST("5") , UNAUTHORIZED("6") ,
|
||||||
|
FORBIDDEN("7"), VALIDATION_COMPLETED("8");
|
||||||
|
|
||||||
|
private String action;
|
||||||
|
|
||||||
|
public String getAction() {
|
||||||
|
return this.action;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Status(String action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CreateCallRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CreateCallResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.CallApi;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("${openapi.gepafin.base-path:/v1/call}")
|
||||||
|
public class CallApiController implements CallApi {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallService callService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor=Exception.class)
|
||||||
|
public ResponseEntity<Response<CreateCallResponseBean>> createCall(HttpServletRequest request, CreateCallRequest createCallRequest) {
|
||||||
|
CreateCallResponseBean createCallResponseBean = callService.createCall(request, createCallRequest);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<>(createCallResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_CREATED_SUCCESSFULLY_MSG)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.repositories.RoleRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
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.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CustomUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(CustomUserDetailsService.class);
|
||||||
|
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final RoleRepository roleRepository;
|
||||||
|
|
||||||
|
public CustomUserDetailsService(UserRepository userRepository, RoleRepository roleRepository) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
this.roleRepository = roleRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public UserDetails loadUserByUsername(final String email) throws UsernameNotFoundException {
|
||||||
|
log.debug("Authenticating {}", email);
|
||||||
|
|
||||||
|
UserEntity user = userRepository.findByEmail(email);
|
||||||
|
if (user == null) {
|
||||||
|
throw new UsernameNotFoundException("User " + email + " was not found in the database");
|
||||||
|
}
|
||||||
|
|
||||||
|
return createSpringSecurityUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private org.springframework.security.core.userdetails.User createSpringSecurityUser(UserEntity user) {
|
||||||
|
RoleEntity role = user.getRoleEntity();
|
||||||
|
GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role.getRoleName());
|
||||||
|
|
||||||
|
return new org.springframework.security.core.userdetails.User(
|
||||||
|
user.getEmail(),
|
||||||
|
user.getPassword(),
|
||||||
|
Collections.singletonList(grantedAuthority)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.DocumentApi;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("${openapi.swaggerBflowsMiddleware.base-path:/v1/document}")
|
||||||
|
public class DocumentApiController implements DocumentApi {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentService fileService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest,
|
||||||
|
List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||||
|
try {
|
||||||
|
List<DocumentResponseBean> responseBeans=fileService.uploadFile(files,fileType);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<List<DocumentResponseBean>>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILES_UPLOADED_MSG)));
|
||||||
|
} catch (CustomValidationException ex) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<Void>> deleteFile(HttpServletRequest httpServletRequest, Long documentId) {
|
||||||
|
fileService.deleteFile(documentId);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILE_DELETED_SUCCESSFULLY_MSG)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.service.RegionService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.RegionApi;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("${openapi.gepafin.base-path:/v1/region}")
|
||||||
|
public class RegionApiController implements RegionApi {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(RegionApiController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionService regionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RegionResponseBean>> createRegion(
|
||||||
|
@Valid @RequestBody RegionReq regionReq) {
|
||||||
|
log.info("Create Region - Request Body: {}", regionReq);
|
||||||
|
RegionResponseBean createdRegion = regionService.createRegion(regionReq);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<>(createdRegion, Status.SUCCESS, Translator.toLocale(GepafinConstant.REGION_CREATED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RegionResponseBean>> updateRegion(
|
||||||
|
@PathVariable("regionId") Long regionId,
|
||||||
|
@Valid @RequestBody RegionReq regionReq) {
|
||||||
|
log.info("Update Region - Region ID: {}, Request Body: {}", regionId, regionReq);
|
||||||
|
RegionResponseBean updatedRegion = regionService.updateRegion(regionId, regionReq);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(updatedRegion, Status.SUCCESS, Translator.toLocale(GepafinConstant.REGION_UPDATED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RegionEntity>> getRegionById(
|
||||||
|
@PathVariable("regionId") Long regionId) {
|
||||||
|
log.info("Get Region by ID - Region ID: {}", regionId);
|
||||||
|
RegionEntity region = regionService.getRegionById(regionId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(region, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_REGION_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<Void>> deleteRegion(
|
||||||
|
@PathVariable("regionId") Long regionId) {
|
||||||
|
log.info("Delete Region - Region ID: {}", regionId);
|
||||||
|
regionService.deleteRegion(regionId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_REGION_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<List<RegionResponseBean>>> getAllRegions() {
|
||||||
|
List<RegionResponseBean> regions = regionService.getAllRegions();
|
||||||
|
log.info("Get All Region");
|
||||||
|
regionService.getAllRegions();
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(regions, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_REGION_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.service.RoleService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.RoleApi;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("${openapi.gepafin.base-path:/v1/role}")
|
||||||
|
public class RoleApiController implements RoleApi {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RoleApiController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleService roleService;
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RoleResponseBean>> createRole(RoleReq body) {
|
||||||
|
log.info("Create Role - Request Body: {}", body);
|
||||||
|
RoleResponseBean roleReq = roleService.createRole(body);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<>(roleReq, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_CREATED_SUCCESS_MSG)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RoleResponseBean>> updateRole(Long roleId, RoleReq body) {
|
||||||
|
log.info("Update Role - Role ID: {}, Request Body: {}", roleId, body);
|
||||||
|
RoleResponseBean updatedUserRole = roleService.updateRole(roleId, body);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(updatedUserRole, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_UPDATED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles() {
|
||||||
|
log.info("Get All Roles");
|
||||||
|
List<RoleResponseBean> roles = roleService.getAllRoles();
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(roles, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<RoleEntity>> getRoleById(Long roleId) {
|
||||||
|
log.info("Get Role by ID - Role ID: {}", roleId);
|
||||||
|
RoleEntity roleEntity = roleService.getRoleById(roleId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(roleEntity, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<Void>> deleteRole(Long roleId) {
|
||||||
|
log.info("Delete Role - Role ID: {}", roleId);
|
||||||
|
roleService.deleteRole(roleId);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.NO_CONTENT)
|
||||||
|
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_DELETED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,77 @@
|
|||||||
package net.gepafin.tendermanagement.web.rest.api.impl;
|
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.model.User;
|
import jakarta.validation.Valid;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.UserApi;
|
import net.gepafin.tendermanagement.web.rest.api.UserApi;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/v1/user")
|
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
|
||||||
public class UserApiController implements UserApi
|
@Validated
|
||||||
{
|
public class UserApiController implements UserApi {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(UserApiController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUser() {
|
public ResponseEntity<Response<UserResponseBean>> createUser(@RequestBody UserReq userReq) {
|
||||||
return new User(1L, "John Doe", "john.doe@test.test");
|
log.info("Create User with - Request Body: {}", userReq);
|
||||||
|
UserResponseBean createdUser = userService.createUser(userReq);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
|
.body(new Response<>(createdUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_CREATED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<UserResponseBean>> updateUser(
|
||||||
|
@PathVariable("userId") Long userId,
|
||||||
|
@Valid @RequestBody UpdateUserReq userReq) {
|
||||||
|
log.info("Update User - User ID: {}, Request Body: {}", userId, userReq);
|
||||||
|
UserResponseBean updatedUser = userService.updateUser(userId, userReq);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(updatedUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_UPDATED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<UserResponseBean>> getUserById(
|
||||||
|
@PathVariable("userId") Long userId) {
|
||||||
|
log.info("Get User by ID - User ID: {}", userId);
|
||||||
|
UserResponseBean user = userService.getUserById(userId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<Void>> deleteUser(
|
||||||
|
@PathVariable("userId") Long userId) {
|
||||||
|
log.info("Delete User - User ID: {}", userId);
|
||||||
|
userService.deleteUser(userId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_DELETED_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<JWTToken>> login(
|
||||||
|
@Valid @RequestBody LoginReq loginReq) {
|
||||||
|
log.info("User login attempt ");
|
||||||
|
JWTToken jwtToken = userService.login(loginReq);
|
||||||
|
return ResponseEntity.ok(new Response<>(jwtToken, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOGIN_SUCCESS_MSG)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/main/resources/application-dev.properties
Normal file
8
src/main/resources/application-dev.properties
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# DataSource Configuration
|
||||||
|
spring.datasource.url=jdbc:postgresql://dbstaging.memento.credit:20184/gepaDb
|
||||||
|
spring.datasource.username=usergepa
|
||||||
|
spring.datasource.password=vs1pAc9vu07mMcdx93j6WiBS
|
||||||
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
|
|
||||||
|
# JPA Configuration
|
||||||
|
spring.h2.console.enabled=true
|
||||||
8
src/main/resources/application-local.properties
Normal file
8
src/main/resources/application-local.properties
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# DataSource Configuration
|
||||||
|
spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_local
|
||||||
|
spring.datasource.username=postgres
|
||||||
|
spring.datasource.password=root
|
||||||
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
|
|
||||||
|
# JPA Configuration
|
||||||
|
spring.jpa.show-sql=true
|
||||||
7
src/main/resources/application-testing.properties
Normal file
7
src/main/resources/application-testing.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# DataSource Configuration
|
||||||
|
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||||
|
spring.datasource.username=sa
|
||||||
|
spring.datasource.password=sa
|
||||||
|
|
||||||
|
# JPA Configuration
|
||||||
|
spring.h2.console.enabled=true
|
||||||
@@ -1,3 +1,40 @@
|
|||||||
spring.application.name=tendermanagement
|
spring.application.name=tendermanagement
|
||||||
server.port=8080
|
|
||||||
|
# Multipart Configuration
|
||||||
|
spring.servlet.multipart.max-file-size=50MB
|
||||||
|
spring.servlet.multipart.max-request-size=50MB
|
||||||
|
|
||||||
|
spring.profiles.active=testing
|
||||||
|
|
||||||
|
|
||||||
|
# JPA Configuration
|
||||||
|
spring.jpa.properties.hibernate.default_schema=gepafin_schema
|
||||||
|
spring.jpa.hibernate.ddl-auto=none
|
||||||
|
spring.jpa.show-sql=false
|
||||||
|
|
||||||
|
|
||||||
|
# Liquibase Configuration
|
||||||
|
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
|
||||||
|
spring.liquibase.default-schema=gepafin_schema
|
||||||
|
spring.liquibase.enabled=true
|
||||||
|
|
||||||
|
|
||||||
|
# Swagger Configuration
|
||||||
|
springdoc.api-docs.path=/v1/api-docs
|
||||||
|
|
||||||
|
|
||||||
|
#aws configuration
|
||||||
|
aws.access.key.id=AKIAVWDQWCUEOSUN4LUW
|
||||||
|
aws.secret.access.key=FtnkzF8E3vtqPrVnloqMyNSUSqg0f9Z9L0R7qQOu
|
||||||
|
aws.s3.region=eu-west-1
|
||||||
|
aws.s3.bucket.name=mementoresources
|
||||||
|
aws.s3.url = https://mementoresources.s3.eu-west-1.amazonaws.com/
|
||||||
|
aws.s3.url.folder=gepafin
|
||||||
|
# JWT configuration
|
||||||
|
# Ensure these values match your expectations
|
||||||
|
security.authentication.jwt.secret=my-secret-token-to-change-in-prod-environment-your-super-secure-randomly-generated-key
|
||||||
|
security.authentication.jwt.token-validity-in-seconds=86400
|
||||||
|
|
||||||
|
|
||||||
|
spring.main.allow-circular-references=true
|
||||||
|
|
||||||
|
|||||||
295
src/main/resources/db/changelog/db.changelog-1.0.0.xml
Normal file
295
src/main/resources/db/changelog/db.changelog-1.0.0.xml
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog
|
||||||
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.23.xsd">
|
||||||
|
<changeSet id="14-08-2024_1" author="Harish Bagora">
|
||||||
|
<createTable tableName="region">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="region_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="region_name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="description" type="TEXT">
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="country" type="VARCHAR(100)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="status" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="priority_area" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="population" type="INTEGER">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="area_size" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="gdp" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="unemployment_rate" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="infrastructure_score" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="education_level" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="healthcare_access" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="environmental_score" type="numeric">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="14-08-2024_2" author="Harish Bagora">
|
||||||
|
<createTable tableName="role">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="role_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="role_name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="description" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="permissions" type="TEXT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="region_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_role_region" references="region(id)"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="14-08-2024_3" author="Harish Bagora">
|
||||||
|
<createTable tableName="gepafin_user">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="gepafin_user_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="password" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="email" type="varchar(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="first_name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="last_name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="phone_number" type="VARCHAR(255)"/>
|
||||||
|
<column name="role_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_gepafin_user_role" references="role(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="status" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="last_login" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="organization" type="TEXT">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="address" type="TEXT">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="city" type="TEXT">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="country" type="TEXT">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="21-08-2024_1" author="Rajesh Khore">
|
||||||
|
<createTable tableName="call">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="call_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="description_short" type="TEXT"/>
|
||||||
|
<column name="description_long" type="TEXT"/>
|
||||||
|
<column name="start_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="end_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="status" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="region_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_region_call" references="region(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="amount" type="numeric">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="amount_max" type="numeric">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="documentation_requested" type="TEXT"/>
|
||||||
|
<column name="contact_info" type="TEXT"/>
|
||||||
|
<column name="submission_method" type="TEXT">
|
||||||
|
</column>
|
||||||
|
<column name="threshold" type="INTEGER">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="priority_area" type="TEXT"/>
|
||||||
|
<column name="confidi" type="BOOLEAN"/>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<createTable tableName="evaluation_criteria">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="evaluation_criteria_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="call_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_call_evaluation_criteria" references="call(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="name" type="TEXT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="description" type="TEXT"/>
|
||||||
|
<column name="score" type="INTEGER">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<createTable tableName="faq">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="faq_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="call_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_call_faq" references="call(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="user_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_gepafin_user_faq" references="gepafin_user(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="is_visible" type="BOOLEAN">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="question_short" type="VARCHAR(255)"/>
|
||||||
|
<column name="question" type="TEXT"/>
|
||||||
|
<column name="response_short" type="VARCHAR(255)"/>
|
||||||
|
<column name="response" type="TEXT"/>
|
||||||
|
<column name="response_date" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<createTable tableName="document">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="document_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="file_name" type="VARCHAR(255)">
|
||||||
|
</column>
|
||||||
|
<column name="file_path" type="TEXT"/>
|
||||||
|
<column name="call_id" type="INTEGER">
|
||||||
|
<constraints foreignKeyName="fk_call_document" references="call(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="description" type="TEXT"/>
|
||||||
|
<column name="type" type="VARCHAR(255)">
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/></column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<createTable tableName="lookup_data">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="lookup_data_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="title" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="type" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="value" type="TEXT">
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/></column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<createTable tableName="call_target_audience_checklist">
|
||||||
|
<column autoIncrement="true" name="id" type="INTEGER">
|
||||||
|
<constraints nullable="false" primaryKey="true"
|
||||||
|
primaryKeyName="call_target_audience_checklist_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="call_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_call_call_target_audience_checklist" references="call(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="lookup_data_id" type="INTEGER">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_lookup_data_call_target_audience_checklist" references="lookup_data(id)"/>
|
||||||
|
</column>
|
||||||
|
<column name="is_validated" type="BOOLEAN">
|
||||||
|
</column>
|
||||||
|
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/></column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user