readMessagesFromClassPath(String path) {
- URL url = getClass().getClassLoader().getResource(path)
- return url.readLines().each { it.trim() }.collect()
- }
-}
diff --git a/src/main/groovy/life/qbic/springminimaltemplate/DeveloperNews.groovy b/src/main/groovy/life/qbic/springminimaltemplate/DeveloperNews.groovy
deleted file mode 100644
index 04ed5d1..0000000
--- a/src/main/groovy/life/qbic/springminimaltemplate/DeveloperNews.groovy
+++ /dev/null
@@ -1,20 +0,0 @@
-package life.qbic.springminimaltemplate
-
-/**
- * An example {@link NewsMedia} implementation for developer news.
- *
- * @since 0.1.0
- */
-class DeveloperNews implements NewsMedia {
-
- private MessageService service
-
- DeveloperNews(MessageService service) {
- this.service = service
- }
-
- @Override
- String getNews() {
- return service.collectMessage()
- }
-}
diff --git a/src/main/groovy/life/qbic/springminimaltemplate/MessageService.groovy b/src/main/groovy/life/qbic/springminimaltemplate/MessageService.groovy
deleted file mode 100644
index eaadf3e..0000000
--- a/src/main/groovy/life/qbic/springminimaltemplate/MessageService.groovy
+++ /dev/null
@@ -1,18 +0,0 @@
-package life.qbic.springminimaltemplate
-
-/**
- * Small toy interface that represents message services
- *
- * Message services shall provide access to received messages.
- *
- * @since 0.1.0
- */
-interface MessageService {
-
- /**
- * Collects the latest message
- * @return the latest message
- * @since 0.1.0
- */
- String collectMessage()
-}
diff --git a/src/main/groovy/life/qbic/springminimaltemplate/NewsMedia.groovy b/src/main/groovy/life/qbic/springminimaltemplate/NewsMedia.groovy
deleted file mode 100644
index d335196..0000000
--- a/src/main/groovy/life/qbic/springminimaltemplate/NewsMedia.groovy
+++ /dev/null
@@ -1,17 +0,0 @@
-package life.qbic.springminimaltemplate
-
-/**
- * Example interface for a news media
- *
- * @since 0.1.0
- */
-interface NewsMedia {
-
- /**
- * Returns latest news
- * @return news stuff!
- * @since 0.1.0
- */
- String getNews()
-
-}
\ No newline at end of file
diff --git a/src/main/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplication.groovy b/src/main/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplication.groovy
deleted file mode 100644
index e9ba274..0000000
--- a/src/main/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplication.groovy
+++ /dev/null
@@ -1,23 +0,0 @@
-package life.qbic.springminimaltemplate
-
-import org.springframework.boot.SpringApplication
-import org.springframework.boot.autoconfigure.SpringBootApplication
-import org.springframework.context.annotation.AnnotationConfigApplicationContext
-
-@SpringBootApplication
-class SpringMinimalTemplateApplication {
-
- static void main(String[] args) {
- SpringApplication.run(SpringMinimalTemplateApplication, args)
-
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class)
-
- NewsMedia media = context.getBean("newsMedia", NewsMedia.class)
- println "####################### Message of the day ##################"
- println media.getNews()
- println "##############################################################"
-
- context.close()
- }
-
-}
diff --git a/src/main/java/life/qbic/registration/openbis/DataSetProvenance.java b/src/main/java/life/qbic/registration/openbis/DataSetProvenance.java
new file mode 100644
index 0000000..aa82b8b
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/DataSetProvenance.java
@@ -0,0 +1,94 @@
+package life.qbic.registration.openbis;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * Class holding provenance information provided by the user. This is a record of immutable data.
+ *
+ * @since 1.0.0
+ */
+public class DataSetProvenance implements Serializable {
+
+ private static final long serialVersionUID = -1597156104025439195L;
+
+ @JsonProperty("origin")
+ private String origin;
+ @JsonProperty("user")
+ private String user;
+ @JsonProperty("measurementId")
+ private String measurementId;
+ @JsonProperty("datasetFiles")
+ private String[] datasetFiles;
+ @JsonProperty("taskId")
+ private String taskId;
+ @JsonProperty("history")
+ private String[] history;
+
+
+ private DataSetProvenance() {
+
+ }
+ public DataSetProvenance(String origin, String user, String measurementId, String[] datasetFiles,
+ String taskId, String[] history) {
+ this.origin = origin;
+ this.user = user;
+ this.measurementId = measurementId;
+ this.datasetFiles = datasetFiles;
+ this.taskId = taskId;
+ this.history = history;
+ }
+
+ public String origin() {
+ return origin;
+ }
+
+ public String user() {
+ return user;
+ }
+
+ public String measurementId() {
+ return measurementId;
+ }
+
+ public String[] datasetFiles() {
+ return datasetFiles;
+ }
+
+ public String taskId() {
+ return taskId;
+ }
+
+ public String[] history() {
+ return history;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof DataSetProvenance)) {
+ return false;
+ }
+
+ DataSetProvenance that = (DataSetProvenance) o;
+ return Objects.equals(origin, that.origin) && Objects.equals(user, that.user)
+ && Objects.equals(measurementId, that.measurementId) && Arrays.equals(
+ datasetFiles, that.datasetFiles) && Objects.equals(taskId, that.taskId)
+ && Arrays.equals(history, that.history);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Objects.hashCode(origin);
+ result = 31 * result + Objects.hashCode(user);
+ result = 31 * result + Objects.hashCode(measurementId);
+ result = 31 * result + Arrays.hashCode(datasetFiles);
+ result = 31 * result + Objects.hashCode(taskId);
+ result = 31 * result + Arrays.hashCode(history);
+ return result;
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/OpenBisDropboxETL.java b/src/main/java/life/qbic/registration/openbis/OpenBisDropboxETL.java
new file mode 100644
index 0000000..be29f86
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/OpenBisDropboxETL.java
@@ -0,0 +1,81 @@
+package life.qbic.registration.openbis;
+
+import ch.systemsx.cisd.common.exceptions.NotImplementedException;
+import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationContext;
+import ch.systemsx.cisd.etlserver.registrator.api.v2.AbstractJavaDataSetRegistrationDropboxV2;
+import ch.systemsx.cisd.etlserver.registrator.api.v2.IDataSet;
+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 life.qbic.registration.openbis.exceptions.fail.MeasurementHasDataException;
+import life.qbic.registration.openbis.exceptions.fail.UnknownSampleTypeException;
+import life.qbic.registration.openbis.types.QDatasetType;
+import life.qbic.registration.openbis.types.QPropertyType;
+import life.qbic.registration.openbis.types.QSampleType;
+
+/**
+ * The Dropbox ETL process.
+ *
+ * This process is responsible for
+ *
+ * - fetching the measurement sample from openbis
+ *
- creating a data set linked to the sample
+ *
- moving files into the dataset
+ *
+ * Some constraints are taken care of during this process. These constraints being:
+ *
+ * - the measurement sample already exists in openbis
+ *
- only one measurement sample exists with the provided identifier
+ *
- the measurement sample has no data set linked as one measurement can only have one dataset.
+ *
+ *
+ * @version 1.0.0
+ */
+public class OpenBisDropboxETL extends AbstractJavaDataSetRegistrationDropboxV2 {
+
+ private static final String PROVENANCE_FILE_NAME = "provenance.json";
+
+ public OpenBisDropboxETL(){
+ }
+
+
+ public interface WithRetryOption {
+ }
+
+ @Override
+ public boolean shouldRetryProcessing(DataSetRegistrationContext context, Exception problem)
+ throws NotImplementedException {
+ return problem instanceof WithRetryOption || super.shouldRetryProcessing(context, problem);
+ }
+
+ @Override
+ public void process(IDataSetRegistrationTransactionV2 transaction) {
+ DataSetProvenance dataSetProvenance = ProvenanceParser.parseProvenanceJson(
+ new File(transaction.getIncoming(), PROVENANCE_FILE_NAME));
+
+ String measurementId = dataSetProvenance.measurementId();
+
+ OpenBisSearchImpl openBisSearch = new OpenBisSearchImpl(transaction.getSearchService());
+
+ ISampleImmutable measurementSample = openBisSearch.getMeasurementSample(measurementId);
+
+ if (openBisSearch.doesMeasurementHaveData(measurementSample)) {
+ throw new MeasurementHasDataException("Measurement " + measurementId + " has data attached.");
+ }
+ IDataSet newDataSet = transaction.createNewDataSet();
+ newDataSet.setSample(measurementSample);
+ newDataSet.setPropertyValue(QPropertyType.Q_SUBMITTER.getOpenBisPropertyName(), dataSetProvenance.user());
+ newDataSet.setPropertyValue(QPropertyType.Q_TASK_ID.getOpenBisPropertyName(), dataSetProvenance.taskId());
+ QDatasetType qDatasetType = getDatasetType(measurementSample);
+ newDataSet.setDataSetType(qDatasetType.name());
+
+ transaction.moveFile(transaction.getIncoming().getAbsolutePath(), newDataSet);
+ }
+
+ private static QDatasetType getDatasetType(ISampleImmutable measurementSample) {
+ QSampleType qSampleType = QSampleType.lookup(measurementSample.getSampleType())
+ .orElseThrow(() -> new UnknownSampleTypeException(
+ "Unknown sample type: " + measurementSample.getSampleType()));
+ return QDatasetType.fromQSampleType(qSampleType);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/OpenBisSearch.java b/src/main/java/life/qbic/registration/openbis/OpenBisSearch.java
new file mode 100644
index 0000000..93dd6da
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/OpenBisSearch.java
@@ -0,0 +1,24 @@
+package life.qbic.registration.openbis;
+
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISampleImmutable;
+
+/**
+ * Interface that allows for searching openbis infrastructure
+ */
+public interface OpenBisSearch {
+
+ /**
+ * Searches for a sample with the measurement code in openbis. Assumes that there is one sample and only one; Fails otherwise.
+ * @param measurementId the identifier of the measurement
+ * @return the existing measurement
+ */
+ ISampleImmutable getMeasurementSample(String measurementId);
+
+ /**
+ * Checks for datasets attached to a measurement sample
+ * @param measurementSample
+ * @return true if a dataset is contained in the measurement; false otherwise.
+ */
+ boolean doesMeasurementHaveData(ISampleImmutable measurementSample);
+
+}
diff --git a/src/main/java/life/qbic/registration/openbis/OpenBisSearchImpl.java b/src/main/java/life/qbic/registration/openbis/OpenBisSearchImpl.java
new file mode 100644
index 0000000..ad95d63
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/OpenBisSearchImpl.java
@@ -0,0 +1,69 @@
+package life.qbic.registration.openbis;
+
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.IDataSetImmutable;
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISampleImmutable;
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISearchService;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseAttribute;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchSubCriteria;
+import java.util.List;
+import life.qbic.registration.openbis.exceptions.fail.TooManyMeasurementsException;
+import life.qbic.registration.openbis.exceptions.retry.NoMeasurementsFoundException;
+
+/**
+ * Implements the Openbis access
+ */
+public class OpenBisSearchImpl implements OpenBisSearch {
+
+ private final ISearchService searchService;
+
+ public OpenBisSearchImpl(ISearchService searchService) {
+ this.searchService = searchService;
+ }
+
+ @Override
+ public ISampleImmutable getMeasurementSample(String measurementId) {
+ return findMeasurementSample(measurementId, searchService);
+ }
+
+ private static ISampleImmutable findMeasurementSample(String measurementId,
+ ISearchService searchService) {
+ SearchCriteria measurementSearchCriteria = new SearchCriteria();
+ measurementSearchCriteria.addMatchClause(
+ MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, measurementId));
+ List immutableSamples = searchService.searchForSamples(
+ measurementSearchCriteria);
+
+ if (immutableSamples.isEmpty()) {
+ //measurement not found
+ throw new NoMeasurementsFoundException("Measurement '" + measurementId + "' not found");
+ }
+ if (immutableSamples.size() > 1) {
+ throw new TooManyMeasurementsException(
+ "Multiple measurement with id '" + measurementId + "' found");
+ }
+ return immutableSamples.get(0);
+ }
+
+ @Override
+ public boolean doesMeasurementHaveData(ISampleImmutable sample) {
+ return doesMeasurementHaveData(sample, searchService);
+ }
+
+ private static boolean doesMeasurementHaveData(ISampleImmutable sample,
+ ISearchService searchService) {
+ SearchCriteria parentSampleSearchCriteria = new SearchCriteria();
+ parentSampleSearchCriteria.addMatchClause(
+ MatchClause.createAttributeMatch(MatchClauseAttribute.PERM_ID, sample.getPermId()));
+
+ SearchCriteria dataSetSearchCriteria = new SearchCriteria();
+ dataSetSearchCriteria.addSubCriteria(
+ SearchSubCriteria.createDataSetContainerCriteria(parentSampleSearchCriteria));
+ List existingDataSets = searchService.searchForDataSets(
+ dataSetSearchCriteria);
+ return !existingDataSets.isEmpty();
+ }
+
+
+}
diff --git a/src/main/java/life/qbic/registration/openbis/ProvenanceParser.java b/src/main/java/life/qbic/registration/openbis/ProvenanceParser.java
new file mode 100644
index 0000000..b46e69e
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/ProvenanceParser.java
@@ -0,0 +1,26 @@
+package life.qbic.registration.openbis;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.File;
+import java.io.IOException;
+import life.qbic.registration.openbis.exceptions.fail.ProvenanceParseException;
+
+/**
+ * Parses a provenance file and produces a java object from it.
+ */
+public class ProvenanceParser {
+
+
+ private static final Class DATA_SET_PROVENANCE_CLASS = DataSetProvenance.class;
+
+ static DataSetProvenance parseProvenanceJson(File provenanceFile) {
+ try {
+ return new ObjectMapper().readValue(provenanceFile,
+ DATA_SET_PROVENANCE_CLASS);
+ } catch (IOException e) {
+ throw new ProvenanceParseException(
+ "Could not parse '" + provenanceFile.getAbsolutePath() + "'", e);
+ }
+ }
+
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/fail/DatasetTypeMappingException.java b/src/main/java/life/qbic/registration/openbis/exceptions/fail/DatasetTypeMappingException.java
new file mode 100644
index 0000000..675debb
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/fail/DatasetTypeMappingException.java
@@ -0,0 +1,10 @@
+package life.qbic.registration.openbis.exceptions.fail;
+
+/**
+ * Thrown when the dataset type cannot be determined.
+ */
+public class DatasetTypeMappingException extends RuntimeException {
+ public DatasetTypeMappingException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/fail/MeasurementHasDataException.java b/src/main/java/life/qbic/registration/openbis/exceptions/fail/MeasurementHasDataException.java
new file mode 100644
index 0000000..cf8c7c9
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/fail/MeasurementHasDataException.java
@@ -0,0 +1,10 @@
+package life.qbic.registration.openbis.exceptions.fail;
+
+/**
+ * Thrown when a measurement has data already attached and this breaks an assumption.
+ */
+public class MeasurementHasDataException extends RuntimeException {
+ public MeasurementHasDataException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/fail/ProvenanceParseException.java b/src/main/java/life/qbic/registration/openbis/exceptions/fail/ProvenanceParseException.java
new file mode 100644
index 0000000..8c9cb86
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/fail/ProvenanceParseException.java
@@ -0,0 +1,10 @@
+package life.qbic.registration.openbis.exceptions.fail;
+
+/**
+ * Thrown when the provenance file does not match the expected format.
+ */
+public class ProvenanceParseException extends RuntimeException {
+ public ProvenanceParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/fail/TooManyMeasurementsException.java b/src/main/java/life/qbic/registration/openbis/exceptions/fail/TooManyMeasurementsException.java
new file mode 100644
index 0000000..bd4595b
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/fail/TooManyMeasurementsException.java
@@ -0,0 +1,10 @@
+package life.qbic.registration.openbis.exceptions.fail;
+
+/**
+ * Thrown when multiple measurements exist where only one is expected.
+ */
+public class TooManyMeasurementsException extends RuntimeException {
+ public TooManyMeasurementsException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/fail/UnknownSampleTypeException.java b/src/main/java/life/qbic/registration/openbis/exceptions/fail/UnknownSampleTypeException.java
new file mode 100644
index 0000000..d0d2414
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/fail/UnknownSampleTypeException.java
@@ -0,0 +1,10 @@
+package life.qbic.registration.openbis.exceptions.fail;
+
+/**
+ * Thrown when the ETL is not able to parse the sample type or no sample type was provided.
+ */
+public class UnknownSampleTypeException extends RuntimeException {
+ public UnknownSampleTypeException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/exceptions/retry/NoMeasurementsFoundException.java b/src/main/java/life/qbic/registration/openbis/exceptions/retry/NoMeasurementsFoundException.java
new file mode 100644
index 0000000..ff9af6b
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/exceptions/retry/NoMeasurementsFoundException.java
@@ -0,0 +1,13 @@
+package life.qbic.registration.openbis.exceptions.retry;
+
+import life.qbic.registration.openbis.OpenBisDropboxETL.WithRetryOption;
+
+/**
+ * Thrown whenever a measurement was not found even if it is assumed to be there.
+ */
+public class NoMeasurementsFoundException extends RuntimeException implements
+ WithRetryOption {
+ public NoMeasurementsFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/types/QDatasetType.java b/src/main/java/life/qbic/registration/openbis/types/QDatasetType.java
new file mode 100644
index 0000000..b2b5c4e
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/types/QDatasetType.java
@@ -0,0 +1,44 @@
+package life.qbic.registration.openbis.types;
+
+import java.util.Objects;
+import life.qbic.registration.openbis.exceptions.fail.DatasetTypeMappingException;
+
+/**
+ * Controlled vocabulary for openBiS dataset types
+ *
+ * @since 1.0.0
+ */
+public enum QDatasetType {
+
+ Q_NGS_RAW_DATA("Q_NGS_RAW_DATA"),
+ Q_PROTEOMICS_RAW_DATA("Q_PROTEOMICS_RAW_DATA"),
+ ;
+
+ private final String openBisPropertyName;
+
+ QDatasetType(String openBisPropertyName) {
+ this.openBisPropertyName = openBisPropertyName;
+ }
+
+ public String getOpenBisPropertyName() {
+ return openBisPropertyName;
+ }
+
+ public static QDatasetType fromQSampleType(QSampleType qSampleType) {
+// If this was Java 17+ the following code would easily solve the issue.
+ /*
+ return switch (qSampleType) {
+ case Q_NGS_MEASUREMENT -> Q_NGS_RAW_DATA;
+ case Q_PROTEOMICS_MEASUREMENT -> Q_PROTEOMICS_RAW_DATA;
+ };
+ */
+
+ if (Objects.requireNonNull(qSampleType) == QSampleType.Q_NGS_MEASUREMENT) {
+ return Q_NGS_RAW_DATA;
+ } else if (qSampleType == QSampleType.Q_PROTEOMICS_MEASUREMENT) {
+ return Q_PROTEOMICS_RAW_DATA;
+ }
+ throw new DatasetTypeMappingException("Unknown sample type to dataset type mapping. Cannot map " + qSampleType);
+ }
+
+}
diff --git a/src/main/java/life/qbic/registration/openbis/types/QPropertyType.java b/src/main/java/life/qbic/registration/openbis/types/QPropertyType.java
new file mode 100644
index 0000000..aeb7f42
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/types/QPropertyType.java
@@ -0,0 +1,42 @@
+package life.qbic.registration.openbis.types;
+
+import java.util.Optional;
+
+/**
+ * Controlled vocabulary for openBIS property types
+ *
+ * @since 1.0.0
+ */
+public enum QPropertyType {
+ Q_SUBMITTER("Q_SUBMITTER"),
+ Q_TASK_ID("Q_TASK_ID"),
+ ;
+
+ private final String openBisPropertyName;
+
+ QPropertyType(String openBisPropertyName) {
+ this.openBisPropertyName = openBisPropertyName;
+ }
+
+ public String getOpenBisPropertyName() {
+ return openBisPropertyName;
+ }
+
+ /**
+ * Looks up the enum of a given name. If none match, an empty optional is returned.
+ * @param name the name of the enum
+ * @return an optional containing the matching enum if any.
+ */
+ public static Optional lookup(String name) {
+ try {
+ return Optional.of(valueOf(name));
+ } catch (IllegalArgumentException e) {
+ for (var value : values()) {
+ if (value.openBisPropertyName.equals(name)) {
+ return Optional.of(value);
+ }
+ }
+ }
+ return Optional.empty();
+ }
+}
diff --git a/src/main/java/life/qbic/registration/openbis/types/QSampleType.java b/src/main/java/life/qbic/registration/openbis/types/QSampleType.java
new file mode 100644
index 0000000..99b9895
--- /dev/null
+++ b/src/main/java/life/qbic/registration/openbis/types/QSampleType.java
@@ -0,0 +1,37 @@
+package life.qbic.registration.openbis.types;
+
+import java.util.Optional;
+
+/**
+ * Controlled vocabulary for openBIS sample types
+ *
+ * @since 1.0.0
+ */
+public enum QSampleType {
+ Q_NGS_MEASUREMENT("Q_NGS_MEASUREMENT"),
+ Q_PROTEOMICS_MEASUREMENT("Q_PROTEOMICS_MEASUREMENT");
+
+ private final String openBisTypeName;
+
+ QSampleType(String openBisTypeName) {
+ this.openBisTypeName = openBisTypeName;
+ }
+
+ /**
+ * Looks up the enum of a given name. If none match, an empty optional is returned.
+ * @param name the name of the enum
+ * @return an optional containing the matching enum if any.
+ */
+ public static Optional lookup(String name) {
+ try {
+ return Optional.of(valueOf(name));
+ } catch (IllegalArgumentException e) {
+ for (QSampleType value : values()) {
+ if (value.openBisTypeName.equals(name)) {
+ return Optional.of(value);
+ }
+ }
+ }
+ return Optional.empty();
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
deleted file mode 100644
index 43f0696..0000000
--- a/src/main/resources/application.properties
+++ /dev/null
@@ -1 +0,0 @@
-messages.file=messages.txt
diff --git a/src/main/resources/messages.txt b/src/main/resources/messages.txt
deleted file mode 100644
index 76dab38..0000000
--- a/src/main/resources/messages.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Have you written unit tests yet? If not, do it!
-Keep it simple!
-Remember the single responsibility principle!
-Clean architecture ftw!
-Favor composition over inheritance!
\ No newline at end of file
diff --git a/src/test/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplicationTests.groovy b/src/test/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplicationTests.groovy
deleted file mode 100644
index f472c3e..0000000
--- a/src/test/groovy/life/qbic/springminimaltemplate/SpringMinimalTemplateApplicationTests.groovy
+++ /dev/null
@@ -1,26 +0,0 @@
-package life.qbic.springminimaltemplate
-
-import org.junit.jupiter.api.Test
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import spock.lang.Specification
-
-@SpringBootTest
-class SpringMinimalTemplateApplicationTests extends Specification {
-
- @Test
- void contextLoads() {
- }
-
- @Autowired
- private MessageService messageService
-
- def "autowired works"() {
- when:
- String messages = messageService.collectMessage()
- println(messages)
- then:
- messages != null
- }
-
-}
diff --git a/src/test/java/life/qbic/registration/openbis/ProvenanceParserTest.groovy b/src/test/java/life/qbic/registration/openbis/ProvenanceParserTest.groovy
new file mode 100644
index 0000000..38b6936
--- /dev/null
+++ b/src/test/java/life/qbic/registration/openbis/ProvenanceParserTest.groovy
@@ -0,0 +1,25 @@
+package life.qbic.registration.openbis
+
+import spock.lang.Specification
+
+class ProvenanceParserTest extends Specification {
+
+ final File validFile = new File(ProvenanceParserTest.class.getClassLoader().getResource("valid-provenance.json").toURI());
+
+ def "parsing a valid file works"() {
+ when:
+ var resultingProvenanceObject = ProvenanceParser.parseProvenanceJson(validFile)
+ then:
+ resultingProvenanceObject.measurementId() == "NGSQTEST001AE-1234512312"
+ and:
+ resultingProvenanceObject.origin() == "/Users/myuser/registration"
+ and:
+ resultingProvenanceObject.datasetFiles() == ["file1.fastq.gz", "file2.fastq.gz"]
+ and:
+ resultingProvenanceObject.user() == "/Users/myuser"
+ and:
+ resultingProvenanceObject.taskId() == "ce36775e-0d06-471e-baa7-1e3b63de871f"
+ and:
+ resultingProvenanceObject.history() == ["/some/dir", "/some/other/dir"]
+ }
+}
diff --git a/src/test/resources/valid-provenance.json b/src/test/resources/valid-provenance.json
new file mode 100644
index 0000000..99ebbfd
--- /dev/null
+++ b/src/test/resources/valid-provenance.json
@@ -0,0 +1,14 @@
+{
+ "origin": "/Users/myuser/registration",
+ "user": "/Users/myuser",
+ "measurementId": "NGSQTEST001AE-1234512312",
+ "datasetFiles" : [
+ "file1.fastq.gz",
+ "file2.fastq.gz"
+ ],
+ "taskId": "ce36775e-0d06-471e-baa7-1e3b63de871f",
+ "history": [
+ "/some/dir",
+ "/some/other/dir"
+ ]
+}