Commit 9e0f28ed authored by Hando Lukats's avatar Hando Lukats
Browse files

TEIS-2452; implemented changes from testing

parent b4810067
......@@ -36,8 +36,9 @@ public class RiskAssessmentPDFComposeService {
private final RiskIndicatorDataService riskIndicatorDataService;
private final FileReferenceBusinessService fileReferenceBusinessService;
public RiskFactorPdfCategoryDto composeRiskFactorCategoryDto(String name, Long seqNo) {
public RiskFactorPdfCategoryDto composeRiskFactorCategoryDto(String name, Long seqNo, boolean additional) {
return RiskFactorPdfCategoryDto.builder()
.additional(additional)
.name(name)
.seqNo(seqNo)
.build();
......
......@@ -80,9 +80,11 @@ public class RiskAssessmentPDFService {
RiskAssessmentPdfDto dto = new RiskAssessmentPdfDto();
String riskAssessmentStatus = calculateStatus(riskAssessment.getStatus().getCode());
dto.setTitle(riskAssessment.getTitle());
dto.setArchivedDate(riskAssessment.getArchivedDate());
dto.setPublishedDate(riskAssessment.getPublishedDate());
dto.setStatus(riskAssessmentStatus);
if (!dto.getStatus().equals(RISK_ASSESSMENT_INCOMPLETE)) {
dto.setArchivedDate(riskAssessment.getArchivedDate());
dto.setPublishedDate(riskAssessment.getPublishedDate());
}
dto.setEmployerName(employer.getLegalPerson().getName());
dto.setRegCode(employer.getLegalPerson().getRegCode());
dto.setSecondaryBusinessTypes(secondaryBusinessTypeNames);
......@@ -108,7 +110,7 @@ public class RiskAssessmentPDFService {
if (BooleanUtils.isFalse(riskFactorAssessment.getAdditional()) && riskFactorAssessment.getRiskFactorId() != null) {
setRiskFactorCategoryByClassifier(categoryList, riskFactorAssessment, requestMetaDTO);
} else if (BooleanUtils.isTrue(riskFactorAssessment.getAdditional())) {
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(ADDITIONAL_RISK_FACTORS, null);
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(ADDITIONAL_RISK_FACTORS, null, true);
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, ADDITIONAL_RISK_FACTORS);
RiskFactorPdfDto riskFactor;
if (riskFactorAssessment.getRiskFactorId() != null) {
......@@ -122,12 +124,21 @@ public class RiskAssessmentPDFService {
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactor);
}
});
sortCategories(categoryList);
return categoryList;
}
private void sortCategories(List<RiskFactorPdfCategoryDto> categoryList) {
categoryList.sort(Comparator.comparing(RiskFactorPdfCategoryDto::getSeqNo, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(RiskFactorPdfCategoryDto::getName, Comparator.nullsLast(Comparator.naturalOrder())));
.thenComparing(RiskFactorPdfCategoryDto::getName, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(RiskFactorPdfCategoryDto::isAdditional));
categoryList.sort((first, second) -> {
boolean b1 = first.getName().equals(ADDITIONAL_RISK_FACTORS);
boolean b2 = second.getName().equals(ADDITIONAL_RISK_FACTORS);
return (b1 != b2) ? (b1) ? 1 : -1 : 0;
});
categoryList.forEach(category -> {
category.getRiskFactors().sort(Comparator.comparing(RiskFactorPdfDto::getSeqNo, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(RiskFactorPdfDto::getName));
});
return categoryList;
}
private void setRiskStatementAssessments(UUID riskAssessmentId,
......@@ -208,7 +219,7 @@ public class RiskAssessmentPDFService {
RiskFactorEntity riskFactor = riskFactorDataService.getCurrentById(riskFactorAssessment.getRiskFactorId());
ClassifierItem categoryClassifier = classifierService.getClassifierItem(riskFactor.getCategory(), requestMetaDTO);
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(categoryClassifier.getName(), categoryClassifier.getSeqNo());
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(categoryClassifier.getName(), categoryClassifier.getSeqNo(), false);
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, categoryClassifier.getName());
RiskFactorPdfDto riskFactorData;
if (riskFactorAssessment.getRiskFactorId() != null) {
......
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