@@ -4,10 +4,10 @@ import ai.ancf.lmos.wot.Servient
44import ai.ancf.lmos.wot.content.Content
55import ai.ancf.lmos.wot.content.ContentCodecException
66import ai.ancf.lmos.wot.content.ContentManager
7- import ai.ancf.lmos.wot.thing.ExposedThingImpl
87import ai.ancf.lmos.wot.thing.form.Form
98import ai.ancf.lmos.wot.thing.form.Operation
10- import ai.ancf.lmos.wot.thing.property.ExposedThingProperty.*
9+ import ai.ancf.lmos.wot.thing.schema.ExposedThing
10+ import ai.ancf.lmos.wot.thing.schema.InteractionAffordance
1111import ai.anfc.lmos.wot.binding.ProtocolServer
1212import ai.anfc.lmos.wot.binding.ProtocolServerException
1313import com.fasterxml.jackson.databind.DeserializationFeature
@@ -34,7 +34,7 @@ open class HttpProtocolServer(
3434 private val bindPort : Int = 8080 ,
3535 private val createServer : (host: String , port: Int , servient: Servient ) -> EmbeddedServer <* , * > = ::defaultServer
3636) : ProtocolServer {
37- val things: MutableMap <String , ExposedThingImpl > = mutableMapOf ()
37+ val things: MutableMap <String , ExposedThing > = mutableMapOf ()
3838 var started = false
3939 private var server: EmbeddedServer <* , * >? = null
4040 private var actualAddresses: List <String > = listOf (" http://$bindHost :$bindPort " )
@@ -59,7 +59,7 @@ open class HttpProtocolServer(
5959 }
6060
6161 // Expose a thing
62- override fun expose (thing : ExposedThingImpl ) {
62+ override fun expose (thing : ExposedThing ) {
6363 if (! started) throw ProtocolServerException (" Server has not started yet" )
6464
6565 log.info(" Exposing thing '{}'" , thing.id)
@@ -82,7 +82,7 @@ open class HttpProtocolServer(
8282 }
8383 }
8484
85- internal fun exposeProperties (thing : ExposedThingImpl , address : String , contentType : String ) {
85+ internal fun exposeProperties (thing : ExposedThing , address : String , contentType : String ) {
8686 thing.properties.forEach { (name, property) ->
8787
8888 val href = getHrefWithVariablePattern(address, thing, " properties" , name, property)
@@ -128,7 +128,7 @@ open class HttpProtocolServer(
128128 }
129129 }
130130
131- internal fun exposeActions (thing : ExposedThingImpl , address : String , contentType : String ) {
131+ internal fun exposeActions (thing : ExposedThing , address : String , contentType : String ) {
132132 thing.actions.forEach { (name, action) ->
133133 val href: String = getHrefWithVariablePattern(address, thing, " actions" , name, action)
134134 // Initialize the form using named parameters
@@ -144,7 +144,7 @@ open class HttpProtocolServer(
144144 }
145145 }
146146
147- internal fun exposeEvents (thing : ExposedThingImpl , address : String , contentType : String ) {
147+ internal fun exposeEvents (thing : ExposedThing , address : String , contentType : String ) {
148148 thing.events.forEach { (name, event) ->
149149 val href = getHrefWithVariablePattern(address, thing, " events" , name, event)
150150
@@ -164,7 +164,7 @@ open class HttpProtocolServer(
164164
165165 private fun getHrefWithVariablePattern (
166166 address : String ,
167- thing : ExposedThingImpl ,
167+ thing : ExposedThing ,
168168 type : String ,
169169 interactionName : String ,
170170 interaction : InteractionAffordance
@@ -178,7 +178,7 @@ open class HttpProtocolServer(
178178 }
179179
180180 // Destroy a thing
181- override suspend fun destroy (thing : ExposedThingImpl ) {
181+ override suspend fun destroy (thing : ExposedThing ) {
182182 log.info(" Removing thing '{}'" , thing.id)
183183 things.remove(thing.id)
184184 }
@@ -197,15 +197,15 @@ fun Application.setupRouting(servient: Servient) {
197197 routing {
198198 route(" /" ) {
199199 get {
200- call.respond(servient.things.values.toList(), typeInfo<List <ExposedThingImpl >>())
200+ call.respond(servient.things.values.toList(), typeInfo<List <ExposedThing >>())
201201 }
202202 }
203203 route(" /{id}" ) {
204204 get {
205205 val id = call.parameters[" id" ]
206- val thing: ExposedThingImpl ? = servient.things[id]
206+ val thing: ExposedThing ? = servient.things[id]
207207 if (thing != null ) {
208- call.respond(thing, typeInfo<ExposedThingImpl >())
208+ call.respond(thing, typeInfo<ExposedThing >())
209209 } else {
210210 call.response.status(HttpStatusCode .NotFound )
211211 }
@@ -224,19 +224,14 @@ fun Application.setupRouting(servient: Servient) {
224224 if (property != null ) {
225225 if (! property.writeOnly) {
226226 try {
227- val value = property.read()
227+
228+ thing.
229+
230+ // val value = property.read()
228231 // contentType = getOrDefaultRequestContentType(call.request)
229232 // val content = ContentManager.valueToContent(value, contentType.toString())
230- when (property) {
231- is ExposedStringProperty -> call.respond(property.read(), typeInfo<String >())
232- is ExposedIntProperty -> call.respond(property.read(), typeInfo<Int >())
233- is ExposedBooleanProperty -> call.respond(property.read(), typeInfo<Boolean >())
234- is ExposedNumberProperty -> call.respond(property.read(), typeInfo<Double >())
235- is ExposedObjectProperty -> call.respond(property.read(), typeInfo<Map <* ,* >>())
236- is ExposedNullProperty -> call.respond(property.read(), typeInfo<Any >())
237- is ExposedArrayProperty -> call.respond(property.read(), typeInfo<List <* >>())
238- }
239- }
233+
234+ }
240235 catch (e: ContentCodecException ) {
241236 call.response.status(HttpStatusCode .InternalServerError )
242237 } catch (e: ExecutionException ) {
@@ -259,15 +254,7 @@ fun Application.setupRouting(servient: Servient) {
259254 // val contentType = getOrDefaultRequestContentType(call.request)
260255 // val content = Content(contentType.toString(), call.receiveChannel().toByteArray())
261256
262- when (property) {
263- is ExposedStringProperty -> call.respond(property.write(call.receive<String >()), typeInfo<String >())
264- is ExposedIntProperty -> call.respond(property.write(call.receive<Int >()), typeInfo<Int >())
265- is ExposedBooleanProperty -> call.respond(property.write(call.receive<Boolean >()), typeInfo<Boolean >())
266- is ExposedNumberProperty -> call.respond(property.write(call.receive<Double >()), typeInfo<Double >())
267- is ExposedObjectProperty -> call.respond(property.write(call.receive<Map <* ,* >>()), typeInfo<Map <* ,* >>())
268- is ExposedNullProperty -> call.respond(property.write(call.receive<Any >()), typeInfo<Any >())
269- is ExposedArrayProperty -> call.respond(property.write(call.receive<List <* >>()), typeInfo<List <* >>())
270- }
257+
271258 } else {
272259 call.response.status(HttpStatusCode .BadRequest )
273260 }
@@ -287,11 +274,11 @@ fun Application.setupRouting(servient: Servient) {
287274
288275 if (action.input != null ){
289276 val input = ContentManager .contentToValue(content, action.input!! )
290- val newValue = action.invokeAction(input, null )
291- call.respond(newValue, typeInfo<Any >())
277+ // val newValue = action.invokeAction(input, null)
278+ // call.respond(newValue, typeInfo<Any>())
292279 }else {
293- val newValue = action.invokeAction(null , null )
294- call.respond(newValue, typeInfo<Any >())
280+ // val newValue = action.invokeAction(null, null)
281+ // call.respond(newValue, typeInfo<Any>())
295282 }
296283
297284
0 commit comments