Search in sources :

Example 6 with ObjectFactory

use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetFull.

@Ignore
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 7 with ObjectFactory

use of net.opengis.cat.csw.v_2_0_2.ObjectFactory 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 8 with ObjectFactory

use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.

the class TestCswFilterDelegate method testFeatureIdOr.

@Test
public void testFeatureIdOr() throws JAXBException, SAXException, IOException, XpathException {
    ObjectFactory filterObjectFactory = new ObjectFactory();
    FeatureIdType fidType = new FeatureIdType();
    fidType.setFid("cswRecord.1234");
    List<JAXBElement<? extends AbstractIdType>> fidFilters = new ArrayList<>();
    fidFilters.add(filterObjectFactory.createFeatureId(fidType));
    FilterType idFilter = new FilterType();
    idFilter.setId(fidFilters);
    FeatureIdType fidType2 = new FeatureIdType();
    fidType2.setFid("cswRecord.5678");
    List<JAXBElement<? extends AbstractIdType>> fidFilters2 = new ArrayList<>();
    fidFilters2.add(filterObjectFactory.createFeatureId(fidType2));
    FilterType idFilter2 = new FilterType();
    idFilter2.setId(fidFilters2);
    List<FilterType> filters = new ArrayList<>();
    filters.add(idFilter);
    filters.add(idFilter2);
    FilterType filterType = cswFilterDelegateLatLon.or(filters);
    String xml = getXmlFromMarshaller(filterType);
    assertXpathExists("/ogc:Filter/ogc:FeatureId[@fid='cswRecord.1234']", xml);
    assertXpathExists("/ogc:Filter/ogc:FeatureId[@fid='cswRecord.5678']", xml);
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ObjectFactory(net.opengis.filter.v_1_1_0.ObjectFactory) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) AbstractIdType(net.opengis.filter.v_1_1_0.AbstractIdType) FeatureIdType(net.opengis.filter.v_1_1_0.FeatureIdType) Test(org.junit.Test)

Example 9 with ObjectFactory

use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.

the class TestCswFilterDelegate method testFeatureIdAndComparisonOpsOr.

@Test(expected = UnsupportedOperationException.class)
public void testFeatureIdAndComparisonOpsOr() throws JAXBException, SAXException, IOException {
    ObjectFactory filterObjectFactory = new ObjectFactory();
    FeatureIdType fidType = new FeatureIdType();
    fidType.setFid("cswRecord.1234");
    List<JAXBElement<? extends AbstractIdType>> fidFilters = new ArrayList<>();
    fidFilters.add(filterObjectFactory.createFeatureId(fidType));
    FilterType idFilter = new FilterType();
    idFilter.setId(fidFilters);
    FilterType propertyIsLikeFilter = cswFilterDelegateLatLon.propertyIsLike(propertyName, likeLiteral, isCaseSensitive);
    List<FilterType> filterList = new ArrayList<>();
    filterList.add(idFilter);
    filterList.add(propertyIsLikeFilter);
    cswFilterDelegateLatLon.or(filterList);
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ObjectFactory(net.opengis.filter.v_1_1_0.ObjectFactory) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) AbstractIdType(net.opengis.filter.v_1_1_0.AbstractIdType) FeatureIdType(net.opengis.filter.v_1_1_0.FeatureIdType) Test(org.junit.Test)

Example 10 with ObjectFactory

use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.

the class WfsSource method logMessage.

private void logMessage(GetFeatureType getFeature) {
    if (LOGGER.isDebugEnabled()) {
        try {
            StringWriter writer = new StringWriter();
            JAXBContext contextObj = JAXBContext.newInstance(GetFeatureType.class);
            Marshaller marshallerObj = contextObj.createMarshaller();
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshallerObj.marshal(new ObjectFactory().createGetFeature(getFeature), writer);
            LOGGER.debug("WfsSource {}: {}", getId(), writer.toString());
        } catch (JAXBException e) {
            LOGGER.debug("An error occurred debugging the GetFeature request", e);
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ObjectFactory(ogc.schema.opengis.wfs.v_1_0_0.ObjectFactory) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

Test (org.junit.Test)23 JAXBElement (javax.xml.bind.JAXBElement)22 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QName (javax.xml.namespace.QName)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ArrayList (java.util.ArrayList)11 Marshaller (javax.xml.bind.Marshaller)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)10 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 StringWriter (java.io.StringWriter)10 BigInteger (java.math.BigInteger)10 JAXBContext (javax.xml.bind.JAXBContext)10 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8