use of com.b2international.commons.exceptions.NotImplementedException in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
final Collection<String> referencedComponentIds = getCollection(OptionKey.REFERENCED_COMPONENT, String.class);
final Collection<SnomedRefSetType> refSetTypes = getCollection(OptionKey.REFSET_TYPE, SnomedRefSetType.class);
final Options propsFilter = getOptions(OptionKey.PROPS);
ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEffectiveTimeClause(queryBuilder);
addEclFilter(context, queryBuilder, OptionKey.REFSET, SnomedRefSetMemberIndexEntry.Expressions::refsetIds);
addComponentClause(queryBuilder);
if (containsKey(OptionKey.REFERENCED_COMPONENT_TYPE)) {
queryBuilder.filter(referencedComponentTypes(getCollection(OptionKey.REFERENCED_COMPONENT_TYPE, String.class)));
}
if (!referencedComponentIds.isEmpty()) {
queryBuilder.filter(referencedComponentIds(referencedComponentIds));
}
if (!refSetTypes.isEmpty()) {
queryBuilder.filter(refSetTypes(refSetTypes));
}
if (!propsFilter.isEmpty()) {
final Set<String> propKeys = newHashSet(propsFilter.keySet());
if (propKeys.remove(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID)) {
queryBuilder.filter(acceptabilityIds(propsFilter.getCollection(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP)) {
final String operatorKey = SearchResourceRequest.operator(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP);
SearchResourceRequest.Operator op;
if (propKeys.remove(operatorKey)) {
op = propsFilter.get(operatorKey, Operator.class);
} else {
op = SearchResourceRequest.Operator.EQUALS;
}
switch(op) {
case EQUALS:
queryBuilder.filter(relationshipGroup(propsFilter.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, Integer.class)));
break;
case NOT_EQUALS:
queryBuilder.mustNot(relationshipGroup(propsFilter.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, Integer.class)));
break;
default:
throw new NotImplementedException("Unsupported relationship group operator %s", op);
}
}
if (propKeys.remove(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::characteristicTypeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_CORRELATION_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_CORRELATION_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::correlationIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_DESCRIPTION_FORMAT)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_DESCRIPTION_FORMAT, String.class), SnomedRefSetMemberIndexEntry.Expressions::descriptionFormats);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::mapCategoryIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::targetComponentIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_TARGET)) {
queryBuilder.filter(mapTargets(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_TARGET, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_TARGET_DESCRIPTION)) {
queryBuilder.filter(mapTargetDescriptions(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_TARGET_DESCRIPTION, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_GROUP)) {
queryBuilder.filter(mapGroups(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_GROUP, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_PRIORITY)) {
queryBuilder.filter(mapPriority(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_PRIORITY, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_BLOCK)) {
queryBuilder.filter(mapBlock(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_BLOCK, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_VALUE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_VALUE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::valueIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::typeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_DOMAIN_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_DOMAIN_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::domainIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_CONTENT_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_CONTENT_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::contentTypeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RULE_STRENGTH_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_RULE_STRENGTH_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::ruleStrengthIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::ruleRefSetIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_GROUPED)) {
queryBuilder.filter(grouped(propsFilter.getBoolean(SnomedRf2Headers.FIELD_MRCM_GROUPED)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RANGE_CONSTRAINT)) {
queryBuilder.filter(rangeConstraint(propsFilter.getString(SnomedRf2Headers.FIELD_MRCM_RANGE_CONSTRAINT)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_OWL_EXPRESSION)) {
queryBuilder.filter(Expressions.exactMatch(SnomedRf2Headers.FIELD_OWL_EXPRESSION, propsFilter.getString(SnomedRf2Headers.FIELD_OWL_EXPRESSION)));
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_CONCEPTID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_CONCEPTID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionConcept);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_DESTINATIONID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_DESTINATIONID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionDestination);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_TYPEID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_TYPEID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionType);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_GCI)) {
queryBuilder.filter(gciAxiom(propsFilter.getBoolean(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_GCI)));
}
final Collection<DataType> dataTypes = propsFilter.getCollection(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE, DataType.class);
if (propKeys.remove(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE)) {
queryBuilder.filter(dataTypes(dataTypes));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_VALUE)) {
if (dataTypes.size() != 1) {
throw new BadRequestException("DataType filter must be specified if filtering by value");
}
final DataType dataType = Iterables.getOnlyElement(dataTypes);
final String operatorKey = SearchResourceRequest.operator(SnomedRf2Headers.FIELD_VALUE);
SearchResourceRequest.Operator op;
if (propKeys.remove(operatorKey)) {
op = propsFilter.get(operatorKey, Operator.class);
} else {
op = SearchResourceRequest.Operator.EQUALS;
}
final Collection<Object> attributeValues = propsFilter.getCollection(SnomedRf2Headers.FIELD_VALUE, Object.class);
switch(op) {
case EQUALS:
queryBuilder.filter(values(dataType, attributeValues));
break;
case NOT_EQUALS:
queryBuilder.mustNot(values(dataType, attributeValues));
break;
case LESS_THAN:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, null, Iterables.getOnlyElement(attributeValues), false, false));
break;
case LESS_THAN_EQUALS:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, null, Iterables.getOnlyElement(attributeValues), false, true));
break;
case GREATER_THAN:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, Iterables.getOnlyElement(attributeValues), null, false, false));
break;
case GREATER_THAN_EQUALS:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, Iterables.getOnlyElement(attributeValues), null, true, false));
break;
default:
throw new NotImplementedException("Unsupported concrete domain value operator %s", op);
}
}
if (!propKeys.isEmpty()) {
throw new IllegalQueryParameterException("Unsupported property filter(s), %s", propKeys);
}
}
return queryBuilder.build();
}
use of com.b2international.commons.exceptions.NotImplementedException in project snow-owl by b2ihealthcare.
the class SnomedEclEvaluationRequest method eval.
protected Promise<Expression> eval(BranchContext context, final DialectIdFilter dialectIdFilter) {
final Multimap<String, String> languageRefSetsByAcceptability = HashMultimap.create();
final ExpressionBuilder dialectQuery = Expressions.builder();
for (Dialect dialect : dialectIdFilter.getDialects()) {
final ExpressionConstraint languageRefSetId = dialect.getLanguageRefSetId();
final Set<String> evaluatedIds = EclExpression.of(languageRefSetId, expressionForm).resolve(context).getSync();
final Set<String> acceptabilitiesToMatch = getAcceptabilityFields(dialect.getAcceptability());
// empty set means that acceptability values are not valid and it should not match any descriptions/concepts
if (acceptabilitiesToMatch.isEmpty()) {
return Promise.immediate(Expressions.matchNone());
}
for (String acceptability : acceptabilitiesToMatch) {
languageRefSetsByAcceptability.putAll(acceptability, evaluatedIds);
}
}
languageRefSetsByAcceptability.asMap().forEach((key, values) -> {
Operator op = Operator.fromString(dialectIdFilter.getOp());
switch(op) {
case EQUALS:
dialectQuery.should(Expressions.matchAny(key, values));
break;
case NOT_EQUALS:
dialectQuery.mustNot(Expressions.matchAny(key, values));
break;
default:
throw new NotImplementedException("Unsupported dialectIdFilter operator '%s'", dialectIdFilter.getOp());
}
});
return Promise.immediate(dialectQuery.build());
}
use of com.b2international.commons.exceptions.NotImplementedException in project snow-owl by b2ihealthcare.
the class SearchMergeRequest method createMergefromJobEntry.
public static Merge createMergefromJobEntry(RemoteJobEntry job, ObjectMapper mapper) {
// the final state will be available as job result value
if (job.isSuccessful()) {
return job.getResultAs(mapper, Merge.class);
}
// any other state should be computed from the ongoing remote job
final Map<String, Object> params = job.getParameters(mapper);
final String source = (String) params.get(SOURCE_FIELD);
final String target = (String) params.get(TARGET_FIELD);
final Builder merge = Merge.builder().id(job.getId()).source(source).target(target).startDate(job.getStartDate()).scheduledDate(job.getScheduleDate()).endDate(job.getFinishDate());
switch(job.getState()) {
case FINISHED:
return merge.status(Status.COMPLETED).build();
case CANCEL_REQUESTED:
return merge.status(Status.CANCEL_REQUESTED).build();
case CANCELED:
return merge.status(Status.FAILED).build();
case FAILED:
return merge.status(Status.FAILED).apiError(job.getResultAs(mapper, ApiError.class)).build();
case RUNNING:
return merge.status(Status.IN_PROGRESS).build();
case SCHEDULED:
return merge.status(Status.SCHEDULED).build();
default:
throw new NotImplementedException("Not implemented case for " + job.getState());
}
}
use of com.b2international.commons.exceptions.NotImplementedException in project snow-owl by b2ihealthcare.
the class SnomedEclEvaluationRequest method eval.
protected Promise<Expression> eval(BranchContext context, final DialectAliasFilter dialectAliasFilter) {
final ListMultimap<String, String> languageMapping = SnomedDescriptionUtils.getLanguageMapping(context);
final Multimap<String, String> languageRefSetsByAcceptabilityField = HashMultimap.create();
final ExpressionBuilder dialectQuery = Expressions.builder();
for (DialectAlias alias : dialectAliasFilter.getDialects()) {
final Set<String> acceptabilityFields = getAcceptabilityFields(alias.getAcceptability());
final Collection<String> languageReferenceSetIds = languageMapping.get(alias.getAlias());
// empty acceptabilities or empty language reference set IDs mean that none of the provided values were valid so no match should be returned
if (acceptabilityFields.isEmpty() || languageReferenceSetIds.isEmpty()) {
return Promise.immediate(Expressions.matchNone());
}
for (String acceptabilityField : acceptabilityFields) {
languageRefSetsByAcceptabilityField.putAll(acceptabilityField, languageReferenceSetIds);
}
}
languageRefSetsByAcceptabilityField.asMap().forEach((key, values) -> {
Operator op = Operator.fromString(dialectAliasFilter.getOp());
switch(op) {
case EQUALS:
dialectQuery.should(Expressions.matchAny(key, values));
break;
case NOT_EQUALS:
dialectQuery.mustNot(Expressions.matchAny(key, values));
break;
default:
throw new NotImplementedException("Unsupported dialectAliasFilter operator '%s'", dialectAliasFilter.getOp());
}
});
return Promise.immediate(dialectQuery.build());
}
use of com.b2international.commons.exceptions.NotImplementedException in project snow-owl by b2ihealthcare.
the class SnomedRelationshipSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addNamespaceFilter(queryBuilder);
addNamespaceConceptIdFilter(context, queryBuilder);
addEffectiveTimeClause(queryBuilder);
addActiveMemberOfClause(context, queryBuilder);
addMemberOfClause(context, queryBuilder);
addEclFilter(context, queryBuilder, OptionKey.SOURCE, SnomedRelationshipIndexEntry.Expressions::sourceIds);
addEclFilter(context, queryBuilder, OptionKey.TYPE, SnomedRelationshipIndexEntry.Expressions::typeIds);
addEclFilter(context, queryBuilder, OptionKey.DESTINATION, SnomedRelationshipIndexEntry.Expressions::destinationIds);
addEclFilter(context, queryBuilder, OptionKey.CHARACTERISTIC_TYPE, SnomedRelationshipIndexEntry.Expressions::characteristicTypeIds);
addEclFilter(context, queryBuilder, OptionKey.MODIFIER, SnomedRelationshipIndexEntry.Expressions::modifierIds);
if (containsKey(OptionKey.GROUP_MIN) || containsKey(OptionKey.GROUP_MAX)) {
final int from = containsKey(OptionKey.GROUP_MIN) ? get(OptionKey.GROUP_MIN, Integer.class) : 0;
final int to = containsKey(OptionKey.GROUP_MAX) ? get(OptionKey.GROUP_MAX, Integer.class) : Integer.MAX_VALUE;
queryBuilder.filter(relationshipGroup(from, to));
}
if (containsKey(OptionKey.UNION_GROUP)) {
queryBuilder.filter(unionGroup(get(OptionKey.UNION_GROUP, Integer.class)));
}
if (containsKey(OptionKey.HAS_DESTINATION_ID)) {
// No need to check the value for the option key here, as it can only be set to "true" in the builder
queryBuilder.filter(hasDestinationId());
}
if (containsKey(OptionKey.VALUE_TYPE)) {
final Collection<RelationshipValueType> valueTypes = getCollection(OptionKey.VALUE_TYPE, RelationshipValueType.class);
queryBuilder.filter(valueTypes(valueTypes));
}
if (containsKey(OptionKey.VALUE)) {
final SearchResourceRequest.Operator op = get(OptionKey.OPERATOR, SearchResourceRequest.Operator.class);
final Collection<RelationshipValue> values = getCollection(OptionKey.VALUE, RelationshipValue.class);
switch(op) {
case EQUALS:
queryBuilder.filter(values(values));
break;
case NOT_EQUALS:
queryBuilder.mustNot(values(values));
break;
case LESS_THAN:
checkRangeValue(values);
queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), false));
break;
case LESS_THAN_EQUALS:
checkRangeValue(values);
queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), true));
break;
case GREATER_THAN:
checkRangeValue(values);
queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), false));
break;
case GREATER_THAN_EQUALS:
checkRangeValue(values);
queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), true));
break;
default:
throw new NotImplementedException("Unsupported concrete value operator %s", op);
}
}
return queryBuilder.build();
}
Aggregations