sane-city / wot-servient

W3C Web of Things implementation for Java
MIT License
29 stars 5 forks source link

Get and set proper context #40

Closed LeebPhil closed 3 years ago

LeebPhil commented 3 years ago

Hey guys,

I'm trying to set the context of my implemented with the object context. It still compiles and runs, but when opening browser and looking at TD there is no context displayed. Is this a known bug?

Second question is, i want set the context of my thing pretty similar to: https://www.w3.org/TR/wot-thing-description/#saref-state-annotation-example and wanted to know how this can be done in your implementation, with a 'nested' context and mentioning ontologies like ssn or saref?

Current approach is:

            wotConfig = ConfigFactory.load();
            wot = new DefaultWot(wotConfig);
            Context context = new Context();
            context.addContext("@context", "https://www.w3.org/2019/wot/td/v1");
            thing = new Thing.Builder().setObjectContext(context).setId(thingID).setTitle(thingTitle)
                    .setDescription(thingDescription).build();
            exposedThing = wot.produce(thing);
            exposedThing.expose();

But my TD looks like:

{"id":"wotgimmick","title":"wot gimmick","description":"This is a simple wot gimmick","forms":[{"href":"http://localhost:8080/wotgimmick/all/properties","op":["readallproperty","readmultipleproperty"],"contentType":"application/json"}]}

Current version: city.sane.wot-servient: 1.15

Thank you in advance for your answer.
Kind regards
Phil

LeebPhil commented 3 years ago

When i print in console with thing.toString() it looks like:

Thing{objectType='null', objectContext=null, id='wotgimmick', title='wot gimmick', titles=null, description='This is a simple wot gimmick', descriptions=null, properties={}, actions={}, events={}, forms=[Form{href='http://localhost:8080/wotgimmick/all/properties', op=[READ_ALL_PROPERTIES, READ_MULTIPLE_PROPERTIES], subprotocol='null', contentType='application/json', optionalProperties={}}], security=[], securityDefinitions={}, base='null'}
LeebPhil commented 3 years ago

Found the solution, constructor of Context needs a parameter.