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.query;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.INVALID_QUERY_PARAMETER_VALUE;
20 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.MISSING_REQUIRED_QUERY_PARAMETER;
21 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.PARAMETER_VALUE_NOT_STRING_LIST;
22 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
23
24 import java.util.List;
25 import java.util.regex.Pattern;
26
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
28 import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
29 import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
30 import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.QuerySlotHelper;
31 import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
32
33
34
35
36
37 public class StatusValidation implements QueryParameterValidation {
38 private static final Pattern PATTERN =
39 Pattern.compile("\\s*\\(\\s*'.*'(\\s*,\\s*'.*')*\\s*\\)\\s*");
40
41 private final QueryParameter param;
42
43
44
45
46
47
48 public StatusValidation(QueryParameter param) {
49 notNull(param, "param cannot be null");
50 this.param = param;
51 }
52
53 @Override
54 public void validate(EbXMLAdhocQueryRequest request) throws XDSMetaDataException {
55 List<String> slotValues = request.getSlotValues(param.getSlotName());
56 metaDataAssert(!slotValues.isEmpty(), MISSING_REQUIRED_QUERY_PARAMETER, slotValues);
57 for (String slotValue : slotValues) {
58 metaDataAssert(slotValue != null, MISSING_REQUIRED_QUERY_PARAMETER, param);
59 metaDataAssert(PATTERN.matcher(slotValue).matches(),
60 PARAMETER_VALUE_NOT_STRING_LIST, param);
61 }
62
63 QuerySlotHelper slots = new QuerySlotHelper(request);
64
65 List<AvailabilityStatus> list = slots.toStatus(param);
66
67 if (list.isEmpty()) {
68 for (String value : slots.toStringList(param)) {
69 metaDataAssert(AvailabilityStatus.valueOfOpcode(value) != null, INVALID_QUERY_PARAMETER_VALUE, value);
70 }
71 }
72 metaDataAssert(!list.isEmpty(), MISSING_REQUIRED_QUERY_PARAMETER, slotValues);
73
74 }
75 }