Commit caeaf92c authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/payments-service!16
parents 92f79832 64f30a75
theGroup=ee.sm.ti.teis
theVersion=1.0.0
theVersion=1.1.0
pluginVersion=1.0.0
commonsVersion=1.1.0
commonApiGatewayVersion=1.0.0
commonsVersion=1.2.0
commonApiGatewayVersion=1.2.0
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
package ee.sm.ti.teis.payments.claim.service;
import ee.sm.ti.teis.cache.classifier.ClassifierService;
import ee.sm.ti.teis.cache.person.PersonService;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.payments.claim.Claim;
import ee.sm.ti.teis.domain.payments.claim.DataObjectReference;
import ee.sm.ti.teis.domain.payments.claim.PatchClaim;
import ee.sm.ti.teis.errors.ConstraintViolationDto;
import ee.sm.ti.teis.exceptions.TeisBusinessException;
import ee.sm.ti.teis.exceptions.TeisConstraintViolationException;
import ee.sm.ti.teis.payments.claim.ClaimErrorCode;
import ee.sm.ti.teis.payments.claim.entity.ClaimDefinitionEntity;
import ee.sm.ti.teis.payments.claim.entity.ClaimEntity;
import ee.sm.ti.teis.payments.claim.entity.DataObjectReferenceEntity;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.transaction.Transactional;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.payments.claim.service.ClaimValidationService.validateCreate;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.VALID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.OBJECT_TYPE;
import static java.util.stream.Collectors.toList;
import static org.hibernate.sql.InFragment.NOT_NULL;
import static org.springframework.util.StringUtils.isEmpty;
@Service
@Transactional
@Validated
public class ClaimBusinessMsService {
private final ClaimDefinitionDataService definitionDataService;
private final PersonService personService;
private final ClassifierService classifierService;
private final ClaimComposeService composeService;
private final TaskNotifyService taskNotifyService;
private final ClaimDataService dataService;
private final DataObjectReferenceDataService dataObjectReferenceDataService;
private final ClaimValidationService validationService;
private final AuditNotifyService auditNotifyService;
private final CreateClaimService createClaimService;
public ClaimBusinessMsService(ClaimDefinitionDataService definitionDataService, PersonService personService,
ClassifierService classifierService, ClaimComposeService composeService,
public ClaimBusinessMsService(ClaimComposeService composeService,
TaskNotifyService taskNotifyService, ClaimDataService dataService,
DataObjectReferenceDataService dataObjectReferenceDataService,
ClaimValidationService validationService, AuditNotifyService auditNotifyService) {
this.definitionDataService = definitionDataService;
this.personService = personService;
this.classifierService = classifierService;
ClaimValidationService validationService, AuditNotifyService auditNotifyService,
CreateClaimService createClaimService) {
this.composeService = composeService;
this.taskNotifyService = taskNotifyService;
this.dataService = dataService;
this.dataObjectReferenceDataService = dataObjectReferenceDataService;
this.validationService = validationService;
this.auditNotifyService = auditNotifyService;
this.createClaimService = createClaimService;
}
public List<Claim> getMSClaims(UUID dataObjectId,
......@@ -72,92 +53,8 @@ public class ClaimBusinessMsService {
.collect(toList());
}
private static void setStatus(Claim claimDto, ClaimEntity entity) {
if (!isEmpty(claimDto.getStatus())) {
entity.setStatus(claimDto.getStatus());
} else {
entity.setStatus(VALID);
}
}
private static void setIssuedDate(Claim claimDto, ClaimEntity entity) {
if (claimDto.getIssuedDate() != null) {
entity.setIssuedDate(claimDto.getIssuedDate());
} else {
entity.setIssuedDate(LocalDate.now());
}
}
private static void setNotForBulkChange(DataObjectReference reference, DataObjectReferenceEntity dataObjectReference) {
if (reference.getNotForBulkChange() != null) {
dataObjectReference.setNotForBulkChange(reference.getNotForBulkChange());
} else {
dataObjectReference.setNotForBulkChange(false);
}
}
private static void setClaimValues(Claim domain, ClaimDefinitionEntity claimDefinition, ClaimEntity entity) {
entity.setClaimDefinition(claimDefinition);
entity.setEmployerId(domain.getEmployer().getId());
setIssuedDate(domain, entity);
entity.setAmount(domain.getAmount());
entity.setBalance(domain.getAmount());
entity.setDeadlineDate(domain.getDeadlineDate());
entity.setReference(domain.getReference());
setStatus(domain, entity);
setPaymentDescription(domain, entity, claimDefinition);
entity.setPaymentReference(claimDefinition.getPaymentReference());
entity.setObjectStatus(CURRENT);
}
private static void setPaymentDescription(Claim domain, ClaimEntity entity, ClaimDefinitionEntity claimDefinition) {
if (!isEmpty(domain.getPaymentDescription())) {
entity.setPaymentDescription(domain.getPaymentDescription());
} else {
entity.setPaymentDescription(claimDefinition.getPaymentDescription());
}
}
public Claim create(@Valid Claim domain, RequestMetaDTO requestMetaDTO) {
validateCreate(domain);
ClaimDefinitionEntity claimDefinition = definitionDataService.getCurrentByCode(domain.getClaimDefinition().getCode());
personService.getPerson(domain.getEmployer().getId(), requestMetaDTO);
ClaimEntity entity = new ClaimEntity();
setClaimValues(domain, claimDefinition, entity);
List<DataObjectReferenceEntity> dataObjectReferences = setDataObjectReferences(domain, requestMetaDTO, entity);
ClaimEntity savedEntity = dataService.save(entity);
dataObjectReferenceDataService.saveAll(dataObjectReferences);
taskNotifyService.createTask(savedEntity, requestMetaDTO);
return composeService.composeDomain(savedEntity, requestMetaDTO);
}
private List<DataObjectReferenceEntity> setDataObjectReferences(Claim domain, RequestMetaDTO requestMetaDTO,
ClaimEntity entity) {
List<DataObjectReferenceEntity> dataObjectReferences = new ArrayList<>();
if (domain.getDataObjectReferences() != null && !domain.getDataObjectReferences().isEmpty()) {
domain.getDataObjectReferences().forEach(reference -> {
DataObjectReferenceEntity dataObjectReference = new DataObjectReferenceEntity();
dataObjectReference.setDataObjectId(reference.getDataObjectId());
ClassifierItem objectTypeClassifier = classifierService.getClassifierItemByCode(OBJECT_TYPE.name(),
reference.getDataObjectType().getCode(), requestMetaDTO);
dataObjectReference.setDataObjectType(objectTypeClassifier.getId());
setNotForBulkChange(reference, dataObjectReference);
dataObjectReference.setObjectStatus(CURRENT);
dataObjectReference.setClaim(entity);
dataObjectReferences.add(dataObjectReference);
});
}
entity.setDataObjectReferences(dataObjectReferences);
return dataObjectReferences;
return createClaimService.create(domain, requestMetaDTO);
}
public void patch(@Valid PatchClaim domain, RequestMetaDTO requestMetaDTO) {
......
package ee.sm.ti.teis.payments.claim.service;
import ee.sm.ti.teis.cache.classifier.ClassifierService;
import ee.sm.ti.teis.cache.person.PersonService;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.payments.claim.Claim;
import ee.sm.ti.teis.domain.payments.claim.DataObjectReference;
import ee.sm.ti.teis.payments.claim.entity.ClaimDefinitionEntity;
import ee.sm.ti.teis.payments.claim.entity.ClaimEntity;
import ee.sm.ti.teis.payments.claim.entity.DataObjectReferenceEntity;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import static ee.sm.ti.teis.payments.claim.service.ClaimValidationService.validateCreate;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.VALID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.OBJECT_TYPE;
import static org.springframework.util.StringUtils.isEmpty;
@Service
public class CreateClaimService {
private final DataObjectReferenceDataService dataObjectReferenceDataService;
private final ClaimDefinitionDataService definitionDataService;
private final PersonService personService;
private final ClassifierService classifierService;
private final ClaimDataService dataService;
private final TaskNotifyService taskNotifyService;
private final ClaimComposeService composeService;
public CreateClaimService(DataObjectReferenceDataService dataObjectReferenceDataService,
ClaimDefinitionDataService definitionDataService, PersonService personService,
ClassifierService classifierService, ClaimDataService dataService,
TaskNotifyService taskNotifyService, ClaimComposeService composeService) {
this.dataObjectReferenceDataService = dataObjectReferenceDataService;
this.definitionDataService = definitionDataService;
this.personService = personService;
this.classifierService = classifierService;
this.dataService = dataService;
this.taskNotifyService = taskNotifyService;
this.composeService = composeService;
}
public Claim create(Claim domain, RequestMetaDTO requestMetaDTO) {
validateCreate(domain);
ClaimDefinitionEntity claimDefinition = definitionDataService.getCurrentByCode(domain.getClaimDefinition().getCode());
personService.getPerson(domain.getEmployer().getId(), requestMetaDTO);
ClaimEntity entity = new ClaimEntity();
setClaimValues(domain, claimDefinition, entity);
List<DataObjectReferenceEntity> dataObjectReferences = setDataObjectReferences(domain, requestMetaDTO, entity);
ClaimEntity savedEntity = dataService.save(entity);
dataObjectReferenceDataService.saveAll(dataObjectReferences);
taskNotifyService.createTask(savedEntity, requestMetaDTO);
return composeService.composeDomain(savedEntity, requestMetaDTO);
}
private void setClaimValues(Claim domain, ClaimDefinitionEntity claimDefinition, ClaimEntity entity) {
entity.setClaimDefinition(claimDefinition);
entity.setEmployerId(domain.getEmployer().getId());
setIssuedDate(domain, entity);
entity.setAmount(domain.getAmount());
entity.setBalance(domain.getAmount());
entity.setDeadlineDate(domain.getDeadlineDate());
entity.setReference(domain.getReference());
setStatus(domain, entity);
setPaymentDescription(domain, entity, claimDefinition);
entity.setPaymentReference(claimDefinition.getPaymentReference());
entity.setObjectStatus(CURRENT);
}
private void setIssuedDate(Claim claimDto, ClaimEntity entity) {
if (claimDto.getIssuedDate() != null) {
entity.setIssuedDate(claimDto.getIssuedDate());
} else {
entity.setIssuedDate(LocalDate.now());
}
}
private void setStatus(Claim claimDto, ClaimEntity entity) {
if (!isEmpty(claimDto.getStatus())) {
entity.setStatus(claimDto.getStatus());
} else {
entity.setStatus(VALID);
}
}
private void setPaymentDescription(Claim domain, ClaimEntity entity, ClaimDefinitionEntity claimDefinition) {
if (!isEmpty(domain.getPaymentDescription())) {
entity.setPaymentDescription(domain.getPaymentDescription());
} else {
entity.setPaymentDescription(claimDefinition.getPaymentDescription());
}
}
private List<DataObjectReferenceEntity> setDataObjectReferences(Claim domain, RequestMetaDTO requestMetaDTO,
ClaimEntity entity) {
List<DataObjectReferenceEntity> dataObjectReferences = new ArrayList<>();
if (domain.getDataObjectReferences() != null && !domain.getDataObjectReferences().isEmpty()) {
domain.getDataObjectReferences().forEach(reference -> {
DataObjectReferenceEntity dataObjectReference = new DataObjectReferenceEntity();
dataObjectReference.setDataObjectId(reference.getDataObjectId());
ClassifierItem objectTypeClassifier = classifierService.getClassifierItemByCode(OBJECT_TYPE.name(),
reference.getDataObjectType().getCode(), requestMetaDTO);
dataObjectReference.setDataObjectType(objectTypeClassifier.getId());
setNotForBulkChange(reference, dataObjectReference);
dataObjectReference.setObjectStatus(CURRENT);
dataObjectReference.setClaim(entity);
dataObjectReferences.add(dataObjectReference);
});
}
entity.setDataObjectReferences(dataObjectReferences);
return dataObjectReferences;
}
private void setNotForBulkChange(DataObjectReference reference, DataObjectReferenceEntity dataObjectReference) {
if (reference.getNotForBulkChange() != null) {
dataObjectReference.setNotForBulkChange(reference.getNotForBulkChange());
} else {
dataObjectReference.setNotForBulkChange(false);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment