Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Deployment: initializing world from template #9

Open
5 tasks
calummackervoy opened this issue Feb 27, 2021 · 8 comments · May be fixed by #29
Open
5 tasks

Deployment: initializing world from template #9

calummackervoy opened this issue Feb 27, 2021 · 8 comments · May be fixed by #29
Assignees
Labels
enhancement New feature or request

Comments

@calummackervoy
Copy link
Member

calummackervoy commented Feb 27, 2021

At the moment in MUDApplication a demo world is created on startup using hardcoded calls to the Jena API. I have in mind that we could instead pass a Turtle file through the web.xml and via that import the configured template into the world dataset. There may be a better design I'm overlooking

TODOs in code referencing this issue

@calummackervoy calummackervoy added the enhancement New feature or request label Feb 27, 2021
@calummackervoy
Copy link
Member Author

Deploying templates to Tomcat along with the .WAR file

e.g. a directory /templates/ which is deployed to the server when I hit run server in eclipse or deploy to a docker container

I think we need a similar thing to work with Jena reasoners, e.g. I'm working at the moment on the logic "if the RDF type is of Building and the class Building is a subclass of mud:Locatable then the instance is also a mud:Locatable" (https://stackoverflow.com/questions/32670869/how-to-use-transitive-reasoner-with-jena) ... writing a rule file like in the SO answer clearly the reusable way to do it but I'm not sure how to have this deploy with the Java app to a relative directory that I can access at runtime

@MattTennison does it make sense? Do you know to do this in a Java project? Are you interested in it?

@MattTennison
Copy link
Collaborator

Ahh, do you mean replacing this block of code with something less...hardcoded?

Resource stadium = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("building", "south_babylon_fc_stadium"));
model.add(stadium, RDF.type, MUDBuildings.Stadium);
model.add(stadium, VCARD4.fn, "South Babylon Football Club Stadium");
Resource image = ResourceFactory.createResource("https://www.arthistoryabroad.com/wp-content/uploads/2013/08/LOWRY-Football-Match.jpg");
model.add(stadium, MUD.primaryImageContent, image);
model.add(stadium, MUD.primaryTextContent, "A towering brickwork structure of an industrial appearance");
// there's a match at the stadium
Resource match = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("event", "demo_football_match"));
model.add(match, RDF.type, MUDEvents.FootballMatch);
Resource matchBegins = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("instant", "demo_football_match_begins"));
model.add(matchBegins, RDF.type, Time.Instant);
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
model.add(matchBegins, Time.inXSDDateTimeStamp, LocalDateTime.now().format(formatter));
Resource matchEnds = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("instant", "demo_football_match_ends"));
model.add(matchEnds, RDF.type, Time.Instant);
model.add(matchEnds, Time.inXSDDateTimeStamp, LocalDateTime.now().plusHours(2).format(formatter));
model.add(match, Time.hasBeginning, matchBegins);
model.add(match, Time.hasEnd, matchEnds);
model.add(stadium, MUDEvents.hasEvent, match);
// add a night club in Babylon
Resource collective = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("building", "the_collective_night_club"));
model.add(collective, RDF.type, MUDBuildings.Nightclub);
model.add(collective, VCARD4.fn, "The Collective Night Club");
Resource babylon = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("settlement", "babylon"));
model.add(babylon, RDF.type, MUD.Settlement);
model.add(babylon, VCARD4.fn, "Babylon");
model.add(babylon, MUD.population, "8000000");
model.add(babylon, MUD.hasBuilding, stadium);
model.add(babylon, MUD.hasBuilding, collective);
model.add(babylon, MUD.primaryTextContent, "The Capital of the Babylonian Empire");
Resource roric = ResourceFactory.createResource(TDBStore.WORLD.getNewResourceUri("settlement", "roric"));
model.add(roric, RDF.type, MUD.Settlement);
model.add(roric, VCARD4.fn, "Roric");
model.add(roric, MUD.population, "1000000");
model.add(roric, MUD.primaryTextContent, "The Second City of the Babylon region, but a cosmopolis in its own right, and an industrial powerhouse");

If so, I get what you're saying - pull that out into a separate file that gets loaded in dynamically. That feels like a good first step, but we'd probably want to take it further, and remove it from the code altogether, instead relying on a DB or something more permanent (so updates to the initial world state don't involve a fresh deployment of the code).

Happy to take a closer look, sounds like an interesting problem 😄 Is it blocking the logic you're building right now?

@calummackervoy
Copy link
Member Author

yeah definitely that's what the issue is about - but the first step to that I think is being able to deploy a file directory onto the Tomcat server alongside the WAR?

We do store it in a DB (using Apache Jena's Triplestore/NoSQL database engine), but the init data here (for a demo) could be read from a turtle "template"/import file I think? And the second checkbox is about having the template/import file configured by the web.xml so that it can easily be changed/deployed with some other data. What do you think?

@calummackervoy
Copy link
Member Author

Nah it's not blocking :) I think that we will need to deploy rules files to the server with the WAR for more complex/exciting inferences as part of describers and things (e.g. "I'm a Tottenham fan and so I can deduce that Millwall scarves are not to my taste"), but for inferring that "a Fish is also an animal" I can hardcode it in the meantime, or temporarily add another RDF property to the POST data as a workaround

@MattTennison
Copy link
Collaborator

MattTennison commented Mar 7, 2021

yeah definitely that's what the issue is about - but the first step to that I think is being able to deploy a file directory onto the Tomcat server alongside the WAR?

We do store it in a DB (using Apache Jena's Triplestore/NoSQL database engine), but the init data here (for a demo) could be read from a turtle "template"/import file I think? And the second checkbox is about having the template/import file configured by the web.xml so that it can easily be changed/deployed with some other data. What do you think?

Gotcha! Okay, so we could have an example template in the codebase as it's own file, but we don't mandate people use it, or modify that specific file - rather they point to a different location at their version via the web.xml.

Yeah, I can pick this up 😄

@MattTennison MattTennison linked a pull request Mar 28, 2021 that will close this issue
@calummackervoy
Copy link
Member Author

@MattTennison I'm not sure if the first task on this list is necessary? #34

If running the Java server is the responsibility of the application using Mud-Jena (particularly if the specifics of that - i.e. Tomcat - aren't a part of this repo), then we can assume that they will do their own template upload or use a URL from somewhere else on the web

Then all we need to do is add some custom web.xml config values for a file name or URI and then load the template from there during init

@calummackervoy
Copy link
Member Author

I suppose that the first task is still great if you've already done it, and we'd just want to move it to a mud-tomcat repository

@calummackervoy
Copy link
Member Author

For the second task... I think that in Jersey/JAX-RS this is fairly straightforward: https://stackoverflow.com/questions/17324075/get-configuration-data-from-web-xml-when-using-a-jersey-servletcontainer

I've already started doing this task for #23 so I could pick it up, we need to synchronise on this issue I think 😅

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants