Commit 55d1314f authored by Hando Lukats's avatar Hando Lukats
Browse files

Merge branch 'TEIS-2380' of...

Merge branch 'TEIS-2380' of https://gitlab.sotsiaalministeerium.ee/teis/riskassessments-service into develop

 Conflicts:
	service/src/main/java/ee/sm/ti/teis/riskassessments/riskassessment/service/RiskAssessmentPDFService.java
parents 63d432c4 2384cfad
......@@ -41,7 +41,6 @@ import static java.util.stream.Collectors.toList;
@Validated
public class RiskAssessmentPDFService {
//TODO text values should be in properties file or similar
private static final String ADDITIONAL_RISK_FACTORS = "Täiendavad ohud";
private static final String ADDED_TO_ACTION_PLAN = "Abinõu on lisatud tegevuskavasse";
private static final String NO_ACTION_NEEDED = "Abinõud ei ole vaja rakendada";
......@@ -81,7 +80,6 @@ public class RiskAssessmentPDFService {
dto.setTitle(riskAssessment.getTitle());
dto.setArchivedDate(riskAssessment.getArchivedDate());
dto.setStatus(riskAssessmentStatus);
dto.setPublishedDate(riskAssessment.getPublishedDate());
dto.setEmployerName(employer.getLegalPerson().getName());
dto.setRegCode(employer.getLegalPerson().getRegCode());
dto.setSecondaryBusinessTypes(secondaryBusinessTypeNames);
......@@ -104,29 +102,21 @@ public class RiskAssessmentPDFService {
RequestMetaDTO requestMetaDTO, List<RiskFactorAssessmentEntity> riskFactorAssessments) {
List<RiskFactorPdfCategoryDto> categoryList = new ArrayList<>();
riskFactorAssessments.forEach(riskFactorAssessment -> {
if (riskFactorAssessment.getRiskFactorId() != null && BooleanUtils.isTrue(riskFactorAssessment.getAdditional())) {
setRiskFactor(riskAssessmentId, requestMetaDTO, categoryList, riskFactorAssessment, ADDITIONAL_RISK_FACTORS, null, riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null);
} else if (riskFactorAssessment.getRiskFactorId() != null) {
setRiskFactorByClassifier(categoryList, riskFactorAssessment, requestMetaDTO);
} else {
setRiskFactor(riskAssessmentId, requestMetaDTO, categoryList, riskFactorAssessment, ADDITIONAL_RISK_FACTORS, null, riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null);
if (BooleanUtils.isFalse(riskFactorAssessment.getAdditional()) && riskFactorAssessment.getRiskFactorId() != null) {
setRiskFactorCategoryByClassifier(categoryList, riskFactorAssessment, requestMetaDTO);
} else if (BooleanUtils.isTrue(riskFactorAssessment.getAdditional()) || riskFactorAssessment.getRiskFactorId() != null) {
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(ADDITIONAL_RISK_FACTORS, null);
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, ADDITIONAL_RISK_FACTORS);
RiskFactorPdfDto riskFactor = pdfComposeService.composeRiskFactorPdfDto(riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null);
setRiskStatementAssessments(riskAssessmentId, riskFactorAssessment.getId(), riskFactor, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactor);
}
});
categoryList.sort(Comparator.comparing(RiskFactorPdfCategoryDto::getSeqNo, Comparator.nullsLast(Comparator.reverseOrder())).thenComparing(RiskFactorPdfCategoryDto::getName, Comparator.nullsLast(Comparator.reverseOrder())));
categoryList.sort(Comparator.comparing(RiskFactorPdfCategoryDto::getSeqNo, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(RiskFactorPdfCategoryDto::getName));
return categoryList;
}
private void setRiskFactor(UUID riskAssessmentId, RequestMetaDTO requestMetaDTO,
List<RiskFactorPdfCategoryDto> categoryList, RiskFactorAssessmentEntity riskFactorAssessment,
String additionalRiskFactors, Long o, String name, String description, String o2) {
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(additionalRiskFactors, o);
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, additionalRiskFactors);
RiskFactorPdfDto riskFactor = pdfComposeService.composeRiskFactorPdfDto(name, description, o2);
setRiskStatementAssessments(riskAssessmentId, riskFactorAssessment.getId(), riskFactor, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactor);
}
private void setRiskStatementAssessments(UUID riskAssessmentId,
UUID riskFactorAssessmentId, RiskFactorPdfDto riskFactor, RequestMetaDTO requestMetaDTO) {
List<RiskStatementAssessmentEntity> riskStatementAssessments = riskStatementAssessmentDataService.getCurrentByRiskFactorAssessmentId(riskFactorAssessmentId);
......@@ -192,12 +182,16 @@ public class RiskAssessmentPDFService {
return taskServiceClient.getTasks(taskQuery, requestMetaDTO);
}
private void setRiskFactorByClassifier(List<RiskFactorPdfCategoryDto> categoryList,
private void setRiskFactorCategoryByClassifier(List<RiskFactorPdfCategoryDto> categoryList,
RiskFactorAssessmentEntity riskFactorAssessment, RequestMetaDTO requestMetaDTO) {
RiskFactorEntity riskFactor = riskFactorDataService.getCurrentById(riskFactorAssessment.getRiskFactorId());
ClassifierItem categoryClassifier = classifierService.getClassifierItem(riskFactor.getCategory(), requestMetaDTO);
setRiskFactor(riskFactorAssessment.getRiskAssessmentId(), requestMetaDTO, categoryList, riskFactorAssessment, categoryClassifier.getName(), categoryClassifier.getSeqNo(), riskFactor.getName(), riskFactor.getImpact(), riskFactorAssessment.getDescription());
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(categoryClassifier.getName(), categoryClassifier.getSeqNo());
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, categoryClassifier.getName());
RiskFactorPdfDto riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactor.getName(), riskFactor.getImpact(), riskFactorAssessment.getDescription());
setRiskStatementAssessments(riskFactorAssessment.getRiskAssessmentId(), riskFactorAssessment.getId(), riskFactorData, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactorData);
}
private Optional<RiskFactorPdfCategoryDto> getExistingRiskFactorCategory(
......
Markdown is supported
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