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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations