1. Juan Carlos Picado Herrera
  2. encuestame

Commits

Paola Morales  committed 0874ad2 Merge

Merge branch 'development' into release

  • Participants
  • Parent commits fc40227, 4e57d86
  • Branches master
  • Tags v1.1.34

Comments (0)

Files changed (248)

File encuestame-business/pom.xml

View file
  • Ignore whitespace
     <parent>
         <groupId>org.encuestame</groupId>
         <artifactId>encuestame</artifactId>
-        <version>1.1.34-SNAPSHOT</version>
+        <version>1.1.35-SNAPSHOT</version>
     </parent>
     <artifactId>encuestame-business</artifactId>
     <packaging>jar</packaging>

File encuestame-business/src/main/java/org/encuestame/business/config/EncuestamePlaceHolderConfigurer.java

View file
  • Ignore whitespace
     public static String getProperty(final String name) {
         return propertiesMap.get(name);
     }
+
+    /**
+     * Get boolean property.
+     * @param property
+     * @return
+     */
+    public static Boolean getBooleanProperty(final String property){
+        String value = EncuestamePlaceHolderConfigurer.getProperty(property);
+        if(value == null){
+            value = "false";
+        }
+        return new Boolean(value);
+    }
+
+    /**
+     * Get integer property.
+     * @param property
+     * @return
+     */
+    public static Integer getIntegerProperty(final String property){
+        String value = EncuestamePlaceHolderConfigurer.getProperty(property);
+        return new Integer(value);
+    }
 }

File encuestame-business/src/main/java/org/encuestame/business/mail/MailServiceImpl.java

View file
  • Ignore whitespace
 import org.apache.velocity.app.VelocityEngine;
 import org.encuestame.core.mail.MailService;
 import org.encuestame.core.service.ServiceOperations;
+import org.encuestame.business.config.EncuestamePlaceHolderConfigurer;
 import org.encuestame.business.service.AbstractBaseService;
 import org.encuestame.utils.mail.InvitationBean;
 import org.encuestame.utils.mail.NotificationBean;
         this.templateMessage = templateMessage;
     }
 
-    /**
-     * Send a email.
-     * @param to email to send
-     * @param subject subject
-     * @param text text of body
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.core.mail.MailService#send(java.lang.String, java.lang.String, java.lang.String)
      */
     public void send(
             final String to,
         send(preparator);
      }
 
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.core.mail.MailService#sendStartUpNotification(java.lang.String)
+     */
+    public void sendStartUpNotification(
+            final String startupMessage){
+        MimeMessagePreparator preparator = new MimeMessagePreparator() {
+            public void prepare(MimeMessage mimeMessage) throws Exception {
+               MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
+               message.setTo(EncuestamePlaceHolderConfigurer
+                       .getProperty("setup.email.notification.webmaster"));
+               message.setSubject("Start Up Notification");
+               message.setFrom(noEmailResponse);
+               Map model = new HashMap();
+               model.put("message", startupMessage);
+               String text = VelocityEngineUtils.mergeTemplateIntoString(
+                  velocityEngine, "/org/encuestame/business/mail/templates/startup.vm", model);
+               message.setText(text, true);
+            }
+         };
+         send(preparator);
+    }
+
     /**
      * Send Password Confirmation Email.
      * @param user

File encuestame-business/src/main/java/org/encuestame/business/search/AttachmentSearchItem.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+/**
+ * Class description.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since Mar 28, 2011
+ */
+public class AttachmentSearchItem {
+
+    private Long attachId;
+    private String description;
+    /**
+    * @return the attachId
+    */
+    public Long getAttachId() {
+        return attachId;
+    }
+    /**
+    * @param attachId the attachId to set
+    */
+    public void setAttachId(Long attachId) {
+        this.attachId = attachId;
+    }
+    /**
+    * @return the description
+    */
+    public String getDescription() {
+        return description;
+    }
+    /**
+    * @param description the description to set
+    */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+
+
+}

File encuestame-business/src/main/java/org/encuestame/business/search/GlobalSearchItem.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+/**
+ * Represent a global search item on results list.
+ *
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 23, 2011
+ */
+public class GlobalSearchItem {
+
+    private Long id;
+
+    private String urlLocation;
+
+    private Long score;
+
+    private Long hits;
+
+    private TypeSearchResult typeSearchResult;
+
+    private String itemSearchTitle;
+
+    private String itemSearchDescription;
+
+    /**
+     * @return the urlLocation
+     */
+    public String getUrlLocation() {
+        return urlLocation;
+    }
+
+    /**
+     * @param urlLocation
+     *            the urlLocation to set
+     */
+    public void setUrlLocation(String urlLocation) {
+        this.urlLocation = urlLocation;
+    }
+
+    /**
+     * @return the score
+     */
+    public Long getScore() {
+        return score;
+    }
+
+    /**
+     * @param score
+     *            the score to set
+     */
+    public void setScore(Long score) {
+        this.score = score;
+    }
+
+    /**
+     * @return the hits
+     */
+    public Long getHits() {
+        return hits;
+    }
+
+    /**
+     * @param hits
+     *            the hits to set
+     */
+    public void setHits(Long hits) {
+        this.hits = hits;
+    }
+
+    /**
+     * @return the typeSearchResult
+     */
+    public TypeSearchResult getTypeSearchResult() {
+        return typeSearchResult;
+    }
+
+    /**
+     * @param typeSearchResult
+     *            the typeSearchResult to set
+     */
+    public void setTypeSearchResult(TypeSearchResult typeSearchResult) {
+        this.typeSearchResult = typeSearchResult;
+    }
+
+    /**
+     * @return the itemSearchTitle
+     */
+    public String getItemSearchTitle() {
+        return itemSearchTitle;
+    }
+
+    /**
+     * @param itemSearchTitle
+     *            the itemSearchTitle to set
+     */
+    public void setItemSearchTitle(String itemSearchTitle) {
+        this.itemSearchTitle = itemSearchTitle;
+    }
+
+    /**
+     * @return the itemSearchDescription
+     */
+    public String getItemSearchDescription() {
+        return itemSearchDescription;
+    }
+
+    /**
+     * @param itemSearchDescription
+     *            the itemSearchDescription to set
+     */
+    public void setItemSearchDescription(String itemSearchDescription) {
+        this.itemSearchDescription = itemSearchDescription;
+    }
+
+    /**
+     * @return the id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * @param id the id to set
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((hits == null) ? 0 : hits.hashCode());
+        result = prime
+                * result
+                + ((itemSearchDescription == null) ? 0 : itemSearchDescription
+                        .hashCode());
+        result = prime * result
+                + ((itemSearchTitle == null) ? 0 : itemSearchTitle.hashCode());
+        result = prime * result + ((score == null) ? 0 : score.hashCode());
+        result = prime
+                * result
+                + ((typeSearchResult == null) ? 0 : typeSearchResult.hashCode());
+        result = prime * result
+                + ((urlLocation == null) ? 0 : urlLocation.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (!(obj instanceof GlobalSearchItem))
+            return false;
+        GlobalSearchItem other = (GlobalSearchItem) obj;
+        if (hits == null) {
+            if (other.hits != null)
+                return false;
+        } else if (!hits.equals(other.hits))
+            return false;
+        if (itemSearchDescription == null) {
+            if (other.itemSearchDescription != null)
+                return false;
+        } else if (!itemSearchDescription.equals(other.itemSearchDescription))
+            return false;
+        if (itemSearchTitle == null) {
+            if (other.itemSearchTitle != null)
+                return false;
+        } else if (!itemSearchTitle.equals(other.itemSearchTitle))
+            return false;
+        if (score == null) {
+            if (other.score != null)
+                return false;
+        } else if (!score.equals(other.score))
+            return false;
+        if (typeSearchResult != other.typeSearchResult)
+            return false;
+        if (urlLocation == null) {
+            if (other.urlLocation != null)
+                return false;
+        } else if (!urlLocation.equals(other.urlLocation))
+            return false;
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "GlobalSearchItem [urlLocation=" + urlLocation + ", score="
+                + score + ", hits=" + hits + ", typeSearchResult="
+                + typeSearchResult + ", itemSearchTitle=" + itemSearchTitle
+                + ", itemSearchDescription=" + itemSearchDescription + "]";
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/search/IndexWriterManager.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+import java.io.File;
+import java.io.IOException;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.util.Version;
+import org.encuestame.business.setup.DirectorySetupOperations;
+
+/**
+ * Index Writer Manager.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since Mar 25, 2011
+ */
+public class IndexWriterManager  {
+
+    /**
+    * Log.
+    */
+    private static final Log log = LogFactory.getLog(IndexWriterManager.class);
+
+    /**
+    * {@link IndexWriter}.
+    */
+    private IndexWriter indexWriter;
+
+    /**
+     * Checking index directory is open to write.
+     */
+    private Boolean isOpen = false;
+
+    /**
+     * Initialize writer lucene index directory.
+     * @throws IOException
+     */
+    @PostConstruct
+    public void openIndexWriter() throws IOException{
+        String dir = DirectorySetupOperations.getIndexesDirectory();
+        log.debug("Index Directory -->"+ dir);
+        final Directory directory = FSDirectory.open(new File(dir));
+        try {
+            this.indexWriter = new IndexWriter(directory, new StandardAnalyzer(
+                    Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);
+        } catch (CorruptIndexException e) {
+             log.error(e);
+        } catch (LockObtainFailedException e) {
+             log.error(e);
+        } catch (IOException e) {
+             log.error(e);
+        }
+    }
+
+    /**
+     * Close Index.
+     * @throws CorruptIndexException
+     * @throws IOException
+     */
+    @PreDestroy
+    public void closeIndexWriter() throws CorruptIndexException, IOException{
+        if (this.indexWriter == null){
+            log.error("Index writer is null");
+        } else {
+            this.indexWriter.close();
+        }
+    }
+
+    /**
+    * @return the isOpen
+    */
+    public Boolean getIsOpen() {
+        return isOpen;
+    }
+
+    /**
+    * @return the indexWriter
+    */
+    public IndexWriter getIndexWriter() {
+        return indexWriter;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/search/IndexerManager.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.document.Document;
+import org.apache.poi.POIXMLException;
+import org.encuestame.search.utils.SearchUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Indexer Manager.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since Mar 23, 2011
+ */
+public class IndexerManager {
+
+    /** Log. **/
+    private static final Log log = LogFactory.getLog(IndexerManager.class);
+
+    /** Index writer. **/
+    @Autowired
+    private IndexWriterManager indexWriterManager;
+
+    /** Constructor. **/
+    public IndexerManager() {
+    }
+
+    /**
+     * Initialize index process.
+     * @throws Exception
+     */
+     public void initializeIndex(final List<File> filesDirectory) throws Exception {
+         log.debug("Initialize");
+         for (File file : filesDirectory) {
+             long start = System.currentTimeMillis();
+             int numIndexed;
+             try {
+                 numIndexed = this.index(file);
+             } finally {
+                 this.close();
+             }
+             long end = System.currentTimeMillis();
+             log.debug("Indexing " + numIndexed + " files took " + (end - start)
+                     + " milliseconds");
+         }
+     }
+
+    /**
+    * Index Writer.
+    * @throws IOException
+    * @throws LockObtainFailedException
+    * @throws CorruptIndexException
+    *
+    */
+
+ /*   private void startIndexWriter() throws CorruptIndexException,
+            LockObtainFailedException, IOException {
+        final Directory dir = FSDirectory.open(new java.io.File(
+                this.indexesLocation));
+        this.indexWriter = new IndexWriter(dir, new StandardAnalyzer(
+                Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);
+    }*/
+
+    /**
+     * Read Files in Attachment Directory.
+     * @param dataDir Attachment Directory
+     * @return
+     * @throws Exception
+     */
+    public int index(final File dataDir) throws Exception {
+        log.debug("Index file is directory: " + dataDir.isDirectory());
+        File[] files = dataDir.listFiles();
+        int numberDocs = 0;
+        if ( files == null) {
+            log.info("No files in the directory ");
+        } else {
+            numberDocs = this.indexWriterManager.getIndexWriter().numDocs();
+            log.debug("List of files in the directory :"+numberDocs);
+            for (File f : files) {
+                if (!f.isDirectory() && !f.isHidden() && f.exists() && f.canRead()) {
+                    indexFile(f); // Write documents in Index
+                }
+            }
+        }
+        return numberDocs;
+    }
+
+
+   /**
+    * Retrieve Document to Index.
+    * @param file {@link File}
+    * @param ext Filename extension
+    * @return {@link Document}
+    * @throws POIXMLException
+    * @throws Exception
+    */
+    public Document getDocument(final File file, final String ext)
+            throws POIXMLException, Exception {
+        Document doc = null;
+        log.debug("get Document extension " + ext);
+        if ("docx".equals(ext)) {
+             doc = SearchUtils.createWordDocument(file);
+        } else if ("xls".equals(ext)) {
+             doc = SearchUtils.createSpreadsheetsDocument(file);
+        } else if ("pdf".equals(ext)) {
+             doc = SearchUtils.createPdfDocument(file);
+        } else if ("txt".equals(ext)) {
+             doc = SearchUtils.createTextDocument(file);
+        }
+        return doc ;
+    }
+
+    /**
+    * Adding Document to Index Directory.
+    * @param file {@link File}
+    * @throws Exception
+    */
+    private void indexFile(final File file) throws Exception {
+        log.debug("Indexing " + file.getCanonicalPath());
+        final String pathFileName = file.getName().toString();
+        final String ext = SearchUtils.getExtension(pathFileName);
+        final Document doc = this.getDocument(file, ext);
+        this.indexWriterManager.openIndexWriter();
+        log.debug("Indexing Files *******************");
+        //log.debug("Adding document..." + doc);
+        if (doc == null) {
+            log.warn("Document is null for this file: "+file.getAbsolutePath());
+        } else {
+            // Add Document to Lucene Index.
+            this.indexWriterManager.getIndexWriter().addDocument(doc);
+        }
+    }
+
+    /**
+    * Close Lucene IndexWriter.
+    * @throws IOException
+    */
+    public void close() throws IOException {
+        this.indexWriterManager.getIndexWriter().commit();
+        this.indexWriterManager.getIndexWriter().close();
+    }
+
+    /**
+    * @param indexWriterManager the indexWriterManager to set
+    */
+    public void setIndexWriterManager(final IndexWriterManager indexWriterManager) {
+        this.indexWriterManager = indexWriterManager;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/search/ReIndexAttachmentsJob.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.encuestame.business.setup.DirectorySetupOperations;
+import org.encuestame.persistence.dao.IAccountDao;
+import org.encuestame.persistence.dao.imp.AccountDaoImp;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * ReIndex Attachments Job.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since Mar 23, 2011
+ */
+public class ReIndexAttachmentsJob {
+
+    /**
+     * Log.
+     */
+    private static final Log log = LogFactory.getLog(ReIndexAttachmentsJob.class);
+
+    /**
+     * {@link AccountDaoImp}.
+     */
+    @Autowired
+    private IAccountDao accountDao;
+
+    /**
+     * {@link IndexerManager}
+     */
+    @Autowired
+    private IndexerManager indexerManager;
+
+
+    /**
+     * Enable/Disable autocreate missing directories.
+     */
+    private Boolean autoCreateDirectories = Boolean.FALSE;
+
+    /**
+     * Constructor.
+     * @throws EnMeExpcetion if indexes directoty is null;
+     */
+    public ReIndexAttachmentsJob() throws EnMeExpcetion {    	//
+    }
+
+    /**
+     * Return list of enabled account directories.
+     * @return
+     */
+    private List<File> getListOfAccountEnabledDirectories(){
+        final List<File> userDomainAttachmentsLocation = new ArrayList<File>();
+        final List<Long> listOfAccounts = getAccountDao().getAccountsEnabled();
+        log.debug("listOfAccounts enabled:{"+listOfAccounts.size());
+        for (Long accountId : listOfAccounts) {
+            final StringBuilder path = new StringBuilder(DirectorySetupOperations.getProfilesDirectory());
+            path.append("/");
+            path.append(accountId.toString());
+            path.append("/");
+            log.debug("Path builded "+path.toString());
+            final File accountPath = new File(path.toString());
+            if (accountPath.exists()) {
+                userDomainAttachmentsLocation.add(accountPath);
+            } else {
+                log.warn("Account Id: "+accountId+ " profile propery is missing, enable autocreate to create missings directories");
+                if (this.autoCreateDirectories) {
+                    log.debug("Autocreate enabled: creating folder for profile:{"+accountId);
+                    accountPath.mkdir();
+                    if(accountPath.exists()){
+                        userDomainAttachmentsLocation.add(accountPath);
+                    }
+                }
+            }
+        }
+        return userDomainAttachmentsLocation;
+    }
+
+    /**
+     * Reindex.
+     */
+    public void reindexAttachments(){
+        log.debug("reindexAttachments");
+        final List<File> userDomainAttachmentsLocation = this.getListOfAccountEnabledDirectories();
+        log.debug("Location size:{"+userDomainAttachmentsLocation.size());
+        try {
+            if (userDomainAttachmentsLocation.size() > 0) {
+                if (this.indexerManager == null) {
+                    log.fatal("IntexManager is missing.");
+                } else {
+                    log.debug("Initialize Index Starting...");
+                    this.indexerManager.initializeIndex(userDomainAttachmentsLocation);
+                }
+            } else {
+                log.debug("Nothing to index... ");
+            }
+        } catch (Exception e) {
+            log.fatal("Index on reindex: "+e);
+        }
+    }
+
+    /**
+    * @param indexerManager the indexerManager to set
+    */
+    public void setIndexerManager(final IndexerManager indexerManager) {
+        this.indexerManager = indexerManager;
+    }
+
+
+    /**
+     * @return the accountDao
+     */
+    public IAccountDao getAccountDao() {
+        return accountDao;
+    }
+
+
+    /**
+     * @param accountDao the accountDao to set
+     */
+    public void setAccountDao(final IAccountDao accountDao) {
+        this.accountDao = accountDao;
+    }
+
+    /**
+     * @return the autoCreateDirectories
+     */
+    public Boolean getAutoCreateDirectories() {
+        return autoCreateDirectories;
+    }
+
+    /**
+     * @param autoCreateDirectories the autoCreateDirectories to set
+     */
+    public void setAutoCreateDirectories(final Boolean autoCreateDirectories) {
+        this.autoCreateDirectories = autoCreateDirectories;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/search/SearchAttachmentManager.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.util.Version;
+import org.encuestame.business.setup.DirectorySetupOperations;
+import org.encuestame.search.SearchManagerOperation;
+
+/**
+ * Query Search Manager to Lucene Index.
+ *
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since Mar 24, 2011
+ */
+public class SearchAttachmentManager implements SearchManagerOperation {
+
+    /** Log. **/
+    private static final Log log = LogFactory.getLog(SearchAttachmentManager.class);
+
+    /** Index Directory Path. **/
+    final String directoryIndex;
+
+    /** Option to Read Index Directory. **/
+    private Boolean readDirectory = true;
+
+    /** Index Directory **/
+    private Directory directory;
+
+    /** Index Searcher **/
+    private IndexSearcher indexSearcher;
+
+    /**
+    * Constructor.
+    */
+    public SearchAttachmentManager() {
+        this.directoryIndex = DirectorySetupOperations.getIndexesDirectory();
+    }
+
+    /**
+    * Start Index Searcher.
+    * @throws IOException
+    */
+    private void startIndexSearcher() throws IOException {
+        // Open Index Directory to Search.
+        this.directory = FSDirectory.open(new File(this.directoryIndex));
+        this.indexSearcher = new IndexSearcher(this.directory, true);
+    }
+
+    /**
+     * Index Searcher.
+     * @return
+     * @throws CorruptIndexException
+     * @throws IOException
+     */
+    private IndexSearcher indexSearch() throws CorruptIndexException,
+            IOException {
+        return this.indexSearcher = new IndexSearcher(this.directory,
+                this.readDirectory);
+    }
+
+    /**
+    * Search Query in Lucene Index.
+    * @param indexDir
+    * @param q
+    * @throws IOException
+    * @throws ParseException
+    */
+    public List<Document> search(final String queryText, final int max, final String field) throws IOException,
+            ParseException {
+        this.startIndexSearcher();
+        final List<Document> results = new ArrayList<Document>();
+        QueryParser parser = new QueryParser(Version.LUCENE_30, field,
+                new StandardAnalyzer(Version.LUCENE_30));
+        Query query = parser.parse(queryText); // Parse Query
+        long start = System.currentTimeMillis();
+        TopDocs hits = this.indexSearch().search(query, max); // Search Index
+        long end = System.currentTimeMillis();
+
+        log.debug("Found " + hits.totalHits + " document(s) (in "
+                + (end - start) + " milliseconds) that matched query '"
+                + queryText + "':"); // Write search Stats
+
+        for (ScoreDoc scoreDoc : hits.scoreDocs) {
+            // Retrieving matching document.
+            Document doc = indexSearch().doc(scoreDoc.doc);
+            log.debug("Fullpath Document -->" + doc.get("fullpath"));
+            results.add(doc);
+        }
+        // Close IndexSearcher.
+        indexSearch().close();
+        return results;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/search/TypeSearchResult.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+/**
+ * Type search result.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 23, 2011
+ */
+enum TypeSearchResult {
+    TWEETPOLL, PROFILE, POLL, SURVEY, ATTACHMENT, QUESTION, HASHTAG
+}

File encuestame-business/src/main/java/org/encuestame/business/search/UtilConvertToSearchItems.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.search;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.encuestame.persistence.domain.HashTag;
+import org.encuestame.persistence.domain.question.Question;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.utils.RestFullUtil;
+
+/**
+ * Utils to convert items to {@link GlobalSearchItem}.
+ *
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 26, 2011
+ */
+public class UtilConvertToSearchItems {
+
+    /**
+     *
+     * @param question
+     * @return
+     */
+    public static GlobalSearchItem convertQuestionToSearchItem(
+            final Question question) {
+        final GlobalSearchItem globalSearchItem = new GlobalSearchItem();
+        globalSearchItem
+                .setUrlLocation("/question/detail/" + question.getQid()+"/"+RestFullUtil.slugify(question.getQuestion()));
+        globalSearchItem.setHits(question.getHits());
+        globalSearchItem.setItemSearchTitle(question.getQuestion());
+        globalSearchItem.setTypeSearchResult(TypeSearchResult.QUESTION);
+        globalSearchItem.setScore(100L);
+        return globalSearchItem;
+    }
+
+    /**
+     *
+     * @param item
+     * @return
+     */
+    public static GlobalSearchItem convertAttachmentSearchToSearchItem(
+            final AttachmentSearchItem item) {
+        final GlobalSearchItem globalSearchItem = new GlobalSearchItem();
+        globalSearchItem
+                .setUrlLocation("/resource/detail/" + item.getAttachId()+"/"+RestFullUtil.slugify(item.getDescription()));
+        globalSearchItem.setHits(200L);
+        globalSearchItem.setItemSearchTitle(item.getDescription());
+        globalSearchItem.setTypeSearchResult(TypeSearchResult.ATTACHMENT);
+        globalSearchItem.setScore(100L);
+        return globalSearchItem;
+    }
+
+    /**
+     *
+     * @param items
+     * @return
+     */
+    public static List<GlobalSearchItem> convertAttachmentSearchToSearchItem(
+            final List<AttachmentSearchItem> items) {
+        final List<GlobalSearchItem> globalSearchItems = new ArrayList<GlobalSearchItem>();
+        for (AttachmentSearchItem item : items) {
+            globalSearchItems.add(UtilConvertToSearchItems
+                    .convertAttachmentSearchToSearchItem(item));
+        }
+        return globalSearchItems;
+    }
+
+    /**
+     *
+     * @param tag
+     * @return
+     */
+    public static GlobalSearchItem convertHashTagToSearchItem(final HashTag tag) {
+        final GlobalSearchItem globalSearchItem = new GlobalSearchItem();
+        globalSearchItem.setUrlLocation("/hashtag/"
+                + RestFullUtil.formatHasgTag(tag.getHashTag()));
+        globalSearchItem.setHits(tag.getHits());
+        globalSearchItem.setItemSearchTitle(tag.getHashTag());
+        globalSearchItem.setTypeSearchResult(TypeSearchResult.HASHTAG);
+        globalSearchItem.setScore(100L);
+        return globalSearchItem;
+    }
+
+    /**
+     *
+     * @param profile
+     * @return
+     */
+    public static GlobalSearchItem convertProfileToSearchItem(
+            final UserAccount profile) {
+        final GlobalSearchItem globalSearchItem = new GlobalSearchItem();
+        globalSearchItem.setUrlLocation("/users/profile/"
+                + profile.getUsername());
+        globalSearchItem.setHits(0L);
+        globalSearchItem.setItemSearchTitle(profile.getCompleteName());
+        globalSearchItem.setTypeSearchResult(TypeSearchResult.PROFILE);
+        globalSearchItem.setScore(100L);
+        return globalSearchItem;
+    }
+
+    /**
+     *
+     * @param profiles
+     * @return
+     */
+    public static List<GlobalSearchItem> convertProfileToSearchItem(
+            final List<UserAccount> profiles) {
+        final List<GlobalSearchItem> globalSearchItems = new ArrayList<GlobalSearchItem>();
+        for (UserAccount profile : profiles) {
+            globalSearchItems.add(UtilConvertToSearchItems
+                    .convertProfileToSearchItem(profile));
+        }
+        return globalSearchItems;
+    }
+
+    /**
+     *
+     * @param questions
+     * @return
+     */
+    public static List<GlobalSearchItem> convertQuestionToSearchItem(
+            final List<Question> questions) {
+        final List<GlobalSearchItem> globalSearchItems = new ArrayList<GlobalSearchItem>();
+        for (Question question : questions) {
+            globalSearchItems.add(UtilConvertToSearchItems
+                    .convertQuestionToSearchItem(question));
+        }
+        return globalSearchItems;
+    }
+
+    /**
+     *
+     * @param tags
+     * @return
+     */
+    public static List<GlobalSearchItem> convertHashTagToSearchItem(
+            final List<HashTag> tags) {
+        final List<GlobalSearchItem> globalSearchItems = new ArrayList<GlobalSearchItem>();
+        for (HashTag tag : tags) {
+            globalSearchItems.add(UtilConvertToSearchItems
+                    .convertHashTagToSearchItem(tag));
+        }
+        return globalSearchItems;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/security/filter/VerifyAuthenticationFilter.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at 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.encuestame.business.security.filter;
 
 import java.io.IOException;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
-import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.log4j.Logger;
-import org.springframework.security.access.ConfigAttribute;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
  * Verify Authentication Filter.
  * @author Picado, Juan juanATencuestameDOTorg
  * @since Aug 21, 2010 10:41:38 PM
- * @version $Id: $
  */
 public class VerifyAuthenticationFilter implements Filter {
 
-    protected Logger log = Logger.getLogger(this.getClass());
+    private Logger log = Logger.getLogger(this.getClass());
 
-    protected  String loginUrl = "/user/signin";
+    private  String loginUrl = "/user/signin";
 
-    protected  String redirectUrl = "/account/dashboard";
+    private  String redirectUrl = "/account/dashboard";
 
     /**
      * Do Filter.

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractIndexService.java

View file
  • Ignore whitespace
 
 package org.encuestame.business.service;
 
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.queryParser.ParseException;
+import org.encuestame.business.search.AttachmentSearchItem;
+import org.encuestame.business.search.GlobalSearchItem;
+import org.encuestame.business.search.UtilConvertToSearchItems;
 import org.encuestame.core.util.ConvertDomainBean;
+import org.encuestame.persistence.domain.Attachment;
 import org.encuestame.persistence.domain.HashTag;
-import org.encuestame.persistence.domain.Question;
+import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.search.SearchManagerOperation;
 import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.QuestionBean;
+import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * Provide of index/search layer.
      */
     private Log log = LogFactory.getLog(this.getClass());
 
+    /** Search Manager Operation**/
+    @Autowired(required = false)
+    private SearchManagerOperation searchOperation; //TODO:ENCUESTAME-154
+
     /**
      * List Suggested Hash Tags.
      * @param hashTagKeyWord keyword to search
     /**
      * Return suggested list of questions by keyword on indexed results.
      * @param keyword keyword to search
-     * @param username username logged
+     * @param userId userId
      * @return
      * @throws EnMeNoResultsFoundException
      */
-    public List<QuestionBean> searchIndexedQuestions(final String keyword, final String username)
+    public List<Question> retrieveQuestionByKeyword(final String keyword, final Long userId)
            throws EnMeNoResultsFoundException{
         final List<Question> questions = getQuestionDao().retrieveIndexQuestionsByKeyword(keyword,
-                                         getUserAccount(username).getAccount().getUid());
-        return ConvertDomainBean.convertListToUnitQuestionBean(questions);
+                                         userId, null, null);
+        return questions;
+    }
+
+    /**
+     *
+     * @param keyword
+     * @param maxResults
+     * @param field
+     * @return
+     * @throws IOException
+     * @throws ParseException
+     */
+    public List<AttachmentSearchItem> getAttachmentItem(final String keyword,
+            final int maxResults, final String field) throws IOException,
+            ParseException {
+        final List<Document> attachItems = getSearchOperation().search(keyword,
+                maxResults, field);
+        return this.convertDocumentToListAttachment(attachItems);
+    }
+
+    /**
+    * @return the searchOperation
+    */
+    public SearchManagerOperation getSearchOperation() {
+        return searchOperation;
+    }
+
+    /**
+    * @param searchOperation the searchOperation to set
+    */
+    public void setSearchOperation(final SearchManagerOperation searchOperation) {
+        this.searchOperation = searchOperation;
+    }
+
+    /**
+     * Convert Document Lucene List to Attachment Search Item List.
+     * @param docAttach Attachment
+     * @return
+     */
+    public static final  List<AttachmentSearchItem> convertDocumentToListAttachment(final List<Document> docAttach) {
+        final List<AttachmentSearchItem> attachmentItems = new ArrayList<AttachmentSearchItem>();
+          for (Document item : docAttach) {
+            attachmentItems.add(convertDoctoSearchItem(item));
+          }
+         return attachmentItems;
+    }
+
+    /**
+     * Convert Lucene Document Item to Attachment Search Bean.
+     * @param docItem Lucene Document
+     * @return
+     */
+    public static final AttachmentSearchItem convertDoctoSearchItem(final Document document){
+        final AttachmentSearchItem attachItem = new AttachmentSearchItem();
+        attachItem.setAttachId(1L);
+        attachItem.setDescription(document.get("filename"));
+        return attachItem;
     }
 }
+

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractSurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.domain.HashTag;
-import org.encuestame.persistence.domain.Question;
+import org.encuestame.persistence.domain.question.Question;
+import org.encuestame.persistence.domain.question.QuestionAnswer;
+import org.encuestame.persistence.domain.question.QuestionPattern;
 import org.encuestame.persistence.domain.security.SocialAccount;
-import org.encuestame.persistence.domain.survey.QuestionPattern;
-import org.encuestame.persistence.domain.survey.QuestionAnswer;
-import org.encuestame.persistence.domain.survey.TweetPoll;
-import org.encuestame.persistence.domain.survey.TweetPollResult;
-import org.encuestame.persistence.domain.survey.TweetPollSwitch;