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