Search in sources :

Example 61 with BinaryContent

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

the class CswQueryResponseTransformer method transform.

@Override
public BinaryContent transform(SourceResponse sourceResponse, Map<String, Serializable> arguments) throws CatalogTransformerException {
    validateInput(sourceResponse, arguments);
    CswRecordCollection recordCollection = buildCollection(sourceResponse, arguments);
    ByteArrayInputStream bais;
    if (ResultType.VALIDATE.equals(recordCollection.getResultType())) {
        ByteArrayOutputStream baos = writeAcknowledgement(recordCollection.getRequest());
        bais = new ByteArrayInputStream(baos.toByteArray());
    } else {
        // "catches" recordCollection.getResultType() == null
        List<Result> results = sourceResponse.getResults();
        String xmlString = convert(recordCollection, results, arguments);
        bais = new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8));
    }
    BinaryContent transformedContent = new BinaryContentImpl(bais, CswRecordConverter.XML_MIME_TYPE);
    return transformedContent;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result)

Example 62 with BinaryContent

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

the class TestCswRecordConverter method testMetacardTransformOmitXmlDeclaration.

@Test
public void testMetacardTransformOmitXmlDeclaration() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
    Metacard metacard = getTestMetacard();
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.WRITE_NAMESPACES, true);
    args.put(CswConstants.OMIT_XML_DECLARATION, true);
    BinaryContent content = converter.transform(metacard, args);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml, not(containsString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")));
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(getControlRecord(), xml);
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 63 with BinaryContent

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

the class TestCswRecordConverter method testMetacardTransformOmitNamespaces.

@Test
public void testMetacardTransformOmitNamespaces() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
    Metacard metacard = getTestMetacard();
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.WRITE_NAMESPACES, false);
    BinaryContent content = converter.transform(metacard, args);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml, containsString("<csw:Record>"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 64 with BinaryContent

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

the class MetacardBackupPluginTest method testGetContentBytes.

@Test
public void testGetContentBytes() throws Exception {
    BinaryContent binaryContent = mock(BinaryContent.class);
    byte[] content = { 'a' };
    when(binaryContent.getByteArray()).thenReturn(content);
    byte[] bytes = metacardBackupPlugin.getContentBytes(binaryContent, "metacard");
    assertThat(bytes, equalTo(content));
}
Also used : BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 65 with BinaryContent

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

the class MetacardBackupPluginTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    metacardTransformer = mock(MetacardTransformer.class);
    BinaryContent binaryContent = new BinaryContentImpl(new ByteArrayInputStream(XML_METADATA.getBytes(StandardCharsets.UTF_8)));
    when(metacardTransformer.transform(any(Metacard.class), anyMap())).thenReturn(binaryContent);
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).store(any(), any());
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).delete(any());
    doReturn(MOCK_ID).when(mockProvider).getId();
    metacardBackupPlugin = new MetacardBackupPlugin();
    metacardBackupPlugin.setMetacardTransformerId(METACARD_TRANSFORMER_ID);
    metacardBackupPlugin.setMetacardTransformer(metacardTransformer);
    createRequest = generateProcessRequest(ProcessCreateItem.class, true);
    updateRequest = generateProcessRequest(ProcessUpdateItem.class, true);
    deleteRequest = generateDeleteRequest();
    fileStorageProvider.setId(FILE_STORAGE_PROVIDER_ID);
    fileStorageProvider.setOutputDirectory(OUTPUT_DIRECTORY);
    metacardBackupPlugin.setMetacardOutputProviderIds(Collections.singletonList(FILE_STORAGE_PROVIDER_ID));
    metacardBackupPlugin.setStorageBackupPlugins(Arrays.asList(new MetacardBackupStorageProvider[] { fileStorageProvider }));
}
Also used : MetacardBackupException(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException) Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessCreateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) MetacardBackupStorageProvider(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider) BinaryContent(ddf.catalog.data.BinaryContent) ProcessUpdateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem) Before(org.junit.Before)

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