org.yamcs.client.timeline.TimelineClient Maven / Gradle / Ivy
package org.yamcs.client.timeline;
import static org.yamcs.client.utils.WellKnownTypes.toTimestamp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.yamcs.api.MethodHandler;
import org.yamcs.api.Observer;
import org.yamcs.client.Page;
import org.yamcs.client.base.AbstractPage;
import org.yamcs.client.base.ResponseObserver;
import org.yamcs.protobuf.AddBandRequest;
import org.yamcs.protobuf.CreateItemRequest;
import org.yamcs.protobuf.DeleteBandRequest;
import org.yamcs.protobuf.DeleteItemRequest;
import org.yamcs.protobuf.DeleteTimelineGroupRequest;
import org.yamcs.protobuf.GetItemLogRequest;
import org.yamcs.protobuf.GetItemRequest;
import org.yamcs.protobuf.ListBandsRequest;
import org.yamcs.protobuf.ListBandsResponse;
import org.yamcs.protobuf.ListItemsRequest;
import org.yamcs.protobuf.ListItemsResponse;
import org.yamcs.protobuf.ListSourcesRequest;
import org.yamcs.protobuf.ListSourcesResponse;
import org.yamcs.protobuf.ListTimelineTagsRequest;
import org.yamcs.protobuf.ListTimelineTagsResponse;
import org.yamcs.protobuf.TimelineApiClient;
import org.yamcs.protobuf.TimelineBand;
import org.yamcs.protobuf.TimelineItem;
import org.yamcs.protobuf.TimelineItemLog;
import org.yamcs.protobuf.TimelineSourceCapabilities;
import org.yamcs.protobuf.UpdateItemRequest;
public class TimelineClient {
static public final String RDB_TIMELINE_SOURCE = "rdb";
final String instance;
final TimelineApiClient timelineService;
public TimelineClient(MethodHandler handler, String instance) {
this.instance = instance;
timelineService = new TimelineApiClient(handler);
}
public CompletableFuture> getItems(Instant start, Instant stop, String band) {
ListItemsRequest.Builder requestb = ListItemsRequest.newBuilder()
.setInstance(instance);
if (start != null) {
requestb.setStart(toTimestamp(start));
}
if (stop != null) {
requestb.setStop(toTimestamp(stop));
}
if (band != null) {
requestb.setBand(band);
}
return new TimelineItemPage(requestb.build()).future();
}
public CompletableFuture addItem(String source, TimelineItem item) {
if (!item.hasType()) {
throw new IllegalArgumentException("type is mandatory");
}
CreateItemRequest.Builder requestb = CreateItemRequest.newBuilder()
.setType(item.getType())
.setInstance(instance)
.setSource(source);
if (item.hasStart()) {
requestb.setStart(item.getStart());
}
if (item.hasRelativeTime()) {
requestb.setRelativeTime(item.getRelativeTime());
}
if (item.hasDuration()) {
requestb.setDuration(item.getDuration());
}
requestb.addAllTags(item.getTagsList());
if (item.hasGroupId()) {
requestb.setGroupId(item.getGroupId());
}
if (item.hasDescription()) {
requestb.setDescription(item.getDescription());
}
CompletableFuture f = new CompletableFuture<>();
timelineService.createItem(null, requestb.build(), new ResponseObserver<>(f));
return f;
}
public CompletableFuture addItem(TimelineItem item) {
return addItem(RDB_TIMELINE_SOURCE, item);
}
public CompletableFuture getItem(String source, String id) {
CompletableFuture f = new CompletableFuture<>();
GetItemRequest.Builder requestb = GetItemRequest.newBuilder()
.setInstance(instance)
.setSource(source)
.setId(id);
timelineService.getItem(null, requestb.build(), new ResponseObserver<>(f));
return f;
}
public CompletableFuture deleteItem(String id) {
return deleteItem(RDB_TIMELINE_SOURCE, id);
}
public CompletableFuture deleteItem(String source, String id) {
CompletableFuture f = new CompletableFuture<>();
DeleteItemRequest.Builder requestb = DeleteItemRequest.newBuilder()
.setInstance(instance)
.setSource(source)
.setId(id);
timelineService.deleteItem(null, requestb.build(), new ResponseObserver<>(f));
return f;
}
public CompletableFuture getItemLog(String id) {
CompletableFuture f = new CompletableFuture<>();
GetItemLogRequest.Builder requestb = GetItemLogRequest.newBuilder()
.setInstance(instance)
.setSource(RDB_TIMELINE_SOURCE)
.setId(id);
timelineService.getItemLog(null, requestb.build(), new ResponseObserver<>(f));
return f;
}
public CompletableFuture deleteTimelineGroup(String id) {
return deleteTimelineGroup(RDB_TIMELINE_SOURCE, id);
}
public CompletableFuture deleteTimelineGroup(String source, String id) {
CompletableFuture f = new CompletableFuture<>();
DeleteTimelineGroupRequest.Builder requestb = DeleteTimelineGroupRequest.newBuilder()
.setInstance(instance)
.setSource(source)
.setId(id);
timelineService.deleteTimelineGroup(null, requestb.build(), new ResponseObserver<>(f));
return f;
}
public CompletableFuture getItem(String id) {
return getItem(RDB_TIMELINE_SOURCE, id);
}
public CompletableFuture
© 2015 - 2024 Weber Informatics LLC | Privacy Policy