org.apache.camel.component.aws.ddb.DdbOperations Java Examples

The following examples show how to use org.apache.camel.component.aws.ddb.DdbOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DDBConnectorCustomizerQuery.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
protected void customize(Exchange exchange, Map<String, Object> options) {
    Map<String, AttributeValue> element = Util.getAttributeValueMap("element", options);
    exchange.getIn().setHeader(DdbConstants.KEY, element);
    exchange.getIn().setHeader(DdbConstants.OPERATION, DdbOperations.GetItem);

    List<String> attributes = new ArrayList<String>();
    String optionAttributes = ConnectorOptions.extractOption(options, "attributes", "");
    if (!optionAttributes.isEmpty()) {
        Splitter splitter = Splitter.on(',');
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        attributes = splitter.splitToList(optionAttributes);
    }


    //fallback to use the list of attributes on the filter
    if (attributes.isEmpty()) {
        attributes.addAll(element.keySet());
    }

    exchange.getIn().setHeader(DdbConstants.ATTRIBUTE_NAMES, attributes);
    LOG.trace("Attributes: " + attributes);

}
 
Example #2
Source File: DDBConnectorCustomizer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Extract results and place them on the body.
 */
@SuppressWarnings("unchecked")
protected void doAfterProducer(Exchange exchange) {
    final Message in = exchange.getIn();
    Map<String, AttributeValue> attributes = (Map<String, AttributeValue>) in.getHeader(DdbConstants.ATTRIBUTES);
    String op = in.getHeader(DdbConstants.OPERATION).toString();

    if (op.equals(DdbOperations.PutItem.name())) {
        //Use input. If we are here, we know it went well (or so DDB says)
        //But attributes may be empty due to caching issues (DDB side)
        Map<String, AttributeValue> items =
            (Map<String, AttributeValue>) exchange.getIn().getHeader(DdbConstants.ITEM);
        in.setBody(mapToJSON(items));
    } else if (attributes != null) {
        in.setBody(mapToJSON(attributes));
    } else  {
        //Something went wrong, we always return something
        throw new IllegalArgumentException("DynamoDB operation failed: " + in.getHeaders());
    }
}
 
Example #3
Source File: AWSDDBLocalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void putItemCustomizer() {
    DDBConnectorCustomizerPutItem customizer = new DDBConnectorCustomizerPutItem();

    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    customizer.doBeforeProducer(exchange);

    assertEquals("true", exchange.getIn().getHeader(DdbConstants.CONSISTENT_READ));
    assertEquals("ALL_OLD", exchange.getIn().getHeader(DdbConstants.RETURN_VALUES));
    assertEquals(DdbOperations.PutItem, exchange.getIn().getHeader(DdbConstants.OPERATION));
}
 
Example #4
Source File: AWSDDBLocalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void queryCustomizer() {
    DDBConnectorCustomizerQuery customizer = new DDBConnectorCustomizerQuery();

    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    customizer.doBeforeProducer(exchange);

    assertEquals("true", exchange.getIn().getHeader(DdbConstants.CONSISTENT_READ));
    assertEquals("ALL_OLD", exchange.getIn().getHeader(DdbConstants.RETURN_VALUES));
    assertEquals(DdbOperations.GetItem, exchange.getIn().getHeader(DdbConstants.OPERATION));
}
 
Example #5
Source File: DynamoDBUtils.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static Map<?, ?> getItem(CamelContext camelctx) {
    HashMap<String, AttributeValue> key = new HashMap<>();
    key.put("Id", new AttributeValue().withN("103"));

    Exchange exchange = new ExchangeBuilder(camelctx)
            .withHeader(DdbConstants.OPERATION, DdbOperations.GetItem)
            .withHeader(DdbConstants.KEY, key).build();

    ProducerTemplate producer = camelctx.createProducerTemplate();
    producer.send("direct:start", exchange);
    Assert.assertNull(exchange.getException());

    return exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class);
}
 
Example #6
Source File: DdbComponentConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
public DdbOperations getOperation() {
    return operation;
}
 
Example #7
Source File: DdbComponentConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
public void setOperation(DdbOperations operation) {
    this.operation = operation;
}
 
Example #8
Source File: DDBConnectorCustomizerRemoveItem.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected void customize(Exchange exchange, Map<String, Object> options) {
    exchange.getIn().setHeader(DdbConstants.KEY, Util.getAttributeValueMap("element", options));
    exchange.getIn().setHeader(DdbConstants.OPERATION, DdbOperations.DeleteItem);
}
 
Example #9
Source File: DDBConnectorCustomizerPutItem.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected void customize(Exchange exchange, Map<String, Object> options) {
    exchange.getIn().setHeader(DdbConstants.ITEM, Util.getAttributeValueMap("element", options));
    exchange.getIn().setHeader(DdbConstants.OPERATION, DdbOperations.PutItem);
}