Search in sources :

Example 11 with IRI

use of org.apache.abdera.i18n.iri.IRI in project dataverse by IQSS.

the class StatementManagerImpl method getStatement.

@Override
public Statement getStatement(String editUri, Map<String, String> map, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordServerException, SwordError, SwordAuthException {
    AuthenticatedUser user = swordAuth.auth(authCredentials);
    DataverseRequest dvReq = new DataverseRequest(user, httpRequest);
    urlManager.processUrl(editUri);
    String globalId = urlManager.getTargetIdentifier();
    if (urlManager.getTargetType().equals("study") && globalId != null) {
        logger.fine("request for sword statement by user " + user.getDisplayInfo().getTitle());
        Dataset dataset = datasetService.findByGlobalId(globalId);
        if (dataset == null) {
            throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "couldn't find dataset with global ID of " + globalId);
        }
        Dataverse dvThatOwnsDataset = dataset.getOwner();
        if (!permissionService.isUserAllowedOn(user, new GetDraftDatasetVersionCommand(dvReq, dataset), dataset)) {
            throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "user " + user.getDisplayInfo().getTitle() + " is not authorized to view dataset with global ID " + globalId);
        }
        String feedUri = urlManager.getHostnamePlusBaseUrlPath(editUri) + "/edit/study/" + dataset.getGlobalIdString();
        String author = dataset.getLatestVersion().getAuthorsStr();
        String title = dataset.getLatestVersion().getTitle();
        // in the statement, the element is called "updated"
        Date lastUpdatedFinal = new Date();
        Date lastUpdateTime = dataset.getLatestVersion().getLastUpdateTime();
        if (lastUpdateTime != null) {
            lastUpdatedFinal = lastUpdateTime;
        } else {
            logger.info("lastUpdateTime was null, trying createtime");
            Date createtime = dataset.getLatestVersion().getCreateTime();
            if (createtime != null) {
                lastUpdatedFinal = createtime;
            } else {
                logger.info("creatime was null, using \"now\"");
                lastUpdatedFinal = new Date();
            }
        }
        AtomDate atomDate = new AtomDate(lastUpdatedFinal);
        String datedUpdated = atomDate.toString();
        Statement statement = new AtomStatement(feedUri, author, title, datedUpdated);
        Map<String, String> states = new HashMap<>();
        states.put("latestVersionState", dataset.getLatestVersion().getVersionState().toString());
        Boolean isMinorUpdate = dataset.getLatestVersion().isMinorUpdate();
        states.put("isMinorUpdate", isMinorUpdate.toString());
        if (dataset.isLocked()) {
            states.put("locked", "true");
            states.put("lockedDetail", dataset.getLocks().stream().map(l -> l.getInfo()).collect(joining(",")));
            Optional<DatasetLock> earliestLock = dataset.getLocks().stream().min((l1, l2) -> (int) Math.signum(l1.getStartTime().getTime() - l2.getStartTime().getTime()));
            states.put("lockedStartTime", earliestLock.get().getStartTime().toString());
        } else {
            states.put("locked", "false");
        }
        statement.setStates(states);
        List<FileMetadata> fileMetadatas = dataset.getLatestVersion().getFileMetadatas();
        for (FileMetadata fileMetadata : fileMetadatas) {
            DataFile dataFile = fileMetadata.getDataFile();
            // We are exposing the filename for informational purposes. The file id is what you
            // actually operate on to delete a file, etc.
            // 
            // Replace spaces to avoid IRISyntaxException
            String fileNameFinal = fileMetadata.getLabel().replace(' ', '_');
            // TODO: Consider where we would show the persistent identifiers for files via SWORD.
            String fileUrlString = urlManager.getHostnamePlusBaseUrlPath(editUri) + "/edit-media/file/" + dataFile.getId() + "/" + fileNameFinal;
            IRI fileUrl;
            try {
                fileUrl = new IRI(fileUrlString);
            } catch (IRISyntaxException ex) {
                throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Invalid URL for file ( " + fileUrlString + " ) resulted in " + ex.getMessage());
            }
            ResourcePart resourcePart = new ResourcePart(fileUrl.toString());
            // default to something that doesn't throw a org.apache.abdera.util.MimeTypeParseException
            String finalFileFormat = "application/octet-stream";
            String contentType = dataFile.getContentType();
            if (contentType != null) {
                finalFileFormat = contentType;
            }
            resourcePart.setMediaType(finalFileFormat);
            /**
             * @todo: Why are properties set on a ResourcePart not exposed
             * when you GET a Statement? Asked about this at
             * http://www.mail-archive.com/sword-app-tech@lists.sourceforge.net/msg00394.html
             */
            // Map<String, String> properties = new HashMap<String, String>();
            // properties.put("filename", studyFile.getFileName());
            // properties.put("category", studyFile.getLatestCategory());
            // properties.put("originalFileType", studyFile.getOriginalFileType());
            // properties.put("id", studyFile.getId().toString());
            // properties.put("UNF", studyFile.getUnf());
            // resourcePart.setProperties(properties);
            statement.addResource(resourcePart);
        /**
         * @todo it's been noted at
         * https://github.com/IQSS/dataverse/issues/892#issuecomment-54159284
         * that at the file level the "updated" date is always "now",
         * which seems to be set here:
         * https://github.com/swordapp/JavaServer2.0/blob/sword2-server-1.0/src/main/java/org/swordapp/server/AtomStatement.java#L70
         */
        }
        return statement;
    } else {
        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not determine target type or identifier from URL: " + editUri);
    }
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) ResourcePart(org.swordapp.server.ResourcePart) SwordError(org.swordapp.server.SwordError) AtomStatement(org.swordapp.server.AtomStatement) HashMap(java.util.HashMap) Dataset(edu.harvard.iq.dataverse.Dataset) AtomStatement(org.swordapp.server.AtomStatement) Statement(org.swordapp.server.Statement) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) Date(java.util.Date) AtomDate(org.apache.abdera.model.AtomDate) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DataFile(edu.harvard.iq.dataverse.DataFile) AtomDate(org.apache.abdera.model.AtomDate) GetDraftDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetDraftDatasetVersionCommand) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException)

Example 12 with IRI

use of org.apache.abdera.i18n.iri.IRI in project DSpace by DSpace.

the class CommunityCollectionGenerator method buildCollection.

public SwordCollection buildCollection(Context context, DSpaceObject dso, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException {
    if (!(dso instanceof Community)) {
        log.error("buildCollection passed something other than a Community object");
        throw new DSpaceSwordException("Incorrect ATOMCollectionGenerator instantiated");
    }
    // get the things we need out of the service
    SwordUrlManager urlManager = swordConfig.getUrlManager(context, swordConfig);
    Community com = (Community) dso;
    SwordCollection scol = new SwordCollection();
    // prepare the parameters to be put in the sword collection
    String location = urlManager.getDepositLocation(com);
    if (location == null) {
        location = handleService.getCanonicalForm(com.getHandle());
    }
    scol.setLocation(location);
    // collection title is just the community name
    String title = communityService.getName(com);
    if (StringUtils.isNotBlank(title)) {
        scol.setTitle(title);
    }
    // FIXME: the community has no obvious licence
    // the collection policy is the licence to which the collection adheres
    // String collectionPolicy = col.getLicense();
    // abstract is the short description of the collection
    List<MetadataValue> abstracts = communityService.getMetadataByMetadataString(com, "short_description");
    if (abstracts != null && !abstracts.isEmpty()) {
        String firstValue = abstracts.get(0).getValue();
        if (StringUtils.isNotBlank(firstValue)) {
            scol.setAbstract(firstValue);
        }
    }
    // do we support mediated deposit
    scol.setMediation(swordConfig.isMediated());
    // NOTE: for communities, there are no MIME types that it accepts.
    // the list of mime types that we accept
    // offer up the collections from this item as deposit targets
    String subService = urlManager.constructSubServiceUrl(com);
    scol.addSubService(new IRI(subService));
    log.debug("Created ATOM Collection for DSpace Community");
    return scol;
}
Also used : MetadataValue(org.dspace.content.MetadataValue) IRI(org.apache.abdera.i18n.iri.IRI) Community(org.dspace.content.Community) SwordCollection(org.swordapp.server.SwordCollection)

Example 13 with IRI

use of org.apache.abdera.i18n.iri.IRI in project DSpace by DSpace.

the class ReceiptGenerator method createFileReceipt.

protected DepositReceipt createFileReceipt(Context context, DepositResult result, SwordConfigurationDSpace config) throws DSpaceSwordException, SwordError, SwordServerException {
    SwordUrlManager urlManager = config.getUrlManager(context, config);
    DepositReceipt receipt = new DepositReceipt();
    receipt.setLocation(new IRI(urlManager.getActionableBitstreamUrl(result.getOriginalDeposit())));
    receipt.setEmpty(true);
    return receipt;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) DepositReceipt(org.swordapp.server.DepositReceipt)

Example 14 with IRI

use of org.apache.abdera.i18n.iri.IRI in project jaggery by wso2.

the class FeedHostObject method jsGet_logo.

public String jsGet_logo() throws ScriptException {
    String logoStr = null;
    IRI logo = feed.getLogo();
    if (logo == null) {
        return null;
    }
    try {
        logoStr = logo.toURL().toString();
    } catch (MalformedURLException e) {
        throw new ScriptException(e);
    } catch (URISyntaxException e) {
        throw new ScriptException(e);
    }
    return logoStr;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException)

Example 15 with IRI

use of org.apache.abdera.i18n.iri.IRI in project dataverse by IQSS.

the class ReceiptGenerator method createDataverseReceipt.

DepositReceipt createDataverseReceipt(String baseUrl, Dataverse dataverse) {
    logger.fine("baseUrl was: " + baseUrl);
    DepositReceipt depositReceipt = new DepositReceipt();
    String globalId = dataverse.getAlias();
    String collectionIri = baseUrl + "/collection/dataverse/" + globalId;
    depositReceipt.setSplashUri(collectionIri);
    /**
     * @todo We have to include an "edit" IRI or else we get
     * NullPointerException in getAbderaEntry at
     * https://github.com/swordapp/JavaServer2.0/blob/sword2-server-1.0/src/main/java/org/swordapp/server/DepositReceipt.java#L52
     *
     * Do we want to support a replaceMetadata of dataverses? Probably not.
     * Let's do that with the native API.
     *
     * Typically, we only operate on the "collection" IRI for dataverses, to
     * create a dataset.
     */
    String editIri = baseUrl + "/edit/dataverse/" + globalId;
    depositReceipt.setEditIRI(new IRI(editIri));
    return depositReceipt;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) DepositReceipt(org.swordapp.server.DepositReceipt)

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