Search in sources :

Example 1 with SqlQueryContext

use of com.evolveum.midpoint.repo.sqlbase.SqlQueryContext in project midpoint by Evolveum.

the class QOperationExecutionMapping method createRowTransformer.

@Override
public ResultListRowTransformer<OperationExecutionType, QOperationExecution<OR>, MOperationExecution> createRowTransformer(SqlQueryContext<OperationExecutionType, QOperationExecution<OR>, MOperationExecution> sqlQueryContext, JdbcSession jdbcSession) {
    Map<UUID, ObjectType> owners = new HashMap<>();
    return new ResultListRowTransformer<>() {

        @Override
        public void beforeTransformation(List<Tuple> rowTuples, QOperationExecution<OR> entityPath) throws SchemaException {
            Set<UUID> ownerOids = rowTuples.stream().map(row -> Objects.requireNonNull(row.get(entityPath)).ownerOid).collect(Collectors.toSet());
            // TODO do we need get options here as well? Is there a scenario where we load container
            // and define what to load for referenced/owner object?
            QObject<?> o = QObjectMapping.getObjectMapping().defaultAlias();
            List<Tuple> result = jdbcSession.newQuery().select(o.oid, o.fullObject).from(o).where(o.oid.in(ownerOids)).fetch();
            for (Tuple row : result) {
                UUID oid = Objects.requireNonNull(row.get(o.oid));
                ObjectType owner = parseSchemaObject(row.get(o.fullObject), oid.toString(), ObjectType.class);
                owners.put(oid, owner);
            }
        }

        @Override
        public OperationExecutionType transform(Tuple rowTuple, QOperationExecution<OR> entityPath, Collection<SelectorOptions<GetOperationOptions>> options) {
            MOperationExecution row = Objects.requireNonNull(rowTuple.get(entityPath));
            ObjectType object = Objects.requireNonNull(owners.get(row.ownerOid), () -> "Missing owner with OID " + row.ownerOid + " for OperationExecution with ID " + row.cid);
            PrismContainer<OperationExecutionType> opexContainer = object.asPrismObject().findContainer(ObjectType.F_OPERATION_EXECUTION);
            if (opexContainer == null) {
                throw new SystemException("Object " + object + " has no operation execution as expected from " + row);
            }
            PrismContainerValue<OperationExecutionType> pcv = opexContainer.findValue(row.cid);
            if (pcv == null) {
                throw new SystemException("Object " + object + " has no operation execution with ID " + row.cid);
            }
            return pcv.asContainerable();
        }
    };
}
Also used : SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) TableRelationResolver(com.evolveum.midpoint.repo.sqlbase.mapping.TableRelationResolver) java.util(java.util) SqlQueryContext(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext) QTaskMapping(com.evolveum.midpoint.repo.sqale.qmodel.task.QTaskMapping) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) QContainerMapping(com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MiscUtil(com.evolveum.midpoint.util.MiscUtil) SqaleRepoContext(com.evolveum.midpoint.repo.sqale.SqaleRepoContext) QFocusMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QFocusMapping) Collectors(java.util.stream.Collectors) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationExecutionType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationExecutionType) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismConstants(com.evolveum.midpoint.prism.PrismConstants) ResultListRowTransformer(com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) NotNull(org.jetbrains.annotations.NotNull) Tuple(com.querydsl.core.Tuple) ResultListRowTransformer(com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer) OperationExecutionType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationExecutionType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) Tuple(com.querydsl.core.Tuple)

Aggregations

PrismConstants (com.evolveum.midpoint.prism.PrismConstants)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 QContainerMapping (com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping)1 QFocusMapping (com.evolveum.midpoint.repo.sqale.qmodel.focus.QFocusMapping)1 QTaskMapping (com.evolveum.midpoint.repo.sqale.qmodel.task.QTaskMapping)1 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)1 SqlQueryContext (com.evolveum.midpoint.repo.sqlbase.SqlQueryContext)1 ResultListRowTransformer (com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer)1 TableRelationResolver (com.evolveum.midpoint.repo.sqlbase.mapping.TableRelationResolver)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 MiscUtil (com.evolveum.midpoint.util.MiscUtil)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 OperationExecutionType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationExecutionType)1 Tuple (com.querydsl.core.Tuple)1 java.util (java.util)1