use of edu.harvard.iq.dataverse.search.DvObjectSolrDoc 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);
}
Aggregations