Search in sources :

Example 6 with QueryType

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

the class Clockwork method triggerReconcileAffected.

private <F extends ObjectType> HookOperationMode triggerReconcileAffected(LensContext<F> context, Task task, OperationResult result) throws SchemaException {
    // check applicability
    if (!ModelExecuteOptions.isReconcileAffected(context.getOptions())) {
        return HookOperationMode.FOREGROUND;
    }
    if (context.getFocusClass() == null || !RoleType.class.isAssignableFrom(context.getFocusClass())) {
        LOGGER.warn("ReconcileAffected requested but not available for {}. Doing nothing.", context.getFocusClass());
        return HookOperationMode.FOREGROUND;
    }
    // check preconditions
    if (context.getFocusContext() == null) {
        throw new IllegalStateException("No focus context when expected it");
    }
    PrismObject<RoleType> role = (PrismObject) context.getFocusContext().getObjectAny();
    if (role == null) {
        throw new IllegalStateException("No role when expected it");
    }
    // preparing the recompute/reconciliation task
    Task reconTask;
    if (task.isPersistent()) {
        reconTask = task.createSubtask();
    } else {
        reconTask = task;
    }
    assert !reconTask.isPersistent();
    // creating object query
    PrismPropertyDefinition propertyDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    PrismReferenceValue referenceValue = new PrismReferenceValue(context.getFocusContext().getOid(), RoleType.COMPLEX_TYPE);
    ObjectFilter refFilter = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
    SearchFilterType filterType = QueryConvertor.createSearchFilterType(refFilter, prismContext);
    QueryType queryType = new QueryType();
    queryType.setFilter(filterType);
    PrismProperty<QueryType> property = propertyDef.instantiate();
    property.setRealValue(queryType);
    reconTask.addExtensionProperty(property);
    // other parameters
    reconTask.setName("Recomputing users after changing role " + role.asObjectable().getName());
    reconTask.setBinding(TaskBinding.LOOSE);
    reconTask.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
    reconTask.setHandlerUri(RecomputeTaskHandler.HANDLER_URI);
    reconTask.setCategory(TaskCategory.RECOMPUTATION);
    taskManager.switchToBackground(reconTask, result);
    result.setBackgroundTaskOid(reconTask.getOid());
    result.recordStatus(OperationResultStatus.IN_PROGRESS, "Reconciliation task switched to background");
    return HookOperationMode.BACKGROUND;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 7 with QueryType

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

the class TestQueryConvertor method testAccountQueryAttributesAndResourceNoNs.

@Test
public void testAccountQueryAttributesAndResourceNoNs() throws Exception {
    displayTestTitle("testAccountQueryAttributesAndResourceNoNs");
    SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_ATTRIBUTES_RESOURCE_REF_NO_NS_FILE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertRefFilter(first, ShadowType.F_RESOURCE_REF, ObjectReferenceType.COMPLEX_TYPE, new ItemPath(ShadowType.F_RESOURCE_REF));
    assertRefFilterValue((RefFilter) first, "aae7be60-df56-11df-8608-0002a5d5c51b");
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, ICF_NAME, DOMUtil.XSD_STRING, new ItemPath("attributes", "name"));
    //PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "uid=jbond,ou=People,dc=example,dc=com");
    QueryType convertedQueryType = toQueryType(query);
    System.out.println(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
// TODO: add some asserts
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 8 with QueryType

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

the class TestQueryConvertor method testConnectorQuery.

@Test
public void testConnectorQuery() throws Exception {
    displayTestTitle("testConnectorQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_CONNECTOR_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        query = QueryJaxbConvertor.createObjectQuery(ConnectorType.class, filterType, getPrismContext());
        displayQuery(query);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        PrismAsserts.assertEqualsFilter(query.getFilter(), ConnectorType.F_CONNECTOR_TYPE, DOMUtil.XSD_STRING, new ItemPath(ConnectorType.F_CONNECTOR_TYPE));
        PrismAsserts.assertEqualsFilterValue((EqualFilter) filter, "org.identityconnectors.ldap.LdapConnector");
        QueryType convertedQueryType = toQueryType(query);
        displayQueryType(convertedQueryType);
    } catch (Exception ex) {
        LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
        throw ex;
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 9 with QueryType

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

the class TestQueryConvertor method checkQuery.

private void checkQuery(Class<? extends Containerable> objectClass, ObjectQuery q1object, String q2xml) throws Exception {
    // step 1 (serialization of Q1 + comparison)
    displayText("Query 1:");
    displayQuery(q1object);
    QueryType q1jaxb = toQueryType(q1object);
    displayQueryType(q1jaxb);
    String q1xml = toXml(q1jaxb);
    displayQueryXml(q1xml);
    //		XMLAssert.assertXMLEqual("Serialized query is not correct: Expected:\n" + q2xml + "\n\nReal:\n" + q1xml, q2xml, q1xml);
    // step 2 (parsing of Q2 + comparison)
    displayText("Query 2:");
    displayQueryXml(q2xml);
    QueryType q2jaxb = toQueryType(q2xml);
    displayQueryType(q2jaxb);
    ObjectQuery q2object = toObjectQuery(objectClass, q2jaxb);
    // primitive way of comparing parsed queries
    assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString());
    assertTrue("Reparsed query is not as original one (via equivalent):\nq1=" + q1object + "\nq2=" + q2object, q1object.equivalent(q2object));
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 10 with QueryType

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

the class TestQueryConvertor method testAccountQueryCompositeOr.

@Test
public void testAccountQueryCompositeOr() throws Exception {
    displayTestTitle("testAccountQueryCompositeOr");
    SearchFilterType filterType = unmarshalFilter(FILTER_OR_COMPOSITE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertOrFilter(filter, 4);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_INTENT, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_INTENT));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, "some account type");
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, fooBlaDefinition, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_ATTRIBUTES, fooBlaDefinition));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "foo value");
    ObjectFilter third = getFilterCondition(filter, 2);
    PrismAsserts.assertEqualsFilter(third, stringExtensionDefinition, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_EXTENSION, stringExtensionDefinition));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) third, "uid=test,dc=example,dc=com");
    ObjectFilter forth = getFilterCondition(filter, 3);
    PrismAsserts.assertRefFilter(forth, ShadowType.F_RESOURCE_REF, ObjectReferenceType.COMPLEX_TYPE, new ItemPath(ShadowType.F_RESOURCE_REF));
    assertRefFilterValue((RefFilter) forth, "d0db5be9-cb93-401f-b6c1-86ffffe4cd5e");
    QueryType convertedQueryType = toQueryType(query);
    LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
// TODO: add some asserts
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

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