generated from qbicsoftware/spring-boot-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
180 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/life/qbic/registration/openbis/OpenBisSearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/life/qbic/registration/openbis/OpenBisSearchImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.ToManyMeasurementsException; | ||
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<ISampleImmutable> immutableSamples = searchService.searchForSamples( | ||
measurementSearchCriteria); | ||
|
||
if (immutableSamples.isEmpty()) { | ||
//measurement not found | ||
throw new NoMeasurementsFoundException("Measurement '" + measurementId + "' not found"); | ||
} | ||
if (immutableSamples.size() > 1) { | ||
throw new ToManyMeasurementsException( | ||
"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<IDataSetImmutable> existingDataSets = searchService.searchForDataSets( | ||
dataSetSearchCriteria); | ||
return !existingDataSets.isEmpty(); | ||
} | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/life/qbic/registration/openbis/ProvenanceParserTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package life.qbic.registration.openbis | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* TODO! | ||
* <b>short description</b> | ||
* | ||
* <p>detailed description</p> | ||
* | ||
* @since <version tag> | ||
*/ | ||
class ProvenanceParserTest extends Specification { | ||
|
||
final File validFile = new File(ProvenanceParserTest.class.getClassLoader().getResource("valid-provenance.json").toURI()); | ||
|
||
def "parsing just works"() { | ||
when: | ||
var resultingProvenanceObject = new ProvenanceParser().parseProvenanceJson(validFile) | ||
then: | ||
resultingProvenanceObject.measurementId() == "NGSQTEST001AE-1234512312" | ||
resultingProvenanceObject.origin() == "/Users/myuser/registration" | ||
resultingProvenanceObject.datasetFiles() == ["file1.fastq.gz", "file2.fastq.gz"] | ||
resultingProvenanceObject.user() == "/Users/myuser" | ||
resultingProvenanceObject.taskId() == "ce36775e-0d06-471e-baa7-1e3b63de871f" | ||
resultingProvenanceObject.history() == ["/some/dir", "/some/other/dir"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |