Skip to content

Commit

Permalink
fix: Issue 988
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Sep 12, 2024
1 parent 21b6fc8 commit 205fb4e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static final class App {
public static final String BEARER_PREFIX = "Bearer ";
public static final String SHA_ERROR = "Errore in fase di calcolo SHA-256";
public static final String SHA_ALGORITHM = "SHA-256";
public static final String SHA1_ALGORITHM = "SHA-1";
public static final String JWT_MISSING_ISSUER_PLACEHOLDER = "UNDEFINED_JWT_ISSUER";
public static final String JWT_MISSING_SUBJECT = "UNDEFINED_SUBJECT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ private ValidationDataDTO executePublicationReplace(final ValidationCreationInpu
private ResourceDTO callFhirMappingEngine(String transformId, String engineId,
final JWTPayloadDTO jwtPayloadToken, PublicationCreateReplaceMetadataDTO jsonObj, final byte[] bytePDF,
final String cda, final String documentSha256) {
String sha1 = StringUtility.encodeSHA1(bytePDF);
final ResourceDTO fhirResourcesDTO = documentReferenceSRV.createFhirResources(cda,jwtPayloadToken.getSubject_role(), jsonObj, bytePDF.length, documentSha256,transformId, engineId,
jwtPayloadToken.getSubject_organization_id());
jwtPayloadToken.getSubject_organization_id(),sha1);

if(!isNullOrEmpty(fhirResourcesDTO.getErrorMessage())) {
final ErrorResponseDTO error = ErrorResponseDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
public interface IFhirSRV {

ResourceDTO createFhirResources(String cda, String authorRole, PublicationCreateReplaceMetadataDTO requestBody,
Integer size, String hash, String transformId, String engineId, String organizationId);
Integer size, String hash, String transformId, String engineId, String organizationId,String sha1);

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class FhirSRV implements IFhirSRV {

@Override
public ResourceDTO createFhirResources(final String cda, String authorRole,final PublicationCreateReplaceMetadataDTO requestBody,
final Integer size, final String hash, String transformId, String engineId, String organizationId) {
final Integer size, final String hash, String transformId, String engineId, String organizationId,String sha1) {

final ResourceDTO output = new ResourceDTO();
final org.jsoup.nodes.Document docCDA = Jsoup.parse(cda);
Expand Down Expand Up @@ -92,7 +92,7 @@ public ResourceDTO createFhirResources(final String cda, String authorRole,final

if(StringUtility.isNullOrEmpty(output.getErrorMessage())) {
try {
final DocumentEntryDTO documentEntryDTO = createDocumentEntry(docCDA, requestBody, size, hash,
final DocumentEntryDTO documentEntryDTO = createDocumentEntry(docCDA, requestBody, size, sha1,
authorSlot);
output.setDocumentEntryJson(StringUtility.toJSON(documentEntryDTO));
} catch(final Exception ex) {
Expand Down Expand Up @@ -173,7 +173,7 @@ private SubmissionSetEntryDTO createSubmissionSetEntry(final org.jsoup.nodes.Doc


private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docCDA,
final PublicationCreateReplaceMetadataDTO requestBody, final Integer size, final String hash,
final PublicationCreateReplaceMetadataDTO requestBody, final Integer size, final String sha1,
AuthorSlotDTO authorSlotDTO) {

DocumentEntryDTO de = new DocumentEntryDTO();
Expand Down Expand Up @@ -208,7 +208,7 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC
de.setUniqueId(requestBody.getIdentificativoDoc());
de.setMimeType("application/pdf+text/x-cda-r2+xml");
de.setCreationTime(new SimpleDateFormat(Constants.Misc.INI_DATE_PATTERN).format(new Date()));
de.setHash(hash);
de.setHash(sha1);
de.setSize(size);
if(requestBody.getAdministrativeRequest() != null) {
List<String> administrativeRequestList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ private CdaUtility() {
}

public static String createWorkflowInstanceId(final String idDoc) {
return encodeSHA256Hex(idDoc) + WIF_SEPARATOR + generateTransactionUID() + WIF_SUFFIX;
return encodeSHA256Hex(idDoc) + WIF_SEPARATOR + generateWii() + WIF_SUFFIX;
}

public static String getWorkflowInstanceId(final org.jsoup.nodes.Document docT) {

try {
String cxi = extractInfo(docT);
return cxi + WIF_SEPARATOR + generateTransactionUID() + WIF_SUFFIX;
return cxi + WIF_SEPARATOR + generateWii() + WIF_SUFFIX;
} catch (Exception e) {
final ErrorResponseDTO error = ErrorResponseDTO.builder()
.title(RestExecutionResultEnum.WORKFLOW_ID_ERROR.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ public static String encodeSHA256(final byte[] objectToEncode) {
}
}

/**
* Returns the encoded String of the SHA-256 algorithm represented in base 64.
*
* @param objectToEncode String to encode.
* @return String Encoded.
*/
public static String encodeSHA1(final byte[] objectToEncode) {
try {
final MessageDigest digest = MessageDigest.getInstance(Constants.App.SHA1_ALGORITHM);
return Hex.encodeHexString(digest.digest(objectToEncode));
} catch (final Exception e) {
log.error(ERROR_MSG, e);
throw new BusinessException(Constants.App.SHA_ERROR, e);
}
}

/**
* Returns the encoded String of the SHA-256 algorithm represented in base 64.
*
Expand Down Expand Up @@ -130,7 +146,7 @@ public static String generateUUID() {
return UUID.randomUUID().toString();
}

public static String generateTransactionUID() {
public static String generateWii() {
return UUID.randomUUID().toString().replace("-", "").substring(0, 10);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void createDocumentReferenceOkTest() {
String cda = new String(cdaFile);
PublicationCreationReqDTO reqDTO = buildPublicationReqDTO(workflowInstanceId);
String documentSha = StringUtility.encodeSHA256(cdaFile);
ResourceDTO resourceDTO = documentReferenceSRV.createFhirResources(cda,"",reqDTO, documentSha.length(), documentSha, "", "","");
ResourceDTO resourceDTO = documentReferenceSRV.createFhirResources(cda,"",reqDTO, documentSha.length(), documentSha, "", "","","");
assertNotNull(resourceDTO.getDocumentEntryJson());
assertNotNull(resourceDTO.getSubmissionSetEntryJson());
assertNull(resourceDTO.getErrorMessage());
Expand Down Expand Up @@ -124,7 +124,7 @@ void createDocumentReferenceErrorTest() {
PublicationCreationReqDTO reqDTO = buildPublicationReqDTO(workflowInstanceId);
String documentSha = StringUtility.encodeSHA256(cdaFile);
ResourceDTO resourceDTO = documentReferenceSRV.createFhirResources(cda, "",reqDTO, documentSha.length(), documentSha,
"PersonId", "", "");
"PersonId", "", "","");
ResourceDTO expectedOutputDTO = new ResourceDTO();
expectedOutputDTO.setErrorMessage("errorMessage");
assertEquals(expectedOutputDTO, resourceDTO);
Expand All @@ -143,7 +143,7 @@ void createDocumentReferenceConnectionRefusedTest() {
PublicationCreationReqDTO reqDTO = buildPublicationReqDTO(workflowInstanceId);
String documentSha = StringUtility.encodeSHA256(cdaFile);
assertThrows(ConnectionRefusedException.class, () -> documentReferenceSRV.createFhirResources(cda,"", reqDTO, documentSha.length(), documentSha,
"PersonId", "",""));
"PersonId", "","",""));
}

@Test
Expand All @@ -159,6 +159,6 @@ void createDocumentReferenceErrorBusinessException() {
PublicationCreationReqDTO reqDTO = buildPublicationReqDTO(workflowInstanceId);
String documentSha = StringUtility.encodeSHA256(cdaFile);
assertThrows(BusinessException.class, () -> documentReferenceSRV.createFhirResources(cda,"", reqDTO, documentSha.length(), documentSha,
"PersonId", "", ""));
"PersonId", "", "",""));
}
}

0 comments on commit 205fb4e

Please sign in to comment.