use of org.apache.abdera.i18n.iri.IRI in project DSpace by DSpace.
the class FeedContentDisseminator method populateEntry.
private void populateEntry(Context context, Entry entry, Bitstream bitstream) throws DSpaceSwordException {
BitstreamFormat format = null;
try {
format = bitstream.getFormat(context);
} catch (SQLException e) {
throw new DSpaceSwordException(e);
}
String contentType = null;
if (format != null) {
contentType = format.getMIMEType();
}
SwordUrlManager urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context);
String bsUrl = urlManager.getBitstreamUrl(bitstream);
entry.setId(bsUrl);
entry.setTitle(bitstream.getName());
String desc = bitstream.getDescription();
if ("".equals(desc) || desc == null) {
desc = bitstream.getName();
}
entry.setSummary(desc);
// required, though content is spurious
entry.setUpdated(new Date());
// add an edit-media link for the bitstream ...
Abdera abdera = new Abdera();
Link link = abdera.getFactory().newLink();
link.setHref(urlManager.getActionableBitstreamUrl(bitstream));
link.setMimeType(contentType);
link.setRel("edit-media");
entry.addLink(link);
// set the content of the bitstream
entry.setContent(new IRI(bsUrl), contentType);
}
use of org.apache.abdera.i18n.iri.IRI in project DSpace by DSpace.
the class CollectionCollectionGenerator method buildCollection.
/**
* Build the collection for the given DSpaceObject. In this implementation,
* if the object is not a DSpace Collection, it will throw DSpaceSwordException
*
* @param context The relevant DSpace Context.
* @param dso DSpace object
* @return the SWORD ATOM collection
* @throws DSpaceSwordException can be thrown by the internals of the DSpace SWORD implementation
*/
@Override
public SwordCollection buildCollection(Context context, DSpaceObject dso, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException {
if (!(dso instanceof org.dspace.content.Collection)) {
log.error("buildCollection passed argument which is not of type Collection");
throw new DSpaceSwordException("Incorrect ATOMCollectionGenerator instantiated");
}
// get the things we need out of the service
SwordUrlManager urlManager = swordConfig.getUrlManager(context, swordConfig);
Collection col = (Collection) dso;
SwordCollection scol = new SwordCollection();
// prepare the parameters to be put in the sword collection
String location = urlManager.getDepositLocation(col);
// collection title is just its name
String title = collectionService.getName(col);
// the collection policy is the licence to which the collection adheres
String collectionPolicy = collectionService.getLicense(col);
// FIXME: what is the treatment? Doesn't seem appropriate for DSpace
// String treatment = " ";
// abstract is the short description of the collection
List<MetadataValue> dcAbstracts = collectionService.getMetadataByMetadataString(col, "short_description");
// we just do support mediation
boolean mediation = swordConfig.isMediated();
// load up the sword collection
scol.setLocation(location);
// add the title if it exists
if (StringUtils.isNotBlank(title)) {
scol.setTitle(title);
}
// add the collection policy if it exists
if (StringUtils.isNotBlank(collectionPolicy)) {
scol.setCollectionPolicy(collectionPolicy);
}
// add the abstract if it exists
if (dcAbstracts != null && !dcAbstracts.isEmpty()) {
String firstValue = dcAbstracts.get(0).getValue();
if (StringUtils.isNotBlank(firstValue)) {
scol.setAbstract(firstValue);
}
}
scol.setMediation(mediation);
List<String> accepts = swordConfig.getCollectionAccepts();
for (String accept : accepts) {
scol.addAccepts(accept);
scol.addMultipartAccepts(accept);
}
// add the accept packaging values
List<String> aps = swordConfig.getAcceptPackaging(col);
for (String ap : aps) {
scol.addAcceptPackaging(ap);
}
// should we offer the items in the collection up as deposit
// targets?
boolean itemService = configurationService.getBooleanProperty("sword.expose-items");
if (itemService) {
String subService = urlManager.constructSubServiceUrl(col);
scol.addSubService(new IRI(subService));
}
log.debug("Created ATOM Collection for DSpace Collection");
return scol;
}
use of org.apache.abdera.i18n.iri.IRI in project box-c by UNC-Libraries.
the class DepositReportingUtil method retrieveDepositReceipt.
/**
* Adds receipt information to the DepositReceipt object for the specified PID. This represents state of the target,
* how it has been unpacked, as well as paths to its individual components and deposit manifest.
*
* @param receipt
* @param targetPID
* @param config
* @return
*/
public DepositReceipt retrieveDepositReceipt(DepositReceipt receipt, PID targetPID, SwordConfigurationImpl config) {
IRI editIRI = new IRI(config.getSwordPath() + SwordConfigurationImpl.EDIT_PATH + "/" + targetPID.getId());
receipt.setEditIRI(editIRI);
IRI swordEditIRI = new IRI(config.getSwordPath() + SwordConfigurationImpl.EDIT_PATH + "/" + targetPID.getId());
receipt.setSwordEditIRI(swordEditIRI);
receipt.addEditMediaIRI(new IRI(config.getSwordPath() + SwordConfigurationImpl.EDIT_MEDIA_PATH + "/" + targetPID.getId()));
return receipt;
}
use of org.apache.abdera.i18n.iri.IRI in project box-c by UNC-Libraries.
the class AtomStatementImpl method writeTo.
@Override
public void writeTo(Writer out) throws IOException {
Abdera abdera = new Abdera();
Feed feed = abdera.newFeed();
feed.setId(this.feedUri);
feed.addLink(this.feedUri, "self");
feed.setTitle(this.title);
feed.addAuthor(this.author);
if (this.updated != null) {
feed.setUpdated(this.updated);
} else {
feed.setUpdated(new Date());
}
// create an entry for each Resource Part
for (ResourcePart resource : this.resources) {
Entry entry = feed.addEntry();
// id
// summary
// title
// updated
entry.setContent(new IRI(resource.getUri()), resource.getMediaType());
entry.setId(resource.getUri());
entry.setTitle("Resource " + resource.getUri());
entry.setSummary("Resource Part");
entry.setUpdated(new Date());
}
// create an entry for each original deposit
for (OriginalDeposit deposit : this.originalDeposits) {
Entry entry = feed.addEntry();
// id
// summary
// title
// updated
entry.setId(deposit.getUri());
entry.setTitle("Original Deposit " + deposit.getUri());
entry.setSummary("Original Deposit");
entry.setUpdated(new Date());
if (deposit.getMediaType() != null) {
entry.setContent(new IRI(deposit.getUri()), deposit.getMediaType());
}
entry.addCategory(UriRegistry.SWORD_TERMS_NAMESPACE, UriRegistry.SWORD_ORIGINAL_DEPOSIT, "Original Deposit");
if (deposit.getDepositedOn() != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
entry.addSimpleExtension(new QName(UriRegistry.SWORD_TERMS_NAMESPACE, "depositedOn"), sdf.format(deposit.getDepositedOn()));
}
if (deposit.getDepositedOnBehalfOf() != null) {
entry.addSimpleExtension(new QName(UriRegistry.SWORD_TERMS_NAMESPACE, "depositedOnBehalfOf"), deposit.getDepositedOnBehalfOf());
}
if (deposit.getDepositedBy() != null) {
entry.addSimpleExtension(new QName(UriRegistry.SWORD_TERMS_NAMESPACE, "depositedBy"), deposit.getDepositedBy());
}
if (deposit.getPackaging() != null) {
for (String packaging : deposit.getPackaging()) {
entry.addSimpleExtension(UriRegistry.SWORD_PACKAGING, packaging);
}
}
}
// now at the state as a categories
for (String state : this.states.keySet()) {
Category cat = feed.addCategory(UriRegistry.SWORD_STATE, state, "State");
if (this.states.get(state) != null) {
cat.setText(this.states.get(state));
}
}
// now write the feed
feed.writeTo(out);
}
use of org.apache.abdera.i18n.iri.IRI in project box-c by UNC-Libraries.
the class ServiceDocumentManagerImpl method getImmediateContainerChildren.
/**
* Retrieves a list of SwordCollection objects representing all the children containers of container pid which the
* groups in groupList have curator access to.
*
* @param pid
* pid of the container to retrieve the children of.
* @param groupList
* list of permission groups
* @param config
* @return
* @throws IOException
*/
protected List<SwordCollection> getImmediateContainerChildren(PID pid, AuthCredentials auth, SwordConfigurationImpl config) throws IOException {
RepositoryObject repoObj = repositoryObjectLoader.getRepositoryObject(pid);
ContentContainerObject containerObj;
if (repoObj instanceof ContentContainerObject) {
containerObj = (ContentContainerObject) repoObj;
} else {
return Collections.emptyList();
}
AgentPrincipals agent = AgentPrincipalsImpl.createFromThread();
return containerObj.getMembers().stream().map(child -> {
PID childPid = child.getPid();
if (!aclService.hasAccess(childPid, agent.getPrincipals(), Permission.ingest)) {
return (SwordCollection) null;
}
SwordCollection collection = new SwordCollection();
collection.setHref(config.getSwordPath() + SwordConfigurationImpl.COLLECTION_PATH + "/" + childPid.getId());
collection.setTitle(childPid.getId());
collection.addAccepts("application/zip");
collection.addAccepts("text/xml");
collection.addAccepts("application/xml");
for (PackagingType packaging : acceptedPackaging) {
collection.addAcceptPackaging(packaging.getUri());
}
collection.setMediation(true);
IRI iri = new IRI(config.getSwordPath() + SwordConfigurationImpl.SERVICE_DOCUMENT_PATH + "/" + childPid.getId());
collection.addSubService(iri);
return collection;
}).collect(Collectors.toList());
}
Aggregations