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));
}
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));
}
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;
}
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;
}
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;");
}
Aggregations