Search in sources :

Example 91 with SelectorOptions

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

the class ModelWebService method getObject.

@Override
public void getObject(QName objectType, String oid, SelectorQualifiedGetOptionsType optionsType, Holder<ObjectType> objectHolder, Holder<OperationResultType> resultHolder) throws FaultMessage {
    notNullArgument(objectType, "Object type must not be null.");
    notEmptyArgument(oid, "Oid must not be null or empty.");
    Task task = createTaskInstance(GET_OBJECT);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        Class objectClass = ObjectTypes.getObjectTypeFromTypeQName(objectType).getClassDefinition();
        Collection<SelectorOptions<GetOperationOptions>> options = MiscSchemaUtil.optionsTypeToOptions(optionsType);
        PrismObject<? extends ObjectType> object = model.getObject(objectClass, oid, options, task, operationResult);
        handleOperationResult(operationResult, resultHolder);
        objectHolder.value = object.asObjectable();
        return;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL getObject() failed", ex);
        throwFault(ex, operationResult);
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

Example 92 with SelectorOptions

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

the class ModelWebService method searchObjects.

@Override
public void searchObjects(QName objectType, QueryType query, SelectorQualifiedGetOptionsType optionsType, Holder<ObjectListType> objectListHolder, Holder<OperationResultType> result) throws FaultMessage {
    notNullArgument(objectType, "Object type must not be null.");
    Task task = createTaskInstance(SEARCH_OBJECTS);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        Class objectClass = ObjectTypes.getObjectTypeFromTypeQName(objectType).getClassDefinition();
        Collection<SelectorOptions<GetOperationOptions>> options = MiscSchemaUtil.optionsTypeToOptions(optionsType);
        ObjectQuery q = QueryJaxbConvertor.createObjectQuery(objectClass, query, prismContext);
        List<PrismObject<? extends ObjectType>> list = (List) model.searchObjects(objectClass, q, options, task, operationResult);
        handleOperationResult(operationResult, result);
        ObjectListType listType = new ObjectListType();
        for (PrismObject<? extends ObjectType> o : list) {
            listType.getObject().add(o.asObjectable());
        }
        objectListHolder.value = listType;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL searchObjects() failed", ex);
        throwFault(ex, operationResult);
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ArrayList(java.util.ArrayList) List(java.util.List)

Example 93 with SelectorOptions

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

the class ModelRestService method searchObjects.

@POST
@Path("/{type}/search")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public Response searchObjects(@PathParam("type") String type, QueryType queryType, @QueryParam("options") List<String> options, @QueryParam("include") List<String> include, @QueryParam("exclude") List<String> exclude, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
    Class clazz = ObjectTypes.getClassFromRestType(type);
    Response response;
    try {
        ObjectQuery query = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
        Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include, exclude);
        List<PrismObject<? extends ObjectType>> objects = model.searchObjects(clazz, query, searchOptions, task, parentResult);
        ObjectListType listType = new ObjectListType();
        for (PrismObject<? extends ObjectType> o : objects) {
            // temporary measure until fixed in repo
            removeExcludes(o, exclude);
            listType.getObject().add(o.asObjectable());
        }
        //			response = Response.ok().entity(listType).build();
        response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 94 with SelectorOptions

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

the class ModelRestService method searchObjectsByType.

@GET
@Path("/{type}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") String type, @QueryParam("options") List<String> options, @Context UriInfo uriInfo, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
    Class<T> clazz = ObjectTypes.getClassFromRestType(type);
    Response response;
    try {
        Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, null, null);
        List<PrismObject<T>> objects = model.searchObjects(clazz, null, searchOptions, task, parentResult);
        ObjectListType listType = new ObjectListType();
        if (objects != null) {
            List<ObjectType> list = objects.stream().map(o -> convert(clazz, o, parentResult.createOperationResultType())).collect(Collectors.toList());
            listType.getObject().addAll(list);
        }
        response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
    //			response = Response.ok().entity(listType).build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Convertor(com.evolveum.midpoint.model.impl.rest.Convertor) ConvertorInterface(com.evolveum.midpoint.model.impl.rest.ConvertorInterface) com.evolveum.midpoint.xml.ns._public.common.api_types_3(com.evolveum.midpoint.xml.ns._public.common.api_types_3) Autowired(org.springframework.beans.factory.annotation.Autowired) PATCH(com.evolveum.midpoint.model.impl.rest.PATCH) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) URI(java.net.URI) Scope(com.evolveum.midpoint.model.api.validator.Scope) ScriptingExpressionEvaluator(com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Collection(java.util.Collection) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) ValuePolicyProcessor(com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor) List(java.util.List) javax.ws.rs(javax.ws.rs) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) RestServiceUtil(com.evolveum.midpoint.model.impl.util.RestServiceUtil) ExecuteScriptOutputType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptOutputType) ResourceValidator(com.evolveum.midpoint.model.api.validator.ResourceValidator) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Item(com.evolveum.midpoint.prism.Item) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) com.evolveum.midpoint.model.api(com.evolveum.midpoint.model.api) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) DeltaConvertor(com.evolveum.midpoint.schema.DeltaConvertor) PrismContext(com.evolveum.midpoint.prism.PrismContext) Service(org.springframework.stereotype.Service) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) JAXBElement(javax.xml.bind.JAXBElement) PrismObject(com.evolveum.midpoint.prism.PrismObject) javax.ws.rs.core(javax.ws.rs.core) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) QueryJaxbConvertor(com.evolveum.midpoint.prism.query.QueryJaxbConvertor) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) SecurityUtil(com.evolveum.midpoint.security.api.SecurityUtil) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SecurityHelper(com.evolveum.midpoint.model.impl.security.SecurityHelper) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 95 with SelectorOptions

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

the class ModelRestService method getObject.

@GET
@Path("/{type}/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response getObject(@PathParam("type") String type, @PathParam("id") String id, @QueryParam("options") List<String> options, @QueryParam("include") List<String> include, @QueryParam("exclude") List<String> exclude, @Context MessageContext mc) {
    LOGGER.debug("model rest service for get operation start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_GET);
    Class<T> clazz = ObjectTypes.getClassFromRestType(type);
    Collection<SelectorOptions<GetOperationOptions>> getOptions = GetOperationOptions.fromRestOptions(options, include, exclude);
    Response response;
    try {
        PrismObject<T> object;
        if (NodeType.class.equals(clazz) && CURRENT.equals(id)) {
            String nodeId = taskManager.getNodeId();
            ObjectQuery query = QueryBuilder.queryFor(NodeType.class, prismContext).item(NodeType.F_NODE_IDENTIFIER).eq(nodeId).build();
            List<PrismObject<NodeType>> objects = model.searchObjects(NodeType.class, query, getOptions, task, parentResult);
            if (objects.isEmpty()) {
                throw new ObjectNotFoundException("Current node (id " + nodeId + ") couldn't be found.");
            } else if (objects.size() > 1) {
                throw new IllegalStateException("More than one 'current' node (id " + nodeId + ") found.");
            } else {
                object = (PrismObject<T>) objects.get(0);
            }
        } else {
            object = model.getObject(clazz, id, getOptions, task, parentResult);
        }
        // temporary measure until fixed in repo
        removeExcludes(object, exclude);
        response = RestServiceUtil.createResponse(Response.Status.OK, object, parentResult);
    //			ResponseBuilder builder = Response.ok();
    //			builder.entity(object);
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)127 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)106 Task (com.evolveum.midpoint.task.api.Task)82 Test (org.testng.annotations.Test)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)34 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)31 PrismObject (com.evolveum.midpoint.prism.PrismObject)28 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)28 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ArrayList (java.util.ArrayList)19 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 QName (javax.xml.namespace.QName)17 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)16 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)16 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)14 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)14 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12