Search in sources :

Example 1 with JpaAnyItemLinkDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyItemLinkDefinition in project midpoint by Evolveum.

the class JpaAnyContainerDefinition method nextLinkDefinition.

@Override
public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) throws QueryException {
    if (ItemPath.asSingleName(path) == null) {
        throw new QueryException("Couldn't resolve paths other than those in the form of single name in extension/attributes container: " + path);
    }
    if (itemDefinition == null) {
        throw new QueryException("Couldn't resolve dynamically defined item path '" + path + "' without proper definition");
    }
    CollectionSpecification collSpec = itemDefinition.isSingleValue() ? null : new CollectionSpecification();
    // longs, strings, ...
    String jpaName;
    JpaDataNodeDefinition jpaNodeDefinition;
    if (itemDefinition instanceof PrismPropertyDefinition) {
        try {
            jpaName = RAnyConverter.getAnySetType(itemDefinition, prismContext);
        } catch (SchemaException e) {
            throw new QueryException(e.getMessage(), e);
        }
        // TODO
        jpaNodeDefinition = new JpaAnyPropertyDefinition(Object.class, null);
    } else if (itemDefinition instanceof PrismReferenceDefinition) {
        jpaName = "references";
        jpaNodeDefinition = new JpaAnyReferenceDefinition(Object.class, RObject.class);
    } else {
        throw new QueryException("Unsupported 'any' item: " + itemDefinition);
    }
    JpaLinkDefinition<?> linkDefinition = new JpaAnyItemLinkDefinition(itemDefinition.getName(), jpaName, collSpec, getOwnerType(), jpaNodeDefinition);
    return new DataSearchResult<>(linkDefinition, ItemPath.EMPTY_PATH);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) DataSearchResult(com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject)

Example 2 with JpaAnyItemLinkDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyItemLinkDefinition in project midpoint by Evolveum.

the class ItemPathResolver method createJoinCondition.

private Condition createJoinCondition(String joinedItemAlias, JpaLinkDefinition joinedItemDefinition, RootHibernateQuery hibernateQuery) throws QueryException {
    Condition condition = null;
    if (joinedItemDefinition instanceof JpaAnyItemLinkDefinition) {
        JpaAnyItemLinkDefinition anyLinkDef = (JpaAnyItemLinkDefinition) joinedItemDefinition;
        AndCondition conjunction = hibernateQuery.createAnd();
        if (anyLinkDef.getOwnerType() != null) {
            // null for assignment extensions
            conjunction.add(hibernateQuery.createEq(joinedItemAlias + ".ownerType", anyLinkDef.getOwnerType()));
        }
        conjunction.add(hibernateQuery.createEq(joinedItemAlias + "." + RAnyValue.F_NAME, RUtil.qnameToString(anyLinkDef.getItemName())));
        condition = conjunction;
    } else if (joinedItemDefinition.getCollectionSpecification() instanceof VirtualCollectionSpecification) {
        VirtualCollectionSpecification vcd = (VirtualCollectionSpecification) joinedItemDefinition.getCollectionSpecification();
        List<Condition> conditions = new ArrayList<>(vcd.getAdditionalParams().length);
        for (VirtualQueryParam vqp : vcd.getAdditionalParams()) {
            // e.g. name = "assignmentOwner", type = RAssignmentOwner.class, value = "ABSTRACT_ROLE"
            Object value = createQueryParamValue(vqp);
            Condition c = hibernateQuery.createEq(joinedItemAlias + "." + vqp.name(), value);
            conditions.add(c);
        }
        if (conditions.size() > 1) {
            condition = hibernateQuery.createAnd(conditions);
        } else if (conditions.size() == 1) {
            condition = conditions.iterator().next();
        }
    }
    return condition;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) JpaAnyItemLinkDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyItemLinkDefinition) VirtualQueryParam(com.evolveum.midpoint.repo.sql.query.definition.VirtualQueryParam) VirtualCollectionSpecification(com.evolveum.midpoint.repo.sql.query2.definition.VirtualCollectionSpecification) ArrayList(java.util.ArrayList) List(java.util.List) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)

Aggregations

RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 VirtualQueryParam (com.evolveum.midpoint.repo.sql.query.definition.VirtualQueryParam)1 JpaAnyItemLinkDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyItemLinkDefinition)1 VirtualCollectionSpecification (com.evolveum.midpoint.repo.sql.query2.definition.VirtualCollectionSpecification)1 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)1 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)1 DataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1