Skip to content

Commit

Permalink
feat: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Jan 17, 2024
1 parent f942200 commit ead5058
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public class SubmissionSetEntryDTO {
private String author;
private String authorRole;
private String authorInstitution;
private String patientId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@
*/
package it.finanze.sanita.fse2.ms.iniclient.utility.common;

import it.finanze.sanita.fse2.ms.iniclient.config.Constants;
import it.finanze.sanita.fse2.ms.iniclient.exceptions.base.BusinessException;
import it.finanze.sanita.fse2.ms.iniclient.utility.StringUtility;
import lombok.extern.slf4j.Slf4j;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.*;

import javax.xml.bind.JAXBElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class SamlBodyBuilderCommonUtility {
import javax.xml.bind.JAXBElement;

private SamlBodyBuilderCommonUtility() {}
import it.finanze.sanita.fse2.ms.iniclient.config.Constants;
import it.finanze.sanita.fse2.ms.iniclient.utility.StringUtility;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.InternationalStringType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.LocalizedStringType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectRefListType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectRefType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SamlBodyBuilderCommonUtility {

private static ObjectFactory objectFactory = new ObjectFactory();

Expand All @@ -45,19 +53,14 @@ public static InternationalStringType buildInternationalStringType(String name)
*/
public static InternationalStringType buildInternationalStringType(List<String> names) {
InternationalStringType internationalStringObject = new InternationalStringType();
try {
List<LocalizedStringType> localizedStringsList = new ArrayList<>();
for (String name : names) {
LocalizedStringType localizedStringObject = new LocalizedStringType();
localizedStringObject.setValue(name);
localizedStringsList.add(localizedStringObject);
}
internationalStringObject.getLocalizedString().addAll(localizedStringsList);
return internationalStringObject;
} catch (Exception e) {
log.error("Error while invoking buildInternationalStringType: {}", e.getMessage());
throw new BusinessException("Error while invoking buildInternationalStringType: " + e.getMessage());
List<LocalizedStringType> localizedStringsList = new ArrayList<>();
for (String name : names) {
LocalizedStringType localizedStringObject = new LocalizedStringType();
localizedStringObject.setValue(name);
localizedStringsList.add(localizedStringObject);
}
internationalStringObject.getLocalizedString().addAll(localizedStringsList);
return internationalStringObject;
}

/**
Expand All @@ -80,22 +83,18 @@ public static ExternalIdentifierType buildExternalIdentifierObject(
) {
ExternalIdentifierType externalIdentifierObject = new ExternalIdentifierType();

try {
InternationalStringType nameType = new InternationalStringType();
LocalizedStringType localizedString = new LocalizedStringType();
localizedString.setValue(name);
nameType.getLocalizedString().add(localizedString);
externalIdentifierObject.setName(nameType);
externalIdentifierObject.setId(id);
externalIdentifierObject.setIdentificationScheme(identificationScheme);
externalIdentifierObject.setObjectType(objectType);
externalIdentifierObject.setRegistryObject(registryObject);
externalIdentifierObject.setValue(value);
return externalIdentifierObject;
} catch (Exception e) {
log.error("Error while invoking buildExternalIdentifierObject: {}", e.getMessage());
throw new BusinessException("Error while invoking buildExternalIdentifierObject: " + e.getMessage());
}
InternationalStringType nameType = new InternationalStringType();
LocalizedStringType localizedString = new LocalizedStringType();
localizedString.setValue(name);
nameType.getLocalizedString().add(localizedString);
externalIdentifierObject.setName(nameType);
externalIdentifierObject.setId(id);
externalIdentifierObject.setIdentificationScheme(identificationScheme);
externalIdentifierObject.setObjectType(objectType);
externalIdentifierObject.setRegistryObject(registryObject);
externalIdentifierObject.setValue(value);
return externalIdentifierObject;

}

/**
Expand Down Expand Up @@ -151,23 +150,18 @@ public static ClassificationType buildClassificationObject(String classification
String classificationScheme,String classifiedObject,String id,
InternationalStringType name,List<SlotType1> slots,String objectType,String nodeRepresentation) {
ClassificationType classificationObject = new ClassificationType();
try {
classificationObject.setClassificationNode(classificationNode);
classificationObject.setClassificationScheme(classificationScheme);
classificationObject.setClassifiedObject(classifiedObject);
classificationObject.setId(id);
classificationObject.setName(name);
if (slots != null) {
classificationObject.getSlot().addAll(slots);
}
classificationObject.setObjectType(objectType);
classificationObject.setNodeRepresentation(nodeRepresentation);

return classificationObject;
} catch (Exception e) {
log.error("Error while invoking buildClassificationObject: {}", e.getMessage());
throw new BusinessException("Error while invoking buildClassificationObject: " + e.getMessage());
classificationObject.setClassificationNode(classificationNode);
classificationObject.setClassificationScheme(classificationScheme);
classificationObject.setClassifiedObject(classifiedObject);
classificationObject.setId(id);
classificationObject.setName(name);
if (slots != null) {
classificationObject.getSlot().addAll(slots);
}
classificationObject.setObjectType(objectType);
classificationObject.setNodeRepresentation(nodeRepresentation);

return classificationObject;
}

public static SlotType1 buildSlotObject(String name,String value) {
Expand All @@ -184,24 +178,20 @@ public static SlotType1 buildSlotObject(String name,String value) {
*/
public static SlotType1 buildSlotObject(String name,String type,List<String> values) {
SlotType1 slotObject = null;
try {
if(values!=null && !values.isEmpty()) {
slotObject = new SlotType1();
slotObject.setName(name);
slotObject.setSlotType(type);
ValueListType valueList = new ValueListType();
for (String value : values) {
valueList.getValue().add(value);
}
slotObject.setValueList(valueList);
if(values!=null && !values.isEmpty()) {
slotObject = new SlotType1();
slotObject.setName(name);
slotObject.setSlotType(type);
ValueListType valueList = new ValueListType();
for (String value : values) {
valueList.getValue().add(value);
}
slotObject.setValueList(valueList);
}


return slotObject;
} catch (Exception e) {
log.error("Error while invoking buildSlotObject: {}", e.getMessage());
throw new BusinessException("Error while invoking buildSlotObject: " + e.getMessage());
}
return slotObject;

}

/**
Expand All @@ -212,15 +202,11 @@ public static SlotType1 buildSlotObject(String name,String type,List<String> val
public static ObjectRefListType buildObjectRefList(String uuid) {
ObjectRefListType objectRefListType = new ObjectRefListType();

try {
ObjectRefType objectRef = new ObjectRefType();
objectRef.setId(uuid);
objectRefListType.getObjectRef().add(objectRef);
return objectRefListType;
} catch(Exception ex) {
log.error("Error while perform build registry object list : " , ex);
throw new BusinessException("Error while perform build registry object list : " , ex);
}
ObjectRefType objectRef = new ObjectRefType();
objectRef.setId(uuid);
objectRefListType.getObjectRef().add(objectRef);
return objectRefListType;

}

/**
Expand All @@ -242,12 +228,8 @@ public static JAXBElement<ExternalIdentifierType> buildExternalIdentifierObjectJ
String registryObject,
String value
) {
try {
return objectFactory.createExternalIdentifier(buildExternalIdentifierObject(name, id, identificationScheme, objectType, registryObject, value));
} catch (Exception e) {
log.error("Error while invoking buildExternalIdentifierObjectJax: {}", e.getMessage());
throw new BusinessException("Error while invoking buildExternalIdentifierObjectJax: " + e.getMessage());
}
return objectFactory.createExternalIdentifier(buildExternalIdentifierObject(name, id, identificationScheme, objectType, registryObject, value));

}

/**
Expand All @@ -271,13 +253,9 @@ public static JAXBElement<ClassificationType> buildClassificationObjectJax(
List<SlotType1> slots,
String objectType,
String nodeRepresentation) {
try {
return objectFactory.createClassification(buildClassificationObject(classificationNode, classificationScheme,
classifiedObject, id, name, slots, objectType, nodeRepresentation));
} catch (Exception e) {
log.error("Error while invoking buildClassificationObjectJax: {}", e.getMessage());
throw new BusinessException("Error while invoking buildClassificationObjectJax: " + e.getMessage());
}
return objectFactory.createClassification(buildClassificationObject(classificationNode, classificationScheme,
classifiedObject, id, name, slots, objectType, nodeRepresentation));

}

/**
Expand All @@ -287,18 +265,8 @@ public static JAXBElement<ClassificationType> buildClassificationObjectJax(
* @param values
* @return
*/
public static JAXBElement<SlotType1> buildSlotObjectJax(
ObjectFactory objectFactory,
String name,
String type,
List<String> values
) {
try {
return objectFactory.createSlot(buildSlotObject(name, type, values));
} catch (Exception e) {
log.error("Error while invoking buildSlotObjectJax: {}", e.getMessage());
throw new BusinessException("Error while invoking buildSlotObjectJax: " + e.getMessage());
}
public static JAXBElement<SlotType1> buildSlotObjectJax(String name,String type,List<String> values) {
return objectFactory.createSlot(buildSlotObject(name, type, values));
}

/**
Expand Down Expand Up @@ -329,19 +297,15 @@ public static JAXBElement<AssociationType1> buildAssociationObject(
List<SlotType1> slots
) {
AssociationType1 associationObject = new AssociationType1();
try {
associationObject.setAssociationType(associationType);
associationObject.setId(id);
associationObject.setSourceObject(sourceObject);
associationObject.setTargetObject(targetObject);
if (slots != null) {
associationObject.getSlot().addAll(slots);
}

return objectFactory.createAssociation(associationObject);
} catch (Exception e) {
log.error("Error while invoking buildAssociationObject: {}", e.getMessage());
throw new BusinessException("Error while invoking buildAssociationObject: " + e.getMessage());
associationObject.setAssociationType(associationType);
associationObject.setId(id);
associationObject.setSourceObject(sourceObject);
associationObject.setTargetObject(targetObject);
if (slots != null) {
associationObject.getSlot().addAll(slots);
}

return objectFactory.createAssociation(associationObject);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static List<SlotType1> buildExtrinsicObjectSlotsDocEntry(DocumentEntryDT
slotType1.add(buildSlotObject("authorPerson", documentEntryDTO.getAuthor()));
slotType1.add(buildSlotObject("languageCode", LANGUAGE_CODE));
slotType1.add(buildSlotObject("repositoryUniqueId", documentEntryDTO.getRepositoryUniqueId()));
slotType1.add(buildSlotObject("sourcePatientId", documentEntryDTO.getPatientId() + "^^^&2.16.840.1.113883.2.9.4.3.2&ISO"));
slotType1.add(buildSlotObject("sourcePatientId", documentEntryDTO.getPatientId())); /*+ "^^^&2.16.840.1.113883.2.9.4.3.2&ISO"*/
slotType1.add(buildSlotObject("urn:ita:2017:repository-type", "CONS^^^&2.16.840.1.113883.2.9.3.3.6.1.7&ISO"));
slotType1.add(buildSlotObject("urn:ita:2022:documentSigned", DOCUMENT_SIGNED));
slotType1.add(buildSlotObject("urn:ita:2022:description", null, documentEntryDTO.getDescription()));
Expand Down Expand Up @@ -156,7 +156,7 @@ private static List<ExternalIdentifierType> buildExternalIdentifierDocEntry(Docu
List<ExternalIdentifierType> out = new ArrayList<>();
ExternalIdentifierType externalIdentifier1 = buildExternalIdentifierObject("XDSDocumentEntry.patientId",
"patientId_1","urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427","urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:ExternalIdentifier",
"urn:uuid:3c86e9e9-6ae0-425d-9c42-93afa1d00db3",documentEntryDTO.getPatientId()+ "^^^&2.16.840.1.113883.2.9.4.3.2&ISO");
"urn:uuid:3c86e9e9-6ae0-425d-9c42-93afa1d00db3",documentEntryDTO.getPatientId());
out.add(externalIdentifier1);
ExternalIdentifierType externalIdentifier2 = buildExternalIdentifierObject("XDSDocumentEntry.uniqueId","uniqueId_1",
"urn:uuid:2e82c1f6-a085-4c72-9da3-8640a32e42ab",Constants.IniClientConstants.EXTERNAL_IDENTIFIER_URN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static JAXBElement<RegistryPackageType> buildRegistryPackageObjectSubmiss

private static List<SlotType1> buildSlotSubmissionSet(SubmissionSetEntryDTO submissionSetEntryDTO){
List<SlotType1> out = new ArrayList<>();
out.add(buildSlotObjectJax(objectFactory,"submissionTime",null,Arrays.asList(submissionSetEntryDTO.getSubmissionTime())).getValue());
out.add(buildSlotObjectJax("submissionTime",null,Arrays.asList(submissionSetEntryDTO.getSubmissionTime())).getValue());
return out;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ private static List<ExternalIdentifierType> buildExternalIdentifierSubmissionSet
"urn:uuid:6b5aea1a-874d-4603-a4bc-96a0a7b38446",
Constants.IniClientConstants.EXTERNAL_IDENTIFIER_URN,
Constants.IniClientConstants.SUBMISSION_SET_DEFAULT_ID,
"GNTLNI47M25D668R^^^&2.16.840.1.113883.2.9.4.3.2&ISO");
submissionSetEntryDTO.getPatientId());
out.add(externalPatientIdentifierObject.getValue());
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static RegistryPackageType rebuildRegistryPackageObjectMetadata(
Constants.IniClientConstants.SOURCE_ID_OID +
jwtTokenDTO.getPayload().getSubject_organization_id()));
JAXBElement<SlotType1> slotObject = buildSlotObjectJax(
objectFactory,

"intendedRecipient",
null,
slotValues
Expand Down Expand Up @@ -366,7 +366,7 @@ private static RegistryPackageType buildBasicRegistryPackageObject(String genera
String submissionSetTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
List<String> slotValues = new ArrayList<>(Collections.singletonList(submissionSetTime));
JAXBElement<SlotType1> slotObject = buildSlotObjectJax(
objectFactory,

"submissionTime",
null,
slotValues
Expand Down

0 comments on commit ead5058

Please sign in to comment.