Search in sources :

Example 1 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project midpoint by Evolveum.

the class OperationResultFactory method createOperationResult.

public static OperationResultType createOperationResult(String operation, OperationResultStatusType status) {
    if (StringUtils.isEmpty(operation)) {
        throw new IllegalArgumentException("Operation name not defined.");
    }
    if (status == null) {
        throw new IllegalArgumentException("Operation status not defined.");
    }
    ObjectFactory factory = new ObjectFactory();
    OperationResultType result = factory.createOperationResultType();
    result.setToken(getNextToken());
    result.setOperation(operation);
    result.setStatus(status);
    return result;
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 2 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionHits.

@Ignore
public void testMarshalRecordCollectionHits() 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);
    collection.setResultType(ResultType.HITS);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
    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(0));
    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 3 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project ddf by codice.

the class CswEndpoint method queryCsw.

private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
    if (LOGGER.isDebugEnabled()) {
        try {
            Writer writer = new StringWriter();
            try {
                Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
                marshaller.marshal(jaxbElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Unable to marshall {} to XML.  Exception {}", GetRecordsType.class, e);
            }
            LOGGER.debug(writer.toString());
        } catch (Exception e) {
            LOGGER.debug("Unable to create debug message for getRecordsType: {}", e);
        }
    }
    QueryType query = (QueryType) request.getAbstractQuery().getValue();
    CswRecordCollection response = new CswRecordCollection();
    response.setRequest(request);
    response.setOutputSchema(request.getOutputSchema());
    response.setMimeType(request.getOutputFormat());
    response.setElementName(query.getElementName());
    response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
    response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
    if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
        QueryRequest queryRequest = queryFactory.getQuery(request);
        try {
            queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
            LOGGER.debug("Attempting to execute query: {}", queryRequest);
            QueryResponse queryResponse = framework.query(queryRequest);
            response.setSourceResponse(queryResponse);
        } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
            LOGGER.debug("Unable to query", e);
            throw new CswException(e);
        }
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Marshaller(javax.xml.bind.Marshaller) QueryRequest(ddf.catalog.operation.QueryRequest) JAXBException(javax.xml.bind.JAXBException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) FederationException(ddf.catalog.federation.FederationException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) MimeTypeParseException(javax.activation.MimeTypeParseException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ParseException(com.vividsolutions.jts.io.ParseException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StringWriter(java.io.StringWriter) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 4 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionFullXml.

@Ignore
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    TransformerManager mockMetacardManager = mock(TransformerManager.class);
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(TestCswRecordConverter.getCswMetacardType()));
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
    XStream xstream = new XStream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.GET_RECORDS_RESPONSE, CswRecordCollection.class);
    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);
    String xml = xstream.toXML(collection);
    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 : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) 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) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) 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) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 5 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetElements.

@Ignore
public void testMarshalRecordCollectionGetElements() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    List<QName> elements = new LinkedList<>();
    elements.add(CswConstants.CSW_TITLE_QNAME);
    elements.add(CswConstants.CSW_SOURCE_QNAME);
    query.setElementName(elements);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementName(elements);
    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(nullValue()));
    assertThat(context.get(CswConstants.ELEMENT_NAMES), is(notNullValue()));
    List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
    assertThat(qnames.contains(CswConstants.CSW_TITLE_QNAME), is(true));
    assertThat(qnames.contains(CswConstants.CSW_SOURCE_QNAME), is(true));
    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(nullValue()));
    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) QName(javax.xml.namespace.QName) 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) LinkedList(java.util.LinkedList) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Aggregations

Test (org.junit.Test)15 JAXBElement (javax.xml.bind.JAXBElement)14 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)13 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)11 QName (javax.xml.namespace.QName)11 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 Marshaller (javax.xml.bind.Marshaller)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 StringWriter (java.io.StringWriter)9 BigInteger (java.math.BigInteger)9 ArrayList (java.util.ArrayList)9 JAXBContext (javax.xml.bind.JAXBContext)9 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8 Holder (javax.xml.ws.Holder)7 ObjectFactory (org.apache.type_test.types3.ObjectFactory)7 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)6 Book (biblemulticonverter.data.Book)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 XStream (com.thoughtworks.xstream.XStream)5