Search in sources :

Example 21 with BinaryContent

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

the class TestCswRecordConverter method testMarshalEmptyInput.

@Test
public void testMarshalEmptyInput() throws CatalogTransformerException {
    Metacard expectedMetacard = getTestMetacard();
    BinaryContent bc = converter.transform(expectedMetacard, new HashMap<>());
    assertThat(bc, notNullValue());
}
Also used : Metacard(ddf.catalog.data.Metacard) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 22 with BinaryContent

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

the class TestPlugin method setup.

@Before
public void setup() {
    // given
    plugin = new RestReplicatorPlugin(ENDPOINT_ADDRESS);
    transformer = mock(MetacardTransformer.class);
    BinaryContent bc = mock(BinaryContent.class);
    byte[] bytes = { 86 };
    try {
        when(bc.getByteArray()).thenReturn(bytes);
        when(transformer.transform(isA(Metacard.class), isA(Map.class))).thenReturn(bc);
    } catch (Exception e) {
        Assert.fail(e.getLocalizedMessage());
    }
    plugin.setTransformer(transformer);
    metacard = getMockMetacard();
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) RestReplicatorPlugin(ddf.catalog.federation.layered.replication.RestReplicatorPlugin) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Before(org.junit.Before)

Example 23 with BinaryContent

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

the class MetacardBackupPlugin method processRequest.

private void processRequest(ProcessRequest<? extends ProcessResourceItem> processRequest) throws PluginExecutionException {
    if (CollectionUtils.isEmpty(storageBackupPlugins)) {
        throw new PluginExecutionException("Unable to backup ingested metacard; no metacard backup storage provider configured.");
    }
    if (metacardTransformer == null) {
        throw new PluginExecutionException("Unable to backup ingested metacard; no Metacard Transformer found.");
    }
    List<? extends ProcessResourceItem> processResourceItems = processRequest.getProcessItems();
    for (ProcessResourceItem processResourceItem : processResourceItems) {
        Metacard metacard = processResourceItem.getMetacard();
        if (shouldBackupMetacard(metacard)) {
            try {
                LOGGER.trace("Backing up metacard : {}", metacard.getId());
                BinaryContent binaryContent = metacardTransformer.transform(metacard, Collections.emptyMap());
                backupData(binaryContent, metacard.getId());
            } catch (CatalogTransformerException e) {
                LOGGER.debug("Unable to transform metacard with id {}.", metacard.getId(), e);
                throw new PluginExecutionException(String.format("Unable to transform metacard with id %s.", metacard.getId()));
            }
        }
    }
}
Also used : ProcessResourceItem(org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem) Metacard(ddf.catalog.data.Metacard) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BinaryContent(ddf.catalog.data.BinaryContent) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 24 with BinaryContent

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

the class MetacardBackupPluginTest method testGetContentBytesNoContentBytes.

@Test(expected = PluginExecutionException.class)
public void testGetContentBytesNoContentBytes() throws Exception {
    BinaryContent binaryContent = mock(BinaryContent.class);
    when(binaryContent.getByteArray()).thenReturn(null);
    metacardBackupPlugin.getContentBytes(binaryContent, "metacard");
}
Also used : BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 25 with BinaryContent

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

the class MetacardBackupPluginTest method testCreateRequestWithNullContentInputStream.

@Test(expected = PluginExecutionException.class)
public void testCreateRequestWithNullContentInputStream() throws Exception {
    BinaryContent binaryContent = mock(BinaryContent.class);
    when(binaryContent.getInputStream()).thenReturn(null);
    when(metacardTransformer.transform(any(Metacard.class), anyMap())).thenReturn(binaryContent);
    metacardBackupPlugin.processCreate(createRequest);
}
Also used : Metacard(ddf.catalog.data.Metacard) BinaryContent(ddf.catalog.data.BinaryContent) 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