use of edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand in project dataverse by IQSS.
the class DatasetPage method init.
private String init(boolean initFull) {
// System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
this.maxFileUploadSizeInBytes = systemConfig.getMaxFileUploadSize();
setDataverseSiteUrl(systemConfig.getDataverseSiteUrl());
guestbookResponse = new GuestbookResponse();
String nonNullDefaultIfKeyNotFound = "";
protocol = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
authority = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
separator = settingsWrapper.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound);
if (dataset.getId() != null || versionId != null || persistentId != null) {
// view mode for a dataset
DatasetVersionServiceBean.RetrieveDatasetVersionResponse retrieveDatasetVersionResponse = null;
// ---------------------------------------
if (persistentId != null) {
logger.fine("initializing DatasetPage with persistent ID " + persistentId);
// Set Working Version and Dataset by PersistentID
dataset = datasetService.findByGlobalId(persistentId);
if (dataset == null) {
logger.warning("No such dataset: " + persistentId);
return permissionsWrapper.notFound();
}
logger.fine("retrieved dataset, id=" + dataset.getId());
retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
// retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionByPersistentId(persistentId, version);
this.workingVersion = retrieveDatasetVersionResponse.getDatasetVersion();
logger.fine("retrieved version: id: " + workingVersion.getId() + ", state: " + this.workingVersion.getVersionState());
} else if (dataset.getId() != null) {
// Set Working Version and Dataset by Datasaet Id and Version
dataset = datasetService.find(dataset.getId());
if (dataset == null) {
logger.warning("No such dataset: " + dataset);
return permissionsWrapper.notFound();
}
// retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionById(dataset.getId(), version);
retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
this.workingVersion = retrieveDatasetVersionResponse.getDatasetVersion();
logger.info("retreived version: id: " + workingVersion.getId() + ", state: " + this.workingVersion.getVersionState());
} else if (versionId != null) {
// TODO: 4.2.1 - this method is broken as of now!
// Set Working Version and Dataset by DatasaetVersion Id
// retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionByVersionId(versionId);
}
if (retrieveDatasetVersionResponse == null) {
return permissionsWrapper.notFound();
}
//
if (workingVersion == null || this.dataset == null) {
return permissionsWrapper.notFound();
}
// Is the Dataset harvested?
if (dataset.isHarvested()) {
// if so, we'll simply forward to the remote URL for the original
// source of this harvested dataset:
String originalSourceURL = dataset.getRemoteArchiveURL();
if (originalSourceURL != null && !originalSourceURL.equals("")) {
logger.fine("redirecting to " + originalSourceURL);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(originalSourceURL);
} catch (IOException ioex) {
// must be a bad URL...
// we don't need to do anything special here - we'll redirect
// to the local 404 page, below.
logger.warning("failed to issue a redirect to " + originalSourceURL);
}
return originalSourceURL;
}
return permissionsWrapper.notFound();
}
// Check permisisons
if (!(workingVersion.isReleased() || workingVersion.isDeaccessioned()) && !this.canViewUnpublishedDataset()) {
return permissionsWrapper.notAuthorized();
}
if (!retrieveDatasetVersionResponse.wasRequestedVersionRetrieved()) {
// msg("checkit " + retrieveDatasetVersionResponse.getDifferentVersionMessage());
// JH.localize("dataset.message.metadataSuccess"));
JsfHelper.addWarningMessage(retrieveDatasetVersionResponse.getDifferentVersionMessage());
}
// init the citation
displayCitation = dataset.getCitation(true, workingVersion);
if (initFull) {
// init the list of FileMetadatas
if (workingVersion.isDraft() && canUpdateDataset()) {
readOnly = false;
} else {
// an attempt to retreive both the filemetadatas and datafiles early on, so that
// we don't have to do so later (possibly, many more times than necessary):
datafileService.findFileMetadataOptimizedExperimental(dataset);
}
fileMetadatasSearch = workingVersion.getFileMetadatasSorted();
ownerId = dataset.getOwner().getId();
datasetNextMajorVersion = this.dataset.getNextMajorVersionString();
datasetNextMinorVersion = this.dataset.getNextMinorVersionString();
datasetVersionUI = datasetVersionUI.initDatasetVersionUI(workingVersion, false);
updateDatasetFieldInputLevels();
setExistReleasedVersion(resetExistRealeaseVersion());
// moving setVersionTabList to tab change event
// setVersionTabList(resetVersionTabList());
// setReleasedVersionTabList(resetReleasedVersionTabList());
// SEK - lazymodel may be needed for datascroller in future release
// lazyModel = new LazyFileMetadataDataModel(workingVersion.getId(), datafileService );
// populate MapLayerMetadata
// A DataFile may have a related MapLayerMetadata object
this.loadMapLayerMetadataLookup();
this.guestbookResponse = guestbookResponseService.initGuestbookResponseForFragment(dataset, null, session);
this.getFileDownloadHelper().setGuestbookResponse(guestbookResponse);
logger.fine("Checking if rsync support is enabled.");
if (DataCaptureModuleUtil.rsyncSupportEnabled(settingsWrapper.getValueForKey(SettingsServiceBean.Key.UploadMethods))) {
try {
ScriptRequestResponse scriptRequestResponse = commandEngine.submit(new RequestRsyncScriptCommand(dvRequestService.getDataverseRequest(), dataset));
logger.fine("script: " + scriptRequestResponse.getScript());
if (scriptRequestResponse.getScript() != null && !scriptRequestResponse.getScript().isEmpty()) {
setHasRsyncScript(true);
setRsyncScript(scriptRequestResponse.getScript());
rsyncScriptFilename = "upload-" + workingVersion.getDataset().getIdentifier() + ".bash";
} else {
setHasRsyncScript(false);
}
} catch (RuntimeException ex) {
logger.warning("Problem getting rsync script: " + ex.getLocalizedMessage());
} catch (CommandException cex) {
logger.warning("Problem getting rsync script (Command Exception): " + cex.getLocalizedMessage());
}
}
}
} else if (ownerId != null) {
// create mode for a new child dataset
readOnly = false;
editMode = EditMode.CREATE;
dataset.setOwner(dataverseService.find(ownerId));
dataset.setProtocol(protocol);
dataset.setAuthority(authority);
dataset.setDoiSeparator(separator);
if (dataset.getOwner() == null) {
return permissionsWrapper.notFound();
} else if (!permissionService.on(dataset.getOwner()).has(Permission.AddDataset)) {
return permissionsWrapper.notAuthorized();
}
dataverseTemplates = dataverseService.find(ownerId).getTemplates();
if (!dataverseService.find(ownerId).isTemplateRoot()) {
dataverseTemplates.addAll(dataverseService.find(ownerId).getParentTemplates());
}
defaultTemplate = dataverseService.find(ownerId).getDefaultTemplate();
if (defaultTemplate != null) {
selectedTemplate = defaultTemplate;
for (Template testT : dataverseTemplates) {
if (defaultTemplate.getId().equals(testT.getId())) {
selectedTemplate = testT;
}
}
workingVersion = dataset.getEditVersion(selectedTemplate);
updateDatasetFieldInputLevels();
} else {
workingVersion = dataset.getCreateVersion();
updateDatasetFieldInputLevels();
}
if (settingsWrapper.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false)) {
JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.message.publicInstall"));
}
resetVersionUI();
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Add New Dataset", " - Enter metadata to create the dataset's citation. You can add more metadata about this dataset after it's created."));
} else {
return permissionsWrapper.notFound();
}
try {
privateUrl = commandEngine.submit(new GetPrivateUrlCommand(dvRequestService.getDataverseRequest(), dataset));
if (privateUrl != null) {
JH.addMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.privateurl.infoMessageAuthor", Arrays.asList(getPrivateUrlLink(privateUrl))));
}
} catch (CommandException ex) {
// No big deal. The user simply doesn't have access to create or delete a Private URL.
}
if (session.getUser() instanceof PrivateUrlUser) {
PrivateUrlUser privateUrlUser = (PrivateUrlUser) session.getUser();
if (dataset != null && dataset.getId().equals(privateUrlUser.getDatasetId())) {
JH.addMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.privateurl.infoMessageReviewer"));
}
}
// Various info messages, when the dataset is locked (for various reasons):
if (dataset.isLocked()) {
if (dataset.isLockedFor(DatasetLock.Reason.Workflow)) {
JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.locked.message"), BundleUtil.getStringFromBundle("dataset.publish.workflow.inprogress"));
}
if (dataset.isLockedFor(DatasetLock.Reason.InReview)) {
JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.locked.inReview.message"), BundleUtil.getStringFromBundle("dataset.inreview.infoMessage"));
}
if (dataset.isLockedFor(DatasetLock.Reason.DcmUpload)) {
JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("file.rsyncUpload.inProgressMessage.summary"), BundleUtil.getStringFromBundle("file.rsyncUpload.inProgressMessage.details"));
}
}
configureTools = externalToolService.findByType(ExternalTool.Type.CONFIGURE);
exploreTools = externalToolService.findByType(ExternalTool.Type.EXPLORE);
return null;
}
use of edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand in project dataverse by IQSS.
the class Datasets method deletePrivateUrl.
@DELETE
@Path("{id}/privateUrl")
public Response deletePrivateUrl(@PathParam("id") String idSupplied) {
return response(req -> {
Dataset dataset = findDatasetOrDie(idSupplied);
PrivateUrl privateUrl = execCommand(new GetPrivateUrlCommand(req, dataset));
if (privateUrl != null) {
execCommand(new DeletePrivateUrlCommand(req, dataset));
return ok("Private URL deleted.");
} else {
return notFound("No Private URL to delete.");
}
});
}
Aggregations