List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, T value)
From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.TestCswFilterDelegate.java
private JAXBElement<FilterType> getFilterTypeJaxbElement(FilterType filterType) { JAXBElement<FilterType> filterTypeJaxbElement = new JAXBElement<FilterType>( new QName("http://www.opengis.net/ogc", FILTER_QNAME_LOCAL_PART), FilterType.class, filterType); return filterTypeJaxbElement; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpoint.java
private InsertResultType getInsertResultFromResponse(CreateResponse createResponse) throws CswException { InsertResultType result = new InsertResultType(); WKTReader reader = new WKTReader(); for (Metacard metacard : createResponse.getCreatedMetacards()) { BoundingBoxType boundingBox = new BoundingBoxType(); Geometry geometry = null;/* www. jav a 2 s .c o m*/ String bbox = null; try { if (metacard.getAttribute(CswConstants.BBOX_PROP) != null) { bbox = metacard.getAttribute(CswConstants.BBOX_PROP).getValue().toString(); geometry = reader.read(bbox); } else if (StringUtils.isNotBlank(metacard.getLocation())) { bbox = metacard.getLocation(); geometry = reader.read(bbox); } } catch (ParseException e) { LOGGER.warn("Unable to parse BoundingBox : {}", bbox, e); } BriefRecordType briefRecordType = new BriefRecordType(); if (geometry != null) { Envelope bounds = geometry.getEnvelopeInternal(); if (bounds != null) { boundingBox.setCrs(CswConstants.SRS_NAME); boundingBox.setLowerCorner(Arrays.asList(bounds.getMinX(), bounds.getMinY())); boundingBox.setUpperCorner(Arrays.asList(bounds.getMaxX(), bounds.getMaxY())); briefRecordType.getBoundingBox() .add(new net.opengis.ows.v_1_0_0.ObjectFactory().createBoundingBox(boundingBox)); } } SimpleLiteral identifier = new SimpleLiteral(); identifier.getContent().add(metacard.getId()); briefRecordType.getIdentifier() .add(new JAXBElement<>(CswConstants.DC_IDENTIFIER_QNAME, SimpleLiteral.class, identifier)); SimpleLiteral title = new SimpleLiteral(); title.getContent().add(metacard.getTitle()); briefRecordType.getTitle() .add(new JAXBElement<>(CswConstants.DC_TITLE_QNAME, SimpleLiteral.class, title)); SimpleLiteral type = new SimpleLiteral(); type.getContent().add(metacard.getContentTypeName()); briefRecordType.setType(type); result.getBriefRecord().add(briefRecordType); } return result; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpoint.java
/** * Creates an Operation object for the OperationsMetadata section TODO: We currently don't use * the constraint or metadata elements, those can be added in as desired * * @param name The name of the operation * @param types The request types supported (GET/POST) * @return The constructed Operation object *//*from w w w.j a va 2 s . c om*/ private Operation buildOperation(String name, List<QName> types) { Operation op = new Operation(); op.setName(name); ArrayList<DCP> dcpList = new ArrayList<>(); DCP dcp = new DCP(); HTTP http = new HTTP(); for (QName type : types) { RequestMethodType rmt = new RequestMethodType(); rmt.setHref(uri.getBaseUri().toASCIIString()); JAXBElement<RequestMethodType> requestElement = new JAXBElement<>(type, RequestMethodType.class, rmt); if (type.equals(CswConstants.POST)) { requestElement.getValue().getConstraint() .add(createDomainType(CswConstants.POST_ENCODING, CswConstants.XML)); } http.getGetOrPost().add(requestElement); } dcp.setHTTP(http); dcpList.add(dcp); op.setDCP(dcpList); return op; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
/** Test Valid GetRecords request, no exceptions should be thrown */ @Test// w w w . j a v a 2s . co m public void testPostGetRecordsValidElementNames() throws CswException { GetRecordsType grr = createDefaultPostRecordsRequest(); QueryType query = new QueryType(); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); List<QName> elementNameList = Arrays.asList(new QName("brief"), new QName("summary"), new QName("full")); query.setElementName(elementNameList); grr.setAbstractQuery(jaxbQuery); csw.getRecords(grr); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
@Test public void testPostGetRecordsValidElementSetNames() throws CswException { GetRecordsType grr = createDefaultPostRecordsRequest(); QueryType query = new QueryType(); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); ElementSetNameType elsnt = new ElementSetNameType(); elsnt.setValue(ElementSetType.BRIEF); query.setElementSetName(elsnt);// ww w . ja va 2 s. com grr.setAbstractQuery(jaxbQuery); csw.getRecords(grr); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
@Test public void testPostGetRecordsResults() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.RESULTS); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames);//from ww w .j a v a 2 s . c o m QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); ElementSetNameType esnt = new ElementSetNameType(); esnt.setValue(ElementSetType.SUMMARY); query.setElementSetName(esnt); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); final String exampleSchema = CswConstants.CSW_OUTPUT_SCHEMA; grr.setOutputSchema(exampleSchema); final String exampleMime = "application/xml"; grr.setOutputFormat(exampleMime); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getMimeType(), is(exampleMime)); assertThat(collection.getOutputSchema(), is(exampleSchema)); assertThat(collection.getSourceResponse(), notNullValue()); assertThat(collection.getResultType(), is(ResultType.RESULTS)); assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
@Test public void testPostGetRecordsGmdCswOutputSchema() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.RESULTS); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(GmdConstants.GMD_NAMESPACE, GmdConstants.GMD_LOCAL_NAME, GmdConstants.GMD_PREFIX)); query.setTypeNames(typeNames);/*from w w w . j a v a 2 s.c om*/ QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(GMD_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); ElementSetNameType esnt = new ElementSetNameType(); esnt.setValue(ElementSetType.SUMMARY); query.setElementSetName(esnt); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); final String exampleSchema = CswConstants.CSW_OUTPUT_SCHEMA; grr.setOutputSchema(exampleSchema); final String exampleMime = "application/xml"; grr.setOutputFormat(exampleMime); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getMimeType(), is(exampleMime)); assertThat(collection.getOutputSchema(), is(exampleSchema)); assertThat(collection.getSourceResponse(), notNullValue()); assertThat(collection.getResultType(), is(ResultType.RESULTS)); assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
@Test public void testPostGetRecordsHits() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.HITS);//from www . ja va 2 s. c om QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames); QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getCswRecords(), is(empty())); assertThat(collection.getResultType(), is(ResultType.HITS)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
@Test public void testPostGetRecordsValidate() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.VALIDATE); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames);/* w w w .j a v a 2s.c om*/ QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getCswRecords(), is(empty())); assertThat(collection.getNumberOfRecordsMatched(), is(0L)); assertThat(collection.getNumberOfRecordsReturned(), is(0L)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
/** Tests to see that JAXB configuration is working */ @Test/*from ww w. ja v a2 s. c o m*/ public void testMarshallDescribeRecord() { DescribeRecordResponseType response = new DescribeRecordResponseType(); List<SchemaComponentType> schemas = new ArrayList<>(); SchemaComponentType schemaComponentType = new SchemaComponentType(); schemas.add(schemaComponentType); response.setSchemaComponent(schemas); JAXBContext context; try { context = JAXBContext .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema, DescribeRecordResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("Response: {}", sw.toString()); } catch (JAXBException e) { fail("Could not marshall message, Error: " + e.getMessage()); } }