Skip to content

Commit

Permalink
in /create , /create-data , add HTTP param. subjecturi to control the…
Browse files Browse the repository at this point in the history
… subject URI created

TODO test !!!
  • Loading branch information
jmvanel committed Mar 8, 2017
1 parent c373f75 commit 3040f5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ trait UnfilledFormFactory[Rdf <: RDF, DATASET]
/**
* create Form from a class URI,
* looking up for Form Configuration within RDF graph
*
* TODO check URI arguments: they must valid be absolute
* TODO return Try
*/
def createFormFromClass(classe: Rdf#URI,
formSpecURI0: String = "" , request: HTTPrequest= HTTPrequest() )
Expand Down Expand Up @@ -52,7 +55,12 @@ trait UnfilledFormFactory[Rdf <: RDF, DATASET]
} else classs
println(s">>> UnfilledFormFactory.createFormFromClass: classFromSpecsOrGiven <$classFromSpecsOrGiven>")

val newId = makeId(request)
val instanceURI = getFirstNonEmptyInMap(request.queryString, "subjecturi")
val newId = if (instanceURI == "")
makeId(request)
else
instanceURI

if (propsListInFormConfig.isEmpty) {
val props = fieldsFromClass(classFromSpecsOrGiven, graph).propertiesList
createFormDetailed(makeUri(newId), addRDFSLabelComment(props), classFromSpecsOrGiven, CreationMode)
Expand All @@ -61,4 +69,11 @@ trait UnfilledFormFactory[Rdf <: RDF, DATASET]
CreationMode, formConfig = formConfig)
}

// TODO put in reusable trait
private def getFirstNonEmptyInMap(
map: Map[String, Seq[String]],
uri: String): String = {
val uriArgs = map.getOrElse(uri, Seq())
uriArgs.find { uri => uri != "" }.getOrElse("") . trim()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ trait ApplicationFacade[Rdf <: RDF, DATASET]
impl.create(classUri, lang, formSpecURI, graphURI, request: HTTPrequest).get

def createDataAsJSON(classUri: String, lang: String, formSpecURI: String,
// graphURI: String,
request: HTTPrequest ): String =
impl.createDataAsJSON(classUri, lang, formSpecURI,
// graphURI,
request: HTTPrequest)

def lookup(search: String, lang: String = "en", clas: String ="", mime: String=""): String =
Expand Down
8 changes: 4 additions & 4 deletions scala/forms_play/app/controllers/ApplicationTrait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ trait ApplicationTrait extends Controller
Action { implicit request =>
logger.info("create: " + request)
// URI of RDF class from which to create instance
val uri0 = getFirstNonEmptyInMap(request.queryString, "uri")
val uri = expandOrUnchanged(uri0)
val classUri0 = getFirstNonEmptyInMap(request.queryString, "uri")
val classUri = expandOrUnchanged(classUri0)
// URI of form Specification
val formSpecURI = getFirstNonEmptyInMap(request.queryString, "formuri")
logger.info(s"create: <$uri>")
logger.info(s"create: class URI <$classUri>")
logger.info(s"create: formSpecURI from HTTP request: <$formSpecURI>")

Ok(createDataAsJSON(uri, chooseLanguage(request),
Ok(createDataAsJSON(classUri, chooseLanguage(request),
formSpecURI,
copyRequest(request))).
as(AcceptsJSONLD.mimeType + "; charset=" + myCustomCharset.charset)
Expand Down

0 comments on commit 3040f5a

Please sign in to comment.