From 579eb5afb5430701ad333bd40a1a6576da2ac053 Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Tue, 7 Jan 2025 08:11:00 -0500 Subject: [PATCH] Update N5 Hash Function Names --- .../export/server/ExportServiceImpl.java | 2 +- .../cbit/vcell/export/server/N5Exporter.java | 25 ++++++++++--------- .../cbit/vcell/export/N5ExporterTest.java | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/export/server/ExportServiceImpl.java b/vcell-core/src/main/java/cbit/vcell/export/server/ExportServiceImpl.java index cc42dcb1b7..3e68b7dc6c 100644 --- a/vcell-core/src/main/java/cbit/vcell/export/server/ExportServiceImpl.java +++ b/vcell-core/src/main/java/cbit/vcell/export/server/ExportServiceImpl.java @@ -315,7 +315,7 @@ public ExportEvent makeRemoteFile(OutputContext outputContext,User user, DataSer case N5: N5Exporter n5Exporter = new N5Exporter(this, user, dataServerImpl, (VCSimulationDataIdentifier) exportSpecs.getVCDataIdentifier()); ExportOutput exportOutput = n5Exporter.makeN5Data(outputContext, newExportJob, exportSpecs, fileDataContainerManager); - return makeRemoteN5File(fileFormat, n5Exporter.getN5FileNameHash(), exportOutput, exportSpecs, newExportJob, n5Exporter.getN5FilePathSuffix()); + return makeRemoteN5File(fileFormat, n5Exporter.getN5FileHash(), exportOutput, exportSpecs, newExportJob, n5Exporter.getN5BucketPath()); default: throw new DataAccessException("Unknown export format requested"); } diff --git a/vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java b/vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java index ff1e56f0c5..4d9c9f4a1d 100644 --- a/vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java +++ b/vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java @@ -45,12 +45,12 @@ public class N5Exporter implements ExportConstants { private ExportServiceImpl exportServiceImpl = null; - private DataServerImpl dataServer; + private final DataServerImpl dataServer; - private VCSimulationDataIdentifier vcDataID; + private final VCSimulationDataIdentifier vcDataID; public String n5BucketName = "n5Data"; - private User user; + private final User user; public static final ArrayList unsupportedTypes = new ArrayList<>(Arrays.asList( VariableType.MEMBRANE, @@ -90,7 +90,7 @@ private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs int[] blockSize = {sizeX, sizeY, 1, 1, 1}; // rewrite so that it still results in a tmp file does not raise File already exists error - N5FSWriter n5FSWriter = new N5FSWriter(getN5FileAbsolutePath(), new GsonBuilder()); + N5FSWriter n5FSWriter = new N5FSWriter(getN5FileSystemPath(), new GsonBuilder()); DatasetAttributes datasetAttributes = new DatasetAttributes(dimensions, blockSize, org.janelia.saalfeldlab.n5.DataType.FLOAT64, n5Specs.getCompression()); n5FSWriter.createDataset(String.valueOf(jobID), datasetAttributes); @@ -183,7 +183,7 @@ private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs exportSpecs.getHumanReadableExportData().numChannels = (int) dimensions[2]; exportSpecs.getHumanReadableExportData().zSlices = (int) dimensions[3]; exportSpecs.getHumanReadableExportData().tSlices = (int) dimensions[4]; - ExportOutput exportOutput = new ExportOutput(true, "." + N5Specs.n5Suffix, vcDataID.getID(), getN5FileNameHash(), fileDataContainerManager); + ExportOutput exportOutput = new ExportOutput(true, "." + N5Specs.n5Suffix, vcDataID.getID(), getN5FileHash(), fileDataContainerManager); return exportOutput; } @@ -213,19 +213,20 @@ public DataIdentifier getSpecificDI(String diName, OutputContext outputContext) return null; } - public String getN5FileAbsolutePath(){ - File outPutDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.n5DataDir) + "/" + getN5FilePathSuffix()); + public String getN5FileSystemPath(){ + File outPutDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.n5DataDir) + "/" + getN5BucketPath()); return outPutDir.getAbsolutePath(); } - public String getN5FilePathSuffix(){ - return n5BucketName + "/" + user.getName() + "/" + this.getN5FileNameHash() + "." + N5Specs.n5Suffix; + public String getN5BucketPath(){ + return n5BucketName + "/" + user.getName() + "/" + this.getN5FileHash() + "." + N5Specs.n5Suffix; } - public String getN5FileNameHash(){ - return actualHash(vcDataID.getDataKey().toString(), String.valueOf(vcDataID.getJobIndex())); + public String getN5FileHash(){ + return hashFunction(vcDataID.getDataKey().toString()); } - private static String actualHash(String simID, String jobID) { + + private static String hashFunction(String simID) { MessageDigest sha256 = DigestUtils.getMd5Digest(); sha256.update(simID.getBytes(StandardCharsets.UTF_8)); String hashString = Hex.encodeHexString(sha256.digest()); diff --git a/vcell-core/src/test/java/cbit/vcell/export/N5ExporterTest.java b/vcell-core/src/test/java/cbit/vcell/export/N5ExporterTest.java index 4a6fee1aff..271deadd55 100644 --- a/vcell-core/src/test/java/cbit/vcell/export/N5ExporterTest.java +++ b/vcell-core/src/test/java/cbit/vcell/export/N5ExporterTest.java @@ -193,7 +193,7 @@ public void makeN5FileWithSpecificSimulationResults(N5Specs.CompressionLevel com if(n5Reader != null){ n5Reader.close(); } - this.n5Reader = new N5FSReader(n5Exporter.getN5FileAbsolutePath()); + this.n5Reader = new N5FSReader(n5Exporter.getN5FileSystemPath()); } private void setExportTestState(TestModels simModel) throws IOException, DataAccessException, MathException {