Search in sources :

Example 1 with IndexResponse

use of edu.harvard.iq.dataverse.search.IndexResponse in project dataverse by IQSS.

the class DestroyDatasetCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    // first check if dataset is released, and if so, if user is a superuser
    if (doomed.isReleased() && (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) {
        throw new PermissionException("Destroy can only be called by superusers.", this, Collections.singleton(Permission.DeleteDatasetDraft), doomed);
    }
    // If there is a dedicated thumbnail DataFile, it needs to be reset
    // explicitly, or we'll get a constraint violation when deleting:
    doomed.setThumbnailFile(null);
    final Dataset managedDoomed = ctxt.em().merge(doomed);
    List<String> datasetAndFileSolrIdsToDelete = new ArrayList<>();
    // files need to iterate through and remove 'by hand' to avoid
    // optimistic lock issues... (plus the physical files need to be
    // deleted too!)
    Iterator<DataFile> dfIt = doomed.getFiles().iterator();
    while (dfIt.hasNext()) {
        DataFile df = dfIt.next();
        // Gather potential Solr IDs of files. As of this writing deaccessioned files are never indexed.
        String solrIdOfPublishedFile = IndexServiceBean.solrDocIdentifierFile + df.getId();
        datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedFile);
        String solrIdOfDraftFile = IndexServiceBean.solrDocIdentifierFile + df.getId() + IndexServiceBean.draftSuffix;
        datasetAndFileSolrIdsToDelete.add(solrIdOfDraftFile);
        ctxt.engine().submit(new DeleteDataFileCommand(df, getRequest(), true));
        dfIt.remove();
    }
    // also, lets delete the uploaded thumbnails!
    deleteDatasetLogo(doomed);
    // ASSIGNMENTS
    for (RoleAssignment ra : ctxt.roles().directRoleAssignments(doomed)) {
        ctxt.em().remove(ra);
    }
    // ROLES
    for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) {
        ctxt.em().remove(ra);
    }
    IdServiceBean idServiceBean = IdServiceBean.getBean(ctxt);
    try {
        if (idServiceBean.alreadyExists(doomed)) {
            idServiceBean.deleteIdentifier(doomed);
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Identifier deletion was not successfull:", e.getMessage());
    }
    Dataverse toReIndex = managedDoomed.getOwner();
    // dataset
    ctxt.em().remove(managedDoomed);
    // add potential Solr IDs of datasets to list for deletion
    String solrIdOfPublishedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId();
    datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedDatasetVersion);
    String solrIdOfDraftDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.draftSuffix;
    datasetAndFileSolrIdsToDelete.add(solrIdOfDraftDatasetVersion);
    String solrIdOfDeaccessionedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.deaccessionedSuffix;
    datasetAndFileSolrIdsToDelete.add(solrIdOfDeaccessionedDatasetVersion);
    IndexResponse resultOfSolrDeletionAttempt = ctxt.solrIndex().deleteMultipleSolrIds(datasetAndFileSolrIdsToDelete);
    logger.log(Level.FINE, "Result of attempt to delete dataset and file IDs from the search index: {0}", resultOfSolrDeletionAttempt.getMessage());
    ctxt.index().indexDataverse(toReIndex);
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) DataFile(edu.harvard.iq.dataverse.DataFile) IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) IdServiceBean(edu.harvard.iq.dataverse.IdServiceBean)

Example 2 with IndexResponse

use of edu.harvard.iq.dataverse.search.IndexResponse in project dataverse by IQSS.

the class DataverseRoleServiceBean method save.

public DataverseRole save(DataverseRole aRole) {
    if (aRole.getId() == null) {
        em.persist(aRole);
        /**
         * @todo Why would getId be null? Should we call
         * indexDefinitionPoint here too?
         * A: it's null for new roles.
         */
        return aRole;
    } else {
        DataverseRole merged = em.merge(aRole);
        /**
         * @todo update permissionModificationTime here.
         */
        IndexResponse indexDefinitionPountResult = indexDefinitionPoint(merged.getOwner());
        logger.info("aRole getId was not null. Indexing result: " + indexDefinitionPountResult);
        return merged;
    }
}
Also used : IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 3 with IndexResponse

use of edu.harvard.iq.dataverse.search.IndexResponse in project dataverse by IQSS.

the class PublishDataverseCommand method execute.

@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
    if (dataverse.isReleased()) {
        throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " has already been published.", this);
    }
    Dataverse parent = dataverse.getOwner();
    // root dataverse doesn't have a parent
    if (parent != null) {
        if (!parent.isReleased()) {
            throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " may not be published because its host dataverse (" + parent.getAlias() + ") has not been published.", this);
        }
    }
    // Before setting dataverse to released send notifications to users with download file
    List<RoleAssignment> ras = ctxt.roles().directRoleAssignments(dataverse);
    for (RoleAssignment ra : ras) {
        if (ra.getRole().permissions().contains(Permission.DownloadFile)) {
            for (AuthenticatedUser au : ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier()))) {
                ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.ASSIGNROLE, dataverse.getId());
            }
        }
    }
    dataverse.setPublicationDate(new Timestamp(new Date().getTime()));
    dataverse.setReleaseUser((AuthenticatedUser) getUser());
    Dataverse savedDataverse = ctxt.dataverses().save(dataverse);
    /**
     * @todo consider also
     * ctxt.solrIndex().indexPermissionsOnSelfAndChildren(savedDataverse.getId());
     */
    /**
     * @todo what should we do with the indexRespose?
     */
    IndexResponse indexResponse = ctxt.solrIndex().indexPermissionsForOneDvObject(savedDataverse);
    return savedDataverse;
}
Also used : IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

IndexResponse (edu.harvard.iq.dataverse.search.IndexResponse)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)2 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 DataFile (edu.harvard.iq.dataverse.DataFile)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 IdServiceBean (edu.harvard.iq.dataverse.IdServiceBean)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)1 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1