From 63c84040d41b48fcbc25908c5c3f82d5b93334c3 Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Wed, 18 Dec 2024 13:00:41 -0500 Subject: [PATCH] Implement Delete For Rest Endpoint --- .../restq/handlers/FieldData/FieldDataDB.java | 9 ++--- .../handlers/FieldData/FieldDataResource.java | 34 +++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataDB.java b/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataDB.java index b6b0e456dc..b331993a76 100644 --- a/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataDB.java +++ b/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataDB.java @@ -10,7 +10,6 @@ import cbit.vcell.geometry.RegionImage; import cbit.vcell.math.VariableType; import cbit.vcell.modeldb.DatabaseServerImpl; -import cbit.vcell.resource.PropertyLoader; import cbit.vcell.simdata.DataSetControllerImpl; import cbit.vcell.solvers.CartesianMesh; import jakarta.enterprise.context.ApplicationScoped; @@ -67,7 +66,7 @@ public FieldDataFileOperationSpec generateFieldDataFromFile(InputStream imageFil } - public FieldDataFileOperationResults saveNewFieldDataFromFile(FieldDataResource.SaveFieldDataFromFile saveFieldData, User user) throws DataAccessException, ImageException, DataFormatException { + public FieldDataFileOperationResults saveNewFieldDataFromFile(FieldDataResource.AnalyzedResultsFromFieldData saveFieldData, User user) throws DataAccessException, ImageException, DataFormatException { VariableType[] varTypes = new VariableType[saveFieldData.varNames().length]; @@ -102,8 +101,10 @@ public FieldDataDBOperationResults saveNewFieldDataIntoDB(User user, FieldDataDB return databaseServer.fieldDataDBOperation(user, spec); } - public void deleteFieldData(User user, FieldDataDBOperationSpec spec) throws DataAccessException { - databaseServer.fieldDataDBOperation(user, spec); + public void deleteFieldData(User user, String fieldDataID) throws DataAccessException { + ExternalDataIdentifier edi = new ExternalDataIdentifier(new KeyValue(fieldDataID), user, null); + databaseServer.fieldDataDBOperation(user, FieldDataDBOperationSpec.createDeleteExtDataIDSpec(edi)); // remove from DB + dataSetController.fieldDataFileOperation(FieldDataFileOperationSpec.createDeleteFieldDataFileOperationSpec(edi)); // remove from File System } } diff --git a/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataResource.java b/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataResource.java index 578fc01d59..8a49452d30 100644 --- a/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataResource.java +++ b/vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataResource.java @@ -82,32 +82,33 @@ public ExternalDataIdentifier submitNewFieldDataToDB(FieldDataDBOperationSpec fi } @POST - @Path("/generateFieldDataEstimate") + @Path("/createFieldDataFromFile") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(operationId = "generateFieldDataEstimate") - public FieldDataFileOperationSpec generateFieldDataEstimate(SubmittedFieldDataFile spec){ + public FieldDataFileOperationSpec generateFieldDataEstimate(FieldDataFile fieldDataFile){ try{ - return fieldDataDB.generateFieldDataFromFile(spec.file, spec.fileName); + return fieldDataDB.generateFieldDataFromFile(fieldDataFile.file, fieldDataFile.fileName); } catch (ImageException | DataFormatException | DataAccessException e) { throw new WebApplicationException("Can't create new field data file", 500); } } @POST - @Path("/createFieldDataFromFile") + @Path("/createFieldDataFromFileAlreadyAnalyzed") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - @Operation(operationId = "createNewFieldDataFromFile") - public FieldDataFileOperationResults createNewFieldDataFromFile(SaveFieldDataFromFile saveFieldData){ - FieldDataFileOperationResults fileResults = null; + @Operation(operationId = "createNewFieldDataFromFileAlreadyAnalyzed") + public FieldDataSaveResults createNewFieldDataFromFile(AnalyzedResultsFromFieldData saveFieldData){ + FieldDataSaveResults fieldDataSaveResults; try{ User user = userRestDB.getUserFromIdentity(securityIdentity); - fileResults = fieldDataDB.saveNewFieldDataFromFile(saveFieldData, user); + FieldDataFileOperationResults fileResults = fieldDataDB.saveNewFieldDataFromFile(saveFieldData, user); + fieldDataSaveResults = new FieldDataSaveResults(fileResults.externalDataIdentifier.getName(), fileResults.externalDataIdentifier.getKey().toString()); } catch (ImageException | DataFormatException | DataAccessException e) { throw new WebApplicationException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } - return fileResults; + return fieldDataSaveResults; } @POST @@ -126,12 +127,10 @@ public FieldDataNoCopyConflict copyFieldData(FieldDataDBOperationSpec fieldDataD } @DELETE - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) @Operation(operationId = "deleteFieldData", summary = "Delete the selected field data.") - public void deleteFieldData(FieldDataDBOperationSpec fieldDataDBOperationSpec){ + public void deleteFieldData(String fieldDataID){ try{ - fieldDataDB.deleteFieldData(userRestDB.getUserFromIdentity(securityIdentity), fieldDataDBOperationSpec); + fieldDataDB.deleteFieldData(userRestDB.getUserFromIdentity(securityIdentity), fieldDataID); } catch (DataAccessException e) { throw new WebApplicationException(e.getMessage(), 500); } @@ -149,7 +148,7 @@ public record FieldDataExternalDataIDs( HashMap> externalDataIDSimRefs ) { } - public record SaveFieldDataFromFile( + public record AnalyzedResultsFromFieldData( short[][][] shortSpecData, //[time][var][data] String[] varNames, double[] times, @@ -160,7 +159,12 @@ public record SaveFieldDataFromFile( String name ){ } - public static class SubmittedFieldDataFile { + public record FieldDataSaveResults( + String fieldDataName, + String fieldDataID + ){ } + + public static class FieldDataFile { @FormParam("file") @PartType(MediaType.APPLICATION_OCTET_STREAM) public InputStream file;