Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Prepare #276
Browse files Browse the repository at this point in the history
  • Loading branch information
hdsdi3g committed Jun 12, 2017
1 parent b472245 commit 1d0fc3c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/hd3gtv/elemtl/CuePointEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import hd3gtv.configuration.Configuration;
import hd3gtv.mydmam.Loggers;
import hd3gtv.mydmam.bcastautomation.BCACatchedEvent;
import hd3gtv.mydmam.bcastautomation.BCAEventCatched;
import hd3gtv.mydmam.bcastautomation.BCAEventCatcherHandler;

public class CuePointEngine extends BCAEventCatcherHandler {
Expand Down Expand Up @@ -65,7 +65,7 @@ public CuePointEngine() throws JsonSyntaxException, IOException {
}
}

public void handleEventCreation(BCACatchedEvent entry) {
public void handleEventCreation(BCAEventCatched entry) {
event_id_by_server.forEach((s, id) -> {
try {
s.createCuePoint(entry.getDate(), Math.round(entry.getDuration().getValue()), id, Integer.parseInt(entry.getExternalRef()));
Expand All @@ -75,7 +75,7 @@ public void handleEventCreation(BCACatchedEvent entry) {
});
}

public void handleEventRemoving(BCACatchedEvent entry) {
public void handleEventRemoving(BCAEventCatched entry) {
event_id_by_server.forEach((s, id) -> {
try {
s.removeCuePoint(id, Integer.parseInt(entry.getExternalRef()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import hd3gtv.mydmam.Loggers;
import hd3gtv.tools.Timecode;

public final class BCACatchedEvent {
public final class BCAEventCatched {

private long date;

Expand All @@ -29,29 +29,33 @@ public final class BCACatchedEvent {

private long update_date;

@Deprecated
private transient boolean checked;

private String external_ref;

private String original_event_key;

/**
* @return checked event
*/
static BCACatchedEvent create(BCAAutomationEvent event, String external_ref) {
BCACatchedEvent result = new BCACatchedEvent();
static BCAEventCatched create(BCAAutomationEvent event, String external_ref) {
BCAEventCatched result = new BCAEventCatched();
result.date = event.getStartDate();
result.duration = event.getDuration();
result.name = event.getName();
result.update_date = System.currentTimeMillis();
result.checked = true;
result.external_ref = external_ref;
// result.original_event_key = event.getAutomationId()XXX
return result;
}

boolean compare(BCAAutomationEvent event) {
/*System.out.println(event.getStartDate());
System.out.println(date);
System.out.println(Timecode.delta(duration, event.getDuration()));*/
return event.getStartDate() == date && Math.abs(Timecode.delta(duration, event.getDuration())) < 10;
return event.getStartDate() == date && Math.abs(Timecode.delta(duration, event.getDuration())) < 10; // TODO test with original_event_key
}

public String toString() {
Expand All @@ -66,14 +70,16 @@ public String toString() {
return sb.toString();
}

boolean isOld() {
boolean isOld() {// TODO for what ?
return date + 10000 < System.currentTimeMillis();
}

@Deprecated
boolean isChecked() {
return checked;
}

@Deprecated
void setChecked(boolean checked) {
this.checked = checked;
}
Expand Down
20 changes: 10 additions & 10 deletions app/hd3gtv/mydmam/bcastautomation/BCAEventCatcherHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public abstract class BCAEventCatcherHandler {
private String property_to_catch;

private File json_db_file;
private ArrayList<BCACatchedEvent> entries;
private ArrayList<BCACatchedEvent> to_add = new ArrayList<>();
private ArrayList<BCACatchedEvent> to_remove = new ArrayList<>();
private ArrayList<BCAEventCatched> entries;
private ArrayList<BCAEventCatched> to_add = new ArrayList<>();
private ArrayList<BCAEventCatched> to_remove = new ArrayList<>();

private boolean modified;

Expand Down Expand Up @@ -92,14 +92,14 @@ boolean isEventCanBeCatched(BCAAutomationEvent event) {
* @param event was tested true by isEventCanBeCatched()
*/
void onCatchEvent(BCAAutomationEvent event) {
Optional<BCACatchedEvent> opt_entry = entries.stream().filter(event_catch -> {
Optional<BCAEventCatched> opt_entry = entries.stream().filter(event_catch -> {
return event_catch.compare(event);
}).findFirst();

if (opt_entry.isPresent()) {
opt_entry.get().setChecked(true);
} else {
BCACatchedEvent entry = BCACatchedEvent.create(event, createExternalRef());
BCAEventCatched entry = BCAEventCatched.create(event, createExternalRef());
to_add.add(entry);
entries.add(entry);
}
Expand Down Expand Up @@ -137,11 +137,11 @@ void onAfterCatchEvents() {

to_remove.forEach(entry -> {
Loggers.BroadcastAutomation.info("Catch event moved/removed in playlist: \"" + entry.toString() + "\"");
handleEventRemoving(entry);
// handleEventRemoving(entry); XXX
});
to_add.forEach(entry -> {
Loggers.BroadcastAutomation.info("Catch new event: \"" + entry.toString() + "\"");
handleEventCreation(entry);
// handleEventCreation(entry); XXX
});

if (modified) {
Expand All @@ -155,7 +155,7 @@ void onAfterCatchEvents() {
}

private String createExternalRef() {
AtomicInteger i = new AtomicInteger(0);
AtomicInteger i = new AtomicInteger(0);// TODO Not start from 0

while (entries.stream().anyMatch(entry -> {
return Integer.parseInt(entry.getExternalRef()) == i.get();
Expand All @@ -165,9 +165,9 @@ private String createExternalRef() {
return String.valueOf(i.get());
}

protected abstract void handleEventCreation(BCACatchedEvent entry);
protected abstract void handleEventCreation(BCAEventCatched entry);

protected abstract void handleEventRemoving(BCACatchedEvent entry);
protected abstract void handleEventRemoving(BCAEventCatched entry);

public abstract String getName();

Expand Down
43 changes: 43 additions & 0 deletions app/hd3gtv/mydmam/cli/CliModuleBCA.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,48 @@ public void execCliModule(ApplicationArgs args) throws Exception {
table.print();

return;
/*} else if (args.getParamExist("-catch")) {
// TODO CLI ?
if (CassandraDb.isColumnFamilyExists(CassandraDb.getkeyspace(), BCAWatcher.CF_NAME) == false) {
System.err.println("No BCA events in database");
return;
}
TimedEventStore database = new TimedEventStore(CassandraDb.getkeyspace(), BCAWatcher.CF_NAME);
TableList table = new TableList();
final JsonParser p = new JsonParser();
Function<String, ArrayList<String>> json_reducer = (event) -> {
ArrayList<String> result = new ArrayList<>();
JsonObject jo_event = p.parse(event).getAsJsonObject();
result.add(jo_event.get("name").getAsString());
result.add(jo_event.get("duration").getAsString());
result.add(jo_event.get("channel").getAsString());
result.add(jo_event.get("file_id").getAsString());
result.add(jo_event.get("video_source").getAsString());
result.add(jo_event.get("other").toString());
return result;
};
database.getFilteredAll().forEach(event -> {
if (event.isAired()) {
return;
}
event.toTable(table, true, json_reducer);
});
if (table.size() > 0) {
Row footer = table.createRow();
footer.addCell("Event key");
footer.addCells("Start date", "End date", "Name", "Duration", "Channel", "File", "Source", "Aired");
System.out.println("Showed " + (table.size() - 1) + " events");
}
table.print();
return;*/
}

showFullCliModuleHelp();
Expand All @@ -129,6 +171,7 @@ public void showFullCliModuleHelp() {
System.out.println(" * get all events actually in database: " + getCliModuleName() + " -dump [-raw] [-key]");
System.out.println(" with -raw for display raw content");
System.out.println(" with -key for display event key");
// System.out.println(" * event catcher debug: " + getCliModuleName() + " -catch"); //TODO CLI ?
}

public boolean isFunctionnal() {
Expand Down
4 changes: 2 additions & 2 deletions app/hd3gtv/mydmam/gson/GsonKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import hd3gtv.mydmam.auth.asyncjs.UserAdminUpdate;
import hd3gtv.mydmam.auth.asyncjs.UserView;
import hd3gtv.mydmam.auth.asyncjs.UserViewList;
import hd3gtv.mydmam.bcastautomation.BCACatchedEvent;
import hd3gtv.mydmam.bcastautomation.BCAEventCatched;
import hd3gtv.mydmam.ftpserver.AJSResponseActivities;
import hd3gtv.mydmam.ftpserver.AJSResponseUserList;
import hd3gtv.mydmam.ftpserver.AJSUser;
Expand Down Expand Up @@ -154,7 +154,7 @@ public class GsonKit {
}.getType();
public final static Type type_ArrayList_UserNotificationNG = new TypeToken<ArrayList<UserNotificationNG>>() {
}.getType();
public final static Type type_ArrayList_BCACatchEntry = new TypeToken<ArrayList<BCACatchedEvent>>() {
public final static Type type_ArrayList_BCACatchEntry = new TypeToken<ArrayList<BCAEventCatched>>() {
}.getType();
public final static Type type_ArrayList_JobContext = new TypeToken<ArrayList<JobContext>>() {
}.getType();
Expand Down

0 comments on commit 1d0fc3c

Please sign in to comment.