Search in sources :

Example 71 with AuthenticatedUser

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;
}
Also used : DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Date(java.util.Date)

Example 72 with AuthenticatedUser

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();
}
Also used : PublishDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) SearchException(edu.harvard.iq.dataverse.search.SearchException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) EJBException(javax.ejb.EJBException)

Example 73 with AuthenticatedUser

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;
    }
}
Also used : ArrayList(java.util.ArrayList) UpdateDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) CreateDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDataverseCommand) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) SearchException(edu.harvard.iq.dataverse.search.SearchException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) EJBException(javax.ejb.EJBException)

Example 74 with AuthenticatedUser

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);
    }
}
Also used : PublishDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) FacesMessage(javax.faces.application.FacesMessage)

Example 75 with AuthenticatedUser

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));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)125 Dataverse (edu.harvard.iq.dataverse.Dataverse)24 Timestamp (java.sql.Timestamp)24 Date (java.util.Date)24 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 Dataset (edu.harvard.iq.dataverse.Dataset)22 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)21 Path (javax.ws.rs.Path)19 EJBException (javax.ejb.EJBException)16 ArrayList (java.util.ArrayList)14 User (edu.harvard.iq.dataverse.authorization.users.User)13 DataFile (edu.harvard.iq.dataverse.DataFile)11 IOException (java.io.IOException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 POST (javax.ws.rs.POST)11 Test (org.junit.Test)11 BuiltinUser (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser)10 SwordError (org.swordapp.server.SwordError)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)8 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)8