Commit 28efade6 authored by Hando Lukats's avatar Hando Lukats
Browse files

TEIS-2394 implemented changes from review

parent b6b0400c
......@@ -17,7 +17,6 @@ import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.RISK_STATEMENT_ASSESSMENT;
......@@ -31,7 +30,7 @@ public class RiskAssessmentPDFComposeService {
private static final String ACTION_NOT_EVALUATED = "Abinõu on hindamata";
private static final String NO_ACTION_NEEDED = "Abinõud ei ole vaja rakendada";
private static final String ADDED_TO_ACTION_PLAN = "Abinõu on lisatud tegevuskavasse";
private final RiskIndicatorValueDataService riskIndicatorValueDataService;
private final RiskIndicatorDataService riskIndicatorDataService;
private final FileReferenceBusinessService fileReferenceBusinessService;
......@@ -51,29 +50,27 @@ public class RiskAssessmentPDFComposeService {
.build();
}
public RiskIndicatorPdfDto composeRiskIndicatorList(RiskStatementAssessmentPdfDto riskStatementAssessment,
public RiskIndicatorPdfDto composeRiskIndicator(RiskStatementAssessmentPdfDto riskStatementAssessment,
RequestMetaDTO requestMetaDTO) {
List<RiskIndicatorValuesPdfDto> riskIndicatorList = new ArrayList<>();
List<RiskIndicatorValueEntity> riskIndicatorValues = riskIndicatorValueDataService.getCurrentByRiskStatementAssessmentId(riskStatementAssessment.getId());
if (!riskIndicatorValues.isEmpty()) {
AtomicReference<String> indicatorName = new AtomicReference<>("");
RiskIndicatorEntity riskIndicator = riskIndicatorDataService.getCurrentById(riskIndicatorValues.get(0).getRiskIndicatorId());
riskIndicatorValues.forEach(item -> {
RiskIndicatorEntity riskIndicator = riskIndicatorDataService.getCurrentById(item.getRiskIndicatorId());
indicatorName.set(riskIndicator.getName());
RiskIndicatorValuesPdfDto riskIndicatorValue = RiskIndicatorValuesPdfDto.builder()
.value(item.getValue() + riskIndicator.getUnit())
.comment(item.getComment())
.build();
riskIndicatorList.add(riskIndicatorValue);
});
riskStatementAssessment.setRiskIndicatorName(indicatorName.get());
riskStatementAssessment.setRiskIndicatorName(riskIndicator.getName());
}
RiskIndicatorPdfDto riskIndicatorPdfDto = RiskIndicatorPdfDto.builder()
.riskIndicatorValues(riskIndicatorList)
.build();
List<FileReferenceDto> fileReferences = fileReferenceBusinessService.getFilesMetadataByObjectIdAndObjectType(riskStatementAssessment.getId(),
RISK_STATEMENT_ASSESSMENT.getId(), requestMetaDTO);
riskIndicatorPdfDto.setHasFiles(fileReferences.isEmpty());
riskIndicatorPdfDto.setHasFiles(!fileReferences.isEmpty());
return riskIndicatorPdfDto;
}
......
......@@ -49,6 +49,8 @@ public class RiskAssessmentPDFService {
private static final String RISK_ASSESSMENT_ARCHIVED = "Arhiveeritud";
private static final String RISK_ASSESSMENT_CURRENT = "Kehtiv";
private static final String DOCUMENT_TEMPLATE_ID = "RISK_ASSESSMENT_PDF";
private static final String BUSINESS_TYPE_DELIMITER = "; ";
private static final String FILE_EXTENSION = ".pdf";
private final RiskAssessmentPublicBusinessService riskAssessmentPublicBusinessService;
private final RiskFactorAssessmentDataService riskFactorAssessmentDataService;
......@@ -106,7 +108,7 @@ public class RiskAssessmentPDFService {
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, requestMetaDTO, riskFactorAssessment, riskFactor);
setRiskStatementAssessments(riskAssessmentId, riskFactorAssessment.getId(), riskFactor, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactor);
}
});
......@@ -115,29 +117,29 @@ public class RiskAssessmentPDFService {
return categoryList;
}
private void setRiskStatementAssessments(UUID riskAssessmentId, RequestMetaDTO requestMetaDTO,
RiskFactorAssessmentEntity riskFactorAssessment, RiskFactorPdfDto riskFactor) {
List<RiskStatementAssessmentEntity> riskStatementAssessments = riskStatementAssessmentDataService.getCurrentByRiskFactorAssessmentId(riskFactorAssessment.getId());
private void setRiskStatementAssessments(UUID riskAssessmentId,
UUID riskFactorAssessmentId, RiskFactorPdfDto riskFactor, RequestMetaDTO requestMetaDTO) {
List<RiskStatementAssessmentEntity> riskStatementAssessments = riskStatementAssessmentDataService.getCurrentByRiskFactorAssessmentId(riskFactorAssessmentId);
List<RiskStatementAssessmentPdfDto> riskStatementAssessmentPdfDtos = new ArrayList<>();
riskStatementAssessments.forEach(riskStatementAssessment -> {
RiskStatementAssessmentPdfDto riskStatementAssessmentPdfDto = RiskStatementAssessmentPdfDto.builder()
.id(riskStatementAssessment.getId())
.build();
RiskIndicatorPdfDto riskIndicatorList = pdfComposeService.composeRiskIndicatorList(riskStatementAssessmentPdfDto, requestMetaDTO);
RiskIndicatorPdfDto riskIndicatorPdfDto = pdfComposeService.composeRiskIndicator(riskStatementAssessmentPdfDto, requestMetaDTO);
String status = pdfComposeService.composeRiskStatementAssessmentStatus(riskStatementAssessment);
setRIskStatementAssessmentDescription(riskStatementAssessment, riskStatementAssessmentPdfDto, status);
setRiskStatementAssessmentDescription(riskStatementAssessment, riskStatementAssessmentPdfDto, status);
if (status.equals(ADDED_TO_ACTION_PLAN)) {
setRiskStatementTask(riskAssessmentId, requestMetaDTO, riskStatementAssessment, riskStatementAssessmentPdfDto);
setRiskStatementAssessmentTask(riskAssessmentId, requestMetaDTO, riskStatementAssessment, riskStatementAssessmentPdfDto);
}
riskStatementAssessmentPdfDto.setRiskIndicators(riskIndicatorList);
riskStatementAssessmentPdfDto.setRiskIndicators(riskIndicatorPdfDto);
riskStatementAssessmentPdfDto.setStatus(status);
riskStatementAssessmentPdfDtos.add(riskStatementAssessmentPdfDto);
});
riskFactor.setRiskStatementAssessments(riskStatementAssessmentPdfDtos);
}
private void setRiskStatementTask(UUID riskAssessmentId, RequestMetaDTO requestMetaDTO,
private void setRiskStatementAssessmentTask(UUID riskAssessmentId, RequestMetaDTO requestMetaDTO,
RiskStatementAssessmentEntity riskStatementAssessment,
RiskStatementAssessmentPdfDto riskStatementAssessmentPdfDto) {
List<Task> tasks = getTasks(riskAssessmentId, requestMetaDTO);
......@@ -158,7 +160,7 @@ public class RiskAssessmentPDFService {
});
}
private void setRIskStatementAssessmentDescription(RiskStatementAssessmentEntity riskStatementAssessment,
private void setRiskStatementAssessmentDescription(RiskStatementAssessmentEntity riskStatementAssessment,
RiskStatementAssessmentPdfDto riskStatementAssessmentPdfDto, String status) {
if (riskStatementAssessment.getRiskStatementId() != null) {
RiskStatementEntity riskStatement = riskStatementDataService.getCurrentById(riskStatementAssessment.getRiskStatementId());
......@@ -181,14 +183,14 @@ public class RiskAssessmentPDFService {
}
private void setRiskFactorCategoryByClassifier(List<RiskFactorPdfCategoryDto> categoryList,
RiskFactorAssessmentEntity item, RequestMetaDTO requestMetaDTO) {
RiskFactorAssessmentEntity riskFactorAssessment, RequestMetaDTO requestMetaDTO) {
RiskFactorEntity riskFactor = riskFactorDataService.getCurrentById(item.getRiskFactorId());
RiskFactorEntity riskFactor = riskFactorDataService.getCurrentById(riskFactorAssessment.getRiskFactorId());
ClassifierItem categoryClassifier = classifierService.getClassifierItem(riskFactor.getCategory(), requestMetaDTO);
RiskFactorPdfCategoryDto category = pdfComposeService.composeRiskFactorCategoryDto(categoryClassifier.getName(), categoryClassifier.getSeqNo());
Optional<RiskFactorPdfCategoryDto> existingCategory = getExistingRiskFactorCategory(categoryList, categoryClassifier.getName());
RiskFactorPdfDto riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactor.getName(), riskFactor.getImpact(), item.getDescription());
setRiskStatementAssessments(item.getRiskAssessmentId(), requestMetaDTO, item, riskFactorData);
RiskFactorPdfDto riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactor.getName(), riskFactor.getImpact(), riskFactorAssessment.getDescription());
setRiskStatementAssessments(riskFactorAssessment.getRiskAssessmentId(), riskFactorAssessment.getId(), riskFactorData, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactorData);
}
......@@ -203,7 +205,7 @@ public class RiskAssessmentPDFService {
private String getSecondaryBusinessTypeNames(RiskAssessmentPublicDto riskAssessment) {
List<AssessedBusinessTypePublicDto> secondaryBusinessTypes = riskAssessment.getAssessedBusinessTypes().stream().filter(item -> !item.isPrimary()).collect(toList());
List<String> businessTypeNames = secondaryBusinessTypes.stream().map(item -> item.getBusinessType().getName()).collect(toList());
return String.join("; ", businessTypeNames);
return String.join(BUSINESS_TYPE_DELIMITER, businessTypeNames);
}
public GeneratedDocumentDto getSignedRiskAssessmentPdf(UUID riskAssessmentId, RequestMetaDTO requestMetaDTO) {
......@@ -213,7 +215,7 @@ public class RiskAssessmentPDFService {
GeneratedDocumentDto extractedMessagesDocument = docGenServiceClient.getDocument(request, requestMetaDTO);
SignFileStream documentToSign = SignFileStream.builder()
.content(extractedMessagesDocument.getContent())
.fileName(riskAssessmentPdf.getTitle() + ".pdf")
.fileName(riskAssessmentPdf.getTitle() + FILE_EXTENSION)
.contentType(extractedMessagesDocument.getContentType())
.build();
SignFileStream signedDocument = signingServiceClient.signFileStream(documentToSign, requestMetaDTO);
......
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