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.responses;
17  
18  import org.openehealth.ipf.commons.core.modules.api.Validator;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryError;
20  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryResponse;
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.INVALID_ERROR_CODE_IN_RESPONSE;
26  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.INVALID_ERROR_INFO_IN_RESPONSE;
27  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.INVALID_SEVERITY_IN_RESPONSE;
28  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.INVALID_STATUS_IN_RESPONSE;
29  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
30  
31  /**
32   * Validate a {@link EbXMLRegistryResponse}.
33   *
34   * @author Jens Riemschneider
35   */
36  public class RegistryResponseValidator implements Validator<EbXMLRegistryResponse, ValidationProfile> {
37      private final HomeCommunityIdValidator hcValidator = new HomeCommunityIdValidator(true);
38  
39      @Override
40      public void validate(EbXMLRegistryResponse response, ValidationProfile profile) {
41          notNull(response, "response cannot be null");
42  
43          metaDataAssert(response.getStatus() != null, INVALID_STATUS_IN_RESPONSE);
44          for (EbXMLRegistryError registryError : response.getErrors()) {
45              metaDataAssert(registryError != null, INVALID_ERROR_INFO_IN_RESPONSE);
46              metaDataAssert(registryError.getErrorCode() != null, INVALID_ERROR_CODE_IN_RESPONSE);
47              metaDataAssert(registryError.getSeverity() != null, INVALID_SEVERITY_IN_RESPONSE);
48  
49              if (profile.getInteractionProfile().requiresHomeCommunityId()) {
50                  hcValidator.validate(registryError.getLocation());
51              }
52          }
53      }
54  }