Search in sources :

Example 11 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class GetPrivateUrlCommandTest method testDatasetWithAnId.

@Test
public void testDatasetWithAnId() throws Exception {
    dataset = new Dataset();
    dataset.setId(42l);
    PrivateUrl privateUrl = testEngine.submit(new GetPrivateUrlCommand(null, dataset));
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Example 12 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class DeleteDatasetVersionCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    ctxt.permissions().checkEditDatasetLock(doomed, getRequest(), this);
    // if you are deleting a dataset that only has 1 draft, we are actually destroying the dataset
    if (doomed.getVersions().size() == 1) {
        ctxt.engine().submit(new DestroyDatasetCommand(doomed, getRequest()));
    } else {
        // we are only deleting a version
        // todo: for now, it's only the latest and if it's a draft
        // but we should add the ability to destroy a specific version
        DatasetVersion doomedVersion = doomed.getLatestVersion();
        if (doomedVersion.isDraft()) {
            Long versionId = doomedVersion.getId();
            // files
            Iterator<FileMetadata> fmIt = doomedVersion.getFileMetadatas().iterator();
            while (fmIt.hasNext()) {
                FileMetadata fmd = fmIt.next();
                if (!fmd.getDataFile().isReleased()) {
                    // if file is draft (ie. new to this version, delete
                    // and remove fileMetadata from list (so that it won't try to merge)
                    ctxt.engine().submit(new DeleteDataFileCommand(fmd.getDataFile(), getRequest()));
                    fmIt.remove();
                }
            }
            DatasetVersion doomedAndMerged = ctxt.em().merge(doomedVersion);
            ctxt.em().remove(doomedAndMerged);
            // remove version from ds obj before indexing....
            Iterator<DatasetVersion> dvIt = doomed.getVersions().iterator();
            while (dvIt.hasNext()) {
                DatasetVersion dv = dvIt.next();
                if (versionId.equals(dv.getId())) {
                    dvIt.remove();
                }
            }
            /**
             * DeleteDatasetDraft, which is required by this command,
             * DeleteDatasetVersionCommand is not sufficient for running
             * GetPrivateUrlCommand nor DeletePrivateUrlCommand, both of
             * which require ManageDatasetPermissions because
             * DeletePrivateUrlCommand calls RevokeRoleCommand which
             * requires ManageDatasetPermissions when executed on a dataset
             * so we make direct calls to the service bean so that a lowly
             * Contributor who does NOT have ManageDatasetPermissions can
             * still successfully delete a Private URL.
             */
            PrivateUrl privateUrl = ctxt.privateUrl().getPrivateUrlFromDatasetId(doomed.getId());
            if (privateUrl != null) {
                logger.fine("Deleting Private URL for dataset id " + doomed.getId());
                PrivateUrlUser privateUrlUser = new PrivateUrlUser(doomed.getId());
                List<RoleAssignment> roleAssignments = ctxt.roles().directRoleAssignments(privateUrlUser, doomed);
                for (RoleAssignment roleAssignment : roleAssignments) {
                    ctxt.roles().revoke(roleAssignment);
                }
            }
            boolean doNormalSolrDocCleanUp = true;
            ctxt.index().indexDataset(doomed, doNormalSolrDocCleanUp);
            return;
        }
        throw new IllegalCommandException("Cannot delete a released version", this);
    }
}
Also used : PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl)

Example 13 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class FinalizeDatasetPublicationCommand method execute.

@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
    registerExternalIdentifier(theDataset, ctxt);
    if (theDataset.getPublicationDate() == null) {
        theDataset.setReleaseUser((AuthenticatedUser) getUser());
        theDataset.setPublicationDate(new Timestamp(new Date().getTime()));
    }
    // update metadata
    Timestamp updateTime = new Timestamp(new Date().getTime());
    theDataset.getEditVersion().setReleaseTime(updateTime);
    theDataset.getEditVersion().setLastUpdateTime(updateTime);
    theDataset.setModificationTime(updateTime);
    theDataset.setFileAccessRequest(theDataset.getLatestVersion().getTermsOfUseAndAccess().isFileAccessRequest());
    updateFiles(updateTime, ctxt);
    // 
    // TODO: Not sure if this .merge() is necessary here - ?
    // I'm moving a bunch of code from PublishDatasetCommand here; and this .merge()
    // comes from there. There's a chance that the final merge, at the end of this
    // command, would be sufficient. -- L.A. Sep. 6 2017
    theDataset = ctxt.em().merge(theDataset);
    DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(theDataset.getLatestVersion(), getUser());
    if (ddu == null) {
        ddu = new DatasetVersionUser();
        ddu.setDatasetVersion(theDataset.getLatestVersion());
        String id = getUser().getIdentifier();
        id = id.startsWith("@") ? id.substring(1) : id;
        AuthenticatedUser au = ctxt.authentication().getAuthenticatedUser(id);
        ddu.setAuthenticatedUser(au);
    }
    ddu.setLastUpdateDate((Timestamp) updateTime);
    ctxt.em().merge(ddu);
    updateParentDataversesSubjectsField(theDataset, ctxt);
    publicizeExternalIdentifier(theDataset, ctxt);
    PrivateUrl privateUrl = ctxt.engine().submit(new GetPrivateUrlCommand(getRequest(), theDataset));
    if (privateUrl != null) {
        ctxt.engine().submit(new DeletePrivateUrlCommand(getRequest(), theDataset));
    }
    theDataset.getEditVersion().setVersionState(DatasetVersion.VersionState.RELEASED);
    exportMetadata(ctxt.settings());
    boolean doNormalSolrDocCleanUp = true;
    ctxt.index().indexDataset(theDataset, doNormalSolrDocCleanUp);
    ctxt.solrIndex().indexPermissionsForOneDvObject(theDataset);
    // Remove locks
    ctxt.engine().submit(new RemoveLockCommand(getRequest(), theDataset, DatasetLock.Reason.Workflow));
    if (theDataset.isLockedFor(DatasetLock.Reason.InReview)) {
        ctxt.engine().submit(new RemoveLockCommand(getRequest(), theDataset, DatasetLock.Reason.InReview));
    }
    ctxt.workflows().getDefaultWorkflow(TriggerType.PostPublishDataset).ifPresent(wf -> {
        try {
            ctxt.workflows().start(wf, buildContext(doiProvider, TriggerType.PostPublishDataset));
        } catch (CommandException ex) {
            logger.log(Level.SEVERE, "Error invoking post-publish workflow: " + ex.getMessage(), ex);
        }
    });
    Dataset resultSet = ctxt.em().merge(theDataset);
    if (resultSet != null) {
        notifyUsersDatasetPublish(ctxt, theDataset);
    }
    return resultSet;
}
Also used : DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Date(java.util.Date)

Example 14 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class CreatePrivateUrlCommand method execute.

@Override
public PrivateUrl execute(CommandContext ctxt) throws CommandException {
    logger.fine("Executing CreatePrivateUrlCommand...");
    if (dataset == null) {
        /**
         * @todo Internationalize this.
         */
        String message = "Can't create Private URL. Dataset is null.";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    PrivateUrl existing = ctxt.privateUrl().getPrivateUrlFromDatasetId(dataset.getId());
    if (existing != null) {
        /**
         * @todo Internationalize this.
         */
        String message = "Private URL already exists for dataset id " + dataset.getId() + ".";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    DatasetVersion latestVersion = dataset.getLatestVersion();
    if (!latestVersion.isDraft()) {
        /**
         * @todo Internationalize this.
         */
        String message = "Can't create Private URL because the latest version of dataset id " + dataset.getId() + " is not a draft.";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(dataset.getId());
    DataverseRole memberRole = ctxt.roles().findBuiltinRoleByAlias(DataverseRole.MEMBER);
    final String privateUrlToken = UUID.randomUUID().toString();
    RoleAssignment roleAssignment = ctxt.engine().submit(new AssignRoleCommand(privateUrlUser, memberRole, dataset, getRequest(), privateUrlToken));
    PrivateUrl privateUrl = new PrivateUrl(roleAssignment, dataset, ctxt.systemConfig().getDataverseSiteUrl());
    return privateUrl;
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)14 Dataset (edu.harvard.iq.dataverse.Dataset)9 Test (org.junit.Test)7 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)6 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)5 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)5 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)2 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)2 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)2 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)2 PrivateUrlServiceBean (edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1