Github user mfranklin commented on a diff in the pull request:
https://github.com/apache/incubator-streams/pull/63#discussion_r15891276
--- Diff:
streams-contrib/streams-persist-elasticsearch/src/main/java/org/apache/streams/elasticsearch/ElasticsearchPersistDeleter.java
---
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.streams.elasticsearch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import org.apache.streams.core.StreamsDatum;
+import org.apache.streams.core.StreamsPersistWriter;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ElasticsearchPersistDeleter extends
ElasticsearchPersistWriter implements StreamsPersistWriter {
+
+ private final static Logger LOGGER =
LoggerFactory.getLogger(ElasticsearchPersistDeleter.class);
+
+ public ElasticsearchPersistDeleter() {
+ super();
+ }
+
+ public ElasticsearchPersistDeleter(ElasticsearchWriterConfiguration
config) {
+ super(config);
+ }
+
+ @Override
+ public void write(StreamsDatum streamsDatum) {
+
+ Preconditions.checkNotNull(streamsDatum);
+ Preconditions.checkNotNull(streamsDatum.getDocument());
+ Preconditions.checkNotNull(streamsDatum.getMetadata());
+ Preconditions.checkNotNull(streamsDatum.getMetadata().get("id"));
+
+ String index;
+ String type;
+ String id;
+
+ index = Optional.fromNullable(
+ (String) streamsDatum.getMetadata().get("index"))
+ .or(config.getIndex());
+ type = Optional.fromNullable(
+ (String) streamsDatum.getMetadata().get("type"))
+ .or(config.getType());
+ id = (String) streamsDatum.getMetadata().get("id");
+
+ delete(index, type, id);
+
+ }
+
+ public void delete(String index, String type, String id) {
+ DeleteRequest deleteRequest;
+
+ Preconditions.checkNotNull(index);
+ Preconditions.checkNotNull(id);
+ Preconditions.checkNotNull(type);
+
+ // They didn't specify an ID, so we will create one for them.
+ deleteRequest = new DeleteRequest()
+ .index(index)
+ .type(type)
+ .id(id);
+
+ add(deleteRequest);
+
+ }
+
+ public void add(DeleteRequest request) {
--- End diff --
That would probably be a good change to propose, but what I was driving at
here is the same logic is copied across 3 implementations. If there is a
common base type, then we can just call a single method that holds all the
logic for adding the request to the bulk, checking indices, etc.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---