use of edu.harvard.iq.dataverse.RoleAssignment 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);
}
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class PublishDataverseCommand method execute.
@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
if (dataverse.isReleased()) {
throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " has already been published.", this);
}
Dataverse parent = dataverse.getOwner();
// root dataverse doesn't have a parent
if (parent != null) {
if (!parent.isReleased()) {
throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " may not be published because its host dataverse (" + parent.getAlias() + ") has not been published.", this);
}
}
// Before setting dataverse to released send notifications to users with download file
List<RoleAssignment> ras = ctxt.roles().directRoleAssignments(dataverse);
for (RoleAssignment ra : ras) {
if (ra.getRole().permissions().contains(Permission.DownloadFile)) {
for (AuthenticatedUser au : ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier()))) {
ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.ASSIGNROLE, dataverse.getId());
}
}
}
dataverse.setPublicationDate(new Timestamp(new Date().getTime()));
dataverse.setReleaseUser((AuthenticatedUser) getUser());
Dataverse savedDataverse = ctxt.dataverses().save(dataverse);
/**
* @todo consider also
* ctxt.solrIndex().indexPermissionsOnSelfAndChildren(savedDataverse.getId());
*/
/**
* @todo what should we do with the indexRespose?
*/
IndexResponse indexResponse = ctxt.solrIndex().indexPermissionsForOneDvObject(savedDataverse);
return savedDataverse;
}
use of edu.harvard.iq.dataverse.RoleAssignment 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;
}
Aggregations