@@ -79,7 +79,7 @@ class ResourceQuery{
7979 ` ;
8080 return this . query ;
8181 }
82- newResource ( endpointParameters , user , graphName , newResourceURI ) {
82+ newResource ( endpointParameters , user , graphName , newResourceURI , templateResourceURI ) {
8383 //todo: consider different value types
8484 let { gStart, gEnd} = this . prepareGraphName ( graphName ) ;
8585 let userSt = '' ;
@@ -88,16 +88,37 @@ class ResourceQuery{
8888 }
8989 let date = new Date ( ) ;
9090 let currentDate = date . toISOString ( ) ; //"2011-12-19T15:28:46.493Z"
91- this . query = `
92- INSERT DATA {
93- ${ gStart }
94- <${ newResourceURI } > a ldr:Resource ;
95- ldr:createdOn "${ currentDate } "^^xsd:dateTime;
96- ${ userSt }
97- rdfs:label "New Resource" .
98- ${ gEnd }
91+ // use a template for resource if set
92+ if ( templateResourceURI ) {
93+ this . query = `
94+ INSERT {
95+ ${ gStart }
96+ <${ newResourceURI } > ?p ?o ;
97+ ldr:createdOn "${ currentDate } "^^xsd:dateTime;
98+ ${ userSt }
99+ ${ gEnd }
100+ } WHERE {
101+ ${ gStart }
102+ <${ templateResourceURI } > ?p ?o .
103+ FILTER (?p != ldr:cloneOf && ?p != ldr:createdOn && ?p != ldr:createdBy)
104+ ${ gEnd }
105+ }
106+ ` ;
107+ } else {
108+ // create an empty resource
109+ this . query = `
110+ INSERT DATA {
111+ ${ gStart }
112+ <${ newResourceURI } > a ldr:Resource ;
113+ ldr:createdOn "${ currentDate } "^^xsd:dateTime;
114+ ${ userSt }
115+ rdfs:label "New Resource" .
116+ ${ gEnd }
117+ }
118+ ` ;
99119 }
100- ` ;
120+
121+
101122 return this . query ;
102123 }
103124 annotateResource ( endpointParameters , user , datasetURI , graphName , resourceURI , propertyURI , annotations , inNewDataset ) {
0 commit comments