use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class Index method searchDebug.
/**
* This method is for integration tests of search.
*/
@GET
@Path("test")
public Response searchDebug(@QueryParam("key") String apiToken, @QueryParam("q") String query, @QueryParam("fq") final List<String> filterQueries) {
User user = findUserByApiToken(apiToken);
if (user == null) {
return error(Response.Status.UNAUTHORIZED, "Invalid apikey '" + apiToken + "'");
}
Dataverse subtreeScope = dataverseService.findRootDataverse();
String sortField = SearchFields.ID;
String sortOrder = SortBy.ASCENDING;
int paginationStart = 0;
boolean dataRelatedToMe = false;
int numResultsPerPage = Integer.MAX_VALUE;
SolrQueryResponse solrQueryResponse;
try {
solrQueryResponse = searchService.search(createDataverseRequest(user), subtreeScope, query, filterQueries, sortField, sortOrder, paginationStart, dataRelatedToMe, numResultsPerPage);
} catch (SearchException ex) {
return error(Response.Status.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage() + ": " + ex.getCause().getLocalizedMessage());
}
JsonArrayBuilder itemsArrayBuilder = Json.createArrayBuilder();
List<SolrSearchResult> solrSearchResults = solrQueryResponse.getSolrSearchResults();
for (SolrSearchResult solrSearchResult : solrSearchResults) {
itemsArrayBuilder.add(solrSearchResult.getType() + ":" + solrSearchResult.getNameSort());
}
return ok(itemsArrayBuilder);
}
use of javax.json.JsonArrayBuilder 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 javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class Index method filesearch.
@GET
@Path("filesearch")
public Response filesearch(@QueryParam("persistentId") String persistentId, @QueryParam("semanticVersion") String semanticVersion, @QueryParam("q") String userSuppliedQuery) {
Dataset dataset = datasetService.findByGlobalId(persistentId);
if (dataset == null) {
return error(Status.BAD_REQUEST, "Could not find dataset with persistent id " + persistentId);
}
User user = GuestUser.get();
try {
AuthenticatedUser authenticatedUser = findAuthenticatedUserOrDie();
if (authenticatedUser != null) {
user = authenticatedUser;
}
} catch (WrappedResponse ex) {
}
RetrieveDatasetVersionResponse datasetVersionResponse = datasetVersionService.retrieveDatasetVersionByPersistentId(persistentId, semanticVersion);
if (datasetVersionResponse == null) {
return error(Status.BAD_REQUEST, "Problem searching for files. Could not find dataset version based on " + persistentId + " and " + semanticVersion);
}
DatasetVersion datasetVersion = datasetVersionResponse.getDatasetVersion();
FileView fileView = searchFilesService.getFileView(datasetVersion, user, userSuppliedQuery);
if (fileView == null) {
return error(Status.BAD_REQUEST, "Problem searching for files. Null returned from getFileView.");
}
JsonArrayBuilder filesFound = Json.createArrayBuilder();
JsonArrayBuilder cards = Json.createArrayBuilder();
JsonArrayBuilder fileIds = Json.createArrayBuilder();
for (SolrSearchResult result : fileView.getSolrSearchResults()) {
cards.add(result.getNameSort());
fileIds.add(result.getEntityId());
JsonObjectBuilder fileFound = Json.createObjectBuilder();
fileFound.add("name", result.getNameSort());
fileFound.add("entityId", result.getEntityId().toString());
fileFound.add("datasetVersionId", result.getDatasetVersionId());
fileFound.add("datasetId", result.getParent().get(SearchFields.ID));
filesFound.add(fileFound);
}
JsonArrayBuilder facets = Json.createArrayBuilder();
for (FacetCategory facetCategory : fileView.getFacetCategoryList()) {
facets.add(facetCategory.getFriendlyName());
}
JsonArrayBuilder filterQueries = Json.createArrayBuilder();
for (String filterQuery : fileView.getFilterQueries()) {
filterQueries.add(filterQuery);
}
JsonArrayBuilder allDatasetVersionIds = Json.createArrayBuilder();
for (DatasetVersion dsVersion : dataset.getVersions()) {
allDatasetVersionIds.add(dsVersion.getId());
}
JsonObjectBuilder data = Json.createObjectBuilder();
data.add("filesFound", filesFound);
data.add("cards", cards);
data.add("fileIds", fileIds);
data.add("facets", facets);
data.add("user", user.getIdentifier());
data.add("persistentID", persistentId);
data.add("query", fileView.getQuery());
data.add("filterQueries", filterQueries);
data.add("allDataverVersionIds", allDatasetVersionIds);
data.add("semanticVersion", datasetVersion.getSemanticVersion());
return ok(data);
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class Index method getPermissionsInSolrButNotDatabase.
private JsonObjectBuilder getPermissionsInSolrButNotDatabase() {
List<Long> staleOrMissingPermissions = solrIndexService.findPermissionsInSolrNoLongerInDatabase();
JsonArrayBuilder stalePermissionList = Json.createArrayBuilder();
for (Long dvObjectId : staleOrMissingPermissions) {
stalePermissionList.add(dvObjectId);
}
return Json.createObjectBuilder().add("dvobjects", stalePermissionList.build().size());
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class Notifications method getAllNotificationsForUser.
@GET
@Path("all")
public Response getAllNotificationsForUser() {
User user;
try {
user = findUserOrDie();
} catch (WrappedResponse ex) {
return error(Response.Status.UNAUTHORIZED, "You must supply an API token.");
}
if (user == null) {
return error(Response.Status.BAD_REQUEST, "A user could not be found based on the API token.");
}
if (!(user instanceof AuthenticatedUser)) {
// It's unlikely we'll reach this error. A Guest doesn't have an API token and would have been blocked above.
return error(Response.Status.BAD_REQUEST, "Only an AuthenticatedUser can have notifications.");
}
AuthenticatedUser authenticatedUser = (AuthenticatedUser) user;
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
List<UserNotification> notifications = userNotificationSvc.findByUser(authenticatedUser.getId());
for (UserNotification notification : notifications) {
NullSafeJsonBuilder notificationObjectBuilder = jsonObjectBuilder();
JsonArrayBuilder reasonsForReturn = Json.createArrayBuilder();
Type type = notification.getType();
notificationObjectBuilder.add("id", notification.getId());
notificationObjectBuilder.add("type", type.toString());
/* FIXME - Re-add reasons for return if/when they are added to the notifications page.
if (Type.RETURNEDDS.equals(type) || Type.SUBMITTEDDS.equals(type)) {
JsonArrayBuilder reasons = getReasonsForReturn(notification);
for (JsonValue reason : reasons.build()) {
reasonsForReturn.add(reason);
}
notificationObjectBuilder.add("reasonsForReturn", reasonsForReturn);
}
*/
jsonArrayBuilder.add(notificationObjectBuilder);
}
JsonObjectBuilder result = Json.createObjectBuilder().add("notifications", jsonArrayBuilder);
return ok(result);
}
Aggregations