Resolved conflicts
This commit is contained in:
2
mvnw
vendored
Normal file → Executable file
2
mvnw
vendored
Normal file → Executable file
@@ -8,7 +8,7 @@
|
|||||||
# "License"); you may not use this file except in compliance
|
# "License"); you may not use this file except in compliance
|
||||||
# with the License. You may obtain a copy of the License at
|
# with the License. You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
|
|||||||
2
mvnw.cmd
vendored
2
mvnw.cmd
vendored
@@ -8,7 +8,7 @@
|
|||||||
@REM "License"); you may not use this file except in compliance
|
@REM "License"); you may not use this file except in compliance
|
||||||
@REM with the License. You may obtain a copy of the License at
|
@REM with the License. You may obtain a copy of the License at
|
||||||
@REM
|
@REM
|
||||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||||
@REM
|
@REM
|
||||||
@REM Unless required by applicable law or agreed to in writing,
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
@REM software distributed under the License is distributed on an
|
@REM software distributed under the License is distributed on an
|
||||||
|
|||||||
23
pom.xml
23
pom.xml
@@ -88,8 +88,8 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
<version>1.12.312</version>
|
<version>1.12.563</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -226,6 +226,25 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Notification RabbitMQ and WebSocket/WS-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.projectreactor.netty</groupId>
|
||||||
|
<artifactId>reactor-netty</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ public class TendermanagementApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
registry.addMapping("/**").allowedOrigins("http://localhost:3000")
|
registry.addMapping("/**").allowedOrigins("http://localhost:3000").allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true);
|
||||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public class SecurityConfig {
|
|||||||
.requestMatchers("/v1/api-docs/**").permitAll() // API docs
|
.requestMatchers("/v1/api-docs/**").permitAll() // API docs
|
||||||
.requestMatchers("/v1/user/reset-password/initiate").permitAll()
|
.requestMatchers("/v1/user/reset-password/initiate").permitAll()
|
||||||
.requestMatchers("/v1/user/reset-password").permitAll()
|
.requestMatchers("/v1/user/reset-password").permitAll()
|
||||||
|
.requestMatchers("/wss/**").permitAll() // if this is not running use this /gs-guide-websocket
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED))
|
||||||
.exceptionHandling(exceptionHandling -> exceptionHandling
|
.exceptionHandling(exceptionHandling -> exceptionHandling
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||||
|
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSocketMessageBroker
|
||||||
|
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||||
|
|
||||||
|
@Value("${spring.rabbitmq.host}")
|
||||||
|
private String relayHost;
|
||||||
|
|
||||||
|
@Value("${spring.rabbitmq.port}")
|
||||||
|
private int relayPort;
|
||||||
|
|
||||||
|
@Value("${spring.rabbitmq.username}")
|
||||||
|
private String clientUserName;
|
||||||
|
|
||||||
|
@Value("${spring.rabbitmq.password}")
|
||||||
|
private String clientPassword;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureMessageBroker(MessageBrokerRegistry config) {
|
||||||
|
|
||||||
|
config.enableStompBrokerRelay("/topic").setRelayHost(relayHost).setRelayPort(relayPort).setClientLogin(clientUserName).setClientPasscode(clientPassword);
|
||||||
|
config.setApplicationDestinationPrefixes("/app");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
|
|
||||||
|
registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000", "http://127.0.0.1:5500/", "https://bandi-staging.memento.credit/**", "https://bandi.gepafin.it/**")
|
||||||
|
.withSockJS();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package net.gepafin.tendermanagement.config.jwt;
|
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;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JWTFilter extends GenericFilterBean {
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public class JWTFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
private final TokenProvider tokenProvider;
|
private final TokenProvider tokenProvider;
|
||||||
|
|
||||||
@@ -20,9 +20,10 @@ public class JWTFilter extends GenericFilterBean {
|
|||||||
this.tokenProvider = tokenProvider;
|
this.tokenProvider = tokenProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void doFilterInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
FilterChain filterChain) throws ServletException, IOException {
|
||||||
throws IOException, ServletException {
|
|
||||||
|
try {
|
||||||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||||
String token = resolveToken(httpServletRequest);
|
String token = resolveToken(httpServletRequest);
|
||||||
|
|
||||||
@@ -34,6 +35,10 @@ public class JWTFilter extends GenericFilterBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterChain.doFilter(servletRequest, servletResponse);
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
|
} catch (Exception e) {
|
||||||
|
servletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveToken(HttpServletRequest request) {
|
private String resolveToken(HttpServletRequest request) {
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package net.gepafin.tendermanagement.config.jwt;
|
package net.gepafin.tendermanagement.config.jwt;
|
||||||
|
|
||||||
|
import static io.micrometer.common.util.StringUtils.isEmpty;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
|
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.Autowired;
|
||||||
|
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.context.SecurityContextHolder;
|
||||||
|
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 com.google.gson.Gson;
|
||||||
|
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
@@ -14,30 +48,6 @@ import net.gepafin.tendermanagement.repositories.UserRepository;
|
|||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.UnauthorizedAccessException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.UnauthorizedAccessException;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
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.context.SecurityContextHolder;
|
|
||||||
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
|
@Component
|
||||||
@@ -48,7 +58,7 @@ public class TokenProvider {
|
|||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|
||||||
@Value("${security.authentication.jwt.token-validity-in-seconds}")
|
@Value("${security.authentication.jwt.token-validity-in-seconds}")
|
||||||
private long tokenValidityInSeconds;
|
private int tokenValidityInSeconds;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@@ -60,7 +70,6 @@ public class TokenProvider {
|
|||||||
private static final String MERCHANTID="merchantId";
|
private static final String MERCHANTID="merchantId";
|
||||||
|
|
||||||
static final String AUTH_SECRET = "X-Api-Secret";
|
static final String AUTH_SECRET = "X-Api-Secret";
|
||||||
private final Set<String> invalidatedTokens = new HashSet<>();
|
|
||||||
private static final String USER_ID = "userId";
|
private static final String USER_ID = "userId";
|
||||||
|
|
||||||
public UserEntity validateUser(Map<String, Object> userInfo) {
|
public UserEntity validateUser(Map<String, Object> userInfo) {
|
||||||
@@ -96,12 +105,12 @@ public class TokenProvider {
|
|||||||
Date validity;
|
Date validity;
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(rememberMe)) {
|
if (Boolean.TRUE.equals(rememberMe)) {
|
||||||
now = DateUtils.addMonths(new Date(), 2).getTime();
|
now = DateUtils.addDays(new Date(), 2).getTime();
|
||||||
validity = new Date(now);
|
validity = new Date(now);
|
||||||
log.info("Creating token with extended validity for 2 months.");
|
log.info("Creating token with extended validity for 2 days.");
|
||||||
} else {
|
} else {
|
||||||
now = (new Date()).getTime();
|
now = DateUtils.addSeconds(new Date(), this.tokenValidityInSeconds).getTime();
|
||||||
validity = new Date(now + (this.tokenValidityInSeconds * 1000));
|
validity = new Date(now);
|
||||||
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,31 +158,14 @@ public class TokenProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateToken(String authToken) {
|
public boolean validateToken(String authToken) {
|
||||||
try {
|
|
||||||
if (isTokenInvalid(authToken)) {
|
Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(authToken);
|
||||||
log.warn("Token is invalidated.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Jwts.parserBuilder()
|
|
||||||
.setSigningKey(key)
|
|
||||||
.build()
|
|
||||||
.parseClaimsJws(authToken);
|
|
||||||
log.info("Token is valid.");
|
log.info("Token is valid.");
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Token validation failed: {}", e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateToken(String token) {
|
|
||||||
invalidatedTokens.add(token);
|
|
||||||
log.info("Token invalidated: {}", token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTokenInvalid(String token) {
|
|
||||||
return invalidatedTokens.contains(token);
|
|
||||||
}
|
|
||||||
public Map<String, Object> getUserInfoAndUserIdFromToken(HttpServletRequest request) {
|
public Map<String, Object> getUserInfoAndUserIdFromToken(HttpServletRequest request) {
|
||||||
Map<String, Object> userInfo = new HashMap<>();
|
Map<String, Object> userInfo = new HashMap<>();
|
||||||
String authSecretHeader=request.getHeader(AUTH_SECRET);
|
String authSecretHeader=request.getHeader(AUTH_SECRET);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.gepafin.tendermanagement.constants;
|
||||||
|
|
||||||
|
public class AppointmentApiConstant {
|
||||||
|
|
||||||
|
public static final String ODESSA_LOGIN = "/WSGatewayLogin.apiLogin";
|
||||||
|
public static final String GET_NDG_BY_VAT_NUMBER = "/WSAnagrafica.getListaNdg";
|
||||||
|
public static final String CREATE_VISURA = "/WSAnagrafica.createVisura";
|
||||||
|
public static final String GET_VISURA_LIST = "/WSAnagrafica.getVisuraList";
|
||||||
|
public static final String GET_APPOINTMENT_TEMPLATE = "/WSCrmConsulenza.getAppuntamentoTemplate?idAppuntamentoTemplate=7";
|
||||||
|
public static final String CREATE_APPOINTMENT_FROM_TEMPLATE = "/WSCrmConsulenza.createAppointmentFromTemplate";
|
||||||
|
public static final String UPLOAD_APOOINTMENT_DOCUMENT = "/WSDocumentDetail.createStream";
|
||||||
|
|
||||||
|
//get ndg number
|
||||||
|
public static final int TARGET_PAGE_SIZE = 1;
|
||||||
|
public static final int RECORD_PER_PAGE_SIZE = 10;
|
||||||
|
|
||||||
|
//create visura request Body constant
|
||||||
|
public static final boolean CREA_ANAGRAFICA = Boolean.TRUE;
|
||||||
|
public static final boolean SALVA_DOCUMENTI = Boolean.TRUE;
|
||||||
|
public static final String VISURA_PROVIDER = "cerved";
|
||||||
|
public static final String VISURA_TYPE = "StandardReport";
|
||||||
|
public static final String VISURA_MODE = "visure";
|
||||||
|
public static final String COD_AGENTE = "UtenzaAPIPortal";
|
||||||
|
public static final boolean IS_FROM_RATING = Boolean.FALSE;
|
||||||
|
public static final boolean IS_ANAGRAFICA_LEGAME = Boolean.FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -294,6 +294,9 @@ public class GepafinConstant {
|
|||||||
public static final String DUPLICATE_BENEFICIARY_CALL = "beneficiary.call.duplicate";
|
public static final String DUPLICATE_BENEFICIARY_CALL = "beneficiary.call.duplicate";
|
||||||
public static final String USER_MUST_BE_ASSOCIATED_WITH_COMPANY="user.must.be.associated.with.company.to.create.application";
|
public static final String USER_MUST_BE_ASSOCIATED_WITH_COMPANY="user.must.be.associated.with.company.to.create.application";
|
||||||
public static final String COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL = "company.id.required.for.preferred.call";
|
public static final String COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL = "company.id.required.for.preferred.call";
|
||||||
|
public static final String CREATED_DATE = "createdDate";
|
||||||
|
public static final String RESPONSE_DAYS_NOT_NULL="response.days.not.null";
|
||||||
|
public static final String APPLICATION_CANNOT_APPROVED_OR_REJECTED="application.cannot.approved.or.rejected";
|
||||||
public static final String SUBMISSION_DATE = "submissionDate";
|
public static final String SUBMISSION_DATE = "submissionDate";
|
||||||
public static final String ASSIGNED_AT = "assignedAt";
|
public static final String ASSIGNED_AT = "assignedAt";
|
||||||
public static final String AUTH = "auth";
|
public static final String AUTH = "auth";
|
||||||
@@ -303,5 +306,54 @@ public class GepafinConstant {
|
|||||||
public static final String LOGIN_ATTEMPT_ID = "loginAttemptId";
|
public static final String LOGIN_ATTEMPT_ID = "loginAttemptId";
|
||||||
public static final String USER_ACTION_ID = "userActionId";
|
public static final String USER_ACTION_ID = "userActionId";
|
||||||
public static final String RESET_PASSWORD_URL_FORMAT = "/reset-password?token=%s&email=%s";
|
public static final String RESET_PASSWORD_URL_FORMAT = "/reset-password?token=%s&email=%s";
|
||||||
|
public static final String VALID_VATNUMBER_MSG = "valid.vatnumber.message";
|
||||||
|
public static final String ATLEAST_ONE_ID_REQUIRED="atleast.one.id.required";
|
||||||
|
|
||||||
|
//Appointment
|
||||||
|
public static final String NDG_IN_PROGRESS = "IN_PROGRESS";
|
||||||
|
public static final String NDG_AVAILABLE = "ndg.available";
|
||||||
|
public static final String NDG_GENERATION_IS_IN_PROGRESS = "ndg.generation.in.progress";
|
||||||
|
public static final String NDG_GENERATED = "NDG_GENERATED";
|
||||||
|
public static final String NDG_FAILED = "FAILED";
|
||||||
|
public static final String NDG_NOT_FOUND_FOR_APPLICATION = "ndg.not.found.for.this.application.or.invalid";
|
||||||
|
public static final String APPOINTMENT_ALREADY_CREATED = "appointment.already.created";
|
||||||
|
public static final String EXTERNAL_DOCUMENT_UPLOAD_FAILURE_MSG = "document.not.uploaded.to.external.system.please.try.again";
|
||||||
|
public static final String PROVIDE_VALID_APPLICATION_DOC_ID = "provide.valid.application.document.id";
|
||||||
|
public static final String DOCUMENT_UPLOADED_SUCCESSFULLY_TO_EXTERNAL_SYSTEM = "document.uploaded.successfully.to.external.system";
|
||||||
|
public static final String ERROR_UPLOADING_DOCUMENT = "error.in.uploading.document.check.input";
|
||||||
|
public static final String DOCUMENT_ALREADY_UPLOADED = "document.already.uploaded";
|
||||||
|
public static final String NDG_NOT_MATCHED_OR_NOT_FOUND = "ndg.not.found.or.not.matched";
|
||||||
|
public static final String NO_NDG_FOR_ANOTHER_HUB = "ndg.generation.is.only.for.gepafin";
|
||||||
|
public static final String NO_APPOINTMENT_FOR_ANOTHER_HUB = "appointment.creation.is.only.for.gepafin";
|
||||||
|
public static final String NO_DOCUMENT_UPLOAD_FOR_ANOTHER_HUB = "upload.document.is.only.for.gepafin";
|
||||||
|
public static final String APPOINTMENT_CREATED = "appointment.created.successfully";
|
||||||
|
public static final String DATA_STRING = "data";
|
||||||
|
public static final String DOCUMENT_ATTACHMENT_ID_STRING = "documentAttachmentId";
|
||||||
|
public static final String TEMP_FILE_PATH = "/tmp/";
|
||||||
|
public static final String RICHIESTA_CLIENTE_STRING = "richiestaCliente";
|
||||||
|
public static final String ID_STRING = "id";
|
||||||
|
public static final String NULL_STRING = "null";
|
||||||
|
public static final String NDG_STRING = "ndg";
|
||||||
|
public static final String ID_VISURA_STRING = "idVisura";
|
||||||
|
public static final String NDG_FETCH_SUCCESSFULLY = "ndg.fetch.successfully";
|
||||||
|
public static final String AUTH_JWT_SECRET_KEY = "hTa5qe$af/4',BFs";
|
||||||
|
public static final String JWT_ALGO_HEADER = "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
|
||||||
|
public static final String HMAC_ALGO = "HmacSHA256";
|
||||||
|
public static final String ERROR_IN_GENERATING_NDG_TRY_AGAIN = "error.try.again";
|
||||||
|
public static final String POLLING_THREAD_NAME = "Ndg-Polling-Thread-";
|
||||||
|
public static final String DOCUMENT_UPLOADING_IN_PROGRESS = "document.uploading.is.in.progress";
|
||||||
|
public static final String ASYNC_DOCUMENT_UPLOAD_NAME = "AsyncDocumentUpload-";
|
||||||
|
public static final String All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED="all.document.checked.and.one.checklist.checked";
|
||||||
|
|
||||||
|
//Notification
|
||||||
|
public static final String COMMON_SINGLE_CHANNEL_PREFIX = "/topic/notifications_user_";
|
||||||
|
public static final String COMPANY_PREFIX = "_company_";
|
||||||
|
public static final String NOTIFICATION_SENT_SUCCESSFULLY = "notification.sent.successfully";
|
||||||
|
public static final String NOTIFICATION_FETCHED_SUCCESSFULLY= "notification.fetched.successfully";
|
||||||
|
public static final String NOTIFICATION_NOT_FOUND= "notification.not.found";
|
||||||
|
public static final String NOTIFICATION_ALREADY_IN_THAT_STATE="notification.already.in.state";
|
||||||
|
public static final String NOTIFICATION_DELETED_SUCCESSFULLY="notification.deleted.successfully";
|
||||||
|
public static final String NOTIFICATION_UPDATED_SUCCESSFULLY="notification.updated.successfully";
|
||||||
|
public static final String USER_WITH_COMPANY_NOT_FOUND = "user.with.company.not.found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.time.temporal.ChronoUnit.DAYS;
|
||||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
|
||||||
@@ -92,6 +93,9 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmailLogDao emailLogDao;
|
private EmailLogDao emailLogDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
LoggingUtil loggingUtil;
|
LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@@ -101,12 +105,44 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AssignedApplicationsDao assignedApplicationsDao;
|
private AssignedApplicationsDao assignedApplicationsDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentRepository documentRepository;
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationDao notificationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||||
Long applicationId = applicationEvaluationEntity.getApplicationId();
|
Long applicationId = applicationEvaluationEntity.getApplicationId();
|
||||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
List<FieldRequest> evaluationFileRequests=new ArrayList<>();
|
||||||
|
List<ChecklistRequest> checklistRequests=new ArrayList<>();
|
||||||
|
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
String file=applicationEvaluationEntity.getFile();
|
||||||
|
String checkList=applicationEvaluationEntity.getChecklist();
|
||||||
|
if(file != null){
|
||||||
|
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
|
||||||
|
}
|
||||||
|
Boolean allValid = evaluationFileRequests.stream()
|
||||||
|
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
|
||||||
|
if(checkList != null) {
|
||||||
|
checklistRequests=Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
|
||||||
|
}
|
||||||
|
boolean resultCheckList = checklistRequests.stream()
|
||||||
|
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
|
||||||
|
|
||||||
|
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
|
||||||
|
}
|
||||||
// Set common application-level details
|
// Set common application-level details
|
||||||
String callName = application.getCall().getName();
|
String callName = application.getCall().getName();
|
||||||
Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null)
|
Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null)
|
||||||
@@ -131,11 +167,18 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
|
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
|
||||||
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||||
|
Map<String, FieldRequest> fieldRequestMap = evaluationFileRequests.stream()
|
||||||
|
.collect(Collectors.toMap(FieldRequest::getId, fieldRequest -> fieldRequest));
|
||||||
for (ApplicationFormEntity form : forms) {
|
for (ApplicationFormEntity form : forms) {
|
||||||
String content = form.getForm().getContent();
|
String content = form.getForm().getContent();
|
||||||
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||||
allFormFields.addAll(getIdAndLabelFromResult(result));
|
List<AmendmentFormFieldResponse> amendmentFormFieldResponses= getIdAndLabelFromResult(result);
|
||||||
|
amendmentFormFieldResponses.removeIf(amendmentFormFieldResponse -> {
|
||||||
|
FieldRequest matchingRequest = fieldRequestMap.get(amendmentFormFieldResponse.getFieldId());
|
||||||
|
// Remove if no matching FieldRequest exists or if valid is true
|
||||||
|
return matchingRequest == null || Boolean.TRUE.equals(matchingRequest.getValid());
|
||||||
|
});
|
||||||
|
allFormFields.addAll(amendmentFormFieldResponses);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setFormFields(allFormFields);
|
response.setFormFields(allFormFields);
|
||||||
@@ -196,7 +239,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
log.info("Submiting application data for amendment Process with details: {}", applicationEvaluationId);
|
log.info("Submiting application data for amendment Process with details: {}", applicationEvaluationId);
|
||||||
|
|
||||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest, applicationEvaluationId);
|
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest, applicationEvaluationId);
|
||||||
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity);
|
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity,false);
|
||||||
log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse);
|
log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse);
|
||||||
if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) {
|
if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) {
|
||||||
emailNotificationDao.sendMailToNotifyBeneficiaryRegardingNewAmendment(applicationAmendmentRequestEntity);
|
emailNotificationDao.sendMailToNotifyBeneficiaryRegardingNewAmendment(applicationAmendmentRequestEntity);
|
||||||
@@ -208,6 +251,11 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = new ApplicationAmendmentRequestEntity();
|
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = new ApplicationAmendmentRequestEntity();
|
||||||
applicationAmendmentRequestEntity.setNote(applicationAmendmentRequest.getNote());
|
applicationAmendmentRequestEntity.setNote(applicationAmendmentRequest.getNote());
|
||||||
applicationAmendmentRequestEntity.setResponseDays(applicationAmendmentRequest.getResponseDays());
|
applicationAmendmentRequestEntity.setResponseDays(applicationAmendmentRequest.getResponseDays());
|
||||||
|
if(applicationAmendmentRequest.getResponseDays()==null || applicationAmendmentRequest.getResponseDays() < 0){
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.RESPONSE_DAYS_NOT_NULL));
|
||||||
|
}
|
||||||
|
applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()).plusDays(applicationAmendmentRequest.getResponseDays()));
|
||||||
|
|
||||||
applicationAmendmentRequestEntity.setIsEmail(applicationAmendmentRequest.getIsSendEmail());
|
applicationAmendmentRequestEntity.setIsEmail(applicationAmendmentRequest.getIsSendEmail());
|
||||||
applicationAmendmentRequestEntity.setIsNotification(applicationAmendmentRequest.getIsSendNotification());
|
applicationAmendmentRequestEntity.setIsNotification(applicationAmendmentRequest.getIsSendNotification());
|
||||||
applicationAmendmentRequestEntity.setStartDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
applicationAmendmentRequestEntity.setStartDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
@@ -228,17 +276,32 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
AmendmentFormField formField = new AmendmentFormField();
|
AmendmentFormField formField = new AmendmentFormField();
|
||||||
formField.setFieldId(amendmentFormFieldRequest.getFieldId());
|
formField.setFieldId(amendmentFormFieldRequest.getFieldId());
|
||||||
formField.setFieldValue(null);
|
formField.setFieldValue(null);
|
||||||
|
formField.setLabel(amendmentFormFieldRequest.getLabel());
|
||||||
return formField;
|
return formField;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
String formFieldsJson = Utils.convertObjectToJson(formFieldRequestBean);
|
String formFieldsJson = Utils.convertObjectToJson(formFieldRequestBean);
|
||||||
applicationAmendmentRequestEntity.setFormFields(formFieldsJson);
|
applicationAmendmentRequestEntity.setFormFields(formFieldsJson);
|
||||||
}
|
}
|
||||||
|
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(applicationEvaluationEntity.getId());
|
||||||
|
// Ensure startDate and initialDays are not null to avoid NullPointerException
|
||||||
|
if (amendmentRequest !=null && amendmentRequest.isEmpty() && applicationEvaluationEntity.getStartDate() != null && applicationEvaluationEntity.getInitialDays() != null ) {
|
||||||
|
Long initialDays = applicationEvaluationEntity.getInitialDays();
|
||||||
|
LocalDateTime startDate = applicationEvaluationEntity.getStartDate();
|
||||||
|
LocalDateTime nowInUTC = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
// Calculate remaining days
|
||||||
|
Long remainingDays = initialDays - DAYS.between(startDate, nowInUTC);
|
||||||
|
// Set remaining days in the entity
|
||||||
|
applicationEvaluationEntity.setRemainingDays(remainingDays);
|
||||||
|
//Set stop date time in the entity becuase amendment has started
|
||||||
|
applicationEvaluationEntity.setStopDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
}
|
||||||
|
|
||||||
UserEntity userEntity = userService.validateUser(applicationEvaluationEntity.getUserId());
|
UserEntity userEntity = userService.validateUser(applicationEvaluationEntity.getUserId());
|
||||||
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
||||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(
|
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(
|
||||||
applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber,
|
applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber,
|
||||||
userEntity.getHub().getId());
|
userEntity.getHub().getId(),false);
|
||||||
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
|
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
|
||||||
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
|
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
|
||||||
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
||||||
@@ -271,6 +334,10 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.SOCCORSO.getValue());
|
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.SOCCORSO.getValue());
|
||||||
assignedApplicationsRepository.save(assignedApplicationsEntity);
|
assignedApplicationsRepository.save(assignedApplicationsEntity);
|
||||||
|
|
||||||
|
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(applicationEntity, NotificationTypeEnum.AMENDMENT_CREATION);
|
||||||
|
|
||||||
|
notificationDao.sendNotificationToInstructor(placeHolders,applicationAmendmentRequestEntity.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CREATION);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update Assigned Application" operation. **/
|
/** This code is responsible for adding a version history log for the "Update Assigned Application" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplication).newData(assignedApplicationsEntity).build());
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplication).newData(assignedApplicationsEntity).build());
|
||||||
}
|
}
|
||||||
@@ -278,6 +345,25 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
return applicationAmendment;
|
return applicationAmendment;
|
||||||
}
|
}
|
||||||
|
private void setAmendmentDocuments(String amendmentNotes, String amendmentFieldRequest,
|
||||||
|
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||||
|
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
|
||||||
|
if (amendmentFieldRequest != null && !amendmentFieldRequest.trim().isEmpty()) {
|
||||||
|
String[] documentIds = amendmentFieldRequest.split(",");
|
||||||
|
String validDocumentIds = Arrays.stream(documentIds)
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(id -> !id.isEmpty())
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
|
||||||
|
amendmentDetails.setAmendmentDocuments(validDocumentIds);
|
||||||
|
}
|
||||||
|
if (amendmentNotes != null && !amendmentNotes.trim().isEmpty()) {
|
||||||
|
amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
|
||||||
|
}
|
||||||
|
amendmentDetails.setValid(null);
|
||||||
|
String amendmentDetailsJson = Utils.convertObjectToString(amendmentDetails);
|
||||||
|
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
|
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
|
||||||
ApplicationAmendmentRequestEntity applicationAmendmentRequest = applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
ApplicationAmendmentRequestEntity applicationAmendmentRequest = applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
@@ -288,23 +374,81 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
return applicationAmendmentRequest;
|
return applicationAmendmentRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,boolean includeEmailContent) {
|
||||||
ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity);
|
ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity,includeEmailContent);
|
||||||
|
|
||||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
|
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
|
||||||
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
|
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
|
||||||
|
// List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>();
|
||||||
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
|
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
|
||||||
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
||||||
|
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||||
|
|
||||||
|
// List<AmendmentDetailsResponseBean> amendmentDetailsList =
|
||||||
|
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
|
||||||
|
// AmendmentDetailsResponseBean.class);
|
||||||
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument() ,AmendmentDetailsResponseBean.class);
|
||||||
|
if(amendmentDetails!=null) {
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||||
|
// Extract the comma-separated document IDs as a string
|
||||||
|
String documentIdsString = amendmentDetails.getAmendmentDocuments();
|
||||||
|
|
||||||
|
if (documentIdsString != null && !documentIdsString.trim().isEmpty()) {
|
||||||
|
// Split the comma-separated values and process them
|
||||||
|
List<String> documentIds = Arrays.stream(documentIdsString.split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(id -> !id.isEmpty())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
documentResponseBeans.addAll(
|
||||||
|
documentIds.stream()
|
||||||
|
.map(id -> {
|
||||||
|
try {
|
||||||
|
return createDocumentResponseBean(id); // Convert to Long
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Handle invalid document IDs gracefully
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull) // Skip null responses
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
|
||||||
|
response.setValid(amendmentDetails.getValid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response.setAmendmentDocuments(documentResponseBeans);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
|
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
public DocumentResponseBean createDocumentResponseBean(String documentId) {
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(documentId)) {
|
||||||
|
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(documentId));
|
||||||
|
if(documentEntity.isPresent()){
|
||||||
|
return applicationEvaluationDao.createDocumentResponseBean(documentEntity.get());
|
||||||
|
}}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity,boolean includeEmailContent) {
|
||||||
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
||||||
|
ApplicationEntity applicationEntity = entity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication();
|
||||||
|
Long hubId = applicationEntity.getHubId();
|
||||||
|
HubEntity hubEntity = hubService.valdateHub(hubId);
|
||||||
|
|
||||||
response.setId(entity.getId());
|
response.setId(entity.getId());
|
||||||
response.setApplicationId(entity.getApplicationId());
|
response.setApplicationId(entity.getApplicationId());
|
||||||
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
|
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
|
||||||
@@ -315,7 +459,8 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
LocalDateTime startDate = entity.getStartDate();
|
LocalDateTime startDate = entity.getStartDate();
|
||||||
response.setStartDate(startDate);
|
response.setStartDate(startDate);
|
||||||
response.setExpirationDate(startDate.plus(expirationDays, ChronoUnit.DAYS));
|
response.setExpirationDate(entity.getEndDate());
|
||||||
|
response.setEvaluationEndDate(entity.getApplicationEvaluationEntity().getEndDate());
|
||||||
response.setIsSendEmail(entity.getIsEmail());
|
response.setIsSendEmail(entity.getIsEmail());
|
||||||
response.setIsSendNotification(entity.getIsNotification());
|
response.setIsSendNotification(entity.getIsNotification());
|
||||||
|
|
||||||
@@ -325,10 +470,17 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
UserEntity userEntity = userService.validateUser(application.getUserId());
|
UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||||
response.setBeneficiaryName(buildBeneficiaryName(userEntity));
|
response.setBeneficiaryName(buildBeneficiaryName(userEntity));
|
||||||
|
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||||
|
response.setCompanyName(company.getCompanyName());
|
||||||
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
|
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
|
||||||
response.setProtocolNumber(protocolNumber);
|
response.setProtocolNumber(protocolNumber);
|
||||||
|
|
||||||
|
if (includeEmailContent) {
|
||||||
|
Map<String, String> bodyPlaceholders = emailNotificationDao.prepareEmailPlaceholders(applicationEntity, entity);
|
||||||
|
EmailContentResponse emailContent = emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, hubEntity, bodyPlaceholders);
|
||||||
|
String body = emailContent.getBody();
|
||||||
|
response.setEmailTemplate(body);
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,6 +525,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
return responseBean;
|
return responseBean;
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
@@ -434,7 +587,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(Long id) {
|
public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(Long id) {
|
||||||
log.info("Fetching application amendment with ID: {}", id);
|
log.info("Fetching application amendment with ID: {}", id);
|
||||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
|
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
|
||||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity);
|
ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity,true);
|
||||||
log.info("Application Amendment fetched successfully by ID: {}", response);
|
log.info("Application Amendment fetched successfully by ID: {}", response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -451,7 +604,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
applicationAmendmentRequestRepository.findAll(spec);
|
applicationAmendmentRequestRepository.findAll(spec);
|
||||||
|
|
||||||
return applicationAmendmentRequestEntities.stream()
|
return applicationAmendmentRequestEntities.stream()
|
||||||
.map(this::convertEntityToResponse)
|
.map(entity -> convertEntityToResponse(entity, false))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +627,20 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
log.info("Updating application amendement with ID: {}", id);
|
log.info("Updating application amendement with ID: {}", id);
|
||||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||||
|
Boolean isBeneficiary=false;
|
||||||
|
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||||
|
validator.validatePreInstructor(request, existingApplicationAmendment.getApplicationEvaluationEntity().getUserId());
|
||||||
|
isBeneficiary=false;
|
||||||
|
} else {
|
||||||
|
validator.validateUserId(request, existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||||
|
isBeneficiary=true;
|
||||||
|
}
|
||||||
|
if(Boolean.TRUE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue())){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||||
|
}
|
||||||
|
if(Boolean.FALSE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||||
|
}
|
||||||
|
|
||||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||||
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
|
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
|
||||||
@@ -486,16 +653,18 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
if(updateRequest.getApplicationFormFields() != null) {
|
if(updateRequest.getApplicationFormFields() != null) {
|
||||||
updateRequest.getApplicationFormFields().stream().forEach(applicationFormFieldRequest->{
|
updateRequest.getApplicationFormFields().stream().forEach(applicationFormFieldRequest->{
|
||||||
AmendmentFormField amendmentFormField = getAmendmentFormField(amendmentFormFieldMap,applicationFormFieldRequest.getFieldId());
|
AmendmentFormField amendmentFormField = getAmendmentFormField(amendmentFormFieldMap,applicationFormFieldRequest.getFieldId());
|
||||||
ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
|
// ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
|
||||||
updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
|
// updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
|
||||||
updateFormField(applicationFormFieldRequest, amendmentFormField);
|
updateFormField(applicationFormFieldRequest, amendmentFormField);
|
||||||
});
|
});
|
||||||
existingApplicationAmendment.setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
|
existingApplicationAmendment.setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
|
||||||
}
|
}
|
||||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) {
|
||||||
|
setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
|
||||||
|
}
|
||||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
|
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
|
||||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
|
||||||
log.info("Application Amendment updated successfully: {}", response);
|
log.info("Application Amendment updated successfully: {}", response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -560,13 +729,13 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
String fieldId) {
|
String fieldId) {
|
||||||
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
|
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
|
||||||
if (amendmentFormField == null) {
|
if (amendmentFormField == null) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND));
|
||||||
}
|
}
|
||||||
return amendmentFormField;
|
return amendmentFormField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateFormField(ApplicationFormFieldRequestBean applicationFormFieldRequest,
|
private void updateFormField(AmendmentFormFieldRequest applicationFormFieldRequest,
|
||||||
AmendmentFormField amendmentFormField) {
|
AmendmentFormField amendmentFormField) {
|
||||||
List<Long> requestedDocumentIds = extractIds(applicationFormFieldRequest.getFieldValue());
|
List<Long> requestedDocumentIds = extractIds(applicationFormFieldRequest.getFieldValue());
|
||||||
List<Long> existingDocumentIds = extractIds(amendmentFormField.getFieldValue());
|
List<Long> existingDocumentIds = extractIds(amendmentFormField.getFieldValue());
|
||||||
@@ -575,7 +744,8 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
if (!existingDocumentIds.isEmpty()) {
|
if (!existingDocumentIds.isEmpty()) {
|
||||||
existingDocumentIds.forEach(this::softDeleteDocument);
|
existingDocumentIds.forEach(this::softDeleteDocument);
|
||||||
amendmentFormField.setFieldValue(null);
|
amendmentFormField.setFieldValue(null);
|
||||||
setIsUploadedBy(amendmentFormField);
|
amendmentFormField.setValid(applicationFormFieldRequest.getValid());
|
||||||
|
// setIsUploadedBy(amendmentFormField);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -589,11 +759,12 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
if (!newFieldValue.equals(amendmentFormField.getFieldValue())) {
|
if (!newFieldValue.equals(amendmentFormField.getFieldValue())) {
|
||||||
amendmentFormField.setFieldValue(newFieldValue);
|
amendmentFormField.setFieldValue(newFieldValue);
|
||||||
setIsUploadedBy(amendmentFormField);
|
amendmentFormField.setValid(applicationFormFieldRequest.getValid());
|
||||||
|
// setIsUploadedBy(amendmentFormField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Long> extractIds(Object fieldValue) {
|
public List<Long> extractIds(Object fieldValue) {
|
||||||
if (fieldValue instanceof String && !StringUtils.isEmpty((String) fieldValue)) {
|
if (fieldValue instanceof String && !StringUtils.isEmpty((String) fieldValue)) {
|
||||||
return Arrays.stream(((String) fieldValue).split(","))
|
return Arrays.stream(((String) fieldValue).split(","))
|
||||||
.map(Long::valueOf)
|
.map(Long::valueOf)
|
||||||
@@ -604,14 +775,14 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
|
// private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
|
||||||
if(validator.checkIsBeneficiary()) {
|
// if(validator.checkIsBeneficiary()) {
|
||||||
amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
|
// amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
|
||||||
}else {
|
// }else {
|
||||||
amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
|
// amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
// private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
// private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||||
@@ -794,7 +965,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
|
applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
|
||||||
|
|
||||||
return entities.stream()
|
return entities.stream()
|
||||||
.map(this::convertEntityToResponse)
|
.map(entity -> convertEntityToResponse(entity, false))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,13 +975,25 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||||
//cloned entity for old data and versioning
|
//cloned entity for old data and versioning
|
||||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||||
|
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||||
|
existingApplicationAmendment.getApplicationEvaluationEntity().getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if this is the last amendment being closed
|
||||||
|
boolean isLastRemaining = amendmentRequestList.stream()
|
||||||
|
.filter(amendment -> !amendment.getId().equals(id)) // Exclude the current amendment
|
||||||
|
.allMatch(amendment -> amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()));
|
||||||
|
|
||||||
|
if (isLastRemaining) {
|
||||||
|
log.info("The current amendment is the last remaining one to be closed.");
|
||||||
|
applicationAmendmentRequestDao.calculateEndDateAndSuspensionDays(existingApplicationAmendment.getApplicationEvaluationEntity());
|
||||||
|
}
|
||||||
setIfUpdated(existingApplicationAmendment::getInternalNote, existingApplicationAmendment::setInternalNote, closeAmendmentRequest.getInternalNote());
|
setIfUpdated(existingApplicationAmendment::getInternalNote, existingApplicationAmendment::setInternalNote, closeAmendmentRequest.getInternalNote());
|
||||||
setIfUpdated(existingApplicationAmendment::getStatus, existingApplicationAmendment::setStatus, ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
setIfUpdated(existingApplicationAmendment::getStatus, existingApplicationAmendment::setStatus, ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
||||||
|
|
||||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment, oldApplicationAmendmentEntity,
|
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment, oldApplicationAmendmentEntity,
|
||||||
VersionActionTypeEnum.UPDATE);
|
VersionActionTypeEnum.UPDATE);
|
||||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
|
||||||
|
|
||||||
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||||
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
||||||
@@ -837,6 +1020,11 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
AssignedApplicationsEntity oldAssignedApplicationData = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
AssignedApplicationsEntity oldAssignedApplicationData = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
||||||
assignedApplicationsEntity = assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
|
assignedApplicationsEntity = assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.AMENDMENT_CLOSED);
|
||||||
|
|
||||||
|
notificationDao.sendNotificationToInstructor(placeHolders,existingApplicationAmendment.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CLOSED);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
|
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity)
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity)
|
||||||
.newData(existingApplicationEvaluationEntity).build());
|
.newData(existingApplicationEvaluationEntity).build());
|
||||||
@@ -856,22 +1044,21 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
|
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
|
||||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id)
|
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
|
||||||
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
|
|
||||||
|
|
||||||
if (newResponseDays != null && newResponseDays > 0) {
|
if (newResponseDays != null && newResponseDays > 0) {
|
||||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
|
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
|
||||||
Long currentResponseDays = applicationAmendmentRequestEntity.getResponseDays() != null ? applicationAmendmentRequestEntity.getResponseDays() : 0L;
|
Long currentResponseDays = applicationAmendmentRequestEntity.getResponseDays() != null ? applicationAmendmentRequestEntity.getResponseDays() : 0L;
|
||||||
applicationAmendmentRequestEntity.setResponseDays(currentResponseDays + newResponseDays);
|
applicationAmendmentRequestEntity.setResponseDays(currentResponseDays + newResponseDays);
|
||||||
|
applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now().plusDays(applicationAmendmentRequestEntity.getResponseDays())));
|
||||||
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(applicationAmendmentRequestEntity).build());
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(applicationAmendmentRequestEntity).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
return convertEntityToResponse(applicationAmendmentRequestEntity);
|
return convertEntityToResponse(applicationAmendmentRequestEntity,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationAmendmentRequestResponse> getAmendmentByApplicationId(HttpServletRequest request, Long applicationId, List<ApplicationAmendmentRequestEnum> statuses) {
|
public List<ApplicationAmendmentRequestResponse> getAmendmentByApplicationId(HttpServletRequest request, Long applicationId, List<ApplicationAmendmentRequestEnum> statuses) {
|
||||||
@@ -896,7 +1083,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
List<ApplicationAmendmentRequestResponse> response = new ArrayList<>();
|
List<ApplicationAmendmentRequestResponse> response = new ArrayList<>();
|
||||||
if (applicationAmendmentRequestEntity != null) {
|
if (applicationAmendmentRequestEntity != null) {
|
||||||
response = applicationAmendmentRequestEntity.stream()
|
response = applicationAmendmentRequestEntity.stream()
|
||||||
.map(this::convertEntityToResponse)
|
.map(entity -> convertEntityToResponse(entity, false))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
@@ -908,7 +1095,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
log.info("Updating application amendment with status: {}", id);
|
log.info("Updating application amendment with status: {}", id);
|
||||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||||
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) || Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) && Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
||||||
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
applicationAmendmentRequestRepository.save(existingApplicationAmendment);
|
applicationAmendmentRequestRepository.save(existingApplicationAmendment);
|
||||||
@@ -916,7 +1103,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(existingApplicationAmendment).build());
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(existingApplicationAmendment).build());
|
||||||
}
|
}
|
||||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(existingApplicationAmendment);
|
ApplicationAmendmentRequestResponse response = convertEntityToResponse(existingApplicationAmendment,false);
|
||||||
log.info("Amendment status updated successfully: {}", response);
|
log.info("Amendment status updated successfully: {}", response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -966,13 +1153,32 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
LocalDateTime dueDate = amendment.getStartDate().plusDays(amendment.getResponseDays());
|
LocalDateTime dueDate = amendment.getStartDate().plusDays(amendment.getResponseDays());
|
||||||
bodyPlaceholders.put("{{amendment_due_date}}", DateTimeUtil.formatLocalDateTime(dueDate, GepafinConstant.DD_MM_YYYY));
|
bodyPlaceholders.put("{{amendment_due_date}}", DateTimeUtil.formatLocalDateTime(dueDate, GepafinConstant.DD_MM_YYYY));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
bodyPlaceholders.put("{{amendment_due_date}}", "Not available");
|
bodyPlaceholders.put("{{amendment_due_date}}", "Not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Utils.replacePlaceholders(template.getHtmlContent(), bodyPlaceholders);
|
return Utils.replacePlaceholders(template.getHtmlContent(), bodyPlaceholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApplicationEvaluationEntity calculateEndDateAndSuspensionDays(ApplicationEvaluationEntity applicationEvaluationEntity){
|
||||||
|
LocalDateTime currentDate=DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
LocalDateTime endDate=currentDate.plusDays(applicationEvaluationEntity.getRemainingDays());
|
||||||
|
Long suspendedDays = ChronoUnit.DAYS.between(applicationEvaluationEntity.getStopDateTime(), currentDate);
|
||||||
|
|
||||||
|
ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(applicationEvaluationEntity);
|
||||||
|
applicationEvaluationEntity.setEndDate(endDate);
|
||||||
|
if(applicationEvaluationEntity.getSuspendedDays() == null) {
|
||||||
|
applicationEvaluationEntity.setSuspendedDays(0L);
|
||||||
|
}
|
||||||
|
applicationEvaluationEntity.setSuspendedDays(applicationEvaluationEntity.getSuspendedDays()+suspendedDays);
|
||||||
|
ApplicationEvaluationEntity applicationEvaluation = applicationEvaluationRepository.save(applicationEvaluationEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(applicationEvaluation).build());
|
||||||
|
|
||||||
|
return applicationEvaluation;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
private void softDeleteDocument(Long documentId) {
|
private void softDeleteDocument(Long documentId) {
|
||||||
documentService.deleteFile(documentId);
|
documentService.deleteFile(documentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea
|
|||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationEvaluationService;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.service.CompanyService;
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.DocumentService;
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
@@ -149,6 +151,9 @@ public class ApplicationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmailLogDao emailLogDao;
|
private EmailLogDao emailLogDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@@ -156,14 +161,29 @@ public class ApplicationDao {
|
|||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenProvider tokenProvider;
|
private ApplicationEvaluationService applicationEvaluationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationDao notificationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||||
|
|
||||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
// callService.validatePublishedCall(formEntity.getCall().getId());
|
// callService.validatePublishedCall(formEntity.getCall().getId());
|
||||||
validateFormFields(applicationRequestBean,formEntity);
|
validateFormFields(applicationRequestBean,formEntity);
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
if(Boolean.FALSE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.DRAFT.getValue()))) {
|
if(Boolean.FALSE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.DRAFT.getValue()))) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
||||||
}
|
}
|
||||||
@@ -172,12 +192,10 @@ public class ApplicationDao {
|
|||||||
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity, formEntity);
|
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity, formEntity);
|
||||||
return getApplicationById(applicationEntity.getId(),formEntity.getId());
|
return getApplicationById(applicationEntity.getId(),formEntity.getId());
|
||||||
}
|
}
|
||||||
|
public void validateDelegation(UserEntity user, UserWithCompanyEntity userWithCompany) {
|
||||||
public void validateDelegation(UserEntity user, CompanyEntity company) {
|
|
||||||
UserWithCompanyEntity userWithCompany = companyService.getUserWithCompanyEntity(user.getId(), company.getId());
|
|
||||||
|
|
||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
.findByUserIdAndCompanyIdAndStatus(user.getId(), company.getId(),
|
.findByUserIdAndUserWithCompanyIdAndStatus(user.getId(), userWithCompany.getId(),
|
||||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
|
||||||
if (!userWithCompany.getIsLegalRepresentant() && userCompanyDelegationEntity == null) {
|
if (!userWithCompany.getIsLegalRepresentant() && userCompanyDelegationEntity == null) {
|
||||||
@@ -200,13 +218,14 @@ public class ApplicationDao {
|
|||||||
return applicationFormEntity;
|
return applicationFormEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, CompanyEntity companyEntity) {
|
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, UserWithCompanyEntity userWithCompany) {
|
||||||
validateDelegation(user,companyEntity);
|
validateDelegation(user,userWithCompany);
|
||||||
ApplicationEntity entity = new ApplicationEntity();
|
ApplicationEntity entity = new ApplicationEntity();
|
||||||
entity.setUserId(user.getId());
|
entity.setUserId(user.getId());
|
||||||
entity.setCompany(companyEntity);
|
entity.setCompanyId(userWithCompany.getCompanyId());
|
||||||
entity.setCall(call);
|
entity.setCall(call);
|
||||||
entity.setHubId(call.getHub().getId());
|
entity.setHubId(call.getHub().getId());
|
||||||
|
entity.setUserWithCompany(userWithCompany);
|
||||||
entity.setIsDeleted(false);
|
entity.setIsDeleted(false);
|
||||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||||
return entity;
|
return entity;
|
||||||
@@ -275,9 +294,11 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
log.info("Deleting application with ID: {}", id);
|
log.info("Deleting application with ID: {}", id);
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(id);
|
ApplicationEntity applicationEntity= validateApplication(id);
|
||||||
|
|
||||||
ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
|
ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
|
||||||
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
applicationEntity.setIsDeleted(true);
|
applicationEntity.setIsDeleted(true);
|
||||||
applicationEntity = applicationRepository.save(applicationEntity);
|
applicationEntity = applicationRepository.save(applicationEntity);
|
||||||
|
|
||||||
@@ -349,7 +370,7 @@ public class ApplicationDao {
|
|||||||
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
||||||
}
|
}
|
||||||
if (companyId != null) {
|
if (companyId != null) {
|
||||||
predicate = builder.and(predicate, builder.equal(root.get("company").get("id"), companyId));
|
predicate = builder.and(predicate, builder.equal(root.get("companyId"), companyId));
|
||||||
}
|
}
|
||||||
if (statusList != null && !statusList.isEmpty()) {
|
if (statusList != null && !statusList.isEmpty()) {
|
||||||
List<String> statusNames = statusList.stream()
|
List<String> statusNames = statusList.stream()
|
||||||
@@ -381,8 +402,19 @@ public class ApplicationDao {
|
|||||||
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||||
responseBean.setStatus(applicationEntity.getStatus());
|
responseBean.setStatus(applicationEntity.getStatus());
|
||||||
responseBean.setComments(applicationEntity.getComments());
|
responseBean.setComments(applicationEntity.getComments());
|
||||||
responseBean.setCompanyId(applicationEntity.getCompany().getId());
|
responseBean.setCompanyId(applicationEntity.getCompanyId());
|
||||||
responseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||||
|
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
|
||||||
|
if(assignedApplicationsOptional.isPresent()){
|
||||||
|
responseBean.setAssignedUserId(assignedApplicationsOptional.get().getUserId());
|
||||||
|
UserEntity user = userService.validateUser(assignedApplicationsOptional.get().getUserId());
|
||||||
|
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||||
|
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||||
|
String userName = String.join(" ", firstName, lastName).trim();
|
||||||
|
responseBean.setAssignedUserName(userName);
|
||||||
|
}
|
||||||
|
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
|
responseBean.setCompanyName(company.getCompanyName());
|
||||||
if(applicationEntity.getProtocol() != null) {
|
if(applicationEntity.getProtocol() != null) {
|
||||||
responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
}
|
}
|
||||||
@@ -453,7 +485,7 @@ public class ApplicationDao {
|
|||||||
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||||
applicationFormFieldEntity = applicationFormFieldEntity1;
|
applicationFormFieldEntity = applicationFormFieldEntity1;
|
||||||
oldApplicationFormFieldData = Utils.getClonedEntityForData(applicationFormFieldEntity);
|
oldApplicationFormFieldData = Utils.getClonedEntityForData(applicationFormFieldEntity);
|
||||||
if (applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm())) {
|
if (applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm()) && checkIfRequestFieldIsDifferent(applicationFormFieldEntity1, applicationFormFieldRequestBean)) {
|
||||||
validateRequiredFields(applicationFormEntity.getForm(), applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
|
validateRequiredFields(applicationFormEntity.getForm(), applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
|
||||||
}
|
}
|
||||||
actionType = VersionActionTypeEnum.UPDATE;
|
actionType = VersionActionTypeEnum.UPDATE;
|
||||||
@@ -489,6 +521,29 @@ public class ApplicationDao {
|
|||||||
return applicationFormField;
|
return applicationFormField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean checkIfRequestFieldIsDifferent(ApplicationFormFieldEntity applicationFormFieldEntity,
|
||||||
|
ApplicationFormFieldRequestBean applicationFormFieldRequestBean) {
|
||||||
|
|
||||||
|
// Retrieve the field values from both objects
|
||||||
|
String entityFieldValue = applicationFormFieldEntity.getFieldValue();
|
||||||
|
Object requestFieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||||
|
|
||||||
|
// Check if both are null
|
||||||
|
if (entityFieldValue == null && requestFieldValue == null) {
|
||||||
|
return false; // No difference if both are null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare values
|
||||||
|
Boolean check = !Objects.equals(entityFieldValue, requestFieldValue);
|
||||||
|
|
||||||
|
// Additional comparison if both are non-null
|
||||||
|
if (Boolean.TRUE.equals(check) && entityFieldValue != null && requestFieldValue != null) {
|
||||||
|
check = !entityFieldValue.equals(requestFieldValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
|
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
|
||||||
List<String> preInstructorDocumentId,boolean isPreInstructor) {
|
List<String> preInstructorDocumentId,boolean isPreInstructor) {
|
||||||
if (newDocumentIds == null) {
|
if (newDocumentIds == null) {
|
||||||
@@ -750,11 +805,12 @@ public class ApplicationDao {
|
|||||||
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||||
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
||||||
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
|
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
|
||||||
applicationGetResponseBean.setCompanyId(applicationEntity.getCompany().getId());
|
applicationGetResponseBean.setCompanyId(applicationEntity.getCompanyId());
|
||||||
if(applicationEntity.getProtocol() != null) {
|
if(applicationEntity.getProtocol() != null) {
|
||||||
applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
}
|
}
|
||||||
applicationGetResponseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
|
applicationGetResponseBean.setCompanyName(company.getCompanyName());
|
||||||
return applicationGetResponseBean;
|
return applicationGetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,19 +827,21 @@ public class ApplicationDao {
|
|||||||
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
||||||
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
||||||
CallEntity call = callService.validateCall(callId);
|
CallEntity call = callService.validateCall(callId);
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyEntity.getId());
|
||||||
|
|
||||||
// call = callService.validatePublishedCall(call.getId());
|
// call = callService.validatePublishedCall(call.getId());
|
||||||
checkIfApplicationExists(call, companyEntity, userEntity);
|
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||||
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, companyEntity);
|
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
|
||||||
applicationEntity.setComments(applicationRequest.getComments());
|
applicationEntity.setComments(applicationRequest.getComments());
|
||||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||||
return getApplicationResponse(applicationEntity);
|
return getApplicationResponse(applicationEntity);
|
||||||
}
|
}
|
||||||
public void checkIfApplicationExists(CallEntity call, CompanyEntity companyEntity, UserEntity userEntity){
|
// public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndCompanyIdAndCallIdAndIsDeletedFalse(userEntity.getId(), companyEntity.getId(),call.getId());
|
// Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId(),call.getId());
|
||||||
if(applicationEntity.isPresent()){
|
// if(applicationEntity.isPresent()){
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
// throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||||
|
|
||||||
@@ -793,7 +851,7 @@ public class ApplicationDao {
|
|||||||
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||||
|
|
||||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
|
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_SUBMITTED_CANNOT_CHANGE));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_SUBMITTED_CANNOT_CHANGE));
|
||||||
}
|
}
|
||||||
@@ -804,11 +862,13 @@ public class ApplicationDao {
|
|||||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
|
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
|
||||||
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
|
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
|
||||||
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
||||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId());
|
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
|
||||||
applicationEntity.setProtocol(protocolEntity);
|
applicationEntity.setProtocol(protocolEntity);
|
||||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
||||||
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
applicationEntity = applicationRepository.save(applicationEntity);
|
applicationEntity = applicationRepository.save(applicationEntity);
|
||||||
|
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION);
|
||||||
|
notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for "Update application status" operation. **/
|
/** This code is responsible for adding a version history log for "Update application status" operation. **/
|
||||||
loggingUtil.addVersionHistory(
|
loggingUtil.addVersionHistory(
|
||||||
@@ -821,6 +881,9 @@ public class ApplicationDao {
|
|||||||
if (status.equals(ApplicationStatusTypeEnum.DRAFT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.AWAITING.getValue()))) {
|
if (status.equals(ApplicationStatusTypeEnum.DRAFT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.AWAITING.getValue()))) {
|
||||||
applicationEntity.setStatus(status.getValue());
|
applicationEntity.setStatus(status.getValue());
|
||||||
}
|
}
|
||||||
|
if(status.equals(ApplicationStatusTypeEnum.ADMISSIBLE) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){
|
||||||
|
applicationEntity.setStatus(status.getValue());
|
||||||
|
}
|
||||||
applicationEntity = applicationRepository.save(applicationEntity);
|
applicationEntity = applicationRepository.save(applicationEntity);
|
||||||
|
|
||||||
if (!status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
if (!status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||||
@@ -917,8 +980,9 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||||
CallEntity call =applicationEntity.getCall();
|
CallEntity call =applicationEntity.getCall();
|
||||||
CompanyEntity company = applicationEntity.getCompany();
|
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
ProtocolEntity protocol = applicationEntity.getProtocol();
|
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||||
|
ProtocolEntity protocol= applicationEntity.getProtocol();
|
||||||
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
||||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||||
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
|
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
|
||||||
@@ -949,8 +1013,8 @@ public class ApplicationDao {
|
|||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
||||||
List<String> recipientEmails = new ArrayList<>();
|
List<String> recipientEmails = new ArrayList<>();
|
||||||
// recipientEmails.add(email);
|
// recipientEmails.add(email);
|
||||||
String companyEmail = company.getEmail();
|
String companyEmail = userWithCompany.getEmail();
|
||||||
String contactEmail = company.getContactEmail();
|
String contactEmail = userWithCompany.getContactEmail();
|
||||||
|
|
||||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||||
recipientEmails.add(companyEmail);
|
recipientEmails.add(companyEmail);
|
||||||
@@ -960,7 +1024,7 @@ public class ApplicationDao {
|
|||||||
recipientEmails.add(contactEmail);
|
recipientEmails.add(contactEmail);
|
||||||
}
|
}
|
||||||
if(Boolean.FALSE.equals(recipientEmails.isEmpty())){
|
if(Boolean.FALSE.equals(recipientEmails.isEmpty())){
|
||||||
emailLogRequest.setRecipientId(applicationEntity.getCompany().getId());
|
emailLogRequest.setRecipientId(applicationEntity.getCompanyId());
|
||||||
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
||||||
emailLogRequest.setRecipientEmails(companyEmail);
|
emailLogRequest.setRecipientEmails(companyEmail);
|
||||||
}
|
}
|
||||||
@@ -968,7 +1032,7 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||||
CallEntity call = applicationEntity.getCall();
|
CallEntity call = applicationEntity.getCall();
|
||||||
CompanyEntity company = applicationEntity.getCompany();
|
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
ProtocolEntity protocol = applicationEntity.getProtocol();
|
ProtocolEntity protocol = applicationEntity.getProtocol();
|
||||||
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
||||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||||
@@ -1008,14 +1072,13 @@ public class ApplicationDao {
|
|||||||
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
||||||
}
|
}
|
||||||
|
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
||||||
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId, MultipartFile file) {
|
MultipartFile file) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
|
||||||
//cloned entity for old data
|
//cloned entity for old data
|
||||||
ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(applicationEntity);
|
ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(applicationEntity);
|
||||||
|
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
|
||||||
validateFileTypeForCall(file, applicationEntity);
|
validateFileTypeForCall(file, applicationEntity);
|
||||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
|
||||||
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
@@ -1069,7 +1132,7 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
private String generateS3PathForDelegation(Long callId, Long applicationId) {
|
private String generateS3PathForDelegation(Long callId, Long applicationId) {
|
||||||
try {
|
try {
|
||||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId);
|
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||||
}
|
}
|
||||||
@@ -1103,7 +1166,14 @@ public class ApplicationDao {
|
|||||||
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
|
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
// validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
|
|
||||||
|
if (validator.checkIsPreInstructor()) {
|
||||||
|
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluationByApplicationId(applicationId);
|
||||||
|
validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId());
|
||||||
|
} else {
|
||||||
|
validator.validateUserId(request, applicationEntity.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
@@ -1115,21 +1185,20 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
|
|
||||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||||
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
//cloned entity for old data
|
//cloned entity for old data
|
||||||
ApplicationSignedDocumentEntity oldApplicationSignedDocument = Utils.getClonedEntityForData(applicationSignedDocument);
|
ApplicationSignedDocumentEntity oldApplicationSignedDocument = Utils.getClonedEntityForData(applicationSignedDocument);
|
||||||
if (applicationSignedDocument == null) {
|
if(applicationSignedDocument == null) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
||||||
}
|
}
|
||||||
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
||||||
applicationSignedDocument = applicationSignedDocumentRepository.save(applicationSignedDocument);
|
applicationSignedDocument = applicationSignedDocumentRepository.save(applicationSignedDocument);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Delete signed document" operation. **/
|
|
||||||
loggingUtil.addVersionHistory(
|
loggingUtil.addVersionHistory(
|
||||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationSignedDocument).newData(applicationSignedDocument)
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationSignedDocument).newData(applicationSignedDocument)
|
||||||
.build());
|
.build());
|
||||||
@@ -1138,11 +1207,10 @@ public class ApplicationDao {
|
|||||||
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
|
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
|
||||||
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||||
|
|
||||||
userService.validateUser(applicationEntity.getUserId());
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
||||||
}
|
}
|
||||||
@@ -1164,47 +1232,43 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) {
|
public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
validateAssignedUser(request, applicationId);
|
validateAssignedUser(request, applicationId);
|
||||||
|
|
||||||
Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId);
|
Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId);
|
||||||
List<DocumentEntity> documents = documentRepository.findAllByIdInAndIsDeletedFalse(documentIds);
|
List<DocumentEntity> documents = documentRepository.findAllByIdInAndIsDeletedFalse(documentIds);
|
||||||
|
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
|
||||||
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository
|
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
List<DocumentEntity> amendmentDocuments = fetchAmendmentDocuments(applicationId);
|
||||||
if (documents.isEmpty() && signedDocument == null) {
|
List<DocumentEntity> evaluationDocuments = fetchEvaluationDocuments(applicationId);
|
||||||
|
if (documents.isEmpty() && signedDocument == null && amendmentDocuments.isEmpty() && evaluationDocuments.isEmpty()) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||||
}
|
}
|
||||||
return createZipWithDocuments(applicationEntity, documents, signedDocument, applicationId);
|
return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateAssignedUser(HttpServletRequest request, Long applicationId) {
|
private void validateAssignedUser(HttpServletRequest request, Long applicationId) {
|
||||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository
|
|
||||||
.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||||
if (assignedApplications != null) {
|
if (assignedApplications != null) {
|
||||||
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) {
|
private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) {
|
||||||
|
|
||||||
Set<Long> documentIds = new HashSet<>();
|
Set<Long> documentIds = new HashSet<>();
|
||||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||||
|
|
||||||
applicationForms.forEach(applicationForm -> {
|
applicationForms.forEach(applicationForm -> {
|
||||||
FormEntity formEntity = applicationForm.getForm();
|
FormEntity formEntity = applicationForm.getForm();
|
||||||
if (formEntity != null) {
|
if (formEntity != null) {
|
||||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||||
contentResponseBeans.stream()
|
contentResponseBeans.stream().filter(content -> "fileupload".equals(content.getName())).forEach(content -> {
|
||||||
.filter(content -> "fileupload".equals(content.getName()))
|
Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||||
.forEach(content -> {
|
|
||||||
Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository
|
|
||||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
|
||||||
content.getId(), applicationForm.getId(), applicationId);
|
content.getId(), applicationForm.getId(), applicationId);
|
||||||
formField.ifPresent(field -> {
|
formField.ifPresent(field -> {
|
||||||
if (field.getFieldValue() != null) {
|
if (field.getFieldValue() != null) {
|
||||||
Arrays.stream(field.getFieldValue().split(","))
|
Arrays.stream(field.getFieldValue().split(",")).map(String::trim).map(Long::valueOf).forEach(documentIds::add);
|
||||||
.map(String::trim)
|
|
||||||
.map(Long::valueOf)
|
|
||||||
.forEach(documentIds::add);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1213,41 +1277,76 @@ public class ApplicationDao {
|
|||||||
return documentIds;
|
return documentIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDocumentToZip(ZipOutputStream zos, String s3Folder, String filePath, String fileName) {
|
private List<DocumentEntity> fetchAmendmentDocuments(Long applicationId) {
|
||||||
|
|
||||||
|
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||||
|
Set<Long> amendmentIds = amendmentRequests.stream().map(ApplicationAmendmentRequestEntity::getId).collect(Collectors.toSet());
|
||||||
|
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(amendmentIds, DocumentSourceTypeEnum.AMENDMENT.getValue());
|
||||||
|
}
|
||||||
|
private List<DocumentEntity> fetchEvaluationDocuments(Long applicationId) {
|
||||||
|
|
||||||
|
Optional<ApplicationEvaluationEntity> evaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||||
|
if (evaluationEntity.isPresent()) {
|
||||||
|
Long evaluationId = evaluationEntity.get().getId();
|
||||||
|
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(Collections.singleton(evaluationId), DocumentSourceTypeEnum.EVALUATION.getValue());
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
private String fetchProtocolNumberForAmendment(Long amendmentRequestId) {
|
||||||
|
|
||||||
|
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentRequestId).orElse(null);
|
||||||
|
if (amendmentRequest != null && amendmentRequest.getProtocol() != null) {
|
||||||
|
return amendmentRequest.getProtocol().getProtocolNumber().toString();
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
private void addDocumentToZip(ZipOutputStream zos, String s3Folder, String filePath, String fullPath) {
|
||||||
|
|
||||||
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, filePath)) {
|
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, filePath)) {
|
||||||
zos.putNextEntry(new ZipEntry(fileName));
|
zos.putNextEntry(new ZipEntry(fullPath));
|
||||||
IOUtils.copy(fileInputStream, zos);
|
IOUtils.copy(fileInputStream, zos);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Error downloading or adding document to ZIP: " + fileName, e);
|
throw new RuntimeException("Error downloading or adding document to ZIP: " + fullPath, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List<DocumentEntity> documents, ApplicationSignedDocumentEntity signedDocument,
|
||||||
|
List<DocumentEntity> amendmentDocuments, List<DocumentEntity> evaluationDocuments, Long applicationId) {
|
||||||
|
|
||||||
private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List<DocumentEntity> documents,
|
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||||
ApplicationSignedDocumentEntity signedDocument, Long applicationId) {
|
Long callId = applicationEntity.getCall().getId();
|
||||||
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
|
// Add Application Documents
|
||||||
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L);
|
||||||
|
|
||||||
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, applicationEntity.getCall().getId(), applicationId);
|
|
||||||
|
|
||||||
for (DocumentEntity document : documents) {
|
for (DocumentEntity document : documents) {
|
||||||
String fileName = Utils.extractFileName(document.getFilePath());
|
String fileName = Utils.extractFileName(document.getFilePath());
|
||||||
addDocumentToZip(zos, s3Folder, document.getFilePath(), fileName);
|
addDocumentToZip(zos, appS3Folder, document.getFilePath(), fileName);
|
||||||
}
|
}
|
||||||
|
// Add Signed Document
|
||||||
if (signedDocument != null) {
|
if (signedDocument != null) {
|
||||||
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId);
|
String signedFolder = "SIGNED_DOCUMENT/";
|
||||||
String signedDocFileName = signedDocument.getFileName();
|
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L);
|
||||||
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedDocFileName);
|
String fileName = signedDocument.getFileName();
|
||||||
|
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedFolder + fileName);
|
||||||
|
}
|
||||||
|
// Add Amendment (Soccorso) Documents
|
||||||
|
for (DocumentEntity amendmentDocument : amendmentDocuments) {
|
||||||
|
String protocolNumber = fetchProtocolNumberForAmendment(amendmentDocument.getSourceId());
|
||||||
|
String amendmentFolder = "SOCCORSO_" + protocolNumber + "/";
|
||||||
|
String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId());
|
||||||
|
String fileName = Utils.extractFileName(amendmentDocument.getFilePath());
|
||||||
|
addDocumentToZip(zos, amendmentS3Folder, amendmentDocument.getFilePath(), amendmentFolder + fileName);
|
||||||
|
}
|
||||||
|
// Add Evaluation Documents
|
||||||
|
for (DocumentEntity evaluationDocument : evaluationDocuments) {
|
||||||
|
String evaluationFolder = "EVALUATION/";
|
||||||
|
String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId());
|
||||||
|
String fileName = Utils.extractFileName(evaluationDocument.getFilePath());
|
||||||
|
addDocumentToZip(zos, evaluationS3Folder, evaluationDocument.getFilePath(), evaluationFolder + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
zos.finish();
|
zos.finish();
|
||||||
return zipOutputStream.toByteArray();
|
return zipOutputStream.toByteArray();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Error while creating ZIP file", e);
|
throw new RuntimeException("Error while creating ZIP file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
@@ -12,23 +11,25 @@ import net.gepafin.tendermanagement.enums.*;
|
|||||||
import net.gepafin.tendermanagement.model.request.*;
|
import net.gepafin.tendermanagement.model.request.*;
|
||||||
import net.gepafin.tendermanagement.model.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
import net.gepafin.tendermanagement.service.*;
|
||||||
import net.gepafin.tendermanagement.service.AssignedApplicationsService;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
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.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNumeric;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ApplicationEvaluationDao {
|
public class ApplicationEvaluationDao {
|
||||||
@@ -91,6 +92,24 @@ public class ApplicationEvaluationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationDao notificationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentService documentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||||
|
|
||||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
||||||
|
|
||||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||||
@@ -106,6 +125,11 @@ public class ApplicationEvaluationDao {
|
|||||||
entity.setNote(req.getNote());
|
entity.setNote(req.getNote());
|
||||||
entity.setMotivation(req.getMotivation());
|
entity.setMotivation(req.getMotivation());
|
||||||
entity.setIsDeleted(false);
|
entity.setIsDeleted(false);
|
||||||
|
entity.setInitialDays(30L);
|
||||||
|
entity.setRemainingDays(30L);
|
||||||
|
entity.setSuspendedDays(0L);
|
||||||
|
entity.setStartDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
entity.setEndDate(DateTimeUtil.DateServerToUTC(application.getSubmissionDate().plusDays(30)));
|
||||||
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@@ -121,16 +145,103 @@ public class ApplicationEvaluationDao {
|
|||||||
List<CallTargetAudienceChecklistEntity> checklistEntities = callTargetAudienceChecklistRepository
|
List<CallTargetAudienceChecklistEntity> checklistEntities = callTargetAudienceChecklistRepository
|
||||||
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.CHECKLIST.getValue());
|
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.CHECKLIST.getValue());
|
||||||
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(entity.getApplicationId());
|
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(entity.getApplicationId());
|
||||||
|
setAmendmentDetails(entity,response);
|
||||||
|
|
||||||
setCriteriaResponses(entity, response, evaluationCriterias);
|
setCriteriaResponses(entity, response, evaluationCriterias);
|
||||||
setChecklistResponses(entity, response, checklistEntities);
|
setChecklistResponses(entity, response, checklistEntities);
|
||||||
setFieldResponses(entity, response, applicationFormEntities);
|
setFieldResponses(entity, response, applicationFormEntities);
|
||||||
|
List<EvaluationDocumentRequest> allDocs = prepareEvaluationDocumentBeanList(entity);
|
||||||
|
setEvaluationDocResponse(response, allDocs);
|
||||||
setApplicationDetails(response, entity);
|
setApplicationDetails(response, entity);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAmendmentDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
|
||||||
|
List<ApplicationAmendmentRequestEntity> amendmentRequests=applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
|
||||||
|
List<AmendmentDocumentResponseBean> amendmentDocumentResponseBeans=new ArrayList<>();
|
||||||
|
for(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity:amendmentRequests){
|
||||||
|
AmendmentDocumentResponseBean amendmentDocumentResponseBean=new AmendmentDocumentResponseBean();
|
||||||
|
amendmentDocumentResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
|
||||||
|
String amendmentDocument=applicationAmendmentRequestEntity.getAmendmentDocument();
|
||||||
|
String formField=applicationAmendmentRequestEntity.getFormFields();
|
||||||
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(amendmentDocument, AmendmentDetailsResponseBean.class);
|
||||||
|
if (amendmentDetails != null) {
|
||||||
|
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(id -> !id.isEmpty())
|
||||||
|
.map(documentId -> applicationAmendmentRequestDao.createDocumentResponseBean(documentId))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
amendmentDocumentResponseBean.setFileDetail(documentResponseBeans);
|
||||||
|
}
|
||||||
|
amendmentDocumentResponseBean.setFieldId("amend_" + applicationAmendmentRequestEntity.getId());
|
||||||
|
amendmentDocumentResponseBean.setLabel(amendmentDetails.getAmendmentNotes());
|
||||||
|
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
|
||||||
|
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
|
||||||
|
}
|
||||||
|
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(formField, AmendmentFormField.class);
|
||||||
|
if (amendmentFormFields != null) {
|
||||||
|
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
|
||||||
|
// Skip fields with null or empty fieldValue
|
||||||
|
if (StringUtils.isEmpty(amendmentFormField.getFieldValue())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
AmendmentDocumentResponseBean formFieldResponseBean = new AmendmentDocumentResponseBean();
|
||||||
|
formFieldResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
|
||||||
|
formFieldResponseBean.setFieldId(amendmentFormField.getFieldId());
|
||||||
|
formFieldResponseBean.setLabel(amendmentFormField.getLabel());
|
||||||
|
formFieldResponseBean.setValid(amendmentFormField.getValid());
|
||||||
|
|
||||||
|
List<Long> fileIds = applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
|
||||||
|
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
formFieldResponseBean.setFileDetail(documentResponseBeans);
|
||||||
|
amendmentDocumentResponseBeans.add(formFieldResponseBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setAmendmentDetails(amendmentDocumentResponseBeans);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
|
||||||
|
List<EvaluationDocumentResponse> evaluationDocResponses = new ArrayList<>();
|
||||||
|
|
||||||
|
for (EvaluationDocumentRequest doc : docRequest) {
|
||||||
|
EvaluationDocumentResponse evaluationDocResponse = new EvaluationDocumentResponse();
|
||||||
|
if (doc.getFileValue() != null) {
|
||||||
|
Long fileId = Long.valueOf(doc.getFileValue().toString());
|
||||||
|
documentRepository.findByIdAndNotDeleted(fileId).ifPresent(documentEntity -> {
|
||||||
|
DocumentResponseBean documentResponseBean = new DocumentResponseBean();
|
||||||
|
documentResponseBean.setId(documentEntity.getId());
|
||||||
|
documentResponseBean.setName(documentEntity.getFileName());
|
||||||
|
documentResponseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||||
|
documentResponseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||||
|
documentResponseBean.setSourceId(documentEntity.getSourceId());
|
||||||
|
documentResponseBean.setFilePath(documentEntity.getFilePath());
|
||||||
|
documentResponseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
|
documentResponseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
documentResponseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
|
evaluationDocResponse.setFileValue(List.of(documentResponseBean));
|
||||||
|
evaluationDocResponse.setNameValue(doc.getNameValue());
|
||||||
|
evaluationDocResponse.setValid(doc.getValid());
|
||||||
|
evaluationDocResponse.setFieldId(doc.getFieldId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (evaluationDocResponse.getFileValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
evaluationDocResponses.add(evaluationDocResponse);
|
||||||
|
}
|
||||||
|
response.setEvaluationDocument(evaluationDocResponses);
|
||||||
|
}
|
||||||
|
|
||||||
private void populateBasicDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
|
private void populateBasicDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
|
||||||
|
|
||||||
response.setId(entity.getId());
|
response.setId(entity.getId());
|
||||||
@@ -140,6 +251,7 @@ public class ApplicationEvaluationDao {
|
|||||||
response.setNote(entity.getNote());
|
response.setNote(entity.getNote());
|
||||||
response.setMotivation(entity.getMotivation());
|
response.setMotivation(entity.getMotivation());
|
||||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus()));
|
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus()));
|
||||||
|
response.setEvaluationEndDate(entity.getEndDate());
|
||||||
response.setCreatedDate(entity.getCreatedDate());
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
response.setUpdatedDate(entity.getUpdatedDate());
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
}
|
}
|
||||||
@@ -148,28 +260,32 @@ public class ApplicationEvaluationDao {
|
|||||||
private void setCriteriaResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<EvaluationCriteriaEntity> evaluationCriterias) {
|
private void setCriteriaResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<EvaluationCriteriaEntity> evaluationCriterias) {
|
||||||
|
|
||||||
List<CriteriaResponse> criteriaResponsesFromEntity = entity.getCriteria() != null ?
|
List<CriteriaResponse> criteriaResponsesFromEntity = entity.getCriteria() != null ?
|
||||||
Utils.convertJsonToList(entity.getCriteria(), new TypeReference<List<CriteriaResponse>>() {
|
Utils.convertJsonToList(entity.getCriteria(), new TypeReference<List<CriteriaResponse>>() {}) :
|
||||||
}) :
|
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
|
||||||
List<CriteriaResponse> criteriaResponsesFromDB = getCriteriaResponse(entity.getApplicationId());
|
List<CriteriaResponse> criteriaResponsesFromDB = getCriteriaResponse(entity.getApplicationId());
|
||||||
addMissingCriteriaResponses(criteriaResponsesFromEntity, criteriaResponsesFromDB, entity.getApplicationId());
|
addMissingCriteriaResponses(criteriaResponsesFromEntity, criteriaResponsesFromDB, entity.getApplicationId());
|
||||||
criteriaResponsesFromEntity.forEach(criteriaResponse -> {
|
|
||||||
EvaluationCriteriaEntity matchingEvaluationCriteria = evaluationCriterias.stream()
|
|
||||||
.filter(evaluationCriteria -> evaluationCriteria.getId().equals(criteriaResponse.getId())).findFirst().orElse(null);
|
|
||||||
|
|
||||||
|
criteriaResponsesFromEntity = criteriaResponsesFromEntity.stream()
|
||||||
|
.filter(criteriaResponse -> {
|
||||||
|
EvaluationCriteriaEntity matchingEvaluationCriteria = evaluationCriterias.stream()
|
||||||
|
.filter(evaluationCriteria -> evaluationCriteria.getId().equals(criteriaResponse.getId())) // Find matching criteria by ID
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
if (matchingEvaluationCriteria != null) {
|
if (matchingEvaluationCriteria != null) {
|
||||||
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
||||||
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
||||||
|
|
||||||
List<CriteriaMappedField> mappedFields = getMappedFieldsForCriteria(matchingEvaluationCriteria.getId(), entity.getApplicationId());
|
List<CriteriaMappedField> mappedFields = getMappedFieldsForCriteria(matchingEvaluationCriteria.getId(), entity.getApplicationId());
|
||||||
criteriaResponse.setCriteriaMappedFields(mappedFields);
|
criteriaResponse.setCriteriaMappedFields(mappedFields);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
return false;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
response.setCriteria(criteriaResponsesFromEntity);
|
response.setCriteria(criteriaResponsesFromEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addMissingCriteriaResponses(List<CriteriaResponse> criteriaResponsesFromEntity, List<CriteriaResponse> criteriaResponsesFromDB, Long applicationId) {
|
private void addMissingCriteriaResponses(List<CriteriaResponse> criteriaResponsesFromEntity, List<CriteriaResponse> criteriaResponsesFromDB, Long applicationId) {
|
||||||
|
|
||||||
Set<Long> existingCriteriaIds = criteriaResponsesFromEntity.stream().map(CriteriaResponse::getId).collect(Collectors.toSet());
|
Set<Long> existingCriteriaIds = criteriaResponsesFromEntity.stream().map(CriteriaResponse::getId).collect(Collectors.toSet());
|
||||||
@@ -256,7 +372,8 @@ public class ApplicationEvaluationDao {
|
|||||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationFormId, applicationId);
|
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationFormId, applicationId);
|
||||||
|
|
||||||
if (formFieldEntityOptional.isPresent()) {
|
if (formFieldEntityOptional.isPresent() && formFieldEntityOptional.get().getFieldValue()!=null && Boolean.FALSE.equals(formFieldEntityOptional.get()
|
||||||
|
.getFieldValue().isEmpty())) {
|
||||||
String[] documentIds = formFieldEntityOptional.get().getFieldValue().split(",");
|
String[] documentIds = formFieldEntityOptional.get().getFieldValue().split(",");
|
||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
@@ -273,6 +390,7 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -290,27 +408,30 @@ public class ApplicationEvaluationDao {
|
|||||||
|
|
||||||
|
|
||||||
private void setChecklistResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
private void setChecklistResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
||||||
|
|
||||||
List<ChecklistResponse> checklistResponsesFromEntity = entity.getChecklist() != null ?
|
List<ChecklistResponse> checklistResponsesFromEntity = entity.getChecklist() != null ?
|
||||||
Utils.convertJsonToList(entity.getChecklist(), new TypeReference<List<ChecklistResponse>>() {
|
Utils.convertJsonToList(entity.getChecklist(), new TypeReference<List<ChecklistResponse>>() {}) :
|
||||||
}) :
|
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
|
||||||
List<ChecklistResponse> checklistResponsesFromDB = getChecklistResponse(entity.getApplicationId());
|
List<ChecklistResponse> checklistResponsesFromDB = getChecklistResponse(entity.getApplicationId());
|
||||||
addMissingChecklistResponses(checklistResponsesFromEntity, checklistResponsesFromDB);
|
addMissingChecklistResponses(checklistResponsesFromEntity, checklistResponsesFromDB);
|
||||||
|
|
||||||
checklistResponsesFromEntity.forEach(checklistResponse -> {
|
checklistResponsesFromEntity = checklistResponsesFromEntity.stream()
|
||||||
CallTargetAudienceChecklistEntity matchingChecklist = checklistEntities.stream().filter(checklistEntity -> checklistEntity.getId().equals(checklistResponse.getId()))
|
.filter(checklistResponse -> {
|
||||||
.findFirst().orElse(null);
|
CallTargetAudienceChecklistEntity matchingChecklist = checklistEntities.stream()
|
||||||
|
.filter(checklistEntity -> checklistEntity.getId().equals(checklistResponse.getId())) // Find matching checklist by ID
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
if (matchingChecklist != null) {
|
if (matchingChecklist != null) {
|
||||||
checklistResponse.setLabel(matchingChecklist.getLookupData().getValue());
|
checklistResponse.setLabel(matchingChecklist.getLookupData().getValue());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
return false;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
response.setChecklist(checklistResponsesFromEntity);
|
response.setChecklist(checklistResponsesFromEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addMissingChecklistResponses(List<ChecklistResponse> checklistResponsesFromEntity, List<ChecklistResponse> checklistResponsesFromDB) {
|
private void addMissingChecklistResponses(List<ChecklistResponse> checklistResponsesFromEntity, List<ChecklistResponse> checklistResponsesFromDB) {
|
||||||
|
|
||||||
Set<Long> existingChecklistIds = checklistResponsesFromEntity.stream().map(ChecklistResponse::getId).collect(Collectors.toSet());
|
Set<Long> existingChecklistIds = checklistResponsesFromEntity.stream().map(ChecklistResponse::getId).collect(Collectors.toSet());
|
||||||
@@ -324,26 +445,31 @@ public class ApplicationEvaluationDao {
|
|||||||
|
|
||||||
private void setFieldResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<ApplicationFormEntity> applicationFormEntities) {
|
private void setFieldResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<ApplicationFormEntity> applicationFormEntities) {
|
||||||
|
|
||||||
List<FieldResponse> fieldResponsesFromEntity = entity.getFile() != null ? Utils.convertJsonToList(entity.getFile(), new TypeReference<List<FieldResponse>>() {
|
List<FieldResponse> fieldResponsesFromEntity = entity.getFile() != null ? Utils.convertJsonToList(entity.getFile(), new TypeReference<List<FieldResponse>>() {}) : new ArrayList<>();
|
||||||
}) : new ArrayList<>();
|
|
||||||
List<FieldResponse> fieldResponsesFromDB = getFieldResponses(entity.getApplicationId());
|
List<FieldResponse> fieldResponsesFromDB = getFieldResponses(entity.getApplicationId());
|
||||||
addMissingFieldResponses(fieldResponsesFromEntity, fieldResponsesFromDB);
|
addMissingFieldResponses(fieldResponsesFromEntity, fieldResponsesFromDB);
|
||||||
|
|
||||||
Set<String> processedFieldIds = new HashSet<>();
|
Set<String> processedFieldIds = new HashSet<>();
|
||||||
|
List<FieldResponse> validFieldResponses = new ArrayList<>();
|
||||||
|
|
||||||
fieldResponsesFromEntity.forEach(fieldResponse -> {
|
fieldResponsesFromEntity.forEach(fieldResponse -> {
|
||||||
if (processedFieldIds.contains(fieldResponse.getId())) {
|
if (processedFieldIds.contains(fieldResponse.getId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Boolean[] allDocumentsDeleted = {true};
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
applicationFormEntities.forEach(applicationForm -> {
|
applicationFormEntities.forEach(applicationForm -> {
|
||||||
FormEntity formEntity = applicationForm.getForm();
|
FormEntity formEntity = applicationForm.getForm();
|
||||||
if (formEntity != null) {
|
if (formEntity != null) {
|
||||||
// List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
// Convert the form to a list of content response beans
|
||||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||||
contentResponseBeans.forEach(contentResponseBean -> {
|
contentResponseBeans.forEach(contentResponseBean -> {
|
||||||
|
// Check if this is a file upload field that matches the current field response
|
||||||
if ("fileupload".equals(contentResponseBean.getName()) && contentResponseBean.getId().equals(fieldResponse.getId())) {
|
if ("fileupload".equals(contentResponseBean.getName()) && contentResponseBean.getId().equals(fieldResponse.getId())) {
|
||||||
String label = null;
|
String label = null;
|
||||||
|
// Set the label if available
|
||||||
if (contentResponseBean.getSettings() != null) {
|
if (contentResponseBean.getSettings() != null) {
|
||||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||||
if ("label".equals(setting.getName())) {
|
if ("label".equals(setting.getName())) {
|
||||||
@@ -362,12 +488,13 @@ public class ApplicationEvaluationDao {
|
|||||||
ApplicationFormFieldEntity formField = optionalFormField.get();
|
ApplicationFormFieldEntity formField = optionalFormField.get();
|
||||||
if (formField.getFieldValue() != null) {
|
if (formField.getFieldValue() != null) {
|
||||||
String[] documentIds = formField.getFieldValue().split(",");
|
String[] documentIds = formField.getFieldValue().split(",");
|
||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String docId : documentIds) {
|
for (String docId : documentIds) {
|
||||||
if (Boolean.FALSE.equals(docId.isEmpty())){
|
if (!docId.trim().isEmpty()) {
|
||||||
Long documentId = Long.valueOf(docId.trim());
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
|
|
||||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
|
if (documentEntity != null && !documentEntity.getIsDeleted()) {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
responseBean.setId(documentEntity.getId());
|
responseBean.setId(documentEntity.getId());
|
||||||
responseBean.setName(documentEntity.getFileName());
|
responseBean.setName(documentEntity.getFileName());
|
||||||
@@ -377,21 +504,28 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
|
allDocumentsDeleted[0] = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(allDocumentsDeleted[0]) && Boolean.FALSE.equals(documentResponseBeans.isEmpty())) {
|
||||||
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
|
validFieldResponses.add(fieldResponse);
|
||||||
|
}
|
||||||
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processedFieldIds.add(fieldResponse.getId());
|
processedFieldIds.add(fieldResponse.getId());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
response.setFiles(validFieldResponses);
|
||||||
});
|
|
||||||
});
|
|
||||||
response.setFiles(fieldResponsesFromEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMissingFieldResponses(List<FieldResponse> fieldResponsesFromEntity, List<FieldResponse> fieldResponsesFromDB) {
|
private void addMissingFieldResponses(List<FieldResponse> fieldResponsesFromEntity, List<FieldResponse> fieldResponsesFromDB) {
|
||||||
@@ -408,22 +542,44 @@ public class ApplicationEvaluationDao {
|
|||||||
private void setApplicationDetails(ApplicationEvaluationResponse response, ApplicationEvaluationEntity entity) {
|
private void setApplicationDetails(ApplicationEvaluationResponse response, ApplicationEvaluationEntity entity) {
|
||||||
|
|
||||||
ApplicationEntity application = applicationService.validateApplication(entity.getApplicationId() != null ? entity.getApplicationId() : null);
|
ApplicationEntity application = applicationService.validateApplication(entity.getApplicationId() != null ? entity.getApplicationId() : null);
|
||||||
|
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository
|
||||||
|
.findByApplicationIdAndIsDeletedFalse(entity.getApplicationId()).orElse(null);
|
||||||
|
|
||||||
UserEntity user = userService.validateUser(application.getUserId());
|
UserEntity user = userService.validateUser(application.getUserId());
|
||||||
|
|
||||||
CallEntity call = callRepository.findCallEntityByApplicationId(entity.getApplicationId());
|
CallEntity call = callRepository.findCallEntityByApplicationId(entity.getApplicationId());
|
||||||
|
|
||||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
String firstName = user.getBeneficiary().getFirstName() != null ? user.getBeneficiary().getFirstName() : "";
|
||||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
String lastName = user.getBeneficiary().getLastName() != null ? user.getBeneficiary().getLastName() : "";
|
||||||
String beneficiary = String.join(" ", firstName, lastName).trim();
|
String beneficiary = String.join(" ", firstName, lastName).trim();
|
||||||
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
||||||
response.setBeneficiary(beneficiary);
|
response.setBeneficiary(beneficiary);
|
||||||
|
response.setNdg(application.getNdg() != null ? application.getNdg() : null);
|
||||||
|
response.setAppointmentId(application.getAppointmentId() != null ? application.getAppointmentId() : null);
|
||||||
|
response.setSubmissionDate(application.getSubmissionDate());
|
||||||
response.setMinScore(call.getThreshold() != null ? call.getThreshold() : null);
|
response.setMinScore(call.getThreshold() != null ? call.getThreshold() : null);
|
||||||
response.setCallName(application.getCall().getName() != null ? application.getCall().getName() : null);
|
response.setCallName(application.getCall().getName() != null ? application.getCall().getName() : null);
|
||||||
response.setProtocolNumber((application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) ? application.getProtocol().getProtocolNumber() : null);
|
response.setProtocolNumber((application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) ? application.getProtocol().getProtocolNumber() : null);
|
||||||
response.setSubmissionDate(application.getSubmissionDate() != null ? application.getSubmissionDate() : null);
|
if (assignedApplications != null) {
|
||||||
response.setEvaluationDate(application.getSubmissionDate() != null ? application.getSubmissionDate().plusDays(30) : null);
|
response.setAssignedAt(assignedApplications.getAssignedAt());
|
||||||
|
}
|
||||||
|
response.setEvaluationEndDate(entity.getEndDate());
|
||||||
|
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||||
|
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(application.getId());
|
||||||
|
if(assignedApplicationsOptional.isPresent()){
|
||||||
|
response.setAssignedUserId(assignedApplicationsOptional.get().getUserId());
|
||||||
|
UserEntity assignedUser = userService.validateUser(assignedApplicationsOptional.get().getUserId());
|
||||||
|
String assignedUserFirstName = assignedUser.getFirstName() != null ? assignedUser.getFirstName() : "";
|
||||||
|
String assignedUserLastName = assignedUser.getLastName() != null ? assignedUser.getLastName() : "";
|
||||||
|
String userName = String.join(" ", assignedUserFirstName, assignedUserLastName).trim();
|
||||||
|
response.setAssignedUserName(userName);
|
||||||
|
}
|
||||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||||
response.setCallEndDate(callEndDate);
|
response.setCallEndDate(callEndDate);
|
||||||
|
if (application.getCompanyId() != null) {
|
||||||
|
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||||
|
response.setCompanyName(company.getCompanyName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -438,22 +594,47 @@ public class ApplicationEvaluationDao {
|
|||||||
Optional<AssignedApplicationsEntity> assignedApplications =
|
Optional<AssignedApplicationsEntity> assignedApplications =
|
||||||
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
|
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
|
||||||
ApplicationEvaluationEntity oldApplicationEvaluation = null;
|
ApplicationEvaluationEntity oldApplicationEvaluation = null;
|
||||||
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
|
VersionActionTypeEnum actionType;
|
||||||
if (existingEntityOptional.isPresent()) {
|
if (existingEntityOptional.isPresent()) {
|
||||||
entity = existingEntityOptional.get();
|
entity = existingEntityOptional.get();
|
||||||
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
|
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
|
||||||
entity.setCriteria(Utils.convertObjectToJson(filterNonNullCriteria(processCriteria(entity, req))));
|
if(req.getCriteria()!=null) {
|
||||||
entity.setChecklist(Utils.convertObjectToJson(filterNonNullChecklist(processChecklist(entity, req))));
|
entity.setCriteria(Utils.convertObjectToJson(processCriteria(entity, req)));
|
||||||
entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req))));
|
}
|
||||||
|
if(req.getChecklist()!=null) {
|
||||||
|
entity.setChecklist(Utils.convertObjectToJson(processChecklist(entity, req)));
|
||||||
|
}
|
||||||
|
if(req.getFiles()!=null) {
|
||||||
|
entity.setFile(Utils.convertObjectToJson(processField(entity, req)));
|
||||||
|
}
|
||||||
entity.setIsDeleted(false);
|
entity.setIsDeleted(false);
|
||||||
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
|
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
|
||||||
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
|
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
|
||||||
actionType = VersionActionTypeEnum.UPDATE;
|
actionType = VersionActionTypeEnum.UPDATE;
|
||||||
} else {
|
} else {
|
||||||
|
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(assignedApplicationsEntity.getApplication().getId());
|
||||||
entity = convertToEntity(user, req, assignedApplicationId);
|
entity = convertToEntity(user, req, assignedApplicationId);
|
||||||
actionType = VersionActionTypeEnum.INSERT;
|
actionType = VersionActionTypeEnum.INSERT;
|
||||||
|
|
||||||
|
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION);
|
||||||
|
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_CREATION);
|
||||||
|
notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_CREATION);
|
||||||
|
|
||||||
}
|
}
|
||||||
ApplicationStatusForEvaluation status = req.getApplicationStatus();
|
ApplicationStatusForEvaluation status = req.getApplicationStatus();
|
||||||
|
// Fetch all amendment request entities associated with the evaluation ID
|
||||||
|
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
|
||||||
|
applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
|
||||||
|
if(req.getEvaluationDocument()!=null) {
|
||||||
|
updateApplicationEvaluation(assignedApplicationId, req.getEvaluationDocument());
|
||||||
|
}
|
||||||
|
// Fetch amendment details from the request
|
||||||
|
if(req.getAmendmentDetails()!=null) {
|
||||||
|
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
|
||||||
|
|
||||||
|
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
|
||||||
|
}
|
||||||
|
|
||||||
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
|
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
|
||||||
|
|
||||||
@@ -469,21 +650,211 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||||
|
// Iterate through amendment request entities
|
||||||
|
|
||||||
private List<ChecklistRequest> filterNonNullChecklist(List<ChecklistRequest> checklistRequests) {
|
//
|
||||||
|
Map<Long,List<AmendmentDetailsRequest>> amendmentFormFieldsMap = amendmentFormFields.stream().collect(Collectors.groupingBy(AmendmentDetailsRequest::getAmendmentId,HashMap::new,Collectors.toCollection(ArrayList::new)));
|
||||||
|
// amendmentFormFields.forEach(data->{
|
||||||
|
// ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestMap.get(data.getAmendmentId());
|
||||||
|
// if (data.getFieldId().contains("amend_")){
|
||||||
|
// updateAmendmentDocument(applicationAmendmentRequestEntity, data);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
applicationAmendmentRequestEntities.forEach(applicationAmendmentRequestEntity->{
|
||||||
|
ApplicationAmendmentRequestEntity oldEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
|
||||||
|
updateAmendment(applicationAmendmentRequestEntity, amendmentFormFieldsMap.get(applicationAmendmentRequestEntity.getId()));
|
||||||
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().actionType(VersionActionTypeEnum.UPDATE).oldData(oldEntity).newData(applicationAmendmentRequestEntity).build());
|
||||||
|
});
|
||||||
|
applicationAmendmentRequestRepository.saveAll(applicationAmendmentRequestEntities);
|
||||||
|
|
||||||
return checklistRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
|
|
||||||
|
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||||
|
// // Process form fields if present
|
||||||
|
// if (applicationAmendmentRequestEntity.getFormFields() != null) {
|
||||||
|
// // Parse existing form fields from JSON
|
||||||
|
// List<AmendmentFormFieldRequest> existingFormFields =
|
||||||
|
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormFieldRequest.class);
|
||||||
|
//
|
||||||
|
// // Prepare a new list to hold updated form fields
|
||||||
|
// List<AmendmentFormFieldRequest> updatedFormFields = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// // Map amendment details for quick lookup by amendment ID
|
||||||
|
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||||
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
|
// .filter(details -> details.getFieldValue() != null) // Null check for getFormFieldDocuments
|
||||||
|
// .collect(Collectors.toMap(
|
||||||
|
// AmendmentDetailsRequest::getAmendmentId,
|
||||||
|
// AmendmentDetailsRequest::getFieldValue
|
||||||
|
// ));
|
||||||
|
// // Get corresponding amendment documents for the current entity
|
||||||
|
// List<AmendmentFormFieldRequest> amendmentDocuments = (List<AmendmentFormFieldRequest>) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||||
|
// if (amendmentDocuments != null) {
|
||||||
|
// // Update existing form fields with new values
|
||||||
|
// for (AmendmentFormFieldRequest existingField : existingFormFields) {
|
||||||
|
// for (AmendmentFormFieldRequest newField : amendmentDocuments) {
|
||||||
|
// if (existingField.getFieldId().equals(newField.getFieldId())) {
|
||||||
|
// // Update fields if there are changes
|
||||||
|
// Utils.setIfUpdated(existingField::getValid, existingField::setValid, newField.getValid());
|
||||||
|
// Utils.setIfUpdated(existingField::getFieldValue, existingField::setFieldValue, newField.getFieldValue());
|
||||||
|
//
|
||||||
|
// updatedFormFields.add(existingField);
|
||||||
|
// break; // Move to the next existing field
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Convert updated form fields back to JSON and save to the database
|
||||||
|
// applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(updatedFormFields));
|
||||||
|
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Process amendment documents if present
|
||||||
|
// if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||||
|
// String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
|
||||||
|
//
|
||||||
|
// // Split comma-separated document IDs into a list
|
||||||
|
// List<String> existingDocumentIdList = Arrays.stream(existingDocumentIds.split(","))
|
||||||
|
// .map(String::trim)
|
||||||
|
// .filter(id -> !id.isEmpty())
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// List<String> updatedDocumentIdList = new ArrayList<>();
|
||||||
|
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||||
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
|
// .collect(Collectors.toMap(
|
||||||
|
// AmendmentDetailsRequest::getAmendmentId,
|
||||||
|
// AmendmentDetailsRequest::getFieldValue
|
||||||
|
// ));
|
||||||
|
//
|
||||||
|
// String amendmentDocumentIds = (String) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||||
|
// if (amendmentDocumentIds != null) {
|
||||||
|
// // Split and validate new document IDs
|
||||||
|
// List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
|
||||||
|
// .map(String::trim)
|
||||||
|
// .filter(id -> !id.isEmpty())
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// for (String existingId : existingDocumentIdList) {
|
||||||
|
// for (String newId : newDocumentIdList) {
|
||||||
|
// if (existingId.equals(newId)) {
|
||||||
|
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
||||||
|
// if(documentEntity.isPresent()) {
|
||||||
|
// updatedDocumentIdList.add(newId);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Add any new IDs not in the existing list
|
||||||
|
// for (String newId : newDocumentIdList) {
|
||||||
|
// if (!existingDocumentIdList.contains(newId)) {
|
||||||
|
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
||||||
|
// if(documentEntity.isPresent()) {
|
||||||
|
// updatedDocumentIdList.add(newId);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// String updatedDocumentIds = String.join(",", updatedDocumentIdList);
|
||||||
|
//
|
||||||
|
// // Create the AmendmentDetailsResponseBean for structured data
|
||||||
|
// AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
|
||||||
|
// amendmentDetails.setAmendmentDocuments(updatedDocumentIds);
|
||||||
|
// AmendmentDetailsRequest amendmentDetailsRequest = amendmentFormFields.stream()
|
||||||
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
|
// .findFirst()
|
||||||
|
// .orElse(null);
|
||||||
|
//
|
||||||
|
// if (amendmentDetailsRequest != null) {
|
||||||
|
// amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
||||||
|
// } else {
|
||||||
|
// amendmentDetails.setValid(false);
|
||||||
|
// }
|
||||||
|
// String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
|
||||||
|
// applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
||||||
|
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CriteriaRequest> filterNonNullCriteria(List<CriteriaRequest> criteriaRequests) {
|
private void updateAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList) {
|
||||||
|
if (CollectionUtils.isEmpty(amendmentDetailsRequestList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, AmendmentFormField> formFieldsMap = null;
|
||||||
|
List<AmendmentFormField> formFieldList = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||||
|
if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldList))){
|
||||||
|
formFieldsMap = formFieldList.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
|
||||||
|
}
|
||||||
|
updateAmendmentData(applicationAmendmentRequestEntity, amendmentDetailsRequestList, formFieldsMap);
|
||||||
|
|
||||||
return criteriaRequests.stream().filter(request -> request.getScore() != null && request.getValid() != null).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FieldRequest> filterNonNullFields(List<FieldRequest> fieldRequests) {
|
private static void updateAmendmentData(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList, Map<String, AmendmentFormField> formFieldsMap) {
|
||||||
|
amendmentDetailsRequestList.forEach(amendmentDetailsRequest -> {
|
||||||
return fieldRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
|
if (amendmentDetailsRequest.getFieldId().contains("amend_")) {
|
||||||
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentDetailsResponseBean.class);
|
||||||
|
if(amendmentDetails!=null) {
|
||||||
|
amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
||||||
|
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertObjectToString(amendmentDetails));
|
||||||
}
|
}
|
||||||
|
} else if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldsMap))){
|
||||||
|
AmendmentFormField amendmentFormField = formFieldsMap.get(amendmentDetailsRequest.getFieldId());
|
||||||
|
amendmentFormField.setValid(amendmentDetailsRequest.getValid());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(formFieldsMap.values().stream().toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// private void updateAmendmentDocuments(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||||
|
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||||
|
// // Skip if there are no amendment documents
|
||||||
|
// if (applicationAmendmentRequestEntity.getAmendmentDocument() == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Parse existing amendment fields from JSON
|
||||||
|
// List<AmendmentFieldRequest> existingAmendmentFields =
|
||||||
|
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentFieldRequest.class);
|
||||||
|
//
|
||||||
|
// // Prepare a new list to hold updated amendment fields
|
||||||
|
// List<AmendmentFieldRequest> updatedAmendmentFields = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// // Map amendment details for quick lookup by amendment ID
|
||||||
|
// Map<Long, List<AmendmentFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
|
||||||
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
|
// .collect(Collectors.toMap(AmendmentDetailsRequest::getAmendmentId, AmendmentDetailsRequest::getAmendmentDocuments));
|
||||||
|
//
|
||||||
|
// // Get corresponding amendment documents for the current entity
|
||||||
|
// List<AmendmentFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||||
|
// if (amendmentDocuments == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Update existing amendment fields with new values
|
||||||
|
// for (AmendmentFieldRequest existingField : existingAmendmentFields) {
|
||||||
|
// for (AmendmentFieldRequest newField : amendmentDocuments) {
|
||||||
|
// if (existingField.getFieldId().equals(newField.getFieldId())) {
|
||||||
|
// // Update fields if there are changes
|
||||||
|
// Utils.setIfUpdated(existingField::getIsValid, existingField::setIsValid, newField.getIsValid());
|
||||||
|
// Utils.setIfUpdated(existingField::getFileValue, existingField::setFileValue, newField.getFileValue());
|
||||||
|
// Utils.setIfUpdated(existingField::getNameValue, existingField::setNameValue, newField.getNameValue());
|
||||||
|
//
|
||||||
|
// updatedAmendmentFields.add(existingField);
|
||||||
|
// break; // Move to the next existing field
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Convert updated fields back to JSON and save to the database
|
||||||
|
// applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(updatedAmendmentFields));
|
||||||
|
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private List<CriteriaRequest> processCriteria(ApplicationEvaluationEntity entity, ApplicationEvaluationRequest req) {
|
private List<CriteriaRequest> processCriteria(ApplicationEvaluationEntity entity, ApplicationEvaluationRequest req) {
|
||||||
|
|
||||||
@@ -604,11 +975,52 @@ public class ApplicationEvaluationDao {
|
|||||||
return entityOptional.get();
|
return entityOptional.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validatePreinstructor(HttpServletRequest request,Long applicationId,Long assignedApplicationId){
|
||||||
|
if (applicationId == null && assignedApplicationId == null) {
|
||||||
|
throw new CustomValidationException(
|
||||||
|
Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.EITHER_APPLICATION_OR_ASSIGNED_APPLICATION_ID_REQUIRED_MSG)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||||
|
assignedApplicationsRepository.findByApplicationIdOrIdAndIsDeletedFalse(applicationId,assignedApplicationId);
|
||||||
|
|
||||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
if (assignedApplicationId != null) {
|
||||||
|
assignedApplicationsOptional = assignedApplicationsOptional.filter(a -> a.getId().equals(assignedApplicationId));
|
||||||
|
}
|
||||||
|
AssignedApplicationsEntity assignedApplications = assignedApplicationsOptional
|
||||||
|
.orElseThrow(() -> new CustomValidationException(
|
||||||
|
Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_WITH_ID_MSG)
|
||||||
|
));
|
||||||
|
if (applicationId == null) {
|
||||||
|
applicationId = assignedApplications.getApplication().getId();
|
||||||
|
}
|
||||||
|
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||||
|
}
|
||||||
|
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request, UserEntity user, Long applicationID, Long assignedApplicationID) {
|
||||||
|
Long applicationId;
|
||||||
|
Long assignedApplicationId;
|
||||||
|
validatePreinstructor(request, applicationID, assignedApplicationID);
|
||||||
|
|
||||||
|
if (applicationID == null && assignedApplicationID != null) {
|
||||||
|
assignedApplicationId = assignedApplicationID;
|
||||||
|
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||||
|
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
|
||||||
|
|
||||||
|
applicationId = assignedApplicationsOptional.map(a -> a.getApplication().getId()).orElse(null);
|
||||||
|
} else {
|
||||||
|
applicationId = applicationID;
|
||||||
|
if (assignedApplicationID == null && applicationID != null) {
|
||||||
|
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||||
|
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||||
|
|
||||||
|
assignedApplicationId = assignedApplicationsOptional.map(AssignedApplicationsEntity::getId).orElse(null);
|
||||||
|
} else {
|
||||||
|
assignedApplicationId = assignedApplicationID;
|
||||||
|
}
|
||||||
|
}
|
||||||
applicationService.validateApplication(applicationId);
|
applicationService.validateApplication(applicationId);
|
||||||
|
|
||||||
Optional<ApplicationEvaluationEntity> entityOptional;
|
Optional<ApplicationEvaluationEntity> entityOptional;
|
||||||
|
|
||||||
if (applicationId != null && assignedApplicationId != null) {
|
if (applicationId != null && assignedApplicationId != null) {
|
||||||
@@ -625,6 +1037,14 @@ public class ApplicationEvaluationDao {
|
|||||||
return getEvaluationResponseByApplicationid(user, applicationId, assignedApplicationId);
|
return getEvaluationResponseByApplicationid(user, applicationId, assignedApplicationId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
private List<EvaluationDocumentRequest> prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) {
|
||||||
|
List<EvaluationDocumentRequest> docRequest = new ArrayList<>();
|
||||||
|
|
||||||
|
if (entity != null && entity.getEvaluationDocument() != null) {
|
||||||
|
docRequest = Utils.convertJsonToList(entity.getEvaluationDocument(), new TypeReference<List<EvaluationDocumentRequest>>() {});
|
||||||
|
}
|
||||||
|
return docRequest;
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
||||||
|
|
||||||
@@ -659,6 +1079,7 @@ public class ApplicationEvaluationDao {
|
|||||||
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
||||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()));
|
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()));
|
||||||
response.setMinScore(call.getThreshold()!=null?call.getThreshold():null);
|
response.setMinScore(call.getThreshold()!=null?call.getThreshold():null);
|
||||||
|
response.setEvaluationEndDate(entity.getEndDate());
|
||||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||||
response.setCallEndDate(callEndDate);
|
response.setCallEndDate(callEndDate);
|
||||||
setCriteriaResponses(entity, application.getId(), response, evaluationCriterias);
|
setCriteriaResponses(entity, application.getId(), response, evaluationCriterias);
|
||||||
@@ -807,6 +1228,10 @@ public class ApplicationEvaluationDao {
|
|||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
findFormFieldValue(applicationId, formFieldId).ifPresent(formField -> {
|
findFormFieldValue(applicationId, formFieldId).ifPresent(formField -> {
|
||||||
Object value = formField.getFieldValue();
|
Object value = formField.getFieldValue();
|
||||||
|
if (value == null) {
|
||||||
|
mappedField.setFieldValue(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<String> labels = new ArrayList<>();
|
List<String> labels = new ArrayList<>();
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
String fieldValue = (String) value;
|
String fieldValue = (String) value;
|
||||||
@@ -846,7 +1271,7 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
|
public DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
responseBean.setId(documentEntity.getId());
|
responseBean.setId(documentEntity.getId());
|
||||||
responseBean.setName(documentEntity.getFileName());
|
responseBean.setName(documentEntity.getFileName());
|
||||||
@@ -856,6 +1281,7 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
return responseBean;
|
return responseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,6 +1354,7 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -948,17 +1375,27 @@ public class ApplicationEvaluationDao {
|
|||||||
private void setApplicationDetails(ApplicationEvaluationResponse response, Long applicationId, UserEntity user) {
|
private void setApplicationDetails(ApplicationEvaluationResponse response, Long applicationId, UserEntity user) {
|
||||||
|
|
||||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository
|
||||||
|
.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||||
userService.validateUser(application.getUserId());
|
userService.validateUser(application.getUserId());
|
||||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
|
||||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
String firstName = user.getBeneficiary().getFirstName() != null ? user.getBeneficiary().getFirstName() : "";
|
||||||
|
String lastName = user.getBeneficiary().getLastName() != null ? user.getBeneficiary().getLastName() : "";
|
||||||
|
|
||||||
String beneficiary = String.join(" ", firstName, lastName).trim();
|
String beneficiary = String.join(" ", firstName, lastName).trim();
|
||||||
response.setBeneficiary(beneficiary);
|
response.setBeneficiary(beneficiary);
|
||||||
|
response.setSubmissionDate(application.getSubmissionDate());
|
||||||
|
response.setNdg(application.getNdg() != null ? application.getNdg() : null);
|
||||||
|
response.setAppointmentId(application.getAppointmentId() != null ? application.getAppointmentId() : null);
|
||||||
response.setCallName(application.getCall().getName() != null ? application.getCall().getName() : null);
|
response.setCallName(application.getCall().getName() != null ? application.getCall().getName() : null);
|
||||||
response.setProtocolNumber((application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) ? application.getProtocol().getProtocolNumber() : null);
|
response.setProtocolNumber((application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) ? application.getProtocol().getProtocolNumber() : null);
|
||||||
response.setSubmissionDate(application.getSubmissionDate() != null ? application.getSubmissionDate() : null);
|
if (assignedApplications != null) {
|
||||||
response.setEvaluationDate(application.getSubmissionDate() != null ? application.getSubmissionDate().plusDays(30) : null);
|
response.setAssignedAt(assignedApplications.getAssignedAt());
|
||||||
|
}
|
||||||
|
if (application.getCompanyId() != null) {
|
||||||
|
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||||
|
response.setCompanyName(company.getCompanyName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private Optional<ApplicationFormFieldEntity> findFormFieldValue(Long applicationId, String formFieldId) {
|
private Optional<ApplicationFormFieldEntity> findFormFieldValue(Long applicationId, String formFieldId) {
|
||||||
@@ -1144,7 +1581,7 @@ public class ApplicationEvaluationDao {
|
|||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
String fieldValue = formField.getFieldValue();
|
String fieldValue = formField.getFieldValue();
|
||||||
if (fieldValue != null) {
|
if (fieldValue != null && (Boolean.FALSE.equals(fieldValue.isEmpty()))) {
|
||||||
String[] fieldValues = fieldValue.split(",");
|
String[] fieldValues = fieldValue.split(",");
|
||||||
for (String value : fieldValues) {
|
for (String value : fieldValues) {
|
||||||
Long documentId = Long.valueOf(value.trim());
|
Long documentId = Long.valueOf(value.trim());
|
||||||
@@ -1168,6 +1605,7 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
return responseBean;
|
return responseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1176,7 +1614,10 @@ public class ApplicationEvaluationDao {
|
|||||||
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
Object value = formField.getFieldValue();
|
Object value = formField.getFieldValue();
|
||||||
List<String> labels = new ArrayList<>();
|
List<String> labels = new ArrayList<>();
|
||||||
|
if (value == null) {
|
||||||
|
mappedField.setFieldValue(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
List<?> parsedValue = parseJsonValue((String) value, objectMapper);
|
List<?> parsedValue = parseJsonValue((String) value, objectMapper);
|
||||||
addLabelsFromParsedValues(parsedValue, contentResponseBean, labels);
|
addLabelsFromParsedValues(parsedValue, contentResponseBean, labels);
|
||||||
@@ -1261,7 +1702,7 @@ public class ApplicationEvaluationDao {
|
|||||||
if (optionalFormField.isPresent()) {
|
if (optionalFormField.isPresent()) {
|
||||||
ApplicationFormFieldEntity formField = optionalFormField.get();
|
ApplicationFormFieldEntity formField = optionalFormField.get();
|
||||||
|
|
||||||
if (formField.getFieldValue() != null) {
|
if (formField.getFieldValue() != null &&(Boolean.FALSE.equals(formField.getFieldValue().isEmpty()))) {
|
||||||
FieldResponse fieldResponse = new FieldResponse();
|
FieldResponse fieldResponse = new FieldResponse();
|
||||||
fieldResponse.setId(fieldId);
|
fieldResponse.setId(fieldId);
|
||||||
String label = null;
|
String label = null;
|
||||||
@@ -1291,6 +1732,7 @@ public class ApplicationEvaluationDao {
|
|||||||
responseBean.setFilePath(documentEntity.getFilePath());
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1348,9 +1790,14 @@ public class ApplicationEvaluationDao {
|
|||||||
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(existingEntity);
|
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(existingEntity);
|
||||||
AssignedApplicationsEntity oldAssignedApplication = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
AssignedApplicationsEntity oldAssignedApplication = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
||||||
|
|
||||||
|
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),List.of(ApplicationAmendmentRequestEnum.AWAITING.getValue(),ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()));
|
||||||
|
if(amendmentRequest !=null && Boolean.FALSE.equals(amendmentRequest.isEmpty())){
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_CANNOT_APPROVED_OR_REJECTED));
|
||||||
|
}
|
||||||
String statusType = application.getStatus();
|
String statusType = application.getStatus();
|
||||||
if (application.getStatus().equals(ApplicationStatusTypeEnum.APPROVED.getValue()) || application.getStatus().equals(ApplicationStatusTypeEnum.REJECTED.getValue())) {
|
if (application.getStatus().equals(ApplicationStatusTypeEnum.APPROVED.getValue()) || application.getStatus().equals(ApplicationStatusTypeEnum.REJECTED.getValue())) {
|
||||||
existingEntity.setStatus(ApplicationEvaluationStatusTypeEnum.CLOSE.getValue());
|
existingEntity.setStatus(ApplicationEvaluationStatusTypeEnum.CLOSE.getValue());
|
||||||
|
existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue());
|
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue());
|
||||||
}
|
}
|
||||||
entity = applicationEvaluationRepository.save(existingEntity);
|
entity = applicationEvaluationRepository.save(existingEntity);
|
||||||
@@ -1366,25 +1813,55 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
|
|
||||||
for (ApplicationAmendmentRequestEntity amendment : amendmentRequest) {
|
|
||||||
ApplicationAmendmentRequestEntity oldAmendment = Utils.getClonedEntityForData(amendment);
|
|
||||||
amendment.setStatus(ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAmendment).newData(amendment).build());
|
|
||||||
|
|
||||||
}
|
|
||||||
applicationAmendmentRequestRepository.saveAll(amendmentRequest);
|
|
||||||
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) {
|
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) {
|
||||||
emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
|
emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) {
|
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) {
|
||||||
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
|
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT);
|
||||||
|
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT);
|
||||||
|
notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT);
|
||||||
|
|
||||||
return convertToResponse(entity);
|
return convertToResponse(entity);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
|
||||||
|
return applicationEvaluationRepository
|
||||||
|
.findByApplicationIdAndIsDeletedFalse(applicationId)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_EVALUATION_NOT_FOUND)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationEvaluationResponse updateApplicationEvaluation(
|
||||||
|
Long assignedApplicationId,
|
||||||
|
List<EvaluationDocumentRequest> docRequest) {
|
||||||
|
Optional<ApplicationEvaluationEntity> entityOptional=applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplicationId);
|
||||||
|
ApplicationEvaluationEntity applicationEvaluationEntity =null;
|
||||||
|
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(entityOptional.get());
|
||||||
|
applicationEvaluationEntity = entityOptional.get();
|
||||||
|
|
||||||
|
if (docRequest != null) {
|
||||||
|
List<EvaluationDocumentRequest> existingDocs = new ArrayList<>();
|
||||||
|
|
||||||
|
for (EvaluationDocumentRequest doc : docRequest) {
|
||||||
|
if (doc.getFileValue() != null) {
|
||||||
|
Long fileId = Long.valueOf(doc.getFileValue());
|
||||||
|
documentService.validateDocument(fileId);
|
||||||
|
existingDocs.add(doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String updatedEvaluationDocJson = Utils.convertObjectToJson(existingDocs);
|
||||||
|
applicationEvaluationEntity.setEvaluationDocument(updatedEvaluationDocJson);
|
||||||
|
}
|
||||||
|
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(applicationEvaluationEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Upload Document in Application Evaluation" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluation).newData(savedEntity).build());
|
||||||
|
return convertToResponse(savedEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,918 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import com.amazonaws.services.s3.AmazonS3Client;
|
||||||
|
import com.amazonaws.services.s3.model.GetObjectRequest;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import feign.FeignException;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
|
import net.gepafin.tendermanagement.constants.AppointmentApiConstant;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.AppointmentCreationRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.AppointmentNdgRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.AppointmentVisuraListRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.AppointmentVisuraRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CreateAppointmentRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UploadDocToExternalSystemRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.AppointmentCreationResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.AppointmentLoginResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.DocumentUploadResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.NdgResponse;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
|
import net.gepafin.tendermanagement.service.feignClient.AppointmentApiService;
|
||||||
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AppointmentDao {
|
||||||
|
|
||||||
|
@Value("${appointment.portal.user}")
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
@Value("${appointment.portal.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Value("${appointment.portal.source}")
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
@Value("${appointment.portal.context}")
|
||||||
|
private String context;
|
||||||
|
|
||||||
|
@Value("${default.hub.uuid}")
|
||||||
|
private String defaultHubUuid;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url}")
|
||||||
|
private String s3Url;
|
||||||
|
|
||||||
|
@Value("${aws.s3.bucket.name}")
|
||||||
|
private String OLD_BUCKET;
|
||||||
|
|
||||||
|
@Value("${flagDaFirmare}")
|
||||||
|
private Boolean flagDaFirmare;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HubRepository hubRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AppointmentApiService appointmentApiService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationService applicationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyRepository companyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentDao documentDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Client s3Client;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentRepository documentRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenProvider tokenProvider;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationDao notificationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
private final Map<Long, ExecutorService> executorMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private final ConcurrentHashMap<Long, ExecutorService> threadForDocumentMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private static final ThreadLocal<Long> threadLocalHubId = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public NdgResponse checkNdgForAppointment(Long applicationId) {
|
||||||
|
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
NdgResponse ndgResponse = new NdgResponse();
|
||||||
|
if (application.getNdgStatus() != null && application.getNdgStatus().equalsIgnoreCase(GepafinConstant.NDG_IN_PROGRESS)) {
|
||||||
|
throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.NDG_GENERATION_IS_IN_PROGRESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (application.getNdgStatus() != null && application.getNdgStatus().equalsIgnoreCase(GepafinConstant.NDG_GENERATED) && application.getNdg() != null) {
|
||||||
|
ndgResponse.setNdg(application.getNdg());
|
||||||
|
return ndgResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update application status
|
||||||
|
application.setNdgStatus(GepafinConstant.NDG_IN_PROGRESS);
|
||||||
|
applicationRepository.save(application);
|
||||||
|
|
||||||
|
// Start async processing
|
||||||
|
startAsyncNdgProcessing(applicationId);
|
||||||
|
|
||||||
|
throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.NDG_GENERATION_IS_IN_PROGRESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startAsyncNdgProcessing(Long applicationId) {
|
||||||
|
// Check if a thread is already running for this application
|
||||||
|
if (executorMap.containsKey(applicationId)) {
|
||||||
|
log.warn("Async processing already running for applicationId: {}", applicationId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a dedicated thread for asynchronous processing
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor(runnable -> {
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.setName("AsyncNdgProcessing-" + applicationId);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
|
executorMap.put(applicationId, executor);
|
||||||
|
|
||||||
|
executor.submit(() -> {
|
||||||
|
try {
|
||||||
|
log.info("Starting async processing for applicationId: {}", applicationId);
|
||||||
|
processNdgGeneration(applicationId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in async NDG processing for applicationId: {}", applicationId, e);
|
||||||
|
} finally {
|
||||||
|
// Cleanup resources
|
||||||
|
ExecutorService executorToShutdown = executorMap.remove(applicationId);
|
||||||
|
if (executorToShutdown != null) {
|
||||||
|
executorToShutdown.shutdown();
|
||||||
|
}
|
||||||
|
log.info("Async processing completed for applicationId: {}", applicationId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processNdgGeneration(Long applicationId) {
|
||||||
|
// Validate application, company, and hub
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||||
|
HubEntity hub = hubRepository.findByHubId(application.getHubId());
|
||||||
|
|
||||||
|
if (!hub.getUniqueUuid().equals(defaultHubUuid)) {
|
||||||
|
log.info("Ndg cannot be created for another Hub, it is default for Gepafin.");
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NO_NDG_FOR_ANOTHER_HUB));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Authenticate and fetch token if required
|
||||||
|
if (hub.getAppointmentAuthTokenId() == null || hub.getAreaCode() == null) {
|
||||||
|
authenticateAndSaveToken(hub);
|
||||||
|
}
|
||||||
|
|
||||||
|
String authorizationToken = getBearerToken(hub);
|
||||||
|
|
||||||
|
// Try retrieving NDG by VAT number
|
||||||
|
AppointmentLoginResponse ndgResponse = retrieveNdgByVatNumber(company.getVatNumber(), authorizationToken, hub, application);
|
||||||
|
if (isNdgValid(ndgResponse.getNdg())) {
|
||||||
|
saveNdgAndIdVisura(application, company, ndgResponse.getNdg(), null);
|
||||||
|
log.info("NDG successfully generated for applicationId: {}", applicationId);
|
||||||
|
} else {
|
||||||
|
// If NDG isn't immediately available, start polling
|
||||||
|
handleNdgPolling(application, company, hub, authorizationToken);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error during NDG generation for applicationId: {}", applicationId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNdgPolling(ApplicationEntity application, CompanyEntity company, HubEntity hub, String authorizationToken) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("Starting NDG polling for applicationId: {}", application.getId());
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (application.getNdg() != null) {
|
||||||
|
log.info("NDG retrieved for applicationId: {}", application.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Fetch Visura list and attempt to parse NDG
|
||||||
|
String visuraListJson = getVisuraList(application.getIdVisura(), authorizationToken, application, hub);
|
||||||
|
String ndg = parseNdgFromVisuraListResponse(visuraListJson);
|
||||||
|
|
||||||
|
if (isNdgValid(ndg)) {
|
||||||
|
// CompanyEntity oldCompanyData = Utils.getClonedEntityForData(company);
|
||||||
|
// ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(application);
|
||||||
|
|
||||||
|
company.setNdg(ndg);
|
||||||
|
application.setNdg(ndg);
|
||||||
|
application.setNdgStatus(GepafinConstant.NDG_GENERATED);
|
||||||
|
application.setStatus(ApplicationStatusTypeEnum.NDG.getValue());
|
||||||
|
applicationRepository.save(application);
|
||||||
|
companyRepository.save(company);
|
||||||
|
log.info("NDG saved successfully for applicationId: {}", application.getId());
|
||||||
|
|
||||||
|
// /** This code is responsible for adding a version history log for the "update application ndg code, status, and Id visura"
|
||||||
|
// operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(
|
||||||
|
// VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData)
|
||||||
|
// .newData(application).build());
|
||||||
|
//
|
||||||
|
// /** This code is responsible for adding a version history log for the "update company ndg code" operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(
|
||||||
|
// VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyData)
|
||||||
|
// .newData(company).build());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if polling has timed out
|
||||||
|
if (System.currentTimeMillis() - startTime > TimeUnit.HOURS.toMillis(2)) {
|
||||||
|
log.warn("NDG polling timed out for applicationId: {}", application.getId());
|
||||||
|
application.setNdgStatus(GepafinConstant.NDG_FAILED);
|
||||||
|
applicationRepository.save(application);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait before the next polling attempt
|
||||||
|
Thread.sleep(TimeUnit.MINUTES.toMillis(15));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.warn("NDG polling interrupted for applicationId: {}", application.getId());
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error during NDG polling for applicationId: {}", application.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
log.info("NDG polling completed for applicationId: {}", application.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getBearerToken(HubEntity hub) {
|
||||||
|
|
||||||
|
return "Bearer " + hub.getAppointmentAuthTokenId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNdgValid(String ndg) {
|
||||||
|
|
||||||
|
return ndg != null && !ndg.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveNdgAndIdVisura(ApplicationEntity application, CompanyEntity company, String ndg, String idVisura) {
|
||||||
|
|
||||||
|
//cloned for old application and company data
|
||||||
|
// ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(application);
|
||||||
|
// CompanyEntity oldCompanyData = Utils.getClonedEntityForData(company);
|
||||||
|
|
||||||
|
application.setNdg(ndg);
|
||||||
|
application.setIdVisura(idVisura);
|
||||||
|
application.setNdgStatus(GepafinConstant.NDG_GENERATED);
|
||||||
|
application.setStatus(ApplicationStatusTypeEnum.NDG.getValue());
|
||||||
|
company.setNdg(ndg);
|
||||||
|
companyRepository.save(company);
|
||||||
|
applicationRepository.save(application);
|
||||||
|
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(application,NotificationTypeEnum.NDG_GENERATION);
|
||||||
|
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.NDG_GENERATION);
|
||||||
|
|
||||||
|
// /** This code is responsible for adding a version history log for the "update application ndg code, status, and Id visura" operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(
|
||||||
|
// VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build());
|
||||||
|
//
|
||||||
|
// /** This code is responsible for adding a version history log for the "update company ndg code" operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyData).newData
|
||||||
|
// (company).build());
|
||||||
|
|
||||||
|
log.info("NDG saved for applicationId: {}, {}", application.getId(), application.getNdg());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getVisuraList(String idVisura, String authorizationToken, ApplicationEntity application, HubEntity hub) {
|
||||||
|
|
||||||
|
AppointmentVisuraListRequest visuraListRequest = new AppointmentVisuraListRequest();
|
||||||
|
AppointmentVisuraListRequest.VisuraFilter filter = new AppointmentVisuraListRequest.VisuraFilter();
|
||||||
|
filter.setIdVisura(idVisura);
|
||||||
|
visuraListRequest.setFilter(filter);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String requestJson = Utils.convertObjectToJson(visuraListRequest);
|
||||||
|
ResponseEntity<Object> response = appointmentApiService.getVisuraList(requestJson, authorizationToken);
|
||||||
|
return Utils.convertObjectToJson(response.getBody());
|
||||||
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
|
log.error("403 Forbidden received while getting visuraList for Ndg code. Regenerating token...");
|
||||||
|
// Regenerate the token and retry
|
||||||
|
String newAuthorizationToken = regenerateTokenAndSave(hub);
|
||||||
|
return getVisuraList(idVisura, newAuthorizationToken, application, hub);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to fetch Ndg code: {}", e.getMessage(), e);
|
||||||
|
throw new RuntimeException("Error fetching Ndg List", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HubEntity authenticateAndSaveToken(HubEntity hub) {
|
||||||
|
|
||||||
|
// HubEntity oldHubData = Utils.getClonedEntityForData(hub);
|
||||||
|
try {
|
||||||
|
//code to generate token with payload having "iat" epoch timestamp and secret key with no expiry and send in below method call
|
||||||
|
String authJwtToken = Utils.generateAuthTokenForLoginToOdessa();
|
||||||
|
log.info("Got the auth for login to odessa {}", authJwtToken);
|
||||||
|
hub.setAuthToken(authJwtToken);
|
||||||
|
hubRepository.save(hub);
|
||||||
|
|
||||||
|
// /** This code is responsible for adding a version history log for the "Updating auth token for login api in hub" operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldHubData).newData
|
||||||
|
// (hub).build());
|
||||||
|
|
||||||
|
// Prepare the request body (adjust if necessary for login API)
|
||||||
|
Map<String, Object> body = Collections.emptyMap();
|
||||||
|
// Perform login API call
|
||||||
|
ResponseEntity<Object> responseLogin = appointmentApiService.loginWithOdessa(authJwtToken, source, context, user, password, body);
|
||||||
|
|
||||||
|
// Handle successful login
|
||||||
|
if (responseLogin.getStatusCode() == HttpStatus.OK) {
|
||||||
|
log.info("Login successful to odessa. Parsing response.");
|
||||||
|
String loginResponseJson = Utils.convertObjectToJson(responseLogin.getBody());
|
||||||
|
AppointmentLoginResponse parsedResponse = parseLoginResponse(loginResponseJson);
|
||||||
|
|
||||||
|
// Validate and save token
|
||||||
|
if (parsedResponse.getTokenId() != null) {
|
||||||
|
hub.setAppointmentAuthTokenId(parsedResponse.getTokenId());
|
||||||
|
hub.setAreaCode(parsedResponse.getAreaCode());
|
||||||
|
hubRepository.save(hub);
|
||||||
|
|
||||||
|
// /** This code is responsible for adding a version history log for the "inserting token and areaCode from login odessa response for
|
||||||
|
// appointment flow api's"
|
||||||
|
// * operation. **/
|
||||||
|
// loggingUtil.addVersionHistory(
|
||||||
|
// VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldHubData).newData(hub)
|
||||||
|
// .build());
|
||||||
|
|
||||||
|
log.info("Saved new authToken and areaCode for Hub.");
|
||||||
|
return hub;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Login response is missing a valid tokenId for login to odessa system, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle non-OK response
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
||||||
|
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AppointmentLoginResponse retrieveNdgByVatNumber(String vatNumber, String authorizationToken, HubEntity hub, ApplicationEntity application) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Prepare the NDG request
|
||||||
|
AppointmentNdgRequest ndgRequest = getAppointmentNdgRequest(vatNumber);
|
||||||
|
// Call the API to retrieve NDG
|
||||||
|
ResponseEntity<Object> response = appointmentApiService.getNdgByVatNumber(ndgRequest, authorizationToken);
|
||||||
|
String responseJson = Utils.convertObjectToJson(response.getBody());
|
||||||
|
// Parse and return the NDG response
|
||||||
|
return parseNdgResponse(responseJson);
|
||||||
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
|
logForbiddenError();
|
||||||
|
// Regenerate the token and retry
|
||||||
|
String newAuthorizationToken = regenerateTokenAndSave(hub);
|
||||||
|
return retrieveNdgByVatNumber(vatNumber, newAuthorizationToken, hub, application);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to retrieve NDG by VAT number: {}", e.getMessage(), e);
|
||||||
|
throw new RuntimeException("NDG retrieval failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String regenerateTokenAndSave(HubEntity hub) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
hub = authenticateAndSaveToken(hub);
|
||||||
|
return "Bearer " + hub.getAppointmentAuthTokenId();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to regenerate token from Odessa: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Token regeneration failed from Odessa.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AppointmentLoginResponse createVisura(CompanyEntity company, String authorizationToken, HubEntity hub) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String visuraRequest = getAppointmentVisuraRequest(company, hub.getAreaCode());
|
||||||
|
ResponseEntity<Object> response = appointmentApiService.createVisura(visuraRequest, authorizationToken);
|
||||||
|
String responseJson = Utils.convertObjectToJson(response.getBody());
|
||||||
|
return parseVisuraResponse(responseJson);
|
||||||
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
|
logForbiddenError();
|
||||||
|
// Regenerate the token and retry
|
||||||
|
String newAuthorizationToken = regenerateTokenAndSave(hub);
|
||||||
|
return createVisura(company, newAuthorizationToken, hub);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to create Visura for Ndg : {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Visura creation failed for Ndg.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logForbiddenError() {
|
||||||
|
|
||||||
|
log.error("403 Forbidden received while retrieving NDG. Regenerating token...");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AppointmentNdgRequest getAppointmentNdgRequest(String vatNumber) {
|
||||||
|
|
||||||
|
AppointmentNdgRequest request = new AppointmentNdgRequest();
|
||||||
|
AppointmentNdgRequest.Filter filter = new AppointmentNdgRequest.Filter();
|
||||||
|
filter.setPartitaIva(vatNumber);
|
||||||
|
|
||||||
|
AppointmentNdgRequest.Pagination pagination = new AppointmentNdgRequest.Pagination();
|
||||||
|
pagination.setTargetPage(AppointmentApiConstant.TARGET_PAGE_SIZE);
|
||||||
|
pagination.setRecordsPerPage(AppointmentApiConstant.RECORD_PER_PAGE_SIZE);
|
||||||
|
|
||||||
|
request.setFilter(filter);
|
||||||
|
request.setPagination(pagination);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getAppointmentVisuraRequest(CompanyEntity company, String areaCode) {
|
||||||
|
|
||||||
|
AppointmentVisuraRequest visuraRequest = new AppointmentVisuraRequest();
|
||||||
|
AppointmentVisuraRequest.VisuraInput input = new AppointmentVisuraRequest.VisuraInput();
|
||||||
|
input.setPartitaIva(company.getVatNumber());
|
||||||
|
input.setCodiceFiscale(company.getCodiceFiscale());
|
||||||
|
input.setCodArea(areaCode);
|
||||||
|
input.setVisuraMode(AppointmentApiConstant.VISURA_MODE);
|
||||||
|
input.setVisuraProvider(AppointmentApiConstant.VISURA_PROVIDER);
|
||||||
|
input.setCodAgente(AppointmentApiConstant.COD_AGENTE);
|
||||||
|
input.setAnagraficaLegame(AppointmentApiConstant.IS_ANAGRAFICA_LEGAME);
|
||||||
|
input.setCreaAnagrafica(AppointmentApiConstant.CREA_ANAGRAFICA);
|
||||||
|
input.setFromRating(AppointmentApiConstant.IS_FROM_RATING);
|
||||||
|
input.setSalvaDocumenti(AppointmentApiConstant.SALVA_DOCUMENTI);
|
||||||
|
input.setVisuraType(AppointmentApiConstant.VISURA_TYPE);
|
||||||
|
visuraRequest.setInput(input);
|
||||||
|
return Utils.convertObjectToJson(visuraRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String parseNdgFromVisuraListResponse(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
JsonNode dataNode = rootNode.get(GepafinConstant.DATA_STRING);
|
||||||
|
|
||||||
|
if (dataNode != null && dataNode.isArray() && dataNode.size() > 0) {
|
||||||
|
JsonNode firstEntry = dataNode.get(0);
|
||||||
|
JsonNode ndgClienteNode = firstEntry.get("ndgCliente");
|
||||||
|
if (ndgClienteNode != null && ndgClienteNode.get("code") != null) {
|
||||||
|
String code = ndgClienteNode.get("code").asText();
|
||||||
|
return normalizeNullValue(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.warn("NDG not found in Visura List API response.");
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to parse NDG from Visura List API response: {}", e.getMessage(), e);
|
||||||
|
throw new RuntimeException("Error parsing NDG from Visura List API response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentLoginResponse parseLoginResponse(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
JsonNode dataNode = rootNode.get(GepafinConstant.DATA_STRING);
|
||||||
|
|
||||||
|
if (dataNode != null) {
|
||||||
|
AppointmentLoginResponse response = new AppointmentLoginResponse();
|
||||||
|
response.setTokenId(dataNode.get("tokenId").asText());
|
||||||
|
JsonNode areasNode = dataNode.get("areas");
|
||||||
|
if (areasNode != null && areasNode.isArray() && areasNode.size() > 0) {
|
||||||
|
response.setAreaCode(areasNode.get(0).get("code").asText());
|
||||||
|
}
|
||||||
|
response.setCompanyId(dataNode.get("companyId").asLong());
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Invalid JSON structure: Missing 'data' node.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to parse response from loginApi for odessa: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentLoginResponse parseVisuraResponse(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
JsonNode dataNode = rootNode.get(GepafinConstant.DATA_STRING);
|
||||||
|
|
||||||
|
if (dataNode != null) {
|
||||||
|
AppointmentLoginResponse response = new AppointmentLoginResponse();
|
||||||
|
response.setIdVisura(normalizeNullValue(dataNode.get(GepafinConstant.ID_VISURA_STRING).asText()));
|
||||||
|
response.setNdg(normalizeNullValue(dataNode.get(GepafinConstant.NDG_STRING).asText()));
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Invalid JSON structure: Missing 'data' node.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to parse response: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentLoginResponse parseNdgResponse(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
JsonNode dataArray = rootNode.get(GepafinConstant.DATA_STRING);
|
||||||
|
if (dataArray == null || !dataArray.isArray() || dataArray.isEmpty()) {
|
||||||
|
log.info("NDG data is empty or missing in the response.");
|
||||||
|
AppointmentLoginResponse emptyResponse = new AppointmentLoginResponse();
|
||||||
|
emptyResponse.setNdg(null);
|
||||||
|
return emptyResponse;
|
||||||
|
}
|
||||||
|
JsonNode firstDataEntry = dataArray.get(0);
|
||||||
|
AppointmentLoginResponse response = new AppointmentLoginResponse();
|
||||||
|
if (firstDataEntry.has(GepafinConstant.NDG_STRING)) {
|
||||||
|
response.setNdg(normalizeNullValue(firstDataEntry.get(GepafinConstant.NDG_STRING).asText()));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to parse response: {}", e.getMessage(), e);
|
||||||
|
throw new RuntimeException("Failed to parse NDG response.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeNullValue(String value) {
|
||||||
|
|
||||||
|
return (value == null || GepafinConstant.NULL_STRING.equalsIgnoreCase(value.trim())) ? null : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentCreationResponse createAppointment(Long applicationId, CreateAppointmentRequest createAppointmentRequest) {
|
||||||
|
// Validate the application
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
|
||||||
|
AppointmentCreationResponse appointmentCreationResponse = new AppointmentCreationResponse();
|
||||||
|
|
||||||
|
ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(application);
|
||||||
|
HubEntity hub = hubRepository.findByHubId(application.getHubId());
|
||||||
|
|
||||||
|
// Check hub UUID and enforce constraints
|
||||||
|
if (!hub.getUniqueUuid().equals(defaultHubUuid)) {
|
||||||
|
log.info("Appointment cannot be created for another Hub; default is required for Gepafin.");
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NO_APPOINTMENT_FOR_ANOTHER_HUB));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Pre-check conditions for appointment creation
|
||||||
|
if (application.getNdg() != null && !Objects.equals(application.getNdgStatus(), GepafinConstant.NDG_IN_PROGRESS) && application.getAppointmentId() != null) {
|
||||||
|
appointmentCreationResponse.setAppointmentId(application.getAppointmentId());
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_ALREADY_CREATED));
|
||||||
|
// return appointmentCreationResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (application.getNdg() == null && Objects.equals(application.getNdgStatus(), GepafinConstant.NDG_IN_PROGRESS)) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NDG_NOT_FOUND_FOR_APPLICATION));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate authorization token and fetch template data
|
||||||
|
String authorizationToken = getBearerToken(hub);
|
||||||
|
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken);
|
||||||
|
|
||||||
|
if (response.getStatusCode() != HttpStatus.OK) {
|
||||||
|
log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode());
|
||||||
|
throw new IllegalStateException("Failed to retrieve appointment template for appointment creation");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse template data
|
||||||
|
String responseDataForTemplate = Utils.convertObjectToJson(response.getBody());
|
||||||
|
AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate);
|
||||||
|
|
||||||
|
// Build the appointment request body
|
||||||
|
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAreaCode(),
|
||||||
|
templateRichiestaData);
|
||||||
|
String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest);
|
||||||
|
|
||||||
|
// Make API call to create the appointment
|
||||||
|
ResponseEntity<Object> appointmentResponse = appointmentApiService.createAppointment(authorizationToken, context, appointmentRequestBody);
|
||||||
|
String appointmentId = extractAppointmentIdFromResponse(appointmentResponse);
|
||||||
|
|
||||||
|
if (appointmentId != null) {
|
||||||
|
// Update application with the appointment ID
|
||||||
|
application.setAppointmentId(appointmentId);
|
||||||
|
application.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue());
|
||||||
|
applicationRepository.save(application);
|
||||||
|
|
||||||
|
// Log version history
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
appointmentCreationResponse.setAppointmentId(appointmentId);
|
||||||
|
return appointmentCreationResponse;
|
||||||
|
|
||||||
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
|
log.error("403 Forbidden received while retrieving template. Regenerating token...");
|
||||||
|
regenerateTokenAndSave(hub);
|
||||||
|
return createAppointment(applicationId, createAppointmentRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractAppointmentIdFromResponse(ResponseEntity<Object> appointmentResponse) {
|
||||||
|
|
||||||
|
if (appointmentResponse.getBody() != null) {
|
||||||
|
Map<String, Object> responseBody = (Map<String, Object>) appointmentResponse.getBody();
|
||||||
|
if (responseBody.containsKey(GepafinConstant.DATA_STRING)) {
|
||||||
|
Map<String, Object> data = (Map<String, Object>) responseBody.get(GepafinConstant.DATA_STRING);
|
||||||
|
if (data != null && data.containsKey(GepafinConstant.ID_STRING)) {
|
||||||
|
return data.get(GepafinConstant.ID_STRING).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
JsonNode richiestaClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTA_CLIENTE_STRING);
|
||||||
|
|
||||||
|
AppointmentCreationRequest appointmentCreationRequest = new AppointmentCreationRequest();
|
||||||
|
AppointmentCreationRequest.Input input = new AppointmentCreationRequest.Input();
|
||||||
|
|
||||||
|
// Map `richiestaCliente` array
|
||||||
|
List<AppointmentCreationRequest.RichiestaCliente> richiestaClienteList = new ArrayList<>();
|
||||||
|
if (richiestaClienteArray.isArray()) {
|
||||||
|
for (JsonNode richiestaNode : richiestaClienteArray) {
|
||||||
|
richiestaClienteList.add(objectMapper.treeToValue(richiestaNode, AppointmentCreationRequest.RichiestaCliente.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input.setRichiestaCliente(richiestaClienteList);
|
||||||
|
appointmentCreationRequest.setInput(input);
|
||||||
|
return appointmentCreationRequest;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error parsing template response: {}", e.getMessage(), e);
|
||||||
|
throw new IllegalStateException("Failed to parse template response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, String areaCode,
|
||||||
|
AppointmentCreationRequest templateRichiestaData) {
|
||||||
|
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
CreateAppointmentRequest.Nota nota = createAppointmentRequest.getNota();
|
||||||
|
|
||||||
|
AppointmentCreationRequest appointmentCreationRequest = new AppointmentCreationRequest();
|
||||||
|
AppointmentCreationRequest.Input input = new AppointmentCreationRequest.Input();
|
||||||
|
|
||||||
|
// Set Input Fields
|
||||||
|
input.setId(areaCode);
|
||||||
|
input.setNdg(application.getNdg());
|
||||||
|
|
||||||
|
// Populate richiestaCliente from template data
|
||||||
|
List<AppointmentCreationRequest.RichiestaCliente> richiestaClienteList = new ArrayList<>();
|
||||||
|
for (AppointmentCreationRequest.RichiestaCliente templateRichiesta : templateRichiestaData.getInput().getRichiestaCliente()) {
|
||||||
|
AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente();
|
||||||
|
BeanUtils.copyProperties(templateRichiesta, richiestaCliente);
|
||||||
|
|
||||||
|
// Add specific `nota`
|
||||||
|
AppointmentCreationRequest.Nota requestNota = new AppointmentCreationRequest.Nota();
|
||||||
|
requestNota.setTitolo(nota.getTitolo());
|
||||||
|
requestNota.setTesto(nota.getTesto());
|
||||||
|
richiestaCliente.setNota(requestNota);
|
||||||
|
|
||||||
|
richiestaClienteList.add(richiestaCliente);
|
||||||
|
}
|
||||||
|
|
||||||
|
input.setRichiestaCliente(richiestaClienteList);
|
||||||
|
appointmentCreationRequest.setInput(input);
|
||||||
|
return appointmentCreationRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentUploadResponse uploadDocumentToExternalSystem(Long documentId, UploadDocToExternalSystemRequest docToExternalSystemRequest) {
|
||||||
|
// Check if the document is already being processed
|
||||||
|
DocumentEntity systemDoc = documentDao.validateDocument(documentId);
|
||||||
|
|
||||||
|
Claims claims = tokenProvider.getClaimsFromToken(tokenProvider.extractTokenFromRequest(request));
|
||||||
|
Long hubId = Utils.extractHubIdFromPayload(claims.getSubject());
|
||||||
|
if (systemDoc.getDocumentAttachmentId() != null) {
|
||||||
|
// If the documentAttachmentId is already set, return the response
|
||||||
|
log.info("Document already uploaded with documentAttachmentId: {}", systemDoc.getDocumentAttachmentId());
|
||||||
|
DocumentUploadResponse response = new DocumentUploadResponse();
|
||||||
|
response.setDocumentAttachmentId(systemDoc.getDocumentAttachmentId());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// Check if a thread is already running for this document upload
|
||||||
|
if (threadForDocumentMap.containsKey(documentId)) {
|
||||||
|
log.warn("Document upload already running for documentId: {}", documentId);
|
||||||
|
throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPLOADING_IN_PROGRESS));
|
||||||
|
}
|
||||||
|
// Start the upload process in the background
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor(runnable -> {
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.setName(GepafinConstant.ASYNC_DOCUMENT_UPLOAD_NAME + documentId);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
|
threadForDocumentMap.put(documentId, executor);
|
||||||
|
|
||||||
|
executor.submit(() -> {
|
||||||
|
threadLocalHubId.set(hubId);
|
||||||
|
try {
|
||||||
|
log.info("Starting async document upload for documentId: {}", documentId);
|
||||||
|
uploadDocumentToExternalSystemSync(documentId, docToExternalSystemRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in async document upload for documentId: {}", documentId, e);
|
||||||
|
} finally {
|
||||||
|
// Cleanup resources
|
||||||
|
ExecutorService executorToShutdown = threadForDocumentMap.remove(documentId);
|
||||||
|
if (executorToShutdown != null) {
|
||||||
|
executorToShutdown.shutdown();
|
||||||
|
threadLocalHubId.remove();
|
||||||
|
}
|
||||||
|
log.info("Async document upload completed for documentId: {}", documentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
// Return an immediate response indicating the process is in progress
|
||||||
|
// throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPLOADING_IN_PROGRESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void uploadDocumentToExternalSystemSync(Long documentId, UploadDocToExternalSystemRequest docToExternalSystemRequest) {
|
||||||
|
// Synchronous upload logic
|
||||||
|
DocumentEntity systemDoc = documentDao.validateDocument(documentId);
|
||||||
|
|
||||||
|
Long hubId = threadLocalHubId.get();
|
||||||
|
HubEntity hub = hubRepository.findByHubId(hubId);
|
||||||
|
|
||||||
|
if (!hub.getUniqueUuid().equals(defaultHubUuid)) {
|
||||||
|
log.info("Document cannot be uploaded for another Hub, it is default for Gepafin.");
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NO_DOCUMENT_UPLOAD_FOR_ANOTHER_HUB));
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Got Document in system: {}", systemDoc);
|
||||||
|
String oldUrl = systemDoc.getFilePath();
|
||||||
|
String authorizationToken = getBearerToken(hub);
|
||||||
|
|
||||||
|
try {
|
||||||
|
File localFile = downloadFileFromS3(oldUrl);
|
||||||
|
MultipartFile multipartFile = convertFileToMultipartFile(localFile);
|
||||||
|
|
||||||
|
UploadDocToExternalSystemRequest externalSystemRequest = new UploadDocToExternalSystemRequest();
|
||||||
|
externalSystemRequest.setInput(getUploadDocumentInput(docToExternalSystemRequest));
|
||||||
|
|
||||||
|
String uploadDocRequest = Utils.convertObjectToJson(externalSystemRequest);
|
||||||
|
ResponseEntity<Object> uploadedDocumentData = appointmentApiService.uploadDocumentToExternalSystemForAppointment(authorizationToken, context, uploadDocRequest,
|
||||||
|
multipartFile);
|
||||||
|
|
||||||
|
String responseData = Utils.convertObjectToJson(uploadedDocumentData.getBody());
|
||||||
|
DocumentUploadResponse parsedResponse = parseDocumentUploadResponse(responseData);
|
||||||
|
|
||||||
|
if (parsedResponse == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_UPLOADING_DOCUMENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the documentAttachmentId to the database
|
||||||
|
systemDoc.setDocumentAttachmentId(parsedResponse.getDocumentAttachmentId());
|
||||||
|
documentRepository.save(systemDoc);
|
||||||
|
|
||||||
|
log.info("Document uploaded successfully to external system: {}", parsedResponse);
|
||||||
|
} catch (FeignException.Forbidden forbiddenException) {
|
||||||
|
log.error("403 Forbidden received while uploading document. Regenerating token...");
|
||||||
|
regenerateTokenAndSave(hub);
|
||||||
|
uploadDocumentToExternalSystemSync(documentId, docToExternalSystemRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception during document upload: {}", e.getMessage(), e);
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.EXTERNAL_DOCUMENT_UPLOAD_FAILURE_MSG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UploadDocToExternalSystemRequest.Input getUploadDocumentInput(UploadDocToExternalSystemRequest docToExternalSystemRequest) {
|
||||||
|
|
||||||
|
UploadDocToExternalSystemRequest.Input input = new UploadDocToExternalSystemRequest.Input();
|
||||||
|
input.setIdTipoProtocollo(docToExternalSystemRequest.getInput().getIdTipoProtocollo());
|
||||||
|
input.setIdClassificazione(docToExternalSystemRequest.getInput().getIdClassificazione());
|
||||||
|
input.setFlagDaFirmare(flagDaFirmare);
|
||||||
|
input.setDescrizione(docToExternalSystemRequest.getInput().getDescrizione());
|
||||||
|
|
||||||
|
UploadDocToExternalSystemRequest.Input.Attributes attributes = new UploadDocToExternalSystemRequest.Input.Attributes();
|
||||||
|
attributes.setNdg(docToExternalSystemRequest.getInput().getAttributes().getNdg());
|
||||||
|
attributes.setEmail(docToExternalSystemRequest.getInput().getAttributes().getEmail());
|
||||||
|
|
||||||
|
input.setAttributes(attributes);
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MultipartFile convertFileToMultipartFile(File file) throws IOException {
|
||||||
|
|
||||||
|
FileInputStream input = new FileInputStream(file);
|
||||||
|
return new MockMultipartFile(file.getName(), file.getName(), MediaType.APPLICATION_OCTET_STREAM_VALUE, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
private File downloadFileFromS3(String fileUrl) throws Exception {
|
||||||
|
|
||||||
|
String key = extractS3KeyFromUrl(fileUrl);
|
||||||
|
File localFile = new File(GepafinConstant.TEMP_FILE_PATH + extractFileName(key));
|
||||||
|
|
||||||
|
GetObjectRequest getObjectRequest = new GetObjectRequest(OLD_BUCKET, key);
|
||||||
|
|
||||||
|
try (InputStream s3Stream = s3Client.getObject(getObjectRequest).getObjectContent(); FileOutputStream outputStream = new FileOutputStream(localFile)) {
|
||||||
|
s3Stream.transferTo(outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Downloaded file from old S3 bucket: {}", key);
|
||||||
|
return localFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractS3KeyFromUrl(String url) {
|
||||||
|
|
||||||
|
return url.replace(s3Url, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractFileName(String filePath) {
|
||||||
|
|
||||||
|
String[] parts = filePath.split("/");
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentUploadResponse parseDocumentUploadResponse(String jsonResponse) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
|
|
||||||
|
// Navigate to the "data" node
|
||||||
|
JsonNode dataNode = rootNode.get(GepafinConstant.DATA_STRING);
|
||||||
|
if (dataNode != null) {
|
||||||
|
DocumentUploadResponse response = new DocumentUploadResponse();
|
||||||
|
|
||||||
|
// Extract "documentAttachmentId"
|
||||||
|
JsonNode documentAttachmentIdNode = dataNode.get(GepafinConstant.DOCUMENT_ATTACHMENT_ID_STRING);
|
||||||
|
if (documentAttachmentIdNode != null) {
|
||||||
|
response.setDocumentAttachmentId(documentAttachmentIdNode.asText());
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Invalid JSON structure: Missing 'documentAttachmentId' node.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to parse response: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,9 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity;
|
import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FaqEntity;
|
import net.gepafin.tendermanagement.entities.FaqEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
@@ -13,11 +15,14 @@ import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
|||||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UpdateAssignedApplicationRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
||||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
@@ -32,6 +37,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||||
@@ -58,12 +64,18 @@ public class AssignedApplicationsDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEvaluationDao applicationEvaluationDao;
|
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||||
|
|
||||||
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest) {
|
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest) {
|
||||||
log.info("Assigning application to pre-Instructor with details: {}", applicationId, userId);
|
log.info("Assigning application to pre-Instructor with details: {}", applicationId, userId);
|
||||||
|
|
||||||
@@ -89,8 +101,8 @@ public class AssignedApplicationsDao {
|
|||||||
|
|
||||||
UserEntity user = userService.validateUser(userId);
|
UserEntity user = userService.validateUser(userId);
|
||||||
AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest);
|
AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest);
|
||||||
|
applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, new ApplicationEvaluationRequest(), assignment.getId());
|
||||||
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
|
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
|
||||||
applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, new ApplicationEvaluationRequest(), assignApplicationToInstructorResponse.getId());
|
|
||||||
log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse);
|
log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse);
|
||||||
return assignApplicationToInstructorResponse;
|
return assignApplicationToInstructorResponse;
|
||||||
}
|
}
|
||||||
@@ -129,6 +141,7 @@ public class AssignedApplicationsDao {
|
|||||||
|
|
||||||
ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
|
ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
|
||||||
String callName = application.getCall() != null ? application.getCall().getName() : "";
|
String callName = application.getCall() != null ? application.getCall().getName() : "";
|
||||||
|
Optional<ApplicationEvaluationEntity> applicationEvaluationEntity=applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(application.getId());
|
||||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||||
LocalDateTime callStartDate = application.getCall().getStartDate();
|
LocalDateTime callStartDate = application.getCall().getStartDate();
|
||||||
|
|
||||||
@@ -155,12 +168,15 @@ public class AssignedApplicationsDao {
|
|||||||
assignedApplicationsResponse.setAssignedAt(assignedApplications.getAssignedAt());
|
assignedApplicationsResponse.setAssignedAt(assignedApplications.getAssignedAt());
|
||||||
assignedApplicationsResponse.setProtocolNumber(protocolNumber);
|
assignedApplicationsResponse.setProtocolNumber(protocolNumber);
|
||||||
assignedApplicationsResponse.setCallName(callName);
|
assignedApplicationsResponse.setCallName(callName);
|
||||||
assignedApplicationsResponse.setCompanyName(application.getCompany().getCompanyName());
|
CompanyEntity company=companyService.validateCompany(application.getCompanyId());
|
||||||
|
assignedApplicationsResponse.setCompanyName(company.getCompanyName());
|
||||||
assignedApplicationsResponse.setBeneficiaryName(beneficiaryName);
|
assignedApplicationsResponse.setBeneficiaryName(beneficiaryName);
|
||||||
assignedApplicationsResponse.setSubmissionDate(submissionDate);
|
assignedApplicationsResponse.setSubmissionDate(submissionDate);
|
||||||
assignedApplicationsResponse.setCallEndDate(callEndDate);
|
assignedApplicationsResponse.setCallEndDate(callEndDate);
|
||||||
assignedApplicationsResponse.setCallStartDate(callStartDate);
|
assignedApplicationsResponse.setCallStartDate(callStartDate);
|
||||||
|
if(applicationEvaluationEntity.isPresent()){
|
||||||
|
assignedApplicationsResponse.setEvaluationEndDate(applicationEvaluationEntity.get().getEndDate());
|
||||||
|
}
|
||||||
return assignedApplicationsResponse;
|
return assignedApplicationsResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +227,7 @@ public class AssignedApplicationsDao {
|
|||||||
|
|
||||||
|
|
||||||
public AssignedApplicationsResponse updateAssignedApplication(HttpServletRequest request,
|
public AssignedApplicationsResponse updateAssignedApplication(HttpServletRequest request,
|
||||||
Long id, AssignedApplicationsRequest updateRequest) {
|
Long id, UpdateAssignedApplicationRequest updateRequest) {
|
||||||
UserEntity updatedByUser = validator.validateUser(request);
|
UserEntity updatedByUser = validator.validateUser(request);
|
||||||
log.info("Updating assigned application with ID: {}", id);
|
log.info("Updating assigned application with ID: {}", id);
|
||||||
AssignedApplicationsEntity existingAssignment = validateAssignedApplication(id);
|
AssignedApplicationsEntity existingAssignment = validateAssignedApplication(id);
|
||||||
@@ -222,7 +238,9 @@ public class AssignedApplicationsDao {
|
|||||||
setIfUpdated(existingAssignment::getNote, existingAssignment::setNote, updateRequest.getNote());
|
setIfUpdated(existingAssignment::getNote, existingAssignment::setNote, updateRequest.getNote());
|
||||||
setIfUpdated(existingAssignment::getStatus, existingAssignment::setStatus, updateRequest.getStatus().name());
|
setIfUpdated(existingAssignment::getStatus, existingAssignment::setStatus, updateRequest.getStatus().name());
|
||||||
setIfUpdated(existingAssignment::getAssignedBy, existingAssignment::setAssignedBy, updatedByUser.getId());
|
setIfUpdated(existingAssignment::getAssignedBy, existingAssignment::setAssignedBy, updatedByUser.getId());
|
||||||
|
setIfUpdated(existingAssignment::getUserId, existingAssignment::setUserId, updateRequest.getUserId());
|
||||||
|
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(id);
|
||||||
|
entityOptional.ifPresent(applicationEvaluationEntity -> setIfUpdated(applicationEvaluationEntity::getUserId, applicationEvaluationEntity::setUserId, updateRequest.getUserId()));
|
||||||
existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
|
||||||
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment, oldAssignedApplicationEntity, VersionActionTypeEnum.UPDATE);
|
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment, oldAssignedApplicationEntity, VersionActionTypeEnum.UPDATE);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
|||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||||
@@ -12,6 +13,8 @@ import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
|||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.BeneficiaryPreferredCallRepository;
|
import net.gepafin.tendermanagement.repositories.BeneficiaryPreferredCallRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
@@ -41,6 +44,12 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@@ -50,16 +59,16 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest httpServletRequest, BeneficiaryPreferredCallReq request, UserEntity user) {
|
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest httpServletRequest, BeneficiaryPreferredCallReq request, UserEntity user) {
|
||||||
log.info("Creating new beneficiary preferred call with details: {}", request);
|
log.info("Creating new beneficiary preferred call with details: {}", request);
|
||||||
validator.validateUserWithCompany(httpServletRequest, request.getCompanyId());
|
validator.validateUserWithCompany(httpServletRequest, request.getCompanyId());
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(), request.getCompanyId());
|
||||||
Optional<BeneficiaryPreferredCallEntity> existingCall = beneficiaryPreferredCallRepository
|
Optional<BeneficiaryPreferredCallEntity> existingCall = beneficiaryPreferredCallRepository
|
||||||
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), request.getCompanyId());
|
.findByUserIdAndCallIdAndUserWithCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), userWithCompanyEntity.getId());
|
||||||
|
|
||||||
if (existingCall.isPresent()) {
|
if (existingCall.isPresent()) {
|
||||||
log.warn("Duplicate beneficiary preferred call detected: {}", existingCall.get());
|
log.warn("Duplicate beneficiary preferred call detected: {}", existingCall.get());
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DUPLICATE_BENEFICIARY_CALL));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DUPLICATE_BENEFICIARY_CALL));
|
||||||
}
|
}
|
||||||
|
|
||||||
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request, user);
|
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request, user,userWithCompanyEntity);
|
||||||
entity = beneficiaryPreferredCallRepository.save(entity);
|
entity = beneficiaryPreferredCallRepository.save(entity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for "Create Beneficiary Preferred Call" operation. **/
|
/** This code is responsible for adding a version history log for "Create Beneficiary Preferred Call" operation. **/
|
||||||
@@ -69,7 +78,7 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
return convertEntityToResponse(entity);
|
return convertEntityToResponse(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeneficiaryPreferredCallEntity convertRequestToEntity(BeneficiaryPreferredCallReq request,UserEntity userEntity) {
|
private BeneficiaryPreferredCallEntity convertRequestToEntity(BeneficiaryPreferredCallReq request,UserEntity userEntity,UserWithCompanyEntity userWithCompanyEntity) {
|
||||||
BeneficiaryPreferredCallEntity entity = new BeneficiaryPreferredCallEntity();
|
BeneficiaryPreferredCallEntity entity = new BeneficiaryPreferredCallEntity();
|
||||||
if (userEntity.getBeneficiary()!=null) {
|
if (userEntity.getBeneficiary()!=null) {
|
||||||
entity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
entity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||||
@@ -77,7 +86,8 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
entity.setStatus(BeneficiaryCallStatus.ENABLED.getValue());
|
entity.setStatus(BeneficiaryCallStatus.ENABLED.getValue());
|
||||||
entity.setCallId(request.getCallId());
|
entity.setCallId(request.getCallId());
|
||||||
entity.setUserId(userEntity.getId());
|
entity.setUserId(userEntity.getId());
|
||||||
entity.setCompanyId(request.getCompanyId());
|
entity.setCompanyId(userWithCompanyEntity.getCompanyId());
|
||||||
|
entity.setUserWithCompany(userWithCompanyEntity);
|
||||||
entity.setIsDeleted( false);
|
entity.setIsDeleted( false);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@@ -142,6 +152,7 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
response.setCallId(entity.getCallId());
|
response.setCallId(entity.getCallId());
|
||||||
response.setUserId(entity.getUserId());
|
response.setUserId(entity.getUserId());
|
||||||
response.setCompanyId(entity.getCompanyId());
|
response.setCompanyId(entity.getCompanyId());
|
||||||
|
response.setUserWithCompanyId(entity.getUserWithCompany().getId());
|
||||||
response.setCreatedDate(entity.getCreatedDate());
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
response.setUpdatedDate(entity.getUpdatedDate());
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
|
||||||
@@ -160,8 +171,8 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
log.info("Beneficiary preferred call status updated with ID: {}", existingEntity.getId());
|
log.info("Beneficiary preferred call status updated with ID: {}", existingEntity.getId());
|
||||||
}
|
}
|
||||||
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(UserEntity userEntity, Long companyId) {
|
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(UserEntity userEntity, Long companyId) {
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
|
||||||
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyId);
|
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId());
|
||||||
return calls.stream()
|
return calls.stream()
|
||||||
.map(this::convertEntityToResponse)
|
.map(this::convertEntityToResponse)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import java.util.zip.ZipOutputStream;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
@@ -49,6 +51,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
|||||||
|
|
||||||
import static net.gepafin.tendermanagement.enums.RoleStatusEnum.ROLE_SUPER_ADMIN;
|
import static net.gepafin.tendermanagement.enums.RoleStatusEnum.ROLE_SUPER_ADMIN;
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class CallDao {
|
public class CallDao {
|
||||||
@@ -99,12 +102,24 @@ public class CallDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationDao notificationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BeneficiaryRepository beneficiaryRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationTypeRepository notificationTypeRepository;
|
||||||
|
|
||||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||||
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||||
@@ -127,7 +142,7 @@ public class CallDao {
|
|||||||
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||||
|
|
||||||
for (DocumentEntity document : documents) {
|
for (DocumentEntity document : documents) {
|
||||||
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L);
|
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L,0L);
|
||||||
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) {
|
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) {
|
||||||
String fileName = Utils.extractFileName(document.getFilePath());
|
String fileName = Utils.extractFileName(document.getFilePath());
|
||||||
ZipEntry zipEntry = new ZipEntry(fileName);
|
ZipEntry zipEntry = new ZipEntry(fileName);
|
||||||
@@ -476,8 +491,9 @@ public class CallDao {
|
|||||||
BeneficiaryPreferredCallEntity preferredCall;
|
BeneficiaryPreferredCallEntity preferredCall;
|
||||||
if (companyId != null) {
|
if (companyId != null) {
|
||||||
validator.validateUserWithCompany(request, companyId);
|
validator.validateUserWithCompany(request, companyId);
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(),companyId);
|
||||||
preferredCall = beneficiaryPreferredCallRepository
|
preferredCall = beneficiaryPreferredCallRepository
|
||||||
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(userId, callId, companyId)
|
.findByUserIdAndCallIdAndUserWithCompanyIdAndIsDeletedFalse(userId, callId, userWithCompanyEntity.getId())
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
} else {
|
} else {
|
||||||
preferredCall = beneficiaryPreferredCallRepository
|
preferredCall = beneficiaryPreferredCallRepository
|
||||||
@@ -735,8 +751,9 @@ public class CallDao {
|
|||||||
|
|
||||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||||
validator.validateUserWithCompany(request, companyId);
|
validator.validateUserWithCompany(request, companyId);
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(),companyId);
|
||||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||||
.findByUserIdAndCompanyIdAndIsDeletedFalse(user.getId(), companyId);
|
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(user.getId(), userWithCompanyEntity.getId());
|
||||||
List<Long> preferredCallIds = preferredCalls.stream()
|
List<Long> preferredCallIds = preferredCalls.stream()
|
||||||
.map(BeneficiaryPreferredCallEntity::getCallId)
|
.map(BeneficiaryPreferredCallEntity::getCallId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -764,10 +781,11 @@ public class CallDao {
|
|||||||
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(HttpServletRequest request, UserEntity user, List<Long> callIds, Long companyId) {
|
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(HttpServletRequest request, UserEntity user, List<Long> callIds, Long companyId) {
|
||||||
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls;
|
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls;
|
||||||
|
|
||||||
if (companyId != null) {
|
if (companyId != null && Boolean.TRUE.equals(validator.checkIsBeneficiary())) {
|
||||||
validator.validateUserWithCompany(request, companyId);
|
validator.validateUserWithCompany(request, companyId);
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(),companyId);
|
||||||
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
|
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
|
||||||
.findByUserIdAndCallIdInAndCompanyIdAndIsDeletedFalse(user.getId(), callIds, companyId);
|
.findByUserIdAndCallIdInAndUserWithCompanyIdAndIsDeletedFalse(user.getId(), callIds, userWithCompanyEntity.getId());
|
||||||
} else {
|
} else {
|
||||||
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
|
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
|
||||||
.findByUserIdAndCallIdInAndIsDeletedFalse(user.getId(), callIds);
|
.findByUserIdAndCallIdInAndIsDeletedFalse(user.getId(), callIds);
|
||||||
@@ -823,6 +841,16 @@ public class CallDao {
|
|||||||
callEntity.setStatus(statusReq.getValue());
|
callEntity.setStatus(statusReq.getValue());
|
||||||
callEntity = callRepository.save(callEntity);
|
callEntity = callRepository.save(callEntity);
|
||||||
|
|
||||||
|
//Creating notification.
|
||||||
|
List<Long> userIds = beneficiaryRepository.findUserIdsByHubIdAndBeneficiaryId(callEntity.getHub().getId());
|
||||||
|
Map<String, String> placeholders = new HashMap<>();
|
||||||
|
placeholders.put("{{call_name}}", callEntity.getName());
|
||||||
|
userIds.forEach(userId -> {
|
||||||
|
List<Long> companyIds = notificationDao.getAllCompanyIdsForUser(userId);
|
||||||
|
NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId, null, companyIds);
|
||||||
|
notificationDao.sendNotification(notificationReq);
|
||||||
|
});
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "update call status" operation **/
|
/** This code is responsible for adding a version history log for the "update call status" operation **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(callEntity).build());
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(callEntity).build());
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
@@ -19,8 +24,6 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||||
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
|
||||||
@@ -42,6 +45,15 @@ public class CompanyDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FaqRepository faqRepository;
|
private FaqRepository faqRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@@ -55,7 +67,7 @@ public class CompanyDao {
|
|||||||
if (existingCompany != null) {
|
if (existingCompany != null) {
|
||||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
|
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
|
||||||
if (existingRelation == null) {
|
if (existingRelation == null) {
|
||||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant());
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant(),companyRequest);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for "adding user with company" operation. **/
|
/** This code is responsible for adding a version history log for "adding user with company" operation. **/
|
||||||
loggingUtil.addVersionHistory(
|
loggingUtil.addVersionHistory(
|
||||||
@@ -72,7 +84,7 @@ public class CompanyDao {
|
|||||||
/** This code is responsible for adding a version history log for "creating company" operation. **/
|
/** This code is responsible for adding a version history log for "creating company" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
|
||||||
|
|
||||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant(),companyRequest);
|
||||||
|
|
||||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||||
}
|
}
|
||||||
@@ -96,7 +108,7 @@ public class CompanyDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) {
|
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant,CompanyRequest companyRequest) {
|
||||||
|
|
||||||
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
||||||
if (userEntity.getBeneficiary() != null) {
|
if (userEntity.getBeneficiary() != null) {
|
||||||
@@ -106,6 +118,11 @@ public class CompanyDao {
|
|||||||
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
||||||
userWithCompanyEntity.setUserId(userEntity.getId());
|
userWithCompanyEntity.setUserId(userEntity.getId());
|
||||||
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
||||||
|
userWithCompanyEntity.setEmail(companyRequest.getEmail());
|
||||||
|
userWithCompanyEntity.setPec(companyRequest.getPec());
|
||||||
|
userWithCompanyEntity.setContactName(companyRequest.getContactName());
|
||||||
|
userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail());
|
||||||
|
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
|
||||||
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
||||||
@@ -124,12 +141,8 @@ public class CompanyDao {
|
|||||||
entity.setProvince(request.getProvince());
|
entity.setProvince(request.getProvince());
|
||||||
entity.setCap(request.getCap());
|
entity.setCap(request.getCap());
|
||||||
entity.setCountry(request.getCountry());
|
entity.setCountry(request.getCountry());
|
||||||
entity.setPec(request.getPec());
|
|
||||||
entity.setEmail(request.getEmail());
|
|
||||||
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||||
entity.setContactName(request.getContactName());
|
|
||||||
entity.setContactEmail(request.getContactEmail());
|
|
||||||
entity.setHub(userEntity.getHub());
|
entity.setHub(userEntity.getHub());
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@@ -146,8 +159,8 @@ public class CompanyDao {
|
|||||||
response.setProvince(entity.getProvince());
|
response.setProvince(entity.getProvince());
|
||||||
response.setCap(entity.getCap());
|
response.setCap(entity.getCap());
|
||||||
response.setCountry(entity.getCountry());
|
response.setCountry(entity.getCountry());
|
||||||
response.setPec(entity.getPec());
|
response.setPec(userWithCompanyEntity.getPec());
|
||||||
response.setEmail(entity.getEmail());
|
response.setEmail(userWithCompanyEntity.getEmail());
|
||||||
response.setNumberOfEmployees(entity.getNumberOfEmployees());
|
response.setNumberOfEmployees(entity.getNumberOfEmployees());
|
||||||
response.setAnnualRevenue(entity.getAnnualRevenue());
|
response.setAnnualRevenue(entity.getAnnualRevenue());
|
||||||
if(userWithCompanyEntity!=null) {
|
if(userWithCompanyEntity!=null) {
|
||||||
@@ -155,8 +168,8 @@ public class CompanyDao {
|
|||||||
}
|
}
|
||||||
response.setCreatedDate(entity.getCreatedDate());
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
response.setUpdatedDate(entity.getUpdatedDate());
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
response.setContactName(entity.getContactName());
|
response.setContactName(userWithCompanyEntity.getContactName());
|
||||||
response.setContactEmail(entity.getContactEmail());
|
response.setContactEmail(userWithCompanyEntity.getContactEmail());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +180,6 @@ public class CompanyDao {
|
|||||||
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
|
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
|
||||||
|
|
||||||
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName());
|
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName());
|
||||||
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
|
|
||||||
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale());
|
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale());
|
||||||
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
||||||
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber, companyRequest.getPhoneNumber());
|
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber, companyRequest.getPhoneNumber());
|
||||||
@@ -175,12 +187,17 @@ public class CompanyDao {
|
|||||||
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
|
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
|
||||||
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
|
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
|
||||||
setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
|
setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
|
||||||
setIfUpdated(companyEntity::getPec, companyEntity::setPec, companyRequest.getPec());
|
|
||||||
setIfUpdated(companyEntity::getEmail, companyEntity::setEmail, companyRequest.getEmail());
|
|
||||||
setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees, companyRequest.getNumberOfEmployees());
|
setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees, companyRequest.getNumberOfEmployees());
|
||||||
setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue, companyRequest.getAnnualRevenue());
|
setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue, companyRequest.getAnnualRevenue());
|
||||||
setIfUpdated(companyEntity::getContactName, companyEntity::setContactName, companyRequest.getContactName());
|
|
||||||
setIfUpdated(companyEntity::getContactEmail, companyEntity::setContactEmail, companyRequest.getContactEmail());
|
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||||
|
CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
|
||||||
|
if(existingCompany!=null){
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
||||||
|
}
|
||||||
|
companyEntity.setVatNumber(companyRequest.getVatNumber());
|
||||||
|
|
||||||
|
}
|
||||||
companyRepository.save(companyEntity);
|
companyRepository.save(companyEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||||
@@ -190,8 +207,15 @@ public class CompanyDao {
|
|||||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||||
//cloned entity for old data
|
//cloned entity for old data
|
||||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||||
|
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
||||||
|
setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson);
|
||||||
|
}
|
||||||
|
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, userWithCompanyEntity.getPec());
|
||||||
|
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, userWithCompanyEntity.getEmail());
|
||||||
|
setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName());
|
||||||
|
setIfUpdated(userWithCompanyEntity::getContactEmail, userWithCompanyEntity::setContactEmail, companyRequest.getContactEmail());
|
||||||
|
setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
||||||
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
|
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||||
@@ -249,36 +273,83 @@ public class CompanyDao {
|
|||||||
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
||||||
}
|
}
|
||||||
public void removeCompanyFromList(UserEntity userEntity, Long companyId) {
|
public void removeCompanyFromList(UserEntity userEntity, Long companyId) {
|
||||||
|
|
||||||
CompanyEntity companyEntity = validateCompany(companyId);
|
CompanyEntity companyEntity = validateCompany(companyId);
|
||||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyEntity.getId())
|
UserWithCompanyEntity existingRelation=companyService.getUserWithCompany(userEntity.getId(),companyEntity.getId());
|
||||||
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY)));
|
List<ApplicationEntity> userApplications = applicationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(existingRelation.getId(), userEntity.getId());
|
||||||
List<ApplicationEntity> userApplications = applicationRepository.findByCompanyIdAndUserIdAndIsDeletedFalse(companyEntity.getId(), userEntity.getId());
|
List<FaqEntity> faqs = faqRepository.findByUserWithCompanyIdAndIsDeletedFalse(existingRelation.getId());
|
||||||
List<FaqEntity> faqs = faqRepository.findByCompanyIdAndUserIdAndIsDeletedFalse(companyEntity.getId(), userEntity.getId());
|
List<BeneficiaryPreferredCallEntity> preferredCallEntities= beneficiaryPreferredCallRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(userEntity.getId(),existingRelation.getId());
|
||||||
for (ApplicationEntity application : userApplications) {
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(),existingRelation.getId(), UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
if (Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
List<String> applicationStatusAllowed = List.of(
|
||||||
|
ApplicationStatusTypeEnum.DRAFT.getValue(),
|
||||||
|
ApplicationStatusTypeEnum.AWAITING.getValue(),
|
||||||
|
ApplicationStatusTypeEnum.READY.getValue()
|
||||||
|
);
|
||||||
|
boolean notAllowedStatus = userApplications.stream()
|
||||||
|
.anyMatch(application -> !applicationStatusAllowed.contains(application.getStatus()));
|
||||||
|
if (notAllowedStatus) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.DRAFT.getValue()))) {
|
|
||||||
|
|
||||||
//cloned entity for old data
|
userApplications = userApplications.stream()
|
||||||
ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(application);
|
.peek(application -> {
|
||||||
|
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
||||||
application.setIsDeleted(Boolean.TRUE);
|
application.setIsDeleted(Boolean.TRUE);
|
||||||
applicationRepository.save(application);
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "" operation. **/
|
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldApplicationData).newData(application).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (FaqEntity faq : faqs) {
|
|
||||||
//cloned for old data
|
|
||||||
FaqEntity oldFaqEntityData = Utils.getClonedEntityForData(faq);
|
|
||||||
faq.setIsDeleted(Boolean.TRUE);
|
|
||||||
faqRepository.save(faq);
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "soft deleting faq" operation. **/
|
|
||||||
loggingUtil.addVersionHistory(
|
loggingUtil.addVersionHistory(
|
||||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaqEntityData).newData(faq).build());
|
VersionHistoryRequest.builder()
|
||||||
|
.request(request)
|
||||||
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
||||||
|
.oldData(oldApplication)
|
||||||
|
.newData(application)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
applicationRepository.saveAll(userApplications);
|
||||||
|
|
||||||
|
faqs = faqs.stream()
|
||||||
|
.peek(faq -> {
|
||||||
|
FaqEntity oldFaq = Utils.getClonedEntityForData(faq);
|
||||||
|
faq.setIsDeleted(Boolean.TRUE);
|
||||||
|
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder()
|
||||||
|
.request(request)
|
||||||
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
||||||
|
.oldData(oldFaq)
|
||||||
|
.newData(faq)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
faqRepository.saveAll(faqs);
|
||||||
|
|
||||||
|
preferredCallEntities = preferredCallEntities.stream()
|
||||||
|
.peek(beneficiaryPreferredCall -> {
|
||||||
|
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
|
||||||
|
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
|
||||||
|
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder()
|
||||||
|
.request(request)
|
||||||
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
||||||
|
.oldData(oldPreferredCall)
|
||||||
|
.newData(beneficiaryPreferredCall)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
beneficiaryPreferredCallRepository.saveAll(preferredCallEntities);
|
||||||
|
|
||||||
|
if(userCompanyDelegationEntity!=null){
|
||||||
|
UserCompanyDelegationEntity oldUserWithCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||||
|
userCompanyDelegationEntity.setStatus( UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||||
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Update UserWithCompanyDelegation" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserWithCompanyDelegation).newData(userCompanyDelegationEntity).build());
|
||||||
}
|
}
|
||||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(existingRelation);
|
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(existingRelation);
|
||||||
existingRelation.setIsDeleted(Boolean.TRUE);
|
existingRelation.setIsDeleted(Boolean.TRUE);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
@@ -12,6 +13,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
|||||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -32,6 +34,9 @@ public class DashboardDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyRepository companyRepository;
|
private CompanyRepository companyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
||||||
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||||
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
||||||
@@ -108,8 +113,9 @@ public class DashboardDao {
|
|||||||
if (activeCalls != null) {
|
if (activeCalls != null) {
|
||||||
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
|
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
|
||||||
}
|
}
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||||
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
|
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
|
||||||
company.getId());
|
userWithCompanyEntity.getId());
|
||||||
if (activeApplication != null) {
|
if (activeApplication != null) {
|
||||||
beneficiaryWidgetResponseBean.setNumberOfApplications(activeApplication);
|
beneficiaryWidgetResponseBean.setNumberOfApplications(activeApplication);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
@@ -21,10 +26,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
|
||||||
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
|
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
|
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
|
||||||
@@ -33,6 +34,7 @@ import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
|||||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
|
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationEvaluationService;
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
@@ -70,15 +72,27 @@ public class DelegationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationService applicationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationService applicationEvaluationService;
|
||||||
|
|
||||||
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||||
try {
|
try {
|
||||||
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L);
|
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L,0L);
|
||||||
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
|
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
|
||||||
XWPFDocument doc = loadTemplate(templateStream);
|
XWPFDocument doc = loadTemplate(templateStream);
|
||||||
replacePlaceholders(doc, placeholders);
|
replacePlaceholders(doc, placeholders);
|
||||||
@@ -191,20 +205,18 @@ public class DelegationDao {
|
|||||||
companyDao.validateCompany(companyId);
|
companyDao.validateCompany(companyId);
|
||||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
validateFileType(file);
|
validateFileType(file);
|
||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
|
||||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
UserCompanyDelegationEntity oldUserCompanyDelegationEntity = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
|
||||||
if (userCompanyDelegationEntity != null) {
|
|
||||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
|
||||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "update user company delegation status" operation. **/
|
if (userCompanyDelegationEntity != null) {
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserCompanyDelegationEntity)
|
deleteDelegationFromS3(userCompanyDelegationEntity);
|
||||||
.newData(userCompanyDelegationEntity).build());
|
|
||||||
}
|
}
|
||||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
|
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
|
||||||
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
||||||
userCompanyDelegationEntity.setCompanyId(companyId);
|
userCompanyDelegationEntity.setUserWithCompany(userWithCompanyEntity);
|
||||||
|
userCompanyDelegationEntity.setCompanyId(userWithCompanyEntity.getCompanyId());
|
||||||
userCompanyDelegationEntity.setUserId(userEntity.getId());
|
userCompanyDelegationEntity.setUserId(userEntity.getId());
|
||||||
if (userEntity.getBeneficiary() != null) {
|
if (userEntity.getBeneficiary() != null) {
|
||||||
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||||
@@ -253,11 +265,12 @@ public class DelegationDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyDelegationResponse getCompanyDelegation(UserEntity userEntity, Long companyId) {
|
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId, Long applicationId) {
|
||||||
|
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity= validateUserAndGetUserWithCompany(request, companyId, applicationId);
|
||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
.findByUserIdAndUserWithCompanyIdAndStatus(userWithCompanyEntity.getUserId(), userWithCompanyEntity.getId(),
|
||||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
|
||||||
if(userCompanyDelegationEntity == null) {
|
if(userCompanyDelegationEntity == null) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
@@ -265,20 +278,49 @@ public class DelegationDao {
|
|||||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
private UserWithCompanyEntity validateUserAndGetUserWithCompany(HttpServletRequest request, Long companyId,
|
||||||
|
Long applicationId) {
|
||||||
|
Long userId = null;
|
||||||
|
if (companyId == null && applicationId == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.ATLEAST_ONE_ID_REQUIRED));
|
||||||
|
}
|
||||||
|
if (applicationId != null) {
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
userId = application.getUserId();
|
||||||
|
companyId = application.getCompanyId();
|
||||||
|
}
|
||||||
|
if (validator.checkIsPreInstructor()) {
|
||||||
|
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluationByApplicationId(applicationId);
|
||||||
|
validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId());
|
||||||
|
} else if (validator.checkIsBeneficiary()) {
|
||||||
|
userId = validator.validateUser(request).getId();
|
||||||
|
}
|
||||||
|
return companyService.getUserWithCompany(userId, companyId);
|
||||||
|
}
|
||||||
|
|
||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
|
||||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
//cloned entity for old data
|
|
||||||
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
|
||||||
|
|
||||||
if (userCompanyDelegationEntity == null) {
|
if (userCompanyDelegationEntity == null) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
deleteDelegationFromS3(userCompanyDelegationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDelegationFromS3(UserCompanyDelegationEntity userCompanyDelegationEntity) {
|
||||||
|
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||||
|
String oldS3Path = userCompanyDelegationEntity.getFilePath();
|
||||||
|
String newS3Path = s3ConfigBean.generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum.DELETED_USER_DELEGATION);
|
||||||
|
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(userCompanyDelegationEntity.getFileName(), oldS3Path, newS3Path);
|
||||||
|
userCompanyDelegationEntity.setFileName(response.getFileName());
|
||||||
|
userCompanyDelegationEntity.setFilePath(response.getFilePath());
|
||||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Soft Deleting company delegation " operation. **/
|
/** This code is responsible for adding a version history log for the "Soft Deleting company delegation " operation. **/
|
||||||
loggingUtil.addVersionHistory(
|
loggingUtil.addVersionHistory(
|
||||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserCompanyDelegation).newData(userCompanyDelegationEntity)
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserCompanyDelegation).newData(userCompanyDelegationEntity)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import net.gepafin.tendermanagement.enums.*;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
@@ -18,20 +17,24 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class DocumentDao {
|
public class DocumentDao {
|
||||||
@@ -52,7 +55,22 @@ public class DocumentDao {
|
|||||||
private S3PathConfig s3ConfigBean;
|
private S3PathConfig s3ConfigBean;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationRepository applicationFormRepository;
|
private ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationService applicationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationAmendmentRequestService applicationAmendmentRequestService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||||
|
|
||||||
|
@Value("${aws.s3.bucket.name}")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
@@ -63,7 +81,7 @@ public class DocumentDao {
|
|||||||
// @Value("${aws.s3.url.folder}")
|
// @Value("${aws.s3.url.folder}")
|
||||||
// private String s3Folder;
|
// private String s3Folder;
|
||||||
|
|
||||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
public List<DocumentResponseBean> uploadFiles(Long userId,List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||||
|
|
||||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||||
Long source = resolveSourceId(sourceId, sourceType);
|
Long source = resolveSourceId(sourceId, sourceType);
|
||||||
@@ -77,6 +95,7 @@ public class DocumentDao {
|
|||||||
documentEntity.setType(fileType.getValue());
|
documentEntity.setType(fileType.getValue());
|
||||||
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||||
documentEntity.setIsDeleted(false);
|
documentEntity.setIsDeleted(false);
|
||||||
|
documentEntity.setUploadedBy(userId);
|
||||||
documentEntities.add(documentEntity);
|
documentEntities.add(documentEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,6 +121,14 @@ public class DocumentDao {
|
|||||||
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_DOCUMENT;
|
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_DOCUMENT;
|
||||||
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||||
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_IMAGES;
|
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_IMAGES;
|
||||||
|
}else if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.AMENDMENT)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_AMENDMENT_DOCUMENT;
|
||||||
|
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.AMENDMENT)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_AMENDMENT_IMAGES;
|
||||||
|
}else if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.EVALUATION)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_EVALUATION_DOCUMENT;
|
||||||
|
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.EVALUATION)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_EVALUATION_IMAGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return userActionContext;
|
return userActionContext;
|
||||||
@@ -122,27 +149,40 @@ public class DocumentDao {
|
|||||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
||||||
|
|
||||||
Long applicationId = 0L;
|
Long applicationId = 0L;
|
||||||
|
Long amendmentId = 0L;
|
||||||
|
Long evaluationId = 0L;
|
||||||
Long callId = sourceId;
|
Long callId = sourceId;
|
||||||
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
||||||
applicationId = sourceId;
|
applicationId = sourceId;
|
||||||
callId = applicationFormRepository.findCallIdById(applicationId);
|
callId = applicationRepository.findCallIdById(applicationId);
|
||||||
|
} else if (type == DocumentSourceTypeEnum.AMENDMENT) {
|
||||||
|
amendmentId = sourceId;
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}else if (type == DocumentSourceTypeEnum.EVALUATION) {
|
||||||
|
evaluationId = sourceId;
|
||||||
|
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String s3Path = generateS3Path(type, callId, applicationId);
|
String s3Path = generateS3Path(type, callId, applicationId, amendmentId);
|
||||||
log.info("Generated S3 path {}", s3Path);
|
log.info("Generated S3 path {}", s3Path);
|
||||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId) {
|
|
||||||
|
|
||||||
|
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId) {
|
||||||
try {
|
try {
|
||||||
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId);
|
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
||||||
|
|
||||||
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
||||||
@@ -159,25 +199,37 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFile(Long documentId) {
|
public void deleteFile(Long documentId) {
|
||||||
|
DocumentEntity documentEntity = documentRepository.findById(documentId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
DocumentEntity documentEntity = documentRepository.findById(documentId)
|
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
if(Boolean.TRUE.equals(documentEntity.getIsDeleted())){
|
||||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
return;
|
||||||
// deleteFileOnAmazonS3(fileName);
|
|
||||||
|
|
||||||
//cloned for old data
|
|
||||||
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
|
||||||
|
|
||||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
|
||||||
// deleteFileOnAmazonS3(fileName);
|
|
||||||
documentEntity.setIsDeleted(true);
|
|
||||||
documentRepository.save(documentEntity);
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Soft delete document" operation. **/
|
|
||||||
loggingUtil.addVersionHistory(
|
|
||||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldDocumentEntity).newData(documentEntity).build());
|
|
||||||
}
|
}
|
||||||
|
Long callId = null;
|
||||||
|
Long applicationId = null;
|
||||||
|
Long amendmentId = null;
|
||||||
|
Long evaluationId = null;
|
||||||
|
|
||||||
|
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||||
|
callId = documentEntity.getSourceId();
|
||||||
|
} else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||||
|
applicationId = documentEntity.getSourceId();
|
||||||
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
else if(DocumentSourceTypeEnum.AMENDMENT.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||||
|
amendmentId = documentEntity.getSourceId();
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
} else if(DocumentSourceTypeEnum.EVALUATION.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||||
|
evaluationId = documentEntity.getSourceId();
|
||||||
|
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DocumentEntity validateDocument(Long id) {
|
public DocumentEntity validateDocument(Long id) {
|
||||||
return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
@@ -206,19 +258,35 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UploadFileOnAmazonS3Response updateFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long id) {
|
private UploadFileOnAmazonS3Response updateFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long id) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Long callId;
|
Long callId=null;
|
||||||
Long applicationId;
|
Long applicationId=null;
|
||||||
if(type.equals(DocumentSourceTypeEnum.APPLICATION)){
|
Long amendmentId=null;
|
||||||
callId = applicationFormRepository.findCallIdById(id);
|
Long evaluationId=null;
|
||||||
|
if (type.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||||
|
callId = applicationRepository.findCallIdById(id);
|
||||||
applicationId = id;
|
applicationId = id;
|
||||||
}else{
|
}
|
||||||
|
else if(type.equals(DocumentSourceTypeEnum.AMENDMENT)){
|
||||||
|
amendmentId = id;
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}else if(type.equals(DocumentSourceTypeEnum.EVALUATION)){
|
||||||
|
evaluationId = id;
|
||||||
|
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
callId = id;
|
callId = id;
|
||||||
applicationId = 0L;
|
applicationId = 0L;
|
||||||
}
|
}
|
||||||
String s3Path = generateS3Path(type, callId, applicationId);
|
String s3Path = generateS3Path(type, callId, applicationId,amendmentId);
|
||||||
log.info("Generated S3 path {}", s3Path);
|
log.info("Generated S3 path {}", s3Path);
|
||||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -229,4 +297,26 @@ public class DocumentDao {
|
|||||||
DocumentEntity documentEntity = validateDocument(documentId);
|
DocumentEntity documentEntity = validateDocument(documentId);
|
||||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||||
|
String oldS3Path = documentEntity.getFilePath();
|
||||||
|
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId);
|
||||||
|
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path);
|
||||||
|
documentEntity.setFileName(response.getFileName());
|
||||||
|
documentEntity.setFilePath(response.getFilePath());
|
||||||
|
documentEntity.setIsDeleted(true);
|
||||||
|
documentRepository.save(documentEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Soft delete document" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldDocumentEntity).newData(documentEntity).build());
|
||||||
|
log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error moving file for document ID {} to deleted folder: {}", documentEntity.getId(), e.getMessage());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, "Error occurred while moving file to deleted folder.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.EmailContentResponse;
|
||||||
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
import net.gepafin.tendermanagement.service.*;
|
||||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
|
||||||
import net.gepafin.tendermanagement.service.HubService;
|
|
||||||
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
|
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
|
||||||
import net.gepafin.tendermanagement.service.impl.EmailService;
|
import net.gepafin.tendermanagement.service.impl.EmailService;
|
||||||
import net.gepafin.tendermanagement.service.impl.EmailServiceFactory;
|
import net.gepafin.tendermanagement.service.impl.EmailServiceFactory;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
@@ -25,11 +19,14 @@ import net.gepafin.tendermanagement.util.Utils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao.filterByName;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EmailNotificationDao {
|
public class EmailNotificationDao {
|
||||||
|
|
||||||
@@ -59,85 +56,180 @@ public class EmailNotificationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmailLogRepository emailLogRepository;
|
private EmailLogRepository emailLogRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType,
|
@Autowired
|
||||||
Map<String, String> bodyPlaceholders, List<String> additionalRecipients,Long amendmentId) {
|
private ApplicationFormRepository applicationFormRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||||
|
|
||||||
|
@Value("${rinaldo_email}")
|
||||||
|
private String rinaldoEmail;
|
||||||
|
|
||||||
|
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType, Map<String, String> bodyPlaceholders,
|
||||||
|
List<String> additionalRecipients, Long amendmentId) {
|
||||||
|
|
||||||
HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId());
|
HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId());
|
||||||
String service = determineService(applicationEntity.getHubId());
|
// String service = determineService(applicationEntity.getHubId());
|
||||||
String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it";
|
// String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it";
|
||||||
|
|
||||||
|
EmailContentResponse emailContent = prepareEmailContent(applicationEntity, templateType, hubEntity, bodyPlaceholders);
|
||||||
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||||
|
sendEmails(applicationEntity, userEntity, additionalRecipients,amendmentId,emailContent.getSystemEmailTemplateResponse(),emailContent.getSubject(),emailContent.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailContentResponse prepareEmailContent(
|
||||||
|
ApplicationEntity applicationEntity,
|
||||||
|
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType,
|
||||||
|
HubEntity hubEntity,
|
||||||
|
Map<String, String> bodyPlaceholders
|
||||||
|
) {
|
||||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null);
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null);
|
||||||
|
|
||||||
Map<String, String> subjectPlaceholders = new HashMap<>();
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||||
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||||
subjectPlaceholders.put("{{company_name}}", applicationEntity.getCompany().getCompanyName());
|
subjectPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||||
bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
// bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
||||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
|
|
||||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
return new EmailContentResponse(subject, body, systemEmailTemplateResponse);
|
||||||
List<String> recipientEmails = getRecipientEmails(applicationEntity, userEntity, additionalRecipients);
|
|
||||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY,userEntity.getBeneficiary().getId(),Utils.listToCommaSeparatedString(recipientEmails),userEntity.getId(),applicationEntity.getId(),amendmentId ,applicationEntity.getCall().getId());
|
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails,emailLogRequest);
|
|
||||||
}
|
}
|
||||||
private List<String> getRecipientEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients) {
|
|
||||||
List<String> recipientEmails = new ArrayList<>();
|
private void sendEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients,Long amendmentId,SystemEmailTemplateResponse systemEmailTemplateResponse,String subject,String body) {
|
||||||
String companyEmail = applicationEntity.getCompany().getEmail();
|
|
||||||
String contactEmail = applicationEntity.getCompany().getContactEmail();
|
Optional<ApplicationEvaluationEntity> applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
|
||||||
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
|
|
||||||
|
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||||
|
String companyEmail = userWithCompany.getEmail();
|
||||||
|
String contactEmail = userWithCompany.getContactEmail();
|
||||||
|
|
||||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||||
recipientEmails.add(companyEmail);
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,
|
||||||
|
companyEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(companyEmail), emailLogRequest);
|
||||||
}
|
}
|
||||||
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||||
recipientEmails.add(contactEmail);
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId(),
|
||||||
|
contactEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(contactEmail), emailLogRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userEntity.getBeneficiary().getEmail() != null) {
|
if (userEntity.getBeneficiary().getEmail() != null) {
|
||||||
recipientEmails.add(userEntity.getBeneficiary().getEmail());
|
String beneficiaryEmail = userEntity.getBeneficiary().getEmail();
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY,userEntity.getBeneficiary().getId() ,
|
||||||
|
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogRequest);
|
||||||
}
|
}
|
||||||
if (additionalRecipients != null) {
|
if(userEntity.getHub().getEmail() != null){
|
||||||
recipientEmails.addAll(additionalRecipients);
|
String hubEmails = userEntity.getHub().getEmail();
|
||||||
|
String[] hubEmailArray = hubEmails.split(",");
|
||||||
|
for (String hubEmail : hubEmailArray) {
|
||||||
|
hubEmail = hubEmail.trim();
|
||||||
|
if (!hubEmail.isEmpty()) {
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null,
|
||||||
|
hubEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(hubEmail), emailLogRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return recipientEmails;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String determineService(Long hubId) {
|
|
||||||
|
|
||||||
HubEntity hub = hubRepository.findById(hubId).orElseThrow(() -> new IllegalArgumentException("Invalid Hub ID: " + hubId));
|
|
||||||
return hub.getEmailServiceType().equalsIgnoreCase("MAILGUN_SERVICE") ? "Gepafin S.p.a." : "Sviluppumbria";
|
|
||||||
}
|
}
|
||||||
|
if (rinaldoEmail != null) {
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
|
||||||
|
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(rinaldoEmail), emailLogRequest);
|
||||||
|
}
|
||||||
|
if (applicationEvaluationEntity.isPresent()) {
|
||||||
|
Long preInstructorId = applicationEvaluationEntity.get().getUserId(); // Assuming UserEntity has an email field
|
||||||
|
UserEntity instructorUser = userService.validateUser(preInstructorId);
|
||||||
|
String preInstructorEmail = instructorUser.getEmail();
|
||||||
|
if (preInstructorEmail != null && !preInstructorEmail.isEmpty()) {
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.INSTRUCTOR, instructorUser.getId(),
|
||||||
|
preInstructorEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(preInstructorEmail), emailLogRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// private String determineService(Long hubId) {
|
||||||
|
//
|
||||||
|
// HubEntity hub = hubRepository.findById(hubId).orElseThrow(() -> new IllegalArgumentException("Invalid Hub ID: " + hubId));
|
||||||
|
// return hub.getEmailServiceType().equalsIgnoreCase("MAILGUN_SERVICE") ? "Sviluppumbria" : "Gepafin S.p.a.";
|
||||||
|
// }
|
||||||
|
|
||||||
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequest) {
|
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequest.getApplicationId());
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequestEntity.getApplicationId());
|
||||||
|
Map<String, String> bodyPlaceholders = prepareEmailPlaceholders(applicationEntity, applicationAmendmentRequestEntity);
|
||||||
|
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,
|
||||||
|
applicationAmendmentRequestEntity.getId());
|
||||||
|
}
|
||||||
|
public Map<String, String> prepareEmailPlaceholders(ApplicationEntity applicationEntity, ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){
|
||||||
Map<String, String> bodyPlaceholders = new HashMap<>();
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||||
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||||
bodyPlaceholders.put("{{protocol_number}}", applicationAmendmentRequest.getProtocol().getProtocolNumber().toString());
|
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
||||||
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationAmendmentRequest.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationEntity.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
||||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationAmendmentRequest.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||||
String formFieldsJson = applicationAmendmentRequest.getFormFields();
|
bodyPlaceholders.put("{{response_days}}", applicationAmendmentRequestEntity.getResponseDays().toString());
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Map<String, Object>> formFields = objectMapper.readValue(formFieldsJson, new TypeReference<List<Map<String, Object>>>() {
|
// Retrieve forms and initialize required collections
|
||||||
});
|
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||||
//•
|
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||||
StringBuilder bulletPoints = new StringBuilder();
|
StringBuilder bulletPoints = new StringBuilder();
|
||||||
for (Map<String, Object> field : formFields) {
|
|
||||||
String label = (String) field.get("label");
|
// Extract data from forms
|
||||||
boolean selected = (boolean) field.get("selected");
|
for (ApplicationFormEntity form : forms) {
|
||||||
if (!selected) {
|
String content = form.getForm().getContent();
|
||||||
bulletPoints.append("• ").append(label).append("\n");
|
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||||
|
allFormFields.addAll(getIdAndLabelFromResult(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process allFormFields and generate bullet points
|
||||||
|
for (AmendmentFormFieldResponse field : allFormFields) {
|
||||||
|
// Build bullet points
|
||||||
|
// bulletPoints.append(field.getLabel());
|
||||||
|
bulletPoints.append("<li>").append(field.getLabel()).append("</li>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Add the generated bullet points to placeholders
|
||||||
bodyPlaceholders.put("{{form_dataInput}}", bulletPoints.toString());
|
bodyPlaceholders.put("{{form_dataInput}}", bulletPoints.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to parse form fields JSON: ", e);
|
log.error("Failed to process form fields: ", e);
|
||||||
}
|
}
|
||||||
bodyPlaceholders.put("{{note}}", applicationAmendmentRequest.getNote());
|
|
||||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,applicationAmendmentRequest.getId());
|
|
||||||
|
bodyPlaceholders.put("{{note}}", applicationAmendmentRequestEntity.getNote());
|
||||||
|
return bodyPlaceholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) {
|
||||||
|
List<AmendmentFormFieldResponse> formFieldResponses = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map<String, Object> item : result) {
|
||||||
|
AmendmentFormFieldResponse formFieldResponse = new AmendmentFormFieldResponse();
|
||||||
|
formFieldResponse.setFieldId((String) item.get("id"));
|
||||||
|
|
||||||
|
// Extract "label" value from the "settings" array
|
||||||
|
List<Map<String, Object>> settings = (List<Map<String, Object>>) item.get("settings");
|
||||||
|
String label = settings.stream()
|
||||||
|
.filter(setting -> "label".equals(setting.get("name")))
|
||||||
|
.map(setting -> (String) setting.get("value"))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(""); // Default to empty string if not found
|
||||||
|
|
||||||
|
if (label == null || label.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
formFieldResponse.setLabel(label); // Set the label as fieldValue
|
||||||
|
formFieldResponses.add(formFieldResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
return formFieldResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FaqEntity;
|
import net.gepafin.tendermanagement.entities.FaqEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
@@ -13,6 +14,7 @@ import net.gepafin.tendermanagement.model.request.FaqReq;
|
|||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.service.CompanyService;
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.LookUpDataService;
|
import net.gepafin.tendermanagement.service.LookUpDataService;
|
||||||
@@ -30,6 +32,7 @@ import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class FaqDao {
|
public class FaqDao {
|
||||||
@@ -49,6 +52,9 @@ public class FaqDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
|
|
||||||
@@ -63,10 +69,15 @@ public class FaqDao {
|
|||||||
if (validator.checkIsBeneficiary() && companyId == null) {
|
if (validator.checkIsBeneficiary() && companyId == null) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
|
||||||
}
|
}
|
||||||
if (companyId != null) {
|
UserWithCompanyEntity userWithCompanyEntity=null;
|
||||||
companyService.validateCompany(companyId);
|
if(companyId!=null) {
|
||||||
entity.setCompanyId(companyId);
|
userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
|
||||||
|
companyService.validateCompany(userWithCompanyEntity.getCompanyId());
|
||||||
|
entity.setCompanyId(userWithCompanyEntity.getCompanyId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entity.setUserWithCompany(userWithCompanyEntity);
|
||||||
faqRepository.save(entity);
|
faqRepository.save(entity);
|
||||||
|
|
||||||
if (entity.getCompanyId() != null) {
|
if (entity.getCompanyId() != null) {
|
||||||
|
|||||||
@@ -3,19 +3,15 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationFormEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationFormFieldEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.FormEntity;
|
|
||||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
@@ -44,6 +40,8 @@ public class FlowFormDao {
|
|||||||
private FormService formService;
|
private FormService formService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private FormDao formDao;
|
private FormDao formDao;
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -290,6 +288,7 @@ public class FlowFormDao {
|
|||||||
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
|
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
|
||||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||||
Integer completedSteps=0;
|
Integer completedSteps=0;
|
||||||
|
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
||||||
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
||||||
nextOrPreviousFormResponse.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(applicationEntity.getStatus()));
|
nextOrPreviousFormResponse.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(applicationEntity.getStatus()));
|
||||||
@@ -297,8 +296,8 @@ public class FlowFormDao {
|
|||||||
applicationDao.processForm(formEntity, applicationEntity));
|
applicationDao.processForm(formEntity, applicationEntity));
|
||||||
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
||||||
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
||||||
nextOrPreviousFormResponse.setCompanyId(applicationEntity.getCompany().getId());
|
nextOrPreviousFormResponse.setCompanyId(applicationEntity.getCompanyId());
|
||||||
nextOrPreviousFormResponse.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
nextOrPreviousFormResponse.setCompanyName(company.getCompanyName());
|
||||||
|
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||||
|
|||||||
@@ -0,0 +1,278 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.NotificationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.NotificationEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||||
|
import net.gepafin.tendermanagement.model.response.NotificationResponse;
|
||||||
|
import net.gepafin.tendermanagement.repositories.NotificationRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
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.messaging.simp.SimpMessagingTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class NotificationDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SimpMessagingTemplate messagingTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationRepository notificationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotificationTypeRepository notificationTypeRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyDao companyDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationService applicationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
public NotificationResponse sendNotification(NotificationReq notificationReq) {
|
||||||
|
|
||||||
|
// Ensure userId is properly set in notificationReq if not already
|
||||||
|
Long userId = notificationReq.getUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
log.error("User ID is missing in the notification request.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
NotificationEntity notificationEntity = saveNotification(notificationReq);
|
||||||
|
log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage());
|
||||||
|
List<Long> companyIds = notificationReq.getCompanyIds();
|
||||||
|
|
||||||
|
if (companyIds == null || companyIds.isEmpty()) {
|
||||||
|
sendToUser(userId, notificationEntity);
|
||||||
|
} else {
|
||||||
|
sendToCompanies(userId, companyIds, notificationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NotificationEntity saveNotification(NotificationReq notificationReq) {
|
||||||
|
|
||||||
|
return notificationRepository.save(convertNotificationRequestToNotificationEntity(notificationReq));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToUser(Long userId, NotificationEntity notificationEntity) {
|
||||||
|
|
||||||
|
String userChannel = GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId;
|
||||||
|
log.info("Channel for User {}", userChannel);
|
||||||
|
NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||||
|
messagingTemplate.convertAndSend(userChannel, notificationResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToCompanies(Long userId, List<Long> companyIds, NotificationEntity notificationEntity) {
|
||||||
|
// Send notification to each company provided in the companyIds list
|
||||||
|
companyIds.forEach(companyId -> {
|
||||||
|
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId);
|
||||||
|
String companyChannel = Utils.createChannelForUserAndCompany(userId, companyId);
|
||||||
|
log.info("Channel for User and Company {}, {}", userId, companyChannel);
|
||||||
|
if (userWithCompany == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_WITH_COMPANY_NOT_FOUND);
|
||||||
|
}
|
||||||
|
notificationEntity.setUserWithCompany(userWithCompany);
|
||||||
|
notificationRepository.save(notificationEntity);
|
||||||
|
NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||||
|
messagingTemplate.convertAndSend(companyChannel, notificationResponse);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private NotificationResponse convertNotificationEntityToNotificationResponse(NotificationEntity notificationEntity) {
|
||||||
|
|
||||||
|
NotificationResponse notificationResponse = new NotificationResponse();
|
||||||
|
notificationResponse.setId(notificationEntity.getId());
|
||||||
|
notificationResponse.setUserId(notificationEntity.getUserId());
|
||||||
|
notificationResponse.setStatus(notificationEntity.getStatus());
|
||||||
|
notificationResponse.setMessage(notificationEntity.getMessage());
|
||||||
|
notificationResponse.setCreatedDate(notificationEntity.getCreatedDate());
|
||||||
|
notificationResponse.setUpdatedDate(notificationEntity.getUpdatedDate());
|
||||||
|
notificationResponse.setRedirectUrl(notificationEntity.getNotificationType());
|
||||||
|
notificationResponse.setCompanyId(notificationEntity.getUserWithCompany() != null ? notificationEntity.getUserWithCompany().getCompanyId() : null);
|
||||||
|
notificationResponse.setNotificationType(notificationEntity.getNotificationType());
|
||||||
|
notificationResponse.setTitle(notificationEntity.getTitle());
|
||||||
|
return notificationResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NotificationEntity convertNotificationRequestToNotificationEntity(NotificationReq notificationReq) {
|
||||||
|
|
||||||
|
NotificationEntity notificationEntity = new NotificationEntity();
|
||||||
|
String message = notificationReq.getMessage();
|
||||||
|
notificationEntity.setNotificationType(notificationReq.getNotificationType());
|
||||||
|
notificationEntity.setUserId(notificationReq.getUserId());
|
||||||
|
notificationEntity.setStatus(NotificationEnum.UNREAD.getValue());
|
||||||
|
notificationEntity.setIsDeleted(Boolean.FALSE);
|
||||||
|
notificationEntity.setUserWithCompany(notificationReq.getUserWithCompanyEntity() != null ? notificationReq.getUserWithCompanyEntity() : null);
|
||||||
|
notificationEntity.setMessage(message);
|
||||||
|
notificationEntity.setTitle(notificationReq.getTitle());
|
||||||
|
return notificationEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotificationReq createNotificationReq(String notificationType, Map<String, String> placeholders, Long userId, UserWithCompanyEntity userWithCompanyEntity,
|
||||||
|
List<Long> companyIds) {
|
||||||
|
// Create NotificationReq object
|
||||||
|
NotificationReq notificationReq = new NotificationReq();
|
||||||
|
NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType);
|
||||||
|
notificationReq.setNotificationType(notificationType);
|
||||||
|
String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders);
|
||||||
|
notificationReq.setMessage(message);
|
||||||
|
notificationReq.setUserId(userId);
|
||||||
|
notificationReq.setCompanyIds(companyIds);
|
||||||
|
String title = Utils.replacePlaceholders(notificationTypeEntity.getTitle(), placeholders);
|
||||||
|
notificationReq.setTitle(title);
|
||||||
|
notificationReq.setUserWithCompanyEntity(userWithCompanyEntity);
|
||||||
|
return notificationReq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> sendNotificationToBeneficiary(ApplicationEntity application, NotificationTypeEnum notificationTypeEnum) {
|
||||||
|
|
||||||
|
Map<String, String> placeHolders = new HashMap<>();
|
||||||
|
placeHolders.put("{{call_name}}", application.getCall().getName());
|
||||||
|
placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber()));
|
||||||
|
NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, application.getUserId(), application.getUserWithCompany(),
|
||||||
|
listOf(application.getCompanyId()));
|
||||||
|
sendNotification(notificationReq);
|
||||||
|
return placeHolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendNotificationToInstructor(Map<String, String> placeHolders, ApplicationEvaluationEntity applicationEvaluationEntity, NotificationTypeEnum notificationTypeEnum) {
|
||||||
|
|
||||||
|
Long instructorId = applicationEvaluationEntity.getUserId();
|
||||||
|
ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId());
|
||||||
|
if (instructorId != null) {
|
||||||
|
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(),
|
||||||
|
null);
|
||||||
|
sendNotification(notificationreq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void sendNotificationToSuperUser(ApplicationEntity application, Map<String, String> placeHolders, NotificationTypeEnum notificationTypeEnum) {
|
||||||
|
|
||||||
|
List<UserEntity> user = userRepository.findByRoleEntity_RoleTypeAndHubId(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue(), application.getHubId());
|
||||||
|
UserEntity userEntity1 = user.get(0);
|
||||||
|
if (userEntity1 != null) {
|
||||||
|
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, userEntity1.getId(), application.getUserWithCompany(),
|
||||||
|
null);
|
||||||
|
sendNotification(notificationreq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Long> getAllCompanyIdsForUser(Long userId) {
|
||||||
|
|
||||||
|
return userWithCompanyRepository.findActiveCompanyIdsByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotificationResponse getNotificationById(Long id) {
|
||||||
|
|
||||||
|
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||||
|
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NotificationEntity validateNotificationEntity(Long id) {
|
||||||
|
|
||||||
|
NotificationEntity notificationEntity = notificationRepository.findByIdAndIsDeletedFalse(id);
|
||||||
|
if (notificationEntity == null) {
|
||||||
|
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.NOTIFICATION_NOT_FOUND));
|
||||||
|
}
|
||||||
|
return notificationEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NotificationResponse> getNotificationByUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||||
|
|
||||||
|
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
|
||||||
|
UserWithCompanyEntity userWithCompany = null;
|
||||||
|
List<String> statusStrings = new ArrayList<>();
|
||||||
|
if (companyId != null) {
|
||||||
|
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statuses != null) {
|
||||||
|
statusStrings = statuses.stream().map(NotificationEnum::name) // Convert enum to its name as String
|
||||||
|
.toList();
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
|
||||||
|
|
||||||
|
if (userWithCompany != null) {
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotificationResponse updateNotificationStatus(Long id, NotificationEnum status) {
|
||||||
|
|
||||||
|
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||||
|
if (notificationEntity.getStatus().equals(status.getValue())) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NOTIFICATION_ALREADY_IN_THAT_STATE));
|
||||||
|
}
|
||||||
|
notificationEntity.setStatus(status.getValue());
|
||||||
|
notificationEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
notificationRepository.save(notificationEntity);
|
||||||
|
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNotification(Long id) {
|
||||||
|
|
||||||
|
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||||
|
notificationEntity.setIsDeleted(true);
|
||||||
|
notificationRepository.save(notificationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||||
|
|
||||||
|
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
|
||||||
|
UserWithCompanyEntity userWithCompany = null;
|
||||||
|
List<String> statusStrings;
|
||||||
|
if (companyId != null) {
|
||||||
|
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statuses != null) {
|
||||||
|
statusStrings = statuses.stream().map(NotificationEnum::name)
|
||||||
|
.toList();
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
|
||||||
|
|
||||||
|
if (userWithCompany != null) {
|
||||||
|
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -57,7 +57,7 @@ public class PdfDao {
|
|||||||
try {
|
try {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
ApplicationEntity applicationEntity = applicationDao.validateApplication(applicationId);
|
ApplicationEntity applicationEntity = applicationDao.validateApplication(applicationId);
|
||||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||||
CallEntity call=callService.validateCall(applicationEntity.getCall().getId());
|
CallEntity call=callService.validateCall(applicationEntity.getCall().getId());
|
||||||
|
|
||||||
// Create a byte stream to hold the PDF
|
// Create a byte stream to hold the PDF
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.enums.ProtocolTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
@@ -42,7 +43,7 @@ public class ProtocolDao {
|
|||||||
return (maxProtocolNumber != null) ? maxProtocolNumber + 1 : startNumber;
|
return (maxProtocolNumber != null) ? maxProtocolNumber + 1 : startNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber, Long hubId){
|
public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber, Long hubId,Boolean isForApplication){
|
||||||
ProtocolEntity protocolEntity=new ProtocolEntity();
|
ProtocolEntity protocolEntity=new ProtocolEntity();
|
||||||
protocolEntity.setCall(applicationEntity.getCall().getId());
|
protocolEntity.setCall(applicationEntity.getCall().getId());
|
||||||
LocalDateTime utcDateTime = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
LocalDateTime utcDateTime = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
@@ -51,6 +52,11 @@ public class ProtocolDao {
|
|||||||
protocolEntity.setTime(LocalTime.now());
|
protocolEntity.setTime(LocalTime.now());
|
||||||
protocolEntity.setApplicationId(applicationEntity.getId());
|
protocolEntity.setApplicationId(applicationEntity.getId());
|
||||||
protocolEntity.setHubId(hubId);
|
protocolEntity.setHubId(hubId);
|
||||||
|
if(Boolean.TRUE.equals(isForApplication)){
|
||||||
|
protocolEntity.setType(ProtocolTypeEnum.INPUT.getValue());
|
||||||
|
}else {
|
||||||
|
protocolEntity.setType(ProtocolTypeEnum.OUTPUT.getValue());
|
||||||
|
}
|
||||||
protocolRepository.save(protocolEntity);
|
protocolRepository.save(protocolEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for "create protocol" operation. **/
|
/** This code is responsible for adding a version history log for "create protocol" operation. **/
|
||||||
|
|||||||
@@ -13,25 +13,28 @@ public class S3PathConfig {
|
|||||||
@Autowired
|
@Autowired
|
||||||
S3ConfigRepository s3ConfigRepository;
|
S3ConfigRepository s3ConfigRepository;
|
||||||
|
|
||||||
public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId) {
|
public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPath(type);
|
S3ConfigEntity config = getDocumentPath(type);
|
||||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId);
|
||||||
}
|
}
|
||||||
public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId) {
|
public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId);
|
||||||
}
|
|
||||||
private String buildS3Path(String pathTemplate, Long callId, Long applicationId) {
|
|
||||||
|
|
||||||
return pathTemplate.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "").replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "");
|
|
||||||
}
|
}
|
||||||
public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) {
|
public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||||
return config.getParentFolder() + "/" + config.getPath();
|
return config.getParentFolder() + "/" + config.getPath();
|
||||||
}
|
}
|
||||||
|
private String buildS3Path(String pathTemplate, Long callId, Long applicationId, Long amendmentId) {
|
||||||
|
return pathTemplate
|
||||||
|
.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "")
|
||||||
|
.replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "")
|
||||||
|
.replace("{amendment_id}", amendmentId != null && amendmentId != 0L ? "amendment_" + amendmentId : "");
|
||||||
|
}
|
||||||
|
|
||||||
private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) {
|
private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) {
|
||||||
|
|
||||||
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class UserDao {
|
|||||||
log.info("Current user details: {}", userEntity);
|
log.info("Current user details: {}", userEntity);
|
||||||
log.info("New user details: {}", userReq);
|
log.info("New user details: {}", userReq);
|
||||||
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
||||||
if (Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
|
if (newStatus!=null && Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
|
||||||
userEntity.setStatus(newStatus);
|
userEntity.setStatus(newStatus);
|
||||||
}
|
}
|
||||||
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
|
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
|
||||||
@@ -280,15 +280,19 @@ public class UserDao {
|
|||||||
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
|
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
|
||||||
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
|
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
|
||||||
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
|
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
|
||||||
|
if (userReq.getRoleId() != null) {
|
||||||
|
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
|
||||||
|
if((userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue())) || (userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()))) {
|
||||||
|
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(userEntity.getBeneficiary()!=null) {
|
||||||
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
|
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
|
||||||
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
|
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
|
||||||
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
|
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
|
||||||
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
|
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
|
||||||
if (userReq.getRoleId() != null) {
|
|
||||||
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
|
|
||||||
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
|
||||||
}
|
|
||||||
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
|
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
|
||||||
|
}
|
||||||
userEntity = userRepository.save(userEntity);
|
userEntity = userRepository.save(userEntity);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update user details" operation **/
|
/** This code is responsible for adding a version history log for the "Update user details" operation **/
|
||||||
@@ -569,12 +573,14 @@ public class UserDao {
|
|||||||
return authService.validateNewUserToken(token);
|
return authService.validateNewUserToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserResponseBean> getAllUsers(UserEntity user, Long roleId) {
|
public List<UserResponseBean> getAllUsers(UserEntity user, List<Long> roleIds) {
|
||||||
List<UserEntity> users;
|
List<UserEntity> users;
|
||||||
if (roleId != null) {
|
if (roleIds != null) {
|
||||||
log.info("Fetching users by role ID: {}", roleId);
|
log.info("Fetching users by role ID: {}", roleIds);
|
||||||
RoleEntity roleEntity=roleService.validateRole(roleId);
|
List<RoleEntity> roleEntities = roleIds.stream()
|
||||||
users = userRepository.findByRoleEntityIdAndHubId(roleEntity.getId(), user.getHub().getId());
|
.map(roleService::validateRole) // Assuming `validateRole` takes an ID and returns a RoleEntity
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
users = userRepository.findByRoleEntityIdInAndHubId(roleIds, user.getHub().getId());
|
||||||
} else {
|
} else {
|
||||||
log.info("Fetching all users");
|
log.info("Fetching all users");
|
||||||
users = userRepository.findByHubId(user.getHub().getId());
|
users = userRepository.findByHubId(user.getHub().getId());
|
||||||
@@ -583,7 +589,7 @@ public class UserDao {
|
|||||||
.map(this::convertUserEntityToUserResponse)
|
.map(this::convertUserEntityToUserResponse)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
log.info("Total users found with role ID {}: {}", roleId, userResponseBeans.size());
|
log.info("Total users found with role ID {}: {}", roleIds, userResponseBeans.size());
|
||||||
return userResponseBeans;
|
return userResponseBeans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,11 @@ import feign.FeignException;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
|
||||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -49,10 +45,13 @@ public class VatCheckDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
public Map<String, Object> checkVatNumberApi(String vatNumber) {
|
public VatCheckResponseBean checkVatNumberApi(String vatNumber) {
|
||||||
|
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
|
||||||
|
vatCheckResponseBean.setValid(false);
|
||||||
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
|
if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
|
||||||
return new HashMap<>();
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
|
return vatCheckResponseBean;
|
||||||
}
|
}
|
||||||
Map<String, Object> responseBody = new HashMap<>();
|
Map<String, Object> responseBody = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
@@ -65,9 +64,6 @@ public class VatCheckDao {
|
|||||||
URI baseUrl = URI.create(GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL);
|
URI baseUrl = URI.create(GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL);
|
||||||
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl, vatNumber, headers);
|
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl, vatNumber, headers);
|
||||||
|
|
||||||
/** This code is responsible for creating user action logs for the "Download company delegation" operation. **/
|
|
||||||
loggingUtil.logUserAction(
|
|
||||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build());
|
|
||||||
|
|
||||||
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
||||||
log.info("Successfully checked vat number");
|
log.info("Successfully checked vat number");
|
||||||
@@ -80,22 +76,28 @@ public class VatCheckDao {
|
|||||||
responseBody.remove("id");
|
responseBody.remove("id");
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
data.put("data", responseBody);
|
data.put("data", responseBody);
|
||||||
return data;
|
vatCheckResponseBean.setValid(true);
|
||||||
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
|
||||||
|
vatCheckResponseBean.setVatCheckResponse(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FeignException ex) {
|
} catch (FeignException ex) {
|
||||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||||
Utils.callException(ex.status(), ex);
|
Utils.callException(ex.status(), ex);
|
||||||
}
|
}
|
||||||
return responseBody;
|
return vatCheckResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> checkVatNumber(String vatNumber) {
|
public VatCheckResponseBean checkVatNumber(String vatNumber) {
|
||||||
try {
|
try {
|
||||||
return checkVatNumberApi(vatNumber);
|
return checkVatNumberApi(vatNumber);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
log.error("Error in checkVatNumber: {}", e.getMessage());
|
||||||
Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
|
||||||
|
vatCheckResponseBean.setValid(false);
|
||||||
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
|
return vatCheckResponseBean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,10 @@ public class ApplicationAmendmentRequestEntity extends BaseEntity {
|
|||||||
@JoinColumn(name = "PROTOCOL_Id")
|
@JoinColumn(name = "PROTOCOL_Id")
|
||||||
private ProtocolEntity protocol;
|
private ProtocolEntity protocol;
|
||||||
|
|
||||||
|
@Column(name = "end_date")
|
||||||
|
private LocalDateTime endDate;
|
||||||
|
|
||||||
|
@Column(name = "amendment_document")
|
||||||
|
private String amendmentDocument;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ public class ApplicationEntity extends BaseEntity {
|
|||||||
@Column(name = "USER_ID")
|
@Column(name = "USER_ID")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@ManyToOne
|
@Column(name = "COMPANY_ID")
|
||||||
@JoinColumn(name = "COMPANY_ID", nullable = false)
|
private Long companyId;
|
||||||
private CompanyEntity company;
|
|
||||||
|
|
||||||
@Column(name = "SUBMISSION_DATE")
|
@Column(name = "SUBMISSION_DATE")
|
||||||
private LocalDateTime submissionDate;
|
private LocalDateTime submissionDate;
|
||||||
@@ -39,4 +38,21 @@ public class ApplicationEntity extends BaseEntity {
|
|||||||
|
|
||||||
@Column(name = "HUB_ID")
|
@Column(name = "HUB_ID")
|
||||||
private Long hubId;
|
private Long hubId;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_WITH_COMPANY_ID")
|
||||||
|
private UserWithCompanyEntity userWithCompany;
|
||||||
|
|
||||||
|
@Column(name = "NDG")
|
||||||
|
private String ndg;
|
||||||
|
|
||||||
|
@Column(name = "ID_VISURA")
|
||||||
|
private String idVisura;
|
||||||
|
|
||||||
|
@Column(name = "NDG_STATUS")
|
||||||
|
private String ndgStatus;
|
||||||
|
|
||||||
|
@Column(name = "APPOINTMENT_ID")
|
||||||
|
private String appointmentId;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@ package net.gepafin.tendermanagement.entities;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "application_evaluation")
|
@Table(name = "application_evaluation")
|
||||||
@@ -20,6 +22,9 @@ public class ApplicationEvaluationEntity extends BaseEntity{
|
|||||||
@Column(name = "checklist")
|
@Column(name = "checklist")
|
||||||
private String checklist;
|
private String checklist;
|
||||||
|
|
||||||
|
@Column(name = "EVALUATION_DOCUMENT")
|
||||||
|
private String evaluationDocument;
|
||||||
|
|
||||||
@Column(name = "file")
|
@Column(name = "file")
|
||||||
private String file;
|
private String file;
|
||||||
|
|
||||||
@@ -39,4 +44,25 @@ public class ApplicationEvaluationEntity extends BaseEntity{
|
|||||||
@JoinColumn(name = "assigned_applications_id", nullable = true)
|
@JoinColumn(name = "assigned_applications_id", nullable = true)
|
||||||
private AssignedApplicationsEntity assignedApplicationsEntity;
|
private AssignedApplicationsEntity assignedApplicationsEntity;
|
||||||
|
|
||||||
|
@Column(name = "INITIAL_DAYS")
|
||||||
|
private Long initialDays;
|
||||||
|
|
||||||
|
@Column(name = "REMAINING_DAYS")
|
||||||
|
private Long remainingDays;
|
||||||
|
|
||||||
|
@Column(name = "SUSPENDED_DAYS")
|
||||||
|
private Long suspendedDays;
|
||||||
|
|
||||||
|
@Column(name = "START_DATE")
|
||||||
|
private LocalDateTime startDate;
|
||||||
|
|
||||||
|
@Column(name = "END_DATE")
|
||||||
|
private LocalDateTime endDate;
|
||||||
|
|
||||||
|
@Column(name = "STOP_DATE_TIME")
|
||||||
|
private LocalDateTime stopDateTime;
|
||||||
|
|
||||||
|
@Column(name = "CLOSING_DATE")
|
||||||
|
private LocalDateTime closingDate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ public class BeneficiaryPreferredCallEntity extends BaseEntity{
|
|||||||
|
|
||||||
@Column(name = "STATUS", length = 255)
|
@Column(name = "STATUS", length = 255)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
@Column(name="IS_DELETED")
|
@Column(name="IS_DELETED")
|
||||||
private Boolean isDeleted;
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_WITH_COMPANY_ID")
|
||||||
|
private UserWithCompanyEntity userWithCompany;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,26 +41,19 @@ public class CompanyEntity extends BaseEntity{
|
|||||||
@Column(name = "COUNTRY")
|
@Column(name = "COUNTRY")
|
||||||
private String country;
|
private String country;
|
||||||
|
|
||||||
@Column(name = "PEC")
|
|
||||||
private String pec;
|
|
||||||
|
|
||||||
@Column(name = "EMAIL")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@Column(name = "NUMBER_OF_EMPLOYEES")
|
@Column(name = "NUMBER_OF_EMPLOYEES")
|
||||||
private String numberOfEmployees;
|
private String numberOfEmployees;
|
||||||
|
|
||||||
@Column(name = "ANNUAL_REVENUE")
|
@Column(name = "ANNUAL_REVENUE")
|
||||||
private BigDecimal annualRevenue;
|
private BigDecimal annualRevenue;
|
||||||
|
|
||||||
@Column(name = "CONTACT_NAME")
|
|
||||||
private String contactName;
|
|
||||||
|
|
||||||
@Column(name = "CONTACT_EMAIL")
|
|
||||||
private String contactEmail;
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "HUB_ID")
|
@JoinColumn(name = "HUB_ID")
|
||||||
private HubEntity hub;
|
private HubEntity hub;
|
||||||
|
|
||||||
|
// @Column(name = "JSON")
|
||||||
|
// private String json;
|
||||||
|
|
||||||
|
@Column(name = "NDG")
|
||||||
|
private String ndg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,10 @@ public class DocumentEntity extends BaseEntity{
|
|||||||
@Column(name ="IS_DELETED", nullable = false)
|
@Column(name ="IS_DELETED", nullable = false)
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
@Column(name="DOCUMENT_ATTACHMENT_ID")
|
||||||
|
private String documentAttachmentId;
|
||||||
|
|
||||||
|
@Column(name="uploaded_by")
|
||||||
|
private Long uploadedBy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,5 +45,9 @@ public class FaqEntity extends BaseEntity {
|
|||||||
@Column(name ="COMPANY_ID")
|
@Column(name ="COMPANY_ID")
|
||||||
private Long companyId;
|
private Long companyId;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_WITH_COMPANY_ID")
|
||||||
|
private UserWithCompanyEntity userWithCompany;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,4 +54,13 @@ public class HubEntity extends BaseEntity{
|
|||||||
|
|
||||||
@Column(name = "EMAIL_SERVICE_CONFIG")
|
@Column(name = "EMAIL_SERVICE_CONFIG")
|
||||||
private String emailServiceConfig;
|
private String emailServiceConfig;
|
||||||
|
|
||||||
|
@Column(name = "AUTH_TOKEN")
|
||||||
|
private String authToken;
|
||||||
|
|
||||||
|
@Column(name = "APPOINTMENT_AUTH_TOKEN_ID")
|
||||||
|
private String appointmentAuthTokenId;
|
||||||
|
|
||||||
|
@Column(name = "AREA_CODE")
|
||||||
|
private String areaCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "NOTIFICATION")
|
||||||
|
@Data
|
||||||
|
public class NotificationEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "USER_ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Column(name = "MESSAGE")
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@Column(name = "TITLE")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name = "STATUS")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@Column(name = "IS_DELETED")
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
@Column(name = "NOTIFICATION_TYPE")
|
||||||
|
private String notificationType;
|
||||||
|
|
||||||
|
@Column(name = "REDIRECT_LINK")
|
||||||
|
private String redirectLink;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_WITH_COMPANY_ID")
|
||||||
|
private UserWithCompanyEntity userWithCompany;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@Table(name = "NOTIFICATION_TYPE")
|
||||||
|
public class NotificationTypeEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "NOTIFICATION_NAME")
|
||||||
|
private String notificationName;
|
||||||
|
|
||||||
|
@Column(name = "JSON_TEMPLATE")
|
||||||
|
private String jsonTemplate;
|
||||||
|
|
||||||
|
@Column(name = "TITLE")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name="IS_DELETED")
|
||||||
|
private Boolean isDeleted;
|
||||||
|
}
|
||||||
@@ -28,4 +28,7 @@ public class ProtocolEntity extends BaseEntity {
|
|||||||
@Column(name="HUB_ID")
|
@Column(name="HUB_ID")
|
||||||
private Long hubId;
|
private Long hubId;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
private String type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package net.gepafin.tendermanagement.entities;
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -28,4 +26,7 @@ public class UserCompanyDelegationEntity extends BaseEntity{
|
|||||||
@Column(name="STATUS")
|
@Column(name="STATUS")
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "USER_WITH_COMPANY_ID")
|
||||||
|
private UserWithCompanyEntity userWithCompany;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ public class UserWithCompanyEntity extends BaseEntity{
|
|||||||
@Column(name = "IS_LEGAL_REPRESENTANT")
|
@Column(name = "IS_LEGAL_REPRESENTANT")
|
||||||
private Boolean isLegalRepresentant;
|
private Boolean isLegalRepresentant;
|
||||||
|
|
||||||
|
|
||||||
|
@Column(name = "CONTACT_NAME")
|
||||||
|
private String contactName;
|
||||||
|
|
||||||
|
@Column(name = "CONTACT_EMAIL")
|
||||||
|
private String contactEmail;
|
||||||
|
|
||||||
|
@Column(name = "PEC")
|
||||||
|
private String pec;
|
||||||
|
|
||||||
|
@Column(name = "EMAIL")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "JSON")
|
||||||
|
private String json;
|
||||||
|
|
||||||
@Column(name = "IS_DELETED")
|
@Column(name = "IS_DELETED")
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
public enum ApplicationEvaluationStatusTypeEnum {
|
public enum ApplicationEvaluationStatusTypeEnum {
|
||||||
OPEN ("OPEN"),
|
OPEN ("OPEN"),
|
||||||
SOCCORSO("SOCCORSO"),
|
SOCCORSO("SOCCORSO"),
|
||||||
|
EXPIRED("EXPIRED"),
|
||||||
CLOSE("CLOSE");
|
CLOSE("CLOSE");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ public enum ApplicationStatusTypeEnum {
|
|||||||
SOCCORSO("SOCCORSO"),
|
SOCCORSO("SOCCORSO"),
|
||||||
APPROVED("APPROVED"),
|
APPROVED("APPROVED"),
|
||||||
REJECTED("REJECTED"),
|
REJECTED("REJECTED"),
|
||||||
EVALUATION("EVALUATION");
|
EVALUATION("EVALUATION"),
|
||||||
|
APPOINTMENT("APPOINTMENT"),
|
||||||
|
NDG("NDG"),
|
||||||
|
ADMISSIBLE("ADMISSIBLE");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ package net.gepafin.tendermanagement.enums;
|
|||||||
public enum DocOtherSourceTypeEnum {
|
public enum DocOtherSourceTypeEnum {
|
||||||
USER_SIGNED_DOCUMENT("USER_SIGNED_DOCUMENT"),
|
USER_SIGNED_DOCUMENT("USER_SIGNED_DOCUMENT"),
|
||||||
USER_DELEGATION("USER_DELEGATION"),
|
USER_DELEGATION("USER_DELEGATION"),
|
||||||
TEMPLATE("TEMPLATE");
|
TEMPLATE("TEMPLATE"),
|
||||||
|
DELETED_USER_DELEGATION("DELETED_USER_DELEGATION"),
|
||||||
|
DELETED_APPLICATION("DELETED_APPLICATION"),
|
||||||
|
DELETED_EVALUATION("DELETED_EVALUATION"),
|
||||||
|
DELETED_CALL("DELETED_CALL"),
|
||||||
|
DELETED_AMENDMENT("DELETED_AMENDMENT");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package net.gepafin.tendermanagement.enums;
|
|||||||
public enum DocumentSourceTypeEnum {
|
public enum DocumentSourceTypeEnum {
|
||||||
CALL("CALL"),
|
CALL("CALL"),
|
||||||
|
|
||||||
APPLICATION("APPLICATION");
|
APPLICATION("APPLICATION"),
|
||||||
|
EVALUATION("EVALUATION"),
|
||||||
|
AMENDMENT("AMENDMENT");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum NotificationEnum {
|
||||||
|
//status
|
||||||
|
READ("READ"), UNREAD("UNREAD");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
NotificationEnum(String value) {
|
||||||
|
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum NotificationTypeEnum {
|
||||||
|
CALL_CREATED("CALL_CREATED"),
|
||||||
|
APPLICATION_SUBMISSION("APPLICATION_SUBMISSION"),
|
||||||
|
AMENDMENT_CREATION("AMENDMENT_CREATION"),
|
||||||
|
EVALUATION_RESULT("EVALUATION_RESULT"),
|
||||||
|
AMENDMENT_EXPIRED("AMENDMENT_EXPIRED"),
|
||||||
|
AMENDMENT_CLOSED("AMENDMENT_CLOSED"),
|
||||||
|
NDG_GENERATION("NDG_GENERATION"),
|
||||||
|
EVALUATION_CREATION("EVALUATION_CREATION"),
|
||||||
|
EVALUATION_EXPIRED("EVALUATION_EXPIRED");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
NotificationTypeEnum(String value) {
|
||||||
|
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum ProtocolTypeEnum {
|
||||||
|
INPUT("INPUT"),
|
||||||
|
OUTPUT("OUTPUT");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
ProtocolTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,8 @@ public enum RecipientTypeEnum {
|
|||||||
BENEFICIARY ("BENEFICIARY"),
|
BENEFICIARY ("BENEFICIARY"),
|
||||||
USER("USER"),
|
USER("USER"),
|
||||||
COMPANY("COMPANY"),
|
COMPANY("COMPANY"),
|
||||||
PROPERTIES("PROPERTIES");
|
PROPERTIES("PROPERTIES"),
|
||||||
|
INSTRUCTOR("INSTRUCTOR");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ public enum RoleStatusEnum {
|
|||||||
ROLE_BENEFICIARY("ROLE_BENEFICIARY"),
|
ROLE_BENEFICIARY("ROLE_BENEFICIARY"),
|
||||||
ROLE_SUPER_ADMIN("ROLE_SUPER_ADMIN"),
|
ROLE_SUPER_ADMIN("ROLE_SUPER_ADMIN"),
|
||||||
ROLE_PRE_INSTRUCTOR("ROLE_PRE_INSTRUCTOR"),
|
ROLE_PRE_INSTRUCTOR("ROLE_PRE_INSTRUCTOR"),
|
||||||
ROLE_GEPAFIN_OPERATOR("ROLE_GEPAFIN_OPERATOR");
|
ROLE_GEPAFIN_OPERATOR("ROLE_GEPAFIN_OPERATOR"),
|
||||||
|
ROLE_INSTRUCTOR_MANAGER("ROLE_INSTRUCTOR_MANAGER");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ public enum UserActionContextEnum {
|
|||||||
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
|
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
|
||||||
UPDATE_IMAGES("UPDATE_IMAGES"),
|
UPDATE_IMAGES("UPDATE_IMAGES"),
|
||||||
GET_DOCUMENT("GET_DOCUMENT"),
|
GET_DOCUMENT("GET_DOCUMENT"),
|
||||||
|
UPLOAD_AMENDMENT_DOCUMENT("UPLOAD_AMENDMENT_DOCUMENT"),
|
||||||
|
UPLOAD_AMENDMENT_IMAGES("UPLOAD_AMENDMENT_IMAGES"),
|
||||||
|
UPLOAD_EVALUATION_DOCUMENT("UPLOAD_EVALUATION_DOCUMENT"),
|
||||||
|
UPLOAD_EVALUATION_IMAGES("UPLOAD_EVALUATION_IMAGES"),
|
||||||
|
|
||||||
/** Assigned flow context **/
|
/** Assigned flow context **/
|
||||||
CREATE_UPDATE_FLOW("CREATE_UPDATE_FLOW"),
|
CREATE_UPDATE_FLOW("CREATE_UPDATE_FLOW"),
|
||||||
@@ -138,6 +142,7 @@ public enum UserActionContextEnum {
|
|||||||
UPDATE_EVALUATION_CRITERIA("UPDATE_EVALUATION_CRITERIA"),
|
UPDATE_EVALUATION_CRITERIA("UPDATE_EVALUATION_CRITERIA"),
|
||||||
DELETE_EVALUATION_CRITERIA("DELETE_EVALUATION_CRITERIA"),
|
DELETE_EVALUATION_CRITERIA("DELETE_EVALUATION_CRITERIA"),
|
||||||
CREATE_EVALUATION_CRITERIA("CREATE_EVALUATION_CRITERIA"),
|
CREATE_EVALUATION_CRITERIA("CREATE_EVALUATION_CRITERIA"),
|
||||||
|
UPLOAD_EVALUATION_DOC("UPLOAD_EVALUATION_DOC"),
|
||||||
|
|
||||||
/** communication action context **/
|
/** communication action context **/
|
||||||
ADD_COMMENT_TO_AMENDMENT_REQUEST("ADD_COMMENT_TO_AMENDMENT_REQUEST"),
|
ADD_COMMENT_TO_AMENDMENT_REQUEST("ADD_COMMENT_TO_AMENDMENT_REQUEST"),
|
||||||
@@ -149,7 +154,16 @@ public enum UserActionContextEnum {
|
|||||||
GET_FORM("GET_FORM"),
|
GET_FORM("GET_FORM"),
|
||||||
CREATE_FORM("CREATE_FORM"),
|
CREATE_FORM("CREATE_FORM"),
|
||||||
UPDATE_FORM("UPDATE_FORM"),
|
UPDATE_FORM("UPDATE_FORM"),
|
||||||
DELETE_FORM("DELETE_FORM");
|
DELETE_FORM("DELETE_FORM"),
|
||||||
|
|
||||||
|
/** scheduler action context **/
|
||||||
|
AMENDMENT_EXPIRATION_SCHEDULER("AMENDMENT_EXPIRATION_SCHEDULER"),
|
||||||
|
EVALUATION_EXPIRATION_SCHEDULER("EVALUATION_EXPIRATION_SCHEDULER"),
|
||||||
|
|
||||||
|
/** appointment action context **/
|
||||||
|
CHECK_OR_CREATE_NDG_CODE("CHECK_OR_CREATE_NDG_CODE"),
|
||||||
|
CREATE_APPOINTMENT("CREATE_APPOINTMENT"),
|
||||||
|
UPLOAD_DOCUMENT_TO_EXTERNAL_SYSTEM("UPLOAD_DOCUMENT_TO_EXTERNAL_SYSTEM");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ public enum UserActionLogsEnum {
|
|||||||
VIEW("VIEW"),
|
VIEW("VIEW"),
|
||||||
INSERT("INSERT"),
|
INSERT("INSERT"),
|
||||||
DOWNLOAD("DOWNLOAD"),
|
DOWNLOAD("DOWNLOAD"),
|
||||||
UPLOAD("UPLOAD");
|
UPLOAD("UPLOAD"),
|
||||||
|
SCHEDULER("SCHEDULER"),
|
||||||
|
SCRIPT("SCRIPT");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AmendmentDetailsRequest {
|
||||||
|
|
||||||
|
private String fieldId;
|
||||||
|
|
||||||
|
private Long amendmentId;
|
||||||
|
|
||||||
|
private Boolean valid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AmendmentFieldRequest {
|
||||||
|
|
||||||
|
private String fieldId;
|
||||||
|
private String nameValue;
|
||||||
|
private String fileValue;
|
||||||
|
private Boolean valid = false;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,9 +9,13 @@ public class AmendmentFormField {
|
|||||||
|
|
||||||
private String fieldId;
|
private String fieldId;
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
|
||||||
private String fieldValue;
|
private String fieldValue;
|
||||||
|
|
||||||
private String isUploadedBy;
|
private Boolean valid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public enum AmendmentIsUploadedByEnum {
|
public enum AmendmentIsUploadedByEnum {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AmendmentFormFieldRequest {
|
||||||
|
|
||||||
|
private String fieldId;
|
||||||
|
|
||||||
|
private Object fieldValue;
|
||||||
|
|
||||||
|
private Boolean valid;
|
||||||
|
}
|
||||||
@@ -7,5 +7,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class ApplicationAmendmentRequestBean {
|
public class ApplicationAmendmentRequestBean {
|
||||||
private String note;
|
private String note;
|
||||||
private List<ApplicationFormFieldRequestBean> applicationFormFields;
|
private List<AmendmentFormFieldRequest> applicationFormFields;
|
||||||
|
private String amendmentDocuments;
|
||||||
|
private String amendmentNotes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public class ApplicationEvaluationRequest {
|
|||||||
private List<CriteriaRequest> criteria;
|
private List<CriteriaRequest> criteria;
|
||||||
private List<ChecklistRequest> checklist;
|
private List<ChecklistRequest> checklist;
|
||||||
private List<FieldRequest> files;
|
private List<FieldRequest> files;
|
||||||
|
private List<EvaluationDocumentRequest> evaluationDocument;
|
||||||
|
private List<AmendmentDetailsRequest> amendmentDetails;
|
||||||
private String note;
|
private String note;
|
||||||
private ApplicationStatusForEvaluation applicationStatus;
|
private ApplicationStatusForEvaluation applicationStatus;
|
||||||
private String motivation;
|
private String motivation;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentCreationRequest {
|
||||||
|
|
||||||
|
private Input input;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Input {
|
||||||
|
private String id;
|
||||||
|
private String ndg;
|
||||||
|
private List<RichiestaCliente> richiestaCliente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class RichiestaCliente {
|
||||||
|
private String codAbi;
|
||||||
|
private String codCab;
|
||||||
|
private Integer durataMesiFinanziamento;
|
||||||
|
private Integer idMotivazione;
|
||||||
|
private String idNota;
|
||||||
|
private String importoAgevolato;
|
||||||
|
private Double importoBreveTermine;
|
||||||
|
private String importoMedioLungoTermine;
|
||||||
|
private String codTipoProdotto;
|
||||||
|
private String codCategoriaProdotto;
|
||||||
|
private String codFormaTecnica;
|
||||||
|
private String codProdotto;
|
||||||
|
private String codOperazione;
|
||||||
|
private Nota nota;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Nota {
|
||||||
|
private String titolo;
|
||||||
|
private String testo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentNdgRequest {
|
||||||
|
private Filter filter;
|
||||||
|
private Pagination pagination;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Filter {
|
||||||
|
private String partitaIva;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Pagination {
|
||||||
|
private int targetPage;
|
||||||
|
private int recordsPerPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentVisuraListRequest {
|
||||||
|
|
||||||
|
private AppointmentVisuraListRequest.VisuraFilter filter;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class VisuraFilter {
|
||||||
|
private String idVisura;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentVisuraRequest {
|
||||||
|
private VisuraInput input;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class VisuraInput {
|
||||||
|
private String codiceFiscale;
|
||||||
|
private String partitaIva;
|
||||||
|
private boolean creaAnagrafica;
|
||||||
|
private boolean salvaDocumenti;
|
||||||
|
private String visuraProvider;
|
||||||
|
private String visuraType;
|
||||||
|
private String visuraMode;
|
||||||
|
private String codArea;
|
||||||
|
private String codAgente;
|
||||||
|
@JsonProperty("isFromRating")
|
||||||
|
private boolean isFromRating;
|
||||||
|
@JsonProperty("isAnagraficaLegame")
|
||||||
|
private boolean isAnagraficaLegame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.model.request;
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -23,4 +24,5 @@ public class CompanyRequest {
|
|||||||
private Boolean isLegalRepresentant;
|
private Boolean isLegalRepresentant;
|
||||||
private String contactName;
|
private String contactName;
|
||||||
private String contactEmail;
|
private String contactEmail;
|
||||||
|
private Map<String, Object> vatCheckResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateAppointmentRequest {
|
||||||
|
private Double importoBreveTermine;
|
||||||
|
private Integer durataMesiFinanziamento;
|
||||||
|
private Nota nota;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Nota {
|
||||||
|
private String titolo;
|
||||||
|
|
||||||
|
private String testo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EvaluationDocumentRequest {
|
||||||
|
|
||||||
|
private String fieldId;
|
||||||
|
|
||||||
|
private String nameValue;
|
||||||
|
|
||||||
|
private String fileValue;
|
||||||
|
|
||||||
|
private Boolean valid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NotificationReq {
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
Long id;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
Long userId;
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
String notificationType;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
String status;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private String redirectUrl;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
private List<Long> companyIds;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private UserWithCompanyEntity userWithCompanyEntity;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||||
|
@Data
|
||||||
|
public class UpdateAssignedApplicationRequest {
|
||||||
|
private String note;
|
||||||
|
private AssignedApplicationEnum status;
|
||||||
|
private Long userId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UploadDocToExternalSystemRequest {
|
||||||
|
private Input input;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Input {
|
||||||
|
private Long idTipoProtocollo;
|
||||||
|
private Long idClassificazione;
|
||||||
|
private Boolean flagDaFirmare;
|
||||||
|
private String descrizione;
|
||||||
|
private Attributes attributes;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Attributes {
|
||||||
|
private String ndg;
|
||||||
|
private String email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
@Data
|
||||||
|
public class AmendmentDetailsResponseBean {
|
||||||
|
private String amendmentDocuments;
|
||||||
|
private String amendmentNotes;
|
||||||
|
private Boolean valid;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AmendmentDocumentResponseBean {
|
||||||
|
|
||||||
|
private Long amendmentId;
|
||||||
|
private String fieldId;
|
||||||
|
private String label;
|
||||||
|
private Boolean valid;
|
||||||
|
private List<DocumentResponseBean> fileDetail ;
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.gepafin.tendermanagement.model.response;
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -19,12 +18,18 @@ public class ApplicationAmendmentRequestResponse {
|
|||||||
private Long protocolNumber;
|
private Long protocolNumber;
|
||||||
private String callName;
|
private String callName;
|
||||||
private String beneficiaryName;
|
private String beneficiaryName;
|
||||||
|
private String companyName;
|
||||||
private List<AmendmentFormFieldResponse> formFields;
|
private List<AmendmentFormFieldResponse> formFields;
|
||||||
private List<ApplicationFormFieldResponseBean> applicationFormFields;
|
private List<ApplicationFormFieldResponseBean> applicationFormFields;
|
||||||
|
private List<DocumentResponseBean> amendmentDocuments;
|
||||||
|
private String amendmentNotes;
|
||||||
|
private Boolean valid;
|
||||||
private Long applicationId;
|
private Long applicationId;
|
||||||
private Long applicationEvaluationId;
|
private Long applicationEvaluationId;
|
||||||
|
private LocalDateTime evaluationEndDate;
|
||||||
private LocalDateTime expirationDate;
|
private LocalDateTime expirationDate;
|
||||||
private List<CommunicationResponseBean> commentsList;
|
private List<CommunicationResponseBean> commentsList;
|
||||||
private String internalNote;
|
private String internalNote;
|
||||||
private ApplicationAmendmentRequestEnum status;
|
private ApplicationAmendmentRequestEnum status;
|
||||||
|
private String emailTemplate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,21 @@ public class ApplicationEvaluationResponse {
|
|||||||
private List<CriteriaResponse> criteria;
|
private List<CriteriaResponse> criteria;
|
||||||
private List<ChecklistResponse> checklist;
|
private List<ChecklistResponse> checklist;
|
||||||
private List<FieldResponse> files;
|
private List<FieldResponse> files;
|
||||||
|
private List<EvaluationDocumentResponse> evaluationDocument;
|
||||||
|
private List<AmendmentDocumentResponseBean> amendmentDetails;
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
private String beneficiary;
|
private String beneficiary;
|
||||||
|
private Long assignedUserId;
|
||||||
|
private String assignedUserName;
|
||||||
private Long protocolNumber;
|
private Long protocolNumber;
|
||||||
private String callName;
|
private String callName;
|
||||||
private String motivation;
|
private String motivation;
|
||||||
private LocalDateTime submissionDate;
|
private LocalDateTime submissionDate;
|
||||||
private LocalDateTime evaluationDate;
|
private LocalDateTime evaluationEndDate;
|
||||||
private LocalDateTime callEndDate;
|
private LocalDateTime callEndDate;
|
||||||
|
private String companyName;
|
||||||
|
private LocalDateTime assignedAt;
|
||||||
|
private String ndg;
|
||||||
|
private String appointmentId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,8 @@ public class ApplicationResponse{
|
|||||||
|
|
||||||
private Long protocolNumber;
|
private Long protocolNumber;
|
||||||
|
|
||||||
|
private Long assignedUserId;
|
||||||
|
|
||||||
|
private String assignedUserName;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentCreationResponse {
|
||||||
|
private String appointmentId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AppointmentLoginResponse {
|
||||||
|
|
||||||
|
private String tokenId;
|
||||||
|
private String areaCode;
|
||||||
|
private Long companyId;
|
||||||
|
private String codecFiscale;
|
||||||
|
private String vatNumber;
|
||||||
|
private String ndg;
|
||||||
|
private String message;
|
||||||
|
private String idVisura;
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ public class AssignedApplicationsResponse extends BaseBean {
|
|||||||
private LocalDateTime callStartDate;
|
private LocalDateTime callStartDate;
|
||||||
private LocalDateTime callEndDate;
|
private LocalDateTime callEndDate;
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
private LocalDateTime evaluationEndDate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class BeneficiaryPreferredCallResponseBean {
|
|||||||
private BeneficiaryCallStatus status;
|
private BeneficiaryCallStatus status;
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
private Long userWithCompanyId;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,6 @@ public class DocumentResponseBean {
|
|||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
private String documentAttachmentId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DocumentUploadResponse {
|
||||||
|
private String documentAttachmentId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EmailContentResponse {
|
||||||
|
private final String subject;
|
||||||
|
private final String body;
|
||||||
|
private final SystemEmailTemplateResponse systemEmailTemplateResponse;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EvaluationDocumentResponse {
|
||||||
|
private String fieldId;
|
||||||
|
private String nameValue;
|
||||||
|
private Boolean valid;
|
||||||
|
private List<DocumentResponseBean> fileValue ;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NdgResponse {
|
||||||
|
private String ndg;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NotificationResponse extends BaseBean {
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String redirectUrl;
|
||||||
|
|
||||||
|
private String notificationType;
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ public class UserResponseBean extends BaseBean {
|
|||||||
|
|
||||||
private List<CompanyResponse> companies;
|
private List<CompanyResponse> companies;
|
||||||
private Boolean privacy;
|
private Boolean privacy;
|
||||||
|
|
||||||
private Boolean terms;
|
private Boolean terms;
|
||||||
|
|
||||||
private Boolean marketing;
|
private Boolean marketing;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class VatCheckResponseBean {
|
||||||
|
private Boolean valid;
|
||||||
|
private Map<String, Object> vatCheckResponse;
|
||||||
|
private String message;
|
||||||
|
}
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface ApplicationAmendmentRequestRepository extends JpaRepository<ApplicationAmendmentRequestEntity,Long>, JpaSpecificationExecutor<ApplicationAmendmentRequestEntity> {
|
public interface ApplicationAmendmentRequestRepository extends JpaRepository<ApplicationAmendmentRequestEntity,Long>, JpaSpecificationExecutor<ApplicationAmendmentRequestEntity> {
|
||||||
Optional<ApplicationAmendmentRequestEntity> findByIdAndIsDeletedFalse(Long id);
|
Optional<ApplicationAmendmentRequestEntity> findByIdAndIsDeletedFalse(Long id);
|
||||||
@@ -25,6 +30,7 @@ public interface ApplicationAmendmentRequestRepository extends JpaRepository<App
|
|||||||
|
|
||||||
@Query(value = "SELECT amr FROM ApplicationAmendmentRequestEntity amr " +
|
@Query(value = "SELECT amr FROM ApplicationAmendmentRequestEntity amr " +
|
||||||
"WHERE amr.applicationEvaluationEntity.id = :id " +
|
"WHERE amr.applicationEvaluationEntity.id = :id " +
|
||||||
|
"AND amr.isDeleted = false " +
|
||||||
"AND amr.applicationEvaluationEntity.isDeleted = false")
|
"AND amr.applicationEvaluationEntity.isDeleted = false")
|
||||||
List<ApplicationAmendmentRequestEntity> findAllByApplicationEvaluationIdAndIsDeletedFalse(Long id);
|
List<ApplicationAmendmentRequestEntity> findAllByApplicationEvaluationIdAndIsDeletedFalse(Long id);
|
||||||
|
|
||||||
@@ -34,4 +40,38 @@ public interface ApplicationAmendmentRequestRepository extends JpaRepository<App
|
|||||||
|
|
||||||
List<ApplicationAmendmentRequestEntity> findByApplicationIdAndStatusInAndIsDeletedFalse(Long applicationId, List<String> statuses);
|
List<ApplicationAmendmentRequestEntity> findByApplicationIdAndStatusInAndIsDeletedFalse(Long applicationId, List<String> statuses);
|
||||||
|
|
||||||
|
@Query("SELECT app " +
|
||||||
|
"FROM ApplicationEntity app " +
|
||||||
|
"WHERE app.id = (SELECT aar.applicationId " +
|
||||||
|
"FROM ApplicationAmendmentRequestEntity aar " +
|
||||||
|
"WHERE aar.id = :amendmentId AND aar.isDeleted = false)")
|
||||||
|
ApplicationEntity findApplicationByAmendmentId(Long amendmentId);
|
||||||
|
|
||||||
|
@Query(value = "SELECT amr " +
|
||||||
|
"FROM ApplicationAmendmentRequestEntity amr " +
|
||||||
|
"WHERE amr.applicationEvaluationEntity.id = :id " +
|
||||||
|
"AND amr.isDeleted = false " +
|
||||||
|
"AND amr.applicationEvaluationEntity.isDeleted = false " +
|
||||||
|
"AND amr.status IN (:statuses)")
|
||||||
|
List<ApplicationAmendmentRequestEntity> findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(Long id, List<String> statuses);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM ApplicationAmendmentRequestEntity a " +
|
||||||
|
"WHERE a.isDeleted = false " +
|
||||||
|
"AND a.status <> 'CLOSE' " +
|
||||||
|
"AND a.endDate < :currentTime")
|
||||||
|
List<ApplicationAmendmentRequestEntity> findAmendmentsDueForExpiration(LocalDateTime currentTime);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT a.applicationEvaluationEntity " +
|
||||||
|
"FROM ApplicationAmendmentRequestEntity a " +
|
||||||
|
"WHERE a.applicationEvaluationEntity.id IN :applicationEvaluationIds " +
|
||||||
|
"AND a.isDeleted = false " +
|
||||||
|
"AND NOT EXISTS ( " +
|
||||||
|
" SELECT 1 FROM ApplicationAmendmentRequestEntity activeAmendment" +
|
||||||
|
" WHERE activeAmendment.applicationEvaluationEntity.id = a.applicationEvaluationEntity.id " +
|
||||||
|
" AND activeAmendment.status <> 'CLOSE' " +
|
||||||
|
" AND activeAmendment.isDeleted = false) ")
|
||||||
|
Set<ApplicationEvaluationEntity> findEvaluationsWithoutActiveAmendmentsByIds(@Param("applicationEvaluationIds") Set<Long> applicationEvaluationIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -20,6 +22,13 @@ public interface ApplicationEvaluationRepository extends JpaRepository<Applicati
|
|||||||
|
|
||||||
Optional<ApplicationEvaluationEntity> findFirstByIsDeletedFalseOrderByCreatedDateDesc();
|
Optional<ApplicationEvaluationEntity> findFirstByIsDeletedFalseOrderByCreatedDateDesc();
|
||||||
boolean existsByApplicationIdAndIsDeletedFalse(Long applicationId);
|
boolean existsByApplicationIdAndIsDeletedFalse(Long applicationId);
|
||||||
|
@Query("SELECT app " +
|
||||||
|
"FROM ApplicationEntity app " +
|
||||||
|
"WHERE app.id = (SELECT aar.applicationId " +
|
||||||
|
"FROM ApplicationEvaluationEntity aar " +
|
||||||
|
"WHERE aar.id = :evaluationId AND aar.isDeleted = false)")
|
||||||
|
ApplicationEntity findApplicationByEvaluationId(Long evaluationId);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM ApplicationEvaluationEntity a WHERE a.isDeleted = false AND a.endDate < :currentDate")
|
||||||
|
List<ApplicationEvaluationEntity> findAllByIsDeletedFalseAndEndDateBefore(@Param("currentDate") LocalDateTime currentDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,17 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
|
|
||||||
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
||||||
|
|
||||||
Optional<ApplicationEntity> findByUserIdAndCompanyIdAndCallIdAndIsDeletedFalse(Long userId, Long companyId, Long callId);
|
Optional<ApplicationEntity> findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(Long userId, Long userWithCompanyId, Long callId);
|
||||||
|
|
||||||
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
||||||
Long callId);
|
Long callId);
|
||||||
|
|
||||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' AND a.isDeleted = false")
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.userWithCompany.id = :userWithCompanyId AND a.status = 'SUBMIT' AND a.isDeleted = false")
|
||||||
Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
|
|
||||||
|
List<ApplicationEntity> findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(Long userWithCompanyId, Long userId);
|
||||||
|
|
||||||
List<ApplicationEntity> findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId);
|
|
||||||
|
|
||||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId AND a.isDeleted = false")
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId AND a.isDeleted = false")
|
||||||
public Long countSubmittedApplicationsByHubId(@Param("hubId") Long hubId);
|
public Long countSubmittedApplicationsByHubId(@Param("hubId") Long hubId);
|
||||||
@@ -40,6 +42,6 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId AND a.isDeleted = false")
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId AND a.isDeleted = false")
|
||||||
public Long countDraftApplicationsByHubId(@Param("hubId") Long hubId);
|
public Long countDraftApplicationsByHubId(@Param("hubId") Long hubId);
|
||||||
|
|
||||||
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id")
|
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
||||||
Long findCallIdById(@Param("id") Long id);
|
Long findCallIdById(@Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,17 @@ public interface BeneficiaryPreferredCallRepository extends JpaRepository<Benefi
|
|||||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndIsDeletedFalse(Long beneficiaryId);
|
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndIsDeletedFalse(Long beneficiaryId);
|
||||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
List<BeneficiaryPreferredCallEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||||
|
|
||||||
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId) AND isDeleted=false")
|
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall WHERE preferredCall.userId = :userId AND (:userWithCompanyId IS NULL OR preferredCall.userWithCompany.id = :userWithCompanyId) AND isDeleted = false")
|
||||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
List<BeneficiaryPreferredCallEntity> findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(@Param("userId") Long userId, @Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
|
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
|
||||||
|
|
||||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndIsDeletedFalse(Long userId, List<Long> callIds);
|
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndIsDeletedFalse(Long userId, List<Long> callIds);
|
||||||
|
|
||||||
Optional<BeneficiaryPreferredCallEntity> findByIdAndIsDeletedFalse(Long id);
|
Optional<BeneficiaryPreferredCallEntity> findByIdAndIsDeletedFalse(Long id);
|
||||||
Optional<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(Long userId, Long callId, Long companyId);
|
|
||||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndCompanyIdAndIsDeletedFalse(Long userId, List<Long> callIds,Long companyId);
|
Optional<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdAndUserWithCompanyIdAndIsDeletedFalse(Long userId, Long callId, Long userWithCompanyId);
|
||||||
|
|
||||||
|
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndUserWithCompanyIdAndIsDeletedFalse(Long userId, List<Long> callIds, Long userWithCompanyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
|
import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface BeneficiaryRepository extends JpaRepository<BeneficiaryEntity, Long> {
|
public interface BeneficiaryRepository extends JpaRepository<BeneficiaryEntity, Long> {
|
||||||
|
|
||||||
|
@Query("SELECT u.id FROM UserEntity u JOIN u.beneficiary b WHERE b.id = u.beneficiary.id AND b.hubId = :hubId")
|
||||||
|
List<Long> findUserIdsByHubIdAndBeneficiaryId(Long hubId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ public interface DocumentRepository extends JpaRepository<DocumentEntity, Long>
|
|||||||
|
|
||||||
@Query("SELECT d FROM DocumentEntity d WHERE d.isDeleted = false")
|
@Query("SELECT d FROM DocumentEntity d WHERE d.isDeleted = false")
|
||||||
List<DocumentEntity> findAllByIsDeleteFalse();
|
List<DocumentEntity> findAllByIsDeleteFalse();
|
||||||
|
|
||||||
|
@Query("SELECT d FROM DocumentEntity d WHERE d.isDeleted = true")
|
||||||
|
List<DocumentEntity> findAllByIsDeleteTrue();
|
||||||
|
|
||||||
List<DocumentEntity> findAllByIdInAndIsDeletedFalse(Set<Long> documentIds);
|
List<DocumentEntity> findAllByIdInAndIsDeletedFalse(Set<Long> documentIds);
|
||||||
|
|
||||||
|
List<DocumentEntity> findBySourceIdInAndSourceAndIsDeletedFalse(Set<Long> sourceId, String type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public interface FaqRepository extends JpaRepository<FaqEntity, Long> {
|
|||||||
List<FaqEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
List<FaqEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
||||||
|
|
||||||
Optional<FaqEntity> findByIdAndCallIdAndIsDeletedFalse(Long id, Long callId);
|
Optional<FaqEntity> findByIdAndCallIdAndIsDeletedFalse(Long id, Long callId);
|
||||||
List<FaqEntity> findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId);
|
|
||||||
|
List<FaqEntity> findByUserWithCompanyIdAndIsDeletedFalse(Long userWithCompanyId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@@ -12,4 +12,6 @@ public interface HubRepository extends JpaRepository<HubEntity, Long> {
|
|||||||
|
|
||||||
Optional<HubEntity> findByUniqueUuid(String hubUuid);
|
Optional<HubEntity> findByUniqueUuid(String hubUuid);
|
||||||
|
|
||||||
|
@Query("SELECT h FROM HubEntity h WHERE h.id = :hubId")
|
||||||
|
HubEntity findByHubId(@Param("hubId") Long hubId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.NotificationEntity;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface NotificationRepository extends JpaRepository<NotificationEntity, Long> {
|
||||||
|
|
||||||
|
NotificationEntity findByIdAndIsDeletedFalse(Long id);
|
||||||
|
|
||||||
|
List<NotificationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||||
|
|
||||||
|
List<NotificationEntity> findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(Long userId, Long userWithCompanyId, List<String> statuses);
|
||||||
|
|
||||||
|
List<NotificationEntity> findByUserIdAndIsDeletedFalseAndStatusIn(Long userId, List<String> statuses);
|
||||||
|
|
||||||
|
List<NotificationEntity> findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(Long userWithCompanyId, Long userId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface NotificationTypeRepository extends JpaRepository<NotificationTypeEntity, Long> {
|
||||||
|
NotificationTypeEntity findByNotificationNameAndIsDeletedFalse(String value);
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface UserCompanyDelegationRepository extends JpaRepository<UserCompanyDelegationEntity, Long> {
|
public interface UserCompanyDelegationRepository extends JpaRepository<UserCompanyDelegationEntity, Long> {
|
||||||
|
|
||||||
UserCompanyDelegationEntity findByUserIdAndCompanyIdAndStatus(Long userId, Long companyId, String status);
|
UserCompanyDelegationEntity findByUserIdAndUserWithCompanyIdAndStatus(Long userId, Long userWithCompanyId, String status);
|
||||||
|
|
||||||
@Query("SELECT d FROM UserCompanyDelegationEntity d where d.status = :status")
|
@Query("SELECT d FROM UserCompanyDelegationEntity d where d.status = :status")
|
||||||
List<UserCompanyDelegationEntity> findAllByStatus(@Param("status") String status);
|
List<UserCompanyDelegationEntity> findAllByStatus(@Param("status") String status);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
|||||||
|
|
||||||
// boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
// boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
||||||
|
|
||||||
List<UserEntity> findByRoleEntityIdAndHubId(Long roleId, Long hubId);
|
List<UserEntity> findByRoleEntityIdInAndHubId(List<Long> roleIds, Long hubId);
|
||||||
|
|
||||||
List<UserEntity> findByHubId(Long hubId);
|
List<UserEntity> findByHubId(Long hubId);
|
||||||
|
|
||||||
@@ -50,5 +50,8 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
|||||||
"AND u.roleEntity.roleType = :beneficiaryRoleType")
|
"AND u.roleEntity.roleType = :beneficiaryRoleType")
|
||||||
Boolean existsByEmailIgnoreCaseForBeneficiaries(String email, String hubUuid, String beneficiaryRoleType);
|
Boolean existsByEmailIgnoreCaseForBeneficiaries(String email, String hubUuid, String beneficiaryRoleType);
|
||||||
|
|
||||||
|
// existsByBebooleanneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||||
|
|
||||||
|
List<UserEntity> findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import java.util.List;
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface UserWithCompanyRepository extends JpaRepository<UserWithCompanyEntity, Long> {
|
public interface UserWithCompanyRepository extends JpaRepository<UserWithCompanyEntity, Long> {
|
||||||
|
|
||||||
@@ -19,4 +17,7 @@ public interface UserWithCompanyRepository extends JpaRepository<UserWithCompany
|
|||||||
|
|
||||||
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId);
|
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId);
|
||||||
|
|
||||||
|
@Query("SELECT u FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.companyId = :companyId AND u.isDeleted = false")
|
||||||
|
UserWithCompanyEntity findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(Long userId, Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user