Commits

Dirk Strauss committed f8174da

TV-6: add basic impl
Signed-off-by: dstrauss <dstrauss@ds-2.de>

Comments (0)

Files changed (8)

search-elasticsearch/pom.xml

       <artifactId>taskerville-api</artifactId>
       <version>0.0.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.weld.se</groupId>
+      <artifactId>weld-se-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+    </dependency>
   </dependencies>
 </project>

search-elasticsearch/src/main/java/ds2/taskerville/search/es/ElasticSearchProducer.java

  */
 package ds2.taskerville.search.es;
 
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Alternative;
 import javax.enterprise.inject.Produces;
 
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.node.Node;
 
 /**
 public class ElasticSearchProducer {
     
     /**
-     * 
+     * Inits the bean.
      */
     public ElasticSearchProducer() {
         // TODO Auto-generated constructor stub
      */
     @Produces
     @Alternative
+    @ApplicationScoped
     public Node createLiveNode() {
+        Settings s;
         Node rc = null;
         return rc;
     }

search-elasticsearch/src/main/java/ds2/taskerville/search/es/ElasticSearchServiceImpl.java

 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.node.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import ds2.taskerville.api.PersistableObject;
 import ds2.taskerville.api.search.SearchConfig;
 import ds2.taskerville.api.svc.SearchService;
 
 /**
- * @author kaeto23
+ * The ElasticSearch implementation.
  * 
+ * @author dstrauss
+ * @version 0.1
  */
 @ApplicationScoped
 public class ElasticSearchServiceImpl implements SearchService {
     /**
+     * A logger.
+     */
+    private static final Logger LOG = LoggerFactory
+        .getLogger(ElasticSearchServiceImpl.class);
+    /**
      * The ES client.
      */
     private Client client;
     }
     
     /**
-     * 
+     * Inits the impl.
      */
     public ElasticSearchServiceImpl() {
-        // TODO Auto-generated constructor stub
+        // nothing special to do
     }
     
     @Override
     public void indexOrUpdate(final PersistableObject i) {
-        String itemName = guessNameFromPersistable(i);
-        String itemIndex = "" + i.getId();
-        IndexRequestBuilder resp =
+        final String itemName = guessNameFromPersistable(i);
+        final String itemIndex = "" + i.getId();
+        final IndexRequestBuilder resp =
             client.prepareIndex(config.getIndexName(), itemName, itemIndex);
         try {
             resp.setSource(
                 XContentFactory.jsonBuilder().startObject()
                     .field("id", i.getId()).endObject()).execute().actionGet();
-        } catch (ElasticSearchException | IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+        } catch (final ElasticSearchException | IOException e) {
+            LOG.info("Error when indexing a given object!", e);
         }
     }
     

search-elasticsearch/src/main/java/ds2/taskerville/search/es/LiveSearchConfig.java

+/**
+ * 
+ */
+package ds2.taskerville.search.es;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+
+import ds2.taskerville.api.search.SearchConfig;
+
+/**
+ * The live config.
+ * 
+ * @author dstrauss
+ * @version 0.1
+ */
+@ApplicationScoped
+@Alternative
+public class LiveSearchConfig implements SearchConfig {
+    
+    /**
+     * Inits the config.
+     */
+    public LiveSearchConfig() {
+        // TODO Auto-generated constructor stub
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.search.SearchConfig#getIndexName()
+     */
+    @Override
+    public String getIndexName() {
+        return "taskerville-live";
+    }
+    
+}

search-elasticsearch/src/main/resources/META-INF/beans.xml

-<!--
-
-    TaskerVille - issue and project management
-    Copyright (C) 2012  Dirk Strauss
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Lesser General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
--->
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>

search-elasticsearch/src/test/java/ds2/taskerville/search/es/CommentDto.java

+/**
+ * 
+ */
+package ds2.taskerville.search.es;
+
+import java.util.Date;
+
+import ds2.taskerville.api.Comment;
+import ds2.taskerville.api.ContentType;
+import ds2.taskerville.api.EntryStates;
+import ds2.taskerville.api.user.User;
+
+/**
+ * @author kaeto23
+ * 
+ */
+public class CommentDto implements Comment {
+    
+    /**
+     * The svuid.
+     */
+    private static final long serialVersionUID = -6257309322377261936L;
+    /**
+     * The entry state.
+     */
+    private EntryStates entryState;
+    /**
+     * The id of the comment.
+     */
+    private long id;
+    /**
+     * The creation date.
+     */
+    private Date created;
+    /**
+     * The deletion date.
+     */
+    private Date deleted;
+    /**
+     * The modification date.
+     */
+    private Date modified;
+    /**
+     * The comment.
+     */
+    private String comment;
+    /**
+     * The content type of the comment.
+     */
+    private ContentType contentType;
+    /**
+     * The editor.
+     */
+    private User editor;
+    /**
+     * The original author.
+     */
+    private User author;
+    
+    /**
+     * 
+     */
+    public CommentDto() {
+        // TODO Auto-generated constructor stub
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.StateAware#getEntryState()
+     */
+    @Override
+    public EntryStates getEntryState() {
+        return entryState;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see
+     * ds2.taskerville.api.StateAware#setEntryState(ds2.taskerville.api.EntryStates
+     * )
+     */
+    @Override
+    public void setEntryState(final EntryStates s) {
+        entryState = s;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.PersistableObject#getId()
+     */
+    @Override
+    public long getId() {
+        return id;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.TimeAware#getCreated()
+     */
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.TimeAware#getDeleted()
+     */
+    @Override
+    public Date getDeleted() {
+        return deleted;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.TimeAware#getModified()
+     */
+    @Override
+    public Date getModified() {
+        return modified;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.TimeAware#setDeleted(java.util.Date)
+     */
+    @Override
+    public void setDeleted(final Date d) {
+        deleted = d;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.TimeAware#touchModified()
+     */
+    @Override
+    public void touchModified() {
+        modified = new Date();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    @Override
+    public int compareTo(final Comment o) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.Comment#getAuthor()
+     */
+    @Override
+    public User getAuthor() {
+        return author;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.Comment#getComment()
+     */
+    @Override
+    public String getComment() {
+        return comment;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.Comment#getContentType()
+     */
+    @Override
+    public ContentType getContentType() {
+        return contentType;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see ds2.taskerville.api.Comment#getEditor()
+     */
+    @Override
+    public User getEditor() {
+        return editor;
+    }
+    
+    /**
+     * Sets the id of the comment.
+     * 
+     * @param id
+     *            the id
+     */
+    public void setId(final long id) {
+        this.id = id;
+    }
+    
+    /**
+     * Sets the creation date.
+     * 
+     * @param created
+     *            the creation date
+     */
+    public void setCreated(final Date created) {
+        this.created = created;
+    }
+    
+    /**
+     * Sets the modification date.
+     * 
+     * @param modified
+     *            the modification date
+     */
+    public void setModified(final Date modified) {
+        this.modified = modified;
+    }
+    
+    /**
+     * Sets the comment.
+     * 
+     * @param comment
+     *            the comment content
+     */
+    public void setComment(final String comment) {
+        this.comment = comment;
+    }
+    
+    /**
+     * Sets the content type of the comment.
+     * 
+     * @param contentType
+     *            the content type
+     */
+    public void setContentType(final ContentType contentType) {
+        this.contentType = contentType;
+    }
+    
+    /**
+     * Sets the editor.
+     * 
+     * @param editor
+     *            the editor
+     */
+    public void setEditor(final User editor) {
+        this.editor = editor;
+    }
+    
+    /**
+     * Sets the author.
+     * 
+     * @param author
+     *            the author
+     */
+    public void setAuthor(final User author) {
+        this.author = author;
+    }
+    
+}

search-elasticsearch/src/test/java/ds2/taskerville/search/es/ElasticSearchImplTest.java

+/**
+ * 
+ */
+package ds2.taskerville.search.es;
+
+import org.jboss.weld.environment.se.Weld;
+import org.jboss.weld.environment.se.WeldContainer;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import ds2.taskerville.api.ContentType;
+import ds2.taskerville.api.svc.SearchService;
+
+/**
+ * Testcase for the indexer.
+ * 
+ * @author dstrauss
+ * @version 0.1
+ */
+@Test(singleThreaded = true)
+public class ElasticSearchImplTest {
+    /**
+     * The service to test.
+     */
+    private SearchService to;
+    /**
+     * Weld.
+     */
+    private Weld weld;
+    /**
+     * The injection container of weld.
+     */
+    private WeldContainer wc;
+    
+    /**
+     * 
+     */
+    public ElasticSearchImplTest() {
+        // nothing to do
+    }
+    
+    /**
+     * Actions to perform at class start.
+     */
+    @BeforeClass
+    public void onClassStart() {
+        weld = new Weld();
+        wc = weld.initialize();
+        to = wc.instance().select(SearchService.class).get();
+    }
+    
+    /**
+     * Simple index test.
+     */
+    @Test
+    public void testIndex() {
+        CommentDto c = new CommentDto();
+        c.setComment("Das ist ein Test.");
+        c.setContentType(ContentType.Text);
+        to.indexOrUpdate(c);
+    }
+    
+    /**
+     * Actions to perform at class end.
+     */
+    @AfterClass
+    public void onClassEnd() {
+        weld.shutdown();
+    }
+    
+}

search-elasticsearch/src/test/resources/META-INF/beans.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>