use of ddf.catalog.operation.CreateResponse in project alliance by codice.
the class CatalogRolloverAction method doAction.
@Override
public MetacardImpl doAction(MetacardImpl metacard, File tempFile) throws RolloverActionException {
return context.modifyParentOrChild(isParentDirty -> {
Subject subject = context.getUdpStreamProcessor().getSubject();
if (subject == null) {
LOGGER.debug("no security subject available, cannot upload video chunk");
return metacard;
}
return subject.execute(() -> {
String fileName = generateFilename();
enforceRequiredMetacardFields(metacard, fileName);
ContentItem contentItem = createContentItem(metacard, fileName, Files.asByteSource(tempFile));
CreateStorageRequest createStorageRequest = createStorageRequest(contentItem);
CreateResponse createResponse = submitStorageCreateRequest(createStorageRequest);
for (Metacard childMetacard : createResponse.getCreatedMetacards()) {
LOGGER.trace("created catalog content with id={}", childMetacard.getId());
linkChildToParent(childMetacard);
updateParentWithChildMetadata(childMetacard);
}
isParentDirty.set(true);
return metacard;
});
});
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class CatalogComponentFrameworkTest method testCreateWithWrongTypeOperation.
@Test
public /**
* Operation: CREATE Body contains: Metacard
*/
void testCreateWithWrongTypeOperation() 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", new Boolean("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, 0);
mockVerifierEndpoint.assertIsSatisfied();
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class CatalogComponentFrameworkTest method testCreateWithListOfMetacards.
@Test
public /**
* Operation: CREATE Body contains: List<Metacard>
*/
void testCreateWithListOfMetacards() 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);
metacards.add(metacard2);
// 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", metacards, "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, 2);
mockVerifierEndpoint.assertIsSatisfied();
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class CatalogComponentFrameworkTest method testCreateWithSingleMetacard.
@Test
public /**
* Operation: CREATE Body contains: Metacard
*/
void testCreateWithSingleMetacard() 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();
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class FrameworkProducer method create.
/**
* Creates metacard(s) in the catalog using the Catalog Framework.
*
* @param exchange The {@link org.apache.camel.Exchange} can contain a {@link
* org.apache.camel.Message} with a body of type {@link java.util.List} of Metacard or a
* single Metacard.
* @throws ddf.catalog.source.SourceUnavailableException
* @throws ddf.catalog.source.IngestException
* @throws ddf.camel.component.catalog.framework.FrameworkProducerException
*/
private void create(final Exchange exchange) throws SourceUnavailableException, IngestException, FrameworkProducerException {
CreateResponse createResponse = null;
// read in data
final List<Metacard> metacardsToBeCreated = readBodyDataAsMetacards(exchange);
if (!validateList(metacardsToBeCreated, Metacard.class)) {
processCatalogResponse(createResponse, exchange);
throw new FrameworkProducerException("Validation of Metacard list failed");
}
LOGGER.debug("Validation of Metacard list passed...");
final CreateRequest createRequest = new CreateRequestImpl(metacardsToBeCreated);
int expectedNumberOfCreatedMetacards = metacardsToBeCreated.size();
if (expectedNumberOfCreatedMetacards < 1) {
LOGGER.debug("Empty list of Metacards...nothing to process");
processCatalogResponse(createResponse, exchange);
return;
}
LOGGER.debug("Making CREATE call to Catalog Framework...");
createResponse = catalogFramework.create(createRequest);
if (createResponse == null) {
LOGGER.debug("CreateResponse is null from catalog framework");
processCatalogResponse(createResponse, exchange);
return;
}
final List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
if (createdMetacards == null) {
LOGGER.debug("CreateResponse returned null metacards list");
processCatalogResponse(createResponse, exchange);
return;
}
final int numberOfCreatedMetacards = createdMetacards.size();
if (numberOfCreatedMetacards != expectedNumberOfCreatedMetacards) {
LOGGER.debug("Expected {} metacards created but only {} were successfully created", expectedNumberOfCreatedMetacards, numberOfCreatedMetacards);
processCatalogResponse(createResponse, exchange);
return;
}
LOGGER.debug("Created {} metacards", numberOfCreatedMetacards);
processCatalogResponse(createResponse, exchange);
}
Aggregations