Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the provenance file from the dataset #4

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import ch.systemsx.cisd.etlserver.registrator.api.v2.IDataSetRegistrationTransactionV2;
import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISampleImmutable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import life.qbic.registration.openbis.exceptions.fail.MeasurementHasDataException;
import life.qbic.registration.openbis.exceptions.fail.UnknownSampleTypeException;
import life.qbic.registration.openbis.types.QDatasetType;
Expand Down Expand Up @@ -50,8 +52,9 @@ public boolean shouldRetryProcessing(DataSetRegistrationContext context, Excepti

@Override
public void process(IDataSetRegistrationTransactionV2 transaction) {
File provenanceFile = new File(transaction.getIncoming(), PROVENANCE_FILE_NAME);
DataSetProvenance dataSetProvenance = ProvenanceParser.parseProvenanceJson(
new File(transaction.getIncoming(), PROVENANCE_FILE_NAME));
provenanceFile);

String measurementId = dataSetProvenance.measurementId();

Expand All @@ -68,8 +71,24 @@ public void process(IDataSetRegistrationTransactionV2 transaction) {
newDataSet.setPropertyValue(QPropertyType.Q_TASK_ID.getOpenBisPropertyName(), dataSetProvenance.taskId());
QDatasetType qDatasetType = getDatasetType(measurementSample);
newDataSet.setDataSetType(qDatasetType.name());
moveFiles(transaction, newDataSet, provenanceFile);

transaction.moveFile(transaction.getIncoming().getAbsolutePath(), newDataSet);
}

private void moveFiles(IDataSetRegistrationTransactionV2 transactionV2, IDataSet dataSet, File provenanceFile) {

try {
var buffer = Files.readAllBytes(provenanceFile.toPath().toAbsolutePath());
Files.delete(provenanceFile.toPath());
try {
transactionV2.moveFile(transactionV2.getIncoming().getAbsolutePath(), dataSet);
} catch (Exception e) {
Files.write(provenanceFile.toPath().toAbsolutePath(), buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm like 99% sure openBIS will automatically recover deleted files (I think it stores a copy of the original folder) on failure, so I advise against writing anything after an exception the ETL service - I'm not sure how this will influence the behaviour

throw new RuntimeException(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static QDatasetType getDatasetType(ISampleImmutable measurementSample) {
Expand Down