1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.validate.requests;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19 import org.openehealth.ipf.commons.core.modules.api.Validator;
20 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLExtrinsicObject;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLProvideAndRegisterDocumentSetRequest;
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSubmitObjectsRequest;
23 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.MISSING_DOCUMENT_FOR_DOC_ENTRY;
24 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.MISSING_DOC_ENTRY_FOR_DOCUMENT;
25
26 import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
27 import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
28 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
29
30 import javax.activation.DataHandler;
31 import java.util.HashSet;
32 import java.util.Map;
33 import java.util.Set;
34
35
36
37
38
39 public class ProvideAndRegisterDocumentSetRequestValidator implements Validator<EbXMLProvideAndRegisterDocumentSetRequest, ValidationProfile>{
40 private final SubmitObjectsRequestValidator submitObjectsRequestValidator =
41 new SubmitObjectsRequestValidator();
42
43 @Override
44 public void validate(EbXMLProvideAndRegisterDocumentSetRequest request, ValidationProfile profile) {
45 notNull(request, "request cannot be null");
46
47 submitObjectsRequestValidator.validate(request, profile);
48
49 validateDocuments(request);
50 }
51
52 private void validateDocuments(EbXMLProvideAndRegisterDocumentSetRequest request) {
53 Map<String, DataHandler> documents = request.getDocuments();
54
55 Set<String> docEntryIds = new HashSet<>();
56 for (EbXMLExtrinsicObject docEntry : request.getExtrinsicObjects(DocumentEntryType.STABLE.getUuid())) {
57 String docId = docEntry.getId();
58 if (docId != null) {
59 docEntryIds.add(docId);
60 metaDataAssert(documents.get(docId) != null, MISSING_DOCUMENT_FOR_DOC_ENTRY, docId);
61 }
62 }
63
64 for (String docId : documents.keySet()) {
65 metaDataAssert(docEntryIds.contains(docId), MISSING_DOC_ENTRY_FOR_DOCUMENT, docId);
66 }
67 }
68 }