24
24
import java .io .FileNotFoundException ;
25
25
import java .io .InputStream ;
26
26
import java .io .StringWriter ;
27
- import java .net .URI ;
28
27
29
28
import org .openiot .gsn .metadata .LSM .LSMFieldMetaData ;
30
29
import org .openiot .gsn .metadata .LSM .LSMSensorMetaData ;
31
30
32
31
import com .hp .hpl .jena .n3 .turtle .TurtleParseException ;
32
+ import com .hp .hpl .jena .rdf .model .Literal ;
33
33
import com .hp .hpl .jena .rdf .model .Model ;
34
34
import com .hp .hpl .jena .rdf .model .ModelFactory ;
35
35
import com .hp .hpl .jena .rdf .model .NodeIterator ;
36
36
import com .hp .hpl .jena .rdf .model .Property ;
37
37
import com .hp .hpl .jena .rdf .model .ResIterator ;
38
38
import com .hp .hpl .jena .rdf .model .Resource ;
39
39
import com .hp .hpl .jena .rdf .model .ResourceFactory ;
40
- import com .hp .hpl .jena .vocabulary .RDF ;
41
40
import com .hp .hpl .jena .vocabulary .RDFS ;
42
41
43
42
public class SensorMetadata {
@@ -68,6 +67,7 @@ public class SensorMetadata {
68
67
Property dulHasLocation =ResourceFactory .createProperty (dul +"hasLocation" );
69
68
Property wgs84Lat =ResourceFactory .createProperty (wgs84 +"lat" );
70
69
Property wgs84Long =ResourceFactory .createProperty (wgs84 +"long" );
70
+ Property lsmFieldName =ResourceFactory .createProperty (lsm +"fieldName" );
71
71
72
72
73
73
public void loadFromFile (String rdfFile ) throws FileNotFoundException ,TurtleParseException {
@@ -90,6 +90,7 @@ public void createMetadata(LSMSensorMetaData meta){
90
90
Resource prop =model .createResource (f .getLsmPropertyName ());
91
91
model .add (sensorUri ,ssnObserves ,prop );
92
92
model .add (prop ,quUnit ,f .getLsmUnit ());
93
+ model .add (prop ,lsmFieldName ,f .getGsnFieldName ());
93
94
}
94
95
Resource location =model .createResource (sensorUri .getURI ()+"_location" );
95
96
model .add (location ,rdfType ,dulPlace );
@@ -131,6 +132,13 @@ public LSMSensorMetaData fillSensorMetadata(){
131
132
throw new IllegalArgumentException ("The property " +prop +" has no unit" );
132
133
Resource unit =prop .getPropertyResourceValue (quUnit );
133
134
//String column=prop.listProperties(rrColumnName).next().getObject().toString();
135
+ NodeIterator fnames =model .listObjectsOfProperty (prop , lsmFieldName );
136
+ if (!fnames .hasNext ())
137
+ throw new IllegalArgumentException ("The property " +prop +" has no associated GSN field name" );
138
+ Literal fn =fnames .next ().asLiteral ();
139
+ lsmField .setGsnFieldName (fn .getString ());
140
+
141
+
134
142
lsmField .setLsmPropertyName (prop .getURI ());
135
143
lsmField .setLsmUnit (unit .getURI ());
136
144
md .getFields ().put (prop .getURI (), lsmField );
0 commit comments