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);
}
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);
}
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());
}
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());
}
}
}
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;
}
Aggregations