Search in sources :

Example 11 with DvObject

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

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee assignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNotNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 12 with DvObject

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

the class SolrIndexServiceBean method indexPermissionsOnSelfAndChildren.

/**
 * We use the database to determine direct children since there is no
 * inheritance
 */
public IndexResponse indexPermissionsOnSelfAndChildren(DvObject definitionPoint) {
    List<DvObject> dvObjectsToReindexPermissionsFor = new ArrayList<>();
    List<DataFile> filesToReindexAsBatch = new ArrayList<>();
    // so don't create a Solr "permission" doc either.
    if (definitionPoint.isInstanceofDataverse()) {
        Dataverse selfDataverse = (Dataverse) definitionPoint;
        if (!selfDataverse.equals(dataverseService.findRootDataverse())) {
            dvObjectsToReindexPermissionsFor.add(definitionPoint);
        }
        List<Dataset> directChildDatasetsOfDvDefPoint = datasetService.findByOwnerId(selfDataverse.getId());
        for (Dataset dataset : directChildDatasetsOfDvDefPoint) {
            dvObjectsToReindexPermissionsFor.add(dataset);
            for (DataFile datafile : filesToReIndexPermissionsFor(dataset)) {
                filesToReindexAsBatch.add(datafile);
            }
        }
    } else if (definitionPoint.isInstanceofDataset()) {
        // index the dataset itself
        indexPermissionsForOneDvObject(definitionPoint);
        dvObjectsToReindexPermissionsFor.add(definitionPoint);
        // index files
        Dataset dataset = (Dataset) definitionPoint;
        for (DataFile datafile : filesToReIndexPermissionsFor(dataset)) {
            filesToReindexAsBatch.add(datafile);
        }
    } else {
        dvObjectsToReindexPermissionsFor.add(definitionPoint);
    }
    /**
     * @todo Error handling? What to do with response?
     *
     * @todo Should update timestamps, probably, even thought these are
     * files, see https://github.com/IQSS/dataverse/issues/2421
     */
    String response = reindexFilesInBatches(filesToReindexAsBatch);
    List<String> updatePermissionTimeSuccessStatus = new ArrayList<>();
    for (DvObject dvObject : dvObjectsToReindexPermissionsFor) {
        /**
         * @todo do something with this response
         */
        IndexResponse indexResponse = indexPermissionsForOneDvObject(dvObject);
        DvObject managedDefinitionPoint = dvObjectService.updatePermissionIndexTime(definitionPoint);
        boolean updatePermissionTimeSuccessful = false;
        if (managedDefinitionPoint != null) {
            updatePermissionTimeSuccessful = true;
        }
        updatePermissionTimeSuccessStatus.add(dvObject + ":" + updatePermissionTimeSuccessful);
    }
    return new IndexResponse("Number of dvObject permissions indexed for " + definitionPoint + " (updatePermissionTimeSuccessful:" + updatePermissionTimeSuccessStatus + "): " + dvObjectsToReindexPermissionsFor.size());
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) ArrayList(java.util.ArrayList) Dataverse(edu.harvard.iq.dataverse.Dataverse)

Example 13 with DvObject

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

the class SolrIndexServiceBean method determineSolrDocsForFilesFromDataset.

private List<DvObjectSolrDoc> determineSolrDocsForFilesFromDataset(Map.Entry<Long, List<Long>> datasetHash) {
    List<DvObjectSolrDoc> emptyList = new ArrayList<>();
    List<DvObjectSolrDoc> solrDocs = emptyList;
    DvObject dvObject = dvObjectService.findDvObject(datasetHash.getKey());
    if (dvObject == null) {
        return emptyList;
    }
    if (dvObject.isInstanceofDataset()) {
        Dataset dataset = (Dataset) dvObject;
        solrDocs.addAll(constructDatafileSolrDocsFromDataset(dataset));
    }
    return solrDocs;
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) ArrayList(java.util.ArrayList)

Example 14 with DvObject

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

the class SolrIndexServiceBean method indexPermissionsForOneDvObject.

public IndexResponse indexPermissionsForOneDvObject(DvObject dvObject) {
    if (dvObject == null) {
        return new IndexResponse("problem indexing... null DvObject passed in");
    }
    long dvObjectId = dvObject.getId();
    Collection<SolrInputDocument> docs = new ArrayList<>();
    List<DvObjectSolrDoc> definitionPoints = determineSolrDocs(dvObject);
    for (DvObjectSolrDoc dvObjectSolrDoc : definitionPoints) {
        SolrInputDocument solrInputDocument = SearchUtil.createSolrDoc(dvObjectSolrDoc);
        docs.add(solrInputDocument);
    }
    try {
        persistToSolr(docs);
        boolean updatePermissionTimeSuccessful = false;
        if (dvObject != null) {
            DvObject savedDvObject = dvObjectService.updatePermissionIndexTime(dvObject);
            if (savedDvObject != null) {
                updatePermissionTimeSuccessful = true;
            }
        }
        return new IndexResponse("attempted to index permissions for DvObject " + dvObjectId + " and updatePermissionTimeSuccessful was " + updatePermissionTimeSuccessful);
    } catch (SolrServerException | IOException ex) {
        return new IndexResponse("problem indexing");
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) DvObject(edu.harvard.iq.dataverse.DvObject) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 15 with DvObject

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

the class SolrIndexServiceBean method findPermissionsInDatabaseButStaleInOrMissingFromSolr.

/**
 * @todo Do we want to report the root dataverse (id 1, often) in
 * permissionsInDatabaseButMissingFromSolr?
 *
 * @return A list of dvobject ids that should have their permissions
 * re-indexed Solr was down when a permission was added. The permission
 * should be added to Solr.
 */
public List<Long> findPermissionsInDatabaseButStaleInOrMissingFromSolr() {
    List<Long> indexingRequired = new ArrayList<>();
    long rootDvId = dataverseService.findRootDataverse().getId();
    for (DvObject dvObject : dvObjectService.findAll()) {
        // logger.info("examining dvObjectId " + dvObject.getId() + "...");
        Timestamp permissionModificationTime = dvObject.getPermissionModificationTime();
        Timestamp permissionIndexTime = dvObject.getPermissionIndexTime();
        if (permissionIndexTime == null) {
            if (dvObject.getId() != rootDvId) {
                // we don't index the rootDv
                indexingRequired.add(dvObject.getId());
            }
        } else if (permissionModificationTime == null) {
            /**
             * @todo What should we do here? Permissions should always be
             * there. They are assigned at create time.
             */
            logger.info("no permission modification time for dvobject id " + dvObject.getId());
        } else if (permissionIndexTime.before(permissionModificationTime)) {
            indexingRequired.add(dvObject.getId());
        }
    }
    return indexingRequired;
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp)

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