Search in sources :

Example 41 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class Main method searchRoleByName.

private static RoleType searchRoleByName(ModelPortType modelPort, String roleName) throws SAXException, IOException, FaultMessage, JAXBException {
    // WARNING: in a real case make sure that the role name is properly escaped before putting it in XML
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType("<equal xmlns='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3' >" + "<path>c:name</path>" + "<value>" + roleName + "</value>" + "</equal>");
    QueryType query = new QueryType();
    query.setFilter(filter);
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    modelPort.searchObjects(ModelClientUtil.getTypeQName(RoleType.class), query, options, objectListHolder, resultHolder);
    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (RoleType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single role with name '" + roleName + "' but found " + objects.size() + " users instead");
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 42 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class Main method createUserQuery2.

private static QueryType createUserQuery2(String username) throws JAXBException {
    QueryType query = new QueryType();
    SearchFilterType filter = new SearchFilterType();
    PropertyComplexValueFilterClauseType fc = new PropertyComplexValueFilterClauseType();
    ItemPathType path = new ItemPathType();
    path.setValue("declare namespace c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\"; c:name");
    fc.setPath(path);
    fc.getValue().add(username);
    ObjectFactory factory = new ObjectFactory();
    JAXBElement<PropertyComplexValueFilterClauseType> equal = factory.createEqual(fc);
    JAXBContext jaxbContext = JAXBContext.newInstance("com.evolveum.midpoint.xml.ns._public.common.api_types_3:" + "com.evolveum.midpoint.xml.ns._public.common.common_3:" + "com.evolveum.prism.xml.ns._public.annotation_3:" + "com.evolveum.prism.xml.ns._public.query_3:" + "com.evolveum.prism.xml.ns._public.types_3:");
    Marshaller marshaller = jaxbContext.createMarshaller();
    DOMResult result = new DOMResult();
    marshaller.marshal(equal, result);
    filter.setFilterClause(((Document) result.getNode()).getDocumentElement());
    query.setFilter(filter);
    return query;
}
Also used : Marshaller(javax.xml.bind.Marshaller) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) DOMResult(javax.xml.transform.dom.DOMResult) ObjectFactory(com.evolveum.prism.xml.ns._public.query_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PropertyComplexValueFilterClauseType(com.evolveum.prism.xml.ns._public.query_3.PropertyComplexValueFilterClauseType) JAXBContext(javax.xml.bind.JAXBContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 43 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class AbstractTestForExchangeConnector method getShadowByName.

protected ShadowType getShadowByName(String resourceOid, QName objectClass, String name) throws JAXBException, SAXException, IOException, FaultMessage {
    // WARNING: in a real case make sure that the username is properly escaped before putting it in XML
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType("                        <q:and xmlns:q='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>\n" + "                            <q:ref>\n" + "                                <q:path>resourceRef</q:path>\n" + "                                <q:value>\n" + "                                    <oid>" + resourceOid + "</oid>\n" + "                                    <type>ResourceType</type>\n" + "                                </q:value>\n" + "                            </q:ref>\n" + "                            <q:equal>\n" + "                                <q:path>objectClass</q:path>\n" + "                                <q:value xmlns:a=\"" + objectClass.getNamespaceURI() + "\">a:" + objectClass.getLocalPart() + "</q:value>\n" + "                            </q:equal>\n" + "                            <q:equal>\n" + "                                <q:path>attributes/name</q:path>\n" + "                                <q:value>" + name + "</q:value>\n" + "                            </q:equal>\n" + "                        </q:and>\n");
    QueryType query = new QueryType();
    query.setFilter(filter);
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<>();
    Holder<OperationResultType> resultHolder = new Holder<>();
    modelPort.searchObjects(ModelClientUtil.getTypeQName(ShadowType.class), query, options, objectListHolder, resultHolder);
    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (ShadowType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single shadow with name '" + name + "' but found " + objects.size() + " ones instead");
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 44 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestCswSource method testQueryWitNullSorting.

@Test
public void testQueryWitNullSorting() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 1;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    query.setSortBy(null);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    SourceResponse response = cswSource.query(new QueryRequestImpl(query));
    // Verify
    Assert.assertNotNull(response);
    assertThat(response.getResults().size(), is(numRecordsReturned));
    assertThat(response.getHits(), is(numRecordsMatched));
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify mock CSW record count: " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
    assertThat(cswQuery.getSortBy(), nullValue());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 45 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestCswSource method testQueryWithSortByTemporal.

@Test
public void testQueryWithSortByTemporal() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 1;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING);
    query.setSortBy(sortBy);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    SourceResponse response = cswSource.query(new QueryRequestImpl(query));
    // Verify
    Assert.assertNotNull(response);
    assertThat(response.getResults().size(), is(numRecordsReturned));
    assertThat(response.getHits(), is(numRecordsMatched));
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify mock CSW record count: " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
    assertThat(cswQuery.getSortBy().getSortProperty().size(), is(1));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0).toString(), equalTo(Core.MODIFIED));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SortBy(org.opengis.filter.sort.SortBy) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.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