Search in sources :

Example 46 with CreateRequest

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

the class SecurityPluginTest method testMetacardPointOfContactNotOverridden.

@Test
public void testMetacardPointOfContactNotOverridden() {
    Subject mockSubject = setupMockSubject();
    ThreadContext.bind(mockSubject);
    MetacardImpl metacardWithPoc = new MetacardImpl();
    metacardWithPoc.setTags(Collections.emptySet());
    metacardWithPoc.setAttribute(new AttributeImpl(Metacard.POINT_OF_CONTACT, "originalPoc"));
    MetacardImpl metacardWithNoPoc = new MetacardImpl();
    metacardWithNoPoc.setTags(Collections.emptySet());
    CreateRequest request = new CreateRequestImpl(Arrays.asList(metacardWithPoc, metacardWithNoPoc));
    SecurityPlugin plugin = new SecurityPlugin(subjectIdentity);
    request = plugin.processPreCreate(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
    assertThat(request.getMetacards().size(), is(2));
    assertThat(request.getMetacards().get(0).getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo("originalPoc"));
    assertThat(request.getMetacards().get(1).getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(TEST_USER));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 47 with CreateRequest

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

the class SecurityPluginTest method testBadSubjectCase.

@Test
public void testBadSubjectCase() throws Exception {
    Subject mockSubject = mock(Subject.class);
    ThreadContext.bind(mockSubject);
    CreateRequest request = new MockCreateRequest();
    request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, new HashMap<>());
    SecurityPlugin plugin = new SecurityPlugin(subjectIdentity);
    request = plugin.processPreCreate(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 48 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 49 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 50 with CreateRequest

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

the class ReplicateCommandTest method testFailedtoIngestHalf.

@Test
public void testFailedtoIngestHalf() throws Exception {
    when(catalogFramework.create(isA(CreateRequest.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        CreateRequest request = (CreateRequest) args[0];
        when(mockCreateResponse.getCreatedMetacards()).thenReturn(request.getMetacards().subList(0, request.getMetacards().size() / 2));
        return mockCreateResponse;
    });
    replicateCommand.isUseTemporal = false;
    replicateCommand.sourceId = "sourceId1";
    replicateCommand.temporalProperty = Metacard.EFFECTIVE;
    replicateCommand.executeWithSubject();
    verifyReplicate(HITS, Metacard.EFFECTIVE, 2);
    verifyConsoleOutput((int) Math.floor(HITS / 2) + " record(s) replicated; " + (int) (HITS - Math.floor(HITS / 2)) + " record(s) failed;");
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)80 Test (org.junit.Test)62 Metacard (ddf.catalog.data.Metacard)44 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)39 CreateResponse (ddf.catalog.operation.CreateResponse)29 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 Subject (ddf.security.Subject)14 Serializable (java.io.Serializable)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)9 List (java.util.List)9 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Map (java.util.Map)5 CatalogFramework (ddf.catalog.CatalogFramework)4