Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple example for LDP service #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A simple beginner project for eniLINK web applications.
* run `mvn test -Pconfigure -DskipTests` to initialize or update a launch configuration
* run `mvn test` to (re-)start the eniLINK platform
* The application should now be available at: [http://localhost:8080/beginner/](http://localhost:8080/beginner/)
* The LDP service (with default configuration) should be available at: [http://localhost:8080/ldp/](http://localhost:8080/ldp/)

## Developing
* The project can be developed with any IDE supporting Java and Scala projects
Expand Down
5 changes: 5 additions & 0 deletions net.enilink.beginner.web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<version>${enilink.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.enilink.platform</groupId>
<artifactId>net.enilink.platform.ldp</artifactId>
<version>${enilink.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.enilink.beginner.web

import net.enilink.komma.core.{Statement, URI, URIs}
import net.enilink.platform.ldp.{LDP, LDPHelper}
import net.enilink.platform.lift.util.Globals
import net.enilink.vocab.rdf.RDF
import net.enilink.vocab.rdfs.RDFS
import net.liftweb.common.Full

import scala.jdk.CollectionConverters._

object LDPServiceExample extends LDPHelper {
// // use Handler to configure LDP service
// val handler = new BasicContainerHandler("ldp")
// val rootUri = URIs.createURI(s"""http://localhost:8080/${ handler.getPath }/""")

// use default configuration
val rootUri = URIs.createURI("http://localhost:8080/ldp/")
// initialize the root container
init(rootUri)

// register LDP endpoint for resources
register("ldp", rootUri, null)

protected def init(uri: URI) = Globals.contextModelSet.vend.map { ms =>
ms.getUnitOfWork.begin
try {
// create the resource model if it does not yet exist
val m = ms.createModel(uri)
m.setLoaded(true)
m.getManager.add(List(
new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_RESOURCE),
//new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_RDFSOURCE),
//new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_CONTAINER),
new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_BASICCONTAINER),
new Statement(uri, RDFS.PROPERTY_LABEL, "LDP Basic container"),
new Statement(uri, RDFS.PROPERTY_COMMENT, "root container for various RDF and none-RDF resources including containers ")).asJava)

// side effect for rdfa templates: set Globals.contextModel
Globals.contextModel.default.set(() => Full(m))
} catch {
case t: Throwable => t.printStackTrace
} finally {
ms.getUnitOfWork.end
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package net.enilink.beginner.web


import scala.language.implicitConversions

import net.enilink.komma.core.URIs
import net.enilink.platform.lift.sitemap.HideIfInactive
import net.enilink.platform.lift.sitemap.Menus
import net.enilink.platform.lift.sitemap.Menus._
import net.enilink.platform.lift.util.Globals
import net.liftweb.common.Full
import net.liftweb.http.Req
import net.liftweb.http.S
import net.liftweb.http.{LiftRules, RedirectResponse, Req, S}
import net.liftweb.sitemap.SiteMap

/**
Expand Down Expand Up @@ -54,8 +52,23 @@ class LiftModule {
Globals.contextModelRules.prepend {
case Req(`app` :: _, _, _) if !S.param("model").isDefined => Full(DEFAULT_MODEL_URI)
}
// add DOM LDP service
LiftRules.dispatch.append(LDPServiceExample)
}

// def boot {
// // redirect to index
// LiftRules.statelessDispatch.prepend {
// case Req(`app` :: Nil, _, _) => {
// () => Full(RedirectResponse(s"/$app/"))
// }
// }
//
// // add DOM LDP service
// LiftRules.dispatch.append(LDPServiceExample)
// }


def shutdown {
}
}