Search in sources :

Example 1 with SwordCollection

use of org.swordapp.server.SwordCollection in project mycore by MyCoRe-Org.

the class MCRSwordServiceDocumentManager method buildSwordCollectionList.

private List<SwordCollection> buildSwordCollectionList(String workspaceName, AuthCredentials auth) {
    String baseURL = MCRFrontendUtil.getBaseURL();
    List<SwordCollection> swordCollections = new ArrayList<>();
    MCRSword.getCollectionsOfWorkspace(workspaceName).stream().map(collection -> new AbstractMap.SimpleEntry<>(collection, MCRSword.getCollection(collection))).filter(collectionEntry -> collectionEntry.getValue().isVisible()).forEach(collection -> {
        SwordCollection swordCollection = new SwordCollection();
        final String collectionTitle = collection.getKey();
        swordCollection.setTitle(collectionTitle);
        // add the supported packaging to the collection Provider
        final MCRSwordCollectionProvider collectionProvider = collection.getValue();
        collectionProvider.getSupportedPagacking().forEach(swordCollection::addAcceptPackaging);
        swordCollection.setHref(baseURL + MCRSwordConstants.SWORD2_COL_IRI + collectionTitle + "/");
        swordCollections.add(swordCollection);
    });
    return swordCollections;
}
Also used : AbstractMap(java.util.AbstractMap) SwordError(org.swordapp.server.SwordError) SwordConfiguration(org.swordapp.server.SwordConfiguration) MCRSwordConstants(org.mycore.sword.MCRSwordConstants) SwordCollection(org.swordapp.server.SwordCollection) SwordAuthException(org.swordapp.server.SwordAuthException) MCRFrontendUtil(org.mycore.frontend.MCRFrontendUtil) ServiceDocumentManager(org.swordapp.server.ServiceDocumentManager) ArrayList(java.util.ArrayList) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) AbstractMap(java.util.AbstractMap) List(java.util.List) MCRSword(org.mycore.sword.MCRSword) ServiceDocument(org.swordapp.server.ServiceDocument) SwordServerException(org.swordapp.server.SwordServerException) AuthCredentials(org.swordapp.server.AuthCredentials) SwordWorkspace(org.swordapp.server.SwordWorkspace) ArrayList(java.util.ArrayList) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) SwordCollection(org.swordapp.server.SwordCollection)

Example 2 with SwordCollection

use of org.swordapp.server.SwordCollection in project dataverse by IQSS.

the class ServiceDocumentManagerImpl method getServiceDocument.

@Override
public ServiceDocument getServiceDocument(String sdUri, AuthCredentials authCredentials, SwordConfiguration config) throws SwordError, SwordServerException, SwordAuthException {
    AuthenticatedUser user = swordAuth.auth(authCredentials);
    String warning = urlManager.processUrl(sdUri);
    ServiceDocument service = new ServiceDocument();
    SwordWorkspace swordWorkspace = new SwordWorkspace();
    Dataverse rootDataverse = dataverseService.findRootDataverse();
    if (rootDataverse != null) {
        String name = rootDataverse.getName();
        if (name != null) {
            swordWorkspace.setTitle(name);
        }
    }
    if (warning != null) {
        swordWorkspace.getWrappedWorkspace().setAttributeValue("warning", warning);
    }
    service.setMaxUploadSize(config.getMaxUploadSize());
    String hostnamePlusBaseUrl = urlManager.getHostnamePlusBaseUrlPath(sdUri);
    if (hostnamePlusBaseUrl == null) {
        ServiceDocument serviceDocument = new ServiceDocument();
        return serviceDocument;
    }
    /**
     * We don't expect this to support Shibboleth groups because even though
     * a Shibboleth user can have an API token the transient
     * shibIdentityProvider String on AuthenticatedUser is only set when a
     * SAML assertion is made at runtime via the browser.
     */
    List<Dataverse> dataverses = permissionService.getDataversesUserHasPermissionOn(user, Permission.AddDataset);
    for (Dataverse dataverse : dataverses) {
        String dvAlias = dataverse.getAlias();
        if (dvAlias != null && !dvAlias.isEmpty()) {
            SwordCollection swordCollection = new SwordCollection();
            swordCollection.setTitle(dataverse.getName());
            swordCollection.setHref(hostnamePlusBaseUrl + "/collection/dataverse/" + dvAlias);
            swordCollection.addAcceptPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
            swordCollection.setCollectionPolicy(systemConfig.getApiTermsOfUse());
            swordWorkspace.addCollection(swordCollection);
        }
    }
    service.addWorkspace(swordWorkspace);
    return service;
}
Also used : SwordWorkspace(org.swordapp.server.SwordWorkspace) ServiceDocument(org.swordapp.server.ServiceDocument) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) SwordCollection(org.swordapp.server.SwordCollection)

Aggregations

ServiceDocument (org.swordapp.server.ServiceDocument)2 SwordCollection (org.swordapp.server.SwordCollection)2 SwordWorkspace (org.swordapp.server.SwordWorkspace)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MCRFrontendUtil (org.mycore.frontend.MCRFrontendUtil)1 MCRSword (org.mycore.sword.MCRSword)1 MCRSwordConstants (org.mycore.sword.MCRSwordConstants)1 MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)1 AuthCredentials (org.swordapp.server.AuthCredentials)1 ServiceDocumentManager (org.swordapp.server.ServiceDocumentManager)1 SwordAuthException (org.swordapp.server.SwordAuthException)1 SwordConfiguration (org.swordapp.server.SwordConfiguration)1 SwordError (org.swordapp.server.SwordError)1 SwordServerException (org.swordapp.server.SwordServerException)1