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.EbXMLSubmitObjectsRequest;
20  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
21  import org.openehealth.ipf.commons.ihe.xds.core.validate.HomeCommunityIdValidator;
22  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
23  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
24  
25  import static org.openehealth.ipf.commons.ihe.xds.XCMU.Interactions.CH_XCMU;
26  
27  /**
28   * Validates a {@link EbXMLSubmitObjectsRequest} request.
29   * @author Jens Riemschneider
30   */
31  public class SubmitObjectsRequestValidator implements Validator<EbXMLSubmitObjectsRequest, ValidationProfile> {
32      private static final ObjectContainerValidator OBJECT_CONTAINER_VALIDATOR = new ObjectContainerValidator();
33  
34      /**
35       * Validates the request.
36       * @param request
37       *          the request.
38       * @throws XDSMetaDataException
39       *          if the validation failed.
40       */
41      @Override
42      public void validate(EbXMLSubmitObjectsRequest request, ValidationProfile profile)  {
43          OBJECT_CONTAINER_VALIDATOR.validate(request, profile);
44  
45          HomeCommunityIdValidator homeCommunityIdValidator = new HomeCommunityIdValidator(profile == CH_XCMU);
46          homeCommunityIdValidator.validate(request.getSingleSlotValue(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID));
47      }
48  }