Change-Id: I6cbfb62855a80d03bf0aebf505505222a146ca38
Signed-off-by: eunok.shin <eunok.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13817
Reviewed-by: Yeonghun Nam <yeonghun.nam@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
(cherry picked from commit
9f5c6903aa2187ca8b7326416f764bed044b1c61)
Reviewed-on: https://gerrit.iotivity.org/gerrit/14543
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit
8f56d068bc3b7d15dd3d07503ee010e595734dc7)
Reviewed-on: https://gerrit.iotivity.org/gerrit/15285
* duplicated one.
*
* @param tableName
- * table name to be inserted
+ * table name to be inserted or replaced
* @param replace
* record to be inserted
*/
* API for selecting records from DB table.
*
* @param tableName
- * table name to be inserted
+ * table name to be selected
* @param condition
* condition record to be selected
* @return selected records
}
/**
+ * API for selecting records to primary key from DB table
+ *
+ * @param tableName
+ * table name to be selected
+ *
+ * @param condition
+ * condition record to be selected
+ * @return selected record
+ */
+
+ public HashMap<String, Object> selectOneRecord(String tableName,
+ HashMap<String, Object> condition) {
+
+ ArrayList<HashMap<String, Object>> records = _selectRecord(tableName,
+ condition);
+
+ if (records.size() > 1) {
+ throw new InternalServerErrorException(
+ "Database record select failed");
+ }
+
+ if (records.isEmpty()) {
+ return new HashMap<String, Object>();
+ } else {
+ return records.get(0);
+ }
+
+ }
+
+ /**
* API for deleting records from DB table.
*
* @param tableName
- * table name to be inserted
+ * table name to be deleted
* @param condition
* condition record to be deleted
*/
* API for updating a record into DB table.
*
* @param tableName
- * table name to be inserted
+ * table name to be updated
* @param replace
* record to be updated
*/
private void readResource(List<String> diList,
HashMap<String, Object> condition, ArrayList<Object> response) {
- for (String di : diList) {
+ ArrayList<String> onDiList = getPresenceOnDevices(diList);
+
+ for (String di : onDiList) {
condition.put(Constants.DEVICE_ID, di);
ArrayList<HashMap<String, Object>> records = DBManager.getInstance()
.selectRecord(Constants.RD_TABLE, condition);
}
}
+ private ArrayList<String> getPresenceOnDevices(List<String> diList) {
+ ArrayList<String> onDiList = new ArrayList<>();
+ HashMap<String, Object> condition = new HashMap<>();
+
+ for (String di : diList) {
+ condition.put(Constants.DEVICE_ID, di);
+ HashMap<String, Object> record = DBManager.getInstance()
+ .selectOneRecord(Constants.PRESENCE_TABLE, condition);
+
+ if (!record.isEmpty() && record.get(Constants.PRESENCE_STATE)
+ .equals(Constants.PRESENCE_ON)) {
+ onDiList.add(di);
+ }
+
+ }
+ return onDiList;
+ }
+
private HashMap<String, Object> makeDiscoverResponseSegment(
ArrayList<HashMap<String, Object>> records) {
return mResourcePresence;
}
-}
+}
\ No newline at end of file
HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+ if (queryMap == null) {
+ return MessageBuilder.createResponse(request,
+ ResponseStatus.NOT_FOUND);
+ }
+
List<String> diList = queryMap.get(Constants.DEVICE_ID);
List<String> rtList = queryMap.get(Constants.RESOURCE_TYPE);
List<String> ifList = queryMap.get(Constants.INTERFACE);