use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class JsonPrinter method getFileCategories.
private static JsonArrayBuilder getFileCategories(FileMetadata fmd) {
if (fmd == null) {
return null;
}
List<String> categories = fmd.getCategoriesByName();
if (categories == null || categories.isEmpty()) {
return null;
}
JsonArrayBuilder fileCategories = Json.createArrayBuilder();
for (String category : categories) {
fileCategories.add(category);
}
return fileCategories;
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class JsonPrinter method json.
public static JsonObject json(DatasetField dfv) {
if (dfv.isEmpty()) {
return null;
} else {
JsonArrayBuilder fieldArray = Json.createArrayBuilder();
DatasetFieldWalker.walk(dfv, new DatasetFieldsToJson(fieldArray));
JsonArray out = fieldArray.build();
return out.getJsonObject(0);
}
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class SavedSearchServiceBean method makeLinksForAllSavedSearches.
public JsonObjectBuilder makeLinksForAllSavedSearches(boolean debugFlag) throws SearchException, CommandException {
JsonObjectBuilder response = Json.createObjectBuilder();
List<SavedSearch> allSavedSearches = findAll();
JsonArrayBuilder savedSearchArrayBuilder = Json.createArrayBuilder();
for (SavedSearch savedSearch : allSavedSearches) {
DataverseRequest dataverseRequest = new DataverseRequest(savedSearch.getCreator(), getHttpServletRequest());
JsonObjectBuilder perSavedSearchResponse = makeLinksForSingleSavedSearch(dataverseRequest, savedSearch, debugFlag);
savedSearchArrayBuilder.add(perSavedSearchResponse);
}
response.add("hits by saved search", savedSearchArrayBuilder);
return response;
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class SolrSearchResult method json.
// getJsonForMydata
public JsonObjectBuilder json(boolean showRelevance, boolean showEntityIds, boolean showApiUrls) {
if (this.type == null) {
return jsonObjectBuilder();
}
String displayName = null;
String identifierLabel = null;
String datasetCitation = null;
String preferredUrl = null;
String apiUrl = null;
if (this.type.equals(SearchConstants.DATAVERSES)) {
displayName = this.name;
identifierLabel = "identifier";
preferredUrl = getHtmlUrl();
} else if (this.type.equals(SearchConstants.DATASETS)) {
displayName = this.title;
identifierLabel = "global_id";
preferredUrl = getPersistentUrl();
/**
* @todo Should we show the name of the parent dataverse?
*/
} else if (this.type.equals(SearchConstants.FILES)) {
displayName = this.name;
identifierLabel = "file_id";
preferredUrl = getDownloadUrl();
/**
* @todo show more information for a file's parent, such as the
* title of the dataset it belongs to.
*/
datasetCitation = parent.get("citation");
}
// displayName = null; // testing NullSafeJsonBuilder
// because we are using NullSafeJsonBuilder key/value pairs will be dropped if the value is null
NullSafeJsonBuilder nullSafeJsonBuilder = jsonObjectBuilder().add("name", displayName).add("type", getDisplayType(getType())).add("url", preferredUrl).add("image_url", getImageUrl()).add(identifierLabel, this.identifier).add("description", this.descriptionNoSnippet).add("published_at", getDateTimePublished()).add("file_type", this.filetype).add("file_content_type", this.fileContentType).add("size_in_bytes", getFileSizeInBytes()).add("md5", getFileMd5()).add("checksum", JsonPrinter.getChecksumTypeAndValue(getFileChecksumType(), getFileChecksumValue())).add("unf", getUnf()).add("dataset_citation", datasetCitation).add("deaccession_reason", this.deaccessionReason).add("citationHtml", this.citationHtml).add("citation", this.citation);
// Now that nullSafeJsonBuilder has been instatiated, check for null before adding to it!
if (showRelevance) {
nullSafeJsonBuilder.add("matches", getRelevance());
nullSafeJsonBuilder.add("score", getScore());
}
if (showEntityIds) {
if (this.entityId != null) {
nullSafeJsonBuilder.add("entity_id", this.entityId);
}
}
if (showApiUrls) {
/**
* @todo We should probably have a metadata_url or api_url concept
* enabled by default, not hidden behind an undocumented boolean.
* For datasets, this would be http://example.com/api/datasets/10 or
* whatever (to get more detailed JSON), but right now this requires
* an API token. Discuss at
* https://docs.google.com/document/d/1d8sT2GLSavgiAuMTVX8KzTCX0lROEET1edhvHHRDZOs/edit?usp=sharing";
*/
if (getApiUrl() != null) {
nullSafeJsonBuilder.add("api_url", getApiUrl());
}
}
// NullSafeJsonBuilder is awesome but can't build null safe arrays. :(
if (!datasetAuthors.isEmpty()) {
JsonArrayBuilder authors = Json.createArrayBuilder();
for (String datasetAuthor : datasetAuthors) {
authors.add(datasetAuthor);
}
nullSafeJsonBuilder.add("authors", authors);
}
return nullSafeJsonBuilder;
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class WorkflowUtil method getAllWorkflowComments.
public static JsonArrayBuilder getAllWorkflowComments(DatasetVersion datasetVersion) {
JsonArrayBuilder workflowCommentsAsJson = Json.createArrayBuilder();
List<WorkflowComment> workflowComments = datasetVersion.getWorkflowComments();
for (WorkflowComment workflowComment : workflowComments) {
NullSafeJsonBuilder workflowCommentAsJson = jsonObjectBuilder();
workflowCommentAsJson.add("workflowCommentId", workflowComment.getId());
workflowCommentAsJson.add("message", workflowComment.getMessage());
workflowCommentAsJson.add("createTime", Util.getDateTimeFormat().format(workflowComment.getCreated()));
workflowCommentAsJson.add("commentBy", workflowComment.getAuthenticatedUser().getIdentifier());
workflowCommentAsJson.add("datasetId", datasetVersion.getDataset().getId());
workflowCommentAsJson.add("datasetVersionId", datasetVersion.getId());
workflowCommentAsJson.add("datasetTitle", datasetVersion.getTitle());
workflowCommentsAsJson.add(workflowCommentAsJson);
}
return workflowCommentsAsJson;
}
Aggregations