Skip to content

Commit

Permalink
Add RDF parsing and writing of screen sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
oxixes committed Jun 18, 2024
1 parent 3ae1941 commit 3830b43
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 44 deletions.
79 changes: 59 additions & 20 deletions src/wirecloud/commons/utils/template/parsers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,12 @@ def _parse_workspace_info(self):
for widget in self._graph.objects(tab, WIRE_M['hasiWidget']):
position = self._get_field(WIRE_M, 'hasPosition', widget, id_=True, required=False)
rendering = self._get_field(WIRE_M, 'hasiWidgetRendering', widget, id_=True, required=False)
screenSizes = self._graph.objects(widget, WIRE_M['hasScreenSize'])
vendor = self._get_field(USDL, 'hasProvider', widget, id_=True, required=True)
layout = int(self._get_field(WIRE_M, 'layout', rendering, default='0'))
if len(screenSizes) > 0:
layout = int(self._get_field(WIRE_M, 'layout', widget, required=False, default='0'))
else:
layout = int(self._get_field(WIRE_M, 'layout', rendering, default='0'))

widget_info = {
'id': self._get_field(WIRE_M, 'iWidgetId', widget),
Expand All @@ -725,28 +729,63 @@ def _parse_workspace_info(self):
'version': self._get_field(USDL, 'versionInfo', widget),
'title': self._get_field(DCTERMS, 'title', widget),
'readonly': self._get_field(WIRE_M, 'readonly', widget, required=False).lower() == 'true',
'layout': layout,
'properties': {},
'preferences': {},
'position': {
'anchor': self._get_field(WIRE_M, 'anchor', position, required=False, default="top-left"),
'relx': self._get_field(WIRE_M, 'relx', position, required=False, default='true').lower() == 'true',
'rely': self._get_field(WIRE_M, 'rely', position, required=False, default=('true' if layout != 1 else 'false')).lower() == 'true',
'x': self._get_field(WIRE_M, 'x', position),
'y': self._get_field(WIRE_M, 'y', position),
'z': self._get_field(WIRE_M, 'z', position),
},
'rendering': {
'relwidth': self._get_field(WIRE_M, 'relwidth', rendering, required=False, default='True').lower() == 'true',
'relheight': self._get_field(WIRE_M, 'relheight', rendering, required=False, default=('true' if layout != 1 else 'false')).lower() == 'true',
'width': self._get_field(WIRE, 'renderingWidth', rendering),
'height': self._get_field(WIRE, 'renderingHeight', rendering),
'layout': layout,
'fulldragboard': self._get_field(WIRE_M, 'fullDragboard', rendering, required=False).lower() == 'true',
'minimized': self._get_field(WIRE_M, 'minimized', rendering, required=False).lower() == 'true',
'titlevisible': self._get_field(WIRE_M, 'titlevisible', rendering, default="true", required=False).lower() == 'true',
},
'preferences': {}
}

widget_info['screenSizes'] = []
if len(screenSizes) > 0:
for screenSize in screenSizes:
position = self._get_field(WIRE_M, 'hasPosition', screenSize, id_=True, required=False)
rendering = self._get_field(WIRE_M, 'hasiWidgetRendering', screenSize, id_=True, required=False)
screen_size_info = {
'moreOrEqual': int(self._get_field(WIRE_M, 'moreOrEqual', screenSize)),
'lessOrEqual': int(self._get_field(WIRE_M, 'lessOrEqual', screenSize)),
'id': int(self._get_field(WIRE_M, 'screenSizeId', screenSize)),
'position': {
'anchor': self._get_field(WIRE_M, 'anchor', position, required=False, default="top-left"),
'relx': self._get_field(WIRE_M, 'relx', position, required=False, default='true').lower() == 'true',
'rely': self._get_field(WIRE_M, 'rely', position, required=False, default=('true' if layout != 1 else 'false')).lower() == 'true',
'x': int(float(self._get_field(WIRE_M, 'x', position))),
'y': int(float(self._get_field(WIRE_M, 'y', position))),
'z': int(float(self._get_field(WIRE_M, 'z', position))),
},
'rendering': {
'fulldragboard': self._get_field(WIRE_M, 'fullDragboard', rendering, required=False).lower() == 'true',
'minimized': self._get_field(WIRE_M, 'minimized', rendering, required=False).lower() == 'true',
'relwidth': self._get_field(WIRE_M, 'relwidth', rendering, required=False).lower() == 'true',
'relheight': self._get_field(WIRE_M, 'relheight', rendering, required=False).lower() == 'true',
'width': int(float(self._get_field(WIRE, 'renderingWidth', rendering))),
'height': int(float(self._get_field(WIRE, 'renderingHeight', rendering))),
'titlevisible': self._get_field(WIRE_M, 'titlevisible', rendering, default="true", required=False).lower() == 'true',
}
}
widget_info['screenSizes'].append(screen_size_info)
else:
screen_size_info = {
'moreOrEqual': 0,
'lessOrEqual': -1,
'id': 0,
'position': {
'anchor': self._get_field(WIRE_M, 'anchor', position, required=False, default="top-left"),
'relx': self._get_field(WIRE_M, 'relx', position, required=False, default='true').lower() == 'true',
'rely': self._get_field(WIRE_M, 'rely', position, required=False, default=('true' if layout != 1 else 'false')).lower() == 'true',
'x': int(float(self._get_field(WIRE_M, 'x', position))),
'y': int(float(self._get_field(WIRE_M, 'y', position))),
'z': int(float(self._get_field(WIRE_M, 'z', position))),
},
'rendering': {
'fulldragboard': self._get_field(WIRE_M, 'fullDragboard', rendering, required=False).lower() == 'true',
'minimized': self._get_field(WIRE_M, 'minimized', rendering, required=False).lower() == 'true',
'relwidth': self._get_field(WIRE_M, 'relwidth', rendering, required=False).lower() == 'true',
'relheight': self._get_field(WIRE_M, 'relheight', rendering, required=False).lower() == 'true',
'width': int(float(self._get_field(WIRE, 'renderingWidth', rendering))),
'height': int(float(self._get_field(WIRE, 'renderingHeight', rendering))),
'titlevisible': self._get_field(WIRE_M, 'titlevisible', rendering, default="true", required=False).lower() == 'true',
}
}

for prop in self._graph.objects(widget, WIRE_M['hasiWidgetProperty']):
widget_info['properties'][self._get_field(DCTERMS, 'title', prop)] = {
'readonly': self._get_field(WIRE_M, 'readonly', prop, required=False).lower() == 'true',
Expand Down
37 changes: 36 additions & 1 deletion src/wirecloud/commons/utils/template/schemas/wire-m.rdf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:usdl-core="http://www.linked-usdl.org/ns/usdl-core#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
Expand Down Expand Up @@ -58,6 +58,12 @@
<rdfs:label>iWidget porperty</rdfs:label>
<rdfs:comment>properties of a wirecloud iWidget</rdfs:comment>
</rdfs:Class>
<rdfs:Class rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#ScreenSize">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>Screen Size Layout Configuration</rdfs:label>
<rdfs:comment>Gives information about the position and rendering of an iWidget in a specific screen size.</rdfs:comment>
</rdfs:Class>
<rdfs:Class rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#iWidgetRendering">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
Expand Down Expand Up @@ -208,6 +214,13 @@
<rdfs:domain rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#iWidget"/>
<rdfs:range rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#iWidgetPreference"/>
</rdf:Property>
<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#hasScreenSize"/>
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>has screen size</rdfs:label>
<rdfs:comment>an iWidget has a position and rendering in a specific screen size</rdfs:comment>
<rdfs:domain rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#iWidgetRendering"/>
<rdfs:range rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#ScreenSize"/>
</rdf:Property>
<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#hasPosition">
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>has position</rdfs:label>
Expand Down Expand Up @@ -267,6 +280,28 @@
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
</rdf:Property>

<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#moreOrEqual">
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>more or equal</rdfs:label>
<rdfs:comment>a screen size start size</rdfs:comment>
<rdfs:domain rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#Position"/>
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
</rdf:Property>
<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#lessOrEqual">
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>less or equal</rdfs:label>
<rdfs:comment>a screen size end size</rdfs:comment>
<rdfs:domain rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#Position"/>
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
</rdf:Property>
<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#screenSizeId">
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>screen size id</rdfs:label>
<rdfs:comment>a screen size id</rdfs:comment>
<rdfs:domain rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup#Position"/>
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
</rdf:Property>

<rdf:Property rdf:about="http://wirecloud.conwet.fi.upm.es/ns/mashup#readonly">
<rdfs:isDefinedBy rdf:resource="http://wirecloud.conwet.fi.upm.es/ns/mashup"/>
<rdfs:label>readonly</rdfs:label>
Expand Down
53 changes: 30 additions & 23 deletions src/wirecloud/commons/utils/template/writers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,36 @@ def write_mashup_resources_graph(graph, resource_uri, template_info):
if iwidget.get('readonly', False):
graph.add((resource, WIRE_M['readonly'], rdflib.Literal('true')))

# iWidget position
pos = rdflib.BNode()
graph.add((pos, rdflib.RDF.type, WIRE_M['Position']))
graph.add((resource, WIRE_M['hasPosition'], pos))
graph.add((pos, WIRE_M['anchor'], rdflib.Literal(iwidget['position']['anchor'])))
graph.add((pos, WIRE_M['relx'], rdflib.Literal(str(iwidget['position']['relx']))))
graph.add((pos, WIRE_M['rely'], rdflib.Literal(str(iwidget['position']['rely']))))
graph.add((pos, WIRE_M['x'], rdflib.Literal(iwidget['position']['x'])))
graph.add((pos, WIRE_M['y'], rdflib.Literal(iwidget['position']['y'])))
graph.add((pos, WIRE_M['z'], rdflib.Literal(iwidget['position']['z'])))

# iWidget rendering
rend = rdflib.BNode()
graph.add((rend, rdflib.RDF.type, WIRE_M['iWidgetRendering']))
graph.add((resource, WIRE_M['hasiWidgetRendering'], rend))
graph.add((rend, WIRE_M['relwidth'], rdflib.Literal(str(iwidget['rendering']['relwidth']))))
graph.add((rend, WIRE_M['relheight'], rdflib.Literal(str(iwidget['rendering']['relheight']))))
graph.add((rend, WIRE['renderingWidth'], rdflib.Literal(str(iwidget['rendering']['width']))))
graph.add((rend, WIRE['renderingHeight'], rdflib.Literal(str(iwidget['rendering']['height']))))
graph.add((rend, WIRE_M['layout'], rdflib.Literal(str(iwidget['rendering']['layout']))))
graph.add((rend, WIRE_M['fullDragboard'], rdflib.Literal(str(iwidget['rendering']['fulldragboard']))))
graph.add((rend, WIRE_M['minimized'], rdflib.Literal(str(iwidget['rendering']['minimized']))))
graph.add((rend, WIRE_M['titlevisible'], rdflib.Literal(str(iwidget['rendering']['titlevisible']))))
graph.add((resource, WIRE_M['layout'], rdflib.Literal(str(iwidget['layout']))))

for screenSize in iwidget.get('screenSizes', []):
screenSizeNode = rdflib.BNode()
graph.add((screenSizeNode, rdflib.RDF.type, WIRE_M['ScreenSize']))
graph.add((resource, WIRE_M['hasScreenSize'], screenSizeNode))
graph.add((screenSizeNode, WIRE_M['moreOrEqual'], rdflib.Literal(str(screenSize['moreOrEqual']))))
graph.add((screenSizeNode, WIRE_M['lessOrEqual'], rdflib.Literal(str(screenSize['lessOrEqual']))))
graph.add((screenSizeNode, WIRE_M['screenSizeId'], rdflib.Literal(str(screenSize['id']))))

pos = rdflib.BNode()
graph.add((pos, rdflib.RDF.type, WIRE_M['Position']))
graph.add((screenSizeNode, WIRE_M['hasPosition'], pos))
graph.add((pos, WIRE_M['anchor'], rdflib.Literal(screenSize['position']['anchor'])))
graph.add((pos, WIRE_M['relx'], rdflib.Literal(str(screenSize['position']['relx']))))
graph.add((pos, WIRE_M['rely'], rdflib.Literal(str(screenSize['position']['rely']))))
graph.add((pos, WIRE_M['x'], rdflib.Literal(str(int(float(screenSize['position']['x']))))))
graph.add((pos, WIRE_M['y'], rdflib.Literal(str(int(float(screenSize['position']['y']))))))
graph.add((pos, WIRE_M['z'], rdflib.Literal(str(int(float(screenSize['position']['z']))))))

rend = rdflib.BNode()
graph.add((rend, rdflib.RDF.type, WIRE_M['iWidgetRendering']))
graph.add((screenSizeNode, WIRE_M['hasiWidgetRendering'], rend))
graph.add((rend, WIRE_M['relwidth'], rdflib.Literal(str(screenSize['rendering']['relwidth']))))
graph.add((rend, WIRE_M['relheight'], rdflib.Literal(str(screenSize['rendering']['relheight']))))
graph.add((rend, WIRE['renderingWidth'], rdflib.Literal(str(int(float(screenSize['rendering']['width']))))))
graph.add((rend, WIRE['renderingHeight'], rdflib.Literal(str(int(float(screenSize['rendering']['height']))))))
graph.add((rend, WIRE_M['fullDragboard'], rdflib.Literal(str(screenSize['rendering']['fulldragboard']))))
graph.add((rend, WIRE_M['minimized'], rdflib.Literal(str(screenSize['rendering']['minimized']))))
graph.add((rend, WIRE_M['titlevisible'], rdflib.Literal(str(screenSize['rendering']['titlevisible']))))

# iWidget preferences
for pref_name, pref in iwidget.get('preferences', {}).items():
Expand Down

0 comments on commit 3830b43

Please sign in to comment.