View Javadoc
1   /*
2    * Copyright 2012 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;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryObject;
20  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
21  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
22  
23  import java.util.HashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.AUTHOR_INCOMPLETE;
28  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
29  
30  /**
31   * @author Dmytro Rud
32   */
33  public class AuthorClassificationValidation extends ClassificationValidation {
34      private static final Set<String> SLOT_NAMES;
35      static {
36          SLOT_NAMES = new HashSet<>();
37          SLOT_NAMES.add(Vocabulary.SLOT_NAME_AUTHOR_PERSON);
38          SLOT_NAMES.add(Vocabulary.SLOT_NAME_AUTHOR_TELECOM);
39          SLOT_NAMES.add(Vocabulary.SLOT_NAME_AUTHOR_INSTITUTION);
40      }
41  
42      public AuthorClassificationValidation(String classScheme, SlotValueValidation[] slotValidations) {
43          super(classScheme, 0, Integer.MAX_VALUE, Vocabulary.DisplayNameUsage.OPTIONAL, Vocabulary.NodeRepresentationUsage.PROHIBITED, slotValidations);
44      }
45  
46      @Override
47      public void validate(EbXMLRegistryObject obj) throws XDSMetaDataException {
48          super.validate(obj);
49  
50          List<EbXMLClassification> classifications = obj.getClassifications(classScheme);
51          for (EbXMLClassification classification : classifications) {
52              // check whether at least an authorPerson, authorTelecommunication,
53              // or authorInstitution sub-attribute is present
54              boolean authorComplete = false;
55              for (EbXMLSlot slot : classification.getSlots()) {
56                  if (SLOT_NAMES.contains(slot.getName())) {
57                      authorComplete = true;
58                      break;
59                  }
60              }
61              metaDataAssert(authorComplete, AUTHOR_INCOMPLETE, classScheme);
62          }
63  
64      }
65  }