aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Rafaj <peter.rafaj@kistler.com>2018-11-12 16:22:03 +0100
committerJozef Kralik <jojo.lwin@gmail.com>2018-11-23 12:21:39 +0000
commit08ef99e6839afccd63a464f2165ef4ce9fd572b7 (patch)
tree248f39ca3f6bbae553e5e1e80d99caa4fe185050
parent5ba3e9afb45e8f16cdc0f1efe50c9f050d4fa7e1 (diff)
IOT-3234 fix discovery request creatingiotivity-cloud
Change-Id: I1a2c2ce90555fa8c7049d0986ac8806c29013f48 Signed-off-by: Peter Rafaj <peter.rafaj@kistler.com>
-rw-r--r--cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java b/cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java
index 7a01402..4212a83 100644
--- a/cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java
+++ b/cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java
@@ -247,7 +247,7 @@ public class RDManager {
ArrayList<HashMap<String, Object>> records = DBManager.getInstance()
.selectRecord(Constants.RD_TABLE, condition);
if (!records.isEmpty()) {
- response.add(makeDiscoverResponseSegment(records));
+ response.addAll(makeDiscoverResponseSegment(records));
}
}
@@ -263,28 +263,32 @@ public class RDManager {
return records.stream().map(record -> (String)record.get("di")).collect(Collectors.toList());
}
- private HashMap<String, Object> makeDiscoverResponseSegment(
+ private Collection<HashMap<String, Object>> makeDiscoverResponseSegment(
ArrayList<HashMap<String, Object>> records) {
- HashMap<String, Object> responseSegment = new HashMap<>();
-
- // make Tags
- HashMap<String, Object> discoverTag = mPayloadManager
- .setPayloadData(records.get(0), mPayloadManager.discoverTagKey);
- responseSegment.putAll(discoverTag);
-
- ArrayList<Object> links = new ArrayList<>();
- // make links
- for (HashMap<String, Object> record : records) {
- HashMap<String, Object> link = mPayloadManager
+ final Map<String, HashMap<String, Object>> result = new HashMap<>();
+ for (final HashMap<String, Object> record : records) {
+ final String di = (String) record.get(Constants.DEVICE_ID);
+ ArrayList<Object> links;
+ if (!result.containsKey(record.get(Constants.DEVICE_ID))) {
+ final HashMap<String, Object> discovered = createDevice(record);
+ result.put(di, discovered);
+ links = (ArrayList<Object>) discovered.get(Constants.LINKS);
+ } else {
+ links = (ArrayList<Object>) result.get(di).get(Constants.LINKS);
+ }
+ HashMap<String, Object> discoveredLinks = mPayloadManager
.setPayloadData(record, mPayloadManager.discoverLinkKey);
- mPayloadManager.changePolicyTypeToDiscover(link);
- links.add(link);
+ mPayloadManager.changePolicyTypeToDiscover(discoveredLinks);
+ links.add(discoveredLinks);
}
- responseSegment.put(Constants.LINKS, links);
-
- return responseSegment;
+ return result.values();
+ }
+ private HashMap<String,Object> createDevice(final HashMap<String, Object> record){
+ HashMap<String, Object> discoverTag = mPayloadManager.setPayloadData(record, mPayloadManager.discoverTagKey);
+ discoverTag.put(Constants.LINKS, new ArrayList<>());
+ return discoverTag;
}
private void setmResourcePresence(