Search in sources :

Example 26 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class UtilIT method addToGroup.

static Response addToGroup(String dataverseThatGroupBelongsIn, String groupIdentifier, List<String> roleAssigneesToAdd, String apiToken) {
    JsonArrayBuilder groupBuilder = Json.createArrayBuilder();
    roleAssigneesToAdd.stream().forEach((string) -> {
        groupBuilder.add(string);
    });
    Response response = given().header(API_TOKEN_HTTP_HEADER, apiToken).body(groupBuilder.build().toString()).contentType(ContentType.JSON).post("/api/dataverses/" + dataverseThatGroupBelongsIn + "/groups/" + groupIdentifier + "/roleAssignees");
    return response;
}
Also used : Response(com.jayway.restassured.response.Response) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 27 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class Pager method asJsonObjectBuilderCore.

private JsonObjectBuilder asJsonObjectBuilderCore(boolean useCardTerms) {
    JsonObjectBuilder jsonPageInfo = Json.createObjectBuilder();
    jsonPageInfo.add("isNecessary", this.isPagerNecessary()).add("numResults", this.numResults).add("numResultsString", this.addCommasToNumber(numResults)).add("docsPerPage", this.docsPerPage).add("selectedPageNumber", this.selectedPageNumber).add("pageCount", this.pageCount).add("hasPreviousPageNumber", this.hasPreviousPageNumber()).add("previousPageNumber", this.previousPageNumber).add("hasNextPageNumber", this.hasNextPageNumber()).add("nextPageNumber", this.nextPageNumber);
    if (useCardTerms) {
        jsonPageInfo.add("startCardNumber", this.startCardNumber).add("endCardNumber", this.endCardNumber).add("startCardNumberString", this.addCommasToNumber(this.startCardNumber)).add("endCardNumberString", this.addCommasToNumber(this.endCardNumber)).add("remainingCards", this.remainingCards);
    } else {
        jsonPageInfo.add("startResultNumber", this.startCardNumber).add("endResultNumber", this.endCardNumber).add("startResultNumberString", this.addCommasToNumber(this.startCardNumber)).add("endResultNumberString", this.addCommasToNumber(this.endCardNumber)).add("remainingResults", this.remainingCards);
    }
    jsonPageInfo.add("numberNextResults", this.numberNextResults);
    // --------------------
    // pageNumberList
    // --------------------
    JsonArrayBuilder jsonPageNumberArrayBuilder = Json.createArrayBuilder();
    if (this.pageNumberList != null) {
        for (int pg : this.pageNumberList) {
            jsonPageNumberArrayBuilder.add(pg);
        }
        jsonPageInfo.add("pageNumberList", jsonPageNumberArrayBuilder);
    }
    return jsonPageInfo;
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 28 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class IndexAllServiceBean method indexAllOrSubsetPreview.

public JsonObjectBuilder indexAllOrSubsetPreview(long numPartitions, long partitionId, boolean skipIndexed) {
    JsonObjectBuilder response = Json.createObjectBuilder();
    JsonObjectBuilder previewOfWorkload = Json.createObjectBuilder();
    JsonObjectBuilder dvContainerIds = Json.createObjectBuilder();
    List<Long> dataverseIds = dataverseService.findDataverseIdsForIndexing(skipIndexed);
    JsonArrayBuilder dataverseIdsJson = Json.createArrayBuilder();
    // List<Dataverse> dataverses = dataverseService.findAllOrSubset(numPartitions, partitionId, skipIndexed);
    for (Long id : dataverseIds) {
        dataverseIdsJson.add(id);
    }
    List<Long> datasetIds = datasetService.findAllOrSubset(numPartitions, partitionId, skipIndexed);
    JsonArrayBuilder datasetIdsJson = Json.createArrayBuilder();
    for (Long id : datasetIds) {
        datasetIdsJson.add(id);
    }
    dvContainerIds.add("dataverses", dataverseIdsJson);
    dvContainerIds.add("datasets", datasetIdsJson);
    previewOfWorkload.add("dvContainerIds", dvContainerIds);
    previewOfWorkload.add("dataverseCount", dataverseIds.size());
    previewOfWorkload.add("datasetCount", datasetIds.size());
    previewOfWorkload.add("partitionId", partitionId);
    response.add("previewOfPartitionWorkload", previewOfWorkload);
    return response;
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 29 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class RepositoryStorageAbstractionLayerUtil method getSitesFromDb.

/**
 * The reason this in JSON is that it probably makes sense to someday query
 * RSAL or some other "big data" component live for a list of remotes sites
 * to which a particular dataset is replicated to.
 */
public static JsonArray getSitesFromDb(String replicationSitesInDB) {
    JsonArrayBuilder arraybuilder = Json.createArrayBuilder();
    if (replicationSitesInDB == null || replicationSitesInDB.isEmpty()) {
        return arraybuilder.build();
    }
    // Right now we have all the data right in the database setting but we should probably query RSAL to get the list.
    String[] sites = replicationSitesInDB.split(",");
    for (String site : sites) {
        String[] parts = site.split(":");
        arraybuilder.add(Json.createObjectBuilder().add("fqdn", parts[0]).add("name", parts[1]).add("country", parts[2]));
    }
    return arraybuilder.build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 30 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class Dataverses method listMetadataBlocks.

@GET
@Path("{identifier}/metadatablocks")
public Response listMetadataBlocks(@PathParam("identifier") String dvIdtf) {
    try {
        JsonArrayBuilder arr = Json.createArrayBuilder();
        final List<MetadataBlock> blocks = execCommand(new ListMetadataBlocksCommand(createDataverseRequest(findUserOrDie()), findDataverseOrDie(dvIdtf)));
        for (MetadataBlock mdb : blocks) {
            arr.add(brief.json(mdb));
        }
        return allowCors(ok(arr));
    } catch (WrappedResponse we) {
        return we.getResponse();
    }
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) ListMetadataBlocksCommand(edu.harvard.iq.dataverse.engine.command.impl.ListMetadataBlocksCommand) JsonArrayBuilder(javax.json.JsonArrayBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

JsonArrayBuilder (javax.json.JsonArrayBuilder)177 JsonObjectBuilder (javax.json.JsonObjectBuilder)103 JsonObject (javax.json.JsonObject)36 Map (java.util.Map)29 Path (javax.ws.rs.Path)26 GET (javax.ws.rs.GET)24 HashMap (java.util.HashMap)19 JsonArray (javax.json.JsonArray)18 ArrayList (java.util.ArrayList)15 List (java.util.List)15 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)12 IOException (java.io.IOException)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)10 Dataset (edu.harvard.iq.dataverse.Dataset)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 JsonValue (javax.json.JsonValue)9 StringWriter (java.io.StringWriter)8 JsonString (javax.json.JsonString)7 Date (java.util.Date)6 JsonException (javax.json.JsonException)6