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);
}
}
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);
}
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;
}
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;
}
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();
}
}
Aggregations