use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class ReturnDatasetToAuthorCommand method save.
public Dataset save(CommandContext ctxt) throws CommandException {
Timestamp updateTime = new Timestamp(new Date().getTime());
theDataset.getEditVersion().setLastUpdateTime(updateTime);
// We set "in review" to false because now the ball is back in the author's court.
theDataset.setModificationTime(updateTime);
// TODO: ctxt.datasets().removeDatasetLocks() doesn't work. Try RemoveLockCommand?
AuthenticatedUser authenticatedUser = null;
for (DatasetLock lock : theDataset.getLocks()) {
if (DatasetLock.Reason.InReview.equals(lock.getReason())) {
theDataset.removeLock(lock);
// TODO: Are we supposed to remove the dataset lock from the user? What's going on here?
authenticatedUser = lock.getUser();
}
}
Dataset savedDataset = ctxt.em().merge(theDataset);
ctxt.em().flush();
DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(theDataset.getLatestVersion(), this.getUser());
WorkflowComment workflowComment = new WorkflowComment(theDataset.getEditVersion(), WorkflowComment.Type.RETURN_TO_AUTHOR, comment, (AuthenticatedUser) this.getUser());
ctxt.datasets().addWorkflowComment(workflowComment);
if (ddu != null) {
ddu.setLastUpdateDate(updateTime);
ctxt.em().merge(ddu);
} else {
// TODO: This logic to update the DatasetVersionUser was copied from UpdateDatasetCommand and also appears in CreateDatasetCommand, PublishDatasetCommand UpdateDatasetCommand, and SubmitDatasetForReviewCommand. Consider consolidating.
DatasetVersionUser datasetDataverseUser = new DatasetVersionUser();
datasetDataverseUser.setDatasetVersion(savedDataset.getLatestVersion());
datasetDataverseUser.setLastUpdateDate(updateTime);
String id = getUser().getIdentifier();
id = id.startsWith("@") ? id.substring(1) : id;
AuthenticatedUser au = ctxt.authentication().getAuthenticatedUser(id);
datasetDataverseUser.setAuthenticatedUser(au);
ctxt.em().merge(datasetDataverseUser);
}
/*
So what we're doing here is sending notifications to the authors who do not have publish permissions
First get users who can publish - or in this case review
Then get authors.
Then remove reviewers from the autors list
Finally send a notification to the remaining (non-reviewing) authors - Hey! your dataset was rejected.
*/
List<AuthenticatedUser> reviewers = ctxt.permissions().getUsersWithPermissionOn(Permission.PublishDataset, savedDataset);
List<AuthenticatedUser> authors = ctxt.permissions().getUsersWithPermissionOn(Permission.EditDataset, savedDataset);
for (AuthenticatedUser au : reviewers) {
authors.remove(au);
}
for (AuthenticatedUser au : authors) {
ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.RETURNEDDS, savedDataset.getLatestVersion().getId(), comment);
}
// TODO: What should we do with the indexing result? Print it to the log?
boolean doNormalSolrDocCleanUp = true;
Future<String> indexingResult = ctxt.index().indexDataset(savedDataset, doNormalSolrDocCleanUp);
return savedDataset;
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser 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.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DataversePage method save.
public String save() {
List<DataverseFieldTypeInputLevel> listDFTIL = new ArrayList<>();
if (editMode != null && editMode.equals(EditMode.INFO)) {
List<MetadataBlock> selectedBlocks = new ArrayList<>();
if (dataverse.isMetadataBlockRoot()) {
dataverse.getMetadataBlocks().clear();
}
for (MetadataBlock mdb : this.allMetadataBlocks) {
if (dataverse.isMetadataBlockRoot() && (mdb.isSelected() || mdb.isRequired())) {
selectedBlocks.add(mdb);
for (DatasetFieldType dsft : mdb.getDatasetFieldTypes()) {
if (dsft.isRequiredDV() && !dsft.isRequired() && ((!dsft.isHasParent() && dsft.isInclude()) || (dsft.isHasParent() && dsft.getParentDatasetFieldType().isInclude()))) {
DataverseFieldTypeInputLevel dftil = new DataverseFieldTypeInputLevel();
dftil.setDatasetFieldType(dsft);
dftil.setDataverse(dataverse);
dftil.setRequired(true);
dftil.setInclude(true);
listDFTIL.add(dftil);
}
if ((!dsft.isHasParent() && !dsft.isInclude()) || (dsft.isHasParent() && !dsft.getParentDatasetFieldType().isInclude())) {
DataverseFieldTypeInputLevel dftil = new DataverseFieldTypeInputLevel();
dftil.setDatasetFieldType(dsft);
dftil.setDataverse(dataverse);
dftil.setRequired(false);
dftil.setInclude(false);
listDFTIL.add(dftil);
}
}
}
}
if (!selectedBlocks.isEmpty()) {
dataverse.setMetadataBlocks(selectedBlocks);
}
if (!dataverse.isFacetRoot()) {
facets.getTarget().clear();
}
}
Command<Dataverse> cmd = null;
// TODO change to Create - for now the page is expecting INFO instead.
Boolean create;
if (dataverse.getId() == null) {
if (session.getUser().isAuthenticated()) {
dataverse.setOwner(ownerId != null ? dataverseService.find(ownerId) : null);
create = Boolean.TRUE;
cmd = new CreateDataverseCommand(dataverse, dvRequestService.getDataverseRequest(), facets.getTarget(), listDFTIL);
} else {
JH.addMessage(FacesMessage.SEVERITY_FATAL, BundleUtil.getStringFromBundle("dataverse.create.authenticatedUsersOnly"));
return null;
}
} else {
create = Boolean.FALSE;
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
cmd = new UpdateDataverseCommand(dataverse, null, featuredDataverses.getTarget(), dvRequestService.getDataverseRequest(), null);
} else {
cmd = new UpdateDataverseCommand(dataverse, facets.getTarget(), null, dvRequestService.getDataverseRequest(), listDFTIL);
}
}
try {
dataverse = commandEngine.submit(cmd);
if (session.getUser() instanceof AuthenticatedUser) {
if (create) {
userNotificationService.sendNotification((AuthenticatedUser) session.getUser(), dataverse.getCreateDate(), Type.CREATEDV, dataverse.getId());
}
}
String message;
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
message = "The featured dataverses for this dataverse have been updated.";
} else {
message = (create) ? BundleUtil.getStringFromBundle("dataverse.create.success", Arrays.asList(settingsWrapper.getGuidesBaseUrl(), systemConfig.getGuidesVersion())) : BundleUtil.getStringFromBundle("dataverse.update.success");
}
JsfHelper.addSuccessMessage(message);
editMode = null;
return returnRedirect();
} catch (CommandException ex) {
logger.log(Level.SEVERE, "Unexpected Exception calling dataverse command", ex);
String errMsg = create ? BundleUtil.getStringFromBundle("dataverse.create.failure") : BundleUtil.getStringFromBundle("dataverse.update.failure");
JH.addMessage(FacesMessage.SEVERITY_FATAL, errMsg);
return null;
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected Exception calling dataverse command", e);
String errMsg = create ? BundleUtil.getStringFromBundle("dataverse.create.failure") : BundleUtil.getStringFromBundle("dataverse.update.failure");
JH.addMessage(FacesMessage.SEVERITY_FATAL, errMsg);
return null;
}
}
use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser 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.authorization.users.AuthenticatedUser in project dataverse by IQSS.
the class DatasetPage method resetVersionUI.
private void resetVersionUI() {
datasetVersionUI = datasetVersionUI.initDatasetVersionUI(workingVersion, true);
if (isSessionUserAuthenticated()) {
AuthenticatedUser au = (AuthenticatedUser) session.getUser();
// On create set pre-populated fields
for (DatasetField dsf : dataset.getEditVersion().getDatasetFields()) {
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.depositor) && dsf.isEmpty()) {
dsf.getDatasetFieldValues().get(0).setValue(au.getLastName() + ", " + au.getFirstName());
}
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.dateOfDeposit) && dsf.isEmpty()) {
dsf.getDatasetFieldValues().get(0).setValue(new SimpleDateFormat("yyyy-MM-dd").format(new Timestamp(new Date().getTime())));
}
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContact) && dsf.isEmpty()) {
for (DatasetFieldCompoundValue contactValue : dsf.getDatasetFieldCompoundValues()) {
for (DatasetField subField : contactValue.getChildDatasetFields()) {
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContactName)) {
subField.getDatasetFieldValues().get(0).setValue(au.getLastName() + ", " + au.getFirstName());
}
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContactAffiliation)) {
subField.getDatasetFieldValues().get(0).setValue(au.getAffiliation());
}
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContactEmail)) {
subField.getDatasetFieldValues().get(0).setValue(au.getEmail());
}
}
}
}
String creatorOrcidId = au.getOrcidId();
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.author) && dsf.isEmpty()) {
for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) {
for (DatasetField subField : authorValue.getChildDatasetFields()) {
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorName)) {
subField.getDatasetFieldValues().get(0).setValue(au.getLastName() + ", " + au.getFirstName());
}
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorAffiliation)) {
subField.getDatasetFieldValues().get(0).setValue(au.getAffiliation());
}
if (creatorOrcidId != null) {
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorIdValue)) {
subField.getDatasetFieldValues().get(0).setValue(creatorOrcidId);
}
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorIdType)) {
DatasetFieldType authorIdTypeDatasetField = fieldService.findByName(DatasetFieldConstant.authorIdType);
subField.setSingleControlledVocabularyValue(fieldService.findControlledVocabularyValueByDatasetFieldTypeAndStrValue(authorIdTypeDatasetField, "ORCID", true));
}
}
}
}
}
}
}
}
Aggregations