use of com.evolveum.midpoint.repo.sqale.ExtensionProcessor in project midpoint by Evolveum.
the class ExtensionItemFilterProcessor method process.
@Override
public Predicate process(ValueFilter<?, ?> filter) throws RepositoryException {
ItemDefinition<?> definition = filter.getDefinition();
Objects.requireNonNull(definition, "Item '" + filter.getPath() + "' without definition used in query.");
MExtItem extItem = new ExtensionProcessor((SqaleRepoContext) context.repositoryContext()).resolveExtensionItem(definition, holderType);
assert definition != null;
if (extItem == null) {
throw new QueryException("Extension item " + definition.getItemName() + " is not indexed, filter: " + filter);
}
if (definition instanceof PrismReferenceDefinition) {
return processReference(extItem, (RefFilter) filter);
}
PropertyValueFilter<?> propertyValueFilter = (PropertyValueFilter<?>) filter;
ValueFilterValues<?, ?> values = ValueFilterValues.from(propertyValueFilter);
FilterOperation operation = operation(filter);
List<?> filterValues = filter.getValues();
if (filterValues == null || filterValues.isEmpty()) {
if (operation.isAnyEqualOperation()) {
return extItemIsNull(extItem);
} else {
throw new QueryException("Null value for other than EQUAL filter: " + filter);
}
}
if (extItem.valueType.equals(STRING_TYPE)) {
return processString(extItem, values, operation, filter);
}
// TODO for anything lower we don't support multi-value filter yet, but the solution from string can be adapted.
if (filterValues.size() > 1) {
throw new QueryException("Multiple values in filter are not supported for extension items: " + filter);
}
if (ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition)) {
return processEnum(extItem, values, operation, filter);
} else if (extItem.valueType.equals(INT_TYPE) || extItem.valueType.equals(INTEGER_TYPE) || extItem.valueType.equals(LONG_TYPE) || extItem.valueType.equals(SHORT_TYPE) || extItem.valueType.equals(DOUBLE_TYPE) || extItem.valueType.equals(FLOAT_TYPE) || extItem.valueType.equals(DECIMAL_TYPE)) {
return processNumeric(extItem, values, operation, filter);
} else if (extItem.valueType.equals(BOOLEAN_TYPE)) {
return processBoolean(extItem, values, operation, filter);
} else if (extItem.valueType.equals(DATETIME_TYPE)) {
// noinspection unchecked
PropertyValueFilter<XMLGregorianCalendar> dateTimeFilter = (PropertyValueFilter<XMLGregorianCalendar>) filter;
return processString(extItem, ValueFilterValues.from(dateTimeFilter, ExtUtils::extensionDateTime), operation, filter);
} else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
return processPolyString(extItem, values, operation, propertyValueFilter);
}
throw new QueryException("Unsupported filter for extension item: " + filter);
}
use of com.evolveum.midpoint.repo.sqale.ExtensionProcessor in project midpoint by Evolveum.
the class ExtensionItemSqlMapper method primaryPath.
@Override
@Nullable
public Expression<?> primaryPath(Q entityPath, ItemDefinition<?> definition) throws QueryException {
Objects.requireNonNull(definition, "Null definition provided for extension/attributes item.");
JsonbPath path = rootToExtensionPath.apply(entityPath);
ExtItemInfo info = new ExtensionProcessor(repositoryContext).findExtensionItem(definition, holderType);
if (info == null) {
throw new QueryException("Extension property " + definition + " is not indexed and cannot be used for ordering.");
}
MExtItem extItem = info.item;
if (extItem.valueType.equals(STRING_TYPE) || ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition) || extItem.valueType.equals(DATETIME_TYPE)) {
return stringTemplate("{0}->>'{1s}'", path, info.getId());
} else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
return stringTemplate("{0}->'{1s}'->>'" + JsonbUtils.JSONB_POLY_ORIG_KEY + "'", path, info.getId());
} else {
return stringTemplate("{0}->'{1s}'", path, info.getId());
}
}
use of com.evolveum.midpoint.repo.sqale.ExtensionProcessor in project midpoint by Evolveum.
the class ExtensionItemDeltaProcessor method process.
@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
ItemPath itemPath = modification.getPath();
if (modification.getDefinition() instanceof PrismContainerDefinition<?>) {
// We do not index containers
return;
}
Item<PrismValue, ?> item = context.findValueOrItem(itemPath);
Collection<?> realValues = item != null ? item.getRealValues() : null;
ItemDefinition<?> definition = modification.getDefinition();
Objects.requireNonNull(definition, "Item '" + itemPath + "' without definition can't be saved.");
ExtensionProcessor extProcessor = new ExtensionProcessor(context.repositoryContext());
ExtensionProcessor.ExtItemInfo extItemInfo = extProcessor.findExtensionItem(definition, holderType);
if (extItemInfo == null) {
// not-indexed, no action
return;
}
// If the extension is single value (and we know it now, we should proceed with deletion of
// multivalue variant and vice-versa (this variants may be indroduced during raw import
// or changes in multiplicity of extension definition or resource definition
context.deleteItem(reverseCardinality(extProcessor, extItemInfo.item));
if (realValues == null || realValues.isEmpty()) {
context.deleteItem(extItemInfo.getId());
return;
}
// changed value
context.setChangedItem(extItemInfo.getId(), extProcessor.extItemValue(item, extItemInfo));
}
Aggregations