From 8cb06bf45166467af65530c783520f451c54bb93 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 19 Nov 2021 20:20:45 +0000 Subject: [PATCH] Return statuses in GET /arbitrary/resources endpoint when the "includestatus" parameter is true. --- .../qortal/api/resource/AdminResource.java | 1 + .../api/resource/ArbitraryResource.java | 22 +++++++++++++++++-- .../data/arbitrary/ArbitraryResourceInfo.java | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/qortal/api/resource/AdminResource.java b/src/main/java/org/qortal/api/resource/AdminResource.java index ec643d3c..7f2e4d57 100644 --- a/src/main/java/org/qortal/api/resource/AdminResource.java +++ b/src/main/java/org/qortal/api/resource/AdminResource.java @@ -84,6 +84,7 @@ public class AdminResource { @Parameter(in = ParameterIn.QUERY, name = "limit", description = "Maximum number of entries to return, 0 means unlimited", schema = @Schema(type = "integer", defaultValue = "20")) @Parameter(in = ParameterIn.QUERY, name = "offset", description = "Starting entry in results, 0 is first entry", schema = @Schema(type = "integer")) @Parameter(in = ParameterIn.QUERY, name = "reverse", description = "Reverse results", schema = @Schema(type = "boolean")) + @Parameter(in = ParameterIn.QUERY, name = "includestatus", description = "Include status", schema = @Schema(type = "boolean")) public String globalParameters() { return ""; } diff --git a/src/main/java/org/qortal/api/resource/ArbitraryResource.java b/src/main/java/org/qortal/api/resource/ArbitraryResource.java index 1e95dd8b..c989b898 100644 --- a/src/main/java/org/qortal/api/resource/ArbitraryResource.java +++ b/src/main/java/org/qortal/api/resource/ArbitraryResource.java @@ -81,7 +81,9 @@ public class ArbitraryResource { ref = "offset" ) @QueryParam("offset") Integer offset, @Parameter( ref = "reverse" - ) @QueryParam("reverse") Boolean reverse) { + ) @QueryParam("reverse") Boolean reverse, @Parameter( + ref = "includestatus" + ) @QueryParam("includestatus") Boolean includeStatus) { try (final Repository repository = RepositoryManager.getRepository()) { List resources = repository.getArbitraryRepository() @@ -90,7 +92,23 @@ public class ArbitraryResource { if (resources == null) { return new ArrayList<>(); } - return resources; + + if (includeStatus == null || includeStatus == false) { + return resources; + } + + // Determine and add the status of each resource + List updatedResources = new ArrayList<>(); + for (ArbitraryResourceInfo resourceInfo : resources) { + ArbitraryDataResource resource = new ArbitraryDataResource(resourceInfo.name, ResourceIdType.NAME, + resourceInfo.service, resourceInfo.identifier); + ArbitraryResourceSummary summary = resource.getSummary(); + if (summary != null) { + resourceInfo.status = summary.status; + } + updatedResources.add(resourceInfo); + } + return updatedResources; } catch (DataException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); diff --git a/src/main/java/org/qortal/data/arbitrary/ArbitraryResourceInfo.java b/src/main/java/org/qortal/data/arbitrary/ArbitraryResourceInfo.java index db057de5..4be83348 100644 --- a/src/main/java/org/qortal/data/arbitrary/ArbitraryResourceInfo.java +++ b/src/main/java/org/qortal/data/arbitrary/ArbitraryResourceInfo.java @@ -1,5 +1,6 @@ package org.qortal.data.arbitrary; +import org.qortal.api.model.ArbitraryResourceSummary.ArbitraryResourceStatus; import org.qortal.arbitrary.misc.Service; import javax.xml.bind.annotation.XmlAccessType; @@ -11,6 +12,7 @@ public class ArbitraryResourceInfo { public String name; public Service service; public String identifier; + public ArbitraryResourceStatus status; public ArbitraryResourceInfo() { }