Search in sources :

Example 56 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class CatalogOutputAdapterTest method testGetNitfBinaryContentBlockedChip.

@Test
public void testGetNitfBinaryContentBlockedChip() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    // 200000N0200000E 200000N0400000E
    // 000000N0200000E 000000N0400000E
    int originalWidth = 2048;
    int originalHeight = 2048;
    int chipX = 0;
    int chipY = 0;
    int chipWidth = 2048;
    int chipHeight = 2048;
    BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_3BYTE_BGR);
    FileSecurityMetadata fileSecurityMetadata = createFileSecurityMetadata();
    DateTime dateTime = DateTimeImpl.getNitfDateTimeForNow();
    DataSource dataSource = mock(DataSource.class);
    NitfHeader nitfHeader = getNitfHeader(fileSecurityMetadata, dateTime);
    ImageCoordinates imageCoordinates = getImageCoordinates();
    SecurityMetadata imageSecurityMetadata = getImageSecurityMetadata();
    ImageSegment imageSegment = getImageSegment(originalWidth, originalHeight, dateTime, imageCoordinates, imageSecurityMetadata);
    when(dataSource.getNitfHeader()).thenReturn(nitfHeader);
    when(dataSource.getImageSegments()).thenReturn(Collections.singletonList(imageSegment));
    Constructor<NitfSegmentsFlowImpl> constructor;
    constructor = NitfSegmentsFlowImpl.class.getDeclaredConstructor(DataSource.class, Runnable.class);
    constructor.setAccessible(true);
    NitfSegmentsFlow nitfSegmentsFlow = constructor.newInstance(dataSource, (Runnable) () -> {
    });
    BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, chipX, chipY);
    NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData();
    assertThat(chipNitfSegmentFlow, notNullValue());
    chipNitfSegmentFlow.fileHeader(nh -> {
        assertThat(nh.getFileType(), is(FileType.NITF_TWO_ONE));
        assertThat(nh.getFileTitle(), is("FileTitle"));
        assertThat(nh.getStandardType(), is("BF01"));
        assertThat(nh.getOriginatingStationId(), is("U21SOO90"));
        assertThat(nh.getFileBackgroundColour().getRed(), is((byte) 0));
        assertThat(nh.getFileBackgroundColour().getGreen(), is((byte) 0));
        assertThat(nh.getFileBackgroundColour().getBlue(), is((byte) 0));
        assertThat(nh.getFileDateTime(), notNullValue());
        assertThat(nh.getOriginatorsName(), is("W.TEMPEL"));
        assertThat(nh.getOriginatorsPhoneNumber(), is("44 1480 84 5611"));
        assertThat(nh.getFileSecurityMetadata().getSecurityClassification(), is(SecurityClassification.UNCLASSIFIED));
        assertThat(nh.getFileSecurityMetadata().getSecurityClassificationSystem(), is("AB"));
        assertThat(nh.getFileSecurityMetadata().getCodewords(), is("ABCDEFGHIJK"));
        assertThat(nh.getFileSecurityMetadata().getControlAndHandling(), is("AB"));
        assertThat(nh.getFileSecurityMetadata().getReleaseInstructions(), is("01234567890123456789"));
        assertThat(nh.getFileSecurityMetadata().getDeclassificationType(), is("DD"));
        assertThat(nh.getFileSecurityMetadata().getDeclassificationDate(), is("20160101"));
        assertThat(nh.getFileSecurityMetadata().getDeclassificationExemption(), is("abcd"));
        assertThat(nh.getFileSecurityMetadata().getDowngrade(), is("S"));
        assertThat(nh.getFileSecurityMetadata().getDowngradeDate(), is("20160202"));
        assertThat(nh.getFileSecurityMetadata().getClassificationText(), is("classtext"));
        assertThat(nh.getFileSecurityMetadata().getClassificationAuthorityType(), is("O"));
        assertThat(nh.getFileSecurityMetadata().getClassificationAuthority(), is("MyAuthority"));
        assertThat(nh.getFileSecurityMetadata().getClassificationReason(), is("A"));
        assertThat(nh.getFileSecurityMetadata().getSecuritySourceDate(), is("20160303"));
        assertThat(nh.getFileSecurityMetadata().getSecurityControlNumber(), is("012345678901234"));
        assertThat(nh.getFileSecurityMetadata().getFileCopyNumber(), is("99999"));
        assertThat(nh.getFileSecurityMetadata().getFileNumberOfCopies(), is("99999"));
    });
    chipNitfSegmentFlow.forEachImageSegment(imageSegment1 -> {
        assertThat(imageSegment1.getImageCoordinates().getCoordinate00().getLongitude(), closeTo(20, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinate00().getLatitude(), closeTo(20, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinate0MaxCol().getLongitude(), closeTo(40, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinate0MaxCol().getLatitude(), closeTo(20, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinateMaxRowMaxCol().getLongitude(), closeTo(40, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinateMaxRowMaxCol().getLatitude(), closeTo(0, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinateMaxRow0().getLongitude(), closeTo(20, 0.01));
        assertThat(imageSegment1.getImageCoordinates().getCoordinateMaxRow0().getLatitude(), closeTo(0, 0.01));
        assertThat(imageSegment1.getNumberOfColumns(), is((long) chipWidth));
        assertThat(imageSegment1.getNumberOfRows(), is((long) chipHeight));
        assertThat(imageSegment1.getImageCategory(), is(ImageCategory.UNKNOWN));
        assertThat(imageSegment1.getImageComments(), is(Collections.singletonList("MyComment")));
        assertThat(imageSegment1.getIdentifier(), is("0123456789"));
        assertThat(imageSegment1.getImageIdentifier2(), is("abc"));
        assertThat(imageSegment1.getImageMagnification(), is("1.0 "));
        try {
            assertThat(imageSegment1.getImageTargetId().textValue(), is(new TargetIdImpl("                 ").textValue()));
        } catch (NitfFormatException e) {
            fail(e.getMessage());
        }
        assertThat(imageSegment1.getImageSource(), is(""));
        assertThat(imageSegment1.getImageDateTime().getSourceString(), is(dateTime.getSourceString()));
        assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBTRUECOLOUR));
    });
}
Also used : ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) TargetIdImpl(org.codice.imaging.nitf.core.image.impl.TargetIdImpl) NitfFormatException(org.codice.imaging.nitf.core.common.NitfFormatException) NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BinaryContent(ddf.catalog.data.BinaryContent) FileSecurityMetadata(org.codice.imaging.nitf.core.security.FileSecurityMetadata) BufferedImage(java.awt.image.BufferedImage) DateTime(org.codice.imaging.nitf.core.common.DateTime) DataSource(org.codice.imaging.nitf.core.DataSource) NitfSegmentsFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfSegmentsFlowImpl) NitfHeader(org.codice.imaging.nitf.core.header.NitfHeader) ImageCoordinates(org.codice.imaging.nitf.core.image.ImageCoordinates) SecurityMetadata(org.codice.imaging.nitf.core.security.SecurityMetadata) FileSecurityMetadata(org.codice.imaging.nitf.core.security.FileSecurityMetadata) Test(org.junit.Test)

Example 57 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class CatalogOutputAdapterTest method testByteIndexed.

@Test
public void testByteIndexed() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    int originalWidth = 200;
    int originalHeight = 100;
    int chipWidth = 160;
    int chipHeight = 80;
    NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight);
    BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_BYTE_INDEXED);
    BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0);
    NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData();
    chipNitfSegmentFlow.forEachImageSegment(imageSegment1 -> {
        assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER));
        assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBLUT));
        assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("LU"));
    });
}
Also used : NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BinaryContent(ddf.catalog.data.BinaryContent) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 58 with BinaryContent

use of ddf.catalog.data.BinaryContent in project alliance by codice.

the class CatalogOutputAdapterTest method testIntARGB.

@Test
public void testIntARGB() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    int originalWidth = 200;
    int originalHeight = 100;
    int chipWidth = 160;
    int chipHeight = 80;
    NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight);
    BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_INT_ARGB);
    BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0);
    NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData();
    chipNitfSegmentFlow.forEachImageSegment(imageSegment1 -> {
        assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER));
        assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBTRUECOLOUR));
        assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("R"));
        assertThat(imageSegment1.getImageBand(2).getImageRepresentation(), is("G"));
        assertThat(imageSegment1.getImageBand(3).getImageRepresentation(), is("B"));
    });
}
Also used : NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BinaryContent(ddf.catalog.data.BinaryContent) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 59 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class CatalogFrameworkImplTest method testMetacardTransform.

@Test
public void testMetacardTransform() throws Exception {
    BundleContext context = mock(BundleContext.class);
    MetacardTransformer transformer = mock(MetacardTransformer.class);
    ServiceReference reference = mock(ServiceReference.class);
    ServiceReference[] serviceReferences = new ServiceReference[] { reference };
    when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
    when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
    when(transformer.transform(isA(Metacard.class), isA(Map.class))).thenReturn(new BinaryContentImpl(null));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    BinaryContent content = framework.transform(newCard, "NONE", new HashMap<String, Serializable>());
    assertNotNull(content);
}
Also used : Serializable(java.io.Serializable) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ServiceReference(org.osgi.framework.ServiceReference) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 60 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class CswQueryResponseTransformer method multiThreadedMarshal.

/**
     * Multi-threaded marshal of metacard assumes that the query size is unbounded to guard against
     * resource exhaustion with fixed thread-pool and fixed work-queue.  CPU-bound for optimum utilization
     * from availableProcessors()+1 thread pool.
     *
     * @param results - the list of results to marshal
     * @param recordSchema - the schema
     * @param arguments - additional args
     * @return - the marshaled results
     * @throws CatalogTransformerException
     */
private String multiThreadedMarshal(List<Result> results, AtomicLong numResults, String recordSchema, final Map<String, Serializable> arguments) throws CatalogTransformerException {
    CompletionService<BinaryContent> completionService = new ExecutorCompletionService<>(queryExecutor);
    final MetacardTransformer transformer = metacardTransformerManager.getTransformerBySchema(recordSchema);
    if (transformer == null) {
        throw new CatalogTransformerException("Cannot find transformer for schema: " + recordSchema);
    }
    Map<Future<BinaryContent>, Result> futures = new HashMap<>(results.size());
    for (Result result : results) {
        final Metacard mc = result.getMetacard();
        // the "current" thread will run submitted task when queueSize exceeded; effectively
        // blocking enqueue of more tasks.
        futures.put(completionService.submit(() -> {
            BinaryContent content = transformer.transform(mc, arguments);
            return content;
        }), result);
    }
    InputStream[] contents = new InputStream[results.size()];
    while (!futures.isEmpty()) {
        try {
            Future<BinaryContent> completedFuture = completionService.take();
            int index = results.indexOf(futures.get(completedFuture));
            try {
                contents[index] = completedFuture.get().getInputStream();
            } catch (ExecutionException | CancellationException | InterruptedException e) {
                LOGGER.debug("Error transforming Metacard", e);
                numResults.decrementAndGet();
            } finally {
                futures.remove(completedFuture);
            }
        } catch (InterruptedException e) {
            LOGGER.debug("Metacard transform interrupted", e);
        }
    }
    CharArrayWriter accum = new CharArrayWriter(ACCUM_INITIAL_SIZE);
    for (InputStream is : contents) {
        try {
            if (is != null) {
                IOUtils.copy(is, accum);
            }
        } catch (IOException e) {
            LOGGER.debug("Error copying Metacard Binary content", e);
        }
    }
    return accum.toString();
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) BinaryContent(ddf.catalog.data.BinaryContent) CharArrayWriter(java.io.CharArrayWriter) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)112 Test (org.junit.Test)79 Metacard (ddf.catalog.data.Metacard)42 SourceResponse (ddf.catalog.operation.SourceResponse)41 HashMap (java.util.HashMap)30 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)28 Map (java.util.Map)24 Result (ddf.catalog.data.Result)22 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)19 Matchers.anyString (org.mockito.Matchers.anyString)18 Serializable (java.io.Serializable)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 Date (java.util.Date)12 LineString (ddf.geo.formatter.LineString)11 MultiLineString (ddf.geo.formatter.MultiLineString)11 File (java.io.File)11 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)10 ResultImpl (ddf.catalog.data.impl.ResultImpl)10 IOException (java.io.IOException)10