@@ -5,6 +5,7 @@ import life.qbic.registration.types.QDatasetType
5
5
6
6
import java.util.regex.Matcher
7
7
import java.util.regex.Pattern
8
+ import java.util.stream.Collectors
8
9
9
10
/**
10
11
* A measurement ID references an openBIS object code used for measurements
@@ -16,8 +17,10 @@ class MeasurementID {
16
17
17
18
/**
18
19
* <p >The regular expression of a valid QBiC measurement code.</p>
20
+ * Prefixes are checked later
21
+ * Z and Y are not allowed, as barcode scanners can switch these depending on country settings.
19
22
*/
20
- static final Pattern QBIC_MEASUREMENT_CODE_SCHEMA = ~/ N*[GM]SQ [A-X0-9]{4}[0-9]{3}[A-X0-9]{2}-[0-9]{14}/
23
+ static final Pattern QBIC_MEASUREMENT_CODE_SCHEMA = ~/ [A-X]*Q [A-X0-9]{4}[0-9]{3}[A-X0-9]{2}-[0-9]{14}/
21
24
/**
22
25
* <p >Holds the project code, which is always part of the object code.</p>
23
26
*/
@@ -81,13 +84,17 @@ class MeasurementID {
81
84
String withoutPrefix = sampleId. replace(prefix, ' ' )
82
85
this . projectCode = withoutPrefix[0 .. 4 ]
83
86
this . runningNumber = Integer . parseInt(withoutPrefix[5 .. 7 ])
84
- this . runningDigit = withoutPrefix[8 ]
85
- this . checksum = withoutPrefix[9 ]
87
+ this . runningDigit = withoutPrefix[8 ] as char
88
+ this . checksum = withoutPrefix[9 ] as char
86
89
this . suffix = Long . parseLong(withoutPrefix[11 .. -1 ])
87
90
}
88
91
89
92
private void findMeasurementType (String id ) {
90
- for (String prefix : QDatasetType . BY_PREFIX . keySet()) {
93
+ // we try to find the longest matching prefix, in case their names overlap
94
+ List<String > prefixesByLength = QDatasetType . BY_PREFIX . keySet(). stream()
95
+ .sorted(Comparator . comparingInt(String ::length). reversed())
96
+ .collect(Collectors . toList());
97
+ for (String prefix : prefixesByLength) {
91
98
if (id. startsWith(prefix)) {
92
99
this . prefix = prefix
93
100
this . datasetType = QDatasetType . BY_PREFIX . get(prefix)
0 commit comments