use of edu.harvard.iq.dataverse.RoleAssignment 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.RoleAssignment in project dataverse by IQSS.
the class JsonPrinterTest method testJson_PrivateUrl.
@Test
public void testJson_PrivateUrl() {
DataverseRole aRole = new DataverseRole();
PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUserIn;
Dataset dataset = new Dataset();
String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
String dataverseSiteUrl = "https://dataverse.example.edu";
PrivateUrl privateUrl = new PrivateUrl(ra, dataset, dataverseSiteUrl);
JsonObjectBuilder job = JsonPrinter.json(privateUrl);
assertNotNull(job);
JsonObject jsonObject = job.build();
assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("token"));
assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("link"));
assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getJsonObject("roleAssignment").getString("privateUrlToken"));
assertEquals("#42", jsonObject.getJsonObject("roleAssignment").getString("assignee"));
}
use of edu.harvard.iq.dataverse.RoleAssignment 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);
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentNullDataset.
@Test
public void testGetDraftDatasetVersionFromRoleAssignmentNullDataset() {
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = null;
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
DatasetVersion datasetVersion = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
assertNull(datasetVersion);
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentSuccess.
@Test
public void testGetPrivateUrlFromRoleAssignmentSuccess() {
String dataverseSiteUrl = "https://dataverse.example.edu";
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = new Dataset();
dataset.setId(42l);
String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
assertNotNull(privateUrl);
assertEquals(new Long(42), privateUrl.getDataset().getId());
assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=cd71e9d7-73a7-4ec8-b890-3d00499e8693", privateUrl.getLink());
}
Aggregations