use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetPage method downloadRsyncScript.
/*
public String getThumbnail() {
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail();
if (datasetThumbnail != null) {
return datasetThumbnail.getBase64image();
} else {
return null;
}
}*/
public void downloadRsyncScript() {
String bibFormatDowload = new BibtexCitation(workingVersion).toString();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("application/download");
String contentDispositionString;
contentDispositionString = "attachment;filename=" + rsyncScriptFilename;
response.setHeader("Content-Disposition", contentDispositionString);
try {
ServletOutputStream out = response.getOutputStream();
out.write(getRsyncScript().getBytes());
out.flush();
ctx.responseComplete();
} catch (IOException e) {
String error = "Problem getting bytes from rsync script: " + e;
logger.warning(error);
return;
}
// If the script has been successfully downloaded, lock the dataset:
String lockInfoMessage = "script downloaded";
DatasetLock lock = datasetService.addDatasetLock(dataset.getId(), DatasetLock.Reason.DcmUpload, session.getUser() != null ? ((AuthenticatedUser) session.getUser()).getId() : null, lockInfoMessage);
if (lock != null) {
dataset.addLock(lock);
} else {
logger.log(Level.WARNING, "Failed to lock the dataset (dataset id={0})", dataset.getId());
}
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetPage method save.
public String save() {
// Validate
Set<ConstraintViolation> constraintViolations = workingVersion.validate();
if (!constraintViolations.isEmpty()) {
// JsfHelper.addFlashMessage(JH.localize("dataset.message.validationError"));
JH.addMessage(FacesMessage.SEVERITY_ERROR, JH.localize("dataset.message.validationError"));
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", "See below for details."));
return "";
}
// Use the API to save the dataset:
Command<Dataset> cmd;
try {
if (editMode == EditMode.CREATE) {
if (selectedTemplate != null) {
if (isSessionUserAuthenticated()) {
cmd = new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), false, null, selectedTemplate);
} else {
JH.addMessage(FacesMessage.SEVERITY_FATAL, JH.localize("dataset.create.authenticatedUsersOnly"));
return null;
}
} else {
cmd = new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest());
}
} else {
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
((UpdateDatasetCommand) cmd).setValidateLenient(true);
}
dataset = commandEngine.submit(cmd);
if (editMode == EditMode.CREATE) {
if (session.getUser() instanceof AuthenticatedUser) {
userNotificationService.sendNotification((AuthenticatedUser) session.getUser(), dataset.getCreateDate(), UserNotification.Type.CREATEDS, dataset.getLatestVersion().getId());
}
}
logger.fine("Successfully executed SaveDatasetCommand.");
} catch (EJBException ex) {
StringBuilder error = new StringBuilder();
error.append(ex).append(" ");
error.append(ex.getMessage()).append(" ");
Throwable cause = ex;
while (cause.getCause() != null) {
cause = cause.getCause();
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
logger.log(Level.FINE, "Couldn''t save dataset: {0}", error.toString());
populateDatasetUpdateFailureMessage();
return returnToDraftVersion();
} catch (CommandException ex) {
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
logger.severe("CommandException, when attempting to update the dataset: " + ex.getMessage());
populateDatasetUpdateFailureMessage();
return returnToDraftVersion();
}
newFiles.clear();
if (editMode != null) {
if (editMode.equals(EditMode.CREATE)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.createSuccess"));
}
if (editMode.equals(EditMode.METADATA)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.metadataSuccess"));
}
if (editMode.equals(EditMode.LICENSE)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.termsSuccess"));
}
if (editMode.equals(EditMode.FILE)) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.filesSuccess"));
}
} else {
// must have been a bulk file update or delete:
if (bulkFileDeleteInProgress) {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.bulkFileDeleteSuccess"));
} else {
JsfHelper.addSuccessMessage(JH.localize("dataset.message.bulkFileUpdateSuccess"));
}
}
editMode = null;
bulkFileDeleteInProgress = false;
// Call Ingest Service one more time, to
// queue the data ingest jobs for asynchronous execution:
ingestService.startIngestJobs(dataset, (AuthenticatedUser) session.getUser());
logger.fine("Redirecting to the Dataset page.");
return returnToDraftVersion();
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetServiceBean method getDatasetVersionUser.
public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
DatasetVersionUser ddu = null;
Query query = em.createQuery("select object(o) from DatasetVersionUser as o " + "where o.datasetVersion.id =:versionId and o.authenticatedUser.id =:userId");
query.setParameter("versionId", version.getId());
String identifier = user.getIdentifier();
identifier = identifier.startsWith("@") ? identifier.substring(1) : identifier;
AuthenticatedUser au = authentication.getAuthenticatedUser(identifier);
query.setParameter("userId", au.getId());
try {
ddu = (DatasetVersionUser) query.getSingleResult();
} catch (javax.persistence.NoResultException e) {
// DO nothing, just return null.
}
return ddu;
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetServiceBean method addDatasetLock.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public /*?*/
DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Long userId, String info) {
Dataset dataset = em.find(Dataset.class, datasetId);
AuthenticatedUser user = null;
if (userId != null) {
user = em.find(AuthenticatedUser.class, userId);
}
DatasetLock lock = new DatasetLock(reason, user);
lock.setDataset(dataset);
lock.setInfo(info);
lock.setStartTime(new Date());
if (userId != null) {
lock.setUser(user);
if (user.getDatasetLocks() == null) {
user.setDatasetLocks(new ArrayList<>());
}
user.getDatasetLocks().add(lock);
}
return addDatasetLock(dataset, lock);
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetServiceBean method removeDatasetLocks.
/**
* Removes all {@link DatasetLock}s for the dataset whose id is passed and reason
* is {@code aReason}.
* @param datasetId Id of the dataset whose locks will b removed.
* @param aReason The reason of the locks that will be removed.
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
Dataset dataset = em.find(Dataset.class, datasetId);
new HashSet<>(dataset.getLocks()).stream().filter(l -> l.getReason() == aReason).forEach(lock -> {
dataset.removeLock(lock);
AuthenticatedUser user = lock.getUser();
user.getDatasetLocks().remove(lock);
em.remove(lock);
});
}
Aggregations