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
c602b92e
Commit
c602b92e
authored
Jun 16, 2016
by
akucera
Browse files
added support for influence queries
parent
64b24b7b
Changes
14
Hide whitespace changes
Inline
Side-by-side
SemanticBMSClient/insert.html
View file @
c602b92e
...
...
@@ -208,11 +208,11 @@ sendInsertSingle: function () {
var
dp
=
{};
$
(
"
#params input.field,select.field
"
).
each
(
function
()
{
var
val
=
$
(
this
).
val
();
p
.
setDpField
(
dp
,
getField
(
this
.
id
),
val
);
p
.
setDpField
(
dp
,
p
.
getField
(
this
.
id
),
val
);
});
if
(
dp
!=
null
)
{
p
.
insertDP
(
dp
,
toggleButtonSending
,
toggleButtonSuccess
,
toggleButtonError
,
toggleButtonComplete
,
"
logSingle
"
);
p
.
insertDP
(
dp
,
p
.
toggleButtonSending
,
p
.
toggleButtonSuccess
,
p
.
toggleButtonError
,
p
.
toggleButtonComplete
,
"
logSingle
"
);
}
},
...
...
SemanticBMSClient/query.html
View file @
c602b92e
...
...
@@ -63,11 +63,11 @@ var p = new SBMSPage (function() {
});
$
(
"
#showJSON
"
).
click
(
function
()
{
switchPanel
(
"
resultsNav
"
,
"
resultsDiv
"
,
this
.
id
,
"
resultsJSON
"
);
p
.
switchPanel
(
"
resultsNav
"
,
"
resultsDiv
"
,
this
,
"
resultsJSON
"
);
});
$
(
"
#showTable
"
).
click
(
function
()
{
switchPanel
(
"
resultsNav
"
,
"
resultsDiv
"
,
this
.
id
,
"
resultsTable
"
);
p
.
switchPanel
(
"
resultsNav
"
,
"
resultsDiv
"
,
this
,
"
resultsTable
"
);
});
$
(
"
#mapSelect
"
).
dialog
({
...
...
@@ -134,7 +134,7 @@ var p = new SBMSPage (function() {
}
html
+=
"
</tr>
"
// getting datapoints
$
.
each
(
data
.
dataPoin
ts
[
group
],
function
(
index2
,
dp
)
{
$
.
each
(
data
.
resul
ts
[
group
],
function
(
index2
,
dp
)
{
html
+=
"
<tr><td></td>
"
;
$
.
each
(
fields
,
function
(
index
,
field
)
{
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/DataPointsEndpoint.java
View file @
c602b92e
...
...
@@ -17,18 +17,16 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.UriInfo
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.log4j.Logger
;
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.entities.ObservedProperty
;
import
cz.muni.fi.lasaris.sbms.api.entities.Scope
;
import
cz.muni.fi.lasaris.sbms.api.entities.Sensing
;
import
cz.muni.fi.lasaris.sbms.api.entities.Source
;
import
cz.muni.fi.lasaris.sbms.api.request.DataPointInsert
;
import
cz.muni.fi.lasaris.sbms.api.request.DataPointsRequest
;
import
cz.muni.fi.lasaris.sbms.api.response.
DataPoints
Response
;
import
cz.muni.fi.lasaris.sbms.api.response.
Grouped
Response
;
import
cz.muni.fi.lasaris.sbms.model.ModelUpdater
;
import
cz.muni.fi.lasaris.sbms.model.QueryParser
;
...
...
@@ -44,7 +42,7 @@ public class DataPointsEndpoint {
@RolesAllowed
({
"user"
,
"admin"
})
@GET
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
DataPoints
Response
getDataPoints
(
public
Grouped
Response
getDataPoints
(
@QueryParam
(
"bmsId"
)
String
dpIdP
,
@QueryParam
(
"type"
)
String
dptP
,
@QueryParam
(
"source.bimId"
)
String
sourceIdP
,
...
...
@@ -106,19 +104,20 @@ public class DataPointsEndpoint {
}
if
(
ip
!=
null
||
is
!=
null
)
{
Influence
i
=
new
Influence
(
ip
,
is
);
dp
.
setInfluence
(
i
);
dp
.
setOneInfluence
();
dp
.
getFirstInfluence
().
setProperty
(
ip
);
dp
.
getFirstInfluence
().
setScope
(
is
);
}
dpr
.
setGrouping
(
groupingP
);
se
t
ResponseFields
(
fieldsP
,
dpr
);
dpr
.
par
seResponseFields
(
fieldsP
);
try
{
return
QueryParser
.
getDataPoint
s
(
dpr
);
return
QueryParser
.
getDataPoint
Response
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
.
toString
());
e
.
printStackTrace
();
DataPoints
Response
r
=
new
DataPoints
Response
();
Grouped
Response
r
=
new
Grouped
Response
();
r
.
setError
(
e
.
toString
());
return
r
;
}
...
...
@@ -128,7 +127,7 @@ public class DataPointsEndpoint {
@GET
@Path
(
"/{bmsId}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
DataPoints
Response
getDataPoint
(
public
Grouped
Response
getDataPoint
(
@PathParam
(
"bmsId"
)
String
bmsIdP
,
@QueryParam
(
"fields"
)
String
fieldsP
)
{
...
...
@@ -137,13 +136,13 @@ public class DataPointsEndpoint {
dp
.
setBmsId
(
bmsIdP
);
dpr
.
setDataPoint
(
dp
);
se
t
ResponseFields
(
fieldsP
,
dpr
);
dpr
.
par
seResponseFields
(
fieldsP
);
try
{
return
QueryParser
.
getDataPoint
s
(
dpr
);
return
QueryParser
.
getDataPoint
Response
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
);
DataPoints
Response
r
=
new
DataPoints
Response
();
Grouped
Response
r
=
new
Grouped
Response
();
r
.
setError
(
e
.
toString
());
return
r
;
}
...
...
@@ -182,18 +181,7 @@ public class DataPointsEndpoint {
logger
.
error
(
e
);
return
Response
.
serverError
().
build
();
}
}
private
void
setResponseFields
(
String
fields
,
DataPointsRequest
dpr
)
{
if
(
fields
!=
null
)
{
for
(
String
f
:
fields
.
split
(
","
))
{
if
(
StringUtils
.
isNotEmpty
(
f
))
{
dpr
.
getResponseFields
().
add
(
f
);
}
}
}
}
}
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/InfluencesEndpoint.java
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api
;
import
javax.annotation.security.PermitAll
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.MediaType
;
import
org.apache.commons.lang3.StringUtils
;
import
cz.muni.fi.lasaris.sbms.api.entities.DataPoint
;
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.DataPointsRequest
;
import
cz.muni.fi.lasaris.sbms.api.response.GroupedResponse
;
import
cz.muni.fi.lasaris.sbms.model.Fields
;
import
cz.muni.fi.lasaris.sbms.model.QueryParser
;
@Path
(
"influence"
)
@PermitAll
public
class
InfluencesEndpoint
{
/*
public InfluenceResponse getInfluence(
@QueryParam("bmsId") String bmsIdP,
@QueryParam("scope.bimId") String scopeBimIdP,
@QueryParam("property.domain") String propDomP,
@QueryParam("property.quality") String propQualityP) {
InfluenceRequest r = new
}
TODO Vymyslet parametry u Influence - nema tam taky byt filtrovani jako vsude jinde?
@GET
@Path
(
"/influencing"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
GroupedResponse
getInfluencing
(
@QueryParam
(
"influenced.scope.bimId"
)
String
scopeBimIdP
,
@QueryParam
(
"influenced.property.domain"
)
String
propDomP
,
@QueryParam
(
"influenced.property.quality"
)
String
propQualityP
,
@QueryParam
(
"grouping"
)
String
groupingP
,
@QueryParam
(
"fields"
)
String
fieldsP
)
{
if
(
scopeBimIdP
==
null
&&
propDomP
==
null
&&
propQualityP
==
null
)
{
return
GroupedResponse
.
getErrorResponse
(
"Parameters must be set"
);
}
if
(!(
propDomP
==
null
&&
propQualityP
==
null
)
&&
(
propDomP
==
null
||
propQualityP
==
null
))
{
return
GroupedResponse
.
getErrorResponse
(
"Both parameters (domain, quality) must be set"
);
}
if
(
propDomP
!=
null
&&
scopeBimIdP
==
null
)
{
return
GroupedResponse
.
getErrorResponse
(
"Scope must be set when property is set"
);
}
DataPointsRequest
r
=
new
DataPointsRequest
();
DataPoint
dp
=
new
DataPoint
();
r
.
setDataPoint
(
dp
);
dp
.
setOneInfluence
();
if
(
StringUtils
.
isNotBlank
(
scopeBimIdP
))
{
dp
.
getFirstInfluence
().
setScope
(
new
Scope
());
dp
.
getFirstInfluence
().
getScope
().
setBimId
(
scopeBimIdP
);
}
if
(
StringUtils
.
isNotBlank
(
propDomP
))
{
dp
.
getFirstInfluence
().
setProperty
(
new
ObservedProperty
());
dp
.
getFirstInfluence
().
getProperty
().
setDomain
(
propDomP
);
}
if
(
StringUtils
.
isNotBlank
(
propQualityP
)){
if
(
dp
.
getFirstInfluence
().
getProperty
()
==
null
)
{
dp
.
getFirstInfluence
().
setProperty
(
new
ObservedProperty
());
}
dp
.
getFirstInfluence
().
getProperty
().
setQuality
(
propQualityP
);
}
r
.
parseResponseFields
(
fieldsP
);
r
.
getResponseFields
().
addAll
(
Fields
.
INFLUENCE_FIELDS
);
r
.
setGrouping
(
groupingP
);
return
QueryParser
.
getInfluencingResponse
(
r
);
}
@GET
@Path
(
"/influenced"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
GroupedResponse
getInfluenced
(
@QueryParam
(
"bmsId"
)
String
bmsIdP
)
{
if
(
StringUtils
.
isBlank
(
bmsIdP
))
{
GroupedResponse
.
getErrorResponse
(
"bmsId must be set"
);
}
DataPointsRequest
r
=
new
DataPointsRequest
();
DataPoint
dp
=
new
DataPoint
();
r
.
setDataPoint
(
dp
);
if
(
StringUtils
.
isNotBlank
(
bmsIdP
))
{
dp
.
setBmsId
(
bmsIdP
);
}
r
.
getResponseFields
().
add
(
"bmsId"
);
r
.
getResponseFields
().
addAll
(
Fields
.
INFLUENCE_FIELDS
);
return
QueryParser
.
getInfluencedResponse
(
r
);
}
*/
// Inserting and Removing of influence is be performed by DataPointsEndpoint
// Inserting and Removing of influence is performed by DataPointsEndpoint
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/TrendsEndpoint.java
View file @
c602b92e
...
...
@@ -20,7 +20,7 @@ import cz.muni.fi.lasaris.sbms.api.entities.Scope;
import
cz.muni.fi.lasaris.sbms.api.entities.Sensing
;
import
cz.muni.fi.lasaris.sbms.api.entities.Source
;
import
cz.muni.fi.lasaris.sbms.api.request.DataPointsRequest
;
import
cz.muni.fi.lasaris.sbms.api.response.
DataPoints
Response
;
import
cz.muni.fi.lasaris.sbms.api.response.
Grouped
Response
;
import
cz.muni.fi.lasaris.sbms.model.QueryParser
;
@Path
(
"trends"
)
...
...
@@ -34,7 +34,7 @@ final static Logger logger = Logger.getLogger(DataPointsEndpoint.class);
@RolesAllowed
({
"user"
,
"admin"
})
@GET
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
DataPoints
Response
getTrends
(
public
Grouped
Response
getTrends
(
@QueryParam
(
"bmsId"
)
String
dpIdP
,
@QueryParam
(
"type"
)
String
dptP
,
@QueryParam
(
"source.bimId"
)
String
sourceIdP
,
...
...
@@ -95,19 +95,20 @@ final static Logger logger = Logger.getLogger(DataPointsEndpoint.class);
}
if
(
ip
!=
null
||
is
!=
null
)
{
Influence
i
=
new
Influence
(
ip
,
is
);
dp
.
setInfluence
(
i
);
dp
.
setOneInfluence
();
dp
.
getFirstInfluence
().
setProperty
(
ip
);
dp
.
getFirstInfluence
().
setScope
(
is
);
}
dpr
.
setGrouping
(
groupingP
);
setResponseFields
(
fieldsP
,
dpr
);
try
{
return
QueryParser
.
getDataPoint
s
(
dpr
);
return
QueryParser
.
getDataPoint
Response
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
.
toString
());
e
.
printStackTrace
();
DataPoints
Response
r
=
new
DataPoints
Response
();
Grouped
Response
r
=
new
Grouped
Response
();
r
.
setError
(
e
.
toString
());
return
r
;
}
...
...
@@ -124,5 +125,5 @@ final static Logger logger = Logger.getLogger(DataPointsEndpoint.class);
}
}
// TODO Inserting and Removing of
influence is
be performed by DataPointsEndpoint
// TODO Inserting and Removing of
trends must
be performed by DataPointsEndpoint
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/DataPoint.java
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api.entities
;
import
java.util.SortedSet
;
import
java.util.TreeSet
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.apache.commons.lang3.StringEscapeUtils
;
...
...
@@ -9,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
@XmlRootElement
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
DataPoint
{
public
class
DataPoint
implements
Groupable
{
private
String
bmsId
;
private
String
type
;
...
...
@@ -18,7 +21,7 @@ public class DataPoint {
private
Sensing
sensing
;
private
ObservedProperty
property
;
private
Influence
influence
;
private
SortedSet
<
Influence
>
influence
;
@JsonIgnore
private
String
group
;
...
...
@@ -76,14 +79,23 @@ public class DataPoint {
this
.
property
=
property
;
}
public
Influence
getInfluence
()
{
public
SortedSet
<
Influence
>
getInfluence
()
{
return
influence
;
}
public
void
setInfluence
(
Influence
influence
)
{
public
Influence
getFirstInfluence
()
{
return
influence
.
first
();
}
public
void
setInfluence
(
SortedSet
<
Influence
>
influence
)
{
this
.
influence
=
influence
;
}
public
void
setOneInfluence
()
{
this
.
influence
=
new
TreeSet
<
Influence
>();
this
.
influence
.
add
(
new
Influence
());
}
public
String
getBmsId
()
{
return
bmsId
;
}
...
...
@@ -104,6 +116,33 @@ public class DataPoint {
public
void
setGroup
(
String
group
)
{
this
.
group
=
group
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
bmsId
==
null
)
?
0
:
bmsId
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
DataPoint
other
=
(
DataPoint
)
obj
;
if
(
bmsId
==
null
)
{
if
(
other
.
bmsId
!=
null
)
return
false
;
}
else
if
(!
bmsId
.
equals
(
other
.
bmsId
))
return
false
;
return
true
;
}
@Override
public
String
toString
()
{
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Groupable.java
0 → 100644
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api.entities
;
public
interface
Groupable
{
public
String
getGroup
();
public
void
setGroup
(
String
group
);
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Influence.java
View file @
c602b92e
...
...
@@ -2,7 +2,7 @@ package cz.muni.fi.lasaris.sbms.api.entities;
import
com.fasterxml.jackson.annotation.JsonInclude
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Influence
{
public
class
Influence
implements
Groupable
{
private
ObservedProperty
property
;
private
Scope
scope
;
...
...
@@ -34,6 +34,19 @@ public class Influence {
public
String
toString
()
{
return
"Influence [property="
+
property
+
", scope="
+
scope
+
"]"
;
}
private
String
group
;
@Override
public
String
getGroup
()
{
return
group
;
}
@Override
public
void
setGroup
(
String
group
)
{
this
.
group
=
group
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/request/DataPointsRequest.java
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api.request
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
cz.muni.fi.lasaris.sbms.api.entities.DataPoint
;
import
cz.muni.fi.lasaris.sbms.model.Fields
;
@XmlRootElement
public
class
DataPointsRequest
{
private
static
Map
<
String
,
String
>
sparqlVars
;
public
static
String
getSPARQLvar
(
String
field
)
{
if
(
sparqlVars
==
null
)
{
sparqlVars
=
new
HashMap
<
String
,
String
>();
for
(
String
f
:
Fields
.
FILTER_FIELDS
)
{
sparqlVars
.
put
(
f
,
f
.
replace
(
"."
,
""
));
}
}
return
sparqlVars
.
get
(
field
);
}
private
DataPoint
dataPoint
;
private
List
<
String
>
responseFields
;
private
String
grouping
;
private
String
[]
g
;
public
List
<
String
>
getResponseFields
()
{
return
responseFields
;
}
public
class
DataPointsRequest
extends
GroupableRequest
{
public
DataPointsRequest
()
{
responseFields
=
new
ArrayList
<
String
>();
}
private
DataPoint
dataPoint
;
public
DataPoint
getDataPoint
()
{
return
dataPoint
;
}
...
...
@@ -47,27 +20,10 @@ public class DataPointsRequest {
public
void
setDataPoint
(
DataPoint
dp
)
{
this
.
dataPoint
=
dp
;
}
public
String
getGrouping
()
{
return
grouping
;
}
public
String
getGrouping
(
int
i
)
{
if
(
g
==
null
||
i
<
0
||
i
>
2
)
{
return
Fields
.
DEFAULT_GROUPING
;
}
return
g
[
i
];
}
public
void
setGrouping
(
String
grouping
)
{
this
.
grouping
=
grouping
;
if
(
grouping
!=
null
)
{
String
[]
gs
=
grouping
.
split
(
"\\."
);
this
.
g
=(
gs
.
length
>
1
)
?
new
String
[]
{
gs
[
0
],
Character
.
toUpperCase
(
gs
[
1
].
charAt
(
0
))
+
gs
[
1
].
substring
(
1
)}
:
new
String
[]
{
gs
[
0
],
gs
[
0
]};
}
else
{
this
.
g
=
new
String
[]
{
Fields
.
DEFAULT_GROUPING
,
Fields
.
DEFAULT_GROUPING
};
}
@Override
public
String
getIdentityField
()
{
return
"bmsId"
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/request/GroupableRequest.java
0 → 100644
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api.request
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
cz.muni.fi.lasaris.sbms.model.Fields
;
public
abstract
class
GroupableRequest
{
protected
List
<
String
>
responseFields
;
private
String
grouping
;
private
String
[]
g
;
public
GroupableRequest
()
{
responseFields
=
new
ArrayList
<
String
>();
}
public
List
<
String
>
getResponseFields
()
{
return
responseFields
;
}
public
String
getGrouping
()
{
return
grouping
;
}
public
String
getGrouping
(
int
i
)
{
if
(
g
==
null
||
i
<
0
||
i
>
2
)
{
return
Fields
.
DEFAULT_GROUPING
;
}
return
g
[
i
];
}
public
void
setGrouping
(
String
grouping
)
{
this
.
grouping
=
grouping
;
if
(
grouping
!=
null
)
{
String
[]
gs
=
grouping
.
split
(
"\\."
);
this
.
g
=(
gs
.
length
>
1
)
?
new
String
[]
{
gs
[
0
],
Character
.
toUpperCase
(
gs
[
1
].
charAt
(
0
))
+
gs
[
1
].
substring
(
1
)}
:
new
String
[]
{
gs
[
0
],
gs
[
0
]};
}
else
{
this
.
g
=
new
String
[]
{
Fields
.
DEFAULT_GROUPING
,
Fields
.
DEFAULT_GROUPING
};
}
}
public
void
parseResponseFields
(
String
fields
)
{
if
(
fields
!=
null
)
{
for
(
String
f
:
fields
.
split
(
","
))
{
if
(
StringUtils
.
isNotBlank
(
f
))
{
responseFields
.
add
(
f
);
}
}
}
}
public
abstract
String
getIdentityField
();
}
\ No newline at end of file
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/response/
DataPoints
Response.java
→
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/response/
Grouped
Response.java
View file @
c602b92e
package
cz.muni.fi.lasaris.sbms.api.response
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -10,16 +11,22 @@ import javax.xml.bind.annotation.XmlRootElement;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
cz.muni.fi.lasaris.sbms.api.entities.
DataPoint
;
import
cz.muni.fi.lasaris.sbms.api.entities.
Groupable
;
@XmlRootElement
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)