Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BCAPP-784] Add filtering method to get by selected type #1443

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,57 @@ public List<Broadcast> filterBroadcastList(int offset, int size, String type) {
return list;
}

@Override
public List<Broadcast> 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<Broadcast> values =broadcastMap.values();

List<Broadcast> list = new ArrayList();

for (Broadcast broadcast : values)
{
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++;
continue;
}
list.add(broadcast);

itemCount++;

if (itemCount >= size) {
break;
}
}
}
return list;
}

@Override
public String addVod(VoD vod) {
String id = null;
Expand Down
71 changes: 70 additions & 1 deletion src/main/java/io/antmedia/datastore/db/MapDBStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,75 @@ public List<Broadcast> filterBroadcastList(int offset, int size, String type) {

}

@Override
public List<Broadcast> filterBroadcastListByType(int offset, int size, String type, String value) {

List<Broadcast> list = new ArrayList<Broadcast>();
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<Broadcast> filterList = new ArrayList<>();
for (int i = 0; i < broadcastArray.length; i++) {
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<Broadcast> 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) {

Expand Down Expand Up @@ -1038,4 +1107,4 @@ public boolean setMp4Muxing(String streamId, int enabled) {
}
return result;
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/io/antmedia/datastore/db/MongoStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ public List<Broadcast> filterBroadcastList(int offset, int size, String type) {
return null;
}

@Override
public List<Broadcast> filterBroadcastListByType(int offset, int size, String type, String value) {
try {
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));
}
return null;
}

@Override
public String addVod(VoD vod) {

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/antmedia/rest/BroadcastRestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,14 @@ public List<Broadcast> 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<Broadcast> filterBroadcastListByType(@PathParam("offset") int offset, @PathParam("size") int size,
@PathParam("type") String type, @PathParam("value") String value) {
return getDataStore().filterBroadcastListByType(offset, size, type, value);
}

@POST
@Consumes({ MediaType.APPLICATION_JSON })
Expand Down