|
12 | 12 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
13 | 13 | import java.util.Collection; |
14 | 14 | import java.util.Iterator; |
| 15 | +import java.util.stream.Collectors; |
| 16 | + |
| 17 | + |
15 | 18 |
|
16 | 19 | // JavaCommons imports |
17 | 20 | import picoded.core.conv.ConvertJSON; |
|
25 | 28 |
|
26 | 29 | // Redis imports |
27 | 30 | import org.redisson.Redisson; |
| 31 | +import org.redisson.client.codec.StringCodec; |
28 | 32 | import org.redisson.api.RedissonClient; |
29 | 33 | import org.redisson.api.RMap; |
30 | 34 | import org.redisson.api.RKeys; |
31 | 35 | import org.redisson.api.RSet; |
32 | 36 | import org.redisson.api.RSetMultimap; |
33 | 37 |
|
| 38 | +// Jackson library used |
| 39 | +import com.fasterxml.jackson.core.JsonParser; |
| 40 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 41 | +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; |
| 42 | +import com.fasterxml.jackson.core.util.DefaultIndenter; |
| 43 | +import com.fasterxml.jackson.databind.MapperFeature; |
34 | 44 |
|
35 | | -import org.redisson.client.codec.StringCodec; |
| 45 | +import org.hjson.*; |
36 | 46 |
|
37 | | -// import org.redisson.api.RSet; |
38 | 47 |
|
39 | 48 | /** |
40 | 49 | * Redis implementation of DataObjectMap data structure. |
@@ -196,24 +205,43 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full |
196 | 205 | * @return null if not exists, else a map with the data |
197 | 206 | **/ |
198 | 207 | public Map<String, Object> DataObjectRemoteDataMap_get(String _oid) { |
199 | | - |
| 208 | + |
200 | 209 | Collection<Object> res = redisMap.values(_oid); |
201 | 210 |
|
202 | 211 | Object resObj = res.iterator().next(); |
203 | 212 | if (resObj == null) { |
204 | 213 | return null; |
205 | 214 | } |
206 | 215 |
|
207 | | - //NEED TO FIND HOW TO CONVERT resObj TO MAP |
| 216 | + //Convert resObj to String |
| 217 | + String resString = resObj.toString(); |
| 218 | + //Get rid of {} |
| 219 | + resString = resString.substring(1, resString.length() - 1); |
| 220 | + |
| 221 | + //Convert resString to Map |
| 222 | + //if duplicate keys show up, the first one encountered takes precedence |
| 223 | + //for latest value for a duplicate key then use (a, b)-> b as the merge lambda.) |
| 224 | + Map<String, Object> resMap = Arrays.stream(resString.split(",")) |
| 225 | + .map(str -> str.split("=")) |
| 226 | + .collect(Collectors.toMap(a -> a[0], a->a[1], (a, b) -> a)); |
| 227 | + |
| 228 | + |
| 229 | + //Convert resObj to String so I can use replace() to make it a valid hjson |
| 230 | + //https://github.com/hjson/hjson-java |
| 231 | + // String tmpString=resObj.toString(); |
| 232 | + // tmpString=tmpString.replace('=',':'); |
| 233 | + // System.out.println(resObj); |
| 234 | + // Map<String, String> mapData = GenericConvert.toStringMap(resObj); |
| 235 | + // System.out.println(mapData); |
208 | 236 |
|
209 | 237 | Map<String, Object> ret = new HashMap<>(); |
210 | 238 |
|
211 | 239 | // Lets iterate through the object |
212 | | - Set<String> fullKeys = resObj.keySet(); |
| 240 | + Set<String> fullKeys = resMap.keySet(); |
213 | 241 | for (String key : fullKeys) { |
214 | 242 |
|
215 | 243 | // Get the value |
216 | | - Object val = resObj.get(key); |
| 244 | + Object val = resMap.get(key); |
217 | 245 |
|
218 | 246 | // Populate the ret map |
219 | 247 | ret.put(key, val); |
|
0 commit comments