Skip to content

Commit

Permalink
Implement Delete For Rest Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Dec 18, 2024
1 parent d5c1849 commit 63c8404
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -149,7 +148,7 @@ public record FieldDataExternalDataIDs(
HashMap<ExternalDataIdentifier, Vector<KeyValue>> externalDataIDSimRefs
) { }

public record SaveFieldDataFromFile(
public record AnalyzedResultsFromFieldData(
short[][][] shortSpecData, //[time][var][data]
String[] varNames,
double[] times,
Expand All @@ -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;
Expand Down

0 comments on commit 63c8404

Please sign in to comment.