Search in sources :

Example 1 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.

the class DatasetPage method isLockedFromEdits.

/**
 * Authors are not allowed to edit but curators are allowed - when Dataset is inReview
 * For all other locks edit should be locked for all editors.
 */
public boolean isLockedFromEdits() {
    if (null == lockedFromEditsVar) {
        try {
            permissionService.checkEditDatasetLock(dataset, dvRequestService.getDataverseRequest(), new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest()));
            lockedFromEditsVar = false;
        } catch (IllegalCommandException ex) {
            lockedFromEditsVar = true;
        }
    }
    return lockedFromEditsVar;
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)

Example 2 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.

the class FilePage method isLockedFromDownload.

public boolean isLockedFromDownload() {
    if (null == dataset) {
        dataset = fileMetadata.getDataFile().getOwner();
    }
    if (null == lockedFromDownloadVar) {
        try {
            permissionService.checkDownloadFileLock(dataset, dvRequestService.getDataverseRequest(), new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest()));
            lockedFromDownloadVar = false;
        } catch (IllegalCommandException ex) {
            lockedFromDownloadVar = true;
        }
    }
    return lockedFromDownloadVar;
}
Also used : CreateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Example 3 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.

the class FilePage method isLockedFromEdits.

/**
 * Authors are not allowed to edit but curators are allowed - when Dataset is inReview
 * For all other locks edit should be locked for all editors.
 */
public boolean isLockedFromEdits() {
    if (null == dataset) {
        dataset = fileMetadata.getDataFile().getOwner();
    }
    if (null == lockedFromEditsVar) {
        try {
            permissionService.checkEditDatasetLock(dataset, dvRequestService.getDataverseRequest(), new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest()));
            lockedFromEditsVar = false;
        } catch (IllegalCommandException ex) {
            lockedFromEditsVar = true;
        }
    }
    return lockedFromEditsVar;
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)

Example 4 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.

the class DeleteDataverseCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    // Make sure we don't delete root
    if (doomed.getOwner() == null) {
        throw new IllegalCommandException("Cannot delete the root dataverse", this);
    }
    // make sure the dataverse is emptyw
    if (ctxt.dvObjects().hasData(doomed)) {
        throw new IllegalCommandException("Cannot delete non-empty dataverses", this);
    }
    // ASSIGNMENTS
    for (RoleAssignment ra : ctxt.roles().directRoleAssignments(doomed)) {
        ctxt.em().remove(ra);
    }
    // ROLES
    for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) {
        ctxt.em().remove(ra);
    }
    // EXPLICIT GROUPS
    for (ExplicitGroup eg : ctxt.em().createNamedQuery("ExplicitGroup.findByOwnerId", ExplicitGroup.class).setParameter("ownerId", doomed.getId()).getResultList()) {
        ctxt.explicitGroups().removeGroup(eg);
    }
    // Input Level
    for (DataverseFieldTypeInputLevel inputLevel : doomed.getDataverseFieldTypeInputLevels()) {
        DataverseFieldTypeInputLevel merged = ctxt.em().merge(inputLevel);
        ctxt.em().remove(merged);
    }
    doomed.setDataverseFieldTypeInputLevels(new ArrayList<>());
    // DATAVERSE
    Dataverse doomedAndMerged = ctxt.em().merge(doomed);
    ctxt.em().remove(doomedAndMerged);
    // Remove from index
    ctxt.index().delete(doomed);
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 5 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.

the class CreateDataverseCommand method execute.

@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
    if (created.getOwner() == null) {
        if (ctxt.dataverses().isRootDataverseExists()) {
            throw new IllegalCommandException("Root Dataverse already exists. Cannot create another one", this);
        }
    }
    if (created.getCreateDate() == null) {
        created.setCreateDate(new Timestamp(new Date().getTime()));
    }
    if (created.getCreator() == null) {
        final User user = getRequest().getUser();
        if (user.isAuthenticated()) {
            created.setCreator((AuthenticatedUser) user);
        } else {
            throw new IllegalCommandException("Guest users cannot create a Dataverse.", this);
        }
    }
    if (created.getDataverseType() == null) {
        created.setDataverseType(Dataverse.DataverseType.UNCATEGORIZED);
    }
    if (created.getDefaultContributorRole() == null) {
        created.setDefaultContributorRole(ctxt.roles().findBuiltinRoleByAlias(DataverseRole.EDITOR));
    }
    // @todo for now we are saying all dataverses are permission root
    created.setPermissionRoot(true);
    if (ctxt.dataverses().findByAlias(created.getAlias()) != null) {
        throw new IllegalCommandException("A dataverse with alias " + created.getAlias() + " already exists", this);
    }
    // Save the dataverse
    Dataverse managedDv = ctxt.dataverses().save(created);
    // Find the built in admin role (currently by alias)
    DataverseRole adminRole = ctxt.roles().findBuiltinRoleByAlias(DataverseRole.ADMIN);
    String privateUrlToken = null;
    ctxt.roles().save(new RoleAssignment(adminRole, getRequest().getUser(), managedDv, privateUrlToken));
    managedDv.setPermissionModificationTime(new Timestamp(new Date().getTime()));
    managedDv = ctxt.dataverses().save(managedDv);
    ctxt.index().indexDataverse(managedDv);
    if (facetList != null) {
        ctxt.facets().deleteFacetsFor(managedDv);
        int i = 0;
        for (DatasetFieldType df : facetList) {
            ctxt.facets().create(i++, df, managedDv);
        }
    }
    if (inputLevelList != null) {
        ctxt.fieldTypeInputLevels().deleteFacetsFor(managedDv);
        for (DataverseFieldTypeInputLevel obj : inputLevelList) {
            obj.setDataverse(managedDv);
            ctxt.fieldTypeInputLevels().create(obj);
        }
    }
    return managedDv;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Timestamp(java.sql.Timestamp) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) Date(java.util.Date) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)25 Dataset (edu.harvard.iq.dataverse.Dataset)6 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)6 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)6 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)6 Timestamp (java.sql.Timestamp)6 Date (java.util.Date)6 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)4 ConstraintViolation (javax.validation.ConstraintViolation)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)3 DatasetField (edu.harvard.iq.dataverse.DatasetField)2 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)2 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)2 CreateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand)2 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)2