Search in sources :

Example 1 with DvObjectSolrDoc

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);
}
Also used : DvObjectSolrDoc(edu.harvard.iq.dataverse.search.DvObjectSolrDoc) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) GuestUser(edu.harvard.iq.dataverse.authorization.users.GuestUser) DvObject(edu.harvard.iq.dataverse.DvObject) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonArrayBuilder(javax.json.JsonArrayBuilder) NullSafeJsonBuilder(edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

DvObject (edu.harvard.iq.dataverse.DvObject)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 GuestUser (edu.harvard.iq.dataverse.authorization.users.GuestUser)1 User (edu.harvard.iq.dataverse.authorization.users.User)1 DvObjectSolrDoc (edu.harvard.iq.dataverse.search.DvObjectSolrDoc)1 NullSafeJsonBuilder (edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1