Skip to content

Commit

Permalink
Write measurement ID into provenance file
Browse files Browse the repository at this point in the history
  • Loading branch information
sven1103 committed Apr 16, 2024
1 parent 2c2e892 commit 7b00866
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/life/qbic/data/processing/Provenance.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Provenance {
@JsonProperty("user")
public String userWorkDirectoryPath;

@JsonProperty("measurementId")
public String qbicMeasurementID;

/**
* A list of ordered processing folder stops the dataset has traversed and passed successfully.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.apache.logging.log4j.LogManager.getLogger;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -149,6 +150,14 @@ private void evaluateDirectory(File taskDir) {
Matcher matcher = measurementIdPattern.matcher(dataset.getName());
var measurementIdResult = matcher.results().map(MatchResult::group).findFirst();
if (measurementIdResult.isPresent()) {
provenance.qbicMeasurementID = measurementIdResult.get();
provenance.addToHistory(taskDir.getAbsolutePath());
try {
updateProvenanceFile(provenanceSearch.get(), provenance);
} catch (IOException e) {
LOG.error("Could not update provenance file: %s".formatted(taskDir.getAbsolutePath()), e);
moveToSystemIntervention(taskDir, e.getMessage());
}
moveToTargetDir(taskDir);
try {
createMarkerFile(targetDirectory, taskDir.getName());
Expand All @@ -166,6 +175,11 @@ private void evaluateDirectory(File taskDir) {
moveBackToOrigin(taskDir, provenance, errorMessage.toString());
}

private void updateProvenanceFile(File provenanceFile, Provenance provenance) throws IOException {
var mapper = new ObjectMapper();
mapper.writerWithDefaultPrettyPrinter().writeValue(provenanceFile, provenance);
}

private boolean createMarkerFile(Path targetDirectory, String name) throws IOException {
Path markerFileName = Paths.get(".MARKER_is_finished_" + name);
return targetDirectory.resolve(markerFileName).toFile().createNewFile();
Expand Down

0 comments on commit 7b00866

Please sign in to comment.