Search in sources :

Example 1 with ServiceDocument

use of org.swordapp.server.ServiceDocument 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)

Example 2 with ServiceDocument

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

the class MCRSwordServiceDocumentManager method getServiceDocument.

@Override
public ServiceDocument getServiceDocument(String sdUri, AuthCredentials auth, SwordConfiguration config) throws SwordError, SwordServerException, SwordAuthException {
    ServiceDocument serviceDocument = new ServiceDocument();
    MCRSword.getWorkspaces().forEach(workspaceName -> {
        SwordWorkspace workspace = buildSwordWorkspace(workspaceName, auth);
        serviceDocument.addWorkspace(workspace);
    });
    return serviceDocument;
}
Also used : SwordWorkspace(org.swordapp.server.SwordWorkspace) ServiceDocument(org.swordapp.server.ServiceDocument)

Aggregations

ServiceDocument (org.swordapp.server.ServiceDocument)2 SwordWorkspace (org.swordapp.server.SwordWorkspace)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 SwordCollection (org.swordapp.server.SwordCollection)1