updated code
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
FROM amazoncorretto:17.0.8-alpine3.17
|
FROM amazoncorretto:17.0.8-alpine3.17
|
||||||
|
ENV TZ="Europe/Rome"
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
ADD /target/tendermanagement-0.0.1-SNAPSHOT.jar tendermanagement-0.0.1-SNAPSHOT.jar
|
ADD /target/tendermanagement-0.0.1-SNAPSHOT.jar tendermanagement-0.0.1-SNAPSHOT.jar
|
||||||
ENTRYPOINT ["java", "-jar","tendermanagement-0.0.1-SNAPSHOT.jar"]
|
ENTRYPOINT ["java", "-jar","tendermanagement-0.0.1-SNAPSHOT.jar"]
|
||||||
|
|||||||
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -56,7 +56,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
script {
|
script {
|
||||||
sh 'ssh ubuntu@46.105.65.89 "sh gepafin-production-api.sh"'
|
sh 'ssh ubuntu@79.137.88.15 "sh gepafin-production-api.sh"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
pom.xml
41
pom.xml
@@ -94,7 +94,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>2.17.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -173,12 +173,51 @@
|
|||||||
<version>4.1.3</version>
|
<version>4.1.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>5.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mailgun</groupId>
|
||||||
|
<artifactId>mailgun-java</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.santuario</groupId>
|
<groupId>org.apache.santuario</groupId>
|
||||||
<artifactId>xmlsec</artifactId>
|
<artifactId>xmlsec</artifactId>
|
||||||
<version>2.3.0</version> <!-- or latest -->
|
<version>2.3.0</version> <!-- or latest -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.itextpdf</groupId>
|
||||||
|
<artifactId>itextpdf</artifactId>
|
||||||
|
<version>5.5.13.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext7-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.itextpdf</groupId>
|
||||||
|
<artifactId>itext7-core</artifactId>
|
||||||
|
<version>8.0.5</version>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.itextpdf/layout -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.itextpdf</groupId>
|
||||||
|
<artifactId>layout</artifactId>
|
||||||
|
<version>8.0.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|||||||
@@ -0,0 +1,203 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.CertificateFactory;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bouncycastle.util.io.pem.PemReader;
|
||||||
|
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
|
||||||
|
import org.opensaml.saml.common.SAMLVersion;
|
||||||
|
import org.opensaml.saml.common.xml.SAMLConstants;
|
||||||
|
import org.opensaml.saml.saml2.core.AuthnContextClassRef;
|
||||||
|
import org.opensaml.saml.saml2.core.AuthnContextComparisonTypeEnumeration;
|
||||||
|
import org.opensaml.saml.saml2.core.AuthnRequest;
|
||||||
|
import org.opensaml.saml.saml2.core.RequestedAuthnContext;
|
||||||
|
import org.opensaml.saml.saml2.core.impl.AuthnContextClassRefBuilder;
|
||||||
|
import org.opensaml.saml.saml2.core.impl.RequestedAuthnContextBuilder;
|
||||||
|
import org.opensaml.security.x509.BasicX509Credential;
|
||||||
|
import org.opensaml.xmlsec.config.impl.DefaultSecurityConfigurationBootstrap;
|
||||||
|
import org.opensaml.xmlsec.signature.Signature;
|
||||||
|
import org.opensaml.xmlsec.signature.support.SignatureConstants;
|
||||||
|
import org.opensaml.xmlsec.signature.support.Signer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.saml2.core.Saml2X509Credential;
|
||||||
|
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
|
||||||
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
||||||
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
||||||
|
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding;
|
||||||
|
import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver;
|
||||||
|
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver;
|
||||||
|
import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml4AuthenticationRequestResolver;
|
||||||
|
import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SamlConfig {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(SamlConfig.class);
|
||||||
|
|
||||||
|
@Value("${base-url}")
|
||||||
|
String baseUrl;
|
||||||
|
|
||||||
|
@Value("${spid.ipd.base.url}")
|
||||||
|
String ipdBaseUrl;
|
||||||
|
|
||||||
|
@Value("${active.profile.folder}")
|
||||||
|
String activeProfileFolder;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RelyingPartyRegistrationRepository relyingPartyRegistrationRepository() {
|
||||||
|
|
||||||
|
String entityId = baseUrl + "/v1/saml/gw/metadata";
|
||||||
|
String acsUrl = baseUrl + "/login/saml2/sso/loginumbria";
|
||||||
|
|
||||||
|
RelyingPartyRegistration registration = RelyingPartyRegistration.withRegistrationId("loginumbria")
|
||||||
|
.entityId(entityId)
|
||||||
|
.signingX509Credentials(credentials -> {
|
||||||
|
try {
|
||||||
|
credentials.add(Saml2X509Credential.signing(readPrivateKey(), readCertificate()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.assertionConsumerServiceLocation(acsUrl)
|
||||||
|
.assertingPartyDetails(details -> details.entityId(ipdBaseUrl + "/gw/metadata")
|
||||||
|
.singleSignOnServiceLocation(ipdBaseUrl + "/gw/SSOProxy/SAML2")
|
||||||
|
.singleSignOnServiceBinding(Saml2MessageBinding.POST)
|
||||||
|
.wantAuthnRequestsSigned(true)
|
||||||
|
.verificationX509Credentials(credentials -> {
|
||||||
|
try {
|
||||||
|
// Load the IDP's public certificate for verifying the SAML response signature
|
||||||
|
credentials.add(Saml2X509Credential.verification(readIdpCertificate()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return new InMemoryRelyingPartyRegistrationRepository(registration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthnRequest createSignedAuthnRequest(PrivateKey privateKey, X509Certificate certificate) throws Exception {
|
||||||
|
AuthnRequest authnRequest = (AuthnRequest) XMLObjectProviderRegistrySupport.getBuilderFactory()
|
||||||
|
.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME)
|
||||||
|
.buildObject(AuthnRequest.DEFAULT_ELEMENT_NAME);
|
||||||
|
|
||||||
|
authnRequest.setID("_" + UUID.randomUUID().toString());
|
||||||
|
authnRequest.setVersion(SAMLVersion.VERSION_20);
|
||||||
|
// authnRequest.setIssueInstant(new DateTime());
|
||||||
|
authnRequest.setIssueInstant(Instant.now());
|
||||||
|
|
||||||
|
|
||||||
|
// Sign the AuthnRequest
|
||||||
|
// BasicCredential signingCredential = new BasicCredential(certificate, privateKey);
|
||||||
|
BasicX509Credential signingCredential = new BasicX509Credential(certificate, privateKey);
|
||||||
|
|
||||||
|
Signature signature = (Signature) XMLObjectProviderRegistrySupport.getBuilderFactory()
|
||||||
|
.getBuilder(Signature.DEFAULT_ELEMENT_NAME)
|
||||||
|
.buildObject(Signature.DEFAULT_ELEMENT_NAME);
|
||||||
|
|
||||||
|
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
|
||||||
|
signature.setSigningCredential(signingCredential);
|
||||||
|
signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1); // Set RSA-SHA1
|
||||||
|
|
||||||
|
authnRequest.setSignature(signature);
|
||||||
|
DefaultSecurityConfigurationBootstrap.buildDefaultSignatureSigningConfiguration();
|
||||||
|
|
||||||
|
// Marshall and sign the object
|
||||||
|
XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest).marshall(authnRequest);
|
||||||
|
Signer.signObject(signature);
|
||||||
|
|
||||||
|
return authnRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Saml2AuthenticationRequestResolver authenticationRequestResolver(RelyingPartyRegistrationRepository registrations) {
|
||||||
|
RelyingPartyRegistrationResolver registrationResolver = new DefaultRelyingPartyRegistrationResolver(registrations);
|
||||||
|
OpenSaml4AuthenticationRequestResolver authenticationRequestResolver = new OpenSaml4AuthenticationRequestResolver(registrationResolver);
|
||||||
|
|
||||||
|
authenticationRequestResolver.setAuthnRequestCustomizer((context) -> {
|
||||||
|
// Set the required attributes
|
||||||
|
AuthnRequest authnRequest = context.getAuthnRequest();
|
||||||
|
authnRequest.setID("_" + UUID.randomUUID().toString()); // Add a unique ID
|
||||||
|
authnRequest.setVersion(SAMLVersion.VERSION_20); // Ensure version is 2.0
|
||||||
|
authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI); // HTTP-POST
|
||||||
|
|
||||||
|
// Set Authentication Context
|
||||||
|
authnRequest.setRequestedAuthnContext(buildRequestedAuthnContext());
|
||||||
|
|
||||||
|
// Log the SAML AuthnRequest after setting context
|
||||||
|
String samlRequest = SamlRequestLogger.convertSAMLObjectToString(authnRequest);
|
||||||
|
logger.info("SAML AuthnRequest after setting context: " + samlRequest);
|
||||||
|
});
|
||||||
|
|
||||||
|
return authenticationRequestResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestedAuthnContext buildRequestedAuthnContext() {
|
||||||
|
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
|
||||||
|
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(
|
||||||
|
SAMLConstants.SAML20_NS, AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX
|
||||||
|
);
|
||||||
|
// Set the SPID Level 2 authentication context
|
||||||
|
authnContextClassRef.setURI("urn:oasis:names:tc:SAML:2.0:ac:classes:SecureRemotePassword");
|
||||||
|
|
||||||
|
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
|
||||||
|
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
|
||||||
|
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
|
||||||
|
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
|
||||||
|
|
||||||
|
return requestedAuthnContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivateKey readPrivateKey() throws Exception {
|
||||||
|
// Path to your private key PEM file
|
||||||
|
try (PemReader pemReader = new PemReader(new InputStreamReader(readKey(activeProfileFolder + "/saml/private-key.pem")))) {
|
||||||
|
// Read the PEM content
|
||||||
|
byte[] pemContent = pemReader.readPemObject().getContent();
|
||||||
|
// Decode the PEM content
|
||||||
|
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemContent);
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // Use RSA algorithm
|
||||||
|
// Generate and return the PrivateKey
|
||||||
|
return keyFactory.generatePrivate(keySpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public X509Certificate readCertificate() throws Exception {
|
||||||
|
// Path to your certificate PEM fileFile
|
||||||
|
try (InputStream inStream = readKey(activeProfileFolder + "/saml/public-cert.pem")) {
|
||||||
|
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
||||||
|
return (X509Certificate) certFactory.generateCertificate(inStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate readIdpCertificate() throws Exception {
|
||||||
|
// Path to your IDP public certificate PEM file
|
||||||
|
try (InputStream inStream = readKey(activeProfileFolder + "/saml/idp-certificate.pem")) {
|
||||||
|
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
||||||
|
return (X509Certificate) certFactory.generateCertificate(inStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public InputStream readKey(String path) throws IOException {
|
||||||
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
InputStream inputStream = classLoader.getResourceAsStream(path);
|
||||||
|
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new FileNotFoundException("file not found : "+path);
|
||||||
|
}
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SamlFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(SamlFailureHandler.class);
|
||||||
|
|
||||||
|
@Value("${fe.base.url}")
|
||||||
|
private String feBaseUrl;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
AuthenticationException exception) throws IOException {
|
||||||
|
try {
|
||||||
|
logger.error("SAML login failed: " + exception.getMessage());
|
||||||
|
|
||||||
|
response.sendRedirect(feBaseUrl + "/login");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error processing SAML failure handler", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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.core.Authentication;
|
||||||
|
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
|
||||||
|
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.SamlResponseEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.repositories.SamlResponseRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SamlSuccessHandler implements AuthenticationSuccessHandler {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(SamlSuccessHandler.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SamlResponseRepository samlResponseLogRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Value("${fe.base.url}")
|
||||||
|
private String feBaseUrl;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
Authentication authentication) throws IOException {
|
||||||
|
try {
|
||||||
|
logger.info("SAML login in Authentication Success Handler");
|
||||||
|
Saml2Authentication samlAuth = (Saml2Authentication) authentication;
|
||||||
|
Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) samlAuth.getPrincipal();
|
||||||
|
|
||||||
|
Map<String, List<Object>> userAttributes = principal.getAttributes();
|
||||||
|
String token = Utils.generateSecureToken();
|
||||||
|
logger.info("SAML User Attributes: " + userAttributes);
|
||||||
|
|
||||||
|
SamlResponseEntity samlResponseLogEntity = new SamlResponseEntity();
|
||||||
|
samlResponseLogEntity.setAuthenticationObject(authentication.toString());
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String userAttributesJson = objectMapper.writeValueAsString(userAttributes);
|
||||||
|
samlResponseLogEntity.setAuthenticationObject(userAttributesJson);
|
||||||
|
samlResponseLogEntity.setToken(token);
|
||||||
|
samlResponseLogRepository.save(samlResponseLogEntity);
|
||||||
|
|
||||||
|
String redirectUrl = feBaseUrl;
|
||||||
|
|
||||||
|
logger.info("SAML login successful for user: " + principal.getName());
|
||||||
|
String cf = userAttributes.get("CodiceFiscale").get(0).toString();
|
||||||
|
UserEntity userEntity = userRepository.findByBeneficiaryCodiceFiscale(cf).orElse(null);
|
||||||
|
if (userEntity == null) {
|
||||||
|
redirectUrl += "/registration?temp_token=" + token;
|
||||||
|
} else {
|
||||||
|
redirectUrl += "/login?temp_token=" + token;
|
||||||
|
}
|
||||||
|
response.sendRedirect(redirectUrl);
|
||||||
|
logger.info("SAML redirect Url: " + redirectUrl);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error processing SAML success handler", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateToken(String token, String codiceFiscale) {
|
||||||
|
SamlResponseEntity samlResponseLogEntity = samlResponseLogRepository.findByToken(token);
|
||||||
|
if (samlResponseLogEntity == null) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
|
||||||
|
}
|
||||||
|
Map<String, List<Object>> userAttributes = Utils
|
||||||
|
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
|
||||||
|
String cf = userAttributes.get("CodiceFiscale").get(0).toString();
|
||||||
|
if (codiceFiscale == null || Boolean.FALSE.equals(codiceFiscale.equals(cf))) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
|
||||||
|
}
|
||||||
|
samlResponseLogRepository.delete(samlResponseLogEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,39 +1,5 @@
|
|||||||
package net.gepafin.tendermanagement.config;
|
package net.gepafin.tendermanagement.config;
|
||||||
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.security.cert.CertificateFactory;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.xml.security.Init;
|
|
||||||
import org.bouncycastle.util.io.pem.PemReader;
|
|
||||||
import org.opensaml.core.config.InitializationService;
|
|
||||||
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
|
|
||||||
import org.opensaml.saml.common.SAMLVersion;
|
|
||||||
import org.opensaml.saml.common.xml.SAMLConstants;
|
|
||||||
import org.opensaml.saml.saml2.core.AuthnContextClassRef;
|
|
||||||
import org.opensaml.saml.saml2.core.AuthnContextComparisonTypeEnumeration;
|
|
||||||
import org.opensaml.saml.saml2.core.AuthnRequest;
|
|
||||||
import org.opensaml.saml.saml2.core.RequestedAuthnContext;
|
|
||||||
import org.opensaml.saml.saml2.core.impl.AuthnContextClassRefBuilder;
|
|
||||||
import org.opensaml.saml.saml2.core.impl.RequestedAuthnContextBuilder;
|
|
||||||
import org.opensaml.security.x509.BasicX509Credential;
|
|
||||||
import org.opensaml.xmlsec.config.impl.DefaultSecurityConfigurationBootstrap;
|
|
||||||
import org.opensaml.xmlsec.signature.Signature;
|
|
||||||
import org.opensaml.xmlsec.signature.support.SignatureConstants;
|
|
||||||
import org.opensaml.xmlsec.signature.support.Signer;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
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.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -49,17 +15,6 @@ import org.springframework.security.config.annotation.web.configurers.AbstractHt
|
|||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.saml2.core.Saml2X509Credential;
|
|
||||||
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
|
|
||||||
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
|
|
||||||
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
|
|
||||||
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
|
||||||
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
|
||||||
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding;
|
|
||||||
import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver;
|
|
||||||
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver;
|
|
||||||
import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml4AuthenticationRequestResolver;
|
|
||||||
import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||||
@@ -69,63 +24,34 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|||||||
import org.springframework.web.filter.CorsFilter;
|
import org.springframework.web.filter.CorsFilter;
|
||||||
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.Components;
|
import io.swagger.v3.oas.models.Components;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import io.swagger.v3.oas.models.servers.Server;
|
import io.swagger.v3.oas.models.servers.Server;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import net.gepafin.tendermanagement.config.jwt.JWTFilter;
|
import net.gepafin.tendermanagement.config.jwt.JWTFilter;
|
||||||
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
import net.gepafin.tendermanagement.entities.SamlResponseLogEntity;
|
|
||||||
import net.gepafin.tendermanagement.repositories.SamlResponseLogRepository;
|
|
||||||
//import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationRequestContext;
|
|
||||||
//import org.springframework.security.saml2.core.Saml2AuthenticationRequest;
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableMethodSecurity(prePostEnabled = true)
|
@EnableMethodSecurity(prePostEnabled = true)
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
private final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
|
|
||||||
private final TokenProvider tokenProvider;
|
private final TokenProvider tokenProvider;
|
||||||
|
private final SamlSuccessHandler samlSuccessHandler;
|
||||||
|
private final SamlFailureHandler samlFailureHandler;
|
||||||
|
|
||||||
@Value("${base-url}")
|
@Value("${base-url}")
|
||||||
String baseUrl;
|
String baseUrl;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SamlResponseLogRepository samlResponseLogRepository;
|
public SecurityConfig(TokenProvider tokenProvider, SamlSuccessHandler samlSuccessHandler, SamlFailureHandler samlFailureHandler) {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SecurityConfig(TokenProvider tokenProvider) {
|
|
||||||
this.tokenProvider = tokenProvider;
|
this.tokenProvider = tokenProvider;
|
||||||
|
this.samlSuccessHandler =samlSuccessHandler;
|
||||||
|
this.samlFailureHandler=samlFailureHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void initXmlSecurity() throws Exception {
|
|
||||||
// Initialize Apache XML Security (Santuario)
|
|
||||||
Init.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void initOpenSAML() throws Exception {
|
|
||||||
InitializationService.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// @Bean
|
|
||||||
// public Saml2AuthenticationRequestResolver authenticationRequestResolver() {
|
|
||||||
// return (Saml2AuthenticationRequestContext context) -> {
|
|
||||||
// Saml2AuthenticationRequest request = Saml2AuthenticationRequest.withAuthenticationRequestContext(context)
|
|
||||||
// .authenticationContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:SecureRemotePassword") // Add context here
|
|
||||||
// .build();
|
|
||||||
// return request;
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
|
||||||
return config.getAuthenticationManager();
|
return config.getAuthenticationManager();
|
||||||
@@ -173,12 +99,23 @@ public class SecurityConfig {
|
|||||||
http.csrf(AbstractHttpConfigurer::disable).authorizeHttpRequests(auth -> auth
|
http.csrf(AbstractHttpConfigurer::disable).authorizeHttpRequests(auth -> auth
|
||||||
// Allow public access to the login endpoints
|
// Allow public access to the login endpoints
|
||||||
.requestMatchers("/v1/user/login").permitAll() // JWT-based login
|
.requestMatchers("/v1/user/login").permitAll() // JWT-based login
|
||||||
|
.requestMatchers("/v1/user").permitAll() // User registration
|
||||||
|
.requestMatchers("/v1/user/sso/validate/existing-user/{token}").permitAll()
|
||||||
|
.requestMatchers("/v1/user/sso/validate/new-user/{token}").permitAll()
|
||||||
.requestMatchers("/v1/saml/**").permitAll() // JWT-based login
|
.requestMatchers("/v1/saml/**").permitAll() // JWT-based login
|
||||||
.requestMatchers("/saml2/**").permitAll() // SAML login initiation
|
.requestMatchers("/saml2/**").permitAll() // SAML login initiation
|
||||||
.requestMatchers("/swagger-ui/**").permitAll() // Swagger docs
|
.requestMatchers("/swagger-ui/**").permitAll() // Swagger docs
|
||||||
.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").permitAll()
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED))
|
||||||
|
.exceptionHandling(exceptionHandling -> exceptionHandling
|
||||||
|
.authenticationEntryPoint((request, response, authException) -> {
|
||||||
|
// Send 403 Forbidden when there is no JWT token provided
|
||||||
|
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden: Authentication token is missing or invalid");
|
||||||
|
})
|
||||||
|
)
|
||||||
.addFilterBefore(corsFilter(), UsernamePasswordAuthenticationFilter.class)
|
.addFilterBefore(corsFilter(), UsernamePasswordAuthenticationFilter.class)
|
||||||
.addFilterBefore(new JWTFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class)
|
.addFilterBefore(new JWTFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class)
|
||||||
// Add SAML2 login configuration (for BENEFICIARI)
|
// Add SAML2 login configuration (for BENEFICIARI)
|
||||||
@@ -186,55 +123,8 @@ public class SecurityConfig {
|
|||||||
* .saml2Login(saml -> saml.loginPage("/saml/login") // Entry point for SAML
|
* .saml2Login(saml -> saml.loginPage("/saml/login") // Entry point for SAML
|
||||||
* login .defaultSuccessUrl("/") // Redirect after successful SAML login );
|
* login .defaultSuccessUrl("/") // Redirect after successful SAML login );
|
||||||
*/
|
*/
|
||||||
.saml2Login(saml ->
|
.saml2Login(saml -> saml.defaultSuccessUrl("/").successHandler(samlSuccessHandler)
|
||||||
saml.defaultSuccessUrl("/")
|
.failureHandler(samlFailureHandler));
|
||||||
.successHandler((request, response, authentication) -> {
|
|
||||||
try {
|
|
||||||
// Cast the authentication object to Saml2Authentication
|
|
||||||
Saml2Authentication samlAuth = (Saml2Authentication) authentication;
|
|
||||||
Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) samlAuth.getPrincipal();
|
|
||||||
|
|
||||||
// Extract the user attributes from the principal
|
|
||||||
Map<String, List<Object>> userAttributes = principal.getAttributes();
|
|
||||||
|
|
||||||
// Log the user attributes for debugging purposes
|
|
||||||
logger.info("SAML User Attributes: " + userAttributes);
|
|
||||||
|
|
||||||
// Save the authentication details in the database (Optional)
|
|
||||||
SamlResponseLogEntity samlResponseLogEntity = new SamlResponseLogEntity();
|
|
||||||
samlResponseLogEntity.setAuthenticationObject(authentication.toString());
|
|
||||||
|
|
||||||
// Convert user attributes to JSON and save in DB
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
String userAttributesJson = objectMapper.writeValueAsString(userAttributes);
|
|
||||||
samlResponseLogEntity.setAuthenticationObject(userAttributesJson);
|
|
||||||
samlResponseLogRepository.save(samlResponseLogEntity);
|
|
||||||
|
|
||||||
// Successful login logic
|
|
||||||
logger.info("SAML login successful for user: " + principal.getName());
|
|
||||||
response.sendRedirect("http://gepafin-staging-fe.s3-website.eu-central-1.amazonaws.com/login");
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error processing SAML success handler", e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.failureHandler((request, response, exception) -> {
|
|
||||||
try {
|
|
||||||
logger.error("SAML login failed: " + exception.getMessage());
|
|
||||||
|
|
||||||
// Log the failure details to the database (Optional)
|
|
||||||
SamlResponseLogEntity samlResponseLogEntity = new SamlResponseLogEntity();
|
|
||||||
samlResponseLogEntity.setRequest(request.toString());
|
|
||||||
samlResponseLogEntity.setResponse(response.toString());
|
|
||||||
samlResponseLogEntity.setExceptionObject(exception.toString());
|
|
||||||
samlResponseLogRepository.save(samlResponseLogEntity);
|
|
||||||
|
|
||||||
// Handle failure redirection
|
|
||||||
response.sendRedirect("http://gepafin-staging-fe.s3-website.eu-central-1.amazonaws.com/login");
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error processing SAML failure handler", e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
@@ -250,148 +140,5 @@ public class SecurityConfig {
|
|||||||
.scheme("bearer").bearerFormat("JWT")));
|
.scheme("bearer").bearerFormat("JWT")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RelyingPartyRegistrationRepository relyingPartyRegistrationRepository() {
|
|
||||||
|
|
||||||
String entityId = baseUrl + "/v1/saml/gw/metadata";
|
|
||||||
String acsUrl = baseUrl + "/login/saml2/sso/loginumbria";
|
|
||||||
|
|
||||||
RelyingPartyRegistration registration = RelyingPartyRegistration.withRegistrationId("loginumbria")
|
|
||||||
.entityId(entityId)
|
|
||||||
.signingX509Credentials(credentials -> {
|
|
||||||
try {
|
|
||||||
credentials.add(Saml2X509Credential.signing(readPrivateKey(), readCertificate()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.assertionConsumerServiceLocation(acsUrl)
|
|
||||||
.assertingPartyDetails(details -> details.entityId("https://federatest.umbriadigitale.it/gw/metadata")
|
|
||||||
.singleSignOnServiceLocation("https://federatest.umbriadigitale.it/gw/SSOProxy/SAML2")
|
|
||||||
.singleSignOnServiceBinding(Saml2MessageBinding.POST)
|
|
||||||
.wantAuthnRequestsSigned(true)
|
|
||||||
.verificationX509Credentials(credentials -> {
|
|
||||||
try {
|
|
||||||
// Load the IDP's public certificate for verifying the SAML response signature
|
|
||||||
credentials.add(Saml2X509Credential.verification(readIdpCertificate()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return new InMemoryRelyingPartyRegistrationRepository(registration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AuthnRequest createSignedAuthnRequest(PrivateKey privateKey, X509Certificate certificate) throws Exception {
|
|
||||||
AuthnRequest authnRequest = (AuthnRequest) XMLObjectProviderRegistrySupport.getBuilderFactory()
|
|
||||||
.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME)
|
|
||||||
.buildObject(AuthnRequest.DEFAULT_ELEMENT_NAME);
|
|
||||||
|
|
||||||
authnRequest.setID("_" + UUID.randomUUID().toString());
|
|
||||||
authnRequest.setVersion(SAMLVersion.VERSION_20);
|
|
||||||
// authnRequest.setIssueInstant(new DateTime());
|
|
||||||
authnRequest.setIssueInstant(Instant.now());
|
|
||||||
|
|
||||||
|
|
||||||
// Sign the AuthnRequest
|
|
||||||
// BasicCredential signingCredential = new BasicCredential(certificate, privateKey);
|
|
||||||
BasicX509Credential signingCredential = new BasicX509Credential(certificate, privateKey);
|
|
||||||
|
|
||||||
Signature signature = (Signature) XMLObjectProviderRegistrySupport.getBuilderFactory()
|
|
||||||
.getBuilder(Signature.DEFAULT_ELEMENT_NAME)
|
|
||||||
.buildObject(Signature.DEFAULT_ELEMENT_NAME);
|
|
||||||
|
|
||||||
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
|
|
||||||
signature.setSigningCredential(signingCredential);
|
|
||||||
signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1); // Set RSA-SHA1
|
|
||||||
|
|
||||||
authnRequest.setSignature(signature);
|
|
||||||
DefaultSecurityConfigurationBootstrap.buildDefaultSignatureSigningConfiguration();
|
|
||||||
|
|
||||||
// Marshall and sign the object
|
|
||||||
XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest).marshall(authnRequest);
|
|
||||||
Signer.signObject(signature);
|
|
||||||
|
|
||||||
return authnRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Saml2AuthenticationRequestResolver authenticationRequestResolver(RelyingPartyRegistrationRepository registrations) {
|
|
||||||
RelyingPartyRegistrationResolver registrationResolver = new DefaultRelyingPartyRegistrationResolver(registrations);
|
|
||||||
OpenSaml4AuthenticationRequestResolver authenticationRequestResolver = new OpenSaml4AuthenticationRequestResolver(registrationResolver);
|
|
||||||
|
|
||||||
authenticationRequestResolver.setAuthnRequestCustomizer((context) -> {
|
|
||||||
// Set the required attributes
|
|
||||||
AuthnRequest authnRequest = context.getAuthnRequest();
|
|
||||||
authnRequest.setID("_" + UUID.randomUUID().toString()); // Add a unique ID
|
|
||||||
authnRequest.setVersion(SAMLVersion.VERSION_20); // Ensure version is 2.0
|
|
||||||
authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI); // HTTP-POST
|
|
||||||
|
|
||||||
// Set Authentication Context
|
|
||||||
authnRequest.setRequestedAuthnContext(buildRequestedAuthnContext());
|
|
||||||
|
|
||||||
// Log the SAML AuthnRequest after setting context
|
|
||||||
String samlRequest = SamlRequestLogger.convertSAMLObjectToString(authnRequest);
|
|
||||||
logger.info("SAML AuthnRequest after setting context: " + samlRequest);
|
|
||||||
});
|
|
||||||
|
|
||||||
return authenticationRequestResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RequestedAuthnContext buildRequestedAuthnContext() {
|
|
||||||
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
|
|
||||||
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(
|
|
||||||
SAMLConstants.SAML20_NS, AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX
|
|
||||||
);
|
|
||||||
// Set the SPID Level 2 authentication context
|
|
||||||
authnContextClassRef.setURI("urn:oasis:names:tc:SAML:2.0:ac:classes:SecureRemotePassword");
|
|
||||||
|
|
||||||
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
|
|
||||||
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
|
|
||||||
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
|
|
||||||
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
|
|
||||||
|
|
||||||
return requestedAuthnContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateKey readPrivateKey() throws Exception {
|
|
||||||
// Path to your private key PEM file
|
|
||||||
try (PemReader pemReader = new PemReader(new InputStreamReader(readKey("dev/saml/private-key.pem")))) {
|
|
||||||
// Read the PEM content
|
|
||||||
byte[] pemContent = pemReader.readPemObject().getContent();
|
|
||||||
// Decode the PEM content
|
|
||||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemContent);
|
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // Use RSA algorithm
|
|
||||||
// Generate and return the PrivateKey
|
|
||||||
return keyFactory.generatePrivate(keySpec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public X509Certificate readCertificate() throws Exception {
|
|
||||||
// Path to your certificate PEM fileFile
|
|
||||||
try (InputStream inStream = readKey("dev/saml/public-cert.pem")) {
|
|
||||||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
|
||||||
return (X509Certificate) certFactory.generateCertificate(inStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public X509Certificate readIdpCertificate() throws Exception {
|
|
||||||
// Path to your IDP public certificate PEM file
|
|
||||||
try (InputStream inStream = readKey("dev/saml/idp-certificate.pem")) {
|
|
||||||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
|
||||||
return (X509Certificate) certFactory.generateCertificate(inStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public InputStream readKey(String path) throws IOException {
|
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
|
||||||
InputStream inputStream = classLoader.getResourceAsStream(path);
|
|
||||||
|
|
||||||
if (inputStream == null) {
|
|
||||||
throw new FileNotFoundException("file not found : "+path);
|
|
||||||
}
|
|
||||||
return inputStream;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -82,10 +82,11 @@ public class TokenProvider {
|
|||||||
log.info("JWT Secret Key initialized.");
|
log.info("JWT Secret Key initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createToken(Authentication authentication, Boolean rememberMe, UserEntity user) {
|
public String createToken(Boolean rememberMe, UserEntity user) {
|
||||||
String authorities = authentication.getAuthorities().stream()
|
// String authorities = authentication.getAuthorities().stream()
|
||||||
.map(GrantedAuthority::getAuthority)
|
// .map(GrantedAuthority::getAuthority)
|
||||||
.collect(Collectors.joining(","));
|
// .collect(Collectors.joining(","));
|
||||||
|
String authorities = user.getRoleEntity().getRoleType();
|
||||||
Long now;
|
Long now;
|
||||||
Date validity;
|
Date validity;
|
||||||
|
|
||||||
@@ -99,11 +100,15 @@ public class TokenProvider {
|
|||||||
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
String payload = authentication.getName();
|
String payload = user.getEmail();
|
||||||
if(user != null) {
|
if(user != null) {
|
||||||
payload += ":"+user.getId();
|
payload += ":"+user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(user != null) {
|
||||||
|
payload += ":"+user.getHub().getId();
|
||||||
|
}
|
||||||
|
|
||||||
String token = Jwts.builder()
|
String token = Jwts.builder()
|
||||||
.setSubject(payload)
|
.setSubject(payload)
|
||||||
.claim("auth", authorities)
|
.claim("auth", authorities)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class GepafinConstant {
|
|||||||
public static final String GET_REGION_SUCCESS_MSG = "get.region.success";
|
public static final String GET_REGION_SUCCESS_MSG = "get.region.success";
|
||||||
public static final String DELETE_REGION_SUCCESS_MSG = "delete.region.success";
|
public static final String DELETE_REGION_SUCCESS_MSG = "delete.region.success";
|
||||||
public static final String REGION_NOT_FOUND_MSG = "user.region.not.found";
|
public static final String REGION_NOT_FOUND_MSG = "user.region.not.found";
|
||||||
public static final String PASSWORD_DOESNT_MATCH ="password.doesnt.match";
|
public static final String PASSWORD_DOESNT_MATCH = "password.doesnt.match";
|
||||||
public static final String USER_NOT_EXIST_MSG = "user.not.exist";
|
public static final String USER_NOT_EXIST_MSG = "user.not.exist";
|
||||||
public static final String REGION_NOT_FOUND = "region.not.found";
|
public static final String REGION_NOT_FOUND = "region.not.found";
|
||||||
public static final String USER_ID_NOT_NULL_MSG = "user.id.not.null";
|
public static final String USER_ID_NOT_NULL_MSG = "user.id.not.null";
|
||||||
@@ -36,12 +36,12 @@ public class GepafinConstant {
|
|||||||
public static final String LOOK_UP_DATA_NOT_VALID_MSG = "look.up.data.not.valid";
|
public static final String LOOK_UP_DATA_NOT_VALID_MSG = "look.up.data.not.valid";
|
||||||
public static final String FILES_UPLOADED_MSG = "files.uploaded";
|
public static final String FILES_UPLOADED_MSG = "files.uploaded";
|
||||||
public static final String CALL_CREATED_SUCCESSFULLY_MSG = "call.created.successfully";
|
public static final String CALL_CREATED_SUCCESSFULLY_MSG = "call.created.successfully";
|
||||||
public static final String FILE_DELETED_SUCCESSFULLY_MSG="file.deleted.successfully";
|
public static final String FILE_DELETED_SUCCESSFULLY_MSG = "file.deleted.successfully";
|
||||||
public static final String DOCUMENT_NOT_FOUND="document.not.found";
|
public static final String DOCUMENT_NOT_FOUND = "document.not.found";
|
||||||
public static final String LOGIN_SUCCESS_MSG="login.successfully";
|
public static final String LOGIN_SUCCESS_MSG = "login.successfully";
|
||||||
public static final String PASSWORD_MIN_LEN ="pass.min.len.msg";
|
public static final String PASSWORD_MIN_LEN = "pass.min.len.msg";
|
||||||
public static final String EMAIL_ALREADY_EXISTS = "email.already.exists";
|
public static final String EMAIL_ALREADY_EXISTS = "email.already.exists";
|
||||||
public static final String DOCUMENT_ID_NOT_FOUND="document.id.not.found";
|
public static final String DOCUMENT_ID_NOT_FOUND = "document.id.not.found";
|
||||||
public static final String INVALID_DATE_MSG = "call.invalid.date";
|
public static final String INVALID_DATE_MSG = "call.invalid.date";
|
||||||
public static final String FORM_NOT_FOUND = "form.not.found";
|
public static final String FORM_NOT_FOUND = "form.not.found";
|
||||||
public static final String FORM_CREATED_SUCCESSFULLY = "form.created.successfully";
|
public static final String FORM_CREATED_SUCCESSFULLY = "form.created.successfully";
|
||||||
@@ -61,7 +61,7 @@ public class GepafinConstant {
|
|||||||
public static final String FORM_TEMPLATE_DELETED_SUCCESSFULLY = "form.template.deleted.successfully";
|
public static final String FORM_TEMPLATE_DELETED_SUCCESSFULLY = "form.template.deleted.successfully";
|
||||||
public static final String FORM_TEMPLATE_FETCHED_SUCCESSFULLY = "form.template.fetched.successfully";
|
public static final String FORM_TEMPLATE_FETCHED_SUCCESSFULLY = "form.template.fetched.successfully";
|
||||||
public static final String REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM_TEMPLATE = "required.parameter.not.found.for.form.template";
|
public static final String REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM_TEMPLATE = "required.parameter.not.found.for.form.template";
|
||||||
public static final String FORM_NOT_FOUND_FOR_CALL_ID="form.not.found.for.call.id";
|
public static final String FORM_NOT_FOUND_FOR_CALL_ID = "form.not.found.for.call.id";
|
||||||
public static final String STEP_1 = "STEP_1";
|
public static final String STEP_1 = "STEP_1";
|
||||||
public static final String STEP_2 = "STEP_2";
|
public static final String STEP_2 = "STEP_2";
|
||||||
public static final String VALIDATE_REQUEST = "VALIDATE_REQUEST";
|
public static final String VALIDATE_REQUEST = "VALIDATE_REQUEST";
|
||||||
@@ -74,7 +74,7 @@ public class GepafinConstant {
|
|||||||
public static final String EVALUATION_CRITERIA_FETCH_SUCCESSFULLY = "evaluation.criteria.fetch.successfully";
|
public static final String EVALUATION_CRITERIA_FETCH_SUCCESSFULLY = "evaluation.criteria.fetch.successfully";
|
||||||
public static final String EVALUATION_CRITERIA_UPDATED_SUCCESSFULLY = "evaluation.criteria.updated.successfully";
|
public static final String EVALUATION_CRITERIA_UPDATED_SUCCESSFULLY = "evaluation.criteria.updated.successfully";
|
||||||
public static final String EVALUATION_CRITERIA_DELETED_SUCCESSFULLY = "evaluation.criteria.deleted.successfully";
|
public static final String EVALUATION_CRITERIA_DELETED_SUCCESSFULLY = "evaluation.criteria.deleted.successfully";
|
||||||
public static final String SCORE_NOT_NULL_MSG="score.not.null";
|
public static final String SCORE_NOT_NULL_MSG = "score.not.null";
|
||||||
public static final String FAQ_NOT_FOUND = "faq.not.found";
|
public static final String FAQ_NOT_FOUND = "faq.not.found";
|
||||||
public static final String FAQ_CREATED_SUCCESSFULLY = "faq.created.successfully";
|
public static final String FAQ_CREATED_SUCCESSFULLY = "faq.created.successfully";
|
||||||
public static final String FAQ_FETCHED_SUCCESSFULLY = "faq.fetched.successfully";
|
public static final String FAQ_FETCHED_SUCCESSFULLY = "faq.fetched.successfully";
|
||||||
@@ -104,40 +104,39 @@ public class GepafinConstant {
|
|||||||
public static final String STATUS_CANNOT_BE_CHANGED = "status.cannot.be.changed";
|
public static final String STATUS_CANNOT_BE_CHANGED = "status.cannot.be.changed";
|
||||||
public static final String PUBLISHED_CALL_NOT_UPDATE = "published.call.not.update";
|
public static final String PUBLISHED_CALL_NOT_UPDATE = "published.call.not.update";
|
||||||
public static final String INVALID_USER = "invalid_user";
|
public static final String INVALID_USER = "invalid_user";
|
||||||
public static final String FLOW_CREATED_SUCCESSFULLY="flow.created.successfully";
|
public static final String FLOW_CREATED_SUCCESSFULLY = "flow.created.successfully";
|
||||||
public static final String FLOW_FETCHED_SUCCESSFULLY="flow.fetched.successfully";
|
public static final String FLOW_FETCHED_SUCCESSFULLY = "flow.fetched.successfully";
|
||||||
public static final String FLOW_ALREADY_EXISTS="flow.already.exists";
|
public static final String FLOW_ALREADY_EXISTS = "flow.already.exists";
|
||||||
public static final String FLOW_REQUEST_NOT_PROPER="flow.request.not.complete";
|
public static final String FLOW_REQUEST_NOT_PROPER = "flow.request.not.complete";
|
||||||
public static final String APPLICATION_CREATED_SUCCESS_MSG = "application.created.success";
|
public static final String APPLICATION_CREATED_SUCCESS_MSG = "application.created.success";
|
||||||
public static final String APPLICATION_UPDATED_SUCCESS_MSG = "application.updated.success";
|
public static final String APPLICATION_UPDATED_SUCCESS_MSG = "application.updated.success";
|
||||||
public static final String DELETE_APPLICATION_SUCCESS_MSG = "application.deleted.success";
|
public static final String DELETE_APPLICATION_SUCCESS_MSG = "application.deleted.success";
|
||||||
public static final String GET_APPLICATION_SUCCESS_MSG = "application.get.success";
|
public static final String GET_APPLICATION_SUCCESS_MSG = "application.get.success";
|
||||||
public static final String APPLICATION_NOT_FOUND_MSG = "application.not.found";
|
public static final String APPLICATION_NOT_FOUND_MSG = "application.not.found";
|
||||||
public static final String APPLICATION_FORM_FIELD_NOT_FOUND="application.form.field.not.found";
|
public static final String APPLICATION_FORM_FIELD_NOT_FOUND = "application.form.field.not.found";
|
||||||
public static final String FORM_ID_DOES_NOT_MACTHES="Form.not.matches.to.call.initial.form";
|
public static final String FORM_ID_DOES_NOT_MACTHES = "Form.not.matches.to.call.initial.form";
|
||||||
public static final String VALIDATION_FIELD_REQUIRED = "validation.field.required";
|
public static final String VALIDATION_FIELD_REQUIRED = "validation.field.required";
|
||||||
public static final String VALIDATION_FIELD_MIN_LENGTH = "validation.field.min_length";
|
public static final String VALIDATION_FIELD_MIN_LENGTH = "validation.field.min_length";
|
||||||
public static final String VALIDATION_FIELD_MAX_LENGTH = "validation.field.max_length";
|
public static final String VALIDATION_FIELD_MAX_LENGTH = "validation.field.max_length";
|
||||||
public static final String VALIDATION_FIELD_PATTERN = "validation.field.pattern";
|
public static final String VALIDATION_FIELD_PATTERN = "validation.field.pattern";
|
||||||
public static final String VALIDATION_FIELD_NOT_NULL = "validation.field.not_null";
|
public static final String VALIDATION_FIELD_NOT_NULL = "validation.field.not_null";
|
||||||
public static final String VALIDATION_FIELD_NOT_EMPTY = "validation.field.not_empty";
|
public static final String VALIDATION_FIELD_NOT_EMPTY = "validation.field.not_empty";
|
||||||
public static final String APPLICATION_ALREADY_EXISTS="application.already.exists";
|
public static final String APPLICATION_ALREADY_EXISTS = "application.already.exists";
|
||||||
// public static final String NEXT_FORM_NOT_FOUND = "next.form.not.found";
|
// public static final String NEXT_FORM_NOT_FOUND = "next.form.not.found";
|
||||||
// public static final String PREVIOUS_FORM_NOT_FOUND = "previous.form.not.found";
|
// public static final String PREVIOUS_FORM_NOT_FOUND = "previous.form.not.found";
|
||||||
public static final String CURRENT_FORM_INCOMPLETE = "current.form.incomplete";
|
public static final String CURRENT_FORM_INCOMPLETE = "current.form.incomplete";
|
||||||
public static final String FLOW_NOT_FOUND = "flow.not.found";
|
public static final String FLOW_NOT_FOUND = "flow.not.found";
|
||||||
public static final String VALIDATION_MESSAGE = "validation.message";
|
public static final String VALIDATION_MESSAGE = "validation.message";
|
||||||
public static final String ACTION_REQUIRED = "action.required";
|
public static final String ACTION_REQUIRED = "action.required";
|
||||||
public static final String CALL_NOT_PUBLISHED="call.not.published";
|
public static final String CALL_NOT_PUBLISHED = "call.not.published";
|
||||||
public static final String APPLICATION_ALREADY_SUBMITTED="application.already.submitted";
|
public static final String APPLICATION_ALREADY_SUBMITTED = "application.already.submitted";
|
||||||
public static final String INITAL_AND_FINAL_FORM_CANNOT_NULL="initial.and.final.form.cannot.null";
|
public static final String INITAL_AND_FINAL_FORM_CANNOT_NULL = "initial.and.final.form.cannot.null";
|
||||||
public static final String APPLICATION_FORM_NOT_FOUND="application.form.not.found";
|
public static final String APPLICATION_FORM_NOT_FOUND = "application.form.not.found";
|
||||||
public static final String UPDATING_FORM_VALUE_IMPACT_ON_FLOW="updating.form.value.impact.on.flow";
|
public static final String UPDATING_FORM_VALUE_IMPACT_ON_FLOW = "updating.form.value.impact.on.flow";
|
||||||
public static final String APPLICATION_IS_INCOMPLETE_MSG = "application.is.incomplete";
|
public static final String APPLICATION_IS_INCOMPLETE_MSG = "application.is.incomplete";
|
||||||
public static final String AUTHORIZATION = "Authorization";
|
public static final String AUTHORIZATION = "Authorization";
|
||||||
public static final String CHECK_VATNUMBER_V2_NEW_URL = "https://imprese.openapi.it/advance";
|
public static final String CHECK_VATNUMBER_V2_NEW_URL = "https://imprese.openapi.it/advance";
|
||||||
public static final String VATNUMBER_V2 = "https://imprese.openapi.it/advance";
|
public static final String VALIDATION_FIELD_CUSTOM = "validation.field.custom";
|
||||||
public static final String VALIDATION_FIELD_CUSTOM="validation.field.custom";
|
|
||||||
public static final String VALIDATION_CODICE_FISCALE = "validation.codice.fiscale";
|
public static final String VALIDATION_CODICE_FISCALE = "validation.codice.fiscale";
|
||||||
public static final String VALIDATION_CAP = "validation.cap";
|
public static final String VALIDATION_CAP = "validation.cap";
|
||||||
public static final String VALIDATION_IBAN = "validation.iban";
|
public static final String VALIDATION_IBAN = "validation.iban";
|
||||||
@@ -146,17 +145,95 @@ public class GepafinConstant {
|
|||||||
public static final String VALIDATION_URL = "validation.url";
|
public static final String VALIDATION_URL = "validation.url";
|
||||||
public static final String VALIDATION_MARCA_DA_BOLLO = "validation.marca.da.bollo";
|
public static final String VALIDATION_MARCA_DA_BOLLO = "validation.marca.da.bollo";
|
||||||
public static final String VALIDATION_PIVA = "validation.piva";
|
public static final String VALIDATION_PIVA = "validation.piva";
|
||||||
public static final String VALIDATION_VALID_PIVA="valid.vat.number";
|
public static final String VALIDATION_VALID_PIVA = "valid.vat.number";
|
||||||
public static final String IS_MARCA_DA_BOLLO="isMarcaDaBollo";
|
public static final String IS_MARCA_DA_BOLLO = "isMarcaDaBollo";
|
||||||
public static final String IS_URL="isUrl";
|
public static final String IS_URL = "isUrl";
|
||||||
public static final String IS_EMAIL_PEC="isEmailPEC";
|
public static final String IS_EMAIL_PEC = "isEmailPEC";
|
||||||
public static final String IS_EMAIL="isEmail";
|
public static final String IS_EMAIL = "isEmail";
|
||||||
public static final String IS_IBAN="isIBAN";
|
public static final String IS_IBAN = "isIBAN";
|
||||||
public static final String IS_CAP="isCAP";
|
public static final String IS_CAP = "isCAP";
|
||||||
public static final String IS_CODICE_FISCALE="isCodiceFiscale";
|
public static final String IS_CODICE_FISCALE = "isCodiceFiscale";
|
||||||
public static final String IS_PIVA="isPIVA";
|
public static final String IS_PIVA = "isPIVA";
|
||||||
|
public static final String FAILED_RETAIN_FIELD = "failed.retain.field";
|
||||||
|
public static final String USER_ALREADY_EXIST_MSG = "user.already.exist.msg";
|
||||||
|
public static final String TOKEN_VALIDATE_SUCCESS_MSE = "token.validate.success";
|
||||||
|
public static final String INVALID_REQUEST = "invalid.request";
|
||||||
|
public static final String CODICE_FISCALE_EXISTS = "codice.fiscale.exists";
|
||||||
|
public static final String TOTAL_STEPS_NOT_BE_ZERO = "total.steps.not.zero";
|
||||||
|
public static final String COMPLETED_STEPS_NOT_VALID = "completed.steps.not.valid";
|
||||||
|
public static final String FIELD_ID_NOT_FOUND = "field.id.not.found";
|
||||||
|
public static final String VALIDATE_EMAIL = "validate.email";
|
||||||
|
public static final String ROLE_ID_MANDATORY = "role.id.mandatory";
|
||||||
|
public static final String VALIDATE_PASSWORD = "validate.password";
|
||||||
|
|
||||||
|
public static final String COMPANY_CREATED_SUCCESS_MSG = "company.created.success";
|
||||||
|
public static final String COMPANY_UPDATED_SUCCESS_MSG = "company.updated.success";
|
||||||
|
public static final String COMPANY_DELETE_SUCCESS_MSG = "company.delete.success";
|
||||||
|
public static final String COMPANY_GET_SUCCESS_MSG = "company.get.success";
|
||||||
|
public static final String COMPANY_NOT_FOUND_MSG = "company.not.found";
|
||||||
|
public static final String CHECK_VATNUMBER_SUCCESS_MSG = "check.vatnumber.success";
|
||||||
|
public static final String INVALID_VATNUMBER = "invalid.vatnumber";
|
||||||
|
public static final String VATNUMBER_MANDATORY = "vatnumber.mandatory";
|
||||||
|
public static final String VATNUMBER_ALREADY_EXISTS = "vatnumber.already.exists";
|
||||||
|
public static final String INVALID_EMAIL = "invalid.email";
|
||||||
|
public static final String UNAUTHORIZED = "UNAUTHORIZED";
|
||||||
|
public static final String COMPANY_ID_MANDATORY = "company.id.mandatory";
|
||||||
|
public static final String USER_ALREADY_CONNECTED_TO_COMPANY = "user.already.connected.to.company";
|
||||||
|
public static final String YYYY_MM_DD_DASH = "yyyy-MM-dd";
|
||||||
|
public static final String YYYY_MM_DD_SLASH = "yyyy/MM/dd";
|
||||||
|
public static final String DELEGATION_TEMPLATE = "DELEGATION_TEMPLATE";
|
||||||
|
public static final String VALIDATION_ERROR_MISSING_FIRSTNAME = "validation.error.missing.firstName";
|
||||||
|
public static final String VALIDATION_ERROR_MISSING_LASTNAME = "validation.error.missing.lastName";
|
||||||
|
public static final String VALIDATION_ERROR_MISSING_CODICEFISCALE = "validation.error.missing.codiceFiscale";
|
||||||
|
public static final String DELEGATION_FILE_UPLOAD_SUCCESS = "delegation.file.upload.success";
|
||||||
|
public static final String DELEGATION_FETCH_SUCCESS = "delegation.fetch.success";
|
||||||
|
public static final String DELEGATION_TEMPLATE_GENERATION_ERROR = "delegation.template.generation.error";
|
||||||
|
public static final String VALIDATION_ERROR_FILE_EMPTY = "validation.error.file.empty";
|
||||||
|
public static final String VALIDATION_ERROR_FILE_INVALIDTYPE = "validation.error.file.invalidType";
|
||||||
|
public static final String UPLOAD_ERROR_S3 = "upload.error.s3";
|
||||||
|
|
||||||
|
public static final String CALL_NOT_STARTED_YET = "call.not.started.yet";
|
||||||
|
public static final String CALL_ALREADY_ENDED = "call.already.ended";
|
||||||
|
public static final String APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "application.status.updated.successfully";
|
||||||
|
public static final String APPLICATION_ALREADY_IN_PREVIOUS_STATUS = "application.already.in.provided.status";
|
||||||
|
public static final String DELEGATION_NOT_FOUND = "delegation.not.found";
|
||||||
|
public static final String USER_COMPANY_RELATION_NOT_FOUND = "user.company.relation.not.found";
|
||||||
|
public static final String DELEGATION_DELETE_SUCCESS = "delegation.delete.success";
|
||||||
|
public static final String HH_MM_SS = "HH:mm:ss";
|
||||||
|
|
||||||
|
public static final String USER_NOT_AUTHORIZED_TO_CREATE_APPLICATION = "user.not.authorized.create.application";
|
||||||
|
public static final String APPLICATION_SUBMITTED_CANNOT_CHANGE = "application.submitted.cannot.change";
|
||||||
|
public static final String CALL_DOCUMENTS_FETCH_SUCCESS_MSG = "call.documents.fetch.success";
|
||||||
|
public static final String CALL_DOCUMENTS_NOT_FOUND_MSG = "call.documents.not.found";
|
||||||
|
|
||||||
|
public static final String BENEFICIARY_PREFERRED_CALL_CREATED_SUCCESS_MSG = "beneficiary.preferred.call.created.success";
|
||||||
|
public static final String GET_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG = "beneficiary.preferred.call.get.success";
|
||||||
|
public static final String DELETE_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG = "beneficiary.preferred.call.delete.success";
|
||||||
|
public static final String GET_BENEFICIARY_PREFERRED_CALLS_SUCCESS_MSG = "beneficiary.preferred.calls.get.success";
|
||||||
|
public static final String BENEFICIARY_PREFERRED_CALL_UPDATED_SUCCESS_MSG = "beneficiary.preferred.call.updated.success";
|
||||||
|
public static final String BENEFICIARY_CALL_NOT_FOUND = "beneficiary.preferred.call.not.found";
|
||||||
|
public static final String BENEFICIARY_PREFERRED_CALL_STATUS_UPDATED_SUCCESS_MSG = "beneficiary.preferred.call.status.updated.success";
|
||||||
|
public static final String GET_ALL_BENEFICIARY_PREFERRED_CALLS_SUCCESS_MSG = "beneficiary.preferred.calls.get.all.success";
|
||||||
|
public static final String USER_ID_AND_BENEFICIARY_ID_ERROR = "userId.and.beneficiaryId.error";
|
||||||
|
public static final String EITHER_USER_OR_BENEFICIARY_ID_REQUIRED = "either.user.or.beneficiary.id.required";
|
||||||
|
public static final String USER_NOT_FOUND_WITH_BENEFICIARYID_MSG = "User.not.found.with.the.given.beneficiaryID";
|
||||||
|
public static final String PERMISSION_DENIED = "permission.denied";
|
||||||
|
public static final String SIGNED_DOCUMENT_FILE_UPLOAD_SUCCESS = "signed.document.file.upload.success";
|
||||||
|
public static final String GET_SIGNED_DOCUMENT_FILE_SUCCESS = "get.signed.document.file.success";
|
||||||
|
public static final String APPLICATION_SIGNED_DOCUMENT_NOT_FOUND = "application.signed.document.not.found";
|
||||||
|
public static final String DELETE_SIGNED_DOCUMENT_FILE_SUCCESS = "delete.signed.document.file.success";
|
||||||
|
public static final String DD_MM_YYYY = "dd/MM/yyyy";
|
||||||
|
|
||||||
|
public static final String DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY="dashboard.widget.fetched.successfully";
|
||||||
|
public static final Integer DEFAULT_PAGE_LIMIT = 1000;
|
||||||
|
public static final Integer DEFAULT_PAGE = 1;
|
||||||
|
public static final String ATTEMPT_DATE = "attemptDate";
|
||||||
|
public static final String LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY="login_attempt_successfully_created";
|
||||||
|
public static final String GET_LOGIN_ATTEMPT_MSG="get_login_attempt_se_msg";
|
||||||
|
public static final String CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT = "application.in.submit.status.cannot.delete.company";
|
||||||
|
public static final String GET_USERS_SUCCESS_MSG = "get.users.success.msg";
|
||||||
|
public static final String CANNOT_CREATE_BENEFICIARY_USER="cannot.create.beneficiary.user";
|
||||||
|
|
||||||
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
|
|
||||||
public static final String HUB_CREATE_SUCCESS = "hub_create_success";
|
public static final String HUB_CREATE_SUCCESS = "hub_create_success";
|
||||||
public static final String HUB_UPDATE_SUCCESS = "hub_update_success";
|
public static final String HUB_UPDATE_SUCCESS = "hub_update_success";
|
||||||
public static final String HUB_GET_SUCCESS = "hub_get_success";
|
public static final String HUB_GET_SUCCESS = "hub_get_success";
|
||||||
@@ -164,3 +241,4 @@ public class GepafinConstant {
|
|||||||
public static final String HUB_DELETE_SUCCESS = "hub_delete_success";
|
public static final String HUB_DELETE_SUCCESS = "hub_delete_success";
|
||||||
public static final String HUB_NOT_FOUND = "hub_not_found";
|
public static final String HUB_NOT_FOUND = "hub_not_found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,30 +3,46 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
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.*;
|
||||||
|
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationSignedDocumentStatusEnum;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||||
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.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.DocumentService;
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
|
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.FieldValidator;
|
||||||
|
import net.gepafin.tendermanagement.util.MailUtil;
|
||||||
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.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.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.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -56,11 +72,61 @@ public class ApplicationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CallDao callDao;
|
private CallDao callDao;
|
||||||
|
|
||||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
@Autowired
|
||||||
|
private FlowFormDao flowFormDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FlowEdgesRepository flowEdgesRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FlowDataRepository flowDataRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProtocolRepository protocolRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SystemEmailTemplatesService systemEmailTemplatesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MailUtil mailUtil;
|
||||||
|
|
||||||
|
@Value("${default_System_Receiver_Email}")
|
||||||
|
private String defaultSystemReceiverEmail;
|
||||||
|
|
||||||
|
@Value("${gepafin_email}")
|
||||||
|
private String gepafinEmail;
|
||||||
|
|
||||||
|
@Value("${rinaldo_email}")
|
||||||
|
private String rinaldoEmail;
|
||||||
|
|
||||||
|
@Value("${carlo_email}")
|
||||||
|
private String carloEmail;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Service amazonS3Service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationSignedDocumentRepository applicationSignedDocumentRepository;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url.folder.signed.document}")
|
||||||
|
private String signedDocumentS3Folder;
|
||||||
|
|
||||||
|
|
||||||
|
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId, Long applicationId) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
// callService.validatePublishedCall(formEntity.getCall().getId());
|
||||||
|
validateFormFields(applicationRequestBean,formEntity);
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
|
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
|
||||||
}
|
}
|
||||||
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
|
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
|
||||||
@@ -68,18 +134,25 @@ 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, CompanyEntity company) {
|
||||||
|
UserWithCompanyEntity userWithCompany = companyService.getUserWithCompanyEntity(user.getId(), company.getId());
|
||||||
|
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndCompanyIdAndStatus(user.getId(), company.getId(),
|
||||||
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
|
||||||
|
if (!userWithCompany.getIsLegalRepresentant() && userCompanyDelegationEntity == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.USER_NOT_AUTHORIZED_TO_CREATE_APPLICATION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ApplicationFormEntity saveApplicationFormEntity(ApplicationFormEntity applicationFormEntity) {
|
public ApplicationFormEntity saveApplicationFormEntity(ApplicationFormEntity applicationFormEntity) {
|
||||||
ApplicationFormEntity applicationFormEntity1 = applicationFormRepository.save(applicationFormEntity);
|
ApplicationFormEntity applicationFormEntity1 = applicationFormRepository.save(applicationFormEntity);
|
||||||
return applicationFormEntity1;
|
return applicationFormEntity1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateFormId(FormEntity formEntity, CallEntity callEntity) {
|
|
||||||
if (Boolean.FALSE.equals(formEntity.getId().equals(callEntity.getInitialForm()))) {
|
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FORM_ID_DOES_NOT_MACTHES));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationFormEntity createApplicationFormEntity(ApplicationEntity application, FormEntity formEntity) {
|
public ApplicationFormEntity createApplicationFormEntity(ApplicationEntity application, FormEntity formEntity) {
|
||||||
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
|
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
|
||||||
applicationFormEntity.setApplication(application);
|
applicationFormEntity.setApplication(application);
|
||||||
@@ -88,9 +161,11 @@ public class ApplicationDao {
|
|||||||
return applicationFormEntity;
|
return applicationFormEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call) {
|
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, CompanyEntity companyEntity) {
|
||||||
|
validateDelegation(user,companyEntity);
|
||||||
ApplicationEntity entity = new ApplicationEntity();
|
ApplicationEntity entity = new ApplicationEntity();
|
||||||
entity.setUser(user);
|
entity.setUserId(user.getId());
|
||||||
|
entity.setCompany(companyEntity);
|
||||||
entity.setCall(call);
|
entity.setCall(call);
|
||||||
entity.setIsDeleted(false);
|
entity.setIsDeleted(false);
|
||||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||||
@@ -103,7 +178,6 @@ public class ApplicationDao {
|
|||||||
ApplicationEntity applicationEntity = validateApplication(id);
|
ApplicationEntity applicationEntity = validateApplication(id);
|
||||||
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formId);
|
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formId);
|
||||||
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans=new ArrayList<>();
|
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans=new ArrayList<>();
|
||||||
ApplicationFormFieldResponseBean applicationFormFieldResponseBeans1=null;
|
|
||||||
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||||
applicationFormFieldResponseBeans=createApplicationFormFieldResponse(applicationFormFieldEntities, applicationFormEntity, applicationFormFieldResponseBeans);
|
applicationFormFieldResponseBeans=createApplicationFormFieldResponse(applicationFormFieldEntities, applicationFormEntity, applicationFormFieldResponseBeans);
|
||||||
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
||||||
@@ -164,56 +238,100 @@ public class ApplicationDao {
|
|||||||
log.info("Application deleted with ID: {}", id);
|
log.info("Application deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
|
// public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, CompanyEntity companyEntity) {
|
||||||
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
|
// boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||||
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
|
//
|
||||||
|
// log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||||
|
// List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// if (callId != null) {
|
||||||
|
// // Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||||
|
// log.info("Fetching applications for callId: {}", callId);
|
||||||
|
// CallEntity call = callService.validateCall(callId);
|
||||||
|
//
|
||||||
|
// // Use a single method to handle both conditions for consistency
|
||||||
|
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
|
// ? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||||
|
// .map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||||
|
// .orElse(List.of()) // If not present, return an empty list
|
||||||
|
// : applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||||
|
//
|
||||||
|
// applicationResponses = applicationEntities.stream()
|
||||||
|
// .map(this::getApplicationResponse)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// // Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||||
|
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
|
// ? applicationRepository.findByUserIdAndIsDeletedFalse(companyEntity.getId())
|
||||||
|
// : applicationRepository.findByIsDeletedFalse();
|
||||||
|
//
|
||||||
|
// applicationResponses = applicationEntities.stream()
|
||||||
|
// .map(this::getApplicationResponse)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return applicationResponses;
|
||||||
|
// }
|
||||||
|
|
||||||
log.info("Fetching applications for RoleType: {}", roleStatus);
|
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, Long companyId) {
|
||||||
List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
|
||||||
|
|
||||||
|
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||||
|
|
||||||
|
Specification<ApplicationEntity> spec = search(userEntity.getId(), callId, companyId);
|
||||||
|
|
||||||
|
List<ApplicationEntity> applicationEntities = applicationRepository.findAll(spec);
|
||||||
|
|
||||||
|
return applicationEntities.stream()
|
||||||
|
.map(this::getApplicationResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Specification<ApplicationEntity> search(Long userId, Long callId, Long companyId) {
|
||||||
|
return (root, query, builder) -> {
|
||||||
|
Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||||
|
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||||
|
if (isBeneficiary) {
|
||||||
|
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||||
|
}
|
||||||
if (callId != null) {
|
if (callId != null) {
|
||||||
// Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
||||||
log.info("Fetching applications for callId: {}", callId);
|
|
||||||
CallEntity call = callService.validateCall(callId);
|
|
||||||
|
|
||||||
// Use a single method to handle both conditions for consistency
|
|
||||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
|
||||||
? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
|
||||||
.map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
|
||||||
.orElse(List.of()) // If not present, return an empty list
|
|
||||||
: applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
|
||||||
|
|
||||||
applicationResponses = applicationEntities.stream()
|
|
||||||
.map(this::getApplicationResponse)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
|
||||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
|
||||||
? applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
|
|
||||||
: applicationRepository.findByIsDeletedFalse();
|
|
||||||
|
|
||||||
applicationResponses = applicationEntities.stream()
|
|
||||||
.map(this::getApplicationResponse)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
if (companyId != null) {
|
||||||
return applicationResponses;
|
predicate = builder.and(predicate, builder.equal(root.get("company").get("id"), companyId));
|
||||||
|
}
|
||||||
|
return predicate;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||||
ApplicationResponse responseBean = new ApplicationResponse();
|
ApplicationResponse responseBean = new ApplicationResponse();
|
||||||
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
|
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||||
|
Long completedSteps= Long.valueOf(flowFormDao.getCompletedSteps(applicationEntity));
|
||||||
|
Integer progress=calculateProgress(totalFormSteps,completedSteps);
|
||||||
responseBean.setId(applicationEntity.getId());
|
responseBean.setId(applicationEntity.getId());
|
||||||
|
responseBean.setProgress(progress);
|
||||||
|
responseBean.setCallTitle(applicationEntity.getCall().getName());
|
||||||
|
responseBean.setCallEndDate(applicationEntity.getCall().getEndDate());
|
||||||
|
responseBean.setModifiedDate(applicationEntity.getCall().getUpdatedDate());
|
||||||
responseBean.setCallId(applicationEntity.getCall().getId());
|
responseBean.setCallId(applicationEntity.getCall().getId());
|
||||||
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.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
|
if(applicationEntity.getProtocol() != null) {
|
||||||
|
responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
return responseBean;
|
return responseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity validateApplication(Long id) {
|
public ApplicationEntity validateApplication(Long id) {
|
||||||
ApplicationEntity applicationEntity= applicationRepository.findById(id).orElseThrow(() ->new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
ApplicationEntity applicationEntity = applicationRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||||
return applicationEntity;
|
return applicationEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,6 +344,9 @@ public class ApplicationDao {
|
|||||||
response.setCallId(entity.getCall().getId());
|
response.setCallId(entity.getCall().getId());
|
||||||
response.setCreatedDate(entity.getCreatedDate());
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
response.setUpdatedDate(entity.getUpdatedDate());
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
if(entity.getProtocol() != null) {
|
||||||
|
response.setProtocolNumber(entity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +380,9 @@ public class ApplicationDao {
|
|||||||
for (ApplicationFormFieldEntity applicationFormFieldEntity1 : applicationFormFieldEntities) {
|
for (ApplicationFormFieldEntity applicationFormFieldEntity1 : applicationFormFieldEntities) {
|
||||||
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||||
applicationFormFieldEntity = applicationFormFieldEntity1;
|
applicationFormFieldEntity = applicationFormFieldEntity1;
|
||||||
|
if(applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm())){
|
||||||
|
validateRequiredFields(applicationFormEntity.getForm(),applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||||
@@ -267,7 +391,13 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldValue, applicationFormFieldEntity::setFieldValue, applicationFormFieldRequestBean.getFieldValue());
|
|
||||||
|
if(applicationFormFieldRequestBean.getFieldValue() !=null ) {
|
||||||
|
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
||||||
|
}
|
||||||
|
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
|
||||||
|
applicationFormFieldEntity.setFieldValue(null);
|
||||||
|
}
|
||||||
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,13 +405,18 @@ public class ApplicationDao {
|
|||||||
List<Long> documentIds=null;
|
List<Long> documentIds=null;
|
||||||
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||||
for (ContentResponseBean contentResponseBean:contentResponseBeans){
|
for (ContentResponseBean contentResponseBean:contentResponseBeans){
|
||||||
if(Boolean.TRUE.equals(contentResponseBean.getName().equals("fileupload"))){
|
if(Boolean.TRUE.equals(contentResponseBean.getName().equals("fileupload"))) {
|
||||||
if(contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
if (contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||||
String documentId = applicationFormFieldRequestBean.getFieldValue();
|
Object fieldValueObject = applicationFormFieldRequestBean.getFieldValue();
|
||||||
|
if (fieldValueObject instanceof String) {
|
||||||
|
// Safely cast the object to a string
|
||||||
|
String documentId = (String) fieldValueObject;
|
||||||
|
// Now you can use documentId as needed
|
||||||
documentIds = validateDocumentIds(documentId);
|
documentIds = validateDocumentIds(documentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return documentIds;
|
return documentIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +454,9 @@ public class ApplicationDao {
|
|||||||
ApplicationFormFieldResponseBean applicationFormFieldResponseBean = new ApplicationFormFieldResponseBean();
|
ApplicationFormFieldResponseBean applicationFormFieldResponseBean = new ApplicationFormFieldResponseBean();
|
||||||
applicationFormFieldResponseBean.setApplicationFormId(applicationFormId);
|
applicationFormFieldResponseBean.setApplicationFormId(applicationFormId);
|
||||||
applicationFormFieldResponseBean.setFieldId(applicationFormFieldEntity.getFieldId());
|
applicationFormFieldResponseBean.setFieldId(applicationFormFieldEntity.getFieldId());
|
||||||
applicationFormFieldResponseBean.setFieldValue(applicationFormFieldEntity.getFieldValue());
|
if(applicationFormFieldEntity.getFieldValue() != null) {
|
||||||
|
applicationFormFieldResponseBean.setFieldValue(Utils.getFieldValueAsObject(applicationFormFieldEntity.getFieldValue()));
|
||||||
|
}
|
||||||
applicationFormFieldResponseBean.setId(applicationFormFieldEntity.getId());
|
applicationFormFieldResponseBean.setId(applicationFormFieldEntity.getId());
|
||||||
applicationFormFieldResponseBean.setCreatedDate(applicationFormFieldEntity.getCreatedDate());
|
applicationFormFieldResponseBean.setCreatedDate(applicationFormFieldEntity.getCreatedDate());
|
||||||
applicationFormFieldResponseBean.setUpdatedDate(applicationFormFieldEntity.getUpdatedDate());
|
applicationFormFieldResponseBean.setUpdatedDate(applicationFormFieldEntity.getUpdatedDate());
|
||||||
@@ -330,15 +467,19 @@ public class ApplicationDao {
|
|||||||
return applicationEntity;
|
return applicationEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId,Long formId, UserEntity userEntity) {
|
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId, Long formId, UserEntity userEntity) {
|
||||||
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
|
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
|
||||||
List<FormEntity> formEntities = new ArrayList<>();
|
List<FormEntity> formEntities = new ArrayList<>();
|
||||||
ApplicationEntity applicationEntity = applicationRepository.findById(applicationId)
|
boolean isBeneficiary = isBeneficiary(userEntity);
|
||||||
|
ApplicationEntity applicationEntity = isBeneficiary
|
||||||
|
? applicationRepository.findByIdAndUserIdAndIsDeletedFalse(applicationId, userEntity.getId())
|
||||||
|
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)))
|
||||||
|
: applicationRepository.findById(applicationId)
|
||||||
|
.stream().findFirst()
|
||||||
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||||
|
|
||||||
if (formId != null) {
|
if (formId != null) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
Optional<ApplicationEntity> application = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),
|
Optional<ApplicationEntity> application = applicationRepository.findByIdAndUserIdAndCallIdAndIsDeletedFalse(applicationId, userEntity.getId(),
|
||||||
formEntity.getCall().getId());
|
formEntity.getCall().getId());
|
||||||
applicationEntity=application.get();
|
applicationEntity=application.get();
|
||||||
formEntities.add(formEntity);
|
formEntities.add(formEntity);
|
||||||
@@ -356,6 +497,12 @@ public class ApplicationDao {
|
|||||||
return createApplicationGetResponseBean(applicationEntity, formEntities, formApplicationResponses);
|
return createApplicationGetResponseBean(applicationEntity, formEntities, formApplicationResponses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBeneficiary(UserEntity userEntity) {
|
||||||
|
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
|
||||||
|
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
|
||||||
|
return isBeneficiary;
|
||||||
|
}
|
||||||
|
|
||||||
private void addFormApplication(FormEntity formEntity, ApplicationEntity applicationEntity,
|
private void addFormApplication(FormEntity formEntity, ApplicationEntity applicationEntity,
|
||||||
List<FormApplicationResponse> formApplicationResponses) {
|
List<FormApplicationResponse> formApplicationResponses) {
|
||||||
FormApplicationResponse formApplicationResponse = processForm(formEntity, applicationEntity);
|
FormApplicationResponse formApplicationResponse = processForm(formEntity, applicationEntity);
|
||||||
@@ -379,7 +526,7 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ApplicationGetResponseBean createApplicationGetResponseBean(ApplicationEntity applicationEntity, List<FormEntity> formEntities, List<FormApplicationResponse> formApplicationResponses) {
|
private ApplicationGetResponseBean createApplicationGetResponseBean(ApplicationEntity applicationEntity, List<FormEntity> formEntities, List<FormApplicationResponse> formApplicationResponses) {
|
||||||
ApplicationGetResponseBean applicationGetResponseBean =createApplicationGetResponseBean(applicationEntity);
|
ApplicationGetResponseBean applicationGetResponseBean = createApplicationGetResponseBean(applicationEntity);
|
||||||
applicationGetResponseBean.setForm(formApplicationResponses);
|
applicationGetResponseBean.setForm(formApplicationResponses);
|
||||||
return applicationGetResponseBean;
|
return applicationGetResponseBean;
|
||||||
}
|
}
|
||||||
@@ -392,6 +539,11 @@ 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());
|
||||||
|
if(applicationEntity.getProtocol() != null) {
|
||||||
|
applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
|
applicationGetResponseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
return applicationGetResponseBean;
|
return applicationGetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,51 +556,289 @@ public class ApplicationDao {
|
|||||||
return formApplicationResponse;
|
return formApplicationResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationResponse createApplicationByCallId(ApplicationRequest applicationRequest,Long callId,UserEntity userEntity){
|
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
||||||
CallEntity call=callService.validateCall(callId);
|
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
||||||
call = callService.validatePublishedCall(call.getId());
|
CallEntity call = callService.validateCall(callId);
|
||||||
checkIfApplicationExists(call,userEntity);
|
// call = callService.validatePublishedCall(call.getId());
|
||||||
ApplicationEntity applicationEntity=createApplicationEntity(userEntity,call);
|
checkIfApplicationExists(call, companyEntity, userEntity);
|
||||||
|
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, companyEntity);
|
||||||
applicationEntity.setComments(applicationRequest.getComments());
|
applicationEntity.setComments(applicationRequest.getComments());
|
||||||
applicationEntity=saveApplicationEntity(applicationEntity);
|
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||||
ApplicationResponse applicationResponse=getApplicationResponse(applicationEntity);
|
ApplicationResponse applicationResponse = getApplicationResponse(applicationEntity);
|
||||||
return applicationResponse;
|
return applicationResponse;
|
||||||
}
|
}
|
||||||
public void checkIfApplicationExists(CallEntity call,UserEntity userEntity){
|
public void checkIfApplicationExists(CallEntity call, CompanyEntity companyEntity, UserEntity userEntity){
|
||||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),call.getId());
|
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndCompanyIdAndCallIdAndIsDeletedFalse(userEntity.getId(), companyEntity.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(UserEntity userEntity, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||||
public ApplicationEntity getApplicationByCallAndUser(CallEntity call, UserEntity userEntity) {
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
return applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_SUBMITTED_CANNOT_CHANGE));
|
||||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
|
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(status.getValue()))){
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
|
||||||
|
}
|
||||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||||
CallEntity callEntity = applicationEntity.getCall();
|
callService.validatePublishedCall(applicationEntity.getCall().getId());
|
||||||
Long initialFormId = callEntity.getInitialForm();
|
// CallEntity callEntity = applicationEntity.getCall();
|
||||||
Long finalFormId = callEntity.getFinalForm();
|
// Long initialFormId = callEntity.getInitialForm();
|
||||||
// if (initialFormId == null || finalFormId == null) {
|
// Long finalFormId = callEntity.getFinalForm();
|
||||||
|
//// if (initialFormId == null || finalFormId == null) {
|
||||||
|
//// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||||
|
//// }
|
||||||
|
// ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId);
|
||||||
|
// ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId);
|
||||||
|
// if (initialApplicationForm == null || finalApplicationForm == null) {
|
||||||
// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||||
// }
|
// }
|
||||||
ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId);
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId);
|
Long totalSteps=flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||||
if (initialApplicationForm == null || finalApplicationForm == null) {
|
Integer completedSteps=flowFormDao.getCompletedSteps(applicationEntity);
|
||||||
|
if (totalSteps.intValue() != completedSteps) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||||
}
|
}
|
||||||
|
Long maxProtocolNumber=protocolRepository.findMaxProtocolNumber();
|
||||||
|
Long protocolNumber = (maxProtocolNumber != null) ? maxProtocolNumber + 1 : 1;
|
||||||
|
ProtocolEntity protocolEntity=createProtocolEntity(applicationEntity,protocolNumber);
|
||||||
|
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()));
|
||||||
|
sendMailToUserAndCompany(userEntity, applicationEntity);
|
||||||
|
sendMailTodefaultSystemAndGepafin(userEntity, applicationEntity);
|
||||||
} else {
|
} else {
|
||||||
applicationEntity.setStatus(status.getValue());
|
applicationEntity.setStatus(status.getValue());
|
||||||
}
|
}
|
||||||
saveApplicationEntity(applicationEntity);
|
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||||
|
|
||||||
|
return getApplicationResponse(applicationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
|
||||||
|
if (FieldValidator.isNullOrZero(totalSteps)) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completedSteps < 0 || completedSteps > totalSteps) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.COMPLETED_STEPS_NOT_VALID));
|
||||||
|
}
|
||||||
|
|
||||||
|
double progress = ((double) completedSteps / totalSteps) * 100;
|
||||||
|
return (int) Math.round(progress);
|
||||||
|
}
|
||||||
|
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
||||||
|
|
||||||
|
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||||
|
|
||||||
|
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
||||||
|
|
||||||
|
Map<String, String> contentMap = contentResponseBeans.stream()
|
||||||
|
.collect(Collectors.toMap(ContentResponseBean::getId, ContentResponseBean::getLabel)); // Change getLabel() if needed
|
||||||
|
FieldValidator validator = FieldValidator.create();
|
||||||
|
for (ApplicationFormFieldRequestBean requestField : requestFields) {
|
||||||
|
String fieldId = requestField.getFieldId();
|
||||||
|
|
||||||
|
if (!contentMap.containsKey(fieldId)) {
|
||||||
|
validator.addError(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_ID_NOT_FOUND), fieldId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
validator.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateRequiredFields(FormEntity formEntity, ApplicationEntity applicationEntity, String fieldId) {
|
||||||
|
FlowDataEntity flowDataEntity = flowDataRepository.findByFormIdAndCallId(
|
||||||
|
formEntity.getId(), applicationEntity.getCall().getId());
|
||||||
|
|
||||||
|
if (flowDataEntity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldRepository
|
||||||
|
.findByFieldIdAndApplicationFormFormIdAndApplicationFormApplicationId(
|
||||||
|
flowDataEntity.getChoosenField(), formEntity.getId(), applicationEntity.getId())
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (applicationFormFieldEntity == null || !fieldId.equals(applicationFormFieldEntity.getFieldId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Long> nextFormIds = flowEdgesRepository.findBySourceIdAndCallId(
|
||||||
|
formEntity.getId(), applicationEntity.getCall().getId())
|
||||||
|
.stream()
|
||||||
|
.map(FlowEdgesEntity::getTargetId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Optional<Long> nextFormIdOptional = flowDataRepository.findByChoosenValueAndFormIdIn(
|
||||||
|
applicationFormFieldEntity.getFieldValue(), nextFormIds)
|
||||||
|
.map(FlowDataEntity::getFormId);
|
||||||
|
|
||||||
|
if (nextFormIdOptional.isPresent()) {
|
||||||
|
Long nextFormId = nextFormIdOptional.get();
|
||||||
|
|
||||||
|
FormEntity nextForm = formService.validateForm(nextFormId);
|
||||||
|
ApplicationFormEntity nextApplicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(
|
||||||
|
applicationEntity.getId(), nextForm.getId());
|
||||||
|
|
||||||
|
if (nextApplicationFormEntity != null) {
|
||||||
|
List<ApplicationFormFieldEntity> nextApplicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(nextApplicationFormEntity.getId());
|
||||||
|
applicationFormFieldRepository.deleteAll(nextApplicationFormFieldEntities);
|
||||||
|
applicationFormRepository.delete(nextApplicationFormEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber){
|
||||||
|
ProtocolEntity protocolEntity=new ProtocolEntity();
|
||||||
|
protocolEntity.setCall(applicationEntity.getCall().getId());
|
||||||
|
LocalDateTime utcDateTime = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||||
|
protocolEntity.setYear(utcDateTime.getYear());
|
||||||
|
protocolEntity.setProtocolNumber(protocolNumber);
|
||||||
|
protocolEntity.setTime(LocalTime.now());
|
||||||
|
protocolEntity.setApplicationId(applicationEntity.getId());
|
||||||
|
protocolRepository.save(protocolEntity);
|
||||||
|
return protocolEntity;
|
||||||
|
}
|
||||||
|
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||||
|
CallEntity call =applicationEntity.getCall();
|
||||||
|
CompanyEntity company = applicationEntity.getCompany();
|
||||||
|
ProtocolEntity protocol = applicationEntity.getProtocol();
|
||||||
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||||
|
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
|
||||||
|
call, null);
|
||||||
|
|
||||||
|
// Create the map for subject placeholders
|
||||||
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||||
|
subjectPlaceholders.put("{{call_name}}", call.getName());
|
||||||
|
subjectPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||||
|
|
||||||
|
// Create the map for body placeholders
|
||||||
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||||
|
bodyPlaceholders.put("{{call_name}}", call.getName());
|
||||||
|
bodyPlaceholders.put("{{protocol_number}}", protocol.getProtocolNumber().toString());
|
||||||
|
bodyPlaceholders.put("{{date}}", DateTimeUtil.formatLocalDateTime(protocol.getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
||||||
|
bodyPlaceholders.put("{{time}}", DateTimeUtil.parseLocalTimeToString(protocol.getTime(), GepafinConstant.HH_MM_SS));
|
||||||
|
|
||||||
|
// Replace placeholders in the subject and body
|
||||||
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
|
|
||||||
|
String email = userEntity.getEmail();
|
||||||
|
if (userEntity.getBeneficiary() != null) {
|
||||||
|
email = userEntity.getBeneficiary().getEmail();
|
||||||
|
}
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(email), null);
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(applicationEntity.getCompany().getEmail()), null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||||
|
CallEntity call = applicationEntity.getCall();
|
||||||
|
CompanyEntity company = applicationEntity.getCompany();
|
||||||
|
ProtocolEntity protocol = applicationEntity.getProtocol();
|
||||||
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||||
|
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_GEPAFIN,
|
||||||
|
call, null);
|
||||||
|
|
||||||
|
// Create the map for subject placeholders
|
||||||
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||||
|
subjectPlaceholders.put("{{call_name}}", call.getName());
|
||||||
|
subjectPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||||
|
|
||||||
|
// Create the map for body placeholders
|
||||||
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||||
|
bodyPlaceholders.put("{{call_name}}", call.getName());
|
||||||
|
bodyPlaceholders.put("{{protocol_number}}", protocol.getProtocolNumber().toString());
|
||||||
|
bodyPlaceholders.put("{{date}}", DateTimeUtil.formatLocalDateTime(protocol.getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
||||||
|
bodyPlaceholders.put("{{time}}", DateTimeUtil.parseLocalTimeToString(protocol.getTime(), GepafinConstant.HH_MM_SS));
|
||||||
|
|
||||||
|
// Replace placeholders in the subject and body
|
||||||
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
|
|
||||||
|
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(defaultSystemReceiverEmail), null);
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(gepafinEmail), null);
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(rinaldoEmail), null);
|
||||||
|
mailUtil.sendByMailGun(subject, body, List.of(carloEmail), null);
|
||||||
|
|
||||||
|
}
|
||||||
|
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
||||||
|
MultipartFile file) {
|
||||||
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
||||||
|
validateFileType(file);
|
||||||
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||||
|
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
|
if (applicationSignedDocument != null) {
|
||||||
|
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
||||||
|
applicationSignedDocumentRepository.save(applicationSignedDocument);
|
||||||
|
}
|
||||||
|
UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = amazonS3Service.uploadFileOnAmazonS3(signedDocumentS3Folder,
|
||||||
|
file);
|
||||||
|
applicationSignedDocument = new ApplicationSignedDocumentEntity();
|
||||||
|
applicationSignedDocument.setApplication(applicationEntity);
|
||||||
|
applicationSignedDocument.setFileName(uploadFileOnAmazonS3.getFileName());
|
||||||
|
applicationSignedDocument.setFilePath(uploadFileOnAmazonS3.getFilePath());
|
||||||
|
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
|
applicationSignedDocumentRepository.save(applicationSignedDocument);
|
||||||
|
return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApplicationSignedDocumentResponse convertApplicationSignedDocumentToApplicationSignedDocumentResponse(
|
||||||
|
ApplicationSignedDocumentEntity applicationSignedDocument) {
|
||||||
|
ApplicationSignedDocumentResponse applicationSignedDocumentResponse = new ApplicationSignedDocumentResponse();
|
||||||
|
applicationSignedDocumentResponse.setId(applicationSignedDocument.getId());
|
||||||
|
applicationSignedDocumentResponse.setApplicationId(applicationSignedDocument.getApplication().getId());
|
||||||
|
applicationSignedDocumentResponse.setFileName(applicationSignedDocument.getFileName());
|
||||||
|
applicationSignedDocumentResponse.setFilePath(applicationSignedDocument.getFilePath());
|
||||||
|
applicationSignedDocumentResponse
|
||||||
|
.setStatus(ApplicationSignedDocumentStatusEnum.valueOf(applicationSignedDocument.getStatus()));
|
||||||
|
applicationSignedDocumentResponse.setCreatedDate(applicationSignedDocument.getCreatedDate());
|
||||||
|
applicationSignedDocumentResponse.setUpdatedDate(applicationSignedDocument.getUpdatedDate());
|
||||||
|
return applicationSignedDocumentResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateFileType(MultipartFile file) {
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_EMPTY));
|
||||||
|
}
|
||||||
|
String filename = file.getOriginalFilename();
|
||||||
|
if (filename == null || !filename.endsWith(".p7m")) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_INVALIDTYPE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||||
|
|
||||||
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
||||||
|
|
||||||
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||||
|
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
|
if(applicationSignedDocument == null) {
|
||||||
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
||||||
|
}
|
||||||
|
return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||||
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
||||||
|
|
||||||
|
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||||
|
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||||
|
if(applicationSignedDocument == null) {
|
||||||
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
||||||
|
}
|
||||||
|
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
||||||
|
applicationSignedDocumentRepository.save(applicationSignedDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.BeneficiaryPreferredCallRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class BeneficiaryPreferredCallDao {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(BeneficiaryPreferredCallDao.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(BeneficiaryPreferredCallReq request,UserEntity user) {
|
||||||
|
log.info("Creating new beneficiary preferred call with details: {}", request);
|
||||||
|
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request,user);
|
||||||
|
entity = beneficiaryPreferredCallRepository.save(entity);
|
||||||
|
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
|
||||||
|
return convertEntityToResponse(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeneficiaryPreferredCallEntity convertRequestToEntity(BeneficiaryPreferredCallReq request,UserEntity userEntity) {
|
||||||
|
BeneficiaryPreferredCallEntity entity = new BeneficiaryPreferredCallEntity();
|
||||||
|
UserEntity user= userService.validateUser(userEntity.getId());
|
||||||
|
if (user.getBeneficiary()!=null) {
|
||||||
|
entity.setBeneficiaryId(user.getBeneficiary().getId());
|
||||||
|
}
|
||||||
|
entity.setStatus(BeneficiaryCallStatus.ENABLED.getValue());
|
||||||
|
entity.setCallId(request.getCallId());
|
||||||
|
entity.setUserId(userEntity.getId());
|
||||||
|
entity.setCompanyId(request.getCompanyId());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BeneficiaryPreferredCallResponseBean getBeneficiaryPreferredCallById(Long id) {
|
||||||
|
log.info("Fetching beneficiary preferred call with ID: {}", id);
|
||||||
|
BeneficiaryPreferredCallEntity entity = validateBeneficiaryPreferredCall(id);
|
||||||
|
log.info("Beneficiary preferred call found: {}", entity);
|
||||||
|
return convertEntityToResponse(entity);
|
||||||
|
}
|
||||||
|
// public BeneficiaryPreferredCallResponseBean updateBeneficiaryPreferredCall(Long id, BeneficiaryPreferredCallReq request,
|
||||||
|
// UserEntity userEntity) {
|
||||||
|
// log.info("Updating beneficiary preferred call with ID: {}", id);
|
||||||
|
// BeneficiaryPreferredCallEntity existingEntity = validateBeneficiaryPreferredCall(id);
|
||||||
|
// setIfUpdated(existingEntity::getCallId, existingEntity::setCallId, request.getCallId());
|
||||||
|
// setIfUpdated(existingEntity::getCompanyId, existingEntity::setCompanyId, request.getCompanyId());
|
||||||
|
//
|
||||||
|
// existingEntity = beneficiaryPreferredCallRepository.save(existingEntity);
|
||||||
|
//
|
||||||
|
// log.info("Beneficiary preferred call updated with ID: {}", existingEntity.getId());
|
||||||
|
// return convertEntityToResponse(existingEntity);
|
||||||
|
// }
|
||||||
|
|
||||||
|
private boolean isUserABeneficiary(Long userId) {
|
||||||
|
UserEntity user=userService.validateUser(userId);
|
||||||
|
return RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(user.getRoleEntity().getRoleType());
|
||||||
|
}
|
||||||
|
public void deleteBeneficiaryPreferredCallById(Long id) {
|
||||||
|
log.info("Deleting beneficiary preferred call with ID: {}", id);
|
||||||
|
validateBeneficiaryPreferredCall(id);
|
||||||
|
beneficiaryPreferredCallRepository.deleteById(id);
|
||||||
|
log.info("Beneficiary preferred call deleted with ID: {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls() {
|
||||||
|
log.info("Fetching all beneficiary preferred calls");
|
||||||
|
List<BeneficiaryPreferredCallResponseBean> calls = beneficiaryPreferredCallRepository.findAll()
|
||||||
|
.stream()
|
||||||
|
.map(this::convertEntityToResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.info("Total beneficiary preferred calls found: {}", calls.size());
|
||||||
|
return calls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeneficiaryPreferredCallEntity validateBeneficiaryPreferredCall(Long id) {
|
||||||
|
log.info("Validating beneficiary preferred call with ID: {}", id);
|
||||||
|
return beneficiaryPreferredCallRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.BENEFICIARY_CALL_NOT_FOUND)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeneficiaryPreferredCallResponseBean convertEntityToResponse(BeneficiaryPreferredCallEntity entity) {
|
||||||
|
BeneficiaryPreferredCallResponseBean response = new BeneficiaryPreferredCallResponseBean();
|
||||||
|
response.setId(entity.getId());
|
||||||
|
response.setBeneficiaryId(entity.getBeneficiaryId());
|
||||||
|
response.setStatus(BeneficiaryCallStatus.valueOf(entity.getStatus()));
|
||||||
|
response.setCallId(entity.getCallId());
|
||||||
|
response.setUserId(entity.getUserId());
|
||||||
|
response.setCompanyId(entity.getCompanyId());
|
||||||
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
public void updateBeneficiaryPreferredCallStatus(Long id, BeneficiaryCallStatus status) {
|
||||||
|
log.info("Updating status for beneficiary preferred call with ID: {}", id);
|
||||||
|
BeneficiaryPreferredCallEntity existingEntity = validateBeneficiaryPreferredCall(id);
|
||||||
|
existingEntity.setStatus(status.getValue());
|
||||||
|
beneficiaryPreferredCallRepository.save(existingEntity);
|
||||||
|
log.info("Beneficiary preferred call status updated with ID: {}", existingEntity.getId());
|
||||||
|
}
|
||||||
|
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(UserEntity userEntity, Long companyId) {
|
||||||
|
|
||||||
|
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId);
|
||||||
|
return calls.stream()
|
||||||
|
.map(this::convertEntityToResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,27 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.service.*;
|
import net.gepafin.tendermanagement.service.*;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import org.h2.util.IOUtils;
|
||||||
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 org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -74,19 +84,23 @@ public class CallDao {
|
|||||||
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private FaqService faqService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FaqService faqService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FlowDao flowDao;
|
private FlowDao flowDao;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FormDao formDao;
|
private FormDao formDao;
|
||||||
|
|
||||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, Long userId) {
|
@Value("${aws.s3.url.folder}")
|
||||||
UserEntity userEntity = userService.validateUser(userId);
|
private String s3Folder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Service amazonS3Service;
|
||||||
|
|
||||||
|
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||||
CallEntity callEntity = convertToCallEntity(createCallRequest);
|
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||||
|
|
||||||
updateFaq(createCallRequest.getFaq(), callEntity, userEntity,LookUpDataTypeEnum.FAQ);
|
updateFaq(createCallRequest.getFaq(), callEntity, userEntity,LookUpDataTypeEnum.FAQ);
|
||||||
|
|
||||||
@@ -98,8 +112,37 @@ public class CallDao {
|
|||||||
return createCallResponseBean;
|
return createCallResponseBean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public byte[] downloadCallDocumentsAsZip(Long callId) {
|
||||||
|
List<DocumentEntity> documents = documentRepository.findBySourceIdAndSourceAndTypeAndIsDeletedFalse(callId, DocumentSourceTypeEnum.CALL.getValue(),DocumentTypeEnum.DOCUMENT.getValue());
|
||||||
|
if (documents.isEmpty()) {
|
||||||
|
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||||
|
}
|
||||||
|
|
||||||
public CallEntity convertToCallEntity(CreateCallRequestStep1 createCallRequest) {
|
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||||
|
|
||||||
|
for (DocumentEntity document : documents) {
|
||||||
|
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFileName())) {
|
||||||
|
ZipEntry zipEntry = new ZipEntry(document.getFileName());
|
||||||
|
zos.putNextEntry(zipEntry);
|
||||||
|
IOUtils.copy(fileInputStream, zos);
|
||||||
|
zos.closeEntry();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Error downloading or adding document to ZIP: " + document.getFileName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zos.finish();
|
||||||
|
return zipOutputStream.toByteArray();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Error while creating ZIP file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public CallEntity convertToCallEntity(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||||
CallEntity callEntity = new CallEntity();
|
CallEntity callEntity = new CallEntity();
|
||||||
// validateCallEntity(createCallRequest);
|
// validateCallEntity(createCallRequest);
|
||||||
RegionEntity region = regionRepository.findById(createCallRequest.getRegionId())
|
RegionEntity region = regionRepository.findById(createCallRequest.getRegionId())
|
||||||
@@ -124,6 +167,18 @@ public class CallDao {
|
|||||||
callEntity.setConfidi(createCallRequest.getConfidi());
|
callEntity.setConfidi(createCallRequest.getConfidi());
|
||||||
}
|
}
|
||||||
callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested());
|
callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested());
|
||||||
|
if (createCallRequest.getAmountMin() != null && createCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
|
||||||
|
}
|
||||||
|
callEntity.setAmountMin(createCallRequest.getAmountMin());
|
||||||
|
if(createCallRequest.getEmail()!=null && Boolean.FALSE.equals(Utils.isValidEmail(createCallRequest.getEmail()))){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.VALIDATION_EMAIL,createCallRequest.getEmail()));
|
||||||
|
}
|
||||||
|
callEntity.setEmail(createCallRequest.getEmail());
|
||||||
|
callEntity.setPhoneNumber(createCallRequest.getPhoneNumber());
|
||||||
|
callEntity.setStartTime(DateTimeUtil.parseTime(createCallRequest.getStartTime()));
|
||||||
|
callEntity.setEndTime(DateTimeUtil.parseTime(createCallRequest.getEndTime()));
|
||||||
|
callEntity.setHub(userEntity.getHub());
|
||||||
callEntity = callRepository.save(callEntity);
|
callEntity = callRepository.save(callEntity);
|
||||||
return callEntity;
|
return callEntity;
|
||||||
}
|
}
|
||||||
@@ -259,6 +314,11 @@ public class CallDao {
|
|||||||
createCallResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
|
createCallResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
|
||||||
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
||||||
createCallResponseBean.setConfidi(callEntity.getConfidi());
|
createCallResponseBean.setConfidi(callEntity.getConfidi());
|
||||||
|
createCallResponseBean.setAmountMin(callEntity.getAmountMin());
|
||||||
|
createCallResponseBean.setPhoneNumber(callEntity.getPhoneNumber());
|
||||||
|
createCallResponseBean.setEndTime(callEntity.getEndTime());
|
||||||
|
createCallResponseBean.setStartTime(callEntity.getStartTime());
|
||||||
|
createCallResponseBean.setEmail(callEntity.getEmail());
|
||||||
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||||
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||||
return createCallResponseBean;
|
return createCallResponseBean;
|
||||||
@@ -358,13 +418,11 @@ public class CallDao {
|
|||||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallResponse getCallById(Long callId) {
|
public CallResponse getCallById(CallEntity callEntity) {
|
||||||
CallEntity callEntity = validateCall(callId);
|
|
||||||
return getCallResponseBean(callEntity);
|
return getCallResponseBean(callEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallResponse createCallStep2(Long callId, CreateCallRequestStep2 createCallRequest, Long userId) {
|
public CallResponse createCallStep2(CallEntity callEntity, CreateCallRequestStep2 createCallRequest, UserEntity user) {
|
||||||
CallEntity callEntity = validateCall(callId);
|
|
||||||
validateUpdate(callEntity);
|
validateUpdate(callEntity);
|
||||||
setIfUpdated(callEntity::getThreshold, callEntity::setThreshold, createCallRequest.getThreshold());
|
setIfUpdated(callEntity::getThreshold, callEntity::setThreshold, createCallRequest.getThreshold());
|
||||||
callRepository.save(callEntity);
|
callRepository.save(callEntity);
|
||||||
@@ -424,8 +482,7 @@ public class CallDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallResponse updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
|
public CallResponse updateCallStep1(CallEntity callEntity, UpdateCallRequestStep1 updateCallRequest, UserEntity userEntity) {
|
||||||
CallEntity callEntity = validateCall(callId);
|
|
||||||
if(Boolean.TRUE.equals(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue()))) {
|
if(Boolean.TRUE.equals(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue()))) {
|
||||||
try {
|
try {
|
||||||
Utils.retainOnlySpecificFields(updateCallRequest, Collections.singletonList("faq"));
|
Utils.retainOnlySpecificFields(updateCallRequest, Collections.singletonList("faq"));
|
||||||
@@ -433,7 +490,6 @@ public class CallDao {
|
|||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FAILED_RETAIN_FIELD));
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FAILED_RETAIN_FIELD));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserEntity userEntity = userService.validateUser(userId);
|
|
||||||
isValidDateRange(updateCallRequest, callEntity);
|
isValidDateRange(updateCallRequest, callEntity);
|
||||||
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
|
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
|
||||||
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
|
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
|
||||||
@@ -456,6 +512,18 @@ public class CallDao {
|
|||||||
setIfUpdated(callEntity::getAmountMax, callEntity::setAmountMax, updateCallRequest.getAmountMax());
|
setIfUpdated(callEntity::getAmountMax, callEntity::setAmountMax, updateCallRequest.getAmountMax());
|
||||||
setIfUpdated(callEntity::getDocumentationRequested, callEntity::setDocumentationRequested,
|
setIfUpdated(callEntity::getDocumentationRequested, callEntity::setDocumentationRequested,
|
||||||
updateCallRequest.getDocumentationRequested());
|
updateCallRequest.getDocumentationRequested());
|
||||||
|
|
||||||
|
if (updateCallRequest.getAmountMin() != null && updateCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
|
||||||
|
}
|
||||||
|
if(updateCallRequest.getEmail()!=null && Boolean.FALSE.equals(Utils.isValidEmail(updateCallRequest.getEmail()))){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.VALIDATION_EMAIL,updateCallRequest.getEmail()));
|
||||||
|
}
|
||||||
|
setIfUpdated(callEntity::getAmountMin, callEntity::setAmountMin, updateCallRequest.getAmountMin());
|
||||||
|
setIfUpdated(callEntity::getEmail, callEntity::setEmail, updateCallRequest.getEmail());
|
||||||
|
setIfUpdated(callEntity::getPhoneNumber, callEntity::setPhoneNumber, updateCallRequest.getPhoneNumber());
|
||||||
|
setIfUpdated(callEntity::getStartTime, callEntity::setStartTime, DateTimeUtil.parseTime(updateCallRequest.getStartTime()));
|
||||||
|
setIfUpdated(callEntity::getEndTime, callEntity::setEndTime, DateTimeUtil.parseTime(updateCallRequest.getEndTime()));
|
||||||
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
|
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
|
||||||
updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO);
|
updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO);
|
||||||
updateFaq(updateCallRequest.getFaq(), callEntity, userEntity, LookUpDataTypeEnum.FAQ);
|
updateFaq(updateCallRequest.getFaq(), callEntity, userEntity, LookUpDataTypeEnum.FAQ);
|
||||||
@@ -475,9 +543,9 @@ public class CallDao {
|
|||||||
}
|
}
|
||||||
List<CallTargetAudienceChecklistEntity> existingChecklist = callTargetAudienceChecklistRepository
|
List<CallTargetAudienceChecklistEntity> existingChecklist = callTargetAudienceChecklistRepository
|
||||||
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(callEntity.getId(), type.getValue());
|
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(callEntity.getId(), type.getValue());
|
||||||
List<Long> incomingIds = lookupDataReqList.stream().map(LookUpDataReq::getLookUpDataId)
|
List<Long> incomingIds = lookupDataReqList.stream().map(LookUpDataReq::getId)
|
||||||
.filter(id -> id != null && id > 0).collect(Collectors.toList());
|
.filter(id -> id != null && id > 0).collect(Collectors.toList());
|
||||||
existingChecklist.stream().filter(checklist -> !incomingIds.contains(checklist.getLookupData().getId()))
|
existingChecklist.stream().filter(checklist -> !incomingIds.contains(checklist.getId()))
|
||||||
.forEach(this::softDeleteCallTargetAudienceChecklist);
|
.forEach(this::softDeleteCallTargetAudienceChecklist);
|
||||||
lookupDataReqList
|
lookupDataReqList
|
||||||
.forEach(lookUpDataReq -> createOrUpdateCallTargetAudienceChecklist(lookUpDataReq, callEntity, type));
|
.forEach(lookUpDataReq -> createOrUpdateCallTargetAudienceChecklist(lookUpDataReq, callEntity, type));
|
||||||
@@ -531,6 +599,11 @@ public class CallDao {
|
|||||||
callDetailsResponseBean.setThreshold(callEntity.getThreshold());
|
callDetailsResponseBean.setThreshold(callEntity.getThreshold());
|
||||||
callDetailsResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
|
callDetailsResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
|
||||||
callDetailsResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
callDetailsResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
||||||
|
callDetailsResponseBean.setAmountMin(callEntity.getAmountMin());
|
||||||
|
callDetailsResponseBean.setEmail(callEntity.getEmail());
|
||||||
|
callDetailsResponseBean.setEndTime(callEntity.getEndTime());
|
||||||
|
callDetailsResponseBean.setStartTime(callEntity.getStartTime());
|
||||||
|
callDetailsResponseBean.setPhoneNumber(callEntity.getPhoneNumber());
|
||||||
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||||
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||||
return callDetailsResponseBean;
|
return callDetailsResponseBean;
|
||||||
@@ -575,7 +648,7 @@ public class CallDao {
|
|||||||
validateUpdate(callEntity);
|
validateUpdate(callEntity);
|
||||||
CallResponse callResponseBean = getCallResponseBean(callEntity);
|
CallResponse callResponseBean = getCallResponseBean(callEntity);
|
||||||
FlowResponseBean flowResponseBean = flowDao.getFlowByCallId(callEntity.getId());
|
FlowResponseBean flowResponseBean = flowDao.getFlowByCallId(callEntity.getId());
|
||||||
List<FormResponseBean> formResponseBean = formDao.getFormsByCallId(callEntity.getId());
|
List<FormResponseBean> formResponseBean = formDao.getFormsByCallId(callEntity);
|
||||||
CallValidatorServiceImpl.validateResponse(callResponseBean,flowResponseBean,formResponseBean);
|
CallValidatorServiceImpl.validateResponse(callResponseBean,flowResponseBean,formResponseBean);
|
||||||
callEntity.setStatus(CallStatusEnum.READY_TO_PUBLISH.getValue());
|
callEntity.setStatus(CallStatusEnum.READY_TO_PUBLISH.getValue());
|
||||||
callRepository.save(callEntity);
|
callRepository.save(callEntity);
|
||||||
@@ -591,8 +664,7 @@ public class CallDao {
|
|||||||
return callEntity;
|
return callEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallResponse updateCallStatus(Long callId, CallStatusEnum statusReq) {
|
public CallResponse updateCallStatus(CallEntity callEntity, CallStatusEnum statusReq) {
|
||||||
CallEntity callEntity = validateCall(callId);
|
|
||||||
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus());
|
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus());
|
||||||
validateStatusChange(currentStatus, statusReq);
|
validateStatusChange(currentStatus, statusReq);
|
||||||
callEntity.setStatus(statusReq.getValue());
|
callEntity.setStatus(statusReq.getValue());
|
||||||
@@ -638,6 +710,25 @@ public class CallDao {
|
|||||||
Status.NOT_FOUND,
|
Status.NOT_FOUND,
|
||||||
Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED));
|
Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED));
|
||||||
}
|
}
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
LocalTime currentTime = LocalTime.now();
|
||||||
|
|
||||||
|
if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) ||
|
||||||
|
(currentDate.isEqual(callEntity.getStartDate().toLocalDate()) && currentTime.isBefore(callEntity.getStartTime()))) {
|
||||||
|
throw new CustomValidationException(
|
||||||
|
Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.CALL_NOT_STARTED_YET)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentDate.isAfter(callEntity.getEndDate().toLocalDate()) ||
|
||||||
|
(currentDate.isEqual(callEntity.getEndDate().toLocalDate()) && currentTime.isAfter(callEntity.getEndTime()))) {
|
||||||
|
throw new CustomValidationException(
|
||||||
|
Status.BAD_REQUEST,
|
||||||
|
Translator.toLocale(GepafinConstant.CALL_ALREADY_ENDED)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return callEntity;
|
return callEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
228
src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
Normal file
228
src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
||||||
|
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.util.Utils;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CompanyDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyRepository companyRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationRepository applicationRepository;
|
||||||
|
@Autowired
|
||||||
|
private FaqRepository faqRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||||
|
CompanyEntity existingCompany = companyRepository.findByVatNumber(companyRequest.getVatNumber());
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity = null;
|
||||||
|
if (existingCompany != null) {
|
||||||
|
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId())
|
||||||
|
.orElse(null);
|
||||||
|
if (existingRelation == null) {
|
||||||
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant());
|
||||||
|
} else {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY));
|
||||||
|
}
|
||||||
|
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||||
|
} else {
|
||||||
|
validateCompany(companyRequest);
|
||||||
|
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
|
||||||
|
companyRepository.save(companyEntity);
|
||||||
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
||||||
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void validateCompany(CompanyRequest companyRequest) {
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
||||||
|
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.INVALID_EMAIL));
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(companyRequest.getVatNumber())) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
|
||||||
|
}
|
||||||
|
if (companyRepository.existsByVatNumber(companyRequest.getVatNumber())) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) {
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
||||||
|
if (userEntity.getBeneficiary() != null) {
|
||||||
|
userWithCompanyEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||||
|
}
|
||||||
|
userWithCompanyEntity.setIsDeleted(Boolean.FALSE);
|
||||||
|
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
||||||
|
userWithCompanyEntity.setUserId(userEntity.getId());
|
||||||
|
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
||||||
|
return userWithCompanyRepository.save(userWithCompanyEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompanyEntity convertCompanyRequestToCompanyEntity(CompanyRequest request) {
|
||||||
|
CompanyEntity entity = new CompanyEntity();
|
||||||
|
entity.setCompanyName(request.getCompanyName());
|
||||||
|
entity.setVatNumber(request.getVatNumber());
|
||||||
|
entity.setCodiceFiscale(request.getCodiceFiscale());
|
||||||
|
entity.setAddress(request.getAddress());
|
||||||
|
entity.setPhoneNumber(request.getPhoneNumber());
|
||||||
|
entity.setCity(request.getCity());
|
||||||
|
entity.setProvince(request.getProvince());
|
||||||
|
entity.setCap(request.getCap());
|
||||||
|
entity.setCountry(request.getCountry());
|
||||||
|
entity.setPec(request.getPec());
|
||||||
|
entity.setEmail(request.getEmail());
|
||||||
|
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||||
|
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||||
|
entity.setContactName(request.getContactName());
|
||||||
|
entity.setContactEmail(request.getContactEmail());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompanyResponse convertCompanyEntityToCompanyResponse(CompanyEntity entity, UserWithCompanyEntity userWithCompanyEntity) {
|
||||||
|
CompanyResponse response = new CompanyResponse();
|
||||||
|
response.setId(entity.getId());
|
||||||
|
response.setCompanyName(entity.getCompanyName());
|
||||||
|
response.setVatNumber(entity.getVatNumber());
|
||||||
|
response.setCodiceFiscale(entity.getCodiceFiscale());
|
||||||
|
response.setAddress(entity.getAddress());
|
||||||
|
response.setPhoneNumber(entity.getPhoneNumber());
|
||||||
|
response.setCity(entity.getCity());
|
||||||
|
response.setProvince(entity.getProvince());
|
||||||
|
response.setCap(entity.getCap());
|
||||||
|
response.setCountry(entity.getCountry());
|
||||||
|
response.setPec(entity.getPec());
|
||||||
|
response.setEmail(entity.getEmail());
|
||||||
|
response.setNumberOfEmployees(entity.getNumberOfEmployees());
|
||||||
|
response.setAnnualRevenue(entity.getAnnualRevenue());
|
||||||
|
if(userWithCompanyEntity!=null) {
|
||||||
|
response.setIsLegalRepresentant(userWithCompanyEntity.getIsLegalRepresentant());
|
||||||
|
}
|
||||||
|
response.setCreatedDate(entity.getCreatedDate());
|
||||||
|
response.setUpdatedDate(entity.getUpdatedDate());
|
||||||
|
response.setContactName(entity.getContactName());
|
||||||
|
response.setContactEmail(entity.getContactEmail());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompanyResponse updateCompany(UserEntity userEntity, Long companyId, CompanyRequest companyRequest) {
|
||||||
|
CompanyEntity companyEntity = validateCompany(companyId);
|
||||||
|
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName,
|
||||||
|
companyRequest.getCompanyName());
|
||||||
|
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
|
||||||
|
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale,
|
||||||
|
companyRequest.getCodiceFiscale());
|
||||||
|
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
||||||
|
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber,
|
||||||
|
companyRequest.getPhoneNumber());
|
||||||
|
setIfUpdated(companyEntity::getCity, companyEntity::setCity, companyRequest.getCity());
|
||||||
|
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
|
||||||
|
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
|
||||||
|
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::getAnnualRevenue, companyEntity::setAnnualRevenue,
|
||||||
|
companyRequest.getAnnualRevenue());
|
||||||
|
setIfUpdated(companyEntity::getContactName,companyEntity::setContactName,companyRequest.getContactName());
|
||||||
|
setIfUpdated(companyEntity::getContactEmail,companyEntity::setContactEmail,companyRequest.getContactEmail());
|
||||||
|
companyRepository.save(companyEntity);
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
|
||||||
|
companyRequest.getIsLegalRepresentant());
|
||||||
|
userWithCompanyRepository.save(userWithCompanyEntity);
|
||||||
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompanyEntity validateCompany(Long companyId) {
|
||||||
|
return companyRepository.findById(companyId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.COMPANY_NOT_FOUND_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompanyResponse getCompany(UserEntity userEntity, Long companyId) {
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
return convertCompanyEntityToCompanyResponse(validateCompany(companyId), userWithCompanyEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteCompany(UserEntity userEntity, Long companyId) {
|
||||||
|
CompanyEntity companyEntity = validateCompany(companyId);
|
||||||
|
companyRepository.delete(companyEntity);
|
||||||
|
userWithCompanyRepository.deleteByCompanyIdAndIsDeletedFalse(companyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CompanyResponse> getCompanyByUserId(Long userId) {
|
||||||
|
UserEntity userEntity = userService.validateUser(userId);
|
||||||
|
List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId());
|
||||||
|
List<CompanyEntity> companies = companyRepository.findByIdIn(activeCompanyIds);
|
||||||
|
return companies.stream().map(companyEntity -> {
|
||||||
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
|
||||||
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
||||||
|
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, companyId).orElseThrow(() -> new ForbiddenAccessException(Status.FORBIDDEN,
|
||||||
|
Translator.toLocale(GepafinConstant.PERMISSION_DENIED)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserWithCompanyEntity getUserWithCompany(Long userId, Long compnayId) {
|
||||||
|
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, compnayId).orElseThrow(
|
||||||
|
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
||||||
|
}
|
||||||
|
public void removeCompanyFromList(UserEntity userEntity, Long companyId) {
|
||||||
|
CompanyEntity companyEntity = validateCompany(companyId);
|
||||||
|
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyEntity.getId())
|
||||||
|
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY)));
|
||||||
|
List<ApplicationEntity> userApplications = applicationRepository.findByCompanyIdAndUserIdAndIsDeletedFalse(companyEntity.getId(), userEntity.getId());
|
||||||
|
List<FaqEntity> faqs = faqRepository.findByCompanyIdAndUserIdAndIsDeletedFalse(companyEntity.getId(), userEntity.getId());
|
||||||
|
for (ApplicationEntity application : userApplications) {
|
||||||
|
if(Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
||||||
|
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()))) {
|
||||||
|
application.setIsDeleted(Boolean.TRUE);
|
||||||
|
applicationRepository.save(application);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(FaqEntity faq:faqs) {
|
||||||
|
faq.setIsDeleted(Boolean.TRUE);
|
||||||
|
faqRepository.save(faq);
|
||||||
|
}
|
||||||
|
existingRelation.setIsDeleted(Boolean.TRUE);
|
||||||
|
userWithCompanyRepository.save(existingRelation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
118
src/main/java/net/gepafin/tendermanagement/dao/DashboardDao.java
Normal file
118
src/main/java/net/gepafin/tendermanagement/dao/DashboardDao.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.response.Widget1;
|
||||||
|
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DashboardDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallRepository callRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyRepository companyRepository;
|
||||||
|
|
||||||
|
public SuperAdminWidgetResponseBean getDashboardWidget() {
|
||||||
|
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||||
|
widgetResponseBean.setWidget1(createWidget1());
|
||||||
|
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall();
|
||||||
|
// widgetResponseBean.setWidgetBars(widgetBars);
|
||||||
|
return widgetResponseBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Widget1 createWidget1() {
|
||||||
|
Widget1 widget1 = initializeWidget1();
|
||||||
|
|
||||||
|
setActiveCalls(widget1);
|
||||||
|
setRegisteredUsers(widget1);
|
||||||
|
setTotalActiveFinancing(widget1);
|
||||||
|
setSubmittedApplications(widget1);
|
||||||
|
setDraftApplications(widget1);
|
||||||
|
setNumberOfCompanies(widget1);
|
||||||
|
|
||||||
|
return widget1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Widget1 initializeWidget1() {
|
||||||
|
return Widget1.builder().numberOfActiveCalls(0L).numberOfCompany(0L).numberOfDraftApplications(0L)
|
||||||
|
.numberOfResgisteredUsers(0L).numberOfSubmittedApplications(0L).totalActiveFinancing(BigDecimal.ZERO)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setActiveCalls(Widget1 widget1) {
|
||||||
|
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
||||||
|
if (activeCalls != null) {
|
||||||
|
widget1.setNumberOfActiveCalls(activeCalls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRegisteredUsers(Widget1 widget1) {
|
||||||
|
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleType(UserStatusEnum.ACTIVE.getValue(),
|
||||||
|
RoleStatusEnum.ROLE_BENEFICIARY.getValue());
|
||||||
|
if (activeUsers != null) {
|
||||||
|
widget1.setNumberOfResgisteredUsers(activeUsers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTotalActiveFinancing(Widget1 widget1) {
|
||||||
|
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls();
|
||||||
|
widget1.setTotalActiveFinancing(totalActiveFinancing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSubmittedApplications(Widget1 widget1) {
|
||||||
|
Long submittedApplications = applicationRepository.countSubmittedApplications();
|
||||||
|
if (submittedApplications != null) {
|
||||||
|
widget1.setNumberOfSubmittedApplications(submittedApplications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDraftApplications(Widget1 widget1) {
|
||||||
|
Long draftApplications = applicationRepository.countDraftApplications();
|
||||||
|
if (draftApplications != null) {
|
||||||
|
widget1.setNumberOfDraftApplications(draftApplications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNumberOfCompanies(Widget1 widget1) {
|
||||||
|
Long numberOfCompanies = companyRepository.countTotalCompanies();
|
||||||
|
if (numberOfCompanies != null) {
|
||||||
|
widget1.setNumberOfCompany(numberOfCompanies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(UserEntity userEntity,
|
||||||
|
CompanyEntity company) {
|
||||||
|
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
|
||||||
|
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
|
||||||
|
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
||||||
|
if (activeCalls != null) {
|
||||||
|
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
|
||||||
|
}
|
||||||
|
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
|
||||||
|
company.getId());
|
||||||
|
if (activeApplication != null) {
|
||||||
|
beneficiaryWidgetResponseBean.setNumberOfApplications(activeApplication);
|
||||||
|
}
|
||||||
|
return beneficiaryWidgetResponseBean;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
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.model.request.CompanyDelegationRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
|
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.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DelegationDao {
|
||||||
|
|
||||||
|
private static final String DEFAULT_PLACEHOLDER = "____________________";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyDao companyDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Service amazonS3Service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentRepository documentRepository;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url.folder.delegation}")
|
||||||
|
private String s3Folder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||||
|
try {
|
||||||
|
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
|
||||||
|
XWPFDocument doc = loadTemplate(templateStream);
|
||||||
|
replacePlaceholders(doc, placeholders);
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
doc.write(byteArrayOutputStream);
|
||||||
|
return byteArrayOutputStream;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.DELEGATION_TEMPLATE_GENERATION_ERROR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replacePlaceholders(XWPFDocument doc, Map<String, String> placeholders) {
|
||||||
|
doc.getParagraphs().forEach(paragraph -> {
|
||||||
|
placeholders.forEach((placeholder, value) -> {
|
||||||
|
if (paragraph.getText().contains(placeholder)) {
|
||||||
|
String updatedText = paragraph.getText().replace(placeholder, value);
|
||||||
|
paragraph.getRuns().forEach(run -> run.setText("", 0)); // Clear the existing text
|
||||||
|
paragraph.createRun().setText(updatedText); // Insert updated text
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public XWPFDocument loadTemplate(InputStream templateStream) throws IOException {
|
||||||
|
return new XWPFDocument(templateStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteArrayOutputStream downloadCompanyDelegation(UserEntity userEntity, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||||
|
Map<String, String> placeholders = getDefaultPlaceholders();
|
||||||
|
UserResponseBean user = userService.getUserById(userEntity.getId());
|
||||||
|
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
|
||||||
|
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
|
||||||
|
return generateDocument(placeholders, documentEntity.getFileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> updatePlaceholdersForDelegation(UserResponseBean user, CompanyEntity companyEntity,
|
||||||
|
Map<String, String> placeholders, CompanyDelegationRequest companyDelegationRequest) {
|
||||||
|
validateMandatoryFields(companyDelegationRequest);
|
||||||
|
addIfNotEmpty(placeholders, "{{company_first_name}}", companyDelegationRequest.getFirstName());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_last_name}}", companyDelegationRequest.getLastName());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_codice_fiscale}}", companyDelegationRequest.getCodiceFiscale());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_name}}", companyEntity.getCompanyName());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_city}}", companyEntity.getCity());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_address}}", companyEntity.getAddress());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_province}}", companyEntity.getProvince());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_cap}}", companyEntity.getCap());
|
||||||
|
addIfNotEmpty(placeholders, "{{company_vat_number}}", companyEntity.getVatNumber());
|
||||||
|
|
||||||
|
addIfNotEmpty(placeholders, "{{user_first_name}}", user.getFirstName());
|
||||||
|
addIfNotEmpty(placeholders, "{{user_last_name}}", user.getLastName());
|
||||||
|
addIfNotNull(placeholders, "{{user_date_of_birth}}", user.getDateOfBirth(),
|
||||||
|
date -> DateTimeUtil.formatLocalDateTime(date, GepafinConstant.YYYY_MM_DD_SLASH));
|
||||||
|
addIfNotEmpty(placeholders, "{{user_codice_fiscale}}", user.getCodiceFiscale());
|
||||||
|
|
||||||
|
return placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getDefaultPlaceholders() {
|
||||||
|
Map<String, String> placeholders = new HashMap<>();
|
||||||
|
placeholders.put("{{company_first_name}}", "");
|
||||||
|
placeholders.put("{{company_last_name}}", "");
|
||||||
|
placeholders.put("{{company_codice_fiscale}}", "");
|
||||||
|
placeholders.put("{{company_name}}", "");
|
||||||
|
placeholders.put("{{company_city}}", "");
|
||||||
|
placeholders.put("{{company_address}}", "");
|
||||||
|
placeholders.put("{{company_province}}", "");
|
||||||
|
placeholders.put("{{company_cap}}", "");
|
||||||
|
placeholders.put("{{company_vat_number}}", "");
|
||||||
|
|
||||||
|
placeholders.put("{{user_first_name}}", "");
|
||||||
|
placeholders.put("{{user_last_name}}", "");
|
||||||
|
placeholders.put("{{user_date_of_birth}}", "");
|
||||||
|
placeholders.put("{{user_codice_fiscale}}", "");
|
||||||
|
return placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateMandatoryFields(CompanyDelegationRequest companyDelegationRequest) {
|
||||||
|
if (StringUtils.isAllEmpty(companyDelegationRequest.getFirstName())) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_FIRSTNAME));
|
||||||
|
}
|
||||||
|
if (StringUtils.isAllEmpty(companyDelegationRequest.getLastName())) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_LASTNAME));
|
||||||
|
}
|
||||||
|
if (StringUtils.isAllEmpty(companyDelegationRequest.getCodiceFiscale())) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_CODICEFISCALE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addIfNotEmpty(Map<String, String> placeholders, String key, String value) {
|
||||||
|
if (Boolean.FALSE.equals(StringUtils.isAllEmpty(value))) {
|
||||||
|
placeholders.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void addIfNotNull(Map<String, String> placeholders, String key, T value, Function<T, String> formatter) {
|
||||||
|
if (value != null) {
|
||||||
|
placeholders.put(key, formatter.apply(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CompanyDelegationResponse uploadCompanyDelegation(UserEntity userEntity, Long companyId, MultipartFile file) {
|
||||||
|
companyDao.validateCompany(companyId);
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
validateFileType(file);
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||||
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
if (userCompanyDelegationEntity != null) {
|
||||||
|
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||||
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
}
|
||||||
|
UploadFileOnAmazonS3 uploadFileOnAmazonS3 = uploadFileOnAmazonS3(file);
|
||||||
|
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
||||||
|
userCompanyDelegationEntity.setCompanyId(companyId);
|
||||||
|
userCompanyDelegationEntity.setUserId(userEntity.getId());
|
||||||
|
if (userEntity.getBeneficiary() != null) {
|
||||||
|
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||||
|
}
|
||||||
|
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
userCompanyDelegationEntity.setFileName(uploadFileOnAmazonS3.fileName());
|
||||||
|
userCompanyDelegationEntity.setFilePath(uploadFileOnAmazonS3.filepath());
|
||||||
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompanyDelegationResponse convertUserCompanyDelegationToCompanyDelegationResponse(
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity) {
|
||||||
|
return Utils.convertSourceObjectToDestinationObject(userCompanyDelegationEntity, CompanyDelegationResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file){
|
||||||
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
|
String fileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
|
||||||
|
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||||
|
firstNameContain+=Utils.randomKey(5);
|
||||||
|
fileName = (firstNameContain + "." + extension);
|
||||||
|
try {
|
||||||
|
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
|
||||||
|
return new UploadFileOnAmazonS3(fileName, filepath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private record UploadFileOnAmazonS3(String fileName, String filepath) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateFileType(MultipartFile file) {
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_EMPTY));
|
||||||
|
}
|
||||||
|
String filename = file.getOriginalFilename();
|
||||||
|
if (filename == null || !filename.endsWith(".p7m")) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_INVALIDTYPE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompanyDelegationResponse getCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||||
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
if(userCompanyDelegationEntity == null) {
|
||||||
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
|
}
|
||||||
|
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||||
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
|
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||||
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
|
if(userCompanyDelegationEntity == null) {
|
||||||
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
|
}
|
||||||
|
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||||
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
|||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
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 org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -41,6 +42,9 @@ public class DocumentDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CallService callService;
|
private CallService callService;
|
||||||
|
|
||||||
|
@Value("${aws.s3.url.folder}")
|
||||||
|
private String s3Folder;
|
||||||
|
|
||||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
public List<DocumentResponseBean> uploadFiles(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);
|
||||||
@@ -81,7 +85,7 @@ public class DocumentDao {
|
|||||||
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
|
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
|
||||||
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||||
fileName = (firstNameContain + "." + extension);
|
fileName = (firstNameContain + "." + extension);
|
||||||
String filepath = amazonS3Service.upload(fileName, file);
|
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
|
||||||
uploadFileOnAmazonS3 result = new uploadFileOnAmazonS3(fileName, filepath);
|
uploadFileOnAmazonS3 result = new uploadFileOnAmazonS3(fileName, filepath);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -99,7 +103,7 @@ public class DocumentDao {
|
|||||||
|
|
||||||
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
|
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
|
||||||
try {
|
try {
|
||||||
amazonS3Service.delete(fileName);
|
amazonS3Service.delete(s3Folder, fileName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ import net.gepafin.tendermanagement.model.request.FaqReq;
|
|||||||
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.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.LookUpDataService;
|
import net.gepafin.tendermanagement.service.LookUpDataService;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -36,11 +39,24 @@ public class FaqDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LookUpDataService lookUpDataService;
|
private LookUpDataService lookUpDataService;
|
||||||
|
|
||||||
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId) {
|
@Autowired
|
||||||
FaqEntity entity = new FaqEntity();
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId, Long companyId) {
|
||||||
CallEntity callEntity = callService.validateCall(callId);
|
CallEntity callEntity = callService.validateCall(callId);
|
||||||
entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
FaqEntity entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
||||||
LookUpDataEntity.LookUpDataTypeEnum.FAQ);
|
LookUpDataEntity.LookUpDataTypeEnum.FAQ);
|
||||||
|
if (validator.checkIsBeneficiary() && companyId == null) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
|
||||||
|
}
|
||||||
|
if(companyId!=null) {
|
||||||
|
companyService.validateCompany(companyId);
|
||||||
|
entity.setCompanyId(companyId);
|
||||||
|
}
|
||||||
faqRepository.save(entity);
|
faqRepository.save(entity);
|
||||||
return convertToFaqResponseBean(entity);
|
return convertToFaqResponseBean(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,20 +4,16 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
||||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowDataRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowDataRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowEdgesRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowEdgesRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
|
||||||
import net.gepafin.tendermanagement.model.response.FlowDataResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowDataResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.FlowEdgesResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowEdgesResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
@@ -29,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -22,7 +20,6 @@ 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;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -46,7 +43,9 @@ public class FlowFormDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FormService formService;
|
private FormService formService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private FormRepository formRepository;
|
private FormDao formDao;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
// // vlaidation if next form findout and cuuent from is not fill the give error
|
// // vlaidation if next form findout and cuuent from is not fill the give error
|
||||||
@@ -176,54 +175,8 @@ public class FlowFormDao {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
|
||||||
// // Retrieve the flow edges for the previous forms
|
|
||||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
|
||||||
// currentFormEntity.getId(), applicationEntity.getCall().getId());
|
|
||||||
//
|
|
||||||
// if (flowEdgesList.isEmpty()) {
|
|
||||||
// return null;
|
|
||||||
//// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
|
||||||
//// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // If only one edge exists, return the source form ID
|
|
||||||
// if (flowEdgesList.size() == 1) {
|
|
||||||
// return flowEdgesList.get(0).getSourceId();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // For multiple edges, find the previous form based on the chosen value
|
|
||||||
// List<Long> previousFormIds = flowEdgesList.stream()
|
|
||||||
// .map(FlowEdgesEntity::getSourceId)
|
|
||||||
// .toList();
|
|
||||||
//
|
|
||||||
// // Fetch the flow data based on previous form IDs
|
|
||||||
// List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
|
||||||
// previousFormIds, applicationEntity.getCall().getId());
|
|
||||||
//
|
|
||||||
// List<String> chosenValues = flowDataList.stream()
|
|
||||||
// .map(FlowDataEntity::getChoosenValue)
|
|
||||||
// .toList();
|
|
||||||
//
|
|
||||||
// // Fetch the previous forms based on the chosen field values
|
|
||||||
// Set<FormEntity> formList = applicationFormFieldRepository
|
|
||||||
// .findByFieldValueInAndApplicationFormApplicationId(chosenValues, applicationEntity.getId()).stream()
|
|
||||||
// .map(fieldEntity -> fieldEntity.getApplicationForm().getForm())
|
|
||||||
// .collect(Collectors.toSet());
|
|
||||||
//
|
|
||||||
// // Find next form IDs recursively for all forms in the formList
|
|
||||||
// List<Long> fieldIds = formList.stream()
|
|
||||||
// .map(formEntity -> getNextForm(formEntity, applicationEntity))
|
|
||||||
// .toList();
|
|
||||||
//
|
|
||||||
// // Return the first matching previous form ID that corresponds to a next form
|
|
||||||
// return previousFormIds.stream()
|
|
||||||
// .filter(fieldIds::contains)
|
|
||||||
// .findFirst().orElse(null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
|
// Retrieve the flow edges for the previous forms
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||||
|
|
||||||
@@ -233,23 +186,71 @@ public class FlowFormDao {
|
|||||||
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
|
||||||
// // If only one edge exists, return the source form ID
|
// If only one edge exists, return the source form ID
|
||||||
// if (flowEdgesList.size() == 1) {
|
if (flowEdgesList.size() == 1) {
|
||||||
// return flowEdgesList.get(0).getSourceId();
|
return flowEdgesList.get(0).getSourceId();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// For multiple edges, find the previous form based on the chosen value
|
// For multiple edges, find the previous form based on the chosen value
|
||||||
List<Long> previousFormIds = flowEdgesList.stream()
|
List<Long> previousFormIds = flowEdgesList.stream()
|
||||||
.map(FlowEdgesEntity::getSourceId)
|
.map(FlowEdgesEntity::getSourceId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
|
// Fetch the flow data based on previous form IDs
|
||||||
|
List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
||||||
|
previousFormIds, applicationEntity.getCall().getId());
|
||||||
|
|
||||||
applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
|
List<String> chosenValues = flowDataList.stream()
|
||||||
|
.map(FlowDataEntity::getChoosenValue)
|
||||||
|
.toList();
|
||||||
|
|
||||||
return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
// Fetch the previous forms based on the chosen field values
|
||||||
|
Set<FormEntity> formList = applicationFormFieldRepository
|
||||||
|
.findByFieldValueInAndApplicationFormApplicationId(chosenValues, applicationEntity.getId()).stream()
|
||||||
|
.map(fieldEntity -> fieldEntity.getApplicationForm().getForm())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// Find next form IDs recursively for all forms in the formList
|
||||||
|
List<Long> fieldIds = formList.stream()
|
||||||
|
.map(formEntity -> getNextForm(formEntity, applicationEntity))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// Return the first matching previous form ID that corresponds to a next form
|
||||||
|
return previousFormIds.stream()
|
||||||
|
.filter(fieldIds::contains)
|
||||||
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
|
||||||
|
// public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
|
//
|
||||||
|
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||||
|
// currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||||
|
//
|
||||||
|
// if (flowEdgesList.isEmpty()) {
|
||||||
|
// return null;
|
||||||
|
//// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
//// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // // If only one edge exists, return the source form ID
|
||||||
|
// // if (flowEdgesList.size() == 1) {
|
||||||
|
// // return flowEdgesList.get(0).getSourceId();
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// // For multiple edges, find the previous form based on the chosen value
|
||||||
|
// List<Long> previousFormIds = flowEdgesList.stream()
|
||||||
|
// .map(FlowEdgesEntity::getSourceId)
|
||||||
|
// .toList();
|
||||||
|
// if (previousFormIds.size() == 1) {
|
||||||
|
// return previousFormIds.get(0);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
|
||||||
|
// applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
|
||||||
|
//
|
||||||
|
// return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
||||||
|
// }
|
||||||
|
public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||||
FormActionEnum action) {
|
FormActionEnum action) {
|
||||||
Long calculatedFormId = null;
|
Long calculatedFormId = null;
|
||||||
FormEntity formEntity = null;
|
FormEntity formEntity = null;
|
||||||
@@ -274,48 +275,93 @@ public class FlowFormDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
|
||||||
if (calculatedFormId != null) {
|
if (calculatedFormId == null && formId == null) {
|
||||||
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
|
FormEntity form=formService.validateForm(applicationEntity.getCall().getInitialForm());
|
||||||
|
calculatedFormId=form.getId();
|
||||||
}
|
}
|
||||||
|
if (calculatedFormId == null) {
|
||||||
|
calculatedFormId=formId;
|
||||||
|
}
|
||||||
|
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
|
||||||
|
|
||||||
return nextOrPreviousFormResponse;
|
return nextOrPreviousFormResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
||||||
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
||||||
|
nextOrPreviousFormResponse.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(applicationEntity.getStatus()));
|
||||||
nextOrPreviousFormResponse.setApplicationFormResponse(
|
nextOrPreviousFormResponse.setApplicationFormResponse(
|
||||||
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.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
|
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
|
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||||
|
Long currentStep = calculateCurrentStep(flowEdgesList, formEntity);
|
||||||
|
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
||||||
|
completedSteps = getCompletedSteps(applicationEntity);
|
||||||
|
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
|
||||||
|
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
||||||
|
if(applicationEntity.getProtocol() != null) {
|
||||||
|
nextOrPreviousFormResponse.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
|
return nextOrPreviousFormResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCompletedSteps(ApplicationEntity applicationEntity) {
|
||||||
|
Integer completedSteps=0;
|
||||||
|
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||||
|
List<ApplicationFormFieldEntity> applicationFormFieldEntities=new ArrayList<>();
|
||||||
|
for (ApplicationFormEntity applicationFormEntity:applicationFormList){
|
||||||
|
applicationFormFieldEntities=applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||||
|
Boolean isCompleted=formDao.validateCompletedSteps(applicationFormFieldEntities, applicationEntity, applicationFormEntity.getForm());
|
||||||
|
if(Boolean.TRUE.equals(isCompleted)){
|
||||||
|
completedSteps++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completedSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long calculateCurrentStep(List<FlowEdgesEntity> flowEdgesList, FormEntity formEntity) {
|
||||||
|
Long currentStep = 2l;
|
||||||
|
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
|
||||||
|
currentStep = 1l;
|
||||||
|
} else if (flowEdgesList.size()>1 && formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
|
||||||
|
currentStep = 3l;
|
||||||
|
}
|
||||||
|
return currentStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long calculateTotalSteps(List<FlowEdgesEntity> flowEdgesList) {
|
||||||
Long totalFormSteps = 3l;
|
Long totalFormSteps = 3l;
|
||||||
if (flowEdgesList.size() == 1) {
|
if (flowEdgesList.size() == 1) {
|
||||||
totalFormSteps = 2l;
|
totalFormSteps = 2l;
|
||||||
}
|
}
|
||||||
Long currentStep = 2l;
|
return totalFormSteps;
|
||||||
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
|
|
||||||
currentStep = 1l;
|
|
||||||
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
|
|
||||||
currentStep = 3l;
|
|
||||||
}
|
|
||||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
|
||||||
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
|
||||||
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
|
|
||||||
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
|
||||||
return nextOrPreviousFormResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
||||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
|
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
|
||||||
if(applicationFormList.isEmpty()) {
|
if (applicationFormList.isEmpty()) {
|
||||||
return applicationEntity.getCall().getInitialForm();
|
return applicationEntity.getCall().getInitialForm();
|
||||||
}
|
}
|
||||||
if(applicationFormList.get(applicationFormList.size()-1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
|
if (applicationFormList.get(applicationFormList.size() - 1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
|
||||||
return applicationEntity.getCall().getInitialForm();
|
return applicationEntity.getCall().getInitialForm();
|
||||||
}
|
}
|
||||||
return getNextForm(applicationFormList.get(applicationFormList.size()-1).getForm(), applicationEntity);
|
FormEntity currentFormEntity = applicationFormList.get(applicationFormList.size() - 1).getForm();
|
||||||
|
|
||||||
|
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
|
||||||
|
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
|
||||||
|
if (Boolean.FALSE.equals(isCompleted)) {
|
||||||
|
return applicationFormEntity.getForm().getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getNextForm(currentFormEntity, applicationEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,18 +6,17 @@ import net.gepafin.tendermanagement.entities.*;
|
|||||||
import net.gepafin.tendermanagement.model.request.*;
|
import net.gepafin.tendermanagement.model.request.*;
|
||||||
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.VatNumberResponseBean;
|
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.FieldValidator;
|
import net.gepafin.tendermanagement.util.FieldValidator;
|
||||||
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.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.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -32,9 +31,6 @@ public class FormDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FormRepository formRepository;
|
private FormRepository formRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CallService callService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationFormRepository applicationFormRepository;
|
private ApplicationFormRepository applicationFormRepository;
|
||||||
|
|
||||||
@@ -53,14 +49,16 @@ public class FormDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CallRepository callRepository;
|
private CallRepository callRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
public FormEntity saveFormEntity(FormEntity formEntity){
|
public FormEntity saveFormEntity(FormEntity formEntity){
|
||||||
formEntity=formRepository.save(formEntity);
|
formEntity=formRepository.save(formEntity);
|
||||||
return formEntity;
|
return formEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormEntity convertFormRequestToFormEntity(Long callId,FormRequest formRequest){
|
public FormEntity convertFormRequestToFormEntity(CallEntity callEntity, FormRequest formRequest){
|
||||||
FormEntity formEntity=new FormEntity();
|
FormEntity formEntity=new FormEntity();
|
||||||
CallEntity callEntity=callService.getCallEntityById(callId);
|
|
||||||
formEntity.setCall(callEntity);
|
formEntity.setCall(callEntity);
|
||||||
formEntity.setLabel(formRequest.getLabel());
|
formEntity.setLabel(formRequest.getLabel());
|
||||||
formEntity.setContent(setContentResponseBean(formRequest.getContent()));
|
formEntity.setContent(setContentResponseBean(formRequest.getContent()));
|
||||||
@@ -73,13 +71,13 @@ public class FormDao {
|
|||||||
formResponseBean.setContent(Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class));
|
formResponseBean.setContent(Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class));
|
||||||
formResponseBean.setLabel(formEntity.getLabel());
|
formResponseBean.setLabel(formEntity.getLabel());
|
||||||
formResponseBean.setCallId(formEntity.getCall().getId());
|
formResponseBean.setCallId(formEntity.getCall().getId());
|
||||||
|
formResponseBean.setCallStatus(formEntity.getCall().getStatus());
|
||||||
return formResponseBean;
|
return formResponseBean;
|
||||||
}
|
}
|
||||||
public FormResponseBean createForm(Long callId,FormRequest formRequest){
|
public FormResponseBean createForm(CallEntity callEntity,FormRequest formRequest){
|
||||||
validateForm(formRequest);
|
validateForm(formRequest);
|
||||||
CallEntity callEntity=callService.validateCall(callId);
|
List<FlowDataEntity> flowDataEntities=flowDataRepository.findByCallId(callEntity.getId());
|
||||||
List<FlowDataEntity> flowDataEntities=flowDataRepository.findByCallId(callId);
|
List<FlowEdgesEntity> flowEdgesEntities=flowEdgesRepository.findByCallId(callEntity.getId());
|
||||||
List<FlowEdgesEntity> flowEdgesEntities=flowEdgesRepository.findByCallId(callId);
|
|
||||||
if(Boolean.FALSE.equals(flowDataEntities.isEmpty() || flowDataEntities==null ) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty() || flowEdgesEntities==null) ){
|
if(Boolean.FALSE.equals(flowDataEntities.isEmpty() || flowDataEntities==null ) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty() || flowEdgesEntities==null) ){
|
||||||
flowDataRepository.deleteAll(flowDataEntities);
|
flowDataRepository.deleteAll(flowDataEntities);
|
||||||
flowEdgesRepository.deleteAll(flowEdgesEntities);
|
flowEdgesRepository.deleteAll(flowEdgesEntities);
|
||||||
@@ -87,7 +85,7 @@ public class FormDao {
|
|||||||
callEntity.setFinalForm(null);
|
callEntity.setFinalForm(null);
|
||||||
callRepository.save(callEntity);
|
callRepository.save(callEntity);
|
||||||
}
|
}
|
||||||
FormEntity formEntity=convertFormRequestToFormEntity(callId,formRequest);
|
FormEntity formEntity=convertFormRequestToFormEntity(callEntity, formRequest);
|
||||||
return convertFormEntityToFormResponseBean(formEntity);
|
return convertFormEntityToFormResponseBean(formEntity);
|
||||||
}
|
}
|
||||||
public void validateForm(FormRequest formRequest){
|
public void validateForm(FormRequest formRequest){
|
||||||
@@ -95,10 +93,11 @@ public class FormDao {
|
|||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public FormResponseBean updateForm(Long formId, FormRequest formRequest,Boolean forceDeleteFlow){
|
public FormResponseBean updateForm(UserEntity user, Long formId, FormRequest formRequest,Boolean forceDeleteFlow){
|
||||||
ContentRequestBean contentRequestBean2=null;
|
ContentRequestBean contentRequestBean2=null;
|
||||||
String choosenField=null;
|
String choosenField=null;
|
||||||
FormEntity formEntity = validateForm(formId);
|
FormEntity formEntity = validateForm(formId);
|
||||||
|
validator.validateUserWithCall(user, formEntity.getCall().getId());
|
||||||
callDao.validateUpdate(formEntity.getCall());
|
callDao.validateUpdate(formEntity.getCall());
|
||||||
List<ContentRequestBean> contentRequestBean = Utils.convertJsonStringToList(formEntity.getContent(), ContentRequestBean.class);
|
List<ContentRequestBean> contentRequestBean = Utils.convertJsonStringToList(formEntity.getContent(), ContentRequestBean.class);
|
||||||
for (ContentRequestBean contentRequestBean1 : contentRequestBean) {
|
for (ContentRequestBean contentRequestBean1 : contentRequestBean) {
|
||||||
@@ -140,6 +139,13 @@ public class FormDao {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Utils.setIfUpdated(formEntity::getLabel, formEntity::setLabel, formRequest.getLabel());
|
||||||
|
Utils.setIfUpdated(formEntity::getContent, formEntity::setContent, setContentResponseBean(formRequest.getContent()));
|
||||||
|
formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
formEntity = saveFormEntity(formEntity);
|
||||||
|
return convertFormEntityToFormResponseBean(formEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,12 +168,14 @@ public class FormDao {
|
|||||||
return formEntity;
|
return formEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormResponseBean getFormEntityById(Long formId) {
|
public FormResponseBean getFormEntityById(UserEntity user, Long formId) {
|
||||||
FormEntity formEntity = validateForm(formId);
|
FormEntity formEntity = validateForm(formId);
|
||||||
|
validator.validateUserWithCall(user, formEntity.getCall().getId());
|
||||||
return convertFormEntityToFormResponseBean(formEntity);
|
return convertFormEntityToFormResponseBean(formEntity);
|
||||||
}
|
}
|
||||||
public void deleteFormById(Long formId){
|
public void deleteFormById(UserEntity user, Long formId){
|
||||||
FormEntity formEntity = validateForm(formId);
|
FormEntity formEntity = validateForm(formId);
|
||||||
|
validator.validateUserWithCall(user, formEntity.getCall().getId());
|
||||||
List<FlowDataEntity> flowDataEntities=flowDataRepository.findByCallId(formEntity.getCall().getId());
|
List<FlowDataEntity> flowDataEntities=flowDataRepository.findByCallId(formEntity.getCall().getId());
|
||||||
List<FlowEdgesEntity> flowEdgesEntities=flowEdgesRepository.findByCallId(formEntity.getCall().getId());
|
List<FlowEdgesEntity> flowEdgesEntities=flowEdgesRepository.findByCallId(formEntity.getCall().getId());
|
||||||
flowDataRepository.deleteAll(flowDataEntities);
|
flowDataRepository.deleteAll(flowDataEntities);
|
||||||
@@ -178,13 +186,12 @@ public class FormDao {
|
|||||||
callRepository.save(callEntity);
|
callRepository.save(callEntity);
|
||||||
formRepository.delete(formEntity);
|
formRepository.delete(formEntity);
|
||||||
}
|
}
|
||||||
public List<FormResponseBean> getFormsByCallId(Long callId){
|
public List<FormResponseBean> getFormsByCallId(CallEntity callEntity){
|
||||||
CallEntity callEntity=callService.validateCall(callId);
|
|
||||||
if(callEntity== null){
|
if(callEntity== null){
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
|
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
|
||||||
}
|
}
|
||||||
List<FormEntity> formEntities=formRepository.findByCallId(callId);
|
List<FormEntity> formEntities=formRepository.findByCallId(callEntity.getId());
|
||||||
List<FormResponseBean> formResponseBeanList = formEntities.stream()
|
List<FormResponseBean> formResponseBeanList = formEntities.stream()
|
||||||
.map(req -> convertFormEntityToFormResponseBean(req))
|
.map(req -> convertFormEntityToFormResponseBean(req))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -197,8 +204,12 @@ public class FormDao {
|
|||||||
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
||||||
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
||||||
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
|
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
|
||||||
formFieldMap.put(applicationFormFieldRequestBean.getFieldId(),applicationFormFieldRequestBean.getFieldValue());
|
if(applicationFormFieldRequestBean.getFieldValue()==null )
|
||||||
}
|
continue;
|
||||||
|
if (applicationFormFieldRequestBean.getFieldValue() != null ) {
|
||||||
|
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||||
|
checkObjectData(applicationFormFieldRequestBean.getFieldId(), fieldValue, formFieldMap);
|
||||||
|
}}
|
||||||
|
|
||||||
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
|
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
|
||||||
ApplicationFormEntity applicationFormEntity=applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formEntity.getId());
|
ApplicationFormEntity applicationFormEntity=applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formEntity.getId());
|
||||||
@@ -207,19 +218,19 @@ public class FormDao {
|
|||||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||||
String fieldId = contentResponseBean.getId();
|
String fieldId = contentResponseBean.getId();
|
||||||
String value = (String) formFieldMap.get(fieldId);
|
String value = (String) formFieldMap.get(fieldId);
|
||||||
|
String fieldLabel=contentResponseBean.getLabel();
|
||||||
|
|
||||||
if(value == null && isApplicationFormExist) {
|
if(value == null && isApplicationFormExist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||||
validator
|
validator
|
||||||
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId)
|
.minLength(value, fieldValidatorBean.getMinLength(), fieldLabel) // Only applies if minLength is not null
|
||||||
.minLength(value, fieldValidatorBean.getMinLength(), fieldId) // Only applies if minLength is not null
|
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldLabel) // Only applies if maxLength is not null
|
||||||
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldId) // Only applies if maxLength is not null
|
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldLabel) // Only applies if pattern is present
|
||||||
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldId) // Only applies if pattern is present
|
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel); // Add the custom validation here
|
||||||
.validateCustom(value, fieldValidatorBean.getCustom(), fieldId); // Add the custom validation here
|
|
||||||
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
||||||
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldId);
|
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldLabel);
|
||||||
if(error != null) {
|
if(error != null) {
|
||||||
validator.addError(error);
|
validator.addError(error);
|
||||||
}
|
}
|
||||||
@@ -228,6 +239,28 @@ public class FormDao {
|
|||||||
validator.validate();
|
validator.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkObjectData(String fieldId, Object fieldValue, Map<String, Object> formFieldMap) {
|
||||||
|
if (fieldValue instanceof List<?>) {
|
||||||
|
List<?> list = (List<?>) fieldValue;
|
||||||
|
|
||||||
|
// Only map if the list is not empty and contains Strings
|
||||||
|
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||||
|
for (Object value : list) {
|
||||||
|
setFormFieldMap(fieldId, formFieldMap, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else setFormFieldMap(fieldId, formFieldMap, fieldValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFormFieldMap(String fieldId, Map<String, Object> formFieldMap, Object value) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
if(value !=null && Boolean.FALSE.equals(StringUtils.isEmpty((String)value))) {
|
||||||
|
formFieldMap.put(fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Boolean getApplicationFormExist(ApplicationFormEntity applicationFormEntity) {
|
private Boolean getApplicationFormExist(ApplicationFormEntity applicationFormEntity) {
|
||||||
if(applicationFormEntity !=null) {
|
if(applicationFormEntity !=null) {
|
||||||
return true;
|
return true;
|
||||||
@@ -235,19 +268,43 @@ public class FormDao {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean validateCompletedSteps(List<ApplicationFormFieldEntity> applicationFormFieldEntityList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
||||||
|
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
||||||
|
for(ApplicationFormFieldEntity applicationFormFieldEntity:applicationFormFieldEntityList) {
|
||||||
|
formFieldMap.put(applicationFormFieldEntity.getFieldId(),applicationFormFieldEntity.getFieldValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
|
||||||
|
FieldValidator validator = FieldValidator.create();
|
||||||
|
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||||
|
String fieldId = contentResponseBean.getId();
|
||||||
|
String value = (String) formFieldMap.get(fieldId);
|
||||||
|
|
||||||
|
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||||
|
validator
|
||||||
|
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId);
|
||||||
|
});
|
||||||
|
if (validator.hasErrors()) {
|
||||||
|
return false; // Validation failed, return false
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public String validateVatNumber(String value,String customRule,String fieldId){
|
public String validateVatNumber(String value,String customRule,String fieldId){
|
||||||
String error=null;
|
String error=null;
|
||||||
if (value.matches("^\\d{1,11}$")) {
|
|
||||||
Map<String, Object> customData=null;
|
if (value!=null && value.matches("^\\d{1,11}$")) {
|
||||||
|
// Map<String, Object> customData=null;
|
||||||
try {
|
try {
|
||||||
Map<String, Object> vatCheckResponse = vatCheckDao.checkVatNumberApi(value);
|
// Map<String, Object> vatCheckResponse = vatCheckDao.checkVatNumberApi(value);
|
||||||
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(vatCheckResponse))) {
|
vatCheckDao.checkVatNumberApi(value);
|
||||||
customData = vatCheckResponse;
|
// if (Boolean.FALSE.equals(CollectionUtils.isEmpty(vatCheckResponse))) {
|
||||||
}
|
// customData = vatCheckResponse;
|
||||||
|
// }
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error=(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_VALID_PIVA), fieldId));
|
error=(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_VALID_PIVA), fieldId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.response.LoginAttemptPageableResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.LoginAttemptRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class LoginAttemptDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
LoginAttemptRepository loginAttemptRepository;
|
||||||
|
|
||||||
|
public void createLoginAttempt(LoginAttemptEntity loginAttemptEntity) {
|
||||||
|
loginAttemptEntity.setAttemptDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
|
||||||
|
loginAttemptRepository.save(loginAttemptEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> getLoginAttemptsList(Integer pageNo, Integer pageLimit) {
|
||||||
|
if (pageLimit == null || pageLimit <= 0) {
|
||||||
|
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageNo == null || pageNo <= 0) {
|
||||||
|
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page<LoginAttemptEntity> page = loginAttemptRepository.findAll(PageRequest.of(pageNo - 1, pageLimit, Sort.by(GepafinConstant.ATTEMPT_DATE).descending()));
|
||||||
|
List<LoginAttemptEntity> list = new ArrayList<>();
|
||||||
|
for (LoginAttemptEntity loginAttemptEntity : page.getContent()) {
|
||||||
|
list.add(loginAttemptEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> pageableResponseBean = new LoginAttemptPageableResponseBean<>();
|
||||||
|
pageableResponseBean.setBody(list);
|
||||||
|
pageableResponseBean.setCurrentPage(page.getNumber() + 1);
|
||||||
|
pageableResponseBean.setTotalPages(page.getTotalPages());
|
||||||
|
pageableResponseBean.setTotalRecords(page.getTotalElements());
|
||||||
|
pageableResponseBean.setPageSize(page.getSize());
|
||||||
|
pageableResponseBean.setStatus(Status.SUCCESS);
|
||||||
|
pageableResponseBean.setMessage(Translator.toLocale(GepafinConstant.GET_LOGIN_ATTEMPT_MSG));
|
||||||
|
return pageableResponseBean;
|
||||||
|
}
|
||||||
|
}
|
||||||
640
src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java
Normal file
640
src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java
Normal file
@@ -0,0 +1,640 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.itextpdf.kernel.colors.ColorConstants;
|
||||||
|
import com.itextpdf.kernel.colors.DeviceRgb;
|
||||||
|
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
|
||||||
|
import com.itextpdf.layout.properties.UnitValue;
|
||||||
|
import com.itextpdf.layout.renderer.CellRenderer;
|
||||||
|
import com.itextpdf.layout.renderer.DrawContext;
|
||||||
|
import com.itextpdf.text.*;
|
||||||
|
import com.itextpdf.text.Element;
|
||||||
|
import com.itextpdf.text.Font;
|
||||||
|
import com.itextpdf.text.Image;
|
||||||
|
import com.itextpdf.text.Rectangle;
|
||||||
|
import com.itextpdf.text.pdf.*;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
|
import net.gepafin.tendermanagement.model.request.CustomPageEvent;
|
||||||
|
import net.gepafin.tendermanagement.model.request.FieldLabelValuePairRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.itextpdf.layout.element.Table;
|
||||||
|
import com.itextpdf.layout.element.Cell;
|
||||||
|
//import com.itextpdf.layout.element.
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PdfDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CallService callService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationDao applicationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
|
|
||||||
|
public byte[] generatePdf(HttpServletRequest request,Long applicationId) {
|
||||||
|
try {
|
||||||
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
|
ApplicationEntity applicationEntity = applicationDao.validateApplication(applicationId);
|
||||||
|
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
||||||
|
CallEntity call=callService.validateCall(applicationEntity.getCall().getId());
|
||||||
|
|
||||||
|
// Create a byte stream to hold the PDF
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
float leftMargin = 50f; // Adjust this for the left margin
|
||||||
|
|
||||||
|
Document document = new Document(PageSize.A4, leftMargin, 36f, 50f, 35);
|
||||||
|
PdfWriter writer = PdfWriter.getInstance(document, out);
|
||||||
|
// CustomPageEvent pageEvent = new CustomPageEvent(call.getName(), 0);
|
||||||
|
// writer.setPageEvent(pageEvent);
|
||||||
|
document.open();
|
||||||
|
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
|
addLogo(document, "https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/logo.jpg"); // Add your image path here
|
||||||
|
|
||||||
|
|
||||||
|
BaseColor customColor = new BaseColor(0, 128, 0); // Adjust RGB values as needed
|
||||||
|
// Define fonts and styles
|
||||||
|
BaseColor greenColor = new BaseColor(0, 128, 0); // Adjust RGB values as needed
|
||||||
|
BaseColor darkGreenColor = new BaseColor(1, 50, 32); // Adjust RGB values as needed
|
||||||
|
Font titleFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, customColor);
|
||||||
|
Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12,darkGreenColor);
|
||||||
|
Font labelFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12,new BaseColor(113,121,126)); // Light grey);
|
||||||
|
Font smallFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8,new BaseColor(105, 105, 105));
|
||||||
|
Font valueFont=FontFactory.getFont(FontFactory.HELVETICA_BOLD,10,new BaseColor(178, 190, 181));
|
||||||
|
Paragraph title = new Paragraph(call.getName(), titleFont);
|
||||||
|
title.setAlignment(Element.ALIGN_LEFT);
|
||||||
|
document.add(title);
|
||||||
|
|
||||||
|
BaseColor greyColor=new BaseColor(178, 190, 181); // Very light grey color
|
||||||
|
addColoredLines(writer,document,greyColor);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
// Application ID section (Centered)
|
||||||
|
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
|
String protocolNumber="XX00";
|
||||||
|
if(applicationEntity.getProtocol()!=null) {
|
||||||
|
protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
|
Paragraph appId = new Paragraph("ID domanda :" +protocolNumber);
|
||||||
|
appId.setAlignment(Element.ALIGN_RIGHT);
|
||||||
|
document.add(appId);
|
||||||
|
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
addColoredLines(writer,document,greenColor);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
document.add(new Paragraph("\n")); // Add line break
|
||||||
|
// String companyName= companyEntity.getCompanyName();
|
||||||
|
// String vatNumber=companyEntity.getVatNumber();
|
||||||
|
// String address=companyEntity.getAddress();
|
||||||
|
// // Section: Dati Anagrafici Azienda
|
||||||
|
// document.add(new Paragraph("Dati Anagrafici Azienda", sectionFont));
|
||||||
|
// addLabelValuePair(document, "Codice ATECO", "SEZIONE C “ATTIVITÀ MANUFATTURIERE”", regularFont);
|
||||||
|
// addLabelValuePair(document, "Ragione Sociale", companyName, regularFont);
|
||||||
|
// addLabelValuePair(document, "Partita IVA", vatNumber, regularFont);
|
||||||
|
// addLabelValuePair(document, "Indirizzo sede Legale", address, regularFont);
|
||||||
|
//
|
||||||
|
// document.add(new Paragraph("\n")); // Add line break
|
||||||
|
//
|
||||||
|
// // Section: Domanda presentata da
|
||||||
|
// document.add(new Paragraph("Domanda presentata da:", sectionFont));
|
||||||
|
// addLabelValuePair(document, "Nome e cognome", userEntity.getBeneficiary().getFirstName()+" "+userEntity.getBeneficiary().getLastName(), regularFont);
|
||||||
|
// addLabelValuePair(document, "Codice fiscale", userEntity.getBeneficiary().getCodiceFiscale(), regularFont);
|
||||||
|
// addLabelValuePair(document, "Telefono", userEntity.getBeneficiary().getPhoneNumber(), regularFont);
|
||||||
|
// addLabelValuePair(document, "Email", userEntity.getBeneficiary().getEmail(), regularFont);
|
||||||
|
// addLabelValuePair(document, "Con il titolo di", "Rappresentante legale", regularFont);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
ApplicationGetResponseBean applicationGetResponseBean=applicationDao.getApplicationByFormId(applicationId,null, userEntity);
|
||||||
|
for(FormApplicationResponse formApplicationResponse: applicationGetResponseBean.getForm()) {
|
||||||
|
document.add(new Paragraph(formApplicationResponse.getLabel(),sectionFont));
|
||||||
|
document.add(new Paragraph(" ")); // Add line break
|
||||||
|
List<FieldLabelValuePairRequest> fieldLabelValuePairRequests = getFormFieldsToLabels(formApplicationResponse);
|
||||||
|
for (FieldLabelValuePairRequest pair : fieldLabelValuePairRequests) {
|
||||||
|
String label = pair.getLabel();
|
||||||
|
Object value = pair.getValue();
|
||||||
|
Integer pages=0;
|
||||||
|
pages=addLabelValuePair(writer,document, label, value, labelFont,valueFont,call.getName(),pages);
|
||||||
|
if(pages !=0 ){
|
||||||
|
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addColoredLines(writer,document,greenColor);
|
||||||
|
document.add(new Paragraph(" ")); // Add line break
|
||||||
|
}
|
||||||
|
document.add(new Paragraph("\n")); // Add line break
|
||||||
|
Font boldSmallFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD,new BaseColor(105, 105, 105));
|
||||||
|
|
||||||
|
// Adding the "Documenti Allegati" section title
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
|
document.newPage();
|
||||||
|
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
|
document.add(new Paragraph("Documenti Allegati", sectionFont));
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 1. Autocertificazione possesso Requisiti
|
||||||
|
Paragraph p1 = new Paragraph();
|
||||||
|
p1.add(new Chunk("1. ", boldSmallFont));
|
||||||
|
p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
|
||||||
|
p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
|
||||||
|
document.add(p1);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 2. Informativa Privacy relativa al trattamento dei dati personali
|
||||||
|
Paragraph p2 = new Paragraph();
|
||||||
|
p2.add(new Chunk("2. ", boldSmallFont));
|
||||||
|
p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
|
||||||
|
document.add(p2);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 3. Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari
|
||||||
|
Paragraph p3 = new Paragraph();
|
||||||
|
p3.add(new Chunk("3. ", boldSmallFont));
|
||||||
|
p3.add(new Chunk("Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari prospettici come da tabella di cui all’Appendice 9", boldSmallFont));
|
||||||
|
document.add(p3);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 4. Rilevazione Centrale dei Rischi
|
||||||
|
Paragraph p4 = new Paragraph();
|
||||||
|
p4.add(new Chunk("4. ", boldSmallFont));
|
||||||
|
p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
|
||||||
|
document.add(p4);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 5. Schema di presentazione dei dati di bilancio
|
||||||
|
Paragraph p5 = new Paragraph();
|
||||||
|
p5.add(new Chunk("5. ", boldSmallFont));
|
||||||
|
p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
|
||||||
|
document.add(p5);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 6. Dettagli bilanci in forma abbreviata
|
||||||
|
Paragraph p6 = new Paragraph();
|
||||||
|
p6.add(new Chunk("6. ", boldSmallFont));
|
||||||
|
p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
|
||||||
|
document.add(p6);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
|
||||||
|
// 7. Relazione aziendale illustrativa
|
||||||
|
Paragraph p7 = new Paragraph();
|
||||||
|
p7.add(new Chunk("7. ", boldSmallFont));
|
||||||
|
p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
|
||||||
|
document.add(p7);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
addColoredLines(writer,document,greenColor);
|
||||||
|
|
||||||
|
// System.out.println(writer.getPageSize());
|
||||||
|
// System.out.println(document.getPageSize());
|
||||||
|
// System.out.println(document.getPageNumber());
|
||||||
|
// System.out.println(writer.getPageNumber());
|
||||||
|
// document.setPageCount(100);
|
||||||
|
// document.setPageCount(writer.getPageNumber());
|
||||||
|
// System.out.println(document.getPageNumber());
|
||||||
|
|
||||||
|
// Close the document
|
||||||
|
document.close();
|
||||||
|
|
||||||
|
// Convert to byte array for response
|
||||||
|
byte[] pdfBytes =PdfPageNumberInserter.addPageNumbers(out.toByteArray());
|
||||||
|
|
||||||
|
return pdfBytes;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer addLabelValuePair(PdfWriter writer,Document document, String label, Object value, Font labelFont,Font valueFont,String title,Integer totalPages) throws DocumentException {
|
||||||
|
// Add label
|
||||||
|
Paragraph labelParagraph = new Paragraph(label, labelFont);
|
||||||
|
document.add(labelParagraph);
|
||||||
|
float leftMargin = 20f;
|
||||||
|
|
||||||
|
PdfContentByte canvas = writer.getDirectContent();
|
||||||
|
|
||||||
|
// Setting the color and width of the line
|
||||||
|
float lineWidth = 1.0f; // Thickness of the line
|
||||||
|
canvas.setLineWidth(lineWidth);
|
||||||
|
|
||||||
|
// Get the current vertical position in the document
|
||||||
|
float yPos = writer.getVerticalPosition(true) - 10f; // Adjust this to move line slightly below current content
|
||||||
|
|
||||||
|
// Define start and end points for the line (relative to the page size and margins)
|
||||||
|
|
||||||
|
if (yPos <= 140) {
|
||||||
|
// If xEnd is less than or equal to 200, generate a new page
|
||||||
|
|
||||||
|
totalPages++;
|
||||||
|
document.newPage();
|
||||||
|
} // Add a gap between the label and value
|
||||||
|
document.add(new Paragraph(" ")); // Adding an empty paragraph for spacing
|
||||||
|
// Create value cell with rounded corners
|
||||||
|
PdfPTable valueTable = new PdfPTable(1);
|
||||||
|
valueTable.setWidthPercentage(100);
|
||||||
|
if (value instanceof List<?>) {
|
||||||
|
// Further check if the list contains Strings
|
||||||
|
List<?> list = (List<?>) value;
|
||||||
|
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||||
|
// Cast to List<String>
|
||||||
|
List<String> values = (List<String>) value;
|
||||||
|
|
||||||
|
// Loop through the list of strings and create a cell for each string
|
||||||
|
for (String item : values) {
|
||||||
|
PdfPCell valueCell = new PdfPCell(new Phrase(item, valueFont));
|
||||||
|
valueCell.setPadding(5f); // Increase padding for better spacing
|
||||||
|
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
||||||
|
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
||||||
|
valueCell.setMinimumHeight(30f);
|
||||||
|
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
||||||
|
|
||||||
|
// Add the cell to the table
|
||||||
|
valueTable.addCell(valueCell);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, add the table to the document
|
||||||
|
document.add(valueTable);
|
||||||
|
} else {
|
||||||
|
boolean containsThreeValues = false; // Variable to track if any map contains three keys
|
||||||
|
List<Map<String, Object>> dataList = (List<Map<String, Object>>) value; // Cast Object to List of Maps
|
||||||
|
for (Map<String, Object> entry : dataList) {
|
||||||
|
if (entry.size() == 3) { // Check if the current map has three keys
|
||||||
|
containsThreeValues = true; // If found, set the variable to true
|
||||||
|
break; // No need to check further, exit loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Map<String, String>> extractedData = new ArrayList<>(); // To hold extracted data
|
||||||
|
for (Map<String, Object> entry : dataList) {
|
||||||
|
Map<String, String> extractedMap = new HashMap<>(); // To hold the current extracted row of data
|
||||||
|
|
||||||
|
List<String> keys = new ArrayList<>(entry.keySet()); // Get all keys in the current map
|
||||||
|
|
||||||
|
// Handle based on the number of keys in the map
|
||||||
|
if (Boolean.FALSE.equals(containsThreeValues) && keys.size() == 2) {
|
||||||
|
// Treat the first key as the "key" and second key as the "value"
|
||||||
|
String heading = (String) entry.get(keys.get(0)); // Get value of first key
|
||||||
|
String value1 = (String) entry.get(keys.get(1)); // Get value of second key
|
||||||
|
extractedMap.put(heading,value1); // Store the first key's value as "heading"
|
||||||
|
} if (Boolean.TRUE.equals(containsThreeValues) ) {
|
||||||
|
String amount="";
|
||||||
|
// Treat the first as number, second as description, third as amount
|
||||||
|
if(keys.size()==3){
|
||||||
|
amount = (String) entry.get(keys.get(2)); // Third key's value
|
||||||
|
}
|
||||||
|
String number = (String) entry.get(keys.get(0)); // First key's value
|
||||||
|
String description = (String) entry.get(keys.get(1)); // Second key's value
|
||||||
|
|
||||||
|
// Store the combined result as a value in the map, with a suitable key
|
||||||
|
String combinedValue = number + "; " + description + "; " + amount; // Concatenate them as a single value
|
||||||
|
extractedMap.put("combined", combinedValue); // Store as a single entry, key as "combined"
|
||||||
|
}
|
||||||
|
|
||||||
|
extractedData.add(extractedMap); // Add each extracted map to the list
|
||||||
|
}
|
||||||
|
document=createPdfTable(extractedData,document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PdfPCell valueCell = new PdfPCell(new Phrase(String.valueOf(value), valueFont));
|
||||||
|
valueCell.setPadding(5f); // Increase padding for better spacing
|
||||||
|
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
||||||
|
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
||||||
|
valueCell.setMinimumHeight(30f);
|
||||||
|
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
||||||
|
|
||||||
|
valueTable.addCell(valueCell);
|
||||||
|
document.add(valueTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.add(new Paragraph("\n")); // Add line break after each value
|
||||||
|
return totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document createPdfTable(List<Map<String, String>> extractedData,Document document) throws DocumentException {
|
||||||
|
// Create a PdfPTable with 2 columns
|
||||||
|
PdfPTable table = new PdfPTable(2); // Initial assumption for 2 columns
|
||||||
|
table.setWidthPercentage(100); // Set table width to 100%
|
||||||
|
table.setTableEvent(new RoundedBorderEvent());
|
||||||
|
Font textFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(105, 105, 105)); // Gray text
|
||||||
|
boolean combinedHeaderAdded = false; // Flag to track if headers for combined have been added
|
||||||
|
float rowHeight = 50f; // Example row height, adjust as necessary
|
||||||
|
float maxTableHeight = 700f; // Maximum height of the table before a page break
|
||||||
|
float[] columnWidths = {0.7f, 0.3f};
|
||||||
|
table.setWidths(columnWidths);
|
||||||
|
|
||||||
|
|
||||||
|
// Add table header
|
||||||
|
// Populate the table with extracted data and style rows
|
||||||
|
for (Map<String, String> row : extractedData) {
|
||||||
|
for (Map.Entry<String, String> entry : row.entrySet()) {
|
||||||
|
String key = entry.getKey(); // This will give you the key
|
||||||
|
String value = entry.getValue(); // This will give you the value
|
||||||
|
|
||||||
|
// Check if the current entry is for the combined section
|
||||||
|
if ("combined".equals(key)) {
|
||||||
|
// Ensure the combined header is added only once
|
||||||
|
if (!combinedHeaderAdded) {
|
||||||
|
// Create a new table for combined entries
|
||||||
|
table = new PdfPTable(3); // 3 columns for combined entries
|
||||||
|
|
||||||
|
PdfPCell headerCell1 = new PdfPCell(new Phrase("Number"));
|
||||||
|
headerCell1.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
|
headerCell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell1.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
table.addCell(headerCell1);
|
||||||
|
|
||||||
|
PdfPCell headerCell2 = new PdfPCell(new Phrase("Details"));
|
||||||
|
headerCell2.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
|
headerCell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell2.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
table.addCell(headerCell2);
|
||||||
|
|
||||||
|
PdfPCell headerCell3 = new PdfPCell(new Phrase("Amount"));
|
||||||
|
headerCell3.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
|
headerCell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell3.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
table.addCell(headerCell3);
|
||||||
|
|
||||||
|
combinedHeaderAdded = true; // Mark header as added
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the value for "combined" into separate parts
|
||||||
|
String[] combinedValues = value.split("; ");
|
||||||
|
|
||||||
|
// Check if we have 3 parts (number, description, amount)
|
||||||
|
String number = combinedValues[0]; // 1st part (number)
|
||||||
|
String description = combinedValues[1]; // 2nd part (description)
|
||||||
|
String amount = "";
|
||||||
|
if (combinedValues.length == 3) {
|
||||||
|
amount = combinedValues[2]; // 3rd part (amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create PDF cells using the split values
|
||||||
|
PdfPCell cellNumber = new PdfPCell(new Phrase(number, textFont)); // Cell for number
|
||||||
|
PdfPCell cellDescription = new PdfPCell(new Phrase(description, textFont)); // Cell for description
|
||||||
|
PdfPCell cellAmount = new PdfPCell(new Phrase(amount, textFont)); // Cell for amount
|
||||||
|
|
||||||
|
// Set row background color for combined values
|
||||||
|
cellNumber.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for combined rows
|
||||||
|
cellDescription.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||||
|
cellAmount.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||||
|
|
||||||
|
// Set cell height and add rounded borders
|
||||||
|
// cellNumber.setFixedHeight(rowHeight);
|
||||||
|
// cellDescription.setFixedHeight(rowHeight);
|
||||||
|
// cellAmount.setFixedHeight(rowHeight);
|
||||||
|
|
||||||
|
cellNumber.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||||
|
cellDescription.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||||
|
cellAmount.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||||
|
|
||||||
|
cellNumber.setPadding(7f);
|
||||||
|
cellDescription.setPadding(7f);
|
||||||
|
cellAmount.setPadding(7f);
|
||||||
|
|
||||||
|
// Add the cells to the table only once
|
||||||
|
table.addCell(cellNumber);
|
||||||
|
table.addCell(cellDescription);
|
||||||
|
table.addCell(cellAmount);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!combinedHeaderAdded) {
|
||||||
|
// Create a new table for combined entries
|
||||||
|
table= new PdfPTable(2); // 3 columns for combined entries
|
||||||
|
table.setWidthPercentage(100);
|
||||||
|
|
||||||
|
PdfPCell headerCell1 = new PdfPCell(new Phrase("Details"));
|
||||||
|
headerCell1.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
|
headerCell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell1.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
table.addCell(headerCell1);
|
||||||
|
|
||||||
|
PdfPCell headerCell2 = new PdfPCell(new Phrase("Amount"));
|
||||||
|
headerCell2.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
|
headerCell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell2.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
table.addCell(headerCell2);
|
||||||
|
combinedHeaderAdded=true;
|
||||||
|
}
|
||||||
|
// Add cells for regular key-value pairs without headers
|
||||||
|
PdfPCell cellKey = new PdfPCell(new Phrase(key, textFont));
|
||||||
|
PdfPCell cellValue = new PdfPCell(new Phrase(value, textFont));
|
||||||
|
|
||||||
|
// Set background color for both cells
|
||||||
|
cellKey.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for other rows
|
||||||
|
cellValue.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||||
|
|
||||||
|
cellKey.setPadding(7f);
|
||||||
|
cellValue.setPadding(7f);
|
||||||
|
// Set cell height and add rounded borders
|
||||||
|
cellKey.setFixedHeight(rowHeight);
|
||||||
|
cellValue.setFixedHeight(rowHeight);
|
||||||
|
|
||||||
|
// Add the cells to the table
|
||||||
|
table.addCell(cellKey);
|
||||||
|
table.addCell(cellValue);
|
||||||
|
}
|
||||||
|
if (table.getTotalHeight() + rowHeight > maxTableHeight) {
|
||||||
|
// Start a new page if needed
|
||||||
|
document.add(table);
|
||||||
|
table = new PdfPTable(2); // Reset table for new page
|
||||||
|
table.setWidthPercentage(100); // Reset width percentage
|
||||||
|
combinedHeaderAdded = false; // Reset header flag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.add(table); // Add the last table before returning
|
||||||
|
|
||||||
|
|
||||||
|
// Check if adding a new row would exceed the maximum height
|
||||||
|
// Return the populated table
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
public static class RoundedBorderEvent implements PdfPTableEvent {
|
||||||
|
@Override
|
||||||
|
public void tableLayout(PdfPTable table, float[][] widths, float[] heights,
|
||||||
|
int headerRows, int rowStart, PdfContentByte[] canvases) {
|
||||||
|
PdfContentByte canvas = canvases[PdfPTable.BASECANVAS];
|
||||||
|
|
||||||
|
// Get the table boundaries
|
||||||
|
float left = widths[0][0];
|
||||||
|
float right = widths[0][widths[0].length - 1];
|
||||||
|
float top = heights[0];
|
||||||
|
float bottom = heights[heights.length - 1];
|
||||||
|
|
||||||
|
// Define the corner radius
|
||||||
|
float radius = 20f;
|
||||||
|
|
||||||
|
// Draw a rounded rectangle around the table
|
||||||
|
canvas.roundRectangle(left, bottom, right - left, top - bottom, radius);
|
||||||
|
canvas.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<FieldLabelValuePairRequest> getFormFieldsToLabels(FormApplicationResponse responseBean) {
|
||||||
|
List<FieldLabelValuePairRequest> labelValuePairs = new ArrayList<>();
|
||||||
|
|
||||||
|
// Iterate through each form in the application response
|
||||||
|
|
||||||
|
List<ApplicationFormFieldResponseBean> formFields = responseBean.getFormFields();
|
||||||
|
List<ContentResponseBean> contents = responseBean.getContent();
|
||||||
|
|
||||||
|
// Iterate through each formField in the current form
|
||||||
|
for (ApplicationFormFieldResponseBean formField : formFields) {
|
||||||
|
String fieldId = formField.getFieldId();
|
||||||
|
Object fieldValue = formField.getFieldValue();
|
||||||
|
|
||||||
|
// Find the content in the form that matches the fieldId
|
||||||
|
Optional<ContentResponseBean> matchingContent = contents.stream()
|
||||||
|
.filter(content -> content.getId().equals(fieldId))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
|
||||||
|
// If the content with the matching fieldId is found, create a label-value pair
|
||||||
|
if (matchingContent.isPresent()) {
|
||||||
|
String name = matchingContent.get().getName();
|
||||||
|
if (name.equals("fileupload")) {
|
||||||
|
|
||||||
|
// Step 1: Check if fieldValue is an instance of List<DocumentResponseBean>
|
||||||
|
if (fieldValue instanceof List<?> && ((List<?>) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) {
|
||||||
|
// Step 2: Safely cast to List<DocumentResponseBean>
|
||||||
|
List<DocumentResponseBean> documentList = (List<DocumentResponseBean>) fieldValue;
|
||||||
|
|
||||||
|
// Step 3: Extract names from the document list
|
||||||
|
List<String> names = documentList.stream()
|
||||||
|
.map(DocumentResponseBean::getName) // Extract the name from each DocumentResponseBean
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
fieldValue=names;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(name.equals("checkboxes")) {
|
||||||
|
List<String> check = (List<String>) fieldValue;
|
||||||
|
List<SettingResponseBean> settingResponseBeans = matchingContent.get().getSettings();
|
||||||
|
for (SettingResponseBean settingResponseBean : settingResponseBeans) {
|
||||||
|
// Initialize a list to hold matched labels for each SettingResponseBean
|
||||||
|
List<String> matchedLabels = new ArrayList<>();
|
||||||
|
if (settingResponseBean.getValue() instanceof List<?>) {
|
||||||
|
|
||||||
|
List<?> valueList = (List<?>) settingResponseBean.getValue();
|
||||||
|
if (!valueList.isEmpty() && valueList.get(0) instanceof Map<?, ?>) {
|
||||||
|
// Cast to List<Map<String, String>>
|
||||||
|
List<Map<String, String>> options = (List<Map<String, String>>) valueList;
|
||||||
|
for (Map<String, String> field : options) {
|
||||||
|
for (String val : check) {
|
||||||
|
String name1=field.get("name");
|
||||||
|
if (val.equals(name1)) { // Check if the key exists in the current field map
|
||||||
|
String label = field.get("label"); // Extract the label
|
||||||
|
if (field != null) { // Check if the value is not null
|
||||||
|
matchedLabels.add(label); // Add the value to the matchedValues list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldValue = matchedLabels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String label = matchingContent.get().getLabel();
|
||||||
|
// Add the label-value pair to the list
|
||||||
|
if (fieldValue != null && !fieldValue.toString().trim().isEmpty()) {
|
||||||
|
fieldValue = findLabelInOptions(matchingContent.get().getSettings(), fieldValue);
|
||||||
|
labelValuePairs.add(new FieldLabelValuePairRequest(label, fieldValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return labelValuePairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object findLabelInOptions(List<SettingResponseBean> settings, Object valueToFind) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (valueToFind instanceof String) {
|
||||||
|
String searchValue = (String) valueToFind;
|
||||||
|
for (SettingResponseBean setting : settings) {
|
||||||
|
Object value = setting.getValue();
|
||||||
|
if (value instanceof List) {
|
||||||
|
List<?> options = (List<?>) value;
|
||||||
|
for (Object option : options) {
|
||||||
|
JsonNode optionNode = objectMapper.convertValue(option, JsonNode.class);
|
||||||
|
if (optionNode.get("name").asText().equals(searchValue)) {
|
||||||
|
return optionNode.get("label").asText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return valueToFind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLogo(Document document, String logoPath) throws Exception {
|
||||||
|
Image logo = Image.getInstance(logoPath);
|
||||||
|
logo.scaleToFit(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), // Fit to document width
|
||||||
|
document.getPageSize().getHeight() / 4); // Adjust the height as needed (1/4th of the page height)
|
||||||
|
logo.setAlignment(Image.ALIGN_CENTER); // Align logo to center
|
||||||
|
document.add(logo);
|
||||||
|
|
||||||
|
// Add some space after logo
|
||||||
|
document.add(new Paragraph("\n")); // Adding space after the logo
|
||||||
|
}
|
||||||
|
public void addColoredLines(PdfWriter writer, Document document, BaseColor color){
|
||||||
|
PdfContentByte canvas = writer.getDirectContent();
|
||||||
|
|
||||||
|
// Setting the color and width of the line
|
||||||
|
canvas.setColorStroke(color);
|
||||||
|
float lineWidth = 1.0f; // Thickness of the line
|
||||||
|
canvas.setLineWidth(lineWidth);
|
||||||
|
|
||||||
|
// Get the current vertical position in the document
|
||||||
|
float yPos = writer.getVerticalPosition(true) - 10f; // Adjust this to move line slightly below current content
|
||||||
|
|
||||||
|
// Define start and end points for the line (relative to the page size and margins)
|
||||||
|
float xStart = document.leftMargin(); // Start from the left margin
|
||||||
|
float xEnd = document.getPageSize().getWidth() - document.rightMargin(); // End at the right margin
|
||||||
|
|
||||||
|
// Draw the line at the current Y position
|
||||||
|
canvas.moveTo(xStart, yPos); // Move to the starting point
|
||||||
|
canvas.lineTo(xEnd, yPos); // Draw the line to the end point
|
||||||
|
canvas.stroke(); // Apply the stroke (line)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
import com.itextpdf.text.BaseColor;
|
||||||
|
import com.itextpdf.text.DocumentException;
|
||||||
|
import com.itextpdf.text.Font;
|
||||||
|
import com.itextpdf.text.FontFactory;
|
||||||
|
import com.itextpdf.text.pdf.BaseFont;
|
||||||
|
import com.itextpdf.text.pdf.PdfReader;
|
||||||
|
import com.itextpdf.text.pdf.PdfStamper;
|
||||||
|
import com.itextpdf.text.pdf.PdfContentByte;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PdfPageNumberInserter {
|
||||||
|
|
||||||
|
public static byte[] addPageNumbers(byte[] pdfData) throws IOException, DocumentException {
|
||||||
|
PdfReader reader = new PdfReader(pdfData); // Read the generated PDF
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
BaseColor darkGreenColor = new BaseColor(1, 50, 32); // Adjust RGB values as needed
|
||||||
|
Font baseFont = FontFactory.getFont(FontFactory.HELVETICA, 4,darkGreenColor);
|
||||||
|
BaseFont font = baseFont.getBaseFont();
|
||||||
|
|
||||||
|
// PdfStamper allows us to modify the existing PDF
|
||||||
|
PdfStamper stamper = new PdfStamper(reader, outputStream);
|
||||||
|
int totalPages = reader.getNumberOfPages();
|
||||||
|
|
||||||
|
// Set the font for page numbers
|
||||||
|
|
||||||
|
for (int i = 1; i <= totalPages; i++) {
|
||||||
|
// Get the content of the current page
|
||||||
|
PdfContentByte over = stamper.getOverContent(i);
|
||||||
|
over.beginText();
|
||||||
|
over.setFontAndSize(font, 12);
|
||||||
|
|
||||||
|
// Add the page number at the bottom center of the page
|
||||||
|
over.showTextAligned(PdfContentByte.ALIGN_CENTER, "Page " + i + " of " + totalPages, 300, 30, 0);
|
||||||
|
|
||||||
|
over.endText();
|
||||||
|
}
|
||||||
|
|
||||||
|
stamper.close();
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
return outputStream.toByteArray(); // Return the modified PDF with page numbers
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.RegionEntity;
|
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||||
import net.gepafin.tendermanagement.entities.RoleEntity;
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.RoleReq;
|
import net.gepafin.tendermanagement.model.request.RoleReq;
|
||||||
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
@@ -119,4 +120,8 @@ public class RoleDao {
|
|||||||
log.info("Total roles found: {}", roles.size());
|
log.info("Total roles found: {}", roles.size());
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RoleEntity getRoleByType(RoleStatusEnum roleStatus) {
|
||||||
|
return roleRepository.findByRoleType(roleStatus.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import com.itextpdf.text.BaseColor;
|
||||||
|
import com.itextpdf.text.Rectangle;
|
||||||
|
import com.itextpdf.text.pdf.PdfContentByte;
|
||||||
|
import com.itextpdf.text.pdf.PdfPCell;
|
||||||
|
import com.itextpdf.text.pdf.PdfPCellEvent;
|
||||||
|
import com.itextpdf.text.pdf.PdfPTable;
|
||||||
|
|
||||||
|
public class RoundedCorners implements PdfPCellEvent {
|
||||||
|
@Override
|
||||||
|
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvas) {
|
||||||
|
// Retrieve the canvas for drawing the background and border
|
||||||
|
PdfContentByte cbBackground = canvas[PdfPTable.BACKGROUNDCANVAS];
|
||||||
|
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
|
||||||
|
|
||||||
|
cbBackground.saveState();
|
||||||
|
cb.saveState();
|
||||||
|
|
||||||
|
// Define the rounded rectangle radius and padding
|
||||||
|
float radius = 10f;
|
||||||
|
float padding = 2f; // Small padding to avoid overlap
|
||||||
|
|
||||||
|
// Get position values with adjusted height and width
|
||||||
|
float x = position.getLeft() + padding;
|
||||||
|
float y = position.getBottom() + padding;
|
||||||
|
float width = position.getWidth() - 2 * padding;
|
||||||
|
float height = position.getHeight() - 2 * padding;
|
||||||
|
|
||||||
|
// Fill the rounded rectangle with lighter grey
|
||||||
|
cbBackground.setColorFill(new BaseColor(239, 243, 248)); // Very light grey color
|
||||||
|
cbBackground.roundRectangle(x, y, width, height, radius);
|
||||||
|
cbBackground.fill(); // Fill the background
|
||||||
|
|
||||||
|
// Set the border stroke to thin and draw the rounded rectangle with dark grey color
|
||||||
|
cb.setLineWidth(0.5f); // Thin border width
|
||||||
|
cb.setColorStroke(new BaseColor(105, 105, 105)); // Dark grey border
|
||||||
|
cb.roundRectangle(x, y, width, height, radius);
|
||||||
|
cb.stroke(); // Draw the border
|
||||||
|
|
||||||
|
// Restore the canvas states
|
||||||
|
cbBackground.restoreState();
|
||||||
|
cb.restoreState();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||||
|
import net.gepafin.tendermanagement.repositories.SystemEmailTemplatesRespository;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SystemEmailTemplatesDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SystemEmailTemplatesRespository systemEmailTemplatesRespository;
|
||||||
|
|
||||||
|
@Value("${fe.base.url}")
|
||||||
|
private String feBaseUrl;
|
||||||
|
|
||||||
|
|
||||||
|
public SystemEmailTemplateResponse retrieveTemplate(SystemEmailTemplatesEntityTypeEnum type, CallEntity call, Locale language) {
|
||||||
|
SystemEmailTemplatesEntity dbSystemEmailTemplatesEntity = null;
|
||||||
|
if(call != null){
|
||||||
|
// dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
|
||||||
|
// .findByTypeAndCallId(type.getValue(), call.getId());
|
||||||
|
}
|
||||||
|
if(dbSystemEmailTemplatesEntity == null){
|
||||||
|
dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
|
||||||
|
.findByType(type.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemEmailTemplateResponse systemEmailTemplateResponse = replaceHtmlContant(dbSystemEmailTemplatesEntity, call, language, Boolean.TRUE);
|
||||||
|
return systemEmailTemplateResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SystemEmailTemplateResponse replaceHtmlContant(SystemEmailTemplatesEntity dbSystemEmailTemplatesEntity,
|
||||||
|
CallEntity call, Locale language1, Boolean isDefaultReplace) {
|
||||||
|
String language = null;
|
||||||
|
String htmlContent = dbSystemEmailTemplatesEntity.getHtmlContent();
|
||||||
|
String subject = dbSystemEmailTemplatesEntity.getSubject();
|
||||||
|
|
||||||
|
if (language1 == null) {
|
||||||
|
// language = getLanguage(LocaleContextHolder.getLocale());
|
||||||
|
language="italian";
|
||||||
|
}else{
|
||||||
|
language="italian";
|
||||||
|
}
|
||||||
|
Map<String, String> languageMap = new HashMap<>();
|
||||||
|
String jsonContent = dbSystemEmailTemplatesEntity.getJson();
|
||||||
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(jsonContent))) {
|
||||||
|
Map<String, Map<String, String>> jsonMap = Utils.parseJsonContent(jsonContent);
|
||||||
|
if (jsonMap != null && jsonMap.containsKey(language)) {
|
||||||
|
languageMap = jsonMap.get(language);
|
||||||
|
htmlContent = replacePlaceholders(htmlContent, languageMap);
|
||||||
|
subject = replaceSubjectPlaceholders(subject, languageMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Boolean.TRUE.equals(StringUtils.isEmpty(subject))){
|
||||||
|
subject = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
htmlContent = replacePlatformLinkPlaceholder(call, htmlContent, languageMap);
|
||||||
|
SystemEmailTemplateResponse systemEmailTemplateResponse = new SystemEmailTemplateResponse();
|
||||||
|
systemEmailTemplateResponse.setHtmlContent(htmlContent);
|
||||||
|
systemEmailTemplateResponse.setSubject(subject);
|
||||||
|
systemEmailTemplateResponse.setJsonMap(languageMap);
|
||||||
|
return systemEmailTemplateResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// private String getLanguage(Locale locale) {
|
||||||
|
// return switch (locale.getLanguage()) {
|
||||||
|
// case "en" -> "english";
|
||||||
|
// case "it" -> "italian";
|
||||||
|
// default -> "italian";
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
private String replacePlaceholders(String htmlContent, Map<String, String> languageMap) {
|
||||||
|
for (Map.Entry<String, String> entry : languageMap.entrySet()) {
|
||||||
|
htmlContent = htmlContent.replace("{{" + entry.getKey() + "}}", entry.getValue());
|
||||||
|
}
|
||||||
|
return htmlContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replaceSubjectPlaceholders(String subject, Map<String, String> languageMap) {
|
||||||
|
if(languageMap.containsKey("subject") && subject != null){
|
||||||
|
String value = languageMap.get("subject");
|
||||||
|
subject = subject.replace("{{subject}}", value);
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
private String replacePlatformLinkPlaceholder(CallEntity call, String htmlContent,
|
||||||
|
Map<String, String> languageMap) {
|
||||||
|
String platformLink = feBaseUrl;
|
||||||
|
|
||||||
|
// if(hubEntity != null && Boolean.FALSE.equals(isEmpty(hubEntity.getDomainName()))){
|
||||||
|
// platformLink = hubEntity.getDomainName();
|
||||||
|
// }
|
||||||
|
htmlContent = htmlContent.replace("{{platform_link}}", platformLink);
|
||||||
|
return htmlContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,33 +4,41 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
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.BeneficiaryEntity;
|
||||||
import net.gepafin.tendermanagement.entities.RoleEntity;
|
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserHubEntity;
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.*;
|
import net.gepafin.tendermanagement.model.request.*;
|
||||||
|
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||||
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
||||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
import net.gepafin.tendermanagement.repositories.UserHubRepository;
|
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||||
|
import net.gepafin.tendermanagement.service.RoleService;
|
||||||
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
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.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.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Component;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
|
||||||
@Repository
|
@Component
|
||||||
public class UserDao {
|
public class UserDao {
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(UserDao.class);
|
private final Logger log = LoggerFactory.getLogger(UserDao.class);
|
||||||
@@ -38,34 +46,116 @@ public class UserDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyDao companyDao;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AuthenticationService authService;
|
private AuthenticationService authService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
@Autowired
|
|
||||||
private UserHubRepository userHubRepository;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleDao roleDao;
|
private RoleDao roleDao;
|
||||||
|
|
||||||
public UserResponseBean createUser(UserReq userReq) {
|
@Autowired
|
||||||
log.info("Creating user with email: {}", userReq.getEmail());
|
private BeneficiaryRepository beneficiaryRepository;
|
||||||
if (userRepository.existsByEmailIgnoreCase(userReq.getEmail())) {
|
|
||||||
log.error("User creation failed: Email {} already exists", userReq.getEmail());
|
@Autowired
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
private RoleService roleService;
|
||||||
|
|
||||||
|
@Value("${default.hub.uuid}")
|
||||||
|
private String defaultHubUuid;
|
||||||
|
|
||||||
|
|
||||||
|
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
|
||||||
|
if(StringUtils.isEmpty(userReq.getHubUuid())) {
|
||||||
|
userReq.setHubUuid(defaultHubUuid);
|
||||||
}
|
}
|
||||||
if (!userReq.getPassword().equals(userReq.getConfPassword())) {
|
validateUserRequest(tempToken, userReq);
|
||||||
log.error("User creation failed: Passwords do not match for email {}", userReq.getEmail());
|
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
|
||||||
|
|
||||||
|
RoleEntity roleEntity = getRoleEntity(userReq.getRoleId());
|
||||||
|
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq);
|
||||||
|
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq);
|
||||||
|
log.info("User created with ID: {}", userEntity.getId());
|
||||||
|
return authService.getJWTTokenBean(userEntity, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq) {
|
||||||
|
BeneficiaryEntity beneficiaryEntity = null;
|
||||||
|
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
|
||||||
|
beneficiaryEntity = new BeneficiaryEntity();
|
||||||
|
beneficiaryEntity.setAddress(userReq.getAddress());
|
||||||
|
beneficiaryEntity.setCity(userReq.getCity());
|
||||||
|
beneficiaryEntity.setCodiceFiscale(userReq.getCodiceFiscale());
|
||||||
|
beneficiaryEntity.setCountry(userReq.getCountry());
|
||||||
|
beneficiaryEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||||
|
beneficiaryEntity.setEmail(userReq.getEmail());
|
||||||
|
beneficiaryEntity.setFirstName(userReq.getFirstName());
|
||||||
|
beneficiaryEntity.setLastName(userReq.getLastName());
|
||||||
|
beneficiaryEntity.setOrganization(userReq.getOrganization());
|
||||||
|
beneficiaryEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||||
|
beneficiaryEntity.setPrivacy(userReq.getPrivacy());
|
||||||
|
beneficiaryEntity.setTerms(userReq.getTerms());
|
||||||
|
beneficiaryEntity.setOffers(userReq.getOffers());
|
||||||
|
beneficiaryEntity.setMarketing(userReq.getMarketing());
|
||||||
|
beneficiaryEntity.setThirdParty(userReq.getThirdParty());
|
||||||
|
beneficiaryEntity.setEmailPec(userReq.getEmailPec());
|
||||||
|
beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity);
|
||||||
|
}
|
||||||
|
return beneficiaryEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateUserRequest(String tempToken, UserReq userReq) {
|
||||||
|
RoleEntity role = roleService.validateRole(userReq.getRoleId());
|
||||||
|
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
|
||||||
|
}
|
||||||
|
log.info("Creating user with email: {}", userReq.getEmail());
|
||||||
|
if (userRepository.existsByEmailIgnoreCaseAndhubUniqueUuid(userReq.getEmail(), userReq.getHubUuid())) {
|
||||||
|
log.error("User creation failed: Email {} already exists", userReq.getEmail());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||||
|
}
|
||||||
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
|
||||||
|
&& userRepository.existsByBeneficiaryCodiceFiscale(userReq.getCodiceFiscale())) {
|
||||||
|
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS));
|
||||||
|
}
|
||||||
|
if (tempToken == null && userReq.getRoleId() == null) {
|
||||||
|
throw new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.ROLE_ID_MANDATORY));
|
||||||
|
}
|
||||||
|
if (tempToken != null) {
|
||||||
|
userReq.setRoleId(null);
|
||||||
|
}
|
||||||
|
if(tempToken == null && Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||||
|
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
|
||||||
|
if(tempToken == null) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.VALIDATE_PASSWORD));
|
||||||
|
}else if(Boolean.FALSE.equals(StringUtils.isEmpty(password) && StringUtils.isEmpty(confirmPassword))){
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.VALIDATE_PASSWORD));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password != null && !password.equals(confirmPassword)) {
|
||||||
|
log.error("User creation failed: Passwords do not match");
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
||||||
}
|
}
|
||||||
if (userReq.getPassword().length() < 8) {
|
|
||||||
log.error("User creation failed: Password length is less than 8 characters for email {}", userReq.getEmail());
|
if (password != null && password.length() < 8) {
|
||||||
|
log.error("User creation failed: Password length is less than 8 characters");
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_MIN_LEN));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_MIN_LEN));
|
||||||
}
|
}
|
||||||
UserEntity userEntity = convertUserRequestToUserEntity(userReq);
|
|
||||||
userEntity = userRepository.save(userEntity);
|
|
||||||
log.info("User created with ID: {}", userEntity.getId());
|
|
||||||
return convertUserEntityToUserResponse(userEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||||
@@ -82,27 +172,48 @@ public class UserDao {
|
|||||||
setIfUpdated(userEntity::getOrganization, userEntity::setOrganization, userReq.getOrganization());
|
setIfUpdated(userEntity::getOrganization, userEntity::setOrganization, userReq.getOrganization());
|
||||||
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.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
|
||||||
|
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
|
||||||
|
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
|
||||||
|
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
|
||||||
if (userReq.getRoleId() != null) {
|
if (userReq.getRoleId() != null) {
|
||||||
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
|
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
|
||||||
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
||||||
}
|
}
|
||||||
|
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
|
||||||
userEntity = userRepository.save(userEntity);
|
userEntity = userRepository.save(userEntity);
|
||||||
log.info("User updated with ID: {}", userEntity.getId());
|
log.info("User updated with ID: {}", userEntity.getId());
|
||||||
return convertUserEntityToUserResponse(userEntity);
|
return convertUserEntityToUserResponse(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserEntity convertUserRequestToUserEntity(UserReq userReq) {
|
private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq) {
|
||||||
UserEntity userEntity = new UserEntity();
|
UserEntity userEntity = new UserEntity();
|
||||||
|
if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) {
|
||||||
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
|
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
|
||||||
|
}
|
||||||
|
userEntity.setRoleEntity(roleEntity);
|
||||||
userEntity.setEmail(userReq.getEmail());
|
userEntity.setEmail(userReq.getEmail());
|
||||||
|
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
|
||||||
|
userEntity.setBeneficiary(beneficiary);
|
||||||
|
if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) {
|
||||||
|
|
||||||
userEntity.setFirstName(userReq.getFirstName());
|
userEntity.setFirstName(userReq.getFirstName());
|
||||||
userEntity.setStatus(UserStatusEnum.PENDING_VERIFICATION.getValue());
|
|
||||||
userEntity.setLastName(userReq.getLastName());
|
userEntity.setLastName(userReq.getLastName());
|
||||||
userEntity.setOrganization(userReq.getOrganization());
|
userEntity.setOrganization(userReq.getOrganization());
|
||||||
userEntity.setAddress(userReq.getAddress());
|
userEntity.setAddress(userReq.getAddress());
|
||||||
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||||
userEntity.setRoleEntity(roleDao.validateRole(userReq.getRoleId()));
|
userEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||||
return userEntity;
|
}
|
||||||
|
return userRepository.save(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RoleEntity getRoleEntity(Long roleId) {
|
||||||
|
if(roleId != null) {
|
||||||
|
return roleDao.validateRole(roleId);
|
||||||
|
} else {
|
||||||
|
return roleDao.getRoleByType(RoleStatusEnum.ROLE_BENEFICIARY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserResponseBean convertUserEntityToUserResponse(UserEntity userEntity) {
|
private UserResponseBean convertUserEntityToUserResponse(UserEntity userEntity) {
|
||||||
@@ -111,6 +222,13 @@ public class UserDao {
|
|||||||
userResponseBean.setCreatedDate(userEntity.getCreatedDate());
|
userResponseBean.setCreatedDate(userEntity.getCreatedDate());
|
||||||
userResponseBean.setUpdatedDate(userEntity.getUpdatedDate());
|
userResponseBean.setUpdatedDate(userEntity.getUpdatedDate());
|
||||||
userResponseBean.setEmail(userEntity.getEmail());
|
userResponseBean.setEmail(userEntity.getEmail());
|
||||||
|
userResponseBean.setStatus(UserStatusEnum.valueOf(userEntity.getStatus()));
|
||||||
|
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(userEntity.getRoleEntity());
|
||||||
|
userResponseBean.setRole(roleResponseBean);
|
||||||
|
userResponseBean.setLastLogin(userEntity.getLastLogin());
|
||||||
|
List<CompanyResponse> companyResponseBeans = companyDao.getCompanyByUserId(userEntity.getId());
|
||||||
|
userResponseBean.setCompanies(companyResponseBeans);
|
||||||
|
if (userEntity.getBeneficiary() == null) {
|
||||||
userResponseBean.setFirstName(userEntity.getFirstName());
|
userResponseBean.setFirstName(userEntity.getFirstName());
|
||||||
userResponseBean.setLastName(userEntity.getLastName());
|
userResponseBean.setLastName(userEntity.getLastName());
|
||||||
userResponseBean.setPhoneNumber(userEntity.getPhoneNumber());
|
userResponseBean.setPhoneNumber(userEntity.getPhoneNumber());
|
||||||
@@ -118,16 +236,30 @@ public class UserDao {
|
|||||||
userResponseBean.setAddress(userEntity.getAddress());
|
userResponseBean.setAddress(userEntity.getAddress());
|
||||||
userResponseBean.setCity(userEntity.getCity());
|
userResponseBean.setCity(userEntity.getCity());
|
||||||
userResponseBean.setCountry(userEntity.getCountry());
|
userResponseBean.setCountry(userEntity.getCountry());
|
||||||
userResponseBean.setStatus(UserStatusEnum.valueOf(userEntity.getStatus()));
|
userResponseBean.setDateOfBirth(userEntity.getDateOfBirth());
|
||||||
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(userEntity.getRoleEntity());
|
} else {
|
||||||
userResponseBean.setRole(roleResponseBean);
|
userResponseBean.setFirstName(userEntity.getBeneficiary().getFirstName());
|
||||||
userResponseBean.setLastLogin(userEntity.getLastLogin());
|
userResponseBean.setLastName(userEntity.getBeneficiary().getLastName());
|
||||||
|
userResponseBean.setPhoneNumber(userEntity.getBeneficiary().getPhoneNumber());
|
||||||
|
userResponseBean.setOrganization(userEntity.getBeneficiary().getOrganization());
|
||||||
|
userResponseBean.setAddress(userEntity.getBeneficiary().getAddress());
|
||||||
|
userResponseBean.setCity(userEntity.getBeneficiary().getCity());
|
||||||
|
userResponseBean.setCountry(userEntity.getBeneficiary().getCountry());
|
||||||
|
userResponseBean.setCodiceFiscale(userEntity.getBeneficiary().getCodiceFiscale());
|
||||||
|
userResponseBean.setDateOfBirth(userEntity.getBeneficiary().getDateOfBirth());
|
||||||
|
userResponseBean.setPrivacy(userEntity.getBeneficiary().getPrivacy());
|
||||||
|
userResponseBean.setTerms(userEntity.getBeneficiary().getTerms());
|
||||||
|
userResponseBean.setOffers(userEntity.getBeneficiary().getOffers());
|
||||||
|
userResponseBean.setMarketing(userEntity.getBeneficiary().getMarketing());
|
||||||
|
userResponseBean.setThirdParty(userEntity.getBeneficiary().getThirdParty());
|
||||||
|
userResponseBean.setEmailPec(userEntity.getBeneficiary().getEmailPec());
|
||||||
|
}
|
||||||
return userResponseBean;
|
return userResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponseBean getUserById(Long id) {
|
public UserResponseBean getUserById(Long id) {
|
||||||
log.info("Fetching user with ID: {}", id);
|
log.info("Fetching user with ID: {}", id);
|
||||||
UserEntity userEntity=validateUser(id);
|
UserEntity userEntity = validateUser(id);
|
||||||
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
||||||
// log.info("User with ID: {} is not active", id);
|
// log.info("User with ID: {} is not active", id);
|
||||||
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||||
@@ -143,9 +275,12 @@ public class UserDao {
|
|||||||
log.info("User deleted with ID: {}", id);
|
log.info("User deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JWTToken login(LoginReq loginReq) {
|
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
|
||||||
log.info("User login attempt for email: {}", loginReq.getEmail());
|
log.info("User login attempt for email: {}", loginReq.getEmail());
|
||||||
JWTToken jwtToken = authService.login(loginReq);
|
if(StringUtils.isEmpty(loginReq.getHubUuid())) {
|
||||||
|
loginReq.setHubUuid(defaultHubUuid);
|
||||||
|
}
|
||||||
|
JWTToken jwtToken = authService.login(loginReq,request);
|
||||||
log.info("Login successful for email: {}", loginReq.getEmail());
|
log.info("Login successful for email: {}", loginReq.getEmail());
|
||||||
return jwtToken;
|
return jwtToken;
|
||||||
}
|
}
|
||||||
@@ -155,22 +290,22 @@ public class UserDao {
|
|||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
}
|
}
|
||||||
public String generateSecureToken() {
|
public UserEntity getUserByBeneficiaryId(Long beneficiaryId) {
|
||||||
SecureRandom secureRandom = new SecureRandom();
|
UserEntity user = userRepository.findByBeneficiaryId(beneficiaryId);
|
||||||
byte[] tokenBytes = new byte[24];
|
if (user == null) {
|
||||||
secureRandom.nextBytes(tokenBytes);
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
String token = Base64.getUrlEncoder().withoutPadding().encodeToString(tokenBytes);
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_WITH_BENEFICIARYID_MSG));
|
||||||
log.debug("Generated secure token: {}", token);
|
}
|
||||||
return token;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) {
|
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) {
|
||||||
UserEntity user = userRepository.findByEmail(resetReq.getEmail());
|
UserEntity user = userRepository
|
||||||
if (user == null) {
|
.findByEmailIgnoreCaseAndhubUniqueUuid(resetReq.getEmail(), resetReq.getHubUuid())
|
||||||
log.info("Password reset attempt for non-existent user: {}", resetReq.getEmail());
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
}
|
|
||||||
String token = generateSecureToken();
|
String token = Utils.generateSecureToken();
|
||||||
user.setResetPasswordToken(token);
|
user.setResetPasswordToken(token);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
log.info("Password reset token generated for user: {}", resetReq.getEmail());
|
log.info("Password reset token generated for user: {}", resetReq.getEmail());
|
||||||
@@ -178,11 +313,11 @@ public class UserDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean resetPassword(ResetPasswordReq resetPasswordReq) {
|
public Boolean resetPassword(ResetPasswordReq resetPasswordReq) {
|
||||||
UserEntity user = userRepository.findByEmail(resetPasswordReq.getEmail());
|
UserEntity user = userRepository
|
||||||
if (user == null) {
|
.findByEmailIgnoreCaseAndhubUniqueUuid(resetPasswordReq.getEmail(), resetPasswordReq.getHubUuid())
|
||||||
log.info("Password reset attempt for non-existent user: {}", resetPasswordReq.getEmail());
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
}
|
|
||||||
if (!resetPasswordReq.getNewPassword().equals(resetPasswordReq.getConfirmPassword())) {
|
if (!resetPasswordReq.getNewPassword().equals(resetPasswordReq.getConfirmPassword())) {
|
||||||
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
|
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
||||||
@@ -201,12 +336,12 @@ public class UserDao {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean changePassword(ChangePasswordRequest request) {
|
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest request) {
|
||||||
UserEntity user = userRepository.findByEmail(request.getEmail());
|
UserEntity user = userRepository
|
||||||
if (user == null) {
|
.findByEmailIgnoreCaseAndhubUniqueUuid(request.getEmail(), userEntity.getHub().getUniqueUuid())
|
||||||
log.info("Password reset attempt for non-existent user: {}", request.getEmail());
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
}
|
|
||||||
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
|
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CURRENT_PASSWORD_INCORRECT));
|
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CURRENT_PASSWORD_INCORRECT));
|
||||||
}
|
}
|
||||||
@@ -232,24 +367,41 @@ public class UserDao {
|
|||||||
return convertUserEntityToUserResponse(userEntity);
|
return convertUserEntityToUserResponse(userEntity);
|
||||||
}
|
}
|
||||||
public List<UserResponseBean> getUserByHubId(String hubId) {
|
public List<UserResponseBean> getUserByHubId(String hubId) {
|
||||||
log.info("Fetching users for hub ID: {}", hubId);
|
// log.info("Fetching users for hub ID: {}", hubId);
|
||||||
List<UserHubEntity> userHubMappings = userHubRepository.findByHubId(hubId);
|
// List<UserHubEntity> userHubMappings = userHubRepository.findByHubId(hubId);
|
||||||
List<UserResponseBean> userResponseBeans = new ArrayList<>();
|
List<UserResponseBean> userResponseBeans = new ArrayList<>();
|
||||||
for (UserHubEntity mapping : userHubMappings) {
|
// for (UserHubEntity mapping : userHubMappings) {
|
||||||
UserEntity userEntity = validateUser(mapping.getUserId());
|
// UserEntity userEntity = validateUser(mapping.getUserId());
|
||||||
userResponseBeans.add(convertUserEntityToUserResponse(userEntity));
|
// userResponseBeans.add(convertUserEntityToUserResponse(userEntity));
|
||||||
}
|
// }
|
||||||
return userResponseBeans;
|
return userResponseBeans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponseBean createUserByHubId(String hubId, UserReq userReq) {
|
public JWTToken validateExistingUserToken(String token) {
|
||||||
log.info("Creating user for hub ID: {}", hubId);
|
return authService.validateExistingUserToken(token);
|
||||||
UserResponseBean createdUser = createUser(userReq);
|
|
||||||
UserHubEntity mapping = new UserHubEntity();
|
|
||||||
mapping.setHubId(hubId);
|
|
||||||
mapping.setUserId(createdUser.getId());
|
|
||||||
userHubRepository.save(mapping);
|
|
||||||
log.info("User created and mapped to hub ID: {} with User ID: {}", hubId, createdUser.getId());
|
|
||||||
return createdUser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserSamlResponse validateNewUserToken(String token) {
|
||||||
|
return authService.validateNewUserToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserResponseBean> getAllUsers(Long roleId) {
|
||||||
|
List<UserEntity> users;
|
||||||
|
if (roleId != null) {
|
||||||
|
log.info("Fetching users by role ID: {}", roleId);
|
||||||
|
RoleEntity roleEntity=roleService.validateRole(roleId);
|
||||||
|
users = userRepository.findByRoleEntityId(roleEntity.getId());
|
||||||
|
} else {
|
||||||
|
log.info("Fetching all users");
|
||||||
|
users = userRepository.findAll();
|
||||||
|
}
|
||||||
|
List<UserResponseBean> userResponseBeans = users.stream()
|
||||||
|
.map(this::convertUserEntityToUserResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
log.info("Total users found with role ID {}: {}", roleId, userResponseBeans.size());
|
||||||
|
return userResponseBeans;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import feign.FeignException;
|
import feign.FeignException;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||||
|
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;
|
||||||
@@ -67,8 +72,17 @@ public class VatCheckDao {
|
|||||||
}
|
}
|
||||||
} 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);
|
||||||
throw ex;
|
Utils.callException(ex.status(), ex);
|
||||||
}
|
}
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> checkVatNumber(String vatNumber) {
|
||||||
|
try {
|
||||||
|
return checkVatNumberApi(vatNumber);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,12 @@ import java.time.LocalDateTime;
|
|||||||
@Builder
|
@Builder
|
||||||
public class ApplicationEntity extends BaseEntity {
|
public class ApplicationEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "USER_ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "USER_ID", nullable = false)
|
@JoinColumn(name = "COMPANY_ID", nullable = false)
|
||||||
private UserEntity user;
|
private CompanyEntity company;
|
||||||
|
|
||||||
@Column(name = "SUBMISSION_DATE")
|
@Column(name = "SUBMISSION_DATE")
|
||||||
private LocalDateTime submissionDate;
|
private LocalDateTime submissionDate;
|
||||||
@@ -33,4 +36,7 @@ public class ApplicationEntity extends BaseEntity {
|
|||||||
@Column(name="IS_DELETED")
|
@Column(name="IS_DELETED")
|
||||||
private Boolean isDeleted;
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "PROTOCOL_NUMBER")
|
||||||
|
private ProtocolEntity protocol;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "application_signed_document")
|
||||||
|
public class ApplicationSignedDocumentEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "APPLICATION_ID")
|
||||||
|
private ApplicationEntity application;
|
||||||
|
|
||||||
|
@Column(name = "FILE_NAME")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "FILE_PATH")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(name="STATUS")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "BENEFICIARY")
|
||||||
|
@Data
|
||||||
|
public class BeneficiaryEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Email
|
||||||
|
@Column(name = "EMAIL")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "FIRST_NAME")
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "LAST_NAME")
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@Column(name = "PHONE_NUMBER")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@Column(name = "ORGANIZATION")
|
||||||
|
private String organization;
|
||||||
|
|
||||||
|
@Column(name = "ADDRESS")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Column(name = "CITY")
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@Column(name = "COUNTRY")
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@Column(name = "CODICE_FISCALE")
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
@Column(name = "DATE_OF_BIRTH")
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
|
||||||
|
@Column(name = "PRIVACY")
|
||||||
|
private Boolean privacy;
|
||||||
|
|
||||||
|
@Column(name = "TERMS")
|
||||||
|
private Boolean terms;
|
||||||
|
|
||||||
|
@Column(name = "MARKETING")
|
||||||
|
private Boolean marketing;
|
||||||
|
|
||||||
|
@Column(name = "OFFERS")
|
||||||
|
private Boolean offers;
|
||||||
|
|
||||||
|
@Column(name = "THIRD_PARTY")
|
||||||
|
private Boolean thirdParty;
|
||||||
|
|
||||||
|
@Column(name = "EMAIL_PEC")
|
||||||
|
private String emailPec;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "beneficiary_preferred_call")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class BeneficiaryPreferredCallEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "beneficiary_id")
|
||||||
|
private Long beneficiaryId;
|
||||||
|
|
||||||
|
@Column(name = "user_id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Column(name = "company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@Column(name = "call_id")
|
||||||
|
private Long callId;
|
||||||
|
|
||||||
|
@Column(name = "STATUS", length = 255)
|
||||||
|
private String status;
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import lombok.Builder;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "CALL")
|
@Table(name = "CALL")
|
||||||
@@ -68,5 +69,24 @@ public class CallEntity extends BaseEntity {
|
|||||||
|
|
||||||
@Column(name="FINAL_FORM")
|
@Column(name="FINAL_FORM")
|
||||||
private Long finalForm;
|
private Long finalForm;
|
||||||
|
|
||||||
|
@Column(name = "AMOUNT_MIN")
|
||||||
|
private BigDecimal amountMin;
|
||||||
|
|
||||||
|
@Column(name="EMAIL")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "PHONE_NUMBER")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@Column(name = "START_TIME")
|
||||||
|
private LocalTime startTime;
|
||||||
|
|
||||||
|
@Column(name = "END_TIME")
|
||||||
|
private LocalTime endTime;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "HUB_ID")
|
||||||
|
private HubEntity hub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "COMPANY")
|
||||||
|
@Data
|
||||||
|
public class CompanyEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Column(name = "COMPANY_NAME")
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
@Column(name = "VAT_NUMBER")
|
||||||
|
private String vatNumber;
|
||||||
|
|
||||||
|
@Column(name = "CODICE_FISCALE")
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
@Column(name = "ADDRESS")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Column(name = "PHONE_NUMBER")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@Column(name = "CITY")
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@Column(name = "PROVINCE")
|
||||||
|
private String province;
|
||||||
|
|
||||||
|
@Column(name = "CAP")
|
||||||
|
private String cap;
|
||||||
|
|
||||||
|
@Column(name = "COUNTRY")
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@Column(name = "PEC")
|
||||||
|
private String pec;
|
||||||
|
|
||||||
|
@Column(name = "EMAIL")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "NUMBER_OF_EMPLOYEES")
|
||||||
|
private String numberOfEmployees;
|
||||||
|
|
||||||
|
@Column(name = "ANNUAL_REVENUE")
|
||||||
|
private BigDecimal annualRevenue;
|
||||||
|
|
||||||
|
@Column(name = "CONTACT_NAME")
|
||||||
|
private String contactName;
|
||||||
|
|
||||||
|
@Column(name = "CONTACT_EMAIL")
|
||||||
|
private String contactEmail;
|
||||||
|
}
|
||||||
@@ -42,5 +42,8 @@ public class FaqEntity extends BaseEntity {
|
|||||||
@Column(name ="IS_DELETED", nullable = false)
|
@Column(name ="IS_DELETED", nullable = false)
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
@Column(name ="COMPANY_ID")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,35 +12,34 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class HubEntity extends BaseEntity{
|
public class HubEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Column(name = "COMPANY_NAME")
|
||||||
@Column(name = "COMPANY_NAME", length = 255,nullable = false)
|
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
|
||||||
@Column(name = "FIRST_NAME", length = 255)
|
@Column(name = "FIRST_NAME")
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name = "LAST_NAME", length = 255)
|
@Column(name = "LAST_NAME")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
@Column(name = "EMAIL", length = 255,nullable = false)
|
@Column(name = "EMAIL")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Column(name = "CITY", length = 255)
|
@Column(name = "CITY")
|
||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
@Column(name = "COUNTRY", length = 255, nullable = false)
|
@Column(name = "COUNTRY")
|
||||||
private String country;
|
private String country;
|
||||||
|
|
||||||
@Size(min=5,max=15)
|
@Size(min=5,max=15)
|
||||||
@Column(name = "VAT_NUMBER", length = 255,nullable = false, unique = true)
|
@Column(name = "VAT_NUMBER")
|
||||||
private String vatNumber;
|
private String vatNumber;
|
||||||
|
|
||||||
@Column(name = "DOMAIN_NAME", length = 255)
|
@Column(name = "DOMAIN_NAME")
|
||||||
private String domainName;
|
private String domainName;
|
||||||
|
|
||||||
@Column(name = "APP_CONFIG", columnDefinition = "TEXT")
|
@Column(name = "APP_CONFIG")
|
||||||
private String appConfig;
|
private String appConfig;
|
||||||
|
|
||||||
@Column(name = "UNIQUE_UUID", length = 255,nullable = false, unique = true)
|
@Column(name = "UNIQUE_UUID")
|
||||||
private String uniqueUuid;
|
private String uniqueUuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "LOGIN_ATTEMPT")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class LoginAttemptEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "ID", unique = true)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "USERNAME")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Column(name = "USER_ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Column(name = "ATTEMPT_DATE", nullable = false)
|
||||||
|
private LocalDateTime attemptDate;
|
||||||
|
|
||||||
|
@Column(name = "IP_ADDRESS", length = 100)
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
@Column(name = "USER_AGENT")
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
|
@Column(name = "RESULT", length = 100, nullable = false)
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
@Column(name = "ERROR_MSG")
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
|
@Column(name = "ATTEMPT_TYPE", length = 100, nullable = false)
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "PROTOCOL")
|
||||||
|
@Data
|
||||||
|
public class ProtocolEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "PROTOCOL_NUMBER", nullable = false)
|
||||||
|
private Long protocolNumber;
|
||||||
|
|
||||||
|
@Column(name = "YEAR", nullable = false)
|
||||||
|
private Integer year;
|
||||||
|
|
||||||
|
@Column(name="CALL_ID")
|
||||||
|
private Long call;
|
||||||
|
|
||||||
|
@Column(name = "TIME", nullable = false)
|
||||||
|
private LocalTime time;
|
||||||
|
|
||||||
|
@Column(name="APPLICATION_ID")
|
||||||
|
private Long applicationId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,21 +6,15 @@ import jakarta.persistence.Table;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "SAML_RESPONSE_LOG")
|
@Table(name = "SAML_RESPONSE")
|
||||||
@Data
|
@Data
|
||||||
public class SamlResponseLogEntity extends BaseEntity{
|
public class SamlResponseEntity extends BaseEntity{
|
||||||
|
|
||||||
@Column(name = "REQUEST")
|
|
||||||
private String request;
|
|
||||||
|
|
||||||
@Column(name = "RESPONSE")
|
|
||||||
private String response;
|
|
||||||
|
|
||||||
@Column(name = "AUTHENTICATION_OBJECT")
|
@Column(name = "AUTHENTICATION_OBJECT")
|
||||||
private String authenticationObject;
|
private String authenticationObject;
|
||||||
|
|
||||||
@Column(name = "EXCEPTION_OBJECT")
|
@Column(name = "TOKEN")
|
||||||
private String exceptionObject;
|
private String token;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
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 = "system_email_template")
|
||||||
|
@Data
|
||||||
|
public class SystemEmailTemplatesEntity extends BaseEntity {
|
||||||
|
|
||||||
|
|
||||||
|
@Column(name = "TEMPLATE_NAME")
|
||||||
|
private String templateName;
|
||||||
|
|
||||||
|
@Column(name = "TYPE")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Column(name = "HTML_CONTENT", columnDefinition = "TEXT")
|
||||||
|
private String htmlContent;
|
||||||
|
|
||||||
|
@Column(name = "SUBJECT")
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
@Column(name = "JSON", columnDefinition = "TEXT")
|
||||||
|
private String json;
|
||||||
|
|
||||||
|
@Column(name = "SYSTEM")
|
||||||
|
private Boolean system;
|
||||||
|
|
||||||
|
@Column(name ="IS_DELETED", nullable = false)
|
||||||
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
public enum SystemEmailTemplatesEntityTypeEnum {
|
||||||
|
|
||||||
|
APPLICATION_SUBMISSION_TO_USER_AND_COMPANY("APPLICATION_SUBMISSION_TO_USER_AND_COMPANY"),
|
||||||
|
APPLICATION_SUBMISSION_TO_GEPAFIN("APPLICATION_SUBMISSION_TO_GEPAFIN");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
SystemEmailTemplatesEntityTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "user_company_delegation")
|
||||||
|
public class UserCompanyDelegationEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Column(name="USER_ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Column(name="COMPANY_ID")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@Column(name = "BENEFICIARY_ID")
|
||||||
|
private Long beneficiaryId;
|
||||||
|
|
||||||
|
@Column(name = "FILE_NAME")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "FILE_PATH")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(name="STATUS")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.gepafin.tendermanagement.entities;
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ import java.time.LocalDateTime;
|
|||||||
@Setter
|
@Setter
|
||||||
public class UserEntity extends BaseEntity {
|
public class UserEntity extends BaseEntity {
|
||||||
|
|
||||||
@Column(name = "PASSWORD", columnDefinition = "TEXT",nullable = false)
|
@Column(name = "PASSWORD", columnDefinition = "TEXT",nullable = true)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ public class UserEntity extends BaseEntity {
|
|||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private RoleEntity roleEntity;
|
private RoleEntity roleEntity;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "LAST_LOGIN")
|
@Column(name = "LAST_LOGIN")
|
||||||
private LocalDateTime lastLogin;
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
@@ -60,4 +58,15 @@ public class UserEntity extends BaseEntity {
|
|||||||
|
|
||||||
@Column(name = "RESET_PASSWORD_TOKEN", length = 255, nullable = true)
|
@Column(name = "RESET_PASSWORD_TOKEN", length = 255, nullable = true)
|
||||||
private String resetPasswordToken;
|
private String resetPasswordToken;
|
||||||
|
|
||||||
|
@Column(name = "DATE_OF_BIRTH")
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "BENEFICIARY_ID")
|
||||||
|
private BeneficiaryEntity beneficiary;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "HUB_ID")
|
||||||
|
private HubEntity hub;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package net.gepafin.tendermanagement.entities;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "USER_HUB")
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class UserHubEntity extends BaseEntity {
|
|
||||||
|
|
||||||
@Column(name = "hub_id")
|
|
||||||
private String hubId;
|
|
||||||
|
|
||||||
@Column(name = "user_id")
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.gepafin.tendermanagement.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "USER_WITH_COMPANY")
|
||||||
|
@Data
|
||||||
|
public class UserWithCompanyEntity extends BaseEntity{
|
||||||
|
|
||||||
|
@Column(name = "USER_ID")
|
||||||
|
Long userId;
|
||||||
|
|
||||||
|
@Column(name = "BENEFICIARY_ID")
|
||||||
|
Long beneficiaryId;
|
||||||
|
|
||||||
|
@Column(name = "COMPANY_ID")
|
||||||
|
Long companyId;
|
||||||
|
|
||||||
|
@Column(name = "IS_LEGAL_REPRESENTANT")
|
||||||
|
private Boolean isLegalRepresentant;
|
||||||
|
|
||||||
|
@Column(name = "IS_DELETED")
|
||||||
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum ApplicationSignedDocumentStatusEnum {
|
||||||
|
ACTIVE("ACTIVE"), INACTIVE("INACTIVE");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
ApplicationSignedDocumentStatusEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum BeneficiaryCallStatus {
|
||||||
|
|
||||||
|
ENABLED("ENABLED"),
|
||||||
|
DISABLED("DISABLED"),
|
||||||
|
APPLIED("APPLIED");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
BeneficiaryCallStatus(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum LoginAttemptResultEnum {
|
||||||
|
|
||||||
|
SUCCESS("SUCCESS"),
|
||||||
|
FAILED("FAILED");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
LoginAttemptResultEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum LoginAttemptTypeEnum {
|
||||||
|
|
||||||
|
LOGIN("LOGIN"),
|
||||||
|
SWITCH("SWITCH");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
LoginAttemptTypeEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.gepafin.tendermanagement.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
public enum UserCompanyDelegationStatusEnum {
|
||||||
|
ACTIVE("ACTIVE"), INACTIVE("INACTIVE");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
UserCompanyDelegationStatusEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,6 @@ public class ApplicationFormFieldRequestBean {
|
|||||||
|
|
||||||
private String fieldId;
|
private String fieldId;
|
||||||
|
|
||||||
private String fieldValue;
|
private Object fieldValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class BeneficiaryPreferredCallReq {
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
private Long callId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CompanyDelegationRequest {
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private String codiceFiscale;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CompanyRequest {
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
private String vatNumber;
|
||||||
|
private String codiceFiscale;
|
||||||
|
private String address;
|
||||||
|
private String phoneNumber;
|
||||||
|
private String city;
|
||||||
|
private String province;
|
||||||
|
private String cap;
|
||||||
|
private String country;
|
||||||
|
private String pec;
|
||||||
|
private String email;
|
||||||
|
private String numberOfEmployees;
|
||||||
|
private BigDecimal annualRevenue;
|
||||||
|
private Boolean isLegalRepresentant;
|
||||||
|
private String contactName;
|
||||||
|
private String contactEmail;
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@ package net.gepafin.tendermanagement.model.request;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -26,6 +28,16 @@ public class CreateCallRequestStep1 {
|
|||||||
|
|
||||||
private String documentationRequested;
|
private String documentationRequested;
|
||||||
|
|
||||||
|
private BigDecimal amountMin;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
private Boolean confidi;
|
private Boolean confidi;
|
||||||
|
|
||||||
private List<FaqReq> faq;
|
private List<FaqReq> faq;
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import com.itextpdf.text.*;
|
||||||
|
import com.itextpdf.text.pdf.ColumnText;
|
||||||
|
import com.itextpdf.text.pdf.PdfContentByte;
|
||||||
|
import com.itextpdf.text.pdf.PdfPageEventHelper;
|
||||||
|
import com.itextpdf.text.pdf.PdfWriter;
|
||||||
|
|
||||||
|
public class CustomPageEvent extends PdfPageEventHelper {
|
||||||
|
private String title;
|
||||||
|
private int totalPages;
|
||||||
|
|
||||||
|
public CustomPageEvent(String title, int totalPages) {
|
||||||
|
this.title = title;
|
||||||
|
this.totalPages = totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndPage(PdfWriter writer, Document document) {
|
||||||
|
PdfContentByte canvas = writer.getDirectContent();
|
||||||
|
|
||||||
|
// Header - Add a title to each page at the top
|
||||||
|
if (writer.getPageNumber() > 1) {
|
||||||
|
Font headerFont = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, new BaseColor(113, 121, 126)); // Gray color for header
|
||||||
|
ColumnText.showTextAligned(
|
||||||
|
canvas,
|
||||||
|
Element.ALIGN_LEFT,
|
||||||
|
new Phrase(title, headerFont),
|
||||||
|
document.leftMargin(), // Use left margin to align fully to the left
|
||||||
|
document.getPageSize().getHeight() - 30, // Positioning header near top
|
||||||
|
0 // No rotation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer - Add page number at the bottom
|
||||||
|
String footerText = String.format("Page %d of %d", writer.getPageNumber(), totalPages);
|
||||||
|
|
||||||
|
// Set font for the footer
|
||||||
|
Font footerFont = new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK);
|
||||||
|
|
||||||
|
// Positioning footer near bottom
|
||||||
|
ColumnText.showTextAligned(writer.getDirectContent(),
|
||||||
|
Element.ALIGN_LEFT,
|
||||||
|
new Phrase(footerText, footerFont),
|
||||||
|
(document.right() + document.left()) / 2,
|
||||||
|
document.bottomMargin() - 10, // Positioning footer near bottom
|
||||||
|
0);
|
||||||
|
|
||||||
|
// Draw a yellow line below header
|
||||||
|
if (writer.getPageNumber() > 1) {
|
||||||
|
canvas.setLineWidth(1.5f);
|
||||||
|
canvas.setColorStroke(new BaseColor(255, 219, 88)); // Yellow color
|
||||||
|
float yPos = document.getPageSize().getHeight() - 50f; // Position for the line below header
|
||||||
|
canvas.moveTo(0, yPos);
|
||||||
|
canvas.lineTo(document.getPageSize().getWidth(), yPos);
|
||||||
|
canvas.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw another line 50 points above the bottom of the document
|
||||||
|
canvas.setLineWidth(1.5f);
|
||||||
|
canvas.setColorStroke(new BaseColor(255, 219, 88)); // Yellow color
|
||||||
|
float lineYPos = document.bottomMargin() + 25f; // Position for the line above the bottom margin
|
||||||
|
canvas.moveTo(0, lineYPos);
|
||||||
|
canvas.lineTo(document.getPageSize().getWidth(), lineYPos);
|
||||||
|
canvas.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPages(int totalPages) {
|
||||||
|
this.totalPages = totalPages;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FieldLabelValuePairRequest {
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
private Object value;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,4 +5,5 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class InitiatePasswordResetReq {
|
public class InitiatePasswordResetReq {
|
||||||
private String email;
|
private String email;
|
||||||
|
private String hubUuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class LoginAttemptReq {
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long userId;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -14,5 +14,6 @@ public class LoginReq {
|
|||||||
private String email;
|
private String email;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String password;
|
private String password;
|
||||||
|
private String hubUuid;
|
||||||
private Boolean rememberMe;
|
private Boolean rememberMe;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ public class ResetPasswordReq {
|
|||||||
private String token;
|
private String token;
|
||||||
private String newPassword;
|
private String newPassword;
|
||||||
private String confirmPassword;
|
private String confirmPassword;
|
||||||
|
private String hubUuid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.request;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -25,6 +26,16 @@ public class UpdateCallRequestStep1 {
|
|||||||
|
|
||||||
private String documentationRequested;
|
private String documentationRequested;
|
||||||
|
|
||||||
|
private BigDecimal amountMin;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
private Boolean confidi;
|
private Boolean confidi;
|
||||||
|
|
||||||
private List<FaqReq> faq;
|
private List<FaqReq> faq;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class UpdateUserReq {
|
public class UpdateUserReq {
|
||||||
@@ -17,4 +19,11 @@ public class UpdateUserReq {
|
|||||||
private String city;
|
private String city;
|
||||||
private UserStatusEnum status;
|
private UserStatusEnum status;
|
||||||
private String country;
|
private String country;
|
||||||
|
private String codiceFiscale;
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
private Boolean marketing;
|
||||||
|
private Boolean offers;
|
||||||
|
private Boolean thirdParty;
|
||||||
|
|
||||||
|
private String emailPec;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
package net.gepafin.tendermanagement.model.request;
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
import jakarta.validation.constraints.Email;
|
import java.time.LocalDateTime;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserReq {
|
public class UserReq {
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Email
|
|
||||||
private String email;
|
private String email;
|
||||||
@NotEmpty
|
|
||||||
private String password;
|
private String password;
|
||||||
@NotEmpty
|
|
||||||
private String confPassword;
|
private String confPassword;
|
||||||
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
@@ -22,7 +17,7 @@ public class UserReq {
|
|||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
@NotNull
|
|
||||||
private Long roleId;
|
private Long roleId;
|
||||||
|
|
||||||
private String organization;
|
private String organization;
|
||||||
@@ -33,4 +28,19 @@ public class UserReq {
|
|||||||
|
|
||||||
private String country;
|
private String country;
|
||||||
|
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
private Boolean privacy;
|
||||||
|
private Boolean terms;
|
||||||
|
|
||||||
|
private Boolean marketing;
|
||||||
|
private Boolean offers;
|
||||||
|
private Boolean thirdParty;
|
||||||
|
|
||||||
|
private String emailPec;
|
||||||
|
|
||||||
|
private String hubUuid;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ public class ApplicationGetResponseBean {
|
|||||||
|
|
||||||
private String callTitle;
|
private String callTitle;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
private Long protocolNumber;
|
||||||
|
|
||||||
private List<FormApplicationResponse> form;
|
private List<FormApplicationResponse> form;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,24 @@ public class ApplicationResponse{
|
|||||||
|
|
||||||
private Long callId;
|
private Long callId;
|
||||||
|
|
||||||
|
private String callTitle;
|
||||||
|
|
||||||
|
private LocalDateTime callEndDate;
|
||||||
|
|
||||||
|
private LocalDateTime modifiedDate;
|
||||||
|
|
||||||
|
private Integer progress;
|
||||||
|
|
||||||
private LocalDateTime submissionDate;
|
private LocalDateTime submissionDate;
|
||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
private String comments;
|
private String comments;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
private Long protocolNumber;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ public class ApplicationResponseBean extends BaseBean {
|
|||||||
|
|
||||||
private String comments;
|
private String comments;
|
||||||
|
|
||||||
|
private Long protocolNumber;
|
||||||
|
|
||||||
private List<ApplicationFormFieldResponseBean> formFields;
|
private List<ApplicationFormFieldResponseBean> formFields;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationSignedDocumentStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApplicationSignedDocumentResponse extends BaseBean{
|
||||||
|
|
||||||
|
private Long applicationId;
|
||||||
|
private String fileName;
|
||||||
|
private String filePath;
|
||||||
|
private ApplicationSignedDocumentStatusEnum status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class BeneficiaryPreferredCallResponseBean {
|
||||||
|
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long beneficiaryId;
|
||||||
|
private Long userId;
|
||||||
|
private Long companyId;
|
||||||
|
private Long callId;
|
||||||
|
private BeneficiaryCallStatus status;
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class BeneficiaryWidgetResponseBean {
|
||||||
|
|
||||||
|
private Long numberOfApplications;
|
||||||
|
|
||||||
|
private Long numberOfCalls;
|
||||||
|
|
||||||
|
private Long numberOfIntegratedDocuments;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class CallDetailsResponseBean {
|
public class CallDetailsResponseBean {
|
||||||
@@ -37,6 +38,16 @@ public class CallDetailsResponseBean {
|
|||||||
|
|
||||||
private String documentationRequested;
|
private String documentationRequested;
|
||||||
|
|
||||||
|
private BigDecimal amountMin;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private LocalTime startTime;
|
||||||
|
|
||||||
|
private LocalTime endTime;
|
||||||
|
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.response;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -40,6 +41,16 @@ public class CallResponse {
|
|||||||
|
|
||||||
private Boolean confidi;
|
private Boolean confidi;
|
||||||
|
|
||||||
|
private BigDecimal amountMin;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
private LocalTime startTime;
|
||||||
|
|
||||||
|
private LocalTime endTime;
|
||||||
|
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.entities.BaseEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CompanyDelegationResponse extends BaseBean{
|
||||||
|
private Long userId;
|
||||||
|
private Long companyId;
|
||||||
|
private Long beneficiaryId;
|
||||||
|
private String fileName;
|
||||||
|
private String filePath;
|
||||||
|
private UserCompanyDelegationStatusEnum status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CompanyResponse extends BaseBean{
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
private String vatNumber;
|
||||||
|
private String codiceFiscale;
|
||||||
|
private String address;
|
||||||
|
private String phoneNumber;
|
||||||
|
private String city;
|
||||||
|
private String province;
|
||||||
|
private String cap;
|
||||||
|
private String country;
|
||||||
|
private String pec;
|
||||||
|
private String email;
|
||||||
|
private String numberOfEmployees;
|
||||||
|
private BigDecimal annualRevenue;
|
||||||
|
private Boolean isLegalRepresentant;
|
||||||
|
private String contactName;
|
||||||
|
private String contactEmail;
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ public class FormResponseBean {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
private String callStatus;
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
private Long callId;
|
private Long callId;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class LoginAttemptPageableResponseBean<T> implements Serializable {
|
||||||
|
|
||||||
|
private transient T body;
|
||||||
|
|
||||||
|
private Long totalRecords;
|
||||||
|
|
||||||
|
private int currentPage;
|
||||||
|
|
||||||
|
private int totalPages;
|
||||||
|
|
||||||
|
private int pageSize;
|
||||||
|
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -36,7 +37,25 @@ public class LoginResponse {
|
|||||||
|
|
||||||
private LocalDateTime lastLogin;
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
|
||||||
|
private Boolean privacy;
|
||||||
|
|
||||||
|
private Boolean terms;
|
||||||
|
|
||||||
|
private Boolean marketing;
|
||||||
|
|
||||||
|
private Boolean offers;
|
||||||
|
|
||||||
|
private Boolean thirdParty;
|
||||||
|
|
||||||
|
private String emailPec;
|
||||||
|
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
private List<CompanyResponse> companies;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.model.response;
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class NextOrPreviousFormResponse {
|
public class NextOrPreviousFormResponse {
|
||||||
@@ -17,6 +18,14 @@ public class NextOrPreviousFormResponse {
|
|||||||
|
|
||||||
private Long currentStep;
|
private Long currentStep;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
private Long protocolNumber;
|
||||||
|
|
||||||
|
private ApplicationStatusTypeEnum applicationStatus;
|
||||||
|
|
||||||
private FormApplicationResponse applicationFormResponse;
|
private FormApplicationResponse applicationFormResponse;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SuperAdminWidgetResponseBean {
|
||||||
|
|
||||||
|
private Widget1 widget1;
|
||||||
|
|
||||||
|
// private List<Object[]> widgetBars;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SystemEmailTemplateResponse {
|
||||||
|
|
||||||
|
String htmlContent;
|
||||||
|
|
||||||
|
String subject;
|
||||||
|
|
||||||
|
Map<String, String> jsonMap;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class UploadFileOnAmazonS3Response {
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
|||||||
import net.gepafin.tendermanagement.model.BaseBean;
|
import net.gepafin.tendermanagement.model.BaseBean;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -33,4 +34,17 @@ public class UserResponseBean extends BaseBean {
|
|||||||
|
|
||||||
private LocalDateTime lastLogin;
|
private LocalDateTime lastLogin;
|
||||||
|
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
|
||||||
|
private List<CompanyResponse> companies;
|
||||||
|
private Boolean privacy;
|
||||||
|
private Boolean terms;
|
||||||
|
|
||||||
|
private Boolean marketing;
|
||||||
|
private Boolean offers;
|
||||||
|
private Boolean thirdParty;
|
||||||
|
|
||||||
|
private String emailPec;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserSamlResponse {
|
||||||
|
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private LocalDateTime dateOfBirth;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class Widget1 {
|
||||||
|
|
||||||
|
private Long numberOfActiveCalls;
|
||||||
|
|
||||||
|
private Long numberOfResgisteredUsers;
|
||||||
|
|
||||||
|
// private Long preInvestigationQuestions;
|
||||||
|
|
||||||
|
private Long numberOfSubmittedApplications;
|
||||||
|
|
||||||
|
private Long numberOfDraftApplications;
|
||||||
|
|
||||||
|
private Long numberOfCompany;
|
||||||
|
|
||||||
|
private BigDecimal totalActiveFinancing;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FaqEntity;
|
|
||||||
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.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;
|
||||||
@@ -11,9 +11,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ApplicationRepository extends JpaRepository<ApplicationEntity,Long> {
|
public interface ApplicationRepository extends JpaRepository<ApplicationEntity, Long>, JpaSpecificationExecutor<ApplicationEntity> {
|
||||||
|
|
||||||
public Optional<ApplicationEntity> findByUserIdAndCallIdAndIsDeletedFalse(Long userId,Long callId);
|
|
||||||
|
|
||||||
public List<ApplicationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
public List<ApplicationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||||
|
|
||||||
@@ -23,4 +21,24 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,L
|
|||||||
public List<ApplicationEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
public List<ApplicationEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
||||||
|
|
||||||
public List<ApplicationEntity> findByIsDeletedFalse();
|
public List<ApplicationEntity> findByIsDeletedFalse();
|
||||||
|
|
||||||
|
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
||||||
|
|
||||||
|
Optional<ApplicationEntity> findByUserIdAndCompanyIdAndCallIdAndIsDeletedFalse(Long userId, Long companyId, Long callId);
|
||||||
|
|
||||||
|
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
||||||
|
Long callId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' ")
|
||||||
|
Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT'")
|
||||||
|
Long countSubmittedApplications();
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT'")
|
||||||
|
Long countDraftApplications();
|
||||||
|
|
||||||
|
List<ApplicationEntity> findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationSignedDocumentEntity;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ApplicationSignedDocumentRepository extends JpaRepository<ApplicationSignedDocumentEntity, Long> {
|
||||||
|
|
||||||
|
ApplicationSignedDocumentEntity findByApplicationIdAndStatus(Long applicationId, String status);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface BeneficiaryPreferredCallRepository extends JpaRepository<BeneficiaryPreferredCallEntity, Long> {
|
||||||
|
List<BeneficiaryPreferredCallEntity> findByBeneficiaryId(Long beneficiaryId);
|
||||||
|
List<BeneficiaryPreferredCallEntity> findByUserId(Long userId);
|
||||||
|
|
||||||
|
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId)")
|
||||||
|
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyId(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||||
|
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@ package net.gepafin.tendermanagement.repositories;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.SamlResponseLogEntity;
|
import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface SamlResponseLogRepository extends JpaRepository<SamlResponseLogEntity, Long> {
|
public interface BeneficiaryRepository extends JpaRepository<BeneficiaryEntity, Long> {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,10 @@ package net.gepafin.tendermanagement.repositories;
|
|||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
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 java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@@ -13,4 +15,14 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
|
|||||||
List<CallEntity> findByStatusIn(List<String> callStatus);
|
List<CallEntity> findByStatusIn(List<String> callStatus);
|
||||||
|
|
||||||
public CallEntity findByIdAndStatus(Long id,String status);
|
public CallEntity findByIdAndStatus(Long id,String status);
|
||||||
|
|
||||||
|
public Long countByStatus(String status);
|
||||||
|
|
||||||
|
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
|
||||||
|
BigDecimal findTotalAmountOfPublishedCalls();
|
||||||
|
|
||||||
|
@Query("SELECT c.name, COUNT(a.id) " +
|
||||||
|
"FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " +
|
||||||
|
"GROUP BY c.name")
|
||||||
|
List<Object[]> findApplicationsPerCall();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CompanyRepository extends JpaRepository<CompanyEntity, Long> {
|
||||||
|
|
||||||
|
List<CompanyEntity> findByIdIn(List<Long> companyIds);
|
||||||
|
|
||||||
|
Boolean existsByVatNumber(String vatNumber);
|
||||||
|
CompanyEntity findByVatNumber(String vatNumber);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(c) FROM CompanyEntity c")
|
||||||
|
long countTotalCompanies();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,5 +19,8 @@ public interface DocumentRepository extends JpaRepository<DocumentEntity, Long>
|
|||||||
|
|
||||||
Optional<DocumentEntity> findByIdAndSourceIdAndIsDeletedFalse(Long id, Long sourceId);
|
Optional<DocumentEntity> findByIdAndSourceIdAndIsDeletedFalse(Long id, Long sourceId);
|
||||||
|
|
||||||
|
List<DocumentEntity> findBySource(String source);
|
||||||
|
List<DocumentEntity> findBySourceIdAndSourceAndTypeAndIsDeletedFalse(Long sourceId, String source, String type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface LoginAttemptRepository extends JpaRepository<LoginAttemptEntity,Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.ProtocolEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ProtocolRepository extends JpaRepository<ProtocolEntity,Long> {
|
||||||
|
|
||||||
|
@Query("SELECT MAX(p.protocolNumber) FROM ProtocolEntity p")
|
||||||
|
Long findMaxProtocolNumber();
|
||||||
|
}
|
||||||
@@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface RoleRepository extends JpaRepository<RoleEntity, Long> {
|
public interface RoleRepository extends JpaRepository<RoleEntity, Long> {
|
||||||
|
|
||||||
|
RoleEntity findByRoleType(String roleType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.SamlResponseEntity;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface SamlResponseRepository extends JpaRepository<SamlResponseEntity, Long> {
|
||||||
|
|
||||||
|
SamlResponseEntity findByToken(String token);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity;
|
||||||
|
|
||||||
|
public interface SystemEmailTemplatesRespository extends JpaRepository<SystemEmailTemplatesEntity, Long> {
|
||||||
|
|
||||||
|
// @Query("select s from SystemEmailTemplatesEntity s where s.type=:type and s.call.id=:callId and s.isDeleted =false and s.system = false")
|
||||||
|
// SystemEmailTemplatesEntity findByTypeAndCallId(@Param("type") String type, @Param("callId") Long callId);
|
||||||
|
|
||||||
|
@Query("select s from SystemEmailTemplatesEntity s where s.type=:type and s.isDeleted =false and s.system = true")
|
||||||
|
SystemEmailTemplatesEntity findByType(@Param("type") String type);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
|
||||||
|
|
||||||
|
public interface UserCompanyDelegationRepository extends JpaRepository<UserCompanyDelegationEntity, Long> {
|
||||||
|
|
||||||
|
UserCompanyDelegationEntity findByUserIdAndCompanyIdAndStatus(Long userId, Long companyId, String status);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
|
||||||
|
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.UserHubEntity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface UserHubRepository extends JpaRepository<UserHubEntity, Long> {
|
|
||||||
List<UserHubEntity> findByHubId(String hubId);
|
|
||||||
UserHubEntity findByHubIdAndUserId(String hubId, Long userId);
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,31 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||||
Optional<UserEntity> findByEmailIgnoreCase(String email);
|
|
||||||
boolean existsByEmailIgnoreCase(String email);
|
// Optional<UserEntity> findByEmailIgnoreCase(String email);
|
||||||
UserEntity findByEmail(String email);
|
|
||||||
|
// boolean existsByEmailIgnoreCase(String email);
|
||||||
|
|
||||||
|
// UserEntity findByEmail(String email);
|
||||||
|
|
||||||
|
Optional<UserEntity> findByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||||
|
|
||||||
|
boolean existsByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||||
|
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
||||||
|
|
||||||
|
Long countByStatusAndRoleEntityRoleType(String status, String roleName);
|
||||||
|
List<UserEntity> findByRoleEntityId(Long roleId);
|
||||||
|
|
||||||
|
Optional<UserEntity> findByEmailIgnoreCaseAndhubUniqueUuid(String email, String hubId);
|
||||||
|
|
||||||
|
boolean existsByEmailIgnoreCaseAndhubUniqueUuid(String email, String hubUuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
|
|
||||||
|
|
||||||
|
public interface UserWithCompanyRepository extends JpaRepository<UserWithCompanyEntity, Long> {
|
||||||
|
|
||||||
|
void deleteByCompanyIdAndIsDeletedFalse(Long companyId);
|
||||||
|
|
||||||
|
@Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false")
|
||||||
|
List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(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