Search in sources :

Example 56 with Dataset

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

the class JsonParser method parseDataset.

public Dataset parseDataset(JsonObject obj) throws JsonParseException {
    Dataset dataset = new Dataset();
    dataset.setAuthority(obj.getString("authority", null) == null ? settingsService.getValueForKey(SettingsServiceBean.Key.Authority) : obj.getString("authority"));
    dataset.setProtocol(obj.getString("protocol", null) == null ? settingsService.getValueForKey(SettingsServiceBean.Key.Protocol) : obj.getString("protocol"));
    dataset.setDoiSeparator(obj.getString("doiSeparator", null) == null ? settingsService.getValueForKey(SettingsServiceBean.Key.DoiSeparator) : obj.getString("doiSeparator"));
    dataset.setIdentifier(obj.getString("identifier", null));
    DatasetVersion dsv = new DatasetVersion();
    dsv.setDataset(dataset);
    dsv = parseDatasetVersion(obj.getJsonObject("datasetVersion"), dsv);
    LinkedList<DatasetVersion> versions = new LinkedList<>();
    versions.add(dsv);
    dataset.setVersions(versions);
    return dataset;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) LinkedList(java.util.LinkedList)

Example 57 with Dataset

use of edu.harvard.iq.dataverse.Dataset 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 58 with Dataset

use of edu.harvard.iq.dataverse.Dataset 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 59 with Dataset

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

the class SolrIndexServiceBean method reindexFilesInBatches.

private String reindexFilesInBatches(List<DataFile> filesToReindexPermissionsFor) {
    List<SolrInputDocument> docs = new ArrayList<>();
    Map<Long, List<Long>> byParentId = new HashMap<>();
    Map<Long, List<String>> permStringByDatasetVersion = new HashMap<>();
    for (DataFile file : filesToReindexPermissionsFor) {
        Dataset dataset = (Dataset) file.getOwner();
        Map<DatasetVersion.VersionState, Boolean> desiredCards = searchPermissionsService.getDesiredCards(dataset);
        for (DatasetVersion datasetVersionFileIsAttachedTo : datasetVersionsToBuildCardsFor(dataset)) {
            boolean cardShouldExist = desiredCards.get(datasetVersionFileIsAttachedTo.getVersionState());
            if (cardShouldExist) {
                List<String> cachedPermission = permStringByDatasetVersion.get(datasetVersionFileIsAttachedTo.getId());
                if (cachedPermission == null) {
                    logger.fine("no cached permission! Looking it up...");
                    List<DvObjectSolrDoc> fileSolrDocs = constructDatafileSolrDocs((DataFile) file, permStringByDatasetVersion);
                    for (DvObjectSolrDoc fileSolrDoc : fileSolrDocs) {
                        Long datasetVersionId = fileSolrDoc.getDatasetVersionId();
                        if (datasetVersionId != null) {
                            permStringByDatasetVersion.put(datasetVersionId, fileSolrDoc.getPermissions());
                            SolrInputDocument solrDoc = SearchUtil.createSolrDoc(fileSolrDoc);
                            docs.add(solrDoc);
                        }
                    }
                } else {
                    logger.fine("cached permission is " + cachedPermission);
                    List<DvObjectSolrDoc> fileSolrDocsBasedOnCachedPermissions = constructDatafileSolrDocs((DataFile) file, permStringByDatasetVersion);
                    for (DvObjectSolrDoc fileSolrDoc : fileSolrDocsBasedOnCachedPermissions) {
                        SolrInputDocument solrDoc = SearchUtil.createSolrDoc(fileSolrDoc);
                        docs.add(solrDoc);
                    }
                }
            }
        }
        Long parent = file.getOwner().getId();
        List<Long> existingList = byParentId.get(parent);
        if (existingList == null) {
            List<Long> empty = new ArrayList<>();
            byParentId.put(parent, empty);
        } else {
            List<Long> updatedList = existingList;
            updatedList.add(file.getId());
            byParentId.put(parent, updatedList);
        }
    }
    try {
        persistToSolr(docs);
        return " " + filesToReindexPermissionsFor.size() + " files indexed across " + docs.size() + " Solr documents ";
    } catch (SolrServerException | IOException ex) {
        return " tried to reindex " + filesToReindexPermissionsFor.size() + " files indexed across " + docs.size() + " Solr documents but caught exception: " + ex;
    }
}
Also used : HashMap(java.util.HashMap) Dataset(edu.harvard.iq.dataverse.Dataset) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) IOException(java.io.IOException) DataFile(edu.harvard.iq.dataverse.DataFile) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Example 60 with Dataset

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

the class AddReplaceFileHelper method step_070_run_update_dataset_command.

/**
 * Create and run the update dataset command
 *
 * @return
 */
private boolean step_070_run_update_dataset_command() {
    if (this.hasError()) {
        return false;
    }
    Command<Dataset> update_cmd;
    update_cmd = new UpdateDatasetCommand(dataset, dvRequest);
    ((UpdateDatasetCommand) update_cmd).setValidateLenient(true);
    try {
        // Submit the update dataset command
        // and update the local dataset object
        // 
        dataset = commandEngine.submit(update_cmd);
    } catch (CommandException ex) {
        /**
         * @todo Add a test to exercise this error.
         */
        this.addErrorSevere(getBundleErr("add.add_file_error"));
        logger.severe(ex.getMessage());
        return false;
    } catch (EJBException ex) {
        /**
         * @todo Add a test to exercise this error.
         */
        this.addErrorSevere("add.add_file_error (see logs)");
        logger.severe(ex.getMessage());
        return false;
    }
    return true;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) EJBException(javax.ejb.EJBException) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)142 Test (org.junit.Test)53 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)44 DataFile (edu.harvard.iq.dataverse.DataFile)41 Dataverse (edu.harvard.iq.dataverse.Dataverse)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)27 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)22 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)17 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)17 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)16 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)16 Date (java.util.Date)16 JsonObjectBuilder (javax.json.JsonObjectBuilder)16 JsonObject (javax.json.JsonObject)15 DvObject (edu.harvard.iq.dataverse.DvObject)14 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)14 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)14