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