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;
17
18 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.HOME_COMMUNITY_ID_MUST_BE_SPECIFIED;
19 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.INVALID_OID;
20 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
21
22
23
24
25
26 public class HomeCommunityIdValidator implements ValueValidator {
27 private final boolean required;
28
29
30
31
32
33
34
35 public HomeCommunityIdValidator(boolean required) {
36 this.required = required;
37 }
38
39 @Override
40 public void validate(String homeCommunityId) throws XDSMetaDataException {
41 if (required) {
42 metaDataAssert((homeCommunityId != null) && (! homeCommunityId.isEmpty()),
43 HOME_COMMUNITY_ID_MUST_BE_SPECIFIED);
44 }
45 if (homeCommunityId != null) {
46 metaDataAssert(homeCommunityId.startsWith("urn:oid:"), INVALID_OID, homeCommunityId);
47 new OIDValidator().validate(homeCommunityId.substring(8));
48 }
49 }
50 }