Search in sources :

Example 31 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class FinalizeDatasetPublicationCommand method notifyUsersDatasetPublish.

private void notifyUsersDatasetPublish(CommandContext ctxt, DvObject subject) {
    Timestamp timestamp = new Timestamp(new Date().getTime());
    ctxt.roles().rolesAssignments(subject).stream().filter(ra -> ra.getRole().permissions().contains(Permission.ViewUnpublishedDataset) || ra.getRole().permissions().contains(Permission.DownloadFile)).flatMap(ra -> ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier())).stream()).distinct().forEach(au -> ctxt.notifications().sendNotification(au, timestamp, UserNotification.Type.PUBLISHEDDS, theDataset.getLatestVersion().getId()));
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) DatasetFieldConstant(edu.harvard.iq.dataverse.DatasetFieldConstant) Date(java.util.Date) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) TriggerType(edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) CommandContext(edu.harvard.iq.dataverse.engine.command.CommandContext) Level(java.util.logging.Level) ExportException(edu.harvard.iq.dataverse.export.ExportException) Permission(edu.harvard.iq.dataverse.authorization.Permission) BundleUtil(edu.harvard.iq.dataverse.util.BundleUtil) DvObject(edu.harvard.iq.dataverse.DvObject) DatasetField(edu.harvard.iq.dataverse.DatasetField) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Dataverse(edu.harvard.iq.dataverse.Dataverse) RequiredPermissions(edu.harvard.iq.dataverse.engine.command.RequiredPermissions) ExportService(edu.harvard.iq.dataverse.export.ExportService) Timestamp(java.sql.Timestamp) Dataset(edu.harvard.iq.dataverse.Dataset) DataFile(edu.harvard.iq.dataverse.DataFile) IOException(java.io.IOException) Logger(java.util.logging.Logger) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) UserNotification(edu.harvard.iq.dataverse.UserNotification) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) IdServiceBean(edu.harvard.iq.dataverse.IdServiceBean) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 32 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class SavedSearchServiceBean method makeLinksForSingleSavedSearch.

/**
 * The "Saved Search" and highly related "Linked Dataverses and Linked
 * Datasets" features can be thought of as periodic execution of the
 * LinkDataverseCommand and LinkDatasetCommand. As of this writing that
 * periodic execution can be triggered via a cron job but we'd like to put
 * it on an EJB timer as part of
 * https://github.com/IQSS/dataverse/issues/2543 .
 *
 * The commands are executed by the creator of the SavedSearch. What happens
 * if the users loses the permission that the command requires? Should the
 * commands continue to be executed periodically as some "system" user?
 *
 * @return Debug information in the form of a JSON object, which is much
 * more structured that a simple String.
 */
public JsonObjectBuilder makeLinksForSingleSavedSearch(DataverseRequest dvReq, SavedSearch savedSearch, boolean debugFlag) throws SearchException, CommandException {
    JsonObjectBuilder response = Json.createObjectBuilder();
    JsonArrayBuilder savedSearchArrayBuilder = Json.createArrayBuilder();
    JsonArrayBuilder infoPerHit = Json.createArrayBuilder();
    SolrQueryResponse queryResponse = findHits(savedSearch);
    for (SolrSearchResult solrSearchResult : queryResponse.getSolrSearchResults()) {
        JsonObjectBuilder hitInfo = Json.createObjectBuilder();
        hitInfo.add("name", solrSearchResult.getNameSort());
        hitInfo.add("dvObjectId", solrSearchResult.getEntityId());
        DvObject dvObjectThatDefinitionPointWillLinkTo = dvObjectService.findDvObject(solrSearchResult.getEntityId());
        if (dvObjectThatDefinitionPointWillLinkTo == null) {
            hitInfo.add(resultString, "Could not find DvObject with id " + solrSearchResult.getEntityId());
            infoPerHit.add(hitInfo);
            break;
        }
        if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataverse()) {
            Dataverse dataverseToLinkTo = (Dataverse) dvObjectThatDefinitionPointWillLinkTo;
            if (wouldResultInLinkingToItself(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse id " + dataverseToLinkTo.getId() + " would link to itself.");
            } else if (alreadyLinkedToTheDataverse(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse " + savedSearch.getDefinitionPoint().getId() + " already links to dataverse " + dataverseToLinkTo.getId() + ".");
            } else if (dataverseToLinkToIsAlreadyPartOfTheSubtree(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because " + dataverseToLinkTo + " is already part of the subtree for " + savedSearch.getDefinitionPoint());
            } else {
                DataverseLinkingDataverse link = commandEngine.submitInNewTransaction(new LinkDataverseCommand(dvReq, savedSearch.getDefinitionPoint(), dataverseToLinkTo));
                hitInfo.add(resultString, "Persisted DataverseLinkingDataverse id " + link.getId() + " link of " + dataverseToLinkTo + " to " + savedSearch.getDefinitionPoint());
            }
        } else if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataset()) {
            Dataset datasetToLinkTo = (Dataset) dvObjectThatDefinitionPointWillLinkTo;
            if (alreadyLinkedToTheDataset(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse " + savedSearch.getDefinitionPoint() + " already links to dataset " + datasetToLinkTo + ".");
            } else if (datasetToLinkToIsAlreadyPartOfTheSubtree(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                // already there from normal search/browse
                hitInfo.add(resultString, "Skipping because dataset " + datasetToLinkTo.getId() + " is already part of the subtree for " + savedSearch.getDefinitionPoint().getAlias());
            } else if (datasetAncestorAlreadyLinked(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                hitInfo.add(resultString, "FIXME: implement this?");
            } else {
                DatasetLinkingDataverse link = commandEngine.submitInNewTransaction(new LinkDatasetCommand(dvReq, savedSearch.getDefinitionPoint(), datasetToLinkTo));
                hitInfo.add(resultString, "Persisted DatasetLinkingDataverse id " + link.getId() + " link of " + link.getDataset() + " to " + link.getLinkingDataverse());
            }
        } else if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataFile()) {
            hitInfo.add(resultString, "Skipping because the search matched a file. The matched file id was " + dvObjectThatDefinitionPointWillLinkTo.getId() + ".");
        } else {
            hitInfo.add(resultString, "Unexpected DvObject type.");
        }
        infoPerHit.add(hitInfo);
    }
    JsonObjectBuilder info = getInfo(savedSearch, infoPerHit);
    if (debugFlag) {
        info.add("debug", getDebugInfo(savedSearch));
    }
    savedSearchArrayBuilder.add(info);
    response.add("hits for saved search id " + savedSearch.getId(), savedSearchArrayBuilder);
    return response;
}
Also used : SolrSearchResult(edu.harvard.iq.dataverse.search.SolrSearchResult) SolrQueryResponse(edu.harvard.iq.dataverse.search.SolrQueryResponse) DataverseLinkingDataverse(edu.harvard.iq.dataverse.DataverseLinkingDataverse) DvObject(edu.harvard.iq.dataverse.DvObject) LinkDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.LinkDatasetCommand) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetLinkingDataverse(edu.harvard.iq.dataverse.DatasetLinkingDataverse) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseLinkingDataverse(edu.harvard.iq.dataverse.DataverseLinkingDataverse) DatasetLinkingDataverse(edu.harvard.iq.dataverse.DatasetLinkingDataverse) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.LinkDataverseCommand)

Aggregations

DvObject (edu.harvard.iq.dataverse.DvObject)32 Dataset (edu.harvard.iq.dataverse.Dataset)16 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)14 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)12 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)12 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IOException (java.io.IOException)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)5 DataFile (edu.harvard.iq.dataverse.DataFile)4 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)4 Permission (edu.harvard.iq.dataverse.authorization.Permission)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 Timestamp (java.sql.Timestamp)4 HashMap (java.util.HashMap)4 DatasetField (edu.harvard.iq.dataverse.DatasetField)3