AdhocQueryRequestValidator implements Validator<EbXMLAdhocQueryRequest, ValidationProfile> { @Override public void validate(EbXMLAdhocQueryRequest request, ValidationProfile profile) { notNull(request, "request cannot be null"); if (profile.getInteractionId() == IpfInteractionId.ITI_63) { metaDataAssert(QueryReturnType.LEAF_CLASS_WITH_REPOSITORY_ITEM.getCode().equals(request.getReturnType()), UNKNOWN_RETURN_TYPE, request.getReturnType()); } else { metaDataAssert(QueryReturnType.LEAF_CLASS.getCode().equals(request.getReturnType()) || QueryReturnType.OBJECT_REF.getCode().equals(request.getReturnType()), UNKNOWN_RETURN_TYPE, request.getReturnType()); } QueryType queryType = QueryType.valueOfId(request.getId()); metaDataAssert(queryType != null, UNKNOWN_QUERY_TYPE, request.getId()); boolean found = false; for(Map.Entry<List<InteractionId>, List<QueryType>> entry : ALLOWED_QUERY_TYPES.entrySet()) { if (entry.getKey().contains(profile.getInteractionId())) { metaDataAssert(entry.getValue().contains(queryType), UNSUPPORTED_QUERY_TYPE, queryType); found = true; break; } } metaDataAssert(found, UNKNOWN_QUERY_TYPE, queryType); if (queryType == QueryType.SQL) { metaDataAssert(request.getSql() != null, MISSING_SQL_QUERY_TEXT); } else { new SlotLengthAndNameUniquenessValidator().validateSlots( request.getSlots(), ALLOWED_MULTIPLE_SLOTS.get(queryType)); for (QueryParameterValidation validation : getValidators(queryType, profile)) { validation.validate(request); } if (queryType == FIND_DOCUMENTS_MPQ) { metaDataAssert( (! request.getSlotValues(DOC_ENTRY_CLASS_CODE.getSlotName()).isEmpty()) || (! request.getSlotValues(DOC_ENTRY_EVENT_CODE.getSlotName()).isEmpty()) || (! request.getSlotValues(DOC_ENTRY_HEALTHCARE_FACILITY_TYPE_CODE.getSlotName()).isEmpty()), ValidationMessage.MISSING_REQUIRED_QUERY_PARAMETER, "at least one of $XDSDocumentEntryClassCode, $XDSDocumentEntryEventCodeList, $XDSDocumentEntryHealthcareFacilityTypeCode"); } } }  @Override void validate(EbXMLAdhocQueryRequest request, ValidationProfile profile);  }
@Test public void testGoodCase() throws XDSMetaDataException { validator.validate(transformer.toEbXML(request), iti18Profile); }
@Test public void testCodeListOldStyleCorrect() { EbXMLAdhocQueryRequest ebXML = transformer.toEbXML(request); ebXML.getSlots(QueryParameter.DOC_ENTRY_CLASS_CODE.getSlotName()).get(0).getValueList().set(0, "('code1')"); ebXML.getSlots(QueryParameter.DOC_ENTRY_CLASS_CODE.getSlotName()).get(0).getValueList().set(1, "('code2')"); ebXML.addSlot(QueryParameter.DOC_ENTRY_CLASS_CODE_SCHEME.getSlotName(), "('scheme1','scheme2')"); validator.validate(transformer.toEbXML(request), iti18Profile); }
@Test public void testUnknownStatusCodes() { EbXMLAdhocQueryRequest ebXML = transformer.toEbXML(request); List<String> valueList = ebXML.getSlots(QueryParameter.DOC_ENTRY_STATUS.getSlotName()).get(0).getValueList(); valueList.clear(); expectFailure(MISSING_REQUIRED_QUERY_PARAMETER, ebXML, iti18Profile); valueList.clear(); valueList.add("('lol')"); valueList.add("('foo')"); expectFailure(MISSING_REQUIRED_QUERY_PARAMETER, ebXML, iti18Profile); valueList.set(0, "('bar')"); valueList.set(1, "('Approved')"); validator.validate(ebXML, iti18Profile); }
@Test public void testGoodCaseMPQ() throws XDSMetaDataException { validator.validate(transformer.toEbXML(requestMpq), iti51Profile); }
@Test public void testMissingPatientIdsMPQ() { ((FindDocumentsForMultiplePatientsQuery) requestMpq.getQuery()).setPatientIds(null); validator.validate(transformer.toEbXML(requestMpq), iti51Profile); }
@Test public void testGoodCaseFolder() throws XDSMetaDataException { validator.validate(transformer.toEbXML(folderRequest), iti18Profile); }
@Test public void testMissingPatientIdFolderMPQ() { ((FindFoldersForMultiplePatientsQuery) folderRequestMpq.getQuery()).setPatientIds(null); validator.validate(transformer.toEbXML(folderRequestMpq), iti51Profile); }
@Test public void testGoodCaseFolderMPQ() throws XDSMetaDataException { validator.validate(transformer.toEbXML(folderRequestMpq), iti51Profile); }
@Test public void testGoodCaseSql() throws XDSMetaDataException { validator.validate(transformer.toEbXML(SampleData.createSqlQuery()), iti16Profile); }