Added user action and versioning for company.
This commit is contained in:
@@ -2,10 +2,14 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -38,25 +42,38 @@ public class CompanyDao {
|
||||
@Autowired
|
||||
private FaqRepository faqRepository;
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||
|
||||
CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
|
||||
UserWithCompanyEntity userWithCompanyEntity = null;
|
||||
if (existingCompany != null) {
|
||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId())
|
||||
.orElse(null);
|
||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
|
||||
if (existingRelation == null) {
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant());
|
||||
|
||||
/** This code is responsible for adding a version history log for "adding user with company" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompanyEntity).build());
|
||||
} else {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY));
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY));
|
||||
}
|
||||
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||
} else {
|
||||
validateCompany(userEntity, companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
|
||||
companyRepository.save(companyEntity);
|
||||
CompanyEntity companyData = companyRepository.save(companyEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for "creating company" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
|
||||
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
||||
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
}
|
||||
}
|
||||
@@ -80,6 +97,7 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) {
|
||||
|
||||
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
userWithCompanyEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||
@@ -88,7 +106,11 @@ public class CompanyDao {
|
||||
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
||||
userWithCompanyEntity.setUserId(userEntity.getId());
|
||||
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
||||
return userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build());
|
||||
return userWithCompany;
|
||||
}
|
||||
|
||||
private CompanyEntity convertCompanyRequestToCompanyEntity(UserEntity userEntity, CompanyRequest request) {
|
||||
@@ -139,32 +161,43 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public CompanyResponse updateCompany(UserEntity userEntity, Long companyId, CompanyRequest companyRequest) {
|
||||
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName,
|
||||
companyRequest.getCompanyName());
|
||||
//cloned entity for old data
|
||||
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
|
||||
|
||||
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName());
|
||||
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
|
||||
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale,
|
||||
companyRequest.getCodiceFiscale());
|
||||
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale());
|
||||
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
||||
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber,
|
||||
companyRequest.getPhoneNumber());
|
||||
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());
|
||||
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);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyData).newData(companyEntity).build());
|
||||
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
|
||||
companyRequest.getIsLegalRepresentant());
|
||||
userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
//cloned entity for old data
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||
|
||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
||||
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserWithCompanyData).newData(userWithCompanyEntity).build());
|
||||
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
}
|
||||
|
||||
@@ -179,8 +212,20 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public void deleteCompany(UserEntity userEntity, Long companyId) {
|
||||
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "delete company" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.DELETE).oldData(companyEntity).newData(null).build());
|
||||
|
||||
companyRepository.delete(companyEntity);
|
||||
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "delete user with company" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.DELETE).oldData(userWithCompanyEntity).newData(null).build());
|
||||
|
||||
userWithCompanyRepository.deleteByCompanyIdAndIsDeletedFalse(companyId);
|
||||
}
|
||||
|
||||
@@ -204,26 +249,44 @@ public class CompanyDao {
|
||||
() -> 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.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()))) {
|
||||
if (Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.DRAFT.getValue()))) {
|
||||
|
||||
//cloned entity for old data
|
||||
ApplicationEntity oldApplicationData = Utils.getClonedEntityForData(application);
|
||||
application.setIsDeleted(Boolean.TRUE);
|
||||
applicationRepository.save(application);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldApplicationData).newData(application).build());
|
||||
}
|
||||
}
|
||||
for(FaqEntity faq:faqs) {
|
||||
for (FaqEntity faq : faqs) {
|
||||
//cloned for old data
|
||||
FaqEntity oldFaqEntityData = Utils.getClonedEntityForData(faq);
|
||||
faq.setIsDeleted(Boolean.TRUE);
|
||||
faqRepository.save(faq);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "soft deleting faq" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaqEntityData).newData(faq).build());
|
||||
}
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(existingRelation);
|
||||
existingRelation.setIsDeleted(Boolean.TRUE);
|
||||
userWithCompanyRepository.save(existingRelation);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "soft deleting existing user relation" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserWithCompanyData).newData(existingRelation).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import java.util.function.Function;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -67,6 +70,12 @@ public class DelegationDao {
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||
try {
|
||||
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L);
|
||||
@@ -177,17 +186,21 @@ public class DelegationDao {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
UserCompanyDelegationEntity oldUserCompanyDelegationEntity = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
if (userCompanyDelegationEntity != null) {
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update user company delegation status" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserCompanyDelegationEntity)
|
||||
.newData(userCompanyDelegationEntity).build());
|
||||
}
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
|
||||
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
||||
@@ -200,8 +213,14 @@ public class DelegationDao {
|
||||
userCompanyDelegationEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
|
||||
userCompanyDelegationEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Insert or upload user company delegation" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null)
|
||||
.newData(userCompanyDelegationEntity).build());
|
||||
|
||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||
}
|
||||
|
||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3ForCompanyDelegation(MultipartFile file) {
|
||||
try {
|
||||
String s3Path = generateS3PathForDelegation();
|
||||
@@ -247,15 +266,22 @@ public class DelegationDao {
|
||||
}
|
||||
|
||||
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), 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));
|
||||
//cloned entity for old data
|
||||
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
|
||||
if (userCompanyDelegationEntity == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||
}
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Soft Deleting company delegation " operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserCompanyDelegation).newData(userCompanyDelegationEntity)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import feign.FeignException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
@@ -38,9 +43,14 @@ public class VatCheckDao {
|
||||
|
||||
public final Logger log = LoggerFactory.getLogger(VatCheckDao.class);
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public Map<String, Object> checkVatNumberApi(String vatNumber) {
|
||||
|
||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
@@ -50,11 +60,14 @@ public class VatCheckDao {
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set(GepafinConstant.AUTHORIZATION, "Bearer " + vatCheckNewToken);
|
||||
headers.add(org.apache.http.HttpHeaders.USER_AGENT,
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
|
||||
headers.add(org.apache.http.HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
|
||||
|
||||
URI baseUrl = URI.create(GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL);
|
||||
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl,vatNumber, headers);
|
||||
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl, vatNumber, headers);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Download company delegation" operation. **/
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build());
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
||||
log.info("Successfully checked vat number");
|
||||
|
||||
@@ -45,6 +45,19 @@ public enum UserActionContextEnum {
|
||||
UPDATE_FAQ_DETAILS("UPDATE_FAQ_DETAILS"),
|
||||
DELETE_FAQ("DELETE_FAQ"),
|
||||
|
||||
/** company action context **/
|
||||
CREATE_COMPANY("CREATE_COMPANY"),
|
||||
GET_COMPANY("GET_COMPANY"),
|
||||
UPDATE_COMPANY("UPDATE_COMPANY"),
|
||||
DELETE_COMPANY("DELETE_COMPANY"),
|
||||
UPLOAD_COMPANY_DELEGATION("UPLOAD_COMPANY_DELEGATION"),
|
||||
DOWNLOAD_COMPANY_DELEGATION_TEMPLATE("DOWNLOAD_COMPANY_DELEGATION_TEMPLATE"),
|
||||
GET_COMPANY_DELEGATION("GET_COMPANY_DELEGATION"),
|
||||
DELETE_COMPANY_DELEGATION("DELETE_COMPANY_DELEGATION"),
|
||||
CHECK_COMPANY_VAT_NUMBER("CHECK_COMPANY_VAT_NUMBER"),
|
||||
GET_COMPANY_BY_USER("GET_COMPANY_BY_USER"),
|
||||
REMOVE_COMPANY_FROM_USER("REMOVE_COMPANY_FROM_USER"),
|
||||
|
||||
/** LookUpData action context **/
|
||||
CREATE_LOOKUP_DATA("CREATE_LOOKUP_DATA"),
|
||||
DELETE_LOOKUP_DATA("DELETE_LOOKUP_DATA"),
|
||||
@@ -75,8 +88,7 @@ public enum UserActionContextEnum {
|
||||
CREATE_ASSIGNED_APPLICATION("CREATE_ASSIGNED_APPLICATION"),
|
||||
DELETE_ASSIGNED_APPLICATION("DELETE_ASSIGNED_APPLICATION"),
|
||||
GET_ASSIGNED_APPLICATION("GET_ASSIGNED_APPLICATION"),
|
||||
UPDATE_ASSIGNED_APPLICATION_DETAILS("UPDATE_ASSIGNED_APPLICATION_DETAILS")
|
||||
;
|
||||
UPDATE_ASSIGNED_APPLICATION_DETAILS("UPDATE_ASSIGNED_APPLICATION_DETAILS");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
@Transactional
|
||||
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
return delegationDao.getCompanyDelegation(userEntity, companyId);
|
||||
@@ -114,7 +114,8 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCompanyDelegation(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
delegationDao.deleteCompanyDelegation(userEntity, companyId);
|
||||
}
|
||||
public UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId){
|
||||
|
||||
@@ -4,6 +4,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,10 +40,17 @@ public class CompanyApiController implements CompanyApi{
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyResponse>> createCompany(HttpServletRequest request,
|
||||
CompanyRequest companyRequest) {
|
||||
log.info("Create company with - Request Body: {}", companyRequest);
|
||||
|
||||
/** This code is responsible for creating user action logs for "Creating company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.CREATE_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.createCompany(request, companyRequest);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_CREATED_SUCCESS_MSG)));
|
||||
@@ -49,6 +60,10 @@ public class CompanyApiController implements CompanyApi{
|
||||
public ResponseEntity<Response<CompanyResponse>> updateCompany(HttpServletRequest request, Long companyId,
|
||||
CompanyRequest companyRequest) {
|
||||
log.info("Update company with - Request Body: {}", companyRequest);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "update company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.UPDATE_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.updateCompany(request, companyId, companyRequest);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
@@ -59,15 +74,22 @@ public class CompanyApiController implements CompanyApi{
|
||||
public ResponseEntity<Response<CompanyResponse>> getCompany(HttpServletRequest request, Long companyId) {
|
||||
|
||||
log.info("Get company with id: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "get company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.getCompany(request, companyId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_GET_SUCCESS_MSG)));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_GET_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteCompany(HttpServletRequest request, Long companyId) {
|
||||
log.info("Delete company with id: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "delete company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_COMPANY).build());
|
||||
|
||||
companyService.deleteCompany(request, companyId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
@@ -78,6 +100,10 @@ public class CompanyApiController implements CompanyApi{
|
||||
public ResponseEntity<Response<List<CompanyResponse>>> getCompanyByUserId(HttpServletRequest request, Long userId) {
|
||||
|
||||
log.info("Get company with userId: {}", userId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get company by user id" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_BY_USER).build());
|
||||
|
||||
List<CompanyResponse> data = companyService.getCompanyByUserId(request, userId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
@@ -87,6 +113,10 @@ public class CompanyApiController implements CompanyApi{
|
||||
@Override
|
||||
public ResponseEntity<Response<Map<String,Object>>> checkVatNumber(HttpServletRequest request, String vatNumber) {
|
||||
log.info("check VatNumber with: {}", vatNumber);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Check vat number" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build());
|
||||
|
||||
Map<String,Object> data = companyService.checkVatNumber(request, vatNumber);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.CHECK_VATNUMBER_SUCCESS_MSG)));
|
||||
@@ -95,6 +125,10 @@ public class CompanyApiController implements CompanyApi{
|
||||
@Override
|
||||
public ResponseEntity<byte[]> downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
log.info("download company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Download company delegation" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DOWNLOAD).actionContext(UserActionContextEnum.DOWNLOAD_COMPANY_DELEGATION_TEMPLATE).build());
|
||||
|
||||
ByteArrayOutputStream data = companyService.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
@@ -107,6 +141,10 @@ public class CompanyApiController implements CompanyApi{
|
||||
public ResponseEntity<Response<CompanyDelegationResponse>> uploadCompanyDelegation(HttpServletRequest request, Long companyId,
|
||||
MultipartFile file) {
|
||||
log.info("upload company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Uploading company delegation document" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPLOAD).actionContext(UserActionContextEnum.UPLOAD_COMPANY_DELEGATION).build());
|
||||
|
||||
CompanyDelegationResponse companyDelegationResponse = companyService.uploadCompanyDelegation(request, companyId, file);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FILE_UPLOAD_SUCCESS)));
|
||||
@@ -116,21 +154,33 @@ public class CompanyApiController implements CompanyApi{
|
||||
public ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
||||
Long companyId) {
|
||||
log.info("get company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get company delegation" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_DELEGATION).build());
|
||||
|
||||
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FETCH_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request,
|
||||
Long companyId) {
|
||||
public ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request, Long companyId) {
|
||||
|
||||
log.info("delete company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "delete company delegation" operation. **/
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_COMPANY_DELEGATION).build());
|
||||
|
||||
companyService.deleteCompanyDelegation(request, companyId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_DELETE_SUCCESS)));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_DELETE_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> removeCompanyFromList(HttpServletRequest request, Long companyId) {
|
||||
log.info("Api to remove a company from user's list");
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Remove company from user list" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.REMOVE_COMPANY_FROM_USER).build());
|
||||
|
||||
companyService.removeCompanyFromList(request, companyId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
|
||||
Reference in New Issue
Block a user