use of org.apache.abdera.Abdera 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.Abdera in project jaggery by wso2.
the class EntryHostObject method jsConstructor.
/**
* Constructor the user will be using inside javaScript
*/
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
EntryHostObject entryHO = new EntryHostObject();
entryHO.abdera = new Abdera();
Factory factory = entryHO.abdera.getFactory();
entryHO.entry = factory.newEntry();
entryHO.context = cx;
return entryHO;
}
use of org.apache.abdera.Abdera in project jaggery by wso2.
the class FeedHostObject method addEntry.
public void addEntry(Object entryObject) throws ScriptException {
abdera = new Abdera();
Factory factory = abdera.getFactory();
entry = factory.newEntry();
if (entryObject instanceof EntryHostObject) {
EntryHostObject entryHostObject = (EntryHostObject) entryObject;
entry = entryHostObject.getEntry();
feed.addEntry(entry);
} else if (entryObject instanceof NativeObject) {
try {
NativeObject nativeObject = (NativeObject) entryObject;
ScriptableObject scriptableObject = (ScriptableObject) nativeObject;
// author and authors processing
Object authorProperty = ScriptableObject.getProperty(nativeObject, "author");
if (authorProperty instanceof String) {
entry.addAuthor((String) (authorProperty));
}
Object authorsProperty = ScriptableObject.getProperty(nativeObject, "authors");
if (authorsProperty instanceof NativeArray) {
NativeArray authorsPropertyArray = (NativeArray) authorsProperty;
for (Object o1 : authorsPropertyArray.getIds()) {
int indexx = (Integer) o1;
String name = authorsPropertyArray.get(indexx, null).toString();
entry.addAuthor(name);
}
}
// processing category
Object categoryProperty = ScriptableObject.getProperty(nativeObject, "category");
if (categoryProperty instanceof String) {
entry.addCategory((String) (categoryProperty));
}
Object categoriesProperty = ScriptableObject.getProperty(nativeObject, "categories");
if (categoriesProperty instanceof NativeArray) {
NativeArray categoriesPropertyArray = (NativeArray) categoriesProperty;
for (Object o1 : categoriesPropertyArray.getIds()) {
int indexC = (Integer) o1;
String name = categoriesPropertyArray.get(indexC, null).toString();
entry.addCategory(name);
}
}
// process content
Object content = ScriptableObject.getProperty(nativeObject, "content");
if (content instanceof XMLObject) {
entry.setContentAsXhtml(content.toString());
} else if (content instanceof String) {
entry.setContent(content.toString());
} else {
throw new ScriptException("Unsupported Content");
}
// process contributor
Object contributorProperty = ScriptableObject.getProperty(nativeObject, "contributor");
if (contributorProperty instanceof String) {
entry.addContributor(contributorProperty.toString());
}
Object contributorsProperty = ScriptableObject.getProperty(nativeObject, "contributors");
if (contributorsProperty instanceof NativeArray) {
NativeArray contributorsPropertyArray = (NativeArray) contributorsProperty;
for (Object o1 : contributorsPropertyArray.getIds()) {
int index = (Integer) o1;
String name = contributorsPropertyArray.get(index, null).toString();
entry.addContributor(name);
}
}
// process id
Object idProperty = ScriptableObject.getProperty(nativeObject, "id");
if (idProperty instanceof String) {
entry.setId((String) (idProperty));
} else {
entry.setId(FOMHelper.generateUuid());
}
// process link
// TODO link object
Object linkProperty = ScriptableObject.getProperty(nativeObject, "link");
if (linkProperty instanceof String) {
entry.addLink((String) (linkProperty));
}
Object linksProperty = ScriptableObject.getProperty(nativeObject, "links");
if (linksProperty instanceof NativeArray) {
NativeArray linksPropertyArray = (NativeArray) contributorsProperty;
for (Object o1 : linksPropertyArray.getIds()) {
int index = (Integer) o1;
String name = linksPropertyArray.get(index, null).toString();
entry.addLink(name);
}
}
// process published
// TODO handle javascript date
Object publishedProperty = ScriptableObject.getProperty(nativeObject, "published");
if (publishedProperty instanceof String) {
if (publishedProperty.equals("now")) {
entry.setPublished(new Date(System.currentTimeMillis()));
} else {
entry.setPublished(publishedProperty.toString());
}
}
// process rights
Object rights = ScriptableObject.getProperty(nativeObject, "rights");
if (rights instanceof XMLObject) {
entry.setRightsAsXhtml(rights.toString());
} else if (rights instanceof String) {
entry.setRights(rights.toString());
}
// process summary
Object summary = ScriptableObject.getProperty(nativeObject, "summary");
if (summary instanceof XMLObject) {
entry.setSummaryAsXhtml(summary.toString());
} else if (summary instanceof String) {
entry.setSummary(summary.toString());
}
// process title
Object title = ScriptableObject.getProperty(nativeObject, "title");
if (title instanceof XMLObject) {
entry.setTitleAsXhtml(title.toString());
} else if (title instanceof String) {
entry.setTitle(title.toString());
} else {
throw new ScriptException("An Entry MUST have a title.");
}
// process updated
Object updated = ScriptableObject.getProperty(nativeObject, "updated");
if (updated instanceof String) {
if (updated.equals("now")) {
entry.setUpdated(new Date(System.currentTimeMillis()));
} else {
entry.setUpdated((String) updated);
}
}
} catch (IRISyntaxException e) {
throw new ScriptException(e);
}
} else if (!(entryObject instanceof EntryHostObject)) {
throw new ScriptException("Invalid parameter");
}
// log.info("New Added Entry" + entry);
}
use of org.apache.abdera.Abdera in project jaggery by wso2.
the class FeedHostObject method jsConstructor.
/**
* Constructor the user will be using inside javaScript
*/
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws ScriptException {
int argsCount = args.length;
if (argsCount > 2) {
HostObjectUtil.invalidNumberOfArgs(HOST_OBJECT_NAME, HOST_OBJECT_NAME, argsCount, true);
}
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
feed = factory.newFeed();
feedHostObject = new FeedHostObject();
ctx = cx;
if (argsCount == 0) {
return feedHostObject;
}
if (argsCount == 1) {
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(HOST_OBJECT_NAME, HOST_OBJECT_NAME, "1", "string", args[0], true);
}
FeedHostObject.jsFunction_getFeed(cx, null, args, null);
}
return feedHostObject;
}
use of org.apache.abdera.Abdera in project mycore by MyCoRe-Org.
the class MCRSwordCollectionManager method listCollectionContents.
@Override
public Feed listCollectionContents(IRI collectionIRI, AuthCredentials authCredentials, SwordConfiguration config) throws SwordServerException, SwordAuthException, SwordError {
String collection = MCRSwordUtil.ParseLinkUtil.CollectionIRI.getCollectionNameFromCollectionIRI(collectionIRI);
String path = collectionIRI.getPath();
LOGGER.info(MessageFormat.format("List Collection: {0}", collection));
Feed feed = new Abdera().newFeed();
if (MCRSword.getCollectionNames().contains(collection)) {
MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
collectionProvider.getAuthHandler().authentication(authCredentials);
if (collectionProvider.isVisible()) {
Integer paginationFromIRI = MCRSwordUtil.ParseLinkUtil.CollectionIRI.getPaginationFromCollectionIRI(collectionIRI);
final int start = (paginationFromIRI - 1) * MCRSwordConstants.MAX_ENTRYS_PER_PAGE;
collectionProvider.getIDSupplier().get(start, MCRSwordConstants.MAX_ENTRYS_PER_PAGE).stream().map(id -> {
try {
return collectionProvider.getMetadataProvider().provideListMetadata(id);
} catch (SwordError swordError) {
LOGGER.warn("Error while creating feed for [{}]! (Will be removed from List)", id);
return null;
}
}).filter(Objects::nonNull).forEach(feed::addEntry);
MCRSwordUtil.BuildLinkUtil.addPaginationLinks(collectionIRI, collection, feed, collectionProvider);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The collection '" + collection + "' does not exist!");
}
return feed;
}
Aggregations