View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.validate.requests;
17  
18  import org.openehealth.ipf.commons.core.modules.api.Validator;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLNonconstructiveDocumentSetRequest;
20  import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
21  import org.openehealth.ipf.commons.ihe.xds.core.validate.HomeCommunityIdValidator;
22  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
23  
24  import static org.apache.commons.lang3.Validate.notNull;
25  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.DOC_ID_MUST_BE_SPECIFIED;
26  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.REPO_ID_MUST_BE_SPECIFIED;
27  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
28  
29  /**
30   * Validates a {@link EbXMLNonconstructiveDocumentSetRequest}.
31   * @author Jens Riemschneider
32   */
33  public class NonconstructiveDocumentSetRequestValidator implements Validator<EbXMLNonconstructiveDocumentSetRequest, ValidationProfile> {
34      private final HomeCommunityIdValidator hcValidator = new HomeCommunityIdValidator(true);
35  
36      @Override
37      public void validate(EbXMLNonconstructiveDocumentSetRequest request, ValidationProfile profile) {
38          notNull(request, "request cannot be null");
39          
40          for (DocumentReference document : request.getDocuments()) {
41              String repoId = document.getRepositoryUniqueId();
42              metaDataAssert(repoId != null && !repoId.isEmpty(), REPO_ID_MUST_BE_SPECIFIED);
43              
44              String docId = document.getDocumentUniqueId();
45              metaDataAssert(docId != null && !docId.isEmpty(), DOC_ID_MUST_BE_SPECIFIED);
46  
47              if (profile.getInteractionProfile().requiresHomeCommunityId()) {
48                  hcValidator.validate(document.getHomeCommunityId());
49              }
50          }
51      }
52  }