Search in sources :

Example 41 with BinaryContent

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

the class TestXmlResponseQueueTransformer method testNoIdNoSourceId.

@Test
public void testNoIdNoSourceId() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    transformer.setThreshold(2);
    SourceResponse response = givenSourceResponse(null, null);
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(mimeType));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    print(output, verboseDebug);
    assertXpathNotExists("/mc:metacards/mc:metacard/mc:source", output);
    assertXpathNotExists("/mc:metacards/mc:metacard/@gml:id", output);
    verifyDefaults("1", output);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 42 with BinaryContent

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

the class TestZipCompression method testCompressionWithDerivedContentInvalidURI.

@Test
public void testCompressionWithDerivedContentInvalidURI() throws Exception {
    String invalidUri = "^";
    SourceResponse sourceResponse = createSourceResponseWithURISchemes(CONTENT_SCHEME, invalidUri);
    BinaryContent binaryContent = zipCompression.transform(sourceResponse, filePathArgument);
    assertThat(binaryContent, notNullValue());
    assertZipContents(binaryContent, METACARD_RESULT_LIST_WITH_CONTENT);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 43 with BinaryContent

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

the class OverviewSupplierTest method setUp.

@Before
public void setUp() throws CatalogTransformerException {
    final BinaryContent overviewContent = mock(BinaryContent.class);
    doAnswer(invocationOnMock -> getClass().getClassLoader().getResourceAsStream("flower.jpg")).when(overviewContent).getInputStream();
    final MetacardTransformer resourceMetacardTransformer = mock(MetacardTransformer.class);
    doReturn(overviewContent).when(resourceMetacardTransformer).transform(argThat(isMetacardWithDerivedOverviewResource()), eq(Collections.singletonMap(ContentItem.QUALIFIER_KEYWORD, "overview")));
    doThrow(CatalogTransformerException.class).when(resourceMetacardTransformer).transform(argThat(not(isMetacardWithDerivedOverviewResource())), eq(Collections.singletonMap(ContentItem.QUALIFIER_KEYWORD, "overview")));
    supplier = new OverviewSupplier(resourceMetacardTransformer);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Before(org.junit.Before)

Example 44 with BinaryContent

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

the class OverviewSupplier method apply.

@Override
public Optional<BufferedImage> apply(Metacard metacard, Map<String, Serializable> arguments) {
    try {
        final Map<String, Serializable> resourceTransformerArguments = new HashMap<>();
        resourceTransformerArguments.put(ContentItem.QUALIFIER_KEYWORD, "overview");
        final BinaryContent overviewContent = resourceMetacardTransformer.transform(metacard, resourceTransformerArguments);
        try (final InputStream inputStream = overviewContent.getInputStream()) {
            return Optional.ofNullable(ImageIO.read(inputStream));
        }
    } catch (IOException | CatalogTransformerException e) {
        LOGGER.debug("Could not get the overview image.", e);
    }
    return Optional.empty();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) BinaryContent(ddf.catalog.data.BinaryContent)

Example 45 with BinaryContent

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

the class CatalogOutputAdapterTest method testGrayscale.

@Test
public void testGrayscale() 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_GRAY);
    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.MONOCHROME));
        assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8));
        assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("M"));
    });
}
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)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)214 Test (org.junit.Test)164 Metacard (ddf.catalog.data.Metacard)87 SourceResponse (ddf.catalog.operation.SourceResponse)78 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)51 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)44 HashMap (java.util.HashMap)42 Result (ddf.catalog.data.Result)41 Map (java.util.Map)39 Serializable (java.io.Serializable)33 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)27 ResultImpl (ddf.catalog.data.impl.ResultImpl)26 LineString (ddf.geo.formatter.LineString)21 MultiLineString (ddf.geo.formatter.MultiLineString)21 Date (java.util.Date)21 File (java.io.File)20 JSONObject (org.json.simple.JSONObject)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 FileOutputStream (java.io.FileOutputStream)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17