Search in sources :

Example 16 with Context

use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.

the class UpdateParentTest method testEnd.

/**
 * Test that #end calls the catalog framework
 */
@Test
public void testEnd() throws SourceUnavailableException, IngestException {
    UpdateParent.UpdateField updateField = mock(UpdateParent.UpdateField.class);
    UpdateParent updateParent = new UpdateParent(updateField);
    UdpStreamProcessor udpStreamProcessor = mock(UdpStreamProcessor.class);
    CatalogFramework catalogFramework = mock(CatalogFramework.class);
    when(udpStreamProcessor.getCatalogFramework()).thenReturn(catalogFramework);
    when(udpStreamProcessor.getMetacardUpdateInitialDelay()).thenReturn(1L);
    Context context = mock(Context.class);
    when(context.getUdpStreamProcessor()).thenReturn(udpStreamProcessor);
    Metacard parent = mock(Metacard.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    Update update = mock(Update.class);
    when(update.getNewMetacard()).thenReturn(parent);
    when(updateResponse.getUpdatedMetacards()).thenReturn(Collections.singletonList(update));
    when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);
    updateParent.end(context, parent);
    verify(updateField).end(parent, context);
    ArgumentCaptor<UpdateRequest> captor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework).update(captor.capture());
    assertThat(captor.getValue().getUpdates().get(0).getValue(), is(parent));
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) CatalogFramework(ddf.catalog.CatalogFramework) Update(ddf.catalog.operation.Update) UdpStreamProcessor(org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor) Test(org.junit.Test)

Example 17 with Context

use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.

the class LineStringMetacardUpdaterTest method testChildOnly.

@Test
public void testChildOnly() throws ParseException {
    String childWkt = normalize("LINESTRING(0 0, 1 1)");
    when(childAttr.getValue()).thenReturn(childWkt);
    when(childMetacard.getAttribute(attrName)).thenReturn(childAttr);
    Context context = mock(Context.class);
    lineStringMetacardUpdater.update(parentMetacard, childMetacard, context);
    ArgumentCaptor<Attribute> argumentCaptor = ArgumentCaptor.forClass(Attribute.class);
    verify(parentMetacard).setAttribute(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getValue(), is(childWkt));
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 18 with Context

use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.

the class LocationUpdateField method doUpdateField.

@Override
protected void doUpdateField(Metacard parent, List<Metacard> children, Context context) {
    WKTReader wktReader = new WKTReader();
    List<String> childLocations = extractChildLocations(children);
    List<Geometry> geometries = childLocations.stream().map(s -> GeometryUtility.wktToGeometry(s, wktReader)).filter(Optional::isPresent).map(Optional::get).map(geometry -> preUnionGeometryOperator.apply(geometry, context.getGeometryOperatorContext())).collect(Collectors.toList());
    if (intermediateGeometry != null) {
        geometries.add(intermediateGeometry);
    }
    geometries.stream().reduce(Geometry::union).ifPresent(geometry -> intermediateGeometry = geometry);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) StringUtils(org.apache.commons.lang.StringUtils) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) WKTReader(com.vividsolutions.jts.io.WKTReader) Collectors(java.util.stream.Collectors) List(java.util.List) Metacard(ddf.catalog.data.Metacard) Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Optional(java.util.Optional) GeometryUtility(org.codice.alliance.libs.klv.GeometryUtility) Context(org.codice.alliance.video.stream.mpegts.Context) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Core(ddf.catalog.data.types.Core) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) Optional(java.util.Optional) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 19 with Context

use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.

the class FrameCenterUpdateField method doUpdateField.

@Override
protected void doUpdateField(Metacard parent, List<Metacard> children, Context context) {
    WKTReader wktReader = new WKTReader();
    List<String> childLocations = extractChildFrameCenters(children);
    List<Geometry> geometries = new LinkedList<>();
    if (intermediateGeometry != null) {
        geometries.add(intermediateGeometry);
    }
    geometries.addAll(childLocations.stream().map(s -> GeometryUtility.wktToGeometry(s, wktReader)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
    List<Coordinate> coordinates = geometries.stream().flatMap(geometry -> Stream.of(geometry.getCoordinates())).collect(Collectors.toList());
    intermediateGeometry = geometryFactory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) GeometryOperatorList(org.codice.alliance.libs.klv.GeometryOperatorList) LinestringGeometrySubsampler(org.codice.alliance.libs.klv.LinestringGeometrySubsampler) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) WKTReader(com.vividsolutions.jts.io.WKTReader) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) AttributeNameConstants(org.codice.alliance.libs.klv.AttributeNameConstants) Attribute(ddf.catalog.data.Attribute) Stream(java.util.stream.Stream) Metacard(ddf.catalog.data.Metacard) Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Optional(java.util.Optional) GeometryUtility(org.codice.alliance.libs.klv.GeometryUtility) Context(org.codice.alliance.video.stream.mpegts.Context) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LinkedList(java.util.LinkedList) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) Optional(java.util.Optional) Coordinate(com.vividsolutions.jts.geom.Coordinate) WKTReader(com.vividsolutions.jts.io.WKTReader) LinkedList(java.util.LinkedList)

Example 20 with Context

use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.

the class FrameCenterUpdateFieldTest method testLineString.

@Test
public void testLineString() {
    String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
    String wktChild2 = "LINESTRING (50 50, 60 60, 70 70)";
    String wktChild3 = "LINESTRING (80 80, 85 85)";
    String wktExpected = "LINESTRING (30 10, 10 30, 40 40, 50 50, 60 60, 70 70, 80 80, 85 85)";
    Metacard parentMetacard = mock(Metacard.class);
    Metacard childMetacard1 = mock(Metacard.class);
    when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
    Metacard childMetacard2 = mock(Metacard.class);
    when(childMetacard2.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild2));
    Metacard childMetacard3 = mock(Metacard.class);
    when(childMetacard3.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild3));
    FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(GeometryOperator.IDENTITY, new GeometryFactory());
    Context context = mock(Context.class);
    GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
    geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
    when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
    frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
    frameCenterUpdateField.updateField(parentMetacard, Arrays.asList(childMetacard2, childMetacard3), context);
    frameCenterUpdateField.end(parentMetacard, context);
    ArgumentCaptor<Attribute> captor = ArgumentCaptor.forClass(Attribute.class);
    verify(parentMetacard).setAttribute(captor.capture());
    assertThat(captor.getValue().getValue(), is(wktExpected));
    assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Aggregations

Context (org.codice.alliance.video.stream.mpegts.Context)29 Test (org.junit.Test)24 Metacard (ddf.catalog.data.Metacard)19 UdpStreamProcessor (org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor)10 GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)8 Attribute (ddf.catalog.data.Attribute)7 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)6 CatalogFramework (ddf.catalog.CatalogFramework)5 Geometry (com.vividsolutions.jts.geom.Geometry)4 WKTReader (com.vividsolutions.jts.io.WKTReader)4 List (java.util.List)3 Timer (java.util.Timer)3 Before (org.junit.Before)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)2 MetacardType (ddf.catalog.data.MetacardType)2 CreateRequest (ddf.catalog.operation.CreateRequest)2 CreateResponse (ddf.catalog.operation.CreateResponse)2 Update (ddf.catalog.operation.Update)2 UpdateResponse (ddf.catalog.operation.UpdateResponse)2