Skip to content

Commit 527c528

Browse files
committed
handle file names in provenance and change to structure
1 parent 37966d5 commit 527c528

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

src/main/groovy/life/qbic/registration/MainETL.groovy

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,4 @@ class MainETL extends AbstractJavaDataSetRegistrationDropboxV2 {
3030
}
3131
}
3232

33-
private static Optional<String> getExtractedRootDir(String tmpFolderPath) {
34-
File tmpDir = new File(tmpFolderPath)
35-
String[] childList = tmpDir.list();
36-
if(childList.size() == 1) {
37-
String childPath = tmpDir.getAbsolutePath() + "/" + childList[0];
38-
if (new File(childPath).isDirectory()) {
39-
return Optional.of(childPath)
40-
}
41-
}
42-
return Optional.empty()
43-
}
44-
4533
}

src/main/groovy/life/qbic/registration/Provenance.groovy

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@ package life.qbic.registration
22

33
import groovy.json.JsonSlurper
44

5+
/**
6+
* Example of a provenance file:
7+
* {
8+
"origin": "/Users/myuser/registration",
9+
"user": "/Users/myuser",
10+
"measurementId": "NGSQTEST001AE-1234512312",
11+
"datasetFiles" : [ "file1_1.fastq.gz", "file1_2.fastq.gz" ],
12+
"taskId": "74c5d26f-b756-42c3-b6f4-2b4825670a2d",
13+
"history": [
14+
"/opt/scanner-app/scanner-processing-dir/74c5d26f-b756-42c3-b6f4-2b4825670a2d"
15+
]
16+
}
17+
*/
18+
519
class Provenance {
620

721
final String origin
822
final String user
923
final String measurementID
24+
final List<String> datasetFiles
1025
final List<String> history
1126

12-
Provenance(String origin, String user, String measurementID, List<String> history) {
27+
Provenance(String origin, String user, String measurementID, List<String> datasetFiles,
28+
List<String> history) {
1329
this.origin = origin
1430
this.user = user
1531
this.measurementID = measurementID
32+
this.datasetFiles = datasetFiles
1633
this.history = history
1734
}
1835

@@ -21,7 +38,9 @@ class Provenance {
2138
def object = jsonSlurper.parseText(jsonString)
2239
assert object instanceof Map
2340
assert object.history instanceof List
41+
assert object.datasetFiles instanceof List
2442
return new Provenance(object.origin as String, object.user as String,
25-
object.measurementId as String, object.history as List<String>)
43+
object.measurementId as String, object.datasetFiles as List<String>,
44+
object.history as List<String>)
2645
}
2746
}

src/main/groovy/life/qbic/registration/handler/DatasetLocatorImpl.groovy

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,26 @@ class DatasetLocatorImpl implements DatasetLocator{
3838
*/
3939
@Override
4040
String getPathToDataset() {
41-
return findNestedDataset().orElseThrow()
41+
return findOrCreateDataPath().orElseThrow()
4242
}
4343

44-
private Optional<String> findNestedDataset() {
44+
private Optional<String> findOrCreateDataPath() {
4545
File rootDir = new File(incomingPath)
4646
if (!rootDir.isDirectory())
4747
return Optional.empty()
48-
/*
49-
Now we iterate through the list of child elements in the folder, and search for the directory name appearances.
50-
If it is a child directory, that means it has been processed with the dropboxhandler and
51-
we can return the nested dataset path.
52-
*/
53-
for (String child : rootDir.list()) {
54-
if (child.startsWith(provenance.measurementID)) {
55-
String innerFolderPath = rootDir.getAbsolutePath() + "/" + child
56-
File innerFolder = new File(innerFolderPath)
57-
if(innerFolder.list().size() == 1) {
58-
String singleFilePath = innerFolderPath+"/"+innerFolder.list()[0]
59-
return Optional.of(singleFilePath)
60-
} else {
61-
return Optional.of(innerFolderPath)
62-
}
63-
}
48+
List<String> fileNames = provenance.datasetFiles;
49+
if(fileNames.size() == 0)
50+
return Optional.empty()
51+
if(fileNames.size() == 1)
52+
return Optional.of(rootDir.getAbsolutePath() + "/" + fileNames[0])
53+
// more than one file
54+
var newDataFolder = new File(rootDir.getAbsolutePath(), "data");
55+
newDataFolder.mkdir();
56+
for(String fileName : fileNames) {
57+
String targetPath = newDataFolder.getAbsolutePath()+"/"+fileName
58+
new File(rootDir.getAbsolutePath()+"/"+fileName).renameTo(targetPath)
6459
}
65-
return Optional.empty()
60+
return Optional.of(newDataFolder.getAbsolutePath())
6661
}
6762

6863
private static boolean isAbsolutePath(String path) {

0 commit comments

Comments
 (0)