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
cb262d1e
Commit
cb262d1e
authored
Jun 22, 2016
by
akucera
Browse files
commit before changing QueryParser getBody for DataPoints (removing
influence)
parent
c602b92e
Changes
11
Hide whitespace changes
Inline
Side-by-side
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/DataPointsEndpoint.java
View file @
cb262d1e
...
...
@@ -104,9 +104,9 @@ public class DataPointsEndpoint {
}
if
(
ip
!=
null
||
is
!=
null
)
{
dp
.
set
One
Influence
();
dp
.
get
First
Influence
().
setProperty
(
ip
);
dp
.
get
First
Influence
().
setScope
(
is
);
dp
.
setInfluence
d
();
dp
.
getInfluence
d
().
setProperty
(
ip
);
dp
.
getInfluence
d
().
setScope
(
is
);
}
dpr
.
setGrouping
(
groupingP
);
...
...
@@ -115,11 +115,8 @@ public class DataPointsEndpoint {
try
{
return
QueryParser
.
getDataPointResponse
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
.
toString
());
e
.
printStackTrace
();
GroupedResponse
r
=
new
GroupedResponse
();
r
.
setError
(
e
.
toString
());
return
r
;
logger
.
info
(
e
);
return
GroupedResponse
.
getErrorResponse
(
e
.
toString
());
}
}
...
...
@@ -142,9 +139,7 @@ public class DataPointsEndpoint {
return
QueryParser
.
getDataPointResponse
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
);
GroupedResponse
r
=
new
GroupedResponse
();
r
.
setError
(
e
.
toString
());
return
r
;
return
GroupedResponse
.
getErrorResponse
(
e
.
toString
());
}
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/InfluencesEndpoint.java
View file @
cb262d1e
...
...
@@ -9,9 +9,11 @@ import javax.ws.rs.core.MediaType;
import
org.apache.commons.lang3.StringUtils
;
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.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.DataPointsRequest
;
import
cz.muni.fi.lasaris.sbms.api.response.GroupedResponse
;
import
cz.muni.fi.lasaris.sbms.model.Fields
;
...
...
@@ -49,20 +51,20 @@ public class InfluencesEndpoint {
DataPoint
dp
=
new
DataPoint
();
r
.
setDataPoint
(
dp
);
dp
.
set
One
Influence
();
dp
.
setInfluence
d
();
if
(
StringUtils
.
isNotBlank
(
scopeBimIdP
))
{
dp
.
get
First
Influence
().
setScope
(
new
Scope
());
dp
.
get
First
Influence
().
getScope
().
setBimId
(
scopeBimIdP
);
dp
.
getInfluence
d
().
setScope
(
new
Scope
());
dp
.
getInfluence
d
().
getScope
().
setBimId
(
scopeBimIdP
);
}
if
(
StringUtils
.
isNotBlank
(
propDomP
))
{
dp
.
get
First
Influence
().
setProperty
(
new
ObservedProperty
());
dp
.
get
First
Influence
().
getProperty
().
setDomain
(
propDomP
);
dp
.
getInfluence
d
().
setProperty
(
new
ObservedProperty
());
dp
.
getInfluence
d
().
getProperty
().
setDomain
(
propDomP
);
}
if
(
StringUtils
.
isNotBlank
(
propQualityP
)){
if
(
dp
.
get
First
Influence
().
getProperty
()
==
null
)
{
dp
.
get
First
Influence
().
setProperty
(
new
ObservedProperty
());
if
(
dp
.
getInfluence
d
().
getProperty
()
==
null
)
{
dp
.
getInfluence
d
().
setProperty
(
new
ObservedProperty
());
}
dp
.
get
First
Influence
().
getProperty
().
setQuality
(
propQualityP
);
dp
.
getInfluence
d
().
getProperty
().
setQuality
(
propQualityP
);
}
r
.
parseResponseFields
(
fieldsP
);
...
...
@@ -80,14 +82,7 @@ public class InfluencesEndpoint {
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"
);
AddressRequest
r
=
new
AddressRequest
(
new
Address
(
bmsIdP
));
r
.
getResponseFields
().
addAll
(
Fields
.
INFLUENCE_FIELDS
);
return
QueryParser
.
getInfluencedResponse
(
r
);
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/LogAllExceptions.java
View file @
cb262d1e
// http://stackoverflow.com/questions/19621653/how-should-i-log-uncaught-exceptions-in-my-restful-jax-rs-web-service
// (last answer)
package
cz.muni.fi.lasaris.sbms.api
;
import
javax.ws.rs.WebApplicationException
;
...
...
@@ -23,9 +25,11 @@ public class LogAllExceptions implements ExtendedExceptionMapper<Throwable> {
@Override
public
boolean
isMappable
(
Throwable
thro
)
{
/* Primarily, we don't want to log client errors (i.e. 400's) as an error. */
/* Primarily, we don't want to log client errors (i.e. 400's) as an error. */
Level
level
=
isServerError
(
thro
)
?
Level
.
ERROR
:
Level
.
INFO
;
/* TODO add information about the request (using @Context). */
logger
.
log
(
level
,
"ThrowableLogger_ExceptionMapper logging error."
,
thro
);
return
false
;
}
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/TrendsEndpoint.java
View file @
cb262d1e
...
...
@@ -9,12 +9,9 @@ import javax.ws.rs.QueryParam;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.MediaType
;
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
;
...
...
@@ -95,35 +92,21 @@ final static Logger logger = Logger.getLogger(DataPointsEndpoint.class);
}
if
(
ip
!=
null
||
is
!=
null
)
{
dp
.
set
One
Influence
();
dp
.
get
First
Influence
().
setProperty
(
ip
);
dp
.
get
First
Influence
().
setScope
(
is
);
dp
.
setInfluence
d
();
dp
.
getInfluence
d
().
setProperty
(
ip
);
dp
.
getInfluence
d
().
setScope
(
is
);
}
dpr
.
setGrouping
(
groupingP
);
se
t
ResponseFields
(
fieldsP
,
dpr
);
dpr
.
par
seResponseFields
(
fieldsP
);
try
{
return
QueryParser
.
get
DataPoint
Response
(
dpr
);
return
QueryParser
.
get
Trends
Response
(
dpr
);
}
catch
(
Exception
e
){
logger
.
info
(
e
.
toString
());
e
.
printStackTrace
();
GroupedResponse
r
=
new
GroupedResponse
();
r
.
setError
(
e
.
toString
());
return
r
;
}
}
private
void
setResponseFields
(
String
fields
,
DataPointsRequest
dpr
)
{
if
(
fields
!=
null
)
{
for
(
String
f
:
fields
.
split
(
","
))
{
if
(
StringUtils
.
isNotEmpty
(
f
))
{
dpr
.
getResponseFields
().
add
(
f
);
}
dpr
.
getResponseFields
().
add
(
"trendId"
);
}
logger
.
info
(
e
);
return
GroupedResponse
.
getErrorResponse
(
e
.
toString
());
}
}
// TODO Inserting and Removing of trends must 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/Address.java
0 → 100644
View file @
cb262d1e
package
cz.muni.fi.lasaris.sbms.api.entities
;
import
java.util.SortedSet
;
import
java.util.TreeSet
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
public
class
Address
{
protected
String
bmsId
;
protected
String
type
;
protected
Source
publisher
;
public
String
getBmsId
()
{
return
bmsId
;
}
public
void
setBmsId
(
String
bmsId
)
{
this
.
bmsId
=
bmsId
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
dataPointType
)
{
this
.
type
=
dataPointType
;
}
@JsonIgnore
public
String
getResourceId
()
{
return
Address
.
getResourceId
(
this
.
bmsId
);
}
public
static
String
getResourceId
(
String
bmsId
)
{
return
StringEscapeUtils
.
escapeXml10
(
bmsId
);
}
private
SortedSet
<
Influence
>
influence
;
public
SortedSet
<
Influence
>
getInfluenceList
()
{
return
influence
;
}
public
Influence
getInfluenced
()
{
return
influence
.
first
();
}
public
void
setInfluenceList
(
SortedSet
<
Influence
>
influence
)
{
this
.
influence
=
influence
;
}
public
void
setInfluenced
()
{
this
.
influence
=
new
TreeSet
<
Influence
>();
this
.
influence
.
add
(
new
Influence
());
}
public
Source
getPublisher
()
{
return
publisher
;
}
public
void
setPublisher
(
Source
publisher
)
{
this
.
publisher
=
publisher
;
}
public
Address
()
{
}
public
Address
(
String
bmsId
)
{
this
.
bmsId
=
bmsId
;
}
public
Address
(
String
bmsId
,
String
dataPointType
)
{
this
.
bmsId
=
bmsId
;
this
.
type
=
dataPointType
;
}
@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
;
Address
other
=
(
Address
)
obj
;
if
(
bmsId
==
null
)
{
if
(
other
.
bmsId
!=
null
)
return
false
;
}
else
if
(!
bmsId
.
equals
(
other
.
bmsId
))
return
false
;
return
true
;
}
@Override
public
String
toString
()
{
return
"Address [bmsId="
+
bmsId
+
", type="
+
type
+
"]"
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Algorithm.java
0 → 100644
View file @
cb262d1e
package
cz.muni.fi.lasaris.sbms.api.entities
;
import
java.util.SortedSet
;
import
java.util.TreeSet
;
public
class
Algorithm
extends
Address
{
public
SortedSet
<
DataPoint
>
usedDataPointList
;
public
SortedSet
<
DataPoint
>
getUsedDataPointList
()
{
return
usedDataPointList
;
}
public
void
setUsedDataPointList
(
SortedSet
<
DataPoint
>
usedDataPointList
)
{
this
.
usedDataPointList
=
usedDataPointList
;
}
public
DataPoint
getUsedDataPoint
()
{
return
usedDataPointList
.
first
();
}
public
void
setUsedDataPoint
(
DataPoint
dp
)
{
usedDataPointList
=
new
TreeSet
<
DataPoint
>();
usedDataPointList
.
add
(
dp
);
}
public
Algorithm
()
{
}
public
Algorithm
(
String
bmsId
)
{
super
(
bmsId
);
}
public
Algorithm
(
String
bmsId
,
String
dataPointType
)
{
super
(
bmsId
,
dataPointType
);
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/DataPoint.java
View file @
cb262d1e
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
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
@XmlRootElement
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
DataPoint
implements
Groupable
{
private
String
bmsId
;
private
String
type
;
public
class
DataPoint
extends
Address
implements
Groupable
{
private
Source
source
;
private
Scope
scope
;
private
Sensing
sensing
;
private
ObservedProperty
property
;
private
SortedSet
<
Influence
>
influence
;
@JsonIgnore
private
String
group
;
public
DataPoint
()
{
}
public
static
String
getResourceId
(
String
bmsId
)
{
return
StringEscapeUtils
.
escapeXml10
(
bmsId
);
}
@JsonIgnore
public
String
getResourceId
()
{
return
DataPoint
.
getResourceId
(
this
.
bmsId
);
}
public
DataPoint
(
String
bmsId
)
{
this
.
bmsId
=
bmsId
;
//this.bmsId = bmsId;
super
(
bmsId
);
}
public
DataPoint
(
String
bmsId
,
String
dataPointType
)
{
this
.
bmsId
=
bmsId
;
this
.
type
=
dataPointType
;
//this.bmsId = bmsId;
//this.type = dataPointType;
super
(
bmsId
,
dataPointType
);
}
public
Source
getSource
()
{
...
...
@@ -78,36 +63,7 @@ public class DataPoint implements Groupable {
public
void
setProperty
(
ObservedProperty
property
)
{
this
.
property
=
property
;
}
public
SortedSet
<
Influence
>
getInfluence
()
{
return
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
;
}
public
void
setBmsId
(
String
bmsId
)
{
this
.
bmsId
=
bmsId
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
dataPointType
)
{
this
.
type
=
dataPointType
;
}
public
String
getGroup
()
{
return
group
;
...
...
@@ -147,6 +103,6 @@ public class DataPoint implements Groupable {
@Override
public
String
toString
()
{
return
"DataPoint [bmsId="
+
bmsId
+
", dataPointType="
+
type
+
", source="
+
source
+
", scope="
+
scope
+
", sensing="
+
sensing
+
", property="
+
property
+
", influence="
+
influence
+
"]"
;
+
scope
+
", sensing="
+
sensing
+
", property="
+
property
+
"]"
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/entities/Trend.java
0 → 100644
View file @
cb262d1e
package
cz.muni.fi.lasaris.sbms.api.entities
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
@XmlRootElement
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Trend
extends
Address
implements
Groupable
{
private
DataPoint
dataPoint
;
@Override
public
String
getGroup
()
{
return
(
dataPoint
==
null
)
?
null
:
dataPoint
.
getGroup
();
}
@Override
public
void
setGroup
(
String
group
)
{
throw
new
UnsupportedOperationException
();
}
public
DataPoint
getDataPoint
()
{
return
dataPoint
;
}
public
void
setDataPoint
(
DataPoint
dataPoint
)
{
this
.
dataPoint
=
dataPoint
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/api/request/AddressRequest.java
0 → 100644
View file @
cb262d1e
package
cz.muni.fi.lasaris.sbms.api.request
;
import
cz.muni.fi.lasaris.sbms.api.entities.Address
;
public
class
AddressRequest
extends
GroupableRequest
{
private
Address
address
;
public
AddressRequest
()
{
}
public
AddressRequest
(
Address
address
)
{
this
.
address
=
address
;
}
public
Address
getAddress
()
{
return
address
;
}
public
void
setAddress
(
Address
address
)
{
this
.
address
=
address
;
}
@Override
public
String
getIdentityField
()
{
return
"bmsId"
;
}
}
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/model/ModelUpdater.java
View file @
cb262d1e
...
...
@@ -11,6 +11,7 @@ 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.Trend
;
import
cz.muni.fi.lasaris.sbms.api.request.DataPointInsert
;
public
class
ModelUpdater
{
...
...
@@ -141,8 +142,8 @@ public class ModelUpdater {
}
// ?dataPoint sbms:influences ?property.
if
(
d
.
getInfluence
()
!=
null
)
{
for
(
Influence
inf
:
d
.
getInfluence
())
{
if
(
d
.
getInfluence
List
()
!=
null
)
{
for
(
Influence
inf
:
d
.
getInfluence
List
())
{
if
(
inf
.
getProperty
()
!=
null
&&
inf
.
getProperty
().
getDomain
()
!=
null
&&
inf
.
getProperty
().
getQuality
()
!=
null
&&
inf
.
getScope
()
!=
null
&&
...
...
@@ -180,6 +181,21 @@ public class ModelUpdater {
}
public
static
boolean
insertTrend
(
Trend
t
)
{
// TODO Implement insertTrend
return
false
;
}
public
static
boolean
insertInfluence
(
DataPoint
dp
)
{
// TODO Implement insertInfluence
return
false
;
}
public
static
boolean
insertAlgorithm
()
{
// TODO Implement program insert
return
false
;
}
private
static
boolean
failInsert
(
Object
msg
)
{
TdbConnector
.
discardChanges
();
logger
.
info
(
msg
);
...
...
SemanticBMSServer/src/main/java/cz/muni/fi/lasaris/sbms/model/QueryParser.java
View file @
cb262d1e
...
...
@@ -28,6 +28,8 @@ 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.entities.Trend
;
import
cz.muni.fi.lasaris.sbms.api.request.AddressRequest
;
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.response.GroupedResponse
;
...
...
@@ -41,7 +43,6 @@ public class QueryParser {
public
static
GroupedResponse
getDataPointResponse
(
DataPointsRequest
request
)
{
ElementGroup
body
=
getQueryBody
(
request
);
//return getGroupedResponse(request, body);
GroupedResponse
response
=
new
GroupedResponse
();
for
(
QuerySolution
qs
:
getQueryResult
(
request
,
body
))
...
...
@@ -53,7 +54,6 @@ public class QueryParser {
public
static
GroupedResponse
getInfluencingResponse
(
DataPointsRequest
request
)
{
ElementGroup
body
=
getQueryBody
(
request
);
//return getGroupedResponse(request, body);
GroupedResponse
response
=
new
GroupedResponse
();
HashMap
<
String
,
DataPoint
>
dps
=
new
HashMap
<
String
,
DataPoint
>();
...
...
@@ -63,8 +63,8 @@ public class QueryParser {
DataPoint
d
=
createDataPoint
(
qs
,
request
.
getResponseFields
(),
request
.
getGrouping
());
if
(
dps
.
containsKey
(
d
.
getBmsId
()))
{
DataPoint
d2
=
dps
.
get
(
d
.
getBmsId
());
if
(!
d2
.
getInfluence
().
contains
(
d
.
get
First
Influence
()))
{
d2
.
getInfluence
().
add
(
d
.
get
First
Influence
());
if
(!
d2
.
getInfluence
List
().
contains
(
d
.
getInfluence
d
()))
{
d2
.
getInfluence
List
().
add
(
d
.
getInfluence
d
());
}
}
else
{
dps
.
put
(
d
.
getBmsId
(),
d
);
...
...
@@ -78,14 +78,34 @@ public class QueryParser {
return
response
;
}
public
static
GroupedResponse
getInfluencedResponse
(
DataPoint
sRequest
request
)
{
public
static
GroupedResponse
getInfluencedResponse
(
Addres
sRequest
request
)
{
ElementGroup
body
=
getQueryBody
(
request
);
//return getGroupedResponse(request, body);
GroupedResponse
response
=
new
GroupedResponse
();
for
(
QuerySolution
qs
:
getQueryResult
(
request
,
body
))
{
DataPoint
d
=
createDataPoint
(
qs
,
request
.
getResponseFields
(),
request
.
getGrouping
());
response
.
addResult
(
d
.
getFirstInfluence
());
response
.
addResult
(
d
.
getInfluenced
());
}
return
response
;
}
public
static
GroupedResponse
getTrendsResponse
(
DataPointsRequest
request
)
{
request
.
getResponseFields
().
add
(
"trendId"
);
ElementGroup
body
=
getQueryBody
(
request
);