1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19
20 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAssociation;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
23 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
24 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Association;
25 import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationLabel;
26 import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
27 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
28
29
30
31
32
33 public class AssociationTransformer {
34 private final EbXMLFactory factory;
35 private final CodeTransformer codeTransformer;
36 private final StringToBoolTransformer stringToBoolTransformer;
37
38
39
40
41
42
43 public AssociationTransformer(EbXMLFactory factory) {
44 notNull(factory, "factory cannot be null");
45 this.factory = factory;
46 codeTransformer = new CodeTransformer(factory);
47 stringToBoolTransformer = new StringToBoolTransformer();
48 }
49
50
51
52
53
54
55
56
57
58 public EbXMLAssociation toEbXML(Association association, EbXMLObjectLibrary objectLibrary) {
59 notNull(objectLibrary, "objectLibrary cannot be null");
60 if (association == null) {
61 return null;
62 }
63
64 EbXMLAssociation result = factory.createAssociation(association.getEntryUuid(), objectLibrary);
65 result.setAssociationType(association.getAssociationType());
66 result.setSource(association.getSourceUuid());
67 result.setTarget(association.getTargetUuid());
68
69 String label = AssociationLabel.toOpcode(association.getLabel());
70 result.addSlot(Vocabulary.SLOT_NAME_SUBMISSION_SET_STATUS, label);
71
72 String previousVersion = association.getPreviousVersion();
73 result.addSlot(Vocabulary.SLOT_NAME_PREVIOUS_VERSION, previousVersion);
74
75 AvailabilityStatus originalStatus = association.getOriginalStatus();
76 result.addSlot(Vocabulary.SLOT_NAME_ORIGINAL_STATUS, AvailabilityStatus.toQueryOpcode(originalStatus));
77
78 AvailabilityStatus newStatus = association.getNewStatus();
79 result.addSlot(Vocabulary.SLOT_NAME_NEW_STATUS, AvailabilityStatus.toQueryOpcode(newStatus));
80
81 result.addSlot(Vocabulary.SLOT_NAME_ASSOCIATION_PROPAGATION,
82 stringToBoolTransformer.toEbXML(association.getAssociationPropagation()));
83
84 EbXMLClassification contentType = codeTransformer.toEbXML(association.getDocCode(), objectLibrary);
85 result.addClassification(contentType, Vocabulary.ASSOCIATION_DOC_CODE_CLASS_SCHEME);
86
87 result.setExtraMetadata(association.getExtraMetadata());
88 result.setStatus(association.getAvailabilityStatus());
89
90 return result;
91 }
92
93
94
95
96
97
98
99
100 public Association fromEbXML(EbXMLAssociation association) {
101 if (association == null) {
102 return null;
103 }
104 Association result = new Association();
105 result.setAssociationType(association.getAssociationType());
106 result.setTargetUuid(association.getTarget());
107 result.setSourceUuid(association.getSource());
108 result.setEntryUuid(association.getId());
109
110 String label = association.getSingleSlotValue(Vocabulary.SLOT_NAME_SUBMISSION_SET_STATUS);
111 result.setLabel(AssociationLabel.fromOpcode(label));
112
113 String previousVersion = association.getSingleSlotValue(Vocabulary.SLOT_NAME_PREVIOUS_VERSION);
114 result.setPreviousVersion(previousVersion);
115
116 String originalStatus = association.getSingleSlotValue(Vocabulary.SLOT_NAME_ORIGINAL_STATUS);
117 result.setOriginalStatus(AvailabilityStatus.valueOfOpcode(originalStatus));
118
119 String newStatus = association.getSingleSlotValue(Vocabulary.SLOT_NAME_NEW_STATUS);
120 result.setNewStatus(AvailabilityStatus.valueOfOpcode(newStatus));
121
122 String associationPropagation = association.getSingleSlotValue(Vocabulary.SLOT_NAME_ASSOCIATION_PROPAGATION);
123 result.setAssociationPropagation(stringToBoolTransformer.fromEbXML(associationPropagation));
124
125 EbXMLClassification docCode = association.getSingleClassification(Vocabulary.ASSOCIATION_DOC_CODE_CLASS_SCHEME);
126 result.setDocCode(codeTransformer.fromEbXML(docCode));
127
128 result.setExtraMetadata(association.getExtraMetadata());
129 result.setAvailabilityStatus(association.getStatus());
130
131 return result;
132 }
133 }