Search in sources :

Example 11 with CatalogTransformerException

use of ddf.catalog.transform.CatalogTransformerException 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 12 with CatalogTransformerException

use of ddf.catalog.transform.CatalogTransformerException in project alliance by codice.

the class MpegTsInputTransformer method extractInnerTransformerMetadata.

/**
 * Call the inner transformer with the content data and return a metacard based on {@link
 * #metacardTypes} that is populated by the inner transformer and with the content type set to
 * {@link #CONTENT_TYPE}.
 *
 * @param id metacard identifier
 * @param fileBackedOutputStream used to provide a byte source
 * @return metacard
 * @throws IOException
 * @throws CatalogTransformerException
 */
private MetacardImpl extractInnerTransformerMetadata(String id, TemporaryFileBackedOutputStream fileBackedOutputStream) throws IOException, CatalogTransformerException {
    try (InputStream inputStream = fileBackedOutputStream.asByteSource().openStream()) {
        MetacardType metacardType = metacardTypes.stream().findFirst().orElseThrow(() -> new CatalogTransformerException("no matching metacard type found! id = " + id));
        Metacard innerMetacard = innerTransformer.transform(inputStream, id);
        MetacardImpl metacard = new MetacardImpl(innerMetacard, metacardType);
        metacard.setContentTypeName(CONTENT_TYPE);
        return metacard;
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 13 with CatalogTransformerException

use of ddf.catalog.transform.CatalogTransformerException in project alliance by codice.

the class MpegTsInputTransformer method populateFileBackedOutputStream.

private void populateFileBackedOutputStream(InputStream inputStream, TemporaryFileBackedOutputStream fbos) throws CatalogTransformerException {
    try {
        int c = IOUtils.copy(inputStream, fbos);
        LOGGER.debug("copied {} bytes from input stream to file backed output stream", c);
    } catch (IOException e) {
        throw new CatalogTransformerException("Could not copy bytes of content message.", e);
    }
}
Also used : CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException)

Example 14 with CatalogTransformerException

use of ddf.catalog.transform.CatalogTransformerException in project alliance by codice.

the class MpegTsInputTransformer method extractStanag4609Metadata.

private void extractStanag4609Metadata(MetacardImpl metacard, TemporaryFileBackedOutputStream fbos) throws IOException, CatalogTransformerException {
    Stanag4609Parser stanag4609Parser = stanagParserFactory.createParser(fbos.asByteSource());
    Map<Integer, List<DecodedKLVMetadataPacket>> decodedMetadata;
    try {
        decodedMetadata = stanag4609Parser.parse();
    } catch (Stanag4609ParseException e) {
        throw new CatalogTransformerException("failed to extract STANAG 4609 metadata", e);
    }
    Map<String, KlvHandler> handlers = klvHandlerFactory.createStanag4609Handlers();
    stanag4609Processor.handle(handlers, defaultKlvHandler, decodedMetadata);
    KlvProcessor.Configuration klvProcessConfiguration = new KlvProcessor.Configuration();
    klvProcessConfiguration.set(KlvProcessor.Configuration.SUBSAMPLE_COUNT, subsampleCount);
    klvProcessConfiguration.getGeometryOperatorContext().setDistanceTolerance(distanceTolerance);
    klvProcessor.process(handlers, metacard, klvProcessConfiguration);
}
Also used : KlvHandler(org.codice.alliance.libs.klv.KlvHandler) Stanag4609Parser(org.codice.alliance.libs.klv.Stanag4609Parser) Stanag4609ParseException(org.codice.alliance.libs.klv.Stanag4609ParseException) List(java.util.List) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) KlvProcessor(org.codice.alliance.libs.klv.KlvProcessor) SecurityClassificationKlvProcessor(org.codice.alliance.libs.klv.SecurityClassificationKlvProcessor)

Example 15 with CatalogTransformerException

use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.

the class CatalogFrameworkImplTest method testQueryTransformWithTransformException.

@Test(expected = CatalogTransformerException.class)
public void testQueryTransformWithTransformException() throws Exception {
    BundleContext context = mock(BundleContext.class);
    QueryResponseTransformer transformer = mock(QueryResponseTransformer.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(SourceResponse.class), isA(Map.class))).thenThrow(new CatalogTransformerException("Could not transform"));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    SourceResponse response = new SourceResponseImpl(null, null);
    framework.transform(response, "NONE", new HashMap<String, Serializable>());
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) CatalogFramework(ddf.catalog.CatalogFramework) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)112 IOException (java.io.IOException)53 Metacard (ddf.catalog.data.Metacard)44 InputStream (java.io.InputStream)40 ByteArrayInputStream (java.io.ByteArrayInputStream)29 BinaryContent (ddf.catalog.data.BinaryContent)25 InputTransformer (ddf.catalog.transform.InputTransformer)21 Serializable (java.io.Serializable)21 HashMap (java.util.HashMap)21 Result (ddf.catalog.data.Result)16 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)15 TemporaryFileBackedOutputStream (org.codice.ddf.platform.util.TemporaryFileBackedOutputStream)14 ArrayList (java.util.ArrayList)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 Test (org.junit.Test)12 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)10 MimeType (javax.activation.MimeType)10 SourceResponse (ddf.catalog.operation.SourceResponse)9 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)8 List (java.util.List)8