Search in sources :

Example 1 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class WebComponentUtil method createSingleRecurrenceTask.

public static TaskType createSingleRecurrenceTask(String taskName, QName applicableType, ObjectQuery query, ObjectDelta delta, ModelExecuteOptions options, String category, PageBase pageBase) throws SchemaException {
    TaskType task = new TaskType();
    MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
    ObjectReferenceType ownerRef = new ObjectReferenceType();
    ownerRef.setOid(owner.getOid());
    ownerRef.setType(owner.getUser().COMPLEX_TYPE);
    task.setOwnerRef(ownerRef);
    task.setBinding(TaskBindingType.LOOSE);
    task.setCategory(category);
    task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
    task.setRecurrence(TaskRecurrenceType.SINGLE);
    task.setThreadStopAction(ThreadStopActionType.RESTART);
    task.setHandlerUri(pageBase.getTaskService().getHandlerUriForCategory(category));
    ScheduleType schedule = new ScheduleType();
    schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
    task.setSchedule(schedule);
    task.setName(WebComponentUtil.createPolyFromOrigString(taskName));
    PrismObject<TaskType> prismTask = task.asPrismObject();
    ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    PrismProperty objectQuery = prismTask.findOrCreateProperty(path);
    QueryType queryType = QueryJaxbConvertor.createQueryType(query, pageBase.getPrismContext());
    objectQuery.addRealValue(queryType);
    path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
    PrismProperty objectType = prismTask.findOrCreateProperty(path);
    objectType.setRealValue(applicableType);
    if (delta != null) {
        path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA);
        PrismProperty objectDelta = prismTask.findOrCreateProperty(path);
        objectDelta.setRealValue(DeltaConvertor.toObjectDeltaType(delta));
    }
    if (options != null) {
        prismTask.findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS)).setRealValue(options.toModelExecutionOptionsType());
    }
    return task;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class ExportAction method executeSearch.

private void executeSearch(ModelPortType port, Writer writer) throws FaultMessage, IOException, JAXBException, SAXException {
    SelectorQualifiedGetOptionsType options = createOptions();
    QName type = ObjectType.getType(getParams().getType());
    if (type == null) {
        type = ObjectType.OBJECT.getType();
    }
    int count = 0;
    int currentSize = 1;
    Holder<ObjectListType> list = new Holder<>();
    Holder<OperationResultType> result = new Holder<>();
    while (currentSize > 0) {
        QueryType query = createQuery(count);
        port.searchObjects(type, query, options, list, result);
        OperationResultType res = result.value;
        if (!OperationResultStatusType.SUCCESS.equals(res.getStatus()) && !getParams().isIgnore()) {
            printInfoMessage("Search returned {}, reason: ", res.getStatus(), res.getMessage());
            if (getParams().isVerbose()) {
                printInfoMessage("Operation result:\n{}", ToolsUtils.serializeObject(res));
            }
            break;
        }
        ObjectListType objList = list.value;
        if (getParams().isVerbose()) {
            printInfoMessage("Search returned {}, status: {}/{}", res.getStatus(), count, objList.getCount());
        }
        List<com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType> objects = objList.getObject();
        currentSize = objects.size();
        for (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType object : objects) {
            ToolsUtils.serializeObject(object, writer);
            writer.write('\n');
        }
        count += currentSize;
    }
}
Also used : QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) ObjectType(com.evolveum.midpoint.cli.ninja.util.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 3 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class ExportAction method createQuery.

private QueryType createQuery(int from) throws IOException, SAXException, JAXBException {
    QueryType query = new QueryType();
    query.setFilter(loadQuery());
    PagingType paging = new PagingType();
    paging.setOffset(from);
    paging.setMaxSize(SEARCH_PAGE_SIZE);
    paging.setOrderBy(ModelClientUtil.createItemPathType("name"));
    paging.setOrderDirection(OrderDirectionType.ASCENDING);
    query.setPaging(paging);
    return query;
}
Also used : PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 4 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertors method testFilterTypeUserNone.

@Test
public void testFilterTypeUserNone() throws Exception {
    displayTestTitle("testFilterTypeUserNone");
    SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_TYPE_USER_NONE);
    ObjectQuery query = toObjectQuery(UserType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    assertTrue("Filter is not of TYPE type", filter instanceof TypeFilter);
    ObjectFilter subFilter = ((TypeFilter) filter).getFilter();
    assertTrue("Filter is not of NONE type", subFilter instanceof NoneFilter);
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
    LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump());
    System.out.println("Serialized filter (JAXB->DOM)");
    String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement);
    System.out.println(filterAsString);
    LOGGER.info(filterAsString);
    DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "type"));
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismTestUtil.createPolyString(com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 5 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class DeleteTaskHandler method runInternal.

public <O extends ObjectType> TaskRunResult runInternal(Task task) {
    LOGGER.trace("Delete task run starting ({})", task);
    long startTimestamp = System.currentTimeMillis();
    OperationResult opResult = new OperationResult("DeleteTask.run");
    opResult.setStatus(OperationResultStatus.IN_PROGRESS);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    opResult.setSummarizeErrors(true);
    opResult.setSummarizePartialErrors(true);
    opResult.setSummarizeSuccesses(true);
    QueryType queryType;
    PrismProperty<QueryType> objectQueryPrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    if (objectQueryPrismProperty != null && objectQueryPrismProperty.getRealValue() != null) {
        queryType = objectQueryPrismProperty.getRealValue();
    } else {
        // For "foolproofness" reasons we really require a query. Even if it is "ALL" query.
        LOGGER.error("No query parameter in {}", task);
        opResult.recordFatalError("No query parameter in " + task);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    Class<O> objectType;
    QName objectTypeName;
    PrismProperty<QName> objectTypePrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
    if (objectTypePrismProperty != null && objectTypePrismProperty.getRealValue() != null) {
        objectTypeName = objectTypePrismProperty.getRealValue();
        objectType = (Class<O>) ObjectTypes.getObjectTypeFromTypeQName(objectTypeName).getClassDefinition();
    } else {
        LOGGER.error("No object type parameter in {}", task);
        opResult.recordFatalError("No object type parameter in " + task);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    ObjectQuery query;
    try {
        query = QueryJaxbConvertor.createObjectQuery(objectType, queryType, prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Using object query from the task: {}", query.debugDump());
        }
    } catch (SchemaException ex) {
        LOGGER.error("Schema error while creating a search filter: {}", new Object[] { ex.getMessage(), ex });
        opResult.recordFatalError("Schema error while creating a search filter: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    boolean optionRaw = true;
    PrismProperty<Boolean> optionRawPrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OPTION_RAW);
    if (optionRawPrismProperty != null && optionRawPrismProperty.getRealValue() != null && !optionRawPrismProperty.getRealValue()) {
        optionRaw = false;
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Deleting {}, raw={} using query:\n{}", new Object[] { objectType.getSimpleName(), optionRaw, query.debugDump() });
    }
    // TODO
    boolean countObjectsOnStart = true;
    long progress = 0;
    Integer maxSize = 100;
    ObjectPaging paging = ObjectPaging.createPaging(0, maxSize);
    query.setPaging(paging);
    query.setAllowPartialResults(true);
    Collection<SelectorOptions<GetOperationOptions>> searchOptions = null;
    ModelExecuteOptions execOptions = null;
    if (optionRaw) {
        searchOptions = SelectorOptions.createCollection(GetOperationOptions.createRaw());
        execOptions = ModelExecuteOptions.createRaw();
    }
    try {
        // counting objects can be within try-catch block, because the handling is similar to handling errors within searchIterative
        Long expectedTotal = null;
        if (countObjectsOnStart) {
            Integer expectedTotalInt = modelService.countObjects(objectType, query, searchOptions, task, opResult);
            LOGGER.trace("Expecting {} objects to be deleted", expectedTotal);
            if (expectedTotalInt != null) {
                // conversion would fail on null
                expectedTotal = (long) expectedTotalInt;
            }
        }
        runResult.setProgress(progress);
        task.setProgress(progress);
        if (expectedTotal != null) {
            task.setExpectedTotal(expectedTotal);
        }
        try {
            task.savePendingModifications(opResult);
        } catch (ObjectAlreadyExistsException e) {
            // other exceptions are handled in the outer try block
            throw new IllegalStateException("Unexpected ObjectAlreadyExistsException when updating task progress/expectedTotal", e);
        }
        long progressLastUpdated = 0;
        SearchResultList<PrismObject<O>> objects;
        while (true) {
            objects = modelService.searchObjects(objectType, query, searchOptions, task, opResult);
            if (objects.isEmpty()) {
                break;
            }
            int skipped = 0;
            for (PrismObject<O> object : objects) {
                if (!optionRaw && ShadowType.class.isAssignableFrom(objectType) && Boolean.TRUE == ((ShadowType) (object.asObjectable())).isProtectedObject()) {
                    LOGGER.debug("Skipping delete of protected object {}", object);
                    skipped++;
                    continue;
                }
                ObjectDelta<?> delta = ObjectDelta.createDeleteDelta(objectType, object.getOid(), prismContext);
                String objectName = PolyString.getOrig(object.getName());
                String objectDisplayName = StatisticsUtil.getDisplayName(object);
                String objectOid = object.getOid();
                task.recordIterativeOperationStart(objectName, objectDisplayName, objectTypeName, objectOid);
                long objectDeletionStarted = System.currentTimeMillis();
                try {
                    modelService.executeChanges(MiscSchemaUtil.createCollection(delta), execOptions, task, opResult);
                    task.recordIterativeOperationEnd(objectName, objectDisplayName, objectTypeName, objectOid, objectDeletionStarted, null);
                } catch (Throwable t) {
                    task.recordIterativeOperationEnd(objectName, objectDisplayName, objectTypeName, objectOid, objectDeletionStarted, t);
                    // TODO we don't want to continue processing if an error occurs?
                    throw t;
                }
                progress++;
                task.setProgressTransient(progress);
                if (System.currentTimeMillis() - progressLastUpdated > PROGRESS_UPDATE_INTERVAL) {
                    task.setProgress(progress);
                    updateState(task);
                    progressLastUpdated = System.currentTimeMillis();
                }
            }
            opResult.summarize();
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Search returned {} objects, {} skipped, progress: {}, result:\n{}", new Object[] { objects.size(), skipped, progress, opResult.debugDump() });
            }
            if (objects.size() == skipped) {
                break;
            }
        }
    } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        LOGGER.error("{}", new Object[] { e.getMessage(), e });
        opResult.recordFatalError("Object not found " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (CommunicationException e) {
        LOGGER.error("{}", new Object[] { e.getMessage(), e });
        opResult.recordFatalError("Object not found " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        runResult.setProgress(progress);
        return runResult;
    }
    runResult.setProgress(progress);
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    opResult.summarize();
    opResult.recordSuccess();
    long wallTime = System.currentTimeMillis() - startTimestamp;
    String finishMessage = "Finished delete (" + task + "). ";
    String statistics = "Processed " + progress + " objects in " + wallTime / 1000 + " seconds.";
    if (progress > 0) {
        statistics += " Wall clock time average: " + ((float) wallTime / (float) progress) + " milliseconds";
    }
    opResult.createSubresult(DeleteTaskHandler.class.getName() + ".statistics").recordStatus(OperationResultStatus.SUCCESS, statistics);
    LOGGER.info(finishMessage + statistics);
    LOGGER.trace("Run finished (task {}, run result {})", new Object[] { task, runResult });
    return runResult;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)91 Test (org.junit.Test)89 QueryImpl (ddf.catalog.operation.impl.QueryImpl)71 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)67 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)58 Test (org.testng.annotations.Test)52 QName (javax.xml.namespace.QName)50 JAXBElement (javax.xml.bind.JAXBElement)44 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)38 ArrayList (java.util.ArrayList)37 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 Filter (org.opengis.filter.Filter)32 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)23 SortBy (org.opengis.filter.sort.SortBy)22 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)21 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)21 SortByImpl (ddf.catalog.filter.impl.SortByImpl)20 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)19 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)19 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)18