use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class ReturnDatasetToAuthorCommandTest method setUp.
@Before
public void setUp() {
dataset = new Dataset();
HttpServletRequest aHttpServletRequest = null;
dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
testEngine = new TestDataverseEngine(new TestCommandContext() {
@Override
public AuthenticationServiceBean authentication() {
return new AuthenticationServiceBean() {
@Override
public AuthenticatedUser getAuthenticatedUser(String id) {
return MocksFactory.makeAuthenticatedUser("First", "Last");
}
};
}
@Override
public IndexServiceBean index() {
return new IndexServiceBean() {
@Override
public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
return null;
}
};
}
@Override
public EntityManager em() {
return new NoOpTestEntityManager();
}
@Override
public DatasetServiceBean datasets() {
return new DatasetServiceBean() {
{
em = new NoOpTestEntityManager();
}
@Override
public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
return null;
}
@Override
public WorkflowComment addWorkflowComment(WorkflowComment comment) {
return comment;
}
@Override
public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
}
};
}
@Override
public DataverseRoleServiceBean roles() {
return new DataverseRoleServiceBean() {
@Override
public DataverseRole findBuiltinRoleByAlias(String alias) {
return new DataverseRole();
}
@Override
public RoleAssignment save(RoleAssignment assignment) {
// no-op
return assignment;
}
};
}
@Override
public PermissionServiceBean permissions() {
return new PermissionServiceBean() {
@Override
public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
// We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
return Collections.emptyList();
}
};
}
});
}
use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class GroupServiceBean method groupTransitiveClosure.
/**
* Given a set of groups and a DV object, return all the groups that are
* reachable from the set. Effectively, if the initial set has an {@link ExplicitGroup},
* recursively add all the groups it contains.
*
* @param groups
* @param dvo
* @return All the groups included in the groups in {@code groups}.
*/
private Set<Group> groupTransitiveClosure(Set<Group> groups, DvObject dvo) {
// now, get the explicit group transitive closure.
Set<ExplicitGroup> perimeter = new HashSet<>();
Set<ExplicitGroup> visited = new HashSet<>();
groups.stream().filter((g) -> (g instanceof ExplicitGroup)).forEachOrdered((g) -> perimeter.add((ExplicitGroup) g));
visited.addAll(perimeter);
while (!perimeter.isEmpty()) {
ExplicitGroup g = perimeter.iterator().next();
perimeter.remove(g);
groups.add(g);
Set<ExplicitGroup> discovered = explicitGroupProvider.groupsFor(g, dvo);
// Ideally the conjunction is always empty, as we don't allow cycles.
discovered.removeAll(visited);
// Still, coding defensively here, in case someone gets too
// smart on the SQL console.
perimeter.addAll(discovered);
visited.addAll(discovered);
}
return groups;
}
use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class IndexAsync method indexRoles.
@Asynchronous
public void indexRoles(Collection<DvObject> dvObjects) {
for (DvObject dvObject : dvObjects) {
IndexResponse indexResponse = solrIndexService.indexPermissionsOnSelfAndChildren(dvObject);
logger.fine("output from permission indexing operations (dvobject " + dvObject.getId() + ": " + indexResponse);
}
}
use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class Index method searchPermsDebug.
/**
* This method is for integration tests of search.
*/
@GET
@Path("permsDebug")
public Response searchPermsDebug(@QueryParam("key") String apiToken, @QueryParam("id") Long dvObjectId) {
User user = findUserByApiToken(apiToken);
if (user == null) {
return error(Response.Status.UNAUTHORIZED, "Invalid apikey '" + apiToken + "'");
}
DvObject dvObjectToLookUp = dvObjectService.findDvObject(dvObjectId);
if (dvObjectToLookUp == null) {
return error(Status.BAD_REQUEST, "Could not find DvObject based on id " + dvObjectId);
}
List<DvObjectSolrDoc> solrDocs = SolrIndexService.determineSolrDocs(dvObjectToLookUp);
JsonObjectBuilder data = Json.createObjectBuilder();
JsonArrayBuilder permissionsData = Json.createArrayBuilder();
for (DvObjectSolrDoc solrDoc : solrDocs) {
JsonObjectBuilder dataDoc = Json.createObjectBuilder();
dataDoc.add(SearchFields.ID, solrDoc.getSolrId());
dataDoc.add(SearchFields.NAME_SORT, solrDoc.getNameOrTitle());
JsonArrayBuilder perms = Json.createArrayBuilder();
for (String perm : solrDoc.getPermissions()) {
perms.add(perm);
}
dataDoc.add(SearchFields.DISCOVERABLE_BY, perms);
permissionsData.add(dataDoc);
}
data.add("perms", permissionsData);
DvObject dvObject = dvObjectService.findDvObject(dvObjectId);
NullSafeJsonBuilder timestamps = jsonObjectBuilder();
timestamps.add(contentChanged, SearchUtil.getTimestampOrNull(dvObject.getModificationTime()));
timestamps.add(contentIndexed, SearchUtil.getTimestampOrNull(dvObject.getIndexTime()));
timestamps.add(permsChanged, SearchUtil.getTimestampOrNull(dvObject.getPermissionModificationTime()));
timestamps.add(permsIndexed, SearchUtil.getTimestampOrNull(dvObject.getPermissionIndexTime()));
Set<RoleAssignment> roleAssignments = rolesSvc.rolesAssignments(dvObject);
JsonArrayBuilder roleAssignmentsData = Json.createArrayBuilder();
for (RoleAssignment roleAssignment : roleAssignments) {
roleAssignmentsData.add(roleAssignment.getRole() + " has been granted to " + roleAssignment.getAssigneeIdentifier() + " on " + roleAssignment.getDefinitionPoint());
}
data.add("timestamps", timestamps);
data.add("roleAssignments", roleAssignmentsData);
return ok(data);
}
use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser.
@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser() {
DataverseRole aRole = null;
RoleAssignee assignee = GuestUser.get();
DvObject dataset = new Dataset();
String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
assertNull(privateUrl);
}
Aggregations