@Service
public class DataFetchingAndMappingService
extends java.lang.Object
BorderRouterRepository
,
SensorRepository
,
SensorDataRepository
Modifier and Type | Field | Description |
---|---|---|
private BorderRouterRepository |
borderRouterRepository |
|
private org.springframework.context.ApplicationContext |
context |
|
private static org.apache.log4j.Logger |
logger |
|
private PropertyService |
propertyService |
|
private SensorDataRepository |
sensorDataRepository |
|
private SensorRepository |
sensorRepository |
Constructor | Description |
---|---|
DataFetchingAndMappingService() |
Modifier and Type | Method | Description |
---|---|---|
private boolean |
allSameElements(java.util.List<java.lang.String> lst1,
java.util.List<java.lang.String> lst2) |
Check if the input string lists' elements are the same to each other without
considering the order.
|
void |
clearDataBase() |
Delete all entries in database, basically we just need to clear border_router table
|
int |
clearSensorData() |
Delete all sensor data entries in database.
|
java.util.List<java.lang.String[]> |
getAllBorderRouterIpAndName() |
Get IP and name of all border router, if there is no border router in database,
return an empty list.
|
DataPackage |
getAllDataFromDB(java.util.Date timeStamp) |
Fetching all data generated after the given time stamp from database.
|
java.util.List<java.lang.String> |
getAllSensorIp() |
Get all sensor IP in database, if there is no sensor in database, return an
empty list.
|
BorderRouterEntity |
getBorderRouterEntity(java.lang.String borderRouterIP) |
Get border router entity for given border router IP.
|
long |
getBorderRouterNumber() |
Get the total number of border router in database.
|
BorderRouterWrapper |
getDataForBorderRouterFromDB(java.lang.String borderRouterIp,
java.util.Date timeStamp) |
Fetching data from database for given border router.
|
SensorWrapper |
getDataForSensorFromDB(java.lang.String sensorIp,
java.util.Date timeStamp) |
Fetching data generated after the given time stamp for the given sensor from
database.
|
java.util.List<java.lang.String> |
getSensorIpByBorderRouterIp(java.lang.String borderRouterIp) |
Get all sensor IP that connected to the given border router IP.
|
java.util.List<java.lang.String> |
setDataTypes(java.lang.String[] dataTypeArray) |
Update
dataTypeList according to the input array. |
boolean |
updateSensorName(java.lang.String sensorIp,
java.lang.String sensorName) |
Update the name of a sensor.
|
@Autowired private org.springframework.context.ApplicationContext context
@Autowired private SensorDataRepository sensorDataRepository
@Autowired private SensorRepository sensorRepository
@Autowired private BorderRouterRepository borderRouterRepository
@Autowired private PropertyService propertyService
private static final org.apache.log4j.Logger logger
@Transactional public java.util.List<java.lang.String> setDataTypes(java.lang.String[] dataTypeArray)
dataTypeList
according to the input array. Also update
the "dataTypeListString" property in database.
ALl data type string must match this pattern: [0-9a-zA-Z]+
;
Every time the dataTypeList
gets updated, the sensor_data
table in database will be cleared. Because the number of data fields have been
changed, and it will be inconsistent.
This method need to be synchronized to avoid race condition when this method
is called in multi-threads.
Return value is the current dataTypeList
, return null
if the input is invalid.
After this initialize operation, the currentDataTypeList
is sorted
in lexicographic order.dataTypeArray
- An array of data types stringjava.lang.RuntimeException
- if the input dataTypeArray contains invalid characters.private boolean allSameElements(java.util.List<java.lang.String> lst1, java.util.List<java.lang.String> lst2)
@Transactional public long getBorderRouterNumber()
@Transactional public boolean updateSensorName(java.lang.String sensorIp, java.lang.String sensorName)
sensorIp
- IP of the sensor you want to update.sensorName
- The name you want to update for the sensor.true
for success, false
otherwise.@Transactional public java.util.List<java.lang.String[]> getAllBorderRouterIpAndName()
@Transactional public BorderRouterWrapper getDataForBorderRouterFromDB(java.lang.String borderRouterIp, java.util.Date timeStamp)
null
, return all data for the router.
Return null
if the input border router IP doesn't exist in the
database or the size of the results is 0.borderRouterIp
- The IPv6 address of the border router you want to
fetch date from.timeStamp
- The earliest time stamp.BorderRouterWrapper
that contains a list
of SensorDataEntity
.@Transactional public SensorWrapper getDataForSensorFromDB(java.lang.String sensorIp, java.util.Date timeStamp)
null
.
Return null
if the result size == 0.
Return null
if the input sensorIp doesn't exist in database.sensorIp
- he IPv6 address of the sensor you want to fetch from.timeStamp
- The earliest time stamp.SensorWrapper
which contains a list of
SensorDataEntity
.@Transactional public DataPackage getAllDataFromDB(java.util.Date timeStamp)
null
, return all data.
Return null
if the size of result is 0.timeStamp
- The earliest time stamp.DataPackage
which contains all data.@Transactional public void clearDataBase()
@Transactional public int clearSensorData()
@Transactional public java.util.List<java.lang.String> getAllSensorIp()
@Transactional public java.util.List<java.lang.String> getSensorIpByBorderRouterIp(java.lang.String borderRouterIp)
@Transactional public BorderRouterEntity getBorderRouterEntity(java.lang.String borderRouterIP)
borderRouterIP
- BorderRouterEntity