1
|
package eu.dnetlib.dhp.common.java.jsonworkflownodes;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import org.apache.avro.Schema;
|
7
|
|
8
|
import eu.dnetlib.dhp.common.java.jsonworkflownodes.StringPortSpecificationExtractor.PortSpecification;
|
9
|
import eu.dnetlib.dhp.common.java.porttype.AvroPortType;
|
10
|
import eu.dnetlib.dhp.common.java.porttype.PortType;
|
11
|
import eu.dnetlib.dhp.common.utils.AvroUtils;
|
12
|
|
13
|
/**
|
14
|
* @author Mateusz Kobos
|
15
|
*/
|
16
|
public class PortSpecifications {
|
17
|
private static final String[] propertyRegexps =
|
18
|
new String[]{"[\\w\\.]+", "[\\w\\./_\\-]+"};
|
19
|
private final Map<String, SpecificationValues> specs;
|
20
|
|
21
|
public static class SpecificationValues {
|
22
|
|
23
|
private final Schema schema;
|
24
|
|
25
|
private final String jsonFilePath;
|
26
|
|
27
|
public SpecificationValues(Schema schema, String jsonFilePath) {
|
28
|
this.schema = schema;
|
29
|
this.jsonFilePath = jsonFilePath;
|
30
|
}
|
31
|
|
32
|
public Schema getSchema() {
|
33
|
return schema;
|
34
|
}
|
35
|
|
36
|
public String getJsonFilePath() {
|
37
|
return jsonFilePath;
|
38
|
}
|
39
|
|
40
|
}
|
41
|
|
42
|
public PortSpecifications(String[] portSpecifications){
|
43
|
StringPortSpecificationExtractor portSpecExtractor =
|
44
|
new StringPortSpecificationExtractor(propertyRegexps);
|
45
|
specs = new HashMap<String, SpecificationValues>();
|
46
|
for(int i = 0; i < portSpecifications.length; i++){
|
47
|
PortSpecification portSpec = portSpecExtractor.getSpecification(portSpecifications[i]);
|
48
|
Schema schema = AvroUtils.toSchema(portSpec.getProperties()[0]);
|
49
|
String jsonPath = portSpec.getProperties()[1];
|
50
|
specs.put(portSpec.getName(), new SpecificationValues(schema, jsonPath));
|
51
|
}
|
52
|
}
|
53
|
|
54
|
public SpecificationValues get(String portName){
|
55
|
return specs.get(portName);
|
56
|
}
|
57
|
|
58
|
public Map<String, PortType> getPortTypes(){
|
59
|
Map<String, PortType> ports = new HashMap<String, PortType>();
|
60
|
for(Map.Entry<String, SpecificationValues> e: specs.entrySet()){
|
61
|
Schema schema = e.getValue().schema;
|
62
|
ports.put(e.getKey(), new AvroPortType(schema));
|
63
|
}
|
64
|
return ports;
|
65
|
}
|
66
|
}
|