forked from Qortal/qortal
Renamed ArbitraryResourceSummary to ArbitraryResourceStatus, and added status titles & descriptions
This allows for consistent messaging about each status to be shown in different parts of the system. Previously these strings were hardcoded in the loading screen html so were inaccessible elsewhere.
This commit is contained in:
parent
46e4cb4f50
commit
4d4f661548
@ -3,13 +3,13 @@ package org.qortal.api.gateway.resource;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.qortal.api.Security;
|
||||
import org.qortal.api.model.ArbitraryResourceSummary;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.ArbitraryDataReader;
|
||||
import org.qortal.arbitrary.ArbitraryDataRenderer;
|
||||
import org.qortal.arbitrary.ArbitraryDataResource;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -33,24 +33,24 @@ public class GatewayResource {
|
||||
*/
|
||||
@GET
|
||||
@Path("/arbitrary/resource/status/{service}/{name}")
|
||||
public ArbitraryResourceSummary getDefaultResourceStatus(@PathParam("service") Service service,
|
||||
public ArbitraryResourceStatus getDefaultResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
return this.getSummary(service, name, null, build);
|
||||
return this.getStatus(service, name, null, build);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/arbitrary/resource/status/{service}/{name}/{identifier}")
|
||||
public ArbitraryResourceSummary getResourceStatus(@PathParam("service") Service service,
|
||||
public ArbitraryResourceStatus getResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@PathParam("identifier") String identifier,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
return this.getSummary(service, name, identifier, build);
|
||||
return this.getStatus(service, name, identifier, build);
|
||||
}
|
||||
|
||||
private ArbitraryResourceSummary getSummary(Service service, String name, String identifier, Boolean build) {
|
||||
private ArbitraryResourceStatus getStatus(Service service, String name, String identifier, Boolean build) {
|
||||
|
||||
// If "build=true" has been specified in the query string, build the resource before returning its status
|
||||
if (build != null && build == true) {
|
||||
@ -65,7 +65,7 @@ public class GatewayResource {
|
||||
}
|
||||
|
||||
ArbitraryDataResource resource = new ArbitraryDataResource(name, ResourceIdType.NAME, service, identifier);
|
||||
return resource.getSummary();
|
||||
return resource.getStatus();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
package org.qortal.api.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ArbitraryResourceSummary {
|
||||
|
||||
public enum ArbitraryResourceStatus {
|
||||
NOT_STARTED,
|
||||
DOWNLOADING,
|
||||
DOWNLOADED,
|
||||
BUILDING,
|
||||
READY,
|
||||
MISSING_DATA,
|
||||
BUILD_FAILED,
|
||||
UNSUPPORTED,
|
||||
BLOCKED
|
||||
}
|
||||
|
||||
public ArbitraryResourceStatus status;
|
||||
|
||||
public ArbitraryResourceSummary() {
|
||||
}
|
||||
|
||||
public ArbitraryResourceSummary(ArbitraryResourceStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
@ -29,7 +29,6 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
import org.qortal.api.*;
|
||||
import org.qortal.api.model.ArbitraryResourceSummary;
|
||||
import org.qortal.api.resource.TransactionsResource.ConfirmationStatus;
|
||||
import org.qortal.arbitrary.*;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
@ -40,6 +39,7 @@ import org.qortal.controller.arbitrary.ArbitraryDataStorageManager;
|
||||
import org.qortal.data.account.AccountData;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceInfo;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceNameInfo;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
import org.qortal.data.naming.NameData;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
@ -184,17 +184,17 @@ public class ArbitraryResource {
|
||||
description = "If build is set to true, the resource will be built synchronously before returning the status.",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryResourceSummary.class))
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryResourceStatus.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public ArbitraryResourceSummary getDefaultResourceStatus(@PathParam("service") Service service,
|
||||
public ArbitraryResourceStatus getDefaultResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
Security.requirePriorAuthorizationOrApiKey(request, name, service, null);
|
||||
return this.getSummary(service, name, null, build);
|
||||
return this.getStatus(service, name, null, build);
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -204,18 +204,18 @@ public class ArbitraryResource {
|
||||
description = "If build is set to true, the resource will be built synchronously before returning the status.",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryResourceSummary.class))
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryResourceStatus.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public ArbitraryResourceSummary getResourceStatus(@PathParam("service") Service service,
|
||||
public ArbitraryResourceStatus getResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@PathParam("identifier") String identifier,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
Security.requirePriorAuthorizationOrApiKey(request, name, service, identifier);
|
||||
return this.getSummary(service, name, identifier, build);
|
||||
return this.getStatus(service, name, identifier, build);
|
||||
}
|
||||
|
||||
|
||||
@ -1001,7 +1001,7 @@ public class ArbitraryResource {
|
||||
}
|
||||
|
||||
|
||||
private ArbitraryResourceSummary getSummary(Service service, String name, String identifier, Boolean build) {
|
||||
private ArbitraryResourceStatus getStatus(Service service, String name, String identifier, Boolean build) {
|
||||
|
||||
// If "build=true" has been specified in the query string, build the resource before returning its status
|
||||
if (build != null && build == true) {
|
||||
@ -1016,7 +1016,7 @@ public class ArbitraryResource {
|
||||
}
|
||||
|
||||
ArbitraryDataResource resource = new ArbitraryDataResource(name, ResourceIdType.NAME, service, identifier);
|
||||
return resource.getSummary();
|
||||
return resource.getStatus();
|
||||
}
|
||||
|
||||
private List<ArbitraryResourceInfo> addStatusToResources(List<ArbitraryResourceInfo> resources) {
|
||||
@ -1025,9 +1025,9 @@ public class ArbitraryResource {
|
||||
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;
|
||||
ArbitraryResourceStatus status = resource.getStatus();
|
||||
if (status != null) {
|
||||
resourceInfo.status = status;
|
||||
}
|
||||
updatedResources.add(resourceInfo);
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.qortal.arbitrary;
|
||||
|
||||
import org.qortal.api.model.ArbitraryResourceSummary;
|
||||
import org.qortal.api.model.ArbitraryResourceSummary.ArbitraryResourceStatus;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataBuildManager;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataManager;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
import org.qortal.list.ResourceListManager;
|
||||
import org.qortal.repository.DataException;
|
||||
@ -22,6 +21,8 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.qortal.data.arbitrary.ArbitraryResourceStatus.Status;
|
||||
|
||||
public class ArbitraryDataResource {
|
||||
|
||||
protected final String resourceId;
|
||||
@ -45,50 +46,50 @@ public class ArbitraryDataResource {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public ArbitraryResourceSummary getSummary() {
|
||||
public ArbitraryResourceStatus getStatus() {
|
||||
if (resourceIdType != ResourceIdType.NAME) {
|
||||
// We only support statuses for resources with a name
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.UNSUPPORTED);
|
||||
return new ArbitraryResourceStatus(Status.UNSUPPORTED);
|
||||
}
|
||||
|
||||
// Check if the name is blocked
|
||||
if (ResourceListManager.getInstance()
|
||||
.listContains("blockedNames", this.resourceId, false)) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BLOCKED);
|
||||
return new ArbitraryResourceStatus(Status.BLOCKED);
|
||||
}
|
||||
|
||||
// Firstly check the cache to see if it's already built
|
||||
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(
|
||||
resourceId, resourceIdType, service, identifier);
|
||||
if (arbitraryDataReader.isCachedDataAvailable()) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.READY);
|
||||
return new ArbitraryResourceStatus(Status.READY);
|
||||
}
|
||||
|
||||
// Next check if there's a build in progress
|
||||
ArbitraryDataBuildQueueItem queueItem =
|
||||
new ArbitraryDataBuildQueueItem(resourceId, resourceIdType, service, identifier);
|
||||
if (ArbitraryDataBuildManager.getInstance().isInBuildQueue(queueItem)) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILDING);
|
||||
return new ArbitraryResourceStatus(Status.BUILDING);
|
||||
}
|
||||
|
||||
// Check if a build has failed
|
||||
if (ArbitraryDataBuildManager.getInstance().isInFailedBuildsList(queueItem)) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILD_FAILED);
|
||||
return new ArbitraryResourceStatus(Status.BUILD_FAILED);
|
||||
}
|
||||
|
||||
// Check if we have all data locally for this resource
|
||||
if (!this.allFilesDownloaded()) {
|
||||
if (this.isDownloading()) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.DOWNLOADING);
|
||||
return new ArbitraryResourceStatus(Status.DOWNLOADING);
|
||||
}
|
||||
else if (this.isDataPotentiallyAvailable()) {
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.NOT_STARTED);
|
||||
return new ArbitraryResourceStatus(Status.NOT_STARTED);
|
||||
}
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.MISSING_DATA);
|
||||
return new ArbitraryResourceStatus(Status.MISSING_DATA);
|
||||
}
|
||||
|
||||
// We have all data locally
|
||||
return new ArbitraryResourceSummary(ArbitraryResourceStatus.DOWNLOADED);
|
||||
return new ArbitraryResourceStatus(Status.DOWNLOADED);
|
||||
}
|
||||
|
||||
public boolean delete() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.qortal.data.arbitrary;
|
||||
|
||||
import org.qortal.api.model.ArbitraryResourceSummary.ArbitraryResourceStatus;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
|
@ -0,0 +1,42 @@
|
||||
package org.qortal.data.arbitrary;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ArbitraryResourceStatus {
|
||||
|
||||
public enum Status {
|
||||
NOT_STARTED("Not started", "Downloading not yet started"),
|
||||
DOWNLOADING("Downloading", "Locating and downloading files..."),
|
||||
DOWNLOADED("Downloaded", "Files downloaded"),
|
||||
BUILDING("Building", "Building..."),
|
||||
READY("Ready", "Ready"),
|
||||
MISSING_DATA("Missing data", "Unable to locate all files. Please try again later"),
|
||||
BUILD_FAILED("Build failed", "Build failed. Please try again later"),
|
||||
UNSUPPORTED("Unsupported", "Unsupported request"),
|
||||
BLOCKED("Blocked", "Name is blocked so content cannot be served");
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
|
||||
Status(String title, String description) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
private String id;
|
||||
private String title;
|
||||
private String description;
|
||||
|
||||
public ArbitraryResourceStatus() {
|
||||
}
|
||||
|
||||
public ArbitraryResourceStatus(Status status) {
|
||||
this.id = status.toString();
|
||||
this.title = status.title;
|
||||
this.description = status.description;
|
||||
}
|
||||
|
||||
}
|
@ -58,42 +58,42 @@
|
||||
|
||||
console.log("status: " + json.status);
|
||||
|
||||
if (json.status == "UNSUPPORTED") {
|
||||
textStatus = "Unsupported request";
|
||||
if (json.id == "UNSUPPORTED") {
|
||||
textStatus = response.description;
|
||||
document.getElementById("status").style.color = "red";
|
||||
}
|
||||
else if (json.status == "BLOCKED") {
|
||||
else if (json.id == "BLOCKED") {
|
||||
textStatus = name + " is blocked so content cannot be served";
|
||||
retryInterval = 5000;
|
||||
document.getElementById("status").style.color = "red";
|
||||
}
|
||||
else if (json.status == "READY") {
|
||||
textStatus = "Ready";
|
||||
else if (json.id == "READY") {
|
||||
textStatus = response.statusDescription;
|
||||
window.location.reload();
|
||||
}
|
||||
else if (json.status == "BUILDING") {
|
||||
textStatus = "Building...";
|
||||
else if (json.id == "BUILDING") {
|
||||
textStatus = response.statusDescription;
|
||||
retryInterval = 1000;
|
||||
}
|
||||
else if (json.status == "BUILD_FAILED") {
|
||||
textStatus = "Build failed. Please try again later.";
|
||||
else if (json.id == "BUILD_FAILED") {
|
||||
textStatus = response.statusDescription;
|
||||
}
|
||||
else if (json.status == "NOT_STARTED") {
|
||||
textStatus = "Waiting...";
|
||||
else if (json.id == "NOT_STARTED") {
|
||||
textStatus = response.statusDescription;
|
||||
retryInterval = 1000;
|
||||
}
|
||||
else if (json.status == "DOWNLOADING") {
|
||||
textStatus = "Locating and downloading files...";
|
||||
textStatus = response.statusDescription;
|
||||
retryInterval = 1000;
|
||||
}
|
||||
else if (json.status == "MISSING_DATA") {
|
||||
textStatus = "Unable to locate all files. Please try again later.";
|
||||
else if (json.id == "MISSING_DATA") {
|
||||
textStatus = response.statusDescription;
|
||||
retryInterval = 10000;
|
||||
document.getElementById("status").style.color = "red";
|
||||
document.getElementById("c").style.opacity = "0.5";
|
||||
}
|
||||
else if (json.status == "DOWNLOADED") {
|
||||
textStatus = "Files downloaded";
|
||||
else if (json.id == "DOWNLOADED") {
|
||||
textStatus = response.statusDescription;
|
||||
}
|
||||
|
||||
document.getElementById("status").innerHTML = textStatus;
|
||||
|
Loading…
x
Reference in New Issue
Block a user