Search in sources :

Example 1 with RelationalValueSearchQuery

use of com.evolveum.midpoint.schema.RelationalValueSearchQuery in project midpoint by Evolveum.

the class LookupTableHelper method updateLoadedLookupTable.

<T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
        return;
    }
    LOGGER.debug("Loading lookup table data.");
    GetOperationOptions getOption = findLookupTableGetOption(options);
    RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
    Query query = setupLookupTableRowsQuery(session, queryDef, object.getOid());
    if (queryDef != null && queryDef.getPaging() != null) {
        ObjectPaging paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            query.setFirstResult(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            query.setMaxResults(paging.getMaxSize());
        }
    }
    // noinspection unchecked
    List<RLookupTableRow> rows = query.list();
    if (CollectionUtils.isNotEmpty(rows)) {
        LookupTableType lookup = (LookupTableType) object.asObjectable();
        List<LookupTableRowType> jaxbRows = lookup.getRow();
        for (RLookupTableRow row : rows) {
            LookupTableRowType jaxbRow = row.toJAXB(prismContext);
            jaxbRows.add(jaxbRow);
        }
        PrismContainer<LookupTableRowType> rowContainer = object.findContainer(LookupTableType.F_ROW);
        rowContainer.setIncomplete(false);
    } else {
        PrismContainer<LookupTableRowType> rowContainer = object.findContainer(LookupTableType.F_ROW);
        if (rowContainer != null) {
            // just in case
            rowContainer.clear();
            rowContainer.setIncomplete(false);
        }
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) Query(org.hibernate.query.Query) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 2 with RelationalValueSearchQuery

use of com.evolveum.midpoint.schema.RelationalValueSearchQuery in project midpoint by Evolveum.

the class QLookupTableMapping method appendLookupTableRows.

private void appendLookupTableRows(UUID ownerOid, LookupTableType base, GetOperationOptions rowOptions, JdbcSession session) {
    try {
        RelationalValueSearchQuery queryDef = rowOptions == null ? null : rowOptions.getRelationalValueSearchQuery();
        QLookupTableRowMapping rowMapping = QLookupTableRowMapping.get();
        QLookupTableRow alias = rowMapping.defaultAlias();
        BooleanExpression whereQuery = appendConditions(alias, alias.ownerOid.eq(ownerOid), queryDef);
        SQLQuery<MLookupTableRow> query = session.newQuery().from(alias).select(alias).where(whereQuery);
        query = pagingAndOrdering(query, queryDef, rowMapping, alias);
        List<MLookupTableRow> result = query.fetch();
        for (MLookupTableRow r : result) {
            LookupTableRowType lookupRow = new LookupTableRowType().key(r.key);
            if (r.labelOrig != null || r.labelNorm != null) {
                lookupRow.label(PolyString.toPolyStringType(new PolyString(r.labelOrig, r.labelNorm)));
            }
            lookupRow.lastChangeTimestamp(MiscUtil.asXMLGregorianCalendar(r.lastChangeTimestamp));
            lookupRow.value(r.value);
            lookupRow.asPrismContainerValue().setId(r.cid);
            base.getRow().add(lookupRow);
        }
    } catch (QueryException e) {
        throw new SystemException("Unable to fetch nested table rows", e);
    }
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) SystemException(com.evolveum.midpoint.util.exception.SystemException) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Aggregations

RelationalValueSearchQuery (com.evolveum.midpoint.schema.RelationalValueSearchQuery)2 LookupTableRowType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)1 RLookupTableRow (com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)1 BooleanExpression (com.querydsl.core.types.dsl.BooleanExpression)1 Query (org.hibernate.query.Query)1