Search in sources :

Example 1 with CloudFunctionConfiguration

use of com.amazonaws.services.s3.model.CloudFunctionConfiguration in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified notification configuration into an XML byte array.
 *
 * @param notificationConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketNotificationConfiguration notificationConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("NotificationConfiguration", "xmlns", Constants.XML_NAMESPACE);
    final Map<String, NotificationConfiguration> configurations = notificationConfiguration.getConfigurations();
    for (final Map.Entry<String, NotificationConfiguration> entry : configurations.entrySet()) {
        final String configName = entry.getKey();
        final NotificationConfiguration config = entry.getValue();
        if (config instanceof TopicConfiguration) {
            xml.start("TopicConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("Topic").value(((TopicConfiguration) config).getTopicARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof QueueConfiguration) {
            xml.start("QueueConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("Queue").value(((QueueConfiguration) config).getQueueARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof CloudFunctionConfiguration) {
            xml.start("CloudFunctionConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("InvocationRole").value(((CloudFunctionConfiguration) config).getInvocationRoleARN()).end();
            xml.start("CloudFunction").value(((CloudFunctionConfiguration) config).getCloudFunctionARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof LambdaConfiguration) {
            xml.start("CloudFunctionConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("CloudFunction").value(((LambdaConfiguration) config).getFunctionARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        }
    }
    xml.end();
    return xml.getBytes();
}
Also used : CloudFunctionConfiguration(com.amazonaws.services.s3.model.CloudFunctionConfiguration) QueueConfiguration(com.amazonaws.services.s3.model.QueueConfiguration) NotificationConfiguration(com.amazonaws.services.s3.model.NotificationConfiguration) BucketNotificationConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration) LambdaConfiguration(com.amazonaws.services.s3.model.LambdaConfiguration) TopicConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration.TopicConfiguration) Map(java.util.Map) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 2 with CloudFunctionConfiguration

use of com.amazonaws.services.s3.model.CloudFunctionConfiguration in project aws-sdk-android by aws-amplify.

the class BucketNotificationConfigurationStaxUnmarshallerTest method unmarshall_ValidCloudFunctionConfiguration.

/**
 * If CloudFunctionConfiguration has the InvocationRole attribute it should be unmarshalled into
 * a {@link CloudFunctionConfiguration}
 */
@Test
public void unmarshall_ValidCloudFunctionConfiguration() throws Exception {
    final BucketNotificationConfiguration config = unmarshaller.unmarshall(getResource(CLOUD_FUNCTION_INPUT));
    final CloudFunctionConfiguration cloudFunctionConfig = (CloudFunctionConfiguration) config.getConfigurationByName("CloudFunctionConfigId");
    assertEquals("some-cloud-function-arn", cloudFunctionConfig.getCloudFunctionARN());
    assertEquals("some-cloud-invoc-role", cloudFunctionConfig.getInvocationRoleARN());
    assertEventsUnmarshalledCorrectly(cloudFunctionConfig.getEvents());
    assertFilterRulesUnmarshalledCorrectly(cloudFunctionConfig.getFilter().getS3KeyFilter().getFilterRules());
}
Also used : CloudFunctionConfiguration(com.amazonaws.services.s3.model.CloudFunctionConfiguration) BucketNotificationConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration) Test(org.junit.Test)

Example 3 with CloudFunctionConfiguration

use of com.amazonaws.services.s3.model.CloudFunctionConfiguration in project aws-sdk-android by aws-amplify.

the class BucketNotificationConfigurationStaxUnmarshaller method unmarshall.

@Override
public BucketNotificationConfiguration unmarshall(InputStream inputStream) throws Exception {
    final XmlPullParser xpp = xmlPullParserFactory.newPullParser();
    xpp.setInput(inputStream, null);
    final StaxUnmarshallerContext context = new StaxUnmarshallerContext(xpp, null);
    final int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;
    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }
    final BucketNotificationConfiguration config = new BucketNotificationConfiguration();
    while (true) {
        final int xmlEvent = context.nextEvent();
        if (xmlEvent == XmlPullParser.END_DOCUMENT) {
            break;
        } else if (xmlEvent == XmlPullParser.START_TAG) {
            if (context.testExpression("TopicConfiguration", targetDepth)) {
                final Entry<String, NotificationConfiguration> entry = TopicConfigurationStaxUnmarshaller.getInstance().unmarshall(context);
                config.addConfiguration(entry.getKey(), entry.getValue());
            } else if (context.testExpression("QueueConfiguration", targetDepth)) {
                final Entry<String, NotificationConfiguration> entry = QueueConfigurationStaxUnmarshaller.getInstance().unmarshall(context);
                config.addConfiguration(entry.getKey(), entry.getValue());
            } else if (context.testExpression("CloudFunctionConfiguration", targetDepth)) {
                final Entry<String, NotificationConfiguration> entry = LambdaConfigurationStaxUnmarshaller.getInstance().unmarshall(context);
                config.addConfiguration(entry.getKey(), entry.getValue());
            }
        } else if (xmlEvent == XmlPullParser.END_TAG) {
            if (context.getCurrentDepth() < originalDepth) {
                return config;
            }
        }
    }
    return config;
}
Also used : Entry(java.util.Map.Entry) StaxUnmarshallerContext(com.amazonaws.transform.StaxUnmarshallerContext) XmlPullParser(org.xmlpull.v1.XmlPullParser) NotificationConfiguration(com.amazonaws.services.s3.model.NotificationConfiguration) BucketNotificationConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration) BucketNotificationConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration)

Aggregations

BucketNotificationConfiguration (com.amazonaws.services.s3.model.BucketNotificationConfiguration)3 CloudFunctionConfiguration (com.amazonaws.services.s3.model.CloudFunctionConfiguration)2 NotificationConfiguration (com.amazonaws.services.s3.model.NotificationConfiguration)2 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)1 TopicConfiguration (com.amazonaws.services.s3.model.BucketNotificationConfiguration.TopicConfiguration)1 LambdaConfiguration (com.amazonaws.services.s3.model.LambdaConfiguration)1 QueueConfiguration (com.amazonaws.services.s3.model.QueueConfiguration)1 StaxUnmarshallerContext (com.amazonaws.transform.StaxUnmarshallerContext)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Test (org.junit.Test)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1