Commit c89116f5 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Siiri Tann

See merge request teis/riskassessments-service!147
parents 2f51744c a7b3e301
# Changelog
## [1.5.1] - 2021-10-01
* TEIS-2461: generated pdf file is now cleared of special characters
* TEIS-2425: improved regex for markdown removal
* TEIS-2422: fixed risk factor sorting for risk assessment pdf generation
* TEIS-2452: fixed markdown removal regex not including numbers in selection
## [1.5.0] - 2021-09-27
* TEIS-2422: updated risk assessment pdf texts
......
theGroup=ee.sm.ti.teis
theVersion=1.5.0
theVersion=1.5.1
commonsVersion=1.27.0
officeApiGatewayVersion=1.27.0
officeApiGatewayVersion=1.27.1
filesVersion=1.21.0
pluginVersion=1.3.0
......@@ -43,14 +43,15 @@ public class RiskAssessmentPDFComposeService {
.build();
}
public RiskFactorPdfDto composeRiskFactorPdfDto(String name, String impact, String explanation) {
impact = removeMarkdown(impact);
explanation = removeMarkdown(explanation);
name = removeMarkdown(name);
public RiskFactorPdfDto composeRiskFactorPdfDto(String name, String description, String explanation, Long seqNo) {
String cleanedDescription = removeMarkdown(description);
String cleanedExplanation = removeMarkdown(explanation);
String cleanedName = removeMarkdown(name);
return RiskFactorPdfDto.builder()
.name(name)
.description(impact)
.explanation(explanation)
.name(cleanedName)
.seqNo(seqNo)
.description(cleanedDescription)
.explanation(cleanedExplanation)
.build();
}
......@@ -58,7 +59,7 @@ public class RiskAssessmentPDFComposeService {
if (string == null) {
return null;
}
return string.replaceAll("\\[([A-Za-z]*)]\\?*\\([A-Za-z]*\\)", "$1");
return string.replaceAll("\\[([^\\[\\]]*)]\\?*\\([^()]*\\)", "$1");
}
public RiskIndicatorPdfDto composeRiskIndicator(RiskStatementAssessmentPdfDto riskStatementAssessment,
......
......@@ -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);
......@@ -113,19 +115,32 @@ public class RiskAssessmentPDFService {
RiskFactorPdfDto riskFactor;
if (riskFactorAssessment.getRiskFactorId() != null) {
RiskFactorEntity riskFactorEntity = riskFactorDataService.getById(riskFactorAssessment.getRiskFactorId());
riskFactor = pdfComposeService.composeRiskFactorPdfDto(riskFactorEntity.getName(), riskFactorEntity.getImpact(), riskFactorAssessment.getDescription());
riskFactor = pdfComposeService.composeRiskFactorPdfDto(riskFactorEntity.getName(), riskFactorEntity.getImpact(),
riskFactorAssessment.getDescription(), riskFactorEntity.getSeqNo());
} else {
riskFactor = pdfComposeService.composeRiskFactorPdfDto(riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null);
riskFactor = pdfComposeService.composeRiskFactorPdfDto(riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null, null);
}
setRiskStatementAssessments(riskAssessmentId, riskFactorAssessment.getId(), riskFactor, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactor);
}
});
categoryList.sort(Comparator.comparing(RiskFactorPdfCategoryDto::getSeqNo, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(RiskFactorPdfCategoryDto::getName));
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())));
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));
});
}
private void setRiskStatementAssessments(UUID riskAssessmentId,
UUID riskFactorAssessmentId, RiskFactorPdfDto riskFactor, RequestMetaDTO requestMetaDTO) {
List<RiskStatementAssessmentEntity> riskStatementAssessments = riskStatementAssessmentDataService.getCurrentByRiskFactorAssessmentId(riskFactorAssessmentId);
......@@ -209,9 +224,10 @@ public class RiskAssessmentPDFService {
RiskFactorPdfDto riskFactorData;
if (riskFactorAssessment.getRiskFactorId() != null) {
RiskFactorEntity riskFactorEntity = riskFactorDataService.getById(riskFactorAssessment.getRiskFactorId());
riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactorEntity.getName(), riskFactorEntity.getImpact(), riskFactorAssessment.getDescription());
riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactorEntity.getName(), riskFactorEntity.getImpact(),
riskFactorAssessment.getDescription(), riskFactorEntity.getSeqNo());
} else {
riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null);
riskFactorData = pdfComposeService.composeRiskFactorPdfDto(riskFactorAssessment.getName(), riskFactorAssessment.getDescription(), null, null);
}
setRiskStatementAssessments(riskFactorAssessment.getRiskAssessmentId(), riskFactorAssessment.getId(), riskFactorData, requestMetaDTO);
pdfComposeService.addToRiskFactorCategory(categoryList, category, existingCategory, riskFactorData);
......@@ -236,12 +252,14 @@ public class RiskAssessmentPDFService {
String jsonData = jsonUtil.writeObjectAsString(riskAssessmentPdf);
PreviewDocumentMsRequest request = getMsPreviewDocumentRequest(requestMetaDTO, jsonData);
GeneratedDocumentDto extractedMessagesDocument = docGenServiceClient.getDocument(request, requestMetaDTO);
String clearedFileName = riskAssessmentPdf.getTitle().replaceAll("[^A-Za-z0-9\\p{IsCyrillic} ]", "").trim();
SignFileStream documentToSign = SignFileStream.builder()
.content(extractedMessagesDocument.getContent())
.fileName(riskAssessmentPdf.getTitle() + FILE_EXTENSION)
.fileName(clearedFileName + FILE_EXTENSION)
.contentType(extractedMessagesDocument.getContentType())
.build();
SignFileStream signedDocument = signingServiceClient.signFileStream(documentToSign, requestMetaDTO);
return GeneratedDocumentDto.builder()
.docName(signedDocument.getFileName())
.content(signedDocument.getContent())
......
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