Search in sources :

Example 26 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class ModelWebServiceTest method badPagingSearch.

@Test(expectedExceptions = FaultMessage.class)
public void badPagingSearch() throws FaultMessage, SchemaException, IOException, JAXBException {
    PagingType paging = new PagingType();
    paging.setMaxSize(-1);
    paging.setOffset(-1);
    final UserType expectedUser = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
    setSecurityContext(expectedUser);
    try {
        QueryType queryType = new QueryType();
        queryType.setPaging(paging);
        modelService.searchObjects(UserType.COMPLEX_TYPE, queryType, null, new Holder<ObjectListType>(), new Holder<OperationResultType>());
    } catch (FaultMessage ex) {
        ModelTUtil.assertIllegalArgumentFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
    Assert.fail("Illegal argument exception was not thrown.");
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 27 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class ModelWebServiceTest method nullQueryTypeAndPaging.

//    @Test(expectedExceptions = FaultMessage.class)
public void nullQueryTypeAndPaging() throws FaultMessage, SchemaException, IOException, JAXBException {
    try {
        final UserType expectedUser = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
        setSecurityContext(expectedUser);
        modelService.searchObjects(UserType.COMPLEX_TYPE, null, null, new Holder<ObjectListType>(), new Holder<OperationResultType>());
        Assert.fail("Illegal argument exception was not thrown.");
    } catch (FaultMessage ex) {
        ModelTUtil.assertIllegalArgumentFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File)

Example 28 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class ModelWebServiceTest method nullQueryType.

//    @Test(expectedExceptions = FaultMessage.class)
//    public void testDeleteNullOid() throws FaultMessage {
//        try {
//            modelService.deleteObject(UserType.COMPLEX_TYPE, null);
//        } catch (FaultMessage ex) {
//            ModelTUtil.assertIllegalArgumentFault(ex);
//        }
//        Assert.fail("delete must fail");
//    }
//    @Test(expectedExceptions = FaultMessage.class)
//    public void testDeleteEmptyOid() throws FaultMessage {
//        try {
//            modelService.deleteObject(UserType.COMPLEX_TYPE, "");
//        } catch (FaultMessage ex) {
//            ModelTUtil.assertIllegalArgumentFault(ex);
//        }
//        Assert.fail("delete must fail");
//    }
//    @Test(expectedExceptions = FaultMessage.class)
//    public void testDeleteNonExisting() throws FaultMessage, ObjectNotFoundException, SchemaException, JAXBException, FileNotFoundException {
//        try {
//            final String oid = "abababab-abab-abab-abab-000000000001";
//            when(
//                    repositoryService.getObject(any(Class.class), eq(oid),
//                            any(Collection.class), any(OperationResult.class))).thenThrow(
//                    new ObjectNotFoundException("Object with oid '' not found."));
//
//            final UserType user = PrismTestUtil.unmarshalObject(new File(
//                    TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml"), UserType.class);
//            setSecurityContext(user);
//
//            modelService.deleteObject(UserType.COMPLEX_TYPE, oid);
//        } catch (FaultMessage ex) {
//            ModelTUtil.assertObjectNotFoundFault(ex);
//        } finally {
//            SecurityContextHolder.getContext().setAuthentication(null);
//        }
//        Assert.fail("delete must fail");
//    }
//    @Test(expectedExceptions = FaultMessage.class)
public void nullQueryType() throws FaultMessage, SchemaException, IOException, JAXBException {
    try {
        final UserType expectedUser = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
        setSecurityContext(expectedUser);
        modelService.searchObjects(UserType.COMPLEX_TYPE, null, null, new Holder<ObjectListType>(), new Holder<OperationResultType>());
        Assert.fail("Illegal argument exception was not thrown.");
    } catch (FaultMessage ex) {
        ModelTUtil.assertIllegalArgumentFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File)

Example 29 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType 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 30 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class ReportWebService method processReport.

@Override
public ObjectListType processReport(String query, RemoteReportParametersType parameters, SelectorQualifiedGetOptionsType options) {
    try {
        Map<QName, Object> parametersMap = getParamsMap(parameters);
        ObjectQuery q = reportService.parseQuery(query, parametersMap);
        Collection<PrismObject<? extends ObjectType>> resultList = reportService.searchObjects(q, MiscSchemaUtil.optionsTypeToOptions(options));
        return createObjectListType(resultList);
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        // TODO Auto-generated catch block
        throw new Fault(e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)27 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)26 Holder (javax.xml.ws.Holder)24 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)18 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)14 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 Collection (java.util.Collection)9 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)6 Test (org.testng.annotations.Test)6 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)5 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)5 QName (javax.xml.namespace.QName)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)4 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3