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