From 1bd99967e604b6c96bd465dd39cc5634f30a18a6 Mon Sep 17 00:00:00 2001 From: Dmitry Solonina Date: Mon, 20 May 2019 15:35:00 +0300 Subject: [PATCH 1/2] Add filtering method --- .../datastore/db/InMemoryDataStore.java | 35 +++++++++++++ .../io/antmedia/datastore/db/MapDBStore.java | 50 ++++++++++++++++++- .../io/antmedia/datastore/db/MongoStore.java | 10 ++++ .../antmedia/rest/BroadcastRestService.java | 8 +++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java b/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java index 5ae4dc77b..ef4fc3cd8 100644 --- a/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java +++ b/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java @@ -274,6 +274,41 @@ public List filterBroadcastList(int offset, int size, String type) { return list; } + @Override + public List filterBroadcastListByType(int offset, int size, String type, String value) { + int t = 0; + int itemCount = 0; + if (size > MAX_ITEM_IN_ONE_LIST) { + size = MAX_ITEM_IN_ONE_LIST; + } + if (offset < 0) { + offset = 0; + } + + Collection values =broadcastMap.values(); + + List list = new ArrayList(); + + for (Broadcast broadcast : values) + { + if(broadcast.getType().equals("ipCamera")) + { + if (t < offset) { + t++; + continue; + } + list.add(broadcast); + + itemCount++; + + if (itemCount >= size) { + break; + } + } + } + return list; + } + @Override public String addVod(VoD vod) { String id = null; diff --git a/src/main/java/io/antmedia/datastore/db/MapDBStore.java b/src/main/java/io/antmedia/datastore/db/MapDBStore.java index 61b7bbce2..a75ca4599 100644 --- a/src/main/java/io/antmedia/datastore/db/MapDBStore.java +++ b/src/main/java/io/antmedia/datastore/db/MapDBStore.java @@ -455,6 +455,54 @@ public List filterBroadcastList(int offset, int size, String type) { } + @Override + public List filterBroadcastListByType(int offset, int size, String type, String value) { + + List list = new ArrayList(); + synchronized (this) { + int t = 0; + int itemCount = 0; + if (size > MAX_ITEM_IN_ONE_LIST) { + size = MAX_ITEM_IN_ONE_LIST; + } + if (offset < 0) { + offset = 0; + } + + Object[] objectArray = map.getValues().toArray(); + + Broadcast[] broadcastArray = new Broadcast[objectArray.length]; + + for (int i = 0; i < objectArray.length; i++) { + broadcastArray[i] = gson.fromJson((String) objectArray[i], Broadcast.class); + } + + List filterList = new ArrayList<>(); + for (int i = 0; i < broadcastArray.length; i++) { + + if (broadcastArray[i].getType().equals(type)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } + Iterator iterator = filterList.iterator(); + + while(itemCount < size && iterator.hasNext()) { + if (t < offset) { + t++; + iterator.next(); + } + else { + + list.add(iterator.next()); + itemCount++; + } + } + + } + return list; + + } + @Override public String addVod(VoD vod) { @@ -1038,4 +1086,4 @@ public boolean setMp4Muxing(String streamId, int enabled) { } return result; } -} \ No newline at end of file +} diff --git a/src/main/java/io/antmedia/datastore/db/MongoStore.java b/src/main/java/io/antmedia/datastore/db/MongoStore.java index e7f519208..31046b3c0 100644 --- a/src/main/java/io/antmedia/datastore/db/MongoStore.java +++ b/src/main/java/io/antmedia/datastore/db/MongoStore.java @@ -340,6 +340,16 @@ public List filterBroadcastList(int offset, int size, String type) { return null; } + @Override + public List filterBroadcastListByType(int offset, int size, String type, String value) { + try { + return datastore.find(Broadcast.class).field("type").equal(type).asList(new FindOptions().skip(offset).limit(size)); + } catch (Exception e) { + logger.error(ExceptionUtils.getStackTrace(e)); + } + return null; + } + @Override public String addVod(VoD vod) { diff --git a/src/main/java/io/antmedia/rest/BroadcastRestService.java b/src/main/java/io/antmedia/rest/BroadcastRestService.java index f7278051c..460fd0308 100644 --- a/src/main/java/io/antmedia/rest/BroadcastRestService.java +++ b/src/main/java/io/antmedia/rest/BroadcastRestService.java @@ -1176,6 +1176,14 @@ public List filterBroadcastList(@PathParam("offset") int offset, @Pat return getDataStore().filterBroadcastList(offset, size, type); } + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/broadcast/filterListByType/{offset}/{size}/{type}/{value}") + @Produces(MediaType.APPLICATION_JSON) + public List filterBroadcastListByType(@PathParam("offset") int offset, @PathParam("size") int size, + @PathParam("type") String type, @PathParam("value") String value) { + return getDataStore().filterBroadcastListByType(offset, size, type); + } @POST @Consumes({ MediaType.APPLICATION_JSON }) From e751deb813c7d3795f9c926d702150a46e145829 Mon Sep 17 00:00:00 2001 From: Dmitry Solonina Date: Wed, 14 Aug 2019 13:27:57 +0300 Subject: [PATCH 2/2] Add filterByType method --- .../datastore/db/InMemoryDataStore.java | 18 +++++++++++- .../io/antmedia/datastore/db/MapDBStore.java | 29 ++++++++++++++++--- .../io/antmedia/datastore/db/MongoStore.java | 8 ++++- .../antmedia/rest/BroadcastRestService.java | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java b/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java index ef4fc3cd8..0a92161d4 100644 --- a/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java +++ b/src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java @@ -291,7 +291,23 @@ public List filterBroadcastListByType(int offset, int size, String ty for (Broadcast broadcast : values) { - if(broadcast.getType().equals("ipCamera")) + Boolean isEqual = false; + + if (type.equals("channel")) { + isEqual = broadcast.getCategory().equals(value); + } else if (type.equals("status")) { + isEqual = broadcast.getStatus().equals(value); + } else if (type.equals("stream")) { + isEqual = broadcast.getStreamId().equals(value); + } else if (type.equals("type")) { + isEqual = broadcast.getType().equals(value); + } else if (type.equals("name")) { + isEqual = broadcast.getName().equals(value); + } else if (type.equals("description")) { + isEqual = broadcast.getDescription().equals(value); + } + + if (isEqual) { if (t < offset) { t++; diff --git a/src/main/java/io/antmedia/datastore/db/MapDBStore.java b/src/main/java/io/antmedia/datastore/db/MapDBStore.java index a75ca4599..f1690e169 100644 --- a/src/main/java/io/antmedia/datastore/db/MapDBStore.java +++ b/src/main/java/io/antmedia/datastore/db/MapDBStore.java @@ -479,14 +479,35 @@ public List filterBroadcastListByType(int offset, int size, String ty List filterList = new ArrayList<>(); for (int i = 0; i < broadcastArray.length; i++) { - - if (broadcastArray[i].getType().equals(type)) { - filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + if (type.equals("channel")) { + if (broadcastArray[i].getCategory().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } else if (type.equals("status")) { + if (broadcastArray[i].getStatus().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } else if (type.equals("stream")) { + if (broadcastArray[i].getStreamId().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } else if (type.equals("type")) { + if (broadcastArray[i].getType().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } else if (type.equals("name")) { + if (broadcastArray[i].getName().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } + } else if (type.equals("description")) { + if (broadcastArray[i].getDescription().equals(value)) { + filterList.add(gson.fromJson((String) objectArray[i], Broadcast.class)); + } } } Iterator iterator = filterList.iterator(); - while(itemCount < size && iterator.hasNext()) { + while (itemCount < size && iterator.hasNext()) { if (t < offset) { t++; iterator.next(); diff --git a/src/main/java/io/antmedia/datastore/db/MongoStore.java b/src/main/java/io/antmedia/datastore/db/MongoStore.java index 31046b3c0..a1d2a107c 100644 --- a/src/main/java/io/antmedia/datastore/db/MongoStore.java +++ b/src/main/java/io/antmedia/datastore/db/MongoStore.java @@ -343,7 +343,13 @@ public List filterBroadcastList(int offset, int size, String type) { @Override public List filterBroadcastListByType(int offset, int size, String type, String value) { try { - return datastore.find(Broadcast.class).field("type").equal(type).asList(new FindOptions().skip(offset).limit(size)); + if (type.equals("channel")) { + type = "category"; + } else if (type.equals("stream")) { + type = "streamId"; + } + + return datastore.find(Broadcast.class).field(type).equal(value).asList(new FindOptions().skip(offset).limit(size)); } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); } diff --git a/src/main/java/io/antmedia/rest/BroadcastRestService.java b/src/main/java/io/antmedia/rest/BroadcastRestService.java index 460fd0308..1cd3d313b 100644 --- a/src/main/java/io/antmedia/rest/BroadcastRestService.java +++ b/src/main/java/io/antmedia/rest/BroadcastRestService.java @@ -1182,7 +1182,7 @@ public List filterBroadcastList(@PathParam("offset") int offset, @Pat @Produces(MediaType.APPLICATION_JSON) public List filterBroadcastListByType(@PathParam("offset") int offset, @PathParam("size") int size, @PathParam("type") String type, @PathParam("value") String value) { - return getDataStore().filterBroadcastListByType(offset, size, type); + return getDataStore().filterBroadcastListByType(offset, size, type, value); } @POST