diff --git a/src/main/java/com/mackervoy/calum/mud/behaviour/ActionController.java b/src/main/java/com/mackervoy/calum/mud/behaviour/ActionController.java index effb389..b7b9a20 100644 --- a/src/main/java/com/mackervoy/calum/mud/behaviour/ActionController.java +++ b/src/main/java/com/mackervoy/calum/mud/behaviour/ActionController.java @@ -4,6 +4,7 @@ import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.RDFS; import java.util.Set; @@ -43,6 +44,11 @@ public Response discoverActions(String requestBody) { for(String key : keys) { Model m = ModelFactory.createDefaultModel().read(key, "TURTLE"); Resource r = m.getResource(key); + String name = r.hasProperty(RDFS.label) ? r.getProperty(RDFS.label, "en").getString() : ""; + String description = r.hasProperty(RDFS.comment) ? r.getProperty(RDFS.comment, "en").getString() : ""; + + result.add(r, RDFS.label, name); + result.add(r, RDFS.comment, description); result.add(r, RDF.type, r.getPropertyResourceValue(RDF.type)); result.add(r, MUDLogic.actAt, this.getActAtURL(r)); } diff --git a/src/main/java/com/mackervoy/calum/mud/content/ContentController.java b/src/main/java/com/mackervoy/calum/mud/content/ContentController.java index 9e9b887..e6d652c 100644 --- a/src/main/java/com/mackervoy/calum/mud/content/ContentController.java +++ b/src/main/java/com/mackervoy/calum/mud/content/ContentController.java @@ -6,7 +6,6 @@ import com.mackervoy.calum.mud.AbstractMUDController; import com.mackervoy.calum.mud.vocabularies.MUDCharacter; -import java.io.StringReader; import java.util.Optional; import javax.ws.rs.POST; diff --git a/src/main/java/com/mackervoy/calum/mud/vocabularies/MUDLogic.java b/src/main/java/com/mackervoy/calum/mud/vocabularies/MUDLogic.java index 8d42d57..7591826 100644 --- a/src/main/java/com/mackervoy/calum/mud/vocabularies/MUDLogic.java +++ b/src/main/java/com/mackervoy/calum/mud/vocabularies/MUDLogic.java @@ -31,6 +31,7 @@ protected static final Property property( String local ) public final static Resource Task = resource( "Task" ); public final static Resource Transit = resource( "Transit" ); public final static Property actAt = property( "actAt" ); + public final static Property parameterConstraintsShape = property("parameterConstraintsShape"); public final static Property taskImplements = property( "taskImplements" ); public final static Property isComplete = property( "isComplete" ); public final static Property endState = property( "endState" ); diff --git a/src/main/java/com/mackervoy/calum/mud/world/SceneController.java b/src/main/java/com/mackervoy/calum/mud/world/SceneController.java new file mode 100644 index 0000000..14b7a0e --- /dev/null +++ b/src/main/java/com/mackervoy/calum/mud/world/SceneController.java @@ -0,0 +1,31 @@ +package com.mackervoy.calum.mud.world; + +import com.mackervoy.calum.mud.AbstractMUDController; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; + +/** + * @author Calum Mackervoy + * Provides endpoints to help generate objects into a scene + * (e.g. a character walks into a bar and expects to see occupants) + */ +@Path("/mud/scene/") +public class SceneController extends AbstractMUDController { + //NOTE: the ContentContoller POST must receives objects with RDF type set, or it will ignore them + @POST + public Response post(String requestBody) { + // the request object will contain the scene as passed by the client + // e.g. the clientside characters and the selected building + // TODO: context and social context passed in with the scene + Model scene = this.serializeTurtleRequestToModel(requestBody); + + // for now we just add a hard-coded character to the scene + scene = scene.union(ModelFactory.createDefaultModel().read("https://calum.inrupt.net/public/collections/scenedemo.ttl", "TURTLE")); + + return Response.ok(serializeModelToTurtle(scene)).build(); + } +} diff --git a/src/main/webapp/WEB-INF/mudserver.ttl b/src/main/webapp/WEB-INF/mudserver.ttl index f5e3ac0..5f46a07 100644 --- a/src/main/webapp/WEB-INF/mudserver.ttl +++ b/src/main/webapp/WEB-INF/mudserver.ttl @@ -5,7 +5,8 @@ :configuration a mud:Configuration ; mud:worldEndpoint ; + mud:sceneGenerationEndpoint ; mudcontent:SceneDescriptionEndpoint ; mudcontent:SimpleObjectDescriptionEndpoint ; - mudlogic:actionDiscoveryEndpoint ; - mudlogic:Transit . + mudlogic:actionDiscoveryEndpoint ; + mudlogic:Transit . diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index c51165d..828d0a0 100755 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -26,7 +26,7 @@ com.mackervoy.calum.mud.BASE_URL http://localhost:8080/ - The base URL which the site is deployed to e.g. + The base URL which the site is deployed to