diff --git a/src/org/kar/archidata/externalRestApi/model/ApiTool.java b/src/org/kar/archidata/externalRestApi/model/ApiTool.java index f976c3d..e9eb845 100644 --- a/src/org/kar/archidata/externalRestApi/model/ApiTool.java +++ b/src/org/kar/archidata/externalRestApi/model/ApiTool.java @@ -7,8 +7,10 @@ import java.util.Arrays; import java.util.List; import org.glassfish.jersey.media.multipart.FormDataParam; +import org.kar.archidata.annotation.ARCHIVE; import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.FormDataOptional; +import org.kar.archidata.annotation.RESTORE; import org.kar.archidata.annotation.TypeScriptProgress; import io.swagger.v3.oas.annotations.Operation; @@ -107,6 +109,12 @@ public class ApiTool { if (element.getDeclaredAnnotationsByType(DELETE.class).length == 1) { return "DELETE"; } + if (element.getDeclaredAnnotationsByType(RESTORE.class).length == 1) { + return "RESTORE"; + } + if (element.getDeclaredAnnotationsByType(ARCHIVE.class).length == 1) { + return "ARCHIVE"; + } return null; } @@ -126,6 +134,12 @@ public class ApiTool { if (element.getDeclaredAnnotationsByType(DELETE.class).length == 1) { return RestTypeRequest.DELETE; } + if (element.getDeclaredAnnotationsByType(RESTORE.class).length == 1) { + return RestTypeRequest.RESTORE; + } + if (element.getDeclaredAnnotationsByType(ARCHIVE.class).length == 1) { + return RestTypeRequest.ARCHIVE; + } return null; } diff --git a/src/org/kar/archidata/externalRestApi/model/RestTypeRequest.java b/src/org/kar/archidata/externalRestApi/model/RestTypeRequest.java index 6d76c7a..1c96370 100644 --- a/src/org/kar/archidata/externalRestApi/model/RestTypeRequest.java +++ b/src/org/kar/archidata/externalRestApi/model/RestTypeRequest.java @@ -1,5 +1,5 @@ package org.kar.archidata.externalRestApi.model; public enum RestTypeRequest { - GET, POST, PUT, PATCH, DELETE + GET, POST, PUT, PATCH, DELETE, RESTORE, ARCHIVE } diff --git a/src/org/kar/archidata/tools/RESTApi.java b/src/org/kar/archidata/tools/RESTApi.java index d7944ac..d4eb2aa 100644 --- a/src/org/kar/archidata/tools/RESTApi.java +++ b/src/org/kar/archidata/tools/RESTApi.java @@ -222,13 +222,66 @@ public class RESTApi { */ public T delete(final Class clazz, final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + return simpleRequest("DELETE", clazz, urlOffset); + } + + /** + * Call an ARCHIVE on a REST API + * @param urlOffset Offset to call the API + */ + public void archive(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + archive(Void.class, urlOffset); + } + + /** + * Call a ARCHIVE on a REST API with retrieving some data + * @param Type of data that might be received. + * @param clazz Class model of the data that might be parsed. + * @param urlOffset Offset to call the API + * @return The parsed object received. + */ + public T archive(final Class clazz, final String urlOffset) + throws RESTErrorResponseExeption, IOException, InterruptedException { + return simpleRequest("ARCHIVE", clazz, urlOffset); + } + + /** + * Call an RESTORE on a REST API + * @param urlOffset Offset to call the API + */ + public void restore(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + restore(Void.class, urlOffset); + } + + /** + * Call a RESTORE on a REST API with retrieving some data + * @param Type of data that might be received. + * @param clazz Class model of the data that might be parsed. + * @param urlOffset Offset to call the API + * @return The parsed object received. + */ + public T restore(final Class clazz, final String urlOffset) + throws RESTErrorResponseExeption, IOException, InterruptedException { + return simpleRequest("RESTORE", clazz, urlOffset); + } + + /** + * Call a key on a REST API with retrieving some data + * @param Type of data that might be received. + * @param model name of the key for the REST call + * @param clazz Class model of the data that might be parsed. + * @param urlOffset Offset to call the API + * @return The parsed object received. + */ + public T simpleRequest(final String model, final Class clazz, final String urlOffset) + throws RESTErrorResponseExeption, IOException, InterruptedException { final HttpClient client = HttpClient.newHttpClient(); Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1) .uri(URI.create(this.baseUrl + urlOffset)); if (this.token != null) { requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token); } - final HttpRequest request = requestBuilding.DELETE().build(); + final HttpRequest request = requestBuilding.method(model, BodyPublishers.ofString("")).build(); final HttpResponse httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) { try {