Search in sources :

Example 1 with ObjectFactory

use of com.a9.opensearch.ObjectFactory in project ARLAS-server by gisaia.

the class OpenSearchHandler method getOpenSearchDescription.

public OpenSearchDescription getOpenSearchDescription(String serverUrl) {
    ObjectFactory objectFactory = new ObjectFactory();
    OpenSearchDescription description = objectFactory.createOpenSearchDescription();
    description.getOtherAttributes().put(new QName("http://a9.com/-/opensearch/extensions/geo/1.0/", "opensearchgeo"), "opensearchgeo");
    description.setDescription(cswHandler.cswConfiguration.openSearchDescription);
    description.setShortName(cswHandler.cswConfiguration.openSearchShortName);
    Url urlXMLBox = new Url();
    urlXMLBox.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0&q={searchTerms?}" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&bbox={ns3:box?}" + "&elementSetName=full&outputschema=http://www.opengis.net/cat/csw/3.0" + "&outputFormat=application/xml");
    urlXMLBox.setType(MediaType.APPLICATION_XML);
    Url urlATOMBox = new Url();
    urlATOMBox.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0&q={searchTerms?}" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&bbox={ns3:box?}" + "&elementSetName=full" + "&outputFormat=application/atom%2Bxml");
    urlATOMBox.setType(MediaType.APPLICATION_ATOM_XML);
    Url urlXMLId = new Url();
    urlXMLId.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&recordIds={ns3:uid?}" + "&elementSetName=full&outputschema=http://www.opengis.net/cat/csw/3.0" + "&outputFormat=application/xml");
    urlXMLId.setType(MediaType.APPLICATION_XML);
    Url urlATOMId = new Url();
    urlATOMId.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&recordIds={ns3:uid?}" + "&elementSetName=full" + "&outputFormat=application/atom%2Bxml");
    urlATOMId.setType(MediaType.APPLICATION_ATOM_XML);
    description.getUrl().add(urlXMLBox);
    description.getUrl().add(urlXMLId);
    description.getUrl().add(urlATOMBox);
    description.getUrl().add(urlATOMId);
    return description;
}
Also used : ObjectFactory(com.a9.opensearch.ObjectFactory) QName(javax.xml.namespace.QName) Url(com.a9.opensearch.Url) OpenSearchDescription(com.a9.opensearch.OpenSearchDescription)

Example 2 with ObjectFactory

use of com.a9.opensearch.ObjectFactory 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

QName (javax.xml.namespace.QName)2 ObjectFactory (com.a9.opensearch.ObjectFactory)1 OpenSearchDescription (com.a9.opensearch.OpenSearchDescription)1 QueryType (com.a9.opensearch.QueryType)1 Url (com.a9.opensearch.Url)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