This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Multi-User-Domain/33-action-discovery
Action discovery
- Loading branch information
Showing
6 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/com/mackervoy/calum/mud/AbstractMUDController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/mackervoy/calum/mud/behaviour/ActionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.mackervoy.calum.mud.behaviour; | ||
|
||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Resource; | ||
import org.apache.jena.vocabulary.RDF; | ||
|
||
import java.util.Set; | ||
|
||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import com.mackervoy.calum.mud.AbstractMUDController; | ||
import com.mackervoy.calum.mud.MUDApplication; | ||
import com.mackervoy.calum.mud.behaviour.task.TaskActorFactory; | ||
import com.mackervoy.calum.mud.vocabularies.MUDLogic; | ||
|
||
/** | ||
* @author Calum Mackervoy | ||
* Provides Action Discovery (https://multi-user-domain.github.io/docs/05-action-server.html) | ||
*/ | ||
|
||
@Path("/mud/act/discover/") | ||
public class ActionController extends AbstractMUDController { | ||
private String getActAtURL(Resource action) { | ||
String base = MUDApplication.getSiteUrl() + "mud/act/"; | ||
return action.getPropertyResourceValue(RDF.type) == MUDLogic.Task ? base + "task/" : base; | ||
} | ||
|
||
// pass a URI in the query string for an object | ||
// expect to get back the configured endpoints for actions and tasks on this object | ||
@POST | ||
public Response discoverActions(String requestBody) { | ||
// TODO: analyse the objects in the request (the scene), and return those Actions which have matching shapes for them | ||
// https://github.com/Multi-User-Domain/mud-jena/issues/44 | ||
// final Model request = this.serializeTurtleRequestToModel(requestBody); | ||
|
||
Model result = ModelFactory.createDefaultModel(); | ||
|
||
Set<String> keys = TaskActorFactory.keySet(); | ||
|
||
for(String key : keys) { | ||
Model m = ModelFactory.createDefaultModel().read(key, "TURTLE"); | ||
Resource r = m.getResource(key); | ||
result.add(r, RDF.type, r.getPropertyResourceValue(RDF.type)); | ||
result.add(r, MUDLogic.actAt, this.getActAtURL(r)); | ||
} | ||
|
||
String responseData = result.isEmpty() ? null : serializeModelToTurtle(result); | ||
return Response.ok(responseData).build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
@prefix : <#>. | ||
@prefix mud: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mud.ttl#>. | ||
@prefix mudcontent: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mudcontent.ttl#>. | ||
@prefix mudlogic: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mudlogic.ttl#>. | ||
|
||
:configuration a mud:Configuration ; | ||
mud:worldEndpoint <http://localhost:8080/mud/world/> ; | ||
mudcontent:SceneDescriptionEndpoint <http://localhost:8080/mud/content/> ; | ||
mudcontent:SimpleObjectDescriptionEndpoint <http://localhost:8080/mud/content/> . | ||
mudcontent:SimpleObjectDescriptionEndpoint <http://localhost:8080/mud/content/> ; | ||
mudlogic:actionDiscoveryEndpoint <http://localhost:8000/mud/act/discover/> ; | ||
mudlogic:Transit <http://localhost:8000/mud/act/task/> . |