use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.
@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
GetRecordsType query = new GetRecordsType();
query.setResultType(ResultType.VALIDATE);
query.setMaxRecords(BigInteger.valueOf(6));
query.setStartPosition(BigInteger.valueOf(4));
SourceResponse sourceResponse = createSourceResponse(query, 22);
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
args.put(CswConstants.GET_RECORDS, query);
BinaryContent content = transformer.transform(sourceResponse, args);
String xml = new String(content.getByteArray());
JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
use of javax.xml.bind.JAXBElement 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));
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class MetacardMarshaller method getRegistryPackageFromMetacard.
/**
* Converts the metacards metadata into a RegistryPackageType object
*
* @param mcard A metacard with ebrim metadata
* @return A RegistryPackageType object created from the ebrim metadata
* @throws ParserException
*/
public RegistryPackageType getRegistryPackageFromMetacard(Metacard mcard) throws ParserException {
JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement;
String metadata = mcard.getMetadata();
try (InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(StandardCharsets.UTF_8))) {
registryObjectTypeJAXBElement = parser.unmarshal(unmarshalConfigurator, JAXBElement.class, inputStream);
} catch (IOException e) {
throw new ParserException("Error parsing metacards xml as ebrim", e);
}
if (registryObjectTypeJAXBElement == null) {
throw new ParserException("Error parsing metacards xml as ebrim");
}
RegistryPackageType registryPackage = (RegistryPackageType) registryObjectTypeJAXBElement.getValue();
if (registryPackage == null) {
throw new ParserException("Error parsing metacards xml as ebrim. No value");
}
return registryPackage;
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class RegistryPackageConverter method setSlotGeoAttribute.
private static void setSlotGeoAttribute(SlotType1 slot, String metacardAttributeName, MetacardImpl metacard) throws RegistryConversionException {
if (slot.isSetValueList()) {
net.opengis.cat.wrs.v_1_0_2.ValueListType valueList = (net.opengis.cat.wrs.v_1_0_2.ValueListType) slot.getValueList().getValue();
List<AnyValueType> anyValues = valueList.getAnyValue();
for (AnyValueType anyValue : anyValues) {
if (anyValue.isSetContent()) {
for (Object content : anyValue.getContent()) {
if (content instanceof JAXBElement) {
JAXBElement jaxbElement = (JAXBElement) content;
AbstractGeometryType geometry = (AbstractGeometryType) jaxbElement.getValue();
String convertedGeometry = getWKTFromGeometry(geometry, jaxbElement);
if (StringUtils.isNotBlank(convertedGeometry)) {
metacard.setAttribute(metacardAttributeName, convertedGeometry);
}
}
}
}
}
}
}
Aggregations