Search in sources :

Example 1 with QueryType

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) JAXBContext(javax.xml.bind.JAXBContext) Marshaller(javax.xml.bind.Marshaller) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) JAXBElement(javax.xml.bind.JAXBElement) Date(java.util.Date) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) BigInteger(java.math.BigInteger) QueryType(com.a9.opensearch.QueryType)

Aggregations

QueryType (com.a9.opensearch.QueryType)1 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1