use of edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand in project dataverse by IQSS.
the class DataversePage method releaseDataverse.
public String releaseDataverse() {
if (session.getUser() instanceof AuthenticatedUser) {
PublishDataverseCommand cmd = new PublishDataverseCommand(dvRequestService.getDataverseRequest(), dataverse);
try {
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("dataverse.publish.success"));
} catch (Exception ex) {
logger.log(Level.SEVERE, "Unexpected Exception calling publish dataverse command", ex);
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataverse.publish.failure"));
}
} else {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataverse.publish.not.authorized"));
}
return returnRedirect();
}
use of edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand in project dataverse by IQSS.
the class DatasetPage method releaseParentDV.
private void releaseParentDV() {
if (session.getUser() instanceof AuthenticatedUser) {
PublishDataverseCommand cmd = new PublishDataverseCommand(dvRequestService.getDataverseRequest(), dataset.getOwner());
try {
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(JH.localize("dataverse.publish.success"));
} catch (CommandException ex) {
logger.log(Level.SEVERE, "Unexpected Exception calling publish dataverse command", ex);
JsfHelper.addErrorMessage(JH.localize("dataverse.publish.failure"));
}
} else {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "DataverseNotReleased", "Only authenticated users can release a dataverse.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand in project dataverse by IQSS.
the class ContainerManagerImpl method useHeaders.
@Override
public DepositReceipt useHeaders(String uri, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
logger.fine("uri was " + uri);
logger.fine("isInProgress:" + deposit.isInProgress());
AuthenticatedUser user = swordAuth.auth(authCredentials);
DataverseRequest dvRequest = new DataverseRequest(user, httpRequest);
urlManager.processUrl(uri);
String targetType = urlManager.getTargetType();
if (!targetType.isEmpty()) {
logger.fine("operating on target type: " + urlManager.getTargetType());
if ("study".equals(targetType)) {
String globalId = urlManager.getTargetIdentifier();
if (globalId != null) {
Dataset dataset = null;
try {
dataset = datasetService.findByGlobalId(globalId);
} catch (EJBException ex) {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataset based on global id (" + globalId + ") in URL: " + uri);
}
if (dataset != null) {
Dataverse dvThatOwnsDataset = dataset.getOwner();
boolean doMinorVersionBump = false;
// if dataset is unreleased, major version; if released, then check if can be minor
if (dataset.isReleased() && dataset.getLatestVersion().isMinorUpdate()) {
doMinorVersionBump = true;
}
PublishDatasetCommand publishDatasetCommand = new PublishDatasetCommand(dataset, dvRequest, doMinorVersionBump);
if (!permissionService.isUserAllowedOn(user, publishDatasetCommand, dataset)) {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "User " + user.getDisplayInfo().getTitle() + " is not authorized to modify dataverse " + dvThatOwnsDataset.getAlias());
}
if (!deposit.isInProgress()) {
/**
* We are considering a draft version of a study to
* be incomplete and are saying that sending
* isInProgress=false means the study version is
* complete and can be released.
*
* 9.2. Deposit Incomplete
*
* "If In-Progress is true, the server SHOULD expect
* the client to provide further updates to the item
* some undetermined time in the future. Details of
* how this is implemented is dependent on the
* server's purpose. For example, a repository
* system may hold items which are marked
* In-Progress in a workspace until such time as a
* client request indicates that the deposit is
* complete." --
* http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#continueddeposit_incomplete
*/
if (!dataset.getLatestVersion().getVersionState().equals(DatasetVersion.VersionState.RELEASED)) {
try {
dataset = engineSvc.submit(publishDatasetCommand).getDataset();
} catch (CommandException ex) {
String msg = "Unable to publish dataset: " + ex;
logger.severe(msg + ": " + ex.getMessage());
throw SwordUtil.throwRegularSwordErrorWithoutStackTrace(msg);
}
ReceiptGenerator receiptGenerator = new ReceiptGenerator();
String baseUrl = urlManager.getHostnamePlusBaseUrlPath(uri);
DepositReceipt depositReceipt = receiptGenerator.createDatasetReceipt(baseUrl, dataset);
return depositReceipt;
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Latest version of dataset " + globalId + " has already been published.");
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Pass 'In-Progress: false' header to publish a dataset.");
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataset using globalId " + globalId);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to find globalId for dataset in URL:" + uri);
}
} else if ("dataverse".equals(targetType)) {
String dvAlias = urlManager.getTargetIdentifier();
if (dvAlias != null) {
Dataverse dvToRelease = dataverseService.findByAlias(dvAlias);
if (dvToRelease != null) {
PublishDataverseCommand publishDataverseCommand = new PublishDataverseCommand(dvRequest, dvToRelease);
if (!permissionService.isUserAllowedOn(user, publishDataverseCommand, dvToRelease)) {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "User " + user.getDisplayInfo().getTitle() + " is not authorized to modify dataverse " + dvAlias);
}
if (deposit.isInProgress()) {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unpublishing a dataverse is not supported.");
}
try {
engineSvc.submit(publishDataverseCommand);
ReceiptGenerator receiptGenerator = new ReceiptGenerator();
String baseUrl = urlManager.getHostnamePlusBaseUrlPath(uri);
DepositReceipt depositReceipt = receiptGenerator.createDataverseReceipt(baseUrl, dvToRelease);
return depositReceipt;
} catch (CommandException ex) {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Couldn't publish dataverse " + dvAlias + ": " + ex);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataverse based on alias in URL: " + uri);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to find dataverse alias in URL: " + uri);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unsupported target type (" + targetType + ") in URL:" + uri);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Target type missing from URL: " + uri);
}
}
Aggregations