Search in sources :

Example 21 with IRI

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);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) SQLException(java.sql.SQLException) BitstreamFormat(org.dspace.content.BitstreamFormat) Date(java.util.Date) Link(org.apache.abdera.model.Link) Abdera(org.apache.abdera.Abdera)

Example 22 with IRI

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;
}
Also used : MetadataValue(org.dspace.content.MetadataValue) IRI(org.apache.abdera.i18n.iri.IRI) SwordCollection(org.swordapp.server.SwordCollection) Collection(org.dspace.content.Collection) SwordCollection(org.swordapp.server.SwordCollection)

Example 23 with IRI

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;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI)

Example 24 with IRI

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);
}
Also used : ResourcePart(org.swordapp.server.ResourcePart) IRI(org.apache.abdera.i18n.iri.IRI) Entry(org.apache.abdera.model.Entry) Category(org.apache.abdera.model.Category) OriginalDeposit(org.swordapp.server.OriginalDeposit) QName(javax.xml.namespace.QName) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Abdera(org.apache.abdera.Abdera) Feed(org.apache.abdera.model.Feed)

Example 25 with IRI

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());
}
Also used : Permission(edu.unc.lib.boxc.auth.api.Permission) SwordError(org.swordapp.server.SwordError) PackagingType(edu.unc.lib.boxc.persist.api.PackagingType) SwordConfiguration(org.swordapp.server.SwordConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SwordCollection(org.swordapp.server.SwordCollection) Autowired(org.springframework.beans.factory.annotation.Autowired) SwordAuthException(org.swordapp.server.SwordAuthException) ServiceDocumentManager(org.swordapp.server.ServiceDocumentManager) RepositoryPaths(edu.unc.lib.boxc.model.fcrepo.ids.RepositoryPaths) PIDs(edu.unc.lib.boxc.model.fcrepo.ids.PIDs) AgentPrincipalsImpl(edu.unc.lib.boxc.auth.fcrepo.models.AgentPrincipalsImpl) SwordConfigurationImpl(edu.unc.lib.boxc.web.sword.SwordConfigurationImpl) IRI(org.apache.abdera.i18n.iri.IRI) Map(java.util.Map) ServiceDocument(org.swordapp.server.ServiceDocument) SwordServerException(org.swordapp.server.SwordServerException) ContentContainerObject(edu.unc.lib.boxc.model.api.objects.ContentContainerObject) RepositoryObject(edu.unc.lib.boxc.model.api.objects.RepositoryObject) AuthCredentials(org.swordapp.server.AuthCredentials) ErrorURIRegistry(edu.unc.lib.boxc.web.sword.ErrorURIRegistry) Logger(org.slf4j.Logger) DepositHandler(edu.unc.lib.boxc.deposit.api.submit.DepositHandler) Collection(java.util.Collection) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RepositoryObjectLoader(edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader) List(java.util.List) PID(edu.unc.lib.boxc.model.api.ids.PID) Collections(java.util.Collections) AgentPrincipals(edu.unc.lib.boxc.auth.api.models.AgentPrincipals) SwordWorkspace(org.swordapp.server.SwordWorkspace) AgentPrincipals(edu.unc.lib.boxc.auth.api.models.AgentPrincipals) IRI(org.apache.abdera.i18n.iri.IRI) RepositoryObject(edu.unc.lib.boxc.model.api.objects.RepositoryObject) PID(edu.unc.lib.boxc.model.api.ids.PID) ContentContainerObject(edu.unc.lib.boxc.model.api.objects.ContentContainerObject) SwordCollection(org.swordapp.server.SwordCollection) PackagingType(edu.unc.lib.boxc.persist.api.PackagingType)

Aggregations

IRI (org.apache.abdera.i18n.iri.IRI)26 MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)6 MCRBase (org.mycore.datamodel.metadata.MCRBase)5 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)5 Abdera (org.apache.abdera.Abdera)4 Entry (org.apache.abdera.model.Entry)4 Feed (org.apache.abdera.model.Feed)4 Date (java.util.Date)3 DepositReceipt (org.swordapp.server.DepositReceipt)3 SwordCollection (org.swordapp.server.SwordCollection)3 Dataset (edu.harvard.iq.dataverse.Dataset)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 MetadataValue (org.dspace.content.MetadataValue)2 Test (org.junit.Test)2 AuthCredentials (org.swordapp.server.AuthCredentials)2 SwordError (org.swordapp.server.SwordError)2