use of com.a9.opensearch.QueryType in project ARLAS-server by gisaia.
the class AtomGetRecordsMessageBodyWriter method writeTo.
@Override
public void writeTo(GetRecordsResponseType getRecordsResponseType, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
FeedType feedType = new FeedType();
PersonType personType = new PersonType();
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> name = objectFactory.createName("Matthieu Barbet");
personType.getNameOrUriOrEmail().add(name);
feedType.getAuthor().add(personType);
TextType title = objectFactory.createTextType();
title.getContent().add(this.arlasServerConfiguration.cswConfiguration.openSearchShortName);
feedType.setTitle(title);
IdType idTypeValue = new IdType();
idTypeValue.setValue(String.valueOf(this.arlasServerConfiguration.cswConfiguration.openSearchShortName.hashCode()));
feedType.setId(idTypeValue);
GregorianCalendar c = new GregorianCalendar();
c.setTime(new Date());
try {
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
DateTimeType dateTimeType = new DateTimeType();
dateTimeType.setValue(date);
feedType.setUpdated(dateTimeType);
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
LinkType linkType = new LinkType();
linkType.setType(CSWRESTService.MIME_TYPE__OPENSEARCH_XML);
linkType.setHref(arlasServerConfiguration.arlasBaseUri + "ogc/opensearch/{collection}");
linkType.setRel("search");
feedType.getLink().add(linkType);
com.a9.opensearch.ObjectFactory openSearchFactory = new com.a9.opensearch.ObjectFactory();
BigInteger nextRecord = getRecordsResponseType.getSearchResults().getNextRecord();
BigInteger totalResult = getRecordsResponseType.getSearchResults().getNumberOfRecordsReturned();
Long nextRecordLong = nextRecord.longValue();
Long totalResultLong = totalResult.longValue();
JAXBElement<Long> startIndex = openSearchFactory.createStartIndex(nextRecordLong - totalResultLong);
feedType.getAny().add(startIndex);
JAXBElement<Long> totalResults = openSearchFactory.createTotalResults(totalResultLong);
feedType.getAny().add(totalResults);
JAXBElement<Long> itemPerPages = openSearchFactory.createItemsPerPage(totalResultLong);
feedType.getAny().add(itemPerPages);
try {
JAXBContext jc = JAXBContext.newInstance(String.class, QueryType.class, FeedType.class);
Marshaller m = jc.createMarshaller();
QueryType queryType = new QueryType();
queryType.setRole("request");
QName _Query_QNAME = new QName("http://a9.com/-/spec/opensearch/1.1/", "Query");
JAXBElement<QueryType> query = new JAXBElement<>(_Query_QNAME, QueryType.class, null, queryType);
feedType.getAny().add(query);
getRecordsResponseType.getSearchResults().getAbstractRecord().stream().forEach(jaxbElement -> {
EntryType entryType = new EntryType();
AtomBuilder.setEntryType(jaxbElement.getValue(), feedType, entryType);
feedType.getEntry().add(entryType);
});
try {
m.marshal(objectFactory.createFeed(feedType), outputStream);
} catch (JAXBException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
} catch (JAXBException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
}
Aggregations