use of com.helger.xsds.peppol.smp1.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionHits.
@Ignore
@Test
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 com.helger.xsds.peppol.smp1.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetElements.
@Ignore
@Test
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));
}
use of com.helger.xsds.peppol.smp1.ObjectFactory in project ddf by codice.
the class WfsFilterDelegate method createFeatureIdFilter.
private JAXBElement<ResourceIdType> createFeatureIdFilter(final String id) {
ResourceIdType resId = new ResourceIdType();
resId.setRid(id);
ObjectFactory objFact = new ObjectFactory();
return objFact.createResourceId(resId);
}
use of com.helger.xsds.peppol.smp1.ObjectFactory in project ddf by codice.
the class AbstractCswSource method createQuery.
private JAXBElement<QueryType> createQuery(QueryRequest queryRequest, ElementSetType elementSetType, List<QName> elementNames) throws UnsupportedQueryException {
QueryType queryType = new QueryType();
QName queryTypeQName = null;
try {
if (StringUtils.isNotBlank(cswSourceConfiguration.getQueryTypeName())) {
String[] parts = cswSourceConfiguration.getQueryTypeName().split(":");
if (parts.length > 1) {
queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), parts[1], parts[0]);
} else {
queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), cswSourceConfiguration.getQueryTypeName());
}
}
} catch (IllegalArgumentException e) {
LOGGER.debug("Unable to parse query type QName of {}. Defaulting to CSW Record", cswSourceConfiguration.getQueryTypeName());
}
if (queryTypeQName == null) {
queryTypeQName = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME, CswConstants.CSW_NAMESPACE_PREFIX);
}
QueryRequest transformedQueryRequest = cswQueryFilterTransformerProvider != null ? cswQueryFilterTransformerProvider.getTransformer(cswSourceConfiguration.getQueryTypeName()).map(it -> it.transform(queryRequest, null)).orElse(queryRequest) : queryRequest;
queryType.setTypeNames(Arrays.asList(queryTypeQName));
if (null != elementSetType) {
queryType.setElementSetName(createElementSetName(elementSetType));
} else if (!CollectionUtils.isEmpty(elementNames)) {
queryType.setElementName(elementNames);
} else {
queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
}
SortByType sortBy = createSortBy(transformedQueryRequest);
if (sortBy != null) {
queryType.setSortBy(sortBy);
}
QueryConstraintType constraint = createQueryConstraint(transformedQueryRequest);
if (null != constraint) {
queryType.setConstraint(constraint);
}
ObjectFactory objectFactory = new ObjectFactory();
return objectFactory.createQuery(queryType);
}
use of com.helger.xsds.peppol.smp1.ObjectFactory in project ddf by codice.
the class AbstractCswSource method createSubscriptionGetRecordsRequest.
private GetRecordsType createSubscriptionGetRecordsRequest() {
GetRecordsType getRecordsType = new GetRecordsType();
getRecordsType.setVersion(cswVersion);
getRecordsType.setService(CswConstants.CSW);
getRecordsType.setResultType(ResultType.RESULTS);
getRecordsType.setStartPosition(BigInteger.ONE);
getRecordsType.setMaxRecords(BigInteger.TEN);
getRecordsType.setOutputFormat(MediaType.APPLICATION_XML);
getRecordsType.setOutputSchema("urn:catalog:metacard");
getRecordsType.getResponseHandler().add(SystemBaseUrl.EXTERNAL.constructUrl("csw/subscription/event", true));
QueryType queryType = new QueryType();
queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
ObjectFactory objectFactory = new ObjectFactory();
getRecordsType.setAbstractQuery(objectFactory.createQuery(queryType));
return getRecordsType;
}
Aggregations