Search in sources :

Example 31 with JsonArrayBuilder

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

the class ExternalTools method getExternalTools.

@GET
public Response getExternalTools() {
    JsonArrayBuilder jab = Json.createArrayBuilder();
    externalToolService.findAll().forEach((externalTool) -> {
        jab.add(externalTool.toJson());
    });
    return ok(jab);
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) GET(javax.ws.rs.GET)

Example 32 with JsonArrayBuilder

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

the class Geoconnect method checkMapLayerMetadatas.

@POST
@Path("mapLayerMetadatas/check")
public Response checkMapLayerMetadatas() {
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    mapLayerMetadataSrv.findAll().stream().map((unmodified) -> checkStatus(unmodified)).forEach((jsonObjectBuilder) -> {
        jsonArrayBuilder.add(jsonObjectBuilder);
    });
    return ok(jsonArrayBuilder);
}
Also used : PathParam(javax.ws.rs.PathParam) JsonArrayBuilder(javax.json.JsonArrayBuilder) POST(javax.ws.rs.POST) Date(java.util.Date) Timestamp(java.sql.Timestamp) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) Path(javax.ws.rs.Path) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) MapLayerMetadata(edu.harvard.iq.dataverse.MapLayerMetadata) Logger(java.util.logging.Logger) Unirest(com.mashape.unirest.http.Unirest) GetRequest(com.mashape.unirest.request.GetRequest) Response(javax.ws.rs.core.Response) Json(javax.json.Json) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonArrayBuilder(javax.json.JsonArrayBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 33 with JsonArrayBuilder

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

the class Index method getPermissionsInDatabaseButStaleInOrMissingFromSolr.

private JsonObjectBuilder getPermissionsInDatabaseButStaleInOrMissingFromSolr() {
    List<Long> staleOrMissingPermissions;
    staleOrMissingPermissions = solrIndexService.findPermissionsInDatabaseButStaleInOrMissingFromSolr();
    JsonArrayBuilder stalePermissionList = Json.createArrayBuilder();
    for (Long dvObjectId : staleOrMissingPermissions) {
        stalePermissionList.add(dvObjectId);
    }
    return Json.createObjectBuilder().add("dvobjects", stalePermissionList.build().size());
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 34 with JsonArrayBuilder

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

the class Index method indexAllOrSubset.

private Response indexAllOrSubset(Long numPartitionsSelected, Long partitionIdToProcess, boolean skipIndexed, boolean previewOnly) {
    try {
        long numPartitions = 1;
        if (numPartitionsSelected != null) {
            if (numPartitionsSelected < 1) {
                return error(Status.BAD_REQUEST, "numPartitions must be 1 or higher but was " + numPartitionsSelected);
            } else {
                numPartitions = numPartitionsSelected;
            }
        }
        List<Long> availablePartitionIds = new ArrayList<>();
        for (long i = 0; i < numPartitions; i++) {
            availablePartitionIds.add(i);
        }
        Response invalidParitionIdSelection = error(Status.BAD_REQUEST, "You specified " + numPartitions + " partition(s) and your selected partitionId was " + partitionIdToProcess + " but you must select from these availableParitionIds: " + availablePartitionIds);
        if (partitionIdToProcess != null) {
            long selected = partitionIdToProcess;
            if (!availablePartitionIds.contains(selected)) {
                return invalidParitionIdSelection;
            }
        } else if (numPartitionsSelected == null) {
            /**
             * The user has not specified a partitionId and hasn't specified
             * the number of partitions. Run "index all", the whole thing.
             */
            partitionIdToProcess = 0l;
        } else {
            return invalidParitionIdSelection;
        }
        JsonObjectBuilder args = Json.createObjectBuilder();
        args.add("numPartitions", numPartitions);
        args.add("partitionIdToProcess", partitionIdToProcess);
        JsonArrayBuilder availablePartitionIdsBuilder = Json.createArrayBuilder();
        for (long i : availablePartitionIds) {
            availablePartitionIdsBuilder.add(i);
        }
        JsonObjectBuilder preview = indexAllService.indexAllOrSubsetPreview(numPartitions, partitionIdToProcess, skipIndexed);
        if (previewOnly) {
            preview.add("args", args);
            preview.add("availablePartitionIds", availablePartitionIdsBuilder);
            return ok(preview);
        }
        JsonObjectBuilder response = Json.createObjectBuilder();
        response.add("availablePartitionIds", availablePartitionIdsBuilder);
        response.add("args", args);
        /**
         * @todo How can we expose the String returned from "index all" via
         * the API?
         */
        Future<JsonObjectBuilder> indexAllFuture = indexAllService.indexAllOrSubset(numPartitions, partitionIdToProcess, skipIndexed, previewOnly);
        JsonObject workloadPreview = preview.build().getJsonObject("previewOfPartitionWorkload");
        int dataverseCount = workloadPreview.getInt("dataverseCount");
        int datasetCount = workloadPreview.getInt("datasetCount");
        String status = "indexAllOrSubset has begun of " + dataverseCount + " dataverses and " + datasetCount + " datasets.";
        response.add("message", status);
        return ok(response);
    } catch (EJBException ex) {
        Throwable cause = ex;
        StringBuilder sb = new StringBuilder();
        sb.append(ex + " ");
        while (cause.getCause() != null) {
            cause = cause.getCause();
            sb.append(cause.getClass().getCanonicalName() + " ");
            sb.append(cause.getMessage()).append(" ");
            if (cause instanceof ConstraintViolationException) {
                ConstraintViolationException constraintViolationException = (ConstraintViolationException) cause;
                for (ConstraintViolation<?> violation : constraintViolationException.getConstraintViolations()) {
                    sb.append("(invalid value: <<<").append(violation.getInvalidValue()).append(">>> for ").append(violation.getPropertyPath()).append(" at ").append(violation.getLeafBean()).append(" - ").append(violation.getMessage()).append(")");
                }
            } else if (cause instanceof NullPointerException) {
                for (int i = 0; i < 2; i++) {
                    StackTraceElement stacktrace = cause.getStackTrace()[i];
                    if (stacktrace != null) {
                        String classCanonicalName = stacktrace.getClass().getCanonicalName();
                        String methodName = stacktrace.getMethodName();
                        int lineNumber = stacktrace.getLineNumber();
                        String error = "at " + stacktrace.getClassName() + "." + stacktrace.getMethodName() + "(" + stacktrace.getFileName() + ":" + lineNumber + ") ";
                        sb.append(error);
                    }
                }
            }
        }
        if (sb.toString().equals("javax.ejb.EJBException: Transaction aborted javax.transaction.RollbackException java.lang.IllegalStateException ")) {
            return ok("indexing went as well as can be expected... got java.lang.IllegalStateException but some indexing may have happened anyway");
        } else {
            return error(Status.INTERNAL_SERVER_ERROR, sb.toString());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) SolrQueryResponse(edu.harvard.iq.dataverse.search.SolrQueryResponse) IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) Response(javax.ws.rs.core.Response) RetrieveDatasetVersionResponse(edu.harvard.iq.dataverse.DatasetVersionServiceBean.RetrieveDatasetVersionResponse) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) EJBException(javax.ejb.EJBException)

Example 35 with JsonArrayBuilder

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

the class Index method getContentInDatabaseButStaleInOrMissingFromSolr.

private JsonObjectBuilder getContentInDatabaseButStaleInOrMissingFromSolr() {
    List<Dataverse> stateOrMissingDataverses = indexService.findStaleOrMissingDataverses();
    List<Dataset> staleOrMissingDatasets = indexService.findStaleOrMissingDatasets();
    JsonArrayBuilder jsonStateOrMissingDataverses = Json.createArrayBuilder();
    for (Dataverse dataverse : stateOrMissingDataverses) {
        jsonStateOrMissingDataverses.add(dataverse.getId());
    }
    JsonArrayBuilder datasetsInDatabaseButNotSolr = Json.createArrayBuilder();
    for (Dataset dataset : staleOrMissingDatasets) {
        datasetsInDatabaseButNotSolr.add(dataset.getId());
    }
    JsonObjectBuilder contentInDatabaseButStaleInOrMissingFromSolr = Json.createObjectBuilder().add("dataverses", jsonStateOrMissingDataverses.build().size()).add("datasets", datasetsInDatabaseButNotSolr.build().size());
    return contentInDatabaseButStaleInOrMissingFromSolr;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Dataverse(edu.harvard.iq.dataverse.Dataverse)

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