Search in sources :

Example 16 with Metacard

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

the class CatalogBackupPluginTest method testUpdateResponseUpdateSuccessful.

@Test
public void testUpdateResponseUpdateSuccessful() throws Exception {
    // Setup
    int subDirLevels = 3;
    CatalogBackupPlugin plugin = getPlugin(3);
    plugin.process(getCreateResponse(METACARD_IDS));
    UpdateResponse mockUpdateResponse = getUpdateResponse(Arrays.asList(METACARD_IDS));
    // Perform Test
    UpdateResponse postPluginUpdateResponse = plugin.process(mockUpdateResponse);
    // Verify
    assertThat(postPluginUpdateResponse, is(notNullValue()));
    IntStream.range(0, METACARD_IDS.length).forEach(index -> {
        String oldId = METACARD_IDS[index];
        File updatedFile = getFileFor(oldId, subDirLevels);
        Metacard updatedCard = readMetacard(updatedFile);
        assertThat(updatedFile.exists(), is(Boolean.TRUE));
        assertThat(updatedCard.getId(), is(oldId));
        assertThat(updatedCard.getAttribute(Metacard.TITLE).getValue(), is(BASE_NEW_TITLE + index));
    });
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) File(java.io.File) Test(org.junit.Test)

Example 17 with Metacard

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

the class RequiredAttributesMetacardValidatorTest method testValidMetacard.

@Test
public void testValidMetacard() {
    final Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl("title", "test"));
    metacard.setAttribute(new AttributeImpl("created", new Date()));
    metacard.setAttribute(new AttributeImpl("thumbnail", new byte[] { 1, 2, 3, 4 }));
    validateNoErrors(metacard, Sets.newHashSet("title", "created", "thumbnail"));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Metacard

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

the class DuplicateCommands method ingestMetacards.

protected List<Metacard> ingestMetacards(CatalogFacade provider, List<Metacard> metacards) {
    if (metacards.isEmpty()) {
        return Collections.emptyList();
    }
    List<Metacard> createdMetacards = new ArrayList<>();
    LOGGER.debug("Preparing to ingest {} records", metacards.size());
    CreateRequest createRequest = new CreateRequestImpl(metacards);
    CreateResponse createResponse;
    try {
        createResponse = provider.create(createRequest);
        createdMetacards = createResponse.getCreatedMetacards();
    } catch (IngestException e) {
        printErrorMessage(String.format("Received error while ingesting: %s%n", e.getMessage()));
        LOGGER.debug("Error during ingest. Attempting to ingest batch individually.");
        return ingestSingly(provider, metacards);
    } catch (SourceUnavailableException e) {
        printErrorMessage(String.format("Received error while ingesting: %s%n", e.getMessage()));
        LOGGER.debug("Error during ingest:", e);
        return createdMetacards;
    } catch (Exception e) {
        printErrorMessage(String.format("Unexpected Exception received while ingesting: %s%n", e.getMessage()));
        LOGGER.debug("Unexpected Exception during ingest:", e);
        return createdMetacards;
    }
    ingestedCount.addAndGet(createdMetacards.size());
    failedCount.addAndGet(metacards.size() - createdMetacards.size());
    failedMetacards.addAll(subtract(metacards, createdMetacards));
    return createdMetacards;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException)

Example 19 with Metacard

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

the class DuplicateCommands method ingestSingly.

private List<Metacard> ingestSingly(CatalogFacade provider, List<Metacard> metacards) {
    if (metacards.isEmpty()) {
        return Collections.emptyList();
    }
    List<Metacard> createdMetacards = new ArrayList<>();
    LOGGER.debug("Preparing to ingest {} records one at time.", metacards.size());
    for (Metacard metacard : metacards) {
        CreateRequest createRequest = new CreateRequestImpl(Arrays.asList(metacard));
        CreateResponse createResponse;
        try {
            createResponse = provider.create(createRequest);
            createdMetacards.addAll(createResponse.getCreatedMetacards());
        } catch (IngestException | SourceUnavailableException e) {
            LOGGER.debug("Error during ingest:", e);
        } catch (Exception e) {
            LOGGER.debug("Unexpected Exception during ingest:", e);
        }
    }
    return createdMetacards;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException)

Example 20 with Metacard

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

the class CatalogComponentTest method getMockInputTransformer.

/**
     * Mock an InputTransformer, returning a canned Metacard when the transform() method is invoked
     * on the InputTransformer.
     *
     * @return
     */
protected InputTransformer getMockInputTransformer() {
    InputTransformer inputTransformer = mock(InputTransformer.class);
    Metacard generatedMetacard = getSimpleMetacard();
    try {
        when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
        when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
    } catch (IOException e) {
        LOGGER.debug("IOException", e);
    } catch (CatalogTransformerException e) {
        LOGGER.debug("CatalogTransformerException", e);
    }
    return inputTransformer;
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65