use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManagePermissionsPage method saveConfiguration.
public void saveConfiguration(ActionEvent e) {
// Set role (if any) for authenticatedUsers
DataverseRole roleToAssign = null;
List<String> contributorRoles = Arrays.asList(DataverseRole.FULL_CONTRIBUTOR, DataverseRole.DV_CONTRIBUTOR, DataverseRole.DS_CONTRIBUTOR);
if (!StringUtil.isEmpty(authenticatedUsersContributorRoleAlias)) {
roleToAssign = roleService.findBuiltinRoleByAlias(authenticatedUsersContributorRoleAlias);
}
// then, check current contributor role
List<RoleAssignment> aUsersRoleAssignments = roleService.directRoleAssignments(AuthenticatedUsers.get(), dvObject);
for (RoleAssignment roleAssignment : aUsersRoleAssignments) {
DataverseRole currentRole = roleAssignment.getRole();
if (contributorRoles.contains(currentRole.getAlias())) {
if (currentRole.equals(roleToAssign)) {
// found the role, so no need to assign
roleToAssign = null;
} else {
revokeRole(roleAssignment);
}
}
}
// finally, assign role, if new
if (roleToAssign != null) {
assignRole(AuthenticatedUsers.get(), roleToAssign);
}
// set dataverse default contributor role
if (dvObject instanceof Dataverse) {
Dataverse dv = (Dataverse) dvObject;
DataverseRole defaultRole = roleService.findBuiltinRoleByAlias(defaultContributorRoleAlias);
if (!defaultRole.equals(dv.getDefaultContributorRole())) {
try {
commandEngine.submit(new UpdateDataverseDefaultContributorRoleCommand(defaultRole, dvRequestService.getDataverseRequest(), dv));
JsfHelper.addSuccessMessage("The default permissions for this dataverse have been updated.");
} catch (PermissionException ex) {
JH.addMessage(FacesMessage.SEVERITY_ERROR, "Cannot assign default permissions.", "Permissions " + ex.getRequiredPermissions().toString() + " missing.");
} catch (CommandException ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "Cannot assign default permissions.");
logger.log(Level.SEVERE, "Error assigning default permissions: " + ex.getMessage(), ex);
}
}
}
roleAssignments = initRoleAssignments();
showConfigureMessages();
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class ManageTemplatesPage method deleteTemplate.
public void deleteTemplate() {
List<Dataverse> dataverseWDefaultTemplate = null;
if (selectedTemplate != null) {
templates.remove(selectedTemplate);
if (dataverse.getDefaultTemplate() != null && dataverse.getDefaultTemplate().equals(selectedTemplate)) {
dataverse.setDefaultTemplate(null);
}
dataverse.getTemplates().remove(selectedTemplate);
dataverseWDefaultTemplate = templateService.findDataversesByDefaultTemplateId(selectedTemplate.getId());
} else {
System.out.print("selected template is null");
}
try {
engineService.submit(new DeleteTemplateCommand(dvRequestService.getDataverseRequest(), getDataverse(), selectedTemplate, dataverseWDefaultTemplate));
JsfHelper.addFlashMessage("The template has been deleted");
} catch (CommandException ex) {
String failMessage = "The dataset template cannot be deleted.";
JH.addMessage(FacesMessage.SEVERITY_FATAL, failMessage);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class WorkflowServiceBean method rollback.
@Asynchronous
private void rollback(Workflow wf, WorkflowContext ctxt, Failure failure, int lastCompletedStepIdx) {
ctxt = refresh(ctxt);
final List<WorkflowStepData> steps = wf.getSteps();
for (int stepIdx = lastCompletedStepIdx; stepIdx >= 0; --stepIdx) {
WorkflowStepData wsd = steps.get(stepIdx);
WorkflowStep step = createStep(wsd);
try {
logger.log(Level.INFO, "Workflow {0} step {1}: Rollback", new Object[] { ctxt.getInvocationId(), stepIdx });
rollbackStep(step, ctxt, failure);
} catch (Exception e) {
logger.log(Level.WARNING, "Workflow " + ctxt.getInvocationId() + " step " + stepIdx + ": Rollback error: " + e.getMessage(), e);
}
}
logger.log(Level.INFO, "Removing workflow lock");
try {
engine.submit(new RemoveLockCommand(ctxt.getRequest(), ctxt.getDataset(), DatasetLock.Reason.Workflow));
// Corner case - delete locks generated within this same transaction.
Query deleteQuery = em.createQuery("DELETE from DatasetLock l WHERE l.dataset.id=:id AND l.reason=:reason");
deleteQuery.setParameter("id", ctxt.getDataset().getId());
deleteQuery.setParameter("reason", DatasetLock.Reason.Workflow);
deleteQuery.executeUpdate();
} catch (CommandException ex) {
logger.log(Level.SEVERE, "Error restoring dataset locks state after rollback: " + ex.getMessage(), ex);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class AddReplaceFileHelper method step_070_run_update_dataset_command.
/**
* Create and run the update dataset command
*
* @return
*/
private boolean step_070_run_update_dataset_command() {
if (this.hasError()) {
return false;
}
Command<Dataset> update_cmd;
update_cmd = new UpdateDatasetCommand(dataset, dvRequest);
((UpdateDatasetCommand) update_cmd).setValidateLenient(true);
try {
// Submit the update dataset command
// and update the local dataset object
//
dataset = commandEngine.submit(update_cmd);
} catch (CommandException ex) {
/**
* @todo Add a test to exercise this error.
*/
this.addErrorSevere(getBundleErr("add.add_file_error"));
logger.severe(ex.getMessage());
return false;
} catch (EJBException ex) {
/**
* @todo Add a test to exercise this error.
*/
this.addErrorSevere("add.add_file_error (see logs)");
logger.severe(ex.getMessage());
return false;
}
return true;
}
use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.
the class DestroyDatasetCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
// first check if dataset is released, and if so, if user is a superuser
if (doomed.isReleased() && (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) {
throw new PermissionException("Destroy can only be called by superusers.", this, Collections.singleton(Permission.DeleteDatasetDraft), doomed);
}
// If there is a dedicated thumbnail DataFile, it needs to be reset
// explicitly, or we'll get a constraint violation when deleting:
doomed.setThumbnailFile(null);
final Dataset managedDoomed = ctxt.em().merge(doomed);
List<String> datasetAndFileSolrIdsToDelete = new ArrayList<>();
// files need to iterate through and remove 'by hand' to avoid
// optimistic lock issues... (plus the physical files need to be
// deleted too!)
Iterator<DataFile> dfIt = doomed.getFiles().iterator();
while (dfIt.hasNext()) {
DataFile df = dfIt.next();
// Gather potential Solr IDs of files. As of this writing deaccessioned files are never indexed.
String solrIdOfPublishedFile = IndexServiceBean.solrDocIdentifierFile + df.getId();
datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedFile);
String solrIdOfDraftFile = IndexServiceBean.solrDocIdentifierFile + df.getId() + IndexServiceBean.draftSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDraftFile);
ctxt.engine().submit(new DeleteDataFileCommand(df, getRequest(), true));
dfIt.remove();
}
// also, lets delete the uploaded thumbnails!
deleteDatasetLogo(doomed);
// 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);
}
IdServiceBean idServiceBean = IdServiceBean.getBean(ctxt);
try {
if (idServiceBean.alreadyExists(doomed)) {
idServiceBean.deleteIdentifier(doomed);
}
} catch (Exception e) {
logger.log(Level.WARNING, "Identifier deletion was not successfull:", e.getMessage());
}
Dataverse toReIndex = managedDoomed.getOwner();
// dataset
ctxt.em().remove(managedDoomed);
// add potential Solr IDs of datasets to list for deletion
String solrIdOfPublishedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId();
datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedDatasetVersion);
String solrIdOfDraftDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.draftSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDraftDatasetVersion);
String solrIdOfDeaccessionedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.deaccessionedSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDeaccessionedDatasetVersion);
IndexResponse resultOfSolrDeletionAttempt = ctxt.solrIndex().deleteMultipleSolrIds(datasetAndFileSolrIdsToDelete);
logger.log(Level.FINE, "Result of attempt to delete dataset and file IDs from the search index: {0}", resultOfSolrDeletionAttempt.getMessage());
ctxt.index().indexDataverse(toReIndex);
}
Aggregations