Search in sources :

Example 11 with Entry

use of org.apache.abdera.model.Entry in project dataverse by IQSS.

the class CollectionListManagerImpl method listCollectionContents.

@Override
public Feed listCollectionContents(IRI iri, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordServerException, SwordAuthException, SwordError {
    AuthenticatedUser user = swordAuth.auth(authCredentials);
    DataverseRequest dvReq = new DataverseRequest(user, request);
    urlManager.processUrl(iri.toString());
    String dvAlias = urlManager.getTargetIdentifier();
    if (urlManager.getTargetType().equals("dataverse") && dvAlias != null) {
        Dataverse dv = dataverseService.findByAlias(dvAlias);
        if (dv != null) {
            /**
             * We'll say having AddDataset is enough to use this API
             * endpoint, which means you are a Contributor to that
             * dataverse. If we let just anyone call this endpoint, they
             * will be able to see if the supplied dataverse is published or
             * not.
             */
            if (!permissionService.requestOn(dvReq, dv).has(Permission.AddDataset)) {
                throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "user " + user.getDisplayInfo().getTitle() + " is not authorized to list datasets in dataverse " + dv.getAlias());
            }
            Abdera abdera = new Abdera();
            Feed feed = abdera.newFeed();
            feed.setTitle(dv.getName());
            String baseUrl = urlManager.getHostnamePlusBaseUrlPath(iri.toString());
            List<Dataset> datasets = datasetService.findByOwnerId(dv.getId());
            for (Dataset dataset : datasets) {
                /**
                 * @todo Will this be performant enough with production
                 * data, say in the root dataverse? Remove this todo if
                 * there are no complaints. :)
                 */
                if (!permissionService.isUserAllowedOn(user, new UpdateDatasetCommand(dataset, dvReq), dataset)) {
                    continue;
                }
                String editUri = baseUrl + "/edit/study/" + dataset.getGlobalId();
                String editMediaUri = baseUrl + "/edit-media/study/" + dataset.getGlobalId();
                Entry entry = feed.addEntry();
                entry.setId(editUri);
                entry.setTitle(datasetService.getTitleFromLatestVersion(dataset.getId()));
                entry.setBaseUri(new IRI(editUri));
                entry.addLink(editMediaUri, "edit-media");
                feed.addEntry(entry);
            }
            Boolean dvHasBeenReleased = dv.isReleased();
            feed.addSimpleExtension(new QName(UriRegistry.SWORD_STATE, "dataverseHasBeenReleased"), dvHasBeenReleased.toString());
            return feed;
        } else {
            throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataverse: " + dvAlias);
        }
    } else {
        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Couldn't determine target type or identifer from URL: " + iri);
    }
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) SwordError(org.swordapp.server.SwordError) Dataset(edu.harvard.iq.dataverse.Dataset) QName(javax.xml.namespace.QName) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) Abdera(org.apache.abdera.Abdera) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Entry(org.apache.abdera.model.Entry) Feed(org.apache.abdera.model.Feed) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)

Example 12 with Entry

use of org.apache.abdera.model.Entry in project ddf by codice.

the class AtomTransformer method addSingleResult.

private void addSingleResult(Date currentDate, Feed feed, Result result) {
    Metacard metacard = result.getMetacard();
    if (metacard == null) {
        return;
    }
    Entry entry = feed.addEntry();
    entry.setId(URN_CATALOG_ID + metacard.getId());
    addSourceExtension(result, entry);
    addRelevanceScoreExtension(result, entry);
    /*
     * Atom spec text (rfc4287): "The "atom:title" element is a Text construct that conveys
     * a human- readable title for an entry or feed."
     */
    entry.setTitle(metacard.getTitle());
    /*
     * Atom spec text (rfc4287): "The "atom:updated" element is a Date construct indicating
     * the most recent instant in time when an entry or feed was modified in a way the
     * publisher considers significant." Therefore, a new Date is used because we are making
     * the entry for the first time.
     */
    entry.setUpdated(Optional.ofNullable(metacard.getModifiedDate()).orElse(currentDate));
    /*
     * Atom spec text (rfc4287): "Typically, atom:published will be associated with the
     * initial creation or first availability of the resource."
     */
    Optional.ofNullable(metacard.getCreatedDate()).ifPresent(entry::setPublished);
    /*
     * For atom:link elements, Atom spec text (rfc4287): "The value "related" signifies that
     * the IRI in the value of the href attribute identifies a resource related to the
     * resource described by the containing element."
     */
    addLink(resourceActionProvider, metacard, entry, Link.REL_RELATED);
    addLink(viewMetacardActionProvider, metacard, entry, Link.REL_ALTERNATE);
    addLink(thumbnailActionProvider, metacard, entry, REL_PREVIEW);
    /*
     * Atom spec text (rfc4287) Sect. 4.2.2.: "The "atom:category" element conveys
     * information about a category associated with an entry or feed. This specification
     * assigns no meaning to the content (if any) of this element."
     */
    Optional.ofNullable(metacard.getContentTypeName()).ifPresent(entry::addCategory);
    addPosition(metacard, entry);
    setContent(metacard, entry);
}
Also used : Metacard(ddf.catalog.data.Metacard) Entry(org.apache.abdera.model.Entry)

Example 13 with Entry

use of org.apache.abdera.model.Entry in project camel by apache.

the class UpdatedDateFilter method isValidEntry.

public boolean isValidEntry(FeedEndpoint endpoint, Object feed, Object entry) {
    Date updated = ((Entry) entry).getUpdated();
    if (updated == null) {
        // never been updated so get published date
        updated = ((Entry) entry).getPublished();
    }
    if (updated == null) {
        LOG.debug("No updated time for entry so assuming its valid: entry=[{}]", entry);
        return true;
    }
    if (lastUpdate != null) {
        // we need to skip the latest updated entry
        if (lastUpdate.after(updated) || lastUpdate.equals(updated)) {
            LOG.debug("Entry is older than lastupdate=[{}], no valid entry=[{}]", lastUpdate, entry);
            return false;
        }
    }
    lastUpdate = updated;
    return true;
}
Also used : Entry(org.apache.abdera.model.Entry) Date(java.util.Date)

Example 14 with Entry

use of org.apache.abdera.model.Entry in project cxf by apache.

the class JAXRSAtomBookTest method addEntry.

private Entry addEntry(String endpointAddress) throws Exception {
    Entry e = createBookEntry(256, "AtomBook");
    StringWriter w = new StringWriter();
    e.writeTo(w);
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(endpointAddress);
    post.setEntity(new StringEntity(w.toString(), ContentType.APPLICATION_ATOM_XML));
    String location = null;
    try {
        CloseableHttpResponse response = client.execute(post);
        assertEquals(201, response.getStatusLine().getStatusCode());
        location = response.getFirstHeader("Location").getValue();
        InputStream ins = response.getEntity().getContent();
        Document<Entry> entryDoc = abdera.getParser().parse(copyIn(ins));
        assertEquals(entryDoc.getRoot().toString(), e.toString());
    } finally {
        post.releaseConnection();
    }
    Entry entry = getEntry(location, null);
    assertEquals(location, entry.getBaseUri().toString());
    assertEquals("AtomBook", entry.getTitle());
    return entry;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Entry(org.apache.abdera.model.Entry) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 15 with Entry

use of org.apache.abdera.model.Entry in project cxf by apache.

the class JAXRSAtomBookTest method getEntry.

private Entry getEntry(String endpointAddress, String acceptType) throws Exception {
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet(endpointAddress);
    get.setHeader("Content-Type", "*/*");
    if (acceptType != null) {
        get.setHeader("Accept", acceptType);
    }
    try {
        CloseableHttpResponse response = client.execute(get);
        Document<Entry> doc = abdera.getParser().parse(copyIn(response.getEntity().getContent()));
        return doc.getRoot();
    } finally {
        get.releaseConnection();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Entry(org.apache.abdera.model.Entry) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

Entry (org.apache.abdera.model.Entry)22 Test (org.junit.Test)9 Feed (org.apache.abdera.model.Feed)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 JAXBContext (javax.xml.bind.JAXBContext)2 Factory (org.apache.abdera.factory.Factory)2 FOMEntry (org.apache.abdera.parser.stax.FOMEntry)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Metacard (ddf.catalog.data.Metacard)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)1