Commit cb262d1e authored by akucera's avatar akucera
Browse files

commit before changing QueryParser getBody for DataPoints (removing

influence)
parent c602b92e
......@@ -104,9 +104,9 @@ public class DataPointsEndpoint {
}
if(ip != null || is != null) {
dp.setOneInfluence();
dp.getFirstInfluence().setProperty(ip);
dp.getFirstInfluence().setScope(is);
dp.setInfluenced();
dp.getInfluenced().setProperty(ip);
dp.getInfluenced().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());
}
}
......
......@@ -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.setOneInfluence();
dp.setInfluenced();
if(StringUtils.isNotBlank(scopeBimIdP)) {
dp.getFirstInfluence().setScope(new Scope());
dp.getFirstInfluence().getScope().setBimId(scopeBimIdP);
dp.getInfluenced().setScope(new Scope());
dp.getInfluenced().getScope().setBimId(scopeBimIdP);
}
if(StringUtils.isNotBlank(propDomP)) {
dp.getFirstInfluence().setProperty(new ObservedProperty());
dp.getFirstInfluence().getProperty().setDomain(propDomP);
dp.getInfluenced().setProperty(new ObservedProperty());
dp.getInfluenced().getProperty().setDomain(propDomP);
}
if(StringUtils.isNotBlank(propQualityP)){
if(dp.getFirstInfluence().getProperty() == null) {
dp.getFirstInfluence().setProperty(new ObservedProperty());
if(dp.getInfluenced().getProperty() == null) {
dp.getInfluenced().setProperty(new ObservedProperty());
}
dp.getFirstInfluence().getProperty().setQuality(propQualityP);
dp.getInfluenced().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);
}
......
// 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;
}
......
......@@ -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.setOneInfluence();
dp.getFirstInfluence().setProperty(ip);
dp.getFirstInfluence().setScope(is);
dp.setInfluenced();
dp.getInfluenced().setProperty(ip);
dp.getInfluenced().setScope(is);
}
dpr.setGrouping(groupingP);
setResponseFields(fieldsP, dpr);
dpr.parseResponseFields(fieldsP);
try {
return QueryParser.getDataPointResponse(dpr);
return QueryParser.getTrendsResponse(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????
}
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 + "]";
}
}
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);
}
}
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 + "]";
}
}
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;
}
}
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";
}
}
......@@ -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.getInfluenceList() != null) {
for(Influence inf : d.getInfluenceList()) {
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);
......
......@@ -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.getFirstInfluence())) {
d2.getInfluence().add(d.getFirstInfluence());
if(!d2.getInfluenceList().contains(d.getInfluenced())) {
d2.getInfluenceList().add(d.getInfluenced());
}
} else {
dps.put(d.getBmsId(), d);
......@@ -78,14 +78,34 @@ public class QueryParser {
return response;
}
public static GroupedResponse getInfluencedResponse(DataPointsRequest request) {
public static GroupedResponse getInfluencedResponse(AddressRequest 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);