Search in sources :

Example 1 with ExtItemInfo

use of com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo 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());
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) ExtItemInfo(com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo) JsonbPath(com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)1 ExtItemInfo (com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo)1 JsonbPath (com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath)1 MExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 Nullable (org.jetbrains.annotations.Nullable)1