Commits

njo@kvalitetsit.dk authored 296e4c21a29
[SDS-4242] Map more attributes.

git-svn-id: https://svn.nspop.dk/svn/components/labsvar/trunk@4560 3203d48c-b89f-428c-a2b9-71f4dc330d7c
No tags

xdswrappers/documentprovider-parent/documentprovider/src/main/java/dk/nsi/dds/projects/sxa/documentprovider/audit/LogRecordBuilder.java

Modified
80 80 }
81 81 catch(DatatypeConfigurationException e) {
82 82 throw new IllegalStateException("Could not instantiate DatatypeFactory!", e);
83 83 }
84 84 }
85 85
86 86 private RequestingClientType buildRequestingClientType(HsuidHeader hsuidHeader) {
87 87 RequestingClientType requestingClientType = new RequestingClientType();
88 88
89 89 requestingClientType.setClientIdentification(buildClientIdentification(hsuidHeader));
90 + requestingClientType.setClinicName("");
91 + requestingClientType.setClinicDepartment("");
92 + requestingClientType.setUserCprNumber(getActingUserCivilRegistrationNumber(hsuidHeader));
93 + requestingClientType.setUserName("");
94 + requestingClientType.setUserInitials("");
95 + requestingClientType.setBehalfOfCprNumber(getBehalfOfCprNumber(hsuidHeader));
90 96
91 97 return requestingClientType;
92 98 }
93 99
94 100 private RequestingClientType.ClientIdentification buildClientIdentification(HsuidHeader hsuidHeader) {
95 - Attribute userTypeAttribute = getAttribute(hsuidHeader, NameConstraint.NSI_USERTYPE);
101 + Attribute userTypeAttribute = getRequiredAttribute(hsuidHeader, NameConstraint.NSI_USERTYPE);
96 102 switch(userTypeAttribute.getAttributeValue()) {
97 103 case "nsi:Citizen":
98 104 return buildCitizenClientIdentification(hsuidHeader);
99 105 case "nsi:HealthcareProfessional":
100 106 return buildHealthcareProfessionalClientIdentification(hsuidHeader);
101 107 default:
102 108 throw new IllegalArgumentException(String.format("Unexpected nsi:UserType: %s", userTypeAttribute.getAttributeValue()));
103 109 }
104 110 }
105 111
108 114
109 115 clientIdentification.setClientIdentificationType(ClientIdentificationTypeEnumeration.CPR_NUMMER);
110 116 clientIdentification.setValue(getActingUserCivilRegistrationNumber(hsuidHeader));
111 117
112 118 return clientIdentification;
113 119 }
114 120
115 121 private RequestingClientType.ClientIdentification buildHealthcareProfessionalClientIdentification(HsuidHeader hsuidHeader) {
116 122 RequestingClientType.ClientIdentification clientIdentification = new RequestingClientType.ClientIdentification();
117 123
118 - Attribute orgUsingIdAttribute = getAttribute(hsuidHeader, NameConstraint.NSI_ORG_USING_ID);
124 + Attribute orgUsingIdAttribute = getRequiredAttribute(hsuidHeader, NameConstraint.NSI_ORG_USING_ID);
119 125 clientIdentification.setClientIdentificationType(getClientIdentificationTypeForOrgnisation(orgUsingIdAttribute.getNameFormat()));
120 126 clientIdentification.setValue(orgUsingIdAttribute.getAttributeValue());
121 127
122 128 return clientIdentification;
123 129 }
124 130
125 131 private String getActingUserCivilRegistrationNumber(HsuidHeader hsuidHeader) {
126 - Attribute actingUserCivilRegistrationNumberAttribute = getAttribute(hsuidHeader, NameConstraint.NSI_ACTING_USER_CIVIL_REGISTRATION_NUMBER);
132 + Attribute actingUserCivilRegistrationNumberAttribute = getRequiredAttribute(hsuidHeader, NameConstraint.NSI_ACTING_USER_CIVIL_REGISTRATION_NUMBER);
127 133 return actingUserCivilRegistrationNumberAttribute.getAttributeValue();
128 134 }
129 135
136 + private String getBehalfOfCprNumber(HsuidHeader hsuidHeader) {
137 + Attribute responsibleUserCivilRegistrationNumber = getOptionalAttribute(hsuidHeader, NameConstraint.NSI_RESPONSIBLE_USER_CIVIL_REGISTRATION_NUMBER);
138 + return responsibleUserCivilRegistrationNumber != null ? responsibleUserCivilRegistrationNumber.getAttributeValue() : null;
139 + }
140 +
130 141 private ClientIdentificationTypeEnumeration getClientIdentificationTypeForOrgnisation(SubjectIdentifierType subjectIdentifier) {
131 142 switch(subjectIdentifier) {
132 143 case NSI_SKSCODE:
133 144 return ClientIdentificationTypeEnumeration.SKS;
134 145 case NSI_SORCODE:
135 146 return ClientIdentificationTypeEnumeration.SOR;
136 147 case NSI_YNUMBER:
137 148 return ClientIdentificationTypeEnumeration.YDERNUMMER;
138 149 default:
139 150 throw new IllegalArgumentException(String.format("Unexpected SubjectIdentifierType: %s", subjectIdentifier));
140 151 }
141 152 }
142 153
143 - private Attribute getAttribute(HsuidHeader hsuidHeader, NameConstraint nameConstraint) {
154 + private Attribute getRequiredAttribute(HsuidHeader hsuidHeader, NameConstraint nameConstraint) {
155 + return getAttribute(hsuidHeader, nameConstraint, true);
156 + }
157 +
158 + private Attribute getOptionalAttribute(HsuidHeader hsuidHeader, NameConstraint nameConstraint) {
159 + return getAttribute(hsuidHeader, nameConstraint, false);
160 + }
161 +
162 + private Attribute getAttribute(HsuidHeader hsuidHeader, NameConstraint nameConstraint, boolean required) {
144 163 for(Attribute a : hsuidHeader.getAssertion().getAttributeStatement().getAttribute()) {
145 164 if(a.getName().equals(nameConstraint)) {
146 165 return a;
147 166 }
148 167 }
149 168
150 - throw new IllegalArgumentException(String.format("No attribute matched name constraint %s", nameConstraint.toString()));
169 + if(required) {
170 + throw new IllegalArgumentException(String.format("No attribute matched name constraint %s", nameConstraint.toString()));
171 + }
172 +
173 + return null;
151 174 }
152 175 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut