Search in sources :

Example 16 with GetOperationOptions

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

the class LookupTableHelper method findLookupTableGetOption.

public GetOperationOptions findLookupTableGetOption(Collection<SelectorOptions<GetOperationOptions>> options) {
    final ItemPath tablePath = new ItemPath(LookupTableType.F_ROW);
    Collection<SelectorOptions<GetOperationOptions>> filtered = SelectorOptions.filterRetrieveOptions(options);
    for (SelectorOptions<GetOperationOptions> option : filtered) {
        ObjectSelector selector = option.getSelector();
        if (selector == null) {
            // apply to lookup table
            continue;
        }
        ItemPath selected = selector.getPath();
        if (tablePath.equivalent(selected)) {
            return option.getOptions();
        }
    }
    return null;
}
Also used : GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectSelector(com.evolveum.midpoint.schema.ObjectSelector) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 17 with GetOperationOptions

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

the class LookupTableHelper method updateLoadedLookupTable.

public <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();
    Criteria criteria = setupLookupTableRowsQuery(session, queryDef, object.getOid());
    if (queryDef != null && queryDef.getPaging() != null) {
        ObjectPaging paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            criteria.setFirstResult(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            criteria.setMaxResults(paging.getMaxSize());
        }
        ItemPath orderByPath = paging.getOrderBy();
        if (paging.getDirection() != null && orderByPath != null && !orderByPath.isEmpty()) {
            if (orderByPath.size() > 1 || !(orderByPath.first() instanceof NameItemPathSegment) && !(orderByPath.first() instanceof IdentifierPathSegment)) {
                throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
            }
            ItemPathSegment first = orderByPath.first();
            String orderBy = first instanceof NameItemPathSegment ? ((NameItemPathSegment) first).getName().getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
            switch(paging.getDirection()) {
                case ASCENDING:
                    criteria.addOrder(Order.asc(orderBy));
                    break;
                case DESCENDING:
                    criteria.addOrder(Order.desc(orderBy));
                    break;
            }
        }
    }
    List<RLookupTableRow> rows = criteria.list();
    if (rows == null || rows.isEmpty()) {
        return;
    }
    LookupTableType lookup = (LookupTableType) object.asObjectable();
    List<LookupTableRowType> jaxbRows = lookup.getRow();
    for (RLookupTableRow row : rows) {
        LookupTableRowType jaxbRow = row.toJAXB();
        jaxbRows.add(jaxbRow);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) Criteria(org.hibernate.Criteria) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 18 with GetOperationOptions

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

the class ProvisioningServiceImpl method countObjects.

public <T extends ObjectType> Integer countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".countObjects");
    result.addParam("objectType", type);
    result.addParam("query", query);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    ObjectFilter filter = null;
    if (query != null) {
        filter = ObjectQueryUtil.simplify(query.getFilter());
        query = query.cloneEmpty();
        query.setFilter(filter);
    }
    if (filter != null && filter instanceof NoneFilter) {
        result.recordSuccessIfUnknown();
        result.cleanupResult();
        LOGGER.trace("Finished counting. Nothing to do. Filter is NONE");
        return 0;
    }
    GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
    if (!ShadowType.class.isAssignableFrom(type) || GetOperationOptions.isNoFetch(rootOptions) || GetOperationOptions.isRaw(rootOptions)) {
        int count = getCacheRepositoryService().countObjects(type, query, parentResult);
        result.computeStatus();
        result.recordSuccessIfUnknown();
        result.cleanupResult();
        return count;
    }
    Integer count;
    try {
        count = getShadowCache(Mode.STANDARD).countObjects(query, task, result);
        result.computeStatus();
    } catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
        throw e;
    } finally {
        result.cleanupResult();
    }
    return count;
}
Also used : NoneFilter(com.evolveum.midpoint.prism.query.NoneFilter) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 19 with GetOperationOptions

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

the class ProvisioningServiceImpl method getObject.

@SuppressWarnings("unchecked")
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(oid, "Oid of object to get must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    // Result type for this operation
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getObject");
    result.addParam(OperationResult.PARAM_OID, oid);
    result.addParam(OperationResult.PARAM_TYPE, type);
    result.addCollectionOfSerializablesAsParam("options", options);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
    PrismObject<T> resultingObject = null;
    if (ResourceType.class.isAssignableFrom(type)) {
        if (GetOperationOptions.isRaw(rootOptions)) {
            try {
                resultingObject = (PrismObject<T>) cacheRepositoryService.getObject(ResourceType.class, oid, null, result);
            } catch (ObjectNotFoundException | SchemaException ex) {
                // catching an exception is important because otherwise the result is UNKNOWN
                result.recordFatalError(ex);
                throw ex;
            }
            try {
                applyDefinition(resultingObject, task, result);
            } catch (ObjectNotFoundException ex) {
                // this is almost OK, we use raw for debug pages, so we want
                // to return resource and it can be fixed
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Bad connector reference defined for resource:  " + ex.getMessage(), ex);
            } catch (SchemaException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Schema violation:  " + ex.getMessage(), ex);
            } catch (ConfigurationException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Configuration problem:  " + ex.getMessage(), ex);
            }
        } else {
            // schema
            try {
                resultingObject = (PrismObject<T>) resourceManager.getResource(oid, SelectorOptions.findRootOptions(options), task, result);
            } catch (ObjectNotFoundException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Resource object not found", ex);
                throw ex;
            } catch (SchemaException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Schema violation", ex);
                throw ex;
            } catch (CommunicationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error communicating with resource", ex);
                throw ex;
            } catch (ConfigurationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Bad resource configuration", ex);
                throw ex;
            } catch (ExpressionEvaluationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Expression error", ex);
                throw ex;
            }
        }
    } else {
        // Not resource
        PrismObject<T> repositoryObject = getRepoObject(type, oid, rootOptions, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Retrieved repository object:\n{}", repositoryObject.debugDump());
        }
        if (repositoryObject.canRepresent(ShadowType.class)) {
            try {
                resultingObject = (PrismObject<T>) getShadowCache(Mode.STANDARD).getShadow(oid, (PrismObject<ShadowType>) (repositoryObject), options, task, result);
            } catch (ObjectNotFoundException e) {
                if (!GetOperationOptions.isAllowNotFound(rootOptions)) {
                    ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                } else {
                    result.muteLastSubresultError();
                    result.computeStatus();
                }
                throw e;
            } catch (CommunicationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SchemaException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (ConfigurationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SecurityViolationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SystemException e) {
                // Do NOT wrap this into SystemException again
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (RuntimeException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw new SystemException(e);
            }
        } else {
            resultingObject = repositoryObject;
        }
    }
    result.computeStatus();
    if (!GetOperationOptions.isRaw(rootOptions)) {
        resultingObject = resultingObject.cloneIfImmutable();
        resultingObject.asObjectable().setFetchResult(result.createOperationResultType());
    }
    result.cleanupResult();
    validateObject(resultingObject);
    return resultingObject;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 20 with GetOperationOptions

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

the class TaskManagerQuartzImpl method getObject.

//endregion
//region Getting and searching for tasks and nodes
/*
     *  ********************* GETTING AND SEARCHING FOR TASKS AND NODES *********************
     */
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
    OperationResult result = parentResult.createSubresult(DOT_INTERFACE + ".getObject");
    result.addParam("objectType", type);
    result.addParam("oid", oid);
    result.addCollectionOfSerializablesAsParam("options", options);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, TaskManagerQuartzImpl.class);
    try {
        if (TaskType.class.isAssignableFrom(type)) {
            GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
            if (GetOperationOptions.isRaw(rootOptions)) {
                return (PrismObject<T>) repositoryService.getObject(TaskType.class, oid, options, result);
            } else {
                return (PrismObject<T>) getTaskAsObject(oid, options, result);
            }
        } else if (NodeType.class.isAssignableFrom(type)) {
            // TODO add transient attributes just like in searchObject
            return (PrismObject<T>) repositoryService.getObject(NodeType.class, oid, options, result);
        } else {
            throw new IllegalArgumentException("Unsupported object type: " + type);
        }
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)52 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)38 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)31 Task (com.evolveum.midpoint.task.api.Task)22 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)19 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 Collection (java.util.Collection)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)11 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)10 QName (javax.xml.namespace.QName)10 Test (org.testng.annotations.Test)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 ArrayList (java.util.ArrayList)9 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7