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;
}
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());
}
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;
}
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;
}
}
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;
}
Aggregations