Search in sources :

Example 1 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class ExtensionProcessor method addSingleValueIndex.

private void addSingleValueIndex(Map<String, Object> extMap, Item<?, ?> item, MExtItemHolderType holderType) {
    ItemDefinition<?> extDef = item.getDefinition();
    Key singleValueKey = MExtItem.keyFrom(extDef, holderType, MExtItemCardinality.SCALAR);
    MExtItem singleValueExt = repositoryContext.resolveExtensionItem(singleValueKey);
    ExtItemInfo singleInfo = extItemInfo(singleValueExt, extDef);
    Object singleValue = extItemValue(item, singleInfo);
    extMap.put(singleInfo.getId(), singleValue);
}
Also used : MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) Key(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem.Key)

Example 2 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem 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);
}
Also used : ExtUtils(com.evolveum.midpoint.repo.sqale.ExtUtils) SqaleRepoContext(com.evolveum.midpoint.repo.sqale.SqaleRepoContext) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 3 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem 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)

Example 4 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class QShadowMapping method addIndexOnlyAttributes.

private void addIndexOnlyAttributes(ShadowType shadowType, Tuple row, QShadow entityPath, List<SelectorOptions<GetOperationOptions>> retrieveOptions) throws SchemaException {
    Jsonb rowAttributes = row.get(entityPath.attributes);
    if (rowAttributes == null) {
        return;
    }
    Map<String, Object> attributes = Jsonb.toMap(rowAttributes);
    if (attributes.isEmpty()) {
        return;
    }
    ShadowAttributesType attributeContainer = shadowType.getAttributes();
    if (attributeContainer == null) {
        attributeContainer = new ShadowAttributesType(prismContext());
        shadowType.attributes(attributeContainer);
    }
    // noinspection unchecked
    PrismContainerValue<ShadowAttributesType> container = attributeContainer.asPrismContainerValue();
    // Now we retrieve indexOnly options
    for (Entry<String, Object> attribute : attributes.entrySet()) {
        @Nullable MExtItem mapping = repositoryContext().getExtensionItem(Integer.valueOf(attribute.getKey()));
        QName itemName = QNameUtil.uriToQName(mapping.itemName);
        ItemDefinition<?> definition = definitionFrom(itemName, mapping, true);
        if (definition instanceof PrismPropertyDefinition) {
            var item = container.findOrCreateProperty((PrismPropertyDefinition) definition);
            switch(mapping.cardinality) {
                case SCALAR:
                    item.setRealValue(attribute.getValue());
                    break;
                case ARRAY:
                    List<?> value = (List<?>) attribute.getValue();
                    item.setRealValues(value.toArray());
                    break;
                default:
                    throw new IllegalStateException("");
            }
            if (item.isIncomplete() && (item.getDefinition() == null || !item.getDefinition().isIndexOnly())) {
                // Item was not fully serialized / probably indexOnly item
                item.applyDefinition((PrismPropertyDefinition) definition);
            }
            item.setIncomplete(false);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) Jsonb(com.evolveum.midpoint.repo.sqale.jsonb.Jsonb) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class QShadowMapping method applyShadowAttributesDefinitions.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void applyShadowAttributesDefinitions(ShadowType shadowType, Jsonb rowAttributes) throws SchemaException {
    Map<QName, MExtItem> definitions = definitionsFrom(rowAttributes);
    if (shadowType.getAttributes() == null) {
        return;
    }
    PrismContainerValue<?> attributes = shadowType.getAttributes().asPrismContainerValue();
    for (Item<?, ?> attribute : attributes.getItems()) {
        ItemName itemName = attribute.getElementName();
        MExtItem itemInfo = definitions.get(itemName);
        if (itemInfo != null && attribute.getDefinition() == null) {
            ((Item) attribute).applyDefinition(definitionFrom(itemName, itemInfo, false), true);
        }
    }
}
Also used : MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Aggregations

MExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem)9 QExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem)3 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)3 QName (javax.xml.namespace.QName)3 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)2 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)2 Nullable (org.jetbrains.annotations.Nullable)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)1 ExtUtils (com.evolveum.midpoint.repo.sqale.ExtUtils)1 ExtItemInfo (com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 Jsonb (com.evolveum.midpoint.repo.sqale.jsonb.Jsonb)1 JsonbPath (com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath)1 Key (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem.Key)1 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)1 ShadowAttributesType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 NotNull (org.jetbrains.annotations.NotNull)1