Search in sources :

Example 31 with CreateRequest

use of ddf.catalog.operation.CreateRequest 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 32 with CreateRequest

use of ddf.catalog.operation.CreateRequest 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 33 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class CatalogComponentFrameworkTest method testCreateWithDifferentCaseOperation.

@Test
public /**
     * Operation: CREATE
     * Body contains:  Metacard
     */
void testCreateWithDifferentCaseOperation() throws Exception {
    resetMocks();
    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);
    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);
    // Mock catalog framework
    final CreateRequest createRequest = new CreateRequestImpl(metacards);
    final CreateResponse createResponse = new CreateResponseImpl(createRequest, new HashMap(), metacards);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    // Exercise the route with a CREATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "create");
    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Metacard> cardsCreated = (List<Metacard>) exchange.getIn().getBody();
    assertListSize(cardsCreated, 1);
    mockVerifierEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Metacard(ddf.catalog.data.Metacard) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ArrayList(java.util.ArrayList) List(java.util.List) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 34 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class CatalogComponentFrameworkTest method testCreateWithInvalidOperation.

@Test
public /**
     * Operation: CREATE
     * Body contains:  Metacard
     */
void testCreateWithInvalidOperation() throws Exception {
    resetMocks();
    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);
    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);
    // Mock catalog framework
    final CreateRequest createRequest = new CreateRequestImpl(metacards);
    final CreateResponse createResponse = new CreateResponseImpl(createRequest, new HashMap(), metacards);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    // Exercise the route with a CREATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "WRONG OPERATION");
    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Metacard> cardsCreated = (List<Metacard>) exchange.getIn().getBody();
    assertListSize(cardsCreated, 0);
    mockVerifierEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Metacard(ddf.catalog.data.Metacard) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ArrayList(java.util.ArrayList) List(java.util.List) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 35 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class ReplicateCommandTest method setUp.

@Before
public void setUp() throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    catalogFramework = mock(CatalogFramework.class);
    replicateCommand = new ReplicateCommand() {

        @Override
        public String getInput(String message) throws IOException {
            return "sourceId1";
        }
    };
    replicateCommand.catalogFramework = catalogFramework;
    replicateCommand.filterBuilder = new GeotoolsFilterBuilder();
    when(mockSession.getKeyboard()).thenReturn(mockIS);
    when(catalogFramework.getSourceIds()).thenReturn(SOURCE_IDS);
    when(catalogFramework.query(isA(QueryRequest.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        QueryRequest request = (QueryRequest) args[0];
        QueryResponse mockQueryResponse = mock(QueryResponse.class);
        when(mockQueryResponse.getHits()).thenReturn(Long.valueOf(HITS));
        when(mockQueryResponse.getResults()).thenReturn(getResultList(Math.min(replicateCommand.batchSize, HITS - request.getQuery().getStartIndex() + 1)));
        return mockQueryResponse;
    });
    when(catalogFramework.create(isA(CreateRequest.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        CreateRequest request = (CreateRequest) args[0];
        when(mockCreateResponse.getCreatedMetacards()).thenReturn(request.getMetacards());
        return mockCreateResponse;
    });
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CreateRequest(ddf.catalog.operation.CreateRequest) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)63 Test (org.junit.Test)49 Metacard (ddf.catalog.data.Metacard)38 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)36 CreateResponse (ddf.catalog.operation.CreateResponse)26 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)12 Subject (ddf.security.Subject)12 Serializable (java.io.Serializable)10 IngestException (ddf.catalog.source.IngestException)9 List (java.util.List)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 CatalogFramework (ddf.catalog.CatalogFramework)4 QueryRequest (ddf.catalog.operation.QueryRequest)4