Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Adam Kučera
semanticBMS
Commits
dd2fdc98
Commit
dd2fdc98
authored
Jun 24, 2016
by
akucera
Browse files
Addedd support for relations on the server side
parent
dd1c2804
Changes
11
Hide whitespace changes
Inline
Side-by-side
SemanticBMSServer/RDF/SemanticBMS.rdf
View file @
dd2fdc98
...
...
@@ -227,7 +227,7 @@
<ObjectProperty
rdf:about=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#isUsedBy"
>
<inverseOf
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#uses"
/>
<rdfs:domain
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#
DataPoint
"
/>
<rdfs:domain
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#
Address
"
/>
<rdfs:range
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#Algorithm"
/>
</ObjectProperty>
...
...
@@ -322,7 +322,7 @@
<ObjectProperty
rdf:about=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#uses"
>
<rdfs:domain
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#Algorithm"
/>
<rdfs:range
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#
DataPoint
"
/>
<rdfs:range
rdf:resource=
"http://is.muni.cz/www/255658/sbms/v1_0/SemanticBMS#
Address
"
/>
</ObjectProperty>
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/
Influence
sEndpoint.java
→
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/
Relation
sEndpoint.java
View file @
dd2fdc98
...
...
@@ -5,9 +5,11 @@ import java.net.URI;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
import
javax.ws.rs.core.Context
;
...
...
@@ -19,10 +21,12 @@ import org.apache.commons.lang3.StringUtils;
import
org.apache.log4j.Logger
;
import
cz.muni.fi.lasaris.sbms.api.entities.Address
;
import
cz.muni.fi.lasaris.sbms.api.entities.Algorithm
;
import
cz.muni.fi.lasaris.sbms.api.entities.Influence
;
import
cz.muni.fi.lasaris.sbms.api.entities.ObservedProperty
;
import
cz.muni.fi.lasaris.sbms.api.entities.Scope
;
import
cz.muni.fi.lasaris.sbms.api.request.AddressRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.AlgorithmRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.Insert
;
import
cz.muni.fi.lasaris.sbms.api.response.AddressResponse
;
import
cz.muni.fi.lasaris.sbms.api.response.GroupedResponse
;
...
...
@@ -31,10 +35,10 @@ import cz.muni.fi.lasaris.sbms.model.Fields;
import
cz.muni.fi.lasaris.sbms.model.ModelUpdater
;
import
cz.muni.fi.lasaris.sbms.model.QueryParser
;
@Path
(
"
influence
"
)
@Path
(
"
relations
"
)
@PermitAll
public
class
Influence
sEndpoint
{
final
static
Logger
logger
=
Logger
.
getLogger
(
Influence
sEndpoint
.
class
);
public
class
Relation
sEndpoint
{
final
static
Logger
logger
=
Logger
.
getLogger
(
Relation
sEndpoint
.
class
);
@GET
@Path
(
"/influencing"
)
...
...
@@ -87,6 +91,35 @@ public class InfluencesEndpoint {
return
QueryParser
.
getInfluencingResponse
(
r
);
}
@GET
@Path
(
"/used"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
AddressResponse
getUsed
(
@QueryParam
(
"bmsId"
)
String
bmsIdP
)
{
if
(
StringUtils
.
isBlank
(
bmsIdP
))
{
GroupedResponse
.
getErrorResponse
(
"bmsId must be set"
);
}
AlgorithmRequest
r
=
new
AlgorithmRequest
(
new
Algorithm
(
bmsIdP
));
r
.
getResponseFields
().
addAll
(
Fields
.
INFLUENCE_FIELDS
);
return
QueryParser
.
getUsedResponse
(
r
);
}
@GET
@Path
(
"/using"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
AddressResponse
getUsing
(
@QueryParam
(
"bmsId"
)
String
bmsIdP
)
{
if
(
StringUtils
.
isBlank
(
bmsIdP
))
{
GroupedResponse
.
getErrorResponse
(
"bmsId must be set"
);
}
AlgorithmRequest
r
=
new
AlgorithmRequest
(
new
Algorithm
());
r
.
getAlgorithm
().
setUsedAddress
(
new
Address
(
bmsIdP
));
r
.
getResponseFields
().
addAll
(
Fields
.
INFLUENCE_FIELDS
);
return
QueryParser
.
getUsingResponse
(
r
);
}
@GET
@Path
(
"/influenced"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -101,6 +134,8 @@ public class InfluencesEndpoint {
return
QueryParser
.
getInfluencedResponse
(
r
);
}
@Context
private
UriInfo
uriInfo
;
...
...
@@ -112,7 +147,11 @@ public class InfluencesEndpoint {
if
(
insert
.
getAddress
()
!=
null
&&
ModelUpdater
.
insertAddress
(
insert
))
{
URI
createdUri
=
new
URI
(
uriInfo
.
getAbsolutePath
().
toString
()
+
insert
.
getAddress
().
getResourceId
());
return
Response
.
created
(
createdUri
).
build
();
}
else
{
}
else
if
(
insert
.
getAlgorithm
()
!=
null
&&
ModelUpdater
.
insertAlgorithm
(
insert
))
{
URI
createdUri
=
new
URI
(
uriInfo
.
getAbsolutePath
().
toString
()
+
insert
.
getAlgorithm
().
getResourceId
());
return
Response
.
created
(
createdUri
).
build
();
}
else
{
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
).
entity
(
"Invalid JSON data - see server log"
).
build
();
}
}
catch
(
Exception
e
)
{
...
...
@@ -121,4 +160,21 @@ public class InfluencesEndpoint {
}
}
@RolesAllowed
(
"admin"
)
@DELETE
@Path
(
"/{bmsId}"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
Response
RemoveRelationInfo
(
@PathParam
(
"bmsId"
)
String
bmsId
)
{
System
.
out
.
println
(
bmsId
);
try
{
if
(
ModelUpdater
.
removeRelationAssertions
(
bmsId
))
{
return
Response
.
ok
().
build
();
}
else
{
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
).
entity
(
"Invalid JSON data - see server log"
).
build
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
return
Response
.
serverError
().
build
();
}
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/TrendsEndpoint.java
View file @
dd2fdc98
...
...
@@ -5,9 +5,11 @@ import java.net.URI;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
import
javax.ws.rs.core.Context
;
...
...
@@ -139,4 +141,22 @@ final static Logger logger = Logger.getLogger(TrendsEndpoint.class);
}
}
@RolesAllowed
(
"admin"
)
@DELETE
@Path
(
"/{bmsId}"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
Response
RemoveTrendInfo
(
@PathParam
(
"bmsId"
)
String
bmsId
)
{
System
.
out
.
println
(
bmsId
);
try
{
if
(
ModelUpdater
.
removeTrendAssertions
(
bmsId
))
{
return
Response
.
ok
().
build
();
}
else
{
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
).
entity
(
"Invalid JSON data - see server log"
).
build
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
return
Response
.
serverError
().
build
();
}
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Address.java
View file @
dd2fdc98
...
...
@@ -22,8 +22,8 @@ public class Address {
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
dataPointT
ype
)
{
this
.
type
=
dataPointT
ype
;
public
void
setType
(
String
t
ype
)
{
this
.
type
=
t
ype
;
}
@JsonIgnore
...
...
@@ -67,9 +67,9 @@ public class Address {
this
.
bmsId
=
bmsId
;
}
public
Address
(
String
bmsId
,
String
dataPointT
ype
)
{
public
Address
(
String
bmsId
,
String
t
ype
)
{
this
.
bmsId
=
bmsId
;
this
.
type
=
dataPointT
ype
;
this
.
type
=
t
ype
;
}
@Override
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Algorithm.java
View file @
dd2fdc98
...
...
@@ -5,23 +5,23 @@ import java.util.TreeSet;
public
class
Algorithm
extends
Address
{
public
SortedSet
<
DataPoint
>
usedDataPoint
List
;
public
SortedSet
<
Address
>
usedAddress
List
;
public
SortedSet
<
DataPoint
>
getUsedDataPoint
List
()
{
return
used
DataPoint
List
;
public
SortedSet
<
Address
>
getUsedAddress
List
()
{
return
used
Address
List
;
}
public
void
setUsed
DataPoint
List
(
SortedSet
<
DataPoint
>
usedDataPointList
)
{
this
.
used
DataPoint
List
=
usedDataPointList
;
public
void
setUsed
Address
List
(
SortedSet
<
Address
>
usedDataPointList
)
{
this
.
used
Address
List
=
usedDataPointList
;
}
public
DataPoint
getUsedDataPoint
()
{
return
used
DataPoint
List
.
first
();
public
Address
getUsedAddress
()
{
return
used
Address
List
.
first
();
}
public
void
setUsed
DataPoint
(
DataPoint
dp
)
{
used
DataPoint
List
=
new
TreeSet
<
DataPoint
>();
used
DataPoint
List
.
add
(
dp
);
public
void
setUsed
Address
(
Address
a
)
{
used
Address
List
=
new
TreeSet
<
Address
>();
used
Address
List
.
add
(
a
);
}
public
Algorithm
()
{
...
...
@@ -31,8 +31,8 @@ public class Algorithm extends Address {
super
(
bmsId
);
}
public
Algorithm
(
String
bmsId
,
String
dataPointT
ype
)
{
super
(
bmsId
,
dataPointT
ype
);
public
Algorithm
(
String
bmsId
,
String
t
ype
)
{
super
(
bmsId
,
t
ype
);
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/request/AddressRequest.java
View file @
dd2fdc98
...
...
@@ -6,9 +6,11 @@ public class AddressRequest extends Request {
private
Address
address
;
public
AddressRequest
()
{
super
();
}
public
AddressRequest
(
Address
address
)
{
super
();
this
.
address
=
address
;
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/request/AlgorithmRequest.java
0 → 100644
View file @
dd2fdc98
package
cz.muni.fi.lasaris.sbms.api.request
;
import
cz.muni.fi.lasaris.sbms.api.entities.Algorithm
;
public
class
AlgorithmRequest
extends
Request
{
private
Algorithm
algorithm
;
public
Algorithm
getAlgorithm
()
{
return
algorithm
;
}
public
AlgorithmRequest
(
Algorithm
algorithm
)
{
super
();
this
.
algorithm
=
algorithm
;
}
public
void
setAlgorithm
(
Algorithm
algorithm
)
{
this
.
algorithm
=
algorithm
;
}
@Override
public
String
getIdentityField
()
{
return
"bmsId"
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/model/BodyBuilders.java
View file @
dd2fdc98
...
...
@@ -16,8 +16,10 @@ import org.apache.jena.sparql.syntax.ElementOptional;
import
org.apache.jena.sparql.syntax.ElementTriplesBlock
;
import
cz.muni.fi.lasaris.sbms.api.entities.Address
;
import
cz.muni.fi.lasaris.sbms.api.entities.Algorithm
;
import
cz.muni.fi.lasaris.sbms.api.entities.DataPoint
;
import
cz.muni.fi.lasaris.sbms.api.request.AddressRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.AlgorithmRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.DataPointsRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.GroupableRequest
;
import
cz.muni.fi.lasaris.sbms.api.request.TrendsRequest
;
...
...
@@ -342,7 +344,11 @@ public class BodyBuilders {
NodeFactory
.
createURI
(
NS
.
sbms
+
"hasBMSId"
),
NodeFactory
.
createLiteral
(
a
.
getBmsId
())));
}
if
(
fields
.
contains
(
"type"
))
{
setTypeClause
(
body
,
"address"
,
gsv
(
"type"
),
NS
.
sbms
+
"Address"
,
NS
.
sbms
+
"X"
);
}
if
(
a
.
getPublisher
()
!=
null
||
fields
.
contains
(
gsv
(
"publisher.bimId"
)))
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"address"
),
...
...
@@ -410,6 +416,64 @@ public class BodyBuilders {
Var
.
alloc
(
gsv
(
"influenced.property.quality"
))));
}
}
return
body
;
}
public
static
ElementGroup
getQueryBody
(
AlgorithmRequest
request
)
{
ElementGroup
body
=
new
ElementGroup
();
Algorithm
a
=
request
.
getAlgorithm
();
List
<
String
>
fields
=
request
.
getResponseFields
();
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"algorithm"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
"hasBMSId"
),
Var
.
alloc
(
gsv
(
"bmsId"
))));
if
(
a
.
getBmsId
()
!=
null
)
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"algorithm"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
"hasBMSId"
),
NodeFactory
.
createLiteral
(
a
.
getBmsId
())));
}
/*
if(fields.contains("type")) {
setTypeClause(body, "algorithm", gsv("type"), NS.sbms + "Algorithm", NS.sbms + "Algorithm");
}
*/
if
(
a
.
getUsedAddress
()
!=
null
||
fields
.
contains
(
"used.bmsId"
)
||
fields
.
contains
(
"used.type"
))
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"algorithm"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
"uses"
),
Var
.
alloc
(
gsv
(
"used"
))));
if
(
a
.
getUsedAddress
()
!=
null
&&
a
.
getUsedAddress
().
getBmsId
()
!=
null
)
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"used"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
"hasBMSId"
),
NodeFactory
.
createLiteral
(
a
.
getUsedAddress
().
getBmsId
())));
}
if
(
fields
.
contains
(
"used.bmsId"
))
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"used"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
"hasBMSId"
),
Var
.
alloc
(
gsv
(
"used.bmsId"
))));
}
if
(
fields
.
contains
(
"used.type"
))
{
setTypeClause
(
body
,
"used"
,
gsv
(
"type"
),
NS
.
sbms
+
"Address"
,
NS
.
sbms
+
"Address"
);
}
if
(
a
.
getUsedAddress
()
!=
null
&&
a
.
getUsedAddress
().
getType
()
!=
null
)
{
body
.
addTriplePattern
(
Triple
.
create
(
Var
.
alloc
(
"used"
),
NodeFactory
.
createURI
(
NS
.
rdf
+
"type"
),
NodeFactory
.
createURI
(
NS
.
sbms
+
a
.
getUsedAddress
().
getType
())));
}
}
return
body
;
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/model/ModelUpdater.java
View file @
dd2fdc98
...
...
@@ -9,6 +9,7 @@ import org.apache.jena.rdf.model.Resource;
import
org.apache.jena.vocabulary.RDF
;
import
org.apache.log4j.Logger
;
import
cz.muni.fi.lasaris.sbms.api.entities.Address
;
import
cz.muni.fi.lasaris.sbms.api.entities.DataPoint
;
import
cz.muni.fi.lasaris.sbms.api.entities.Influence
;
import
cz.muni.fi.lasaris.sbms.api.request.Insert
;
...
...
@@ -40,9 +41,12 @@ public class ModelUpdater {
// ?dataPoint rdf:type ?dataPointClass.
// ?observation rdf:type sbms:Observation.
dp
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
d
.
getType
()));
obs
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
"Observation"
));
if
(!
dp
.
hasProperty
(
RDF
.
type
))
{
dp
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
d
.
getType
()));
}
if
(!
obs
.
hasProperty
(
RDF
.
type
))
{
obs
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
"Observation"
));
}
// ?dataPoint sbms:hasBMSId ?bmsId.
Property
p
=
null
;
p
=
m
.
createProperty
(
NS
.
sbms
+
"hasBMSId"
);
...
...
@@ -140,34 +144,74 @@ public class ModelUpdater {
}
}
// ?dataPoint sbms:influences ?property.
if
(
d
.
getInfluenceList
()
!=
null
)
{
for
(
Influence
inf
:
d
.
getInfluenceList
())
{
if
(
inf
.
getProperty
()
!=
null
&&
inf
.
getProperty
().
getDomain
()
!=
null
&&
inf
.
getProperty
().
getQuality
()
!=
null
&&
inf
.
getScope
()
!=
null
&&
inf
.
getScope
().
getBimId
()
!=
null
)
{
insertInfluence
(
d
,
m
,
dp
);
TdbConnector
.
commit
();
logger
.
debug
(
"Data commited to the TDB"
);
return
true
;
}
catch
(
Exception
e
)
{
return
failInsert
(
e
);
}
}
Resource
ip
=
m
.
createResource
(
NS
.
sbmsd
+
inf
.
getScope
().
getResourceId
()
+
inf
.
getProperty
().
getDomain
()
+
inf
.
getProperty
().
getQuality
()
+
"ObsProp"
);
ip
.
addProperty
(
RDF
.
type
,
NS
.
sbms
+
m
.
createResource
(
NS
.
sbms
+
"ObservedProperty"
));
private
static
void
insertInfluence
(
Address
entity
,
Model
m
,
Resource
res
)
{
Property
p
;
// ?dataPoint sbms:influences ?property.
if
(
entity
.
getInfluenceList
()
!=
null
)
{
for
(
Influence
inf
:
entity
.
getInfluenceList
())
{
if
(
inf
.
getProperty
()
!=
null
&&
inf
.
getProperty
().
getDomain
()
!=
null
&&
inf
.
getProperty
().
getQuality
()
!=
null
&&
inf
.
getScope
()
!=
null
&&
inf
.
getScope
().
getBimId
()
!=
null
)
{
Resource
ip
=
m
.
createResource
(
NS
.
sbmsd
+
inf
.
getScope
().
getResourceId
()
+
inf
.
getProperty
().
getDomain
()
+
inf
.
getProperty
().
getQuality
()
+
"ObsProp"
);
ip
.
addProperty
(
RDF
.
type
,
NS
.
sbms
+
m
.
createResource
(
NS
.
sbms
+
"ObservedProperty"
));
// ?datapoint sbms:influences ?property.
p
=
m
.
createProperty
(
NS
.
sbms
+
"influences"
);
dp
.
addProperty
(
p
,
ip
);
// ?property sbms:hasPhysicalQuality ?quality.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"hasPhysicalQuality"
),
m
.
createResource
(
NS
.
ucum
+
inf
.
getProperty
().
getQuality
()));
// ?property sbms:hasPropertyDomain ?propDomain.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"hasPropertyDomain"
),
m
.
createResource
(
NS
.
sbms
+
inf
.
getProperty
().
getDomain
()));
// ?property sbms:isPropertyOf ?scope.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"isPropertyOf"
),
m
.
createResource
(
NS
.
sbmsd
+
inf
.
getScope
().
getResourceId
()));
}
// ?datapoint sbms:influences ?property.
p
=
m
.
createProperty
(
NS
.
sbms
+
"influences"
);
res
.
addProperty
(
p
,
ip
);
// ?property sbms:hasPhysicalQuality ?quality.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"hasPhysicalQuality"
),
m
.
createResource
(
NS
.
ucum
+
inf
.
getProperty
().
getQuality
()));
// ?property sbms:hasPropertyDomain ?propDomain.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"hasPropertyDomain"
),
m
.
createResource
(
NS
.
sbms
+
inf
.
getProperty
().
getDomain
()));
// ?property sbms:isPropertyOf ?scope.
ip
.
addProperty
(
m
.
createProperty
(
NS
.
sbms
+
"isPropertyOf"
),
m
.
createResource
(
NS
.
sbmsd
+
inf
.
getScope
().
getResourceId
()));
}
}
}
}
public
static
boolean
insertTrend
(
Insert
insert
)
{
if
(
insert
.
getTrend
()
==
null
||
insert
.
getTrend
().
getBmsId
()
==
null
)
{
return
failInsert
(
"no TL to insert"
);
}
try
{
Model
m
=
TdbConnector
.
getWritableModel
();
Resource
trend
=
m
.
createResource
(
NS
.
sbmsd
+
insert
.
getTrend
().
getResourceId
());
if
(!
trend
.
hasProperty
(
RDF
.
type
))
{
trend
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
"Trend"
));
}
Property
p
=
null
;
p
=
m
.
createProperty
(
NS
.
sbms
+
"hasBMSId"
);
if
(!
trend
.
hasProperty
(
p
))
{
trend
.
addLiteral
(
p
,
insert
.
getTrend
().
getBmsId
());
}
if
(
insert
.
getTrend
().
getDataPoint
()
!=
null
&&
insert
.
getTrend
().
getDataPoint
().
getResourceId
()
!=
null
)
{
Resource
dp
=
m
.
createResource
(
NS
.
sbmsd
+
insert
.
getTrend
().
getDataPoint
().
getResourceId
());
p
=
m
.
createProperty
(
NS
.
sbms
+
"trends"
);
if
(!
trend
.
hasProperty
(
p
))
{
trend
.
addProperty
(
p
,
dp
);
}
}
TdbConnector
.
commit
();
...
...
@@ -176,23 +220,65 @@ public class ModelUpdater {
}
catch
(
Exception
e
)
{
return
failInsert
(
e
);
}
}
public
static
boolean
insertTrend
(
Insert
insert
)
{
// TODO Implement insertTrend
return
false
;
}
public
static
boolean
insertInfluence
(
Insert
insert
)
{
// TODO Implement insertInfluence
return
false
;
public
static
boolean
insertAddress
(
Insert
insert
)
{
if
(
insert
.
getAddress
()
==
null
||
insert
.
getAddress
().
getBmsId
()
==
null
)
{
return
failInsert
(
"no TL to insert"
);
}
try
{
Model
m
=
TdbConnector
.
getWritableModel
();
Resource
address
=
m
.
createResource
(
NS
.
sbmsd
+
insert
.
getTrend
().
getResourceId
());
if
(!
address
.
hasProperty
(
RDF
.
type
))
{
address
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
insert
.
getAddress
().
getType
()));
}
Property
p
=
null
;
p
=
m
.
createProperty
(
NS
.
sbms
+
"hasBMSId"
);
if
(!
address
.
hasProperty
(
p
))
{
address
.
addLiteral
(
p
,
insert
.
getAddress
().
getBmsId
());
}
insertInfluence
(
insert
.
getAddress
(),
m
,
address
);
TdbConnector
.
commit
();
logger
.
debug
(
"Data commited to the TDB"
);
return
true
;
}
catch
(
Exception
e
)
{
return
failInsert
(
e
);
}
}
public
static
boolean
insertAddress
(
Insert
insert
)
{
// TODO Implement program insert
return
false
;
public
static
boolean
insertAlgorithm
(
Insert
insert
)
{
if
(
insert
.
getAlgorithm
()
==
null
||
insert
.
getAlgorithm
().
getBmsId
()
==
null
)
{
return
failInsert
(
"no algorithm to insert"
);
}
try
{
Model
m
=
TdbConnector
.
getWritableModel
();
Resource
alg
=
m
.
createResource
(
NS
.
sbmsd
+
insert
.
getAlgorithm
().
getResourceId
());
Property
p
=
null
;
if
(!
alg
.
hasProperty
(
RDF
.
type
))
{
alg
.
addProperty
(
RDF
.
type
,
m
.
createResource
(
NS
.
sbms
+
"Algorithm"
));
}
p
=
m
.
createProperty
(
NS
.
sbms
+
"hasBMSId"
);
if
(!
alg
.
hasProperty
(
p
))
{
alg
.
addLiteral
(
p
,
insert
.
getAlgorithm
().
getBmsId
());
}
if
(
insert
.
getAlgorithm
().
getUsedAddressList
()
!=
null
)
{
for
(
Address
a
:
insert
.
getAlgorithm
().
getUsedAddressList
())
{
Resource
address
=
m
.
createResource
(
NS
.
sbmsd
+
a
.
getResourceId
());
p
=
m
.
createProperty
(
NS
.
sbms
+
"uses"
);
alg
.
addProperty
(
p
,
address
);
}
}
TdbConnector
.
commit
();
logger
.
debug
(
"Data commited to the TDB"
);
return
true
;
}
catch
(
Exception
e
)
{
return
failInsert
(
e
);
}
}
private
static
boolean
failInsert
(
Object
msg
)
{
...
...
@@ -208,7 +