Skip to content

Commit 8538bbf

Browse files
committed
Schema Editor - xGSN tested version commit
1 parent 06872aa commit 8538bbf

File tree

9 files changed

+122
-20
lines changed

9 files changed

+122
-20
lines changed

ui/ui.schemaeditor/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
<version>20140107</version>
125125
</dependency>
126126

127+
128+
<!-- For Output templating based on xGSN Format -->
129+
<dependency>
130+
<groupId>org.freemarker</groupId>
131+
<artifactId>freemarker</artifactId>
132+
<version>2.3.14</version>
133+
</dependency>
134+
127135

128136
</dependencies>
129137
<build>

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/bean/FieldMetaDataBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void setLsmUnit(String lsmUnit) {
5353

5454
@Override
5555
public String toString() {
56-
return "LSMFieldMetaData{" +
56+
return "FieldMetaData{" +
5757
"gsnFieldName='" + gsnFieldName + '\'' +
5858
", lsmPropertyName='" + lsmPropertyName + '\'' +
5959
", unit='" + lsmUnit + '\'' +

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/bean/SensorBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void clearSession(){
195195
//clear the session for new sensor type creation
196196
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
197197
try {
198-
FacesContext.getCurrentInstance().getExternalContext().redirect("/SensorSchemaEditor/sensortypeeditor.jsf");
198+
FacesContext.getCurrentInstance().getExternalContext().redirect(OpeniotVocab.SCHEMAEDITOR_URI + "/sensortypeeditor.jsf");
199199
} catch (IOException e) {
200200
e.printStackTrace();
201201
}

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/bean/SensorInstanceCreatorBean.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@
3939

4040
import org.openiot.ui.sensorschema.register.AbstractSensorRegistrarFactory;
4141
import org.openiot.ui.sensorschema.register.SensorRegistratFactoryLSM;
42+
import org.openiot.ui.sensorschema.utils.OpeniotVocab;
43+
import org.openiot.ui.sensorschema.utils.Utils;
4244
import org.openiot.ui.sensorschema.utils.XGSNMetaDataCreator;
4345
import org.primefaces.model.DefaultStreamedContent;
4446
import org.primefaces.model.StreamedContent;
45-
import org.primefaces.model.map.DefaultMapModel;
46-
import org.primefaces.model.map.LatLng;
47-
import org.primefaces.model.map.MapModel;
48-
import org.primefaces.model.map.Marker;
4947

5048
@ManagedBean
5149
@SessionScoped
@@ -101,18 +99,29 @@ public void generateMetaDataFile(){
10199
//This will be updated if xGSN metadata format changes.
102100

103101
//create the field data for each property
104-
populatemetadata();
102+
//populatemetadata();
105103

106104
XGSNMetaDataCreator xgsn = new XGSNMetaDataCreator();
107105
sensormeatadata.setSensorID(sensorID);
108-
String rdfmetadata = xgsn.createMetadata(sensormeatadata);
109-
//System.out.println(rdfmetadata);
110106

111-
//creating a file download option for the user
112-
InputStream stream = new ByteArrayInputStream(rdfmetadata.getBytes(StandardCharsets.UTF_8));
107+
Utils utils = new Utils();
108+
String gsnoutput = utils.writetoTemplate(sensormeatadata);
109+
InputStream stream = new ByteArrayInputStream(gsnoutput.getBytes(StandardCharsets.UTF_8));
113110
file = new DefaultStreamedContent(stream, "text/plain", sensormeatadata.getSensorName() + ".metadata");
114111
fileready = true;
115112

113+
114+
//To download the schmea in RDF turtle format
115+
//currently not used. we use simple metadata decsription format
116+
//String rdfmetadata = xgsn.createMetadata(sensormeatadata);
117+
118+
//System.out.println(rdfmetadata);
119+
120+
//creating a file download option for the user
121+
//InputStream stream = new ByteArrayInputStream(rdfmetadata.getBytes(StandardCharsets.UTF_8));
122+
//file = new DefaultStreamedContent(stream, "text/plain", sensormeatadata.getSensorName() + ".metadata");
123+
//fileready = true;
124+
116125
}
117126

118127
public void registersensorinstance(){
@@ -210,7 +219,9 @@ public void clearSession(){
210219
//clear the session for new sensor type creation
211220
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
212221
try {
213-
FacesContext.getCurrentInstance().getExternalContext().redirect("/SensorSchemaEditor/sensorinstanceeditor.jsf");
222+
223+
224+
FacesContext.getCurrentInstance().getExternalContext().redirect(OpeniotVocab.SCHEMAEDITOR_URI + "/sensorinstanceeditor.jsf");
214225
} catch (IOException e) {
215226
e.printStackTrace();
216227
}

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/register/SensorRegistrarLSM.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ public List<String> getSensorList() {
227227
// System.out.println(text);
228228
// System.out.println(OpeniotVocab.NS);
229229
// text = text.replace(OpeniotVocab.NS, "");
230-
sensorlist.add(text);
230+
if (getSensorDescription(text).size()!=0)
231+
sensorlist.add(text);
231232

232233
}
233234
}

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/utils/OpeniotVocab.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public class OpeniotVocab {
3636
//read data from the properties file
3737
private static PropertyManagement propertyManagement = new PropertyManagement();
3838

39-
39+
//construct the sensor schema editor URI
40+
public final static String SCHEMAEDITOR_URI =
41+
propertyManagement.getSchemaEditorUrl().replace("/navigator.xhtml", "");
42+
4043
/**
4144
* <p>
4245
* The ontology model that holds the vocabulary terms

ui/ui.schemaeditor/src/main/java/org/openiot/ui/sensorschema/utils/Utils.java

+77
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,28 @@
2121
*/
2222
package org.openiot.ui.sensorschema.utils;
2323

24+
import java.io.File;
25+
import java.io.FileWriter;
26+
import java.io.IOException;
2427
import java.io.InputStream;
28+
import java.io.OutputStreamWriter;
29+
import java.io.StringWriter;
30+
import java.io.Writer;
31+
import java.util.ArrayList;
2532
import java.util.Arrays;
33+
import java.util.HashMap;
2634
import java.util.List;
35+
import java.util.Map;
2736

37+
import org.openiot.ui.sensorschema.bean.FieldMetaDataBean;
38+
import org.openiot.ui.sensorschema.bean.SensorMetaDataBean;
2839
import org.slf4j.Logger;
2940
import org.slf4j.LoggerFactory;
3041

42+
import freemarker.template.Configuration;
43+
import freemarker.template.Template;
44+
import freemarker.template.TemplateException;
45+
3146
/**
3247
* A collection of helper methods
3348
*/
@@ -110,4 +125,66 @@ public static String formatHTML(String html){
110125
temp_html = "<pre><code>" + temp_html + "</pre></code>";
111126
return temp_html;
112127
}
128+
129+
130+
131+
public String writetoTemplate(SensorMetaDataBean metadata){
132+
//Freemarker configuration object
133+
Configuration cfg = new Configuration();
134+
try {
135+
136+
//Load template from source folder
137+
cfg.setClassForTemplateLoading(this.getClass(), "../../../../../");
138+
139+
//cfg.get
140+
Template template = cfg.getTemplate("xgsn-output.ftl");
141+
142+
// Build the data-model
143+
Map<String, Object> data = new HashMap<String, Object>();
144+
data.put("sensorname", metadata.getSensorName());
145+
data.put("source", metadata.getSensorName());
146+
data.put("sensortype", metadata.getSensorName());
147+
data.put("sourcetype", metadata.getSensorName());
148+
data.put("information", metadata.getSensorName());
149+
data.put("authors", metadata.getSensorName());
150+
data.put("featureofinterest", metadata.getSensorName());
151+
152+
List<FieldMetaDataBean> fielddata = new ArrayList<FieldMetaDataBean>();
153+
Map<String, FieldMetaDataBean> fieldmetadata = metadata.getFields();
154+
for (Map.Entry<String, FieldMetaDataBean> entry : fieldmetadata.entrySet())
155+
{
156+
fielddata.add(entry.getValue());
157+
//System.out.println(entry.getKey() + "/" + entry.getValue());
158+
}
159+
160+
161+
data.put("fields", fielddata);
162+
data.put("latitude", metadata.getLatitude());
163+
data.put("longitude", metadata.getLongitude());
164+
data.put("sensorID", metadata.getSensorID());
165+
166+
// Console output
167+
//Writer out = new OutputStreamWriter(System.out);
168+
//template.process(data, out);
169+
//out.flush();
170+
171+
// File output
172+
//Writer file = new FileWriter (new File("FTL_helloworld.txt"));
173+
//template.process(data, file);
174+
//file.flush();
175+
//file.close();
176+
177+
//String output
178+
Writer out = new StringWriter();
179+
template.process(data, out);
180+
return out.toString();
181+
182+
} catch (IOException e) {
183+
e.printStackTrace();
184+
return null;
185+
} catch (TemplateException e) {
186+
e.printStackTrace();
187+
return null;
188+
}
189+
}
113190
}

ui/ui.schemaeditor/src/main/webapp/index.xhtml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ xmlns:p="http://primefaces.org/ui">
1313
<title>
1414
<ui:insert name="title">OpenIoT Sensor Schema Editor</ui:insert>
1515
</title>
16-
16+
<link rel="stylesheet" href="css/core.css" />
1717
</h:head>
1818

19-
<h:body>
19+
<h:body styleClass="login">
2020

21-
<h:form>
21+
<h:form>
2222
<div align="center">
2323
<div class="logo" />
2424
<div class="slogan">Open Source Solution for the Internet of
@@ -43,6 +43,6 @@ xmlns:p="http://primefaces.org/ui">
4343
<h3>Server Time</h3>
4444
<p:clock pattern="HH:mm:ss dd.MM.yyyy" mode="server" />
4545
</ui:remove>
46-
</h:form>
46+
</h:form>
4747
</h:body>
4848
</html>

ui/ui.schemaeditor/src/main/webapp/sensorinstanceeditor.xhtml

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ xmlns:p="http://primefaces.org/ui">
7676
Things into the Cloud</div>
7777
</div>
7878
<h:form id="form1">
79-
79+
<div align="center">
8080
<p:panelGrid style="margin-top:20px">
8181
<f:facet name="header">
8282
<p:row>
@@ -250,8 +250,10 @@ xmlns:p="http://primefaces.org/ui">
250250
<input id="search" type="button" value="Search" onclick="codeAddress();" />
251251
<input id="close" type="button" value="Close" onclick="PF('dlg').hide();" />
252252
</p:dialog>
253-
253+
</div>
254254
</h:form>
255+
256+
255257
</h:body>
256258

257259
</html>

0 commit comments

Comments
 (0)