Search in sources :

Example 26 with CreateResponse

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

the class CatalogFrameworkImplTest method testCreate.

// Start testing MetacardWriter
/**
 * Tests that the framework properly passes a create request to the local provider.
 */
@Test
public void testCreate() throws Exception {
    List<Metacard> metacards = new ArrayList<>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateResponse response = framework.create(new CreateRequestImpl(metacards, null));
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    for (Metacard curCard : response.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    // make sure that the event was posted correctly
    assertTrue(eventAdmin.wasEventPosted());
    Metacard[] array = {};
    array = response.getCreatedMetacards().toArray(array);
    assertTrue(eventAdmin.wasEventPosted());
    assertEquals(eventAdmin.getLastEvent(), array[array.length - 1]);
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 27 with CreateResponse

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

the class CatalogFrameworkImplTest method testCreateWithDefaultValues.

@Test
public void testCreateWithDefaultValues() throws IngestException, SourceUnavailableException {
    registerDefaults();
    final String title = "some title";
    final Date expiration = new Date();
    CreateRequest createRequest = new CreateRequestImpl(getMetacards(title, expiration));
    CreateResponse createResponse = framework.create(createRequest);
    verifyDefaults(createResponse.getCreatedMetacards(), title, expiration, DEFAULT_TITLE, DEFAULT_EXPIRATION, DEFAULT_TITLE_CUSTOM, DEFAULT_EXPIRATION_CUSTOM);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 28 with CreateResponse

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

the class RestReplicatorPlugin method process.

@Override
public CreateResponse process(CreateResponse input) throws PluginExecutionException {
    if (Requests.isLocal(input.getRequest()) && client != null && transformer != null) {
        for (Metacard m : input.getCreatedMetacards()) {
            String data = transform(m, client);
            Response r = client.post(data);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Posted the following GeoJSON: {}\n", data);
                LOGGER.debug(RESPONSE, ToStringBuilder.reflectionToString(r));
            }
        }
    }
    return input;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Response(javax.ws.rs.core.Response) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard)

Example 29 with CreateResponse

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

the class PluginTest method testCreateNullTransformer.

@Test
@Ignore
public void testCreateNullTransformer() throws PluginExecutionException, IngestException, SourceUnavailableException {
    // given
    plugin = new RestReplicatorPlugin(null);
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
    // then
    verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) RestReplicatorPlugin(ddf.catalog.federation.layered.replication.RestReplicatorPlugin) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UriInfo(javax.ws.rs.core.UriInfo) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with CreateResponse

use of ddf.catalog.operation.CreateResponse 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)

Aggregations

CreateResponse (ddf.catalog.operation.CreateResponse)111 Test (org.junit.Test)82 Metacard (ddf.catalog.data.Metacard)76 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)44 ArrayList (java.util.ArrayList)42 CreateRequest (ddf.catalog.operation.CreateRequest)36 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)29 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)27 HashMap (java.util.HashMap)25 Serializable (java.io.Serializable)23 List (java.util.List)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)22 DeleteResponse (ddf.catalog.operation.DeleteResponse)22 UpdateResponse (ddf.catalog.operation.UpdateResponse)21 Filter (org.opengis.filter.Filter)21 IngestException (ddf.catalog.source.IngestException)20 SourceResponse (ddf.catalog.operation.SourceResponse)18 QueryRequest (ddf.catalog.operation.QueryRequest)17 MetacardType (ddf.catalog.data.MetacardType)16