From f36135f335811f85897f27467d3b42eefcc30acf Mon Sep 17 00:00:00 2001 From: rkv Date: Mon, 22 Oct 2012 07:53:24 +0000 Subject: [PATCH] Reindex of studies is fixed. --- .../src/org/splat/service/SearchService.java | 37 +- .../org/splat/service/SearchServiceImpl.java | 604 +++++++++++------- .../service/technical/IndexServiceImpl.java | 539 +++++++++------- .../src/spring/businessServiceContext.xml | 3 +- Workspace/Siman/WebContent/jsp/searchForm.jsp | 6 +- .../org/splat/simer/ApplicationSettings.java | 2 +- .../org/splat/simer/SearchStudyAction.java | 424 ++++++------ .../simer/admin/DatabaseIndexingAction.java | 159 +++-- .../Siman/src/spring/applicationContext.xml | 179 +++--- 9 files changed, 1104 insertions(+), 849 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchService.java b/Workspace/Siman-Common/src/org/splat/service/SearchService.java index 08a8ab8..b61b2f9 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchService.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchService.java @@ -7,7 +7,7 @@ * @version $Revision$ *****************************************************************************/ -package org.splat.service; +package org.splat.service; import java.util.List; @@ -16,12 +16,37 @@ import org.splat.dal.bo.som.Study; import org.splat.service.dto.Proxy; /** - * @author rkv - * + * Search service interface. + * @author Roman Kozlov (RKV) */ public interface SearchService { - public List selectKnowledgeElementsWhere (KnowledgeElement.Properties... kprop); - public List selectStudiesWhere (Study.Properties... sprop); - public void indexStudy (Study study); + /** + * Refresh lucene index for studies. + * + * @param ridlist + * list of studies id's + */ + public void reindexStudies(String[] ridlist); + + /** + * Find knowledge elements with given properties. + * @param kprop search filter parameters + * @return the list of found knowledge elements as proxiy results of lucene search + */ + public List selectKnowledgeElementsWhere( + KnowledgeElement.Properties... kprop); + + /** + * Find studies with given properties. + * @param sprop search filter parameters + * @return the list of found studies as proxiy results of lucene search + */ + public List selectStudiesWhere(Study.Properties... sprop); + + /** + * Refresh lucene index for a study. + * @param study the study to reindex + */ + public void indexStudy(Study study); } diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java index 75f3d6a..ad113b6 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java @@ -7,7 +7,7 @@ * @version $Revision$ *****************************************************************************/ -package org.splat.service; +package org.splat.service; import java.io.File; import java.io.IOException; @@ -38,263 +38,364 @@ import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Visibility; -import org.splat.dal.dao.som.Database; import org.splat.service.dto.Proxy; import org.splat.service.technical.IndexService; import org.splat.service.technical.IndexServiceImpl; import org.splat.service.technical.RepositoryService; +import org.springframework.transaction.annotation.Transactional; /** - * @author rkv - * + * Search service implementation. + * + * @author Roman Kozlov (RKV) */ public class SearchServiceImpl implements SearchService { - public final static Logger logger = Logger.getLogger(org.splat.service.SearchServiceImpl.class); - - private RepositoryService _repositoryService; + /** + * The service logger. + */ + public final static Logger logger = Logger + .getLogger(org.splat.service.SearchServiceImpl.class); + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; + /** + * Injected index service. + */ private IndexService _indexService; - - public List selectKnowledgeElementsWhere (KnowledgeElement.Properties... kprop) { - // --------------------------------------------------------------------------------------------- - List result = new ArrayList(); - int hitsize = 20; - try { - - // Creation of the Lucene query - File indir = getRepositoryService().getRepositoryIndexDirectory(); - Directory index = FSDirectory.open(indir); - IndexSearcher searcher = new IndexSearcher(index, true); - BooleanQuery fulquery = new BooleanQuery(); - - for (int i=0; i context = kprop[i].getSimulationContexts(); - if (context != null && context.size() > 0) { - BooleanQuery critext = new BooleanQuery(); - for (Iterator j=context.iterator(); j.hasNext();) { - SimulationContext seltext = j.next(); - input = new Term(String.valueOf(seltext.getType().getIndex())); - critext.add(new TermQuery(input.createTerm(seltext.getValue())), BooleanClause.Occur.MUST); - } - query.add(critext, BooleanClause.Occur.MUST); - } - fulquery.add(query, BooleanClause.Occur.SHOULD); - } + + /** + * Injected study service. + */ + private StudyService _studyService; + + /** + * Refresh lucene index for studies. + * + * @param ridlist + * list of studies id's + */ + @Transactional(readOnly = true) + public void reindexStudies(String[] ridlist) { + for (int i = 0; i < ridlist.length; i++) { + long index = Long.valueOf(ridlist[i].trim()); + Study study = getStudyService().selectStudy(index); + indexStudy(study); + } + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[]) + */ + public List selectKnowledgeElementsWhere( + KnowledgeElement.Properties... kprop) { + List result = new ArrayList(); + int hitsize = 20; + try { + + // Creation of the Lucene query + File indir = getRepositoryService().getRepositoryIndexDirectory(); + Directory index = FSDirectory.open(indir); + IndexSearcher searcher = new IndexSearcher(index, true); + BooleanQuery fulquery = new BooleanQuery(); + + for (int i = 0; i < kprop.length; i++) { + BooleanQuery query = new BooleanQuery(); + Term input; // Supposed initialized below at least by the visibility + + Visibility area = kprop[i].getVisibility(); // Visibility + if (area != null) { + input = new Term("area"); + query.add(new TermQuery(input.createTerm(area.toString())), + BooleanClause.Occur.MUST); + } + ProgressState state = kprop[i].getProgressState(); // State + if (state != null) { + input = new Term("state"); + query.add( + new TermQuery(input.createTerm(state.toString())), + BooleanClause.Occur.MUST); + } + String refid = kprop[i].getReference(); // Reference + if (refid != null) { + input = new Term("ref"); + query.add(new TermQuery(input.createTerm(refid)), + BooleanClause.Occur.MUST); + } + KnowledgeElementType type = kprop[i].getType(); // Type + if (type != null) { + input = new Term("type"); + query.add(new TermQuery(input.createTerm(type.getName())), + BooleanClause.Occur.MUST); + } + User manager = kprop[i].getAuthor(); // Author + if (manager != null) { + input = new Term("author"); + query.add(new TermQuery(input + .createTerm(manager.toString())), + BooleanClause.Occur.MUST); + } + User actor = kprop[i].getActor(); // Contributor, Reviewer or Approver of the owner study + if (actor != null) { + input = new Term("actor"); + query.add( + new TermQuery(input.createTerm(actor.toString())), + BooleanClause.Occur.MUST); + } + String title = kprop[i].getTitle(); // Title + if (title != null) { + input = new Term("contents"); + BooleanQuery critext = new BooleanQuery(); + String operator = "AND"; // Future user input + BooleanClause.Occur clause = BooleanClause.Occur.MUST; + if (operator.equals("OR")) + clause = BooleanClause.Occur.SHOULD; + String[] word = title.split(" "); + for (int j = 0; j < word.length; j++) { + critext.add(new TermQuery(input.createTerm(word[j])), + clause); + } + query.add(critext, BooleanClause.Occur.MUST); + } + List context = kprop[i] + .getSimulationContexts(); + if (context != null && context.size() > 0) { + BooleanQuery critext = new BooleanQuery(); + for (Iterator j = context.iterator(); j + .hasNext();) { + SimulationContext seltext = j.next(); + input = new Term(String.valueOf(seltext.getType() + .getIndex())); + critext.add(new TermQuery(input.createTerm(seltext + .getValue())), BooleanClause.Occur.MUST); + } + query.add(critext, BooleanClause.Occur.MUST); + } + fulquery.add(query, BooleanClause.Occur.SHOULD); + } if (logger.isInfoEnabled()) { - logger.info("Searching knowledges by Lucene query \"" + fulquery.toString() + "\"."); - } - // Creation of the knowledge filter - BooleanFilter filter = new BooleanFilter(); - TermsFilter select = new TermsFilter(); - Term mytype = new Term("class"); - select.addTerm( mytype.createTerm("KnowledgeElement") ); - filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD)); - - // Creation of the sort criteria - Sort sort = new Sort(new SortField("title", SortField.STRING)); - - // Search - TopFieldDocs found = searcher.search(fulquery, filter, hitsize, sort); - - if (found.totalHits < 1) return result; // No study found - - // Construction of the result list - ScoreDoc[] hits = found.scoreDocs; - for (int i=0; i selectStudiesWhere(Study.Properties... sprop) { + List result = new ArrayList(); + int hitsize = 20; + try { - public List selectStudiesWhere (Study.Properties... sprop) { - // ------------------------------------------------------------------------ - List result = new ArrayList(); - int hitsize = 20; - try { - - // Creation of the Lucene query - File indir = getRepositoryService().getRepositoryIndexDirectory(); - Directory index = FSDirectory.open(indir); - IndexSearcher searcher = new IndexSearcher(index, true); - BooleanQuery fulquery = new BooleanQuery(); - - for (int i=0; i context = sprop[i].getSimulationContexts(); - if (context != null && context.size() > 0) { - BooleanQuery critext = new BooleanQuery(); - for (Iterator j=context.iterator(); j.hasNext();) { - SimulationContext seltext = j.next(); - input = new Term(String.valueOf(seltext.getType().getIndex())); - critext.add(new TermQuery(input.createTerm(seltext.getValue())), BooleanClause.Occur.MUST); - } - query.add(critext, BooleanClause.Occur.MUST); - } - fulquery.add(query, BooleanClause.Occur.SHOULD); - } + // Creation of the Lucene query + File indir = getRepositoryService().getRepositoryIndexDirectory(); + Directory index = FSDirectory.open(indir); + IndexSearcher searcher = new IndexSearcher(index, true); + BooleanQuery fulquery = new BooleanQuery(); + + for (int i = 0; i < sprop.length; i++) { + BooleanQuery query = new BooleanQuery(); + Term input; // Supposed initialized below at least by the visibility + + Visibility area = sprop[i].getVisibility(); // Visibility + if (area != null) { + input = new Term("area"); + query.add(new TermQuery(input.createTerm(area.toString())), + BooleanClause.Occur.MUST); + } + ProgressState state = sprop[i].getProgressState(); // State + if (state != null) { + input = new Term("state"); + if (state == ProgressState.inPROGRESS) { + BooleanQuery cristate = new BooleanQuery(); + cristate.add(new TermQuery(input.createTerm("inWORK")), + BooleanClause.Occur.SHOULD); + cristate.add( + new TermQuery(input.createTerm("inDRAFT")), + BooleanClause.Occur.SHOULD); + cristate.add( + new TermQuery(input.createTerm("inCHECK")), + BooleanClause.Occur.SHOULD); + query.add(cristate, BooleanClause.Occur.MUST); + } else { + query.add(new TermQuery(input.createTerm(state + .toString())), BooleanClause.Occur.MUST); + } + } + String refid = sprop[i].getReference(); // Reference + if (refid != null) { + input = new Term("ref"); + query.add(new TermQuery(input.createTerm(refid)), + BooleanClause.Occur.MUST); + } + User manager = sprop[i].getManager(); // Author + if (manager != null) { + input = new Term("author"); + query.add(new TermQuery(input + .createTerm(manager.toString())), + BooleanClause.Occur.MUST); + } + User actor = sprop[i].getActor(); // Contributor, Reviewer or Approver + if (actor != null) { + input = new Term("actor"); + query.add( + new TermQuery(input.createTerm(actor.toString())), + BooleanClause.Occur.MUST); + } + String title = sprop[i].getTitle(); // Title + if (title != null) { + input = new Term("contents"); + BooleanQuery critext = new BooleanQuery(); + String operator = "AND"; // Future user input + BooleanClause.Occur clause = BooleanClause.Occur.MUST; + if (operator.equals("OR")) + clause = BooleanClause.Occur.SHOULD; + String[] word = title.split(" "); + for (int j = 0; j < word.length; j++) { + critext.add(new TermQuery(input.createTerm(word[j])), + clause); + } + query.add(critext, BooleanClause.Occur.MUST); + } + List context = sprop[i] + .getSimulationContexts(); + if (context != null && context.size() > 0) { + BooleanQuery critext = new BooleanQuery(); + for (Iterator j = context.iterator(); j + .hasNext();) { + SimulationContext seltext = j.next(); + input = new Term(String.valueOf(seltext.getType() + .getIndex())); + critext.add(new TermQuery(input.createTerm(seltext + .getValue())), BooleanClause.Occur.MUST); + } + query.add(critext, BooleanClause.Occur.MUST); + } + fulquery.add(query, BooleanClause.Occur.SHOULD); + } if (logger.isInfoEnabled()) { - logger.info("Searching studies by Lucene query \"" + fulquery.toString() + "\"."); - } - // Creation of the studies filter - BooleanFilter filter = new BooleanFilter(); - TermsFilter select = new TermsFilter(); - Term mytype = new Term("class"); - select.addTerm( mytype.createTerm("Study") ); - filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD)); - - // Creation of the sort criteria - Sort sort = new Sort(new SortField("title", SortField.STRING)); - - // Search - TopFieldDocs found = searcher.search(fulquery, filter, hitsize, sort); - - if (found.totalHits < 1) return result; // No study found - - // Construction of the result list - ScoreDoc[] hits = found.scoreDocs; - for (int i=0; i index = selectStudiesWhere(sprop.setReference(study.getReference())); - - if (index.size() != 0) return; // The given study is already indexed - - IndexService lucin = getIndex(); - Scenario[] scenes = study.getScenarii(); - - lucin.add(study); - if (study.getProgressState() != ProgressState.inWORK) for (int i=0; i list = scenes[i].getAllKnowledgeElements(); - for (Iterator j=list.iterator(); j.hasNext(); ) { - lucin.add(j.next()); - } - } - } - catch (Exception error) { - Database.logger.error("Unable to index the study '" + study.getIndex() + "', reason:", error); - } - } - - public IndexService getIndex () throws IOException { + logger.info("Searching studies by Lucene query \"" + + fulquery.toString() + "\"."); + } + // Creation of the studies filter + BooleanFilter filter = new BooleanFilter(); + TermsFilter select = new TermsFilter(); + Term mytype = new Term("class"); + select.addTerm(mytype.createTerm("Study")); + filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD)); + + // Creation of the sort criteria + Sort sort = new Sort(new SortField("title", SortField.STRING)); + + // Search + TopFieldDocs found = searcher.search(fulquery, filter, hitsize, + sort); + + if (found.totalHits < 1) + return result; // No study found + + // Construction of the result list + ScoreDoc[] hits = found.scoreDocs; + for (int i = 0; i < hits.length; i++) { + result.add(new IndexServiceImpl.ObjectProxy(searcher + .doc(hits[i].doc))); + } + searcher.close(); + } catch (Exception error) { + logger.error("Error during Lucene search, reason:", error); + } + return result; + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SearchService#indexStudy(org.splat.dal.bo.som.Study) + */ + public void indexStudy(Study study) { + logger.debug("Index study: id=" + study.getRid() + "; reference=" + study.getReference()); + try { + Study.Properties sprop = new Study.Properties(); + List index = selectStudiesWhere(sprop.setReference(study + .getReference())); + + if (index.size() != 0) { + logger.debug("The given study is already indexed."); + return; // The given study is already indexed + } + + IndexService lucin = getIndex(); + Scenario[] scenes = study.getScenarii(); + + logger.debug("Number of study " + study.getReference() + " actors: " + study.getActor().size()); + lucin.add(study); + if (study.getProgressState() != ProgressState.inWORK) + for (int i = 0; i < scenes.length; i++) { + List list = scenes[i] + .getAllKnowledgeElements(); + for (Iterator j = list.iterator(); j + .hasNext();) { + lucin.add(j.next()); + logger.debug("Knowlegge added: id=" + j.next().getIndex()); + } + } + } catch (Exception error) { + logger.error("Unable to index the study '" + + study.getIndex() + "', reason:", error); + } + } + + /** + * Get lucene index handler. Create the index if it is not exist. + * + * @return IndexService + * @throws IOException + * if error when creating a new lucene index + */ + private IndexService getIndex() throws IOException { IndexService lucin = getIndexService(); - if ( !lucin.exists() ) lucin.create(); // Happens when re-indexing all studies + if (!lucin.exists()) + lucin.create(); // Happens when re-indexing all studies return lucin; - } - + } + /** * Get the repositoryService. + * * @return the repositoryService */ public RepositoryService getRepositoryService() { @@ -303,7 +404,9 @@ public class SearchServiceImpl implements SearchService { /** * Set the repositoryService. - * @param repositoryService the repositoryService to set + * + * @param repositoryService + * the repositoryService to set */ public void setRepositoryService(RepositoryService repositoryService) { _repositoryService = repositoryService; @@ -311,6 +414,7 @@ public class SearchServiceImpl implements SearchService { /** * Get the indexService. + * * @return the indexService */ public IndexService getIndexService() { @@ -319,9 +423,27 @@ public class SearchServiceImpl implements SearchService { /** * Set the indexService. - * @param indexService the indexService to set + * + * @param indexService + * the indexService to set */ public void setIndexService(IndexService indexService) { _indexService = indexService; } + + /** + * Get the studyService. + * @return the studyService + */ + public StudyService getStudyService() { + return _studyService; + } + + /** + * Set the studyService. + * @param studyService the studyService to set + */ + public void setStudyService(StudyService studyService) { + _studyService = studyService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/IndexServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/IndexServiceImpl.java index 6f96dc9..498026d 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/IndexServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/IndexServiceImpl.java @@ -1,4 +1,5 @@ package org.splat.service.technical; + /** * * @author Daniel Brunier-Coulin @@ -30,261 +31,297 @@ import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; -import org.splat.dal.dao.som.Database; import org.splat.service.ProjectElementService; import org.splat.service.dto.Proxy; import org.splat.som.Step; - public class IndexServiceImpl implements IndexService { - private Directory index; - private org.apache.lucene.document.Document body; + private Directory index; + private org.apache.lucene.document.Document body; private ProjectElementService _projectElementService; - private RepositoryService _repositoryService; - - protected static StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_29); - private static final Logger logger = Logger.getLogger(IndexServiceImpl.class); - - private class Entry extends IndexWriter { -// --------------------------------------- - private org.apache.lucene.document.Document entry; - - private Entry (Study study) throws CorruptIndexException, LockObtainFailedException, IOException - { - super(index, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); - -// Addition of mandatory fields - entry = new org.apache.lucene.document.Document(); - Field field; - field = body.getField("index"); - field.setValue(String.valueOf(study.getIndex())); - entry.add(field); - field = body.getField("class"); - field.setValue("Study"); - entry.add(field); - field = body.getField("type"); - field.setValue(""); // Reserved for configurable Study type - entry.add(field); - field = body.getField("ref"); - field.setValue(study.getReference()); - entry.add(field); - field = body.getField("area"); - field.setValue(study.getVisibility().toString()); - entry.add(field); - field = body.getField("state"); - field.setValue(study.getProgressState().toString()); - entry.add(field); - field = body.getField("author"); - field.setValue(study.getAuthor().toString()); - entry.add(field); - field = body.getField("title"); - field.setValue(study.getTitle()); - entry.add(field); - field = body.getField("contents"); - field.setValue(study.getTitle()); - entry.add(field); - -// Addition of optional fields - setActorsOf(study); - setContextAt(getProjectElementService().getSteps(study)); - } - private Entry (KnowledgeElement kelm) throws CorruptIndexException, LockObtainFailedException, IOException - { - super(index, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); - -// Addition of mandatory fields - entry = new org.apache.lucene.document.Document(); - Field field; - field = body.getField("index"); - field.setValue(String.valueOf(kelm.getIndex())); - entry.add(field); - field = body.getField("class"); - field.setValue("KnowledgeElement"); - entry.add(field); - field = body.getField("type"); - field.setValue(kelm.getType().getName()); - entry.add(field); - field = body.getField("ref"); - field.setValue(kelm.getReference()); - entry.add(field); - field = body.getField("area"); - field.setValue(kelm.getVisibility().toString()); - entry.add(field); - field = body.getField("state"); - field.setValue(kelm.getProgressState().toString()); - entry.add(field); - field = body.getField("author"); - field.setValue(kelm.getAuthor().toString()); - entry.add(field); - field = body.getField("title"); - field.setValue(kelm.getTitle()); - entry.add(field); - field = body.getField("contents"); - field.setValue(kelm.getTitle()); - entry.add(field); - -//TODO: Addition of optional fields - Scenario scene = kelm.getOwnerScenario(); - Study study = scene.getOwnerStudy(); - setActorsOf(study); // For restricting the visibility of knowledges attached to private studies - setContextAt(getProjectElementService().getSteps(study)); - setContextAt(getProjectElementService().getSteps(scene)); - } - private void add () throws CorruptIndexException, IOException - { - addDocument(entry); -// Save the new entry - optimize(); // Should be called before committing the index - close(); // Commits the index - } - private void update () throws CorruptIndexException, IOException - { - String value = entry.getField("ref").stringValue(); // Only field with unique value - Term term = new Term("ref").createTerm(value); - updateDocument(term, entry); -// Save the updated entry - optimize(); // Should be called before committing the index - close(); // Commits the index - } - private void setContextAt (Step[] step) - { - for (int i=0; i contexts = step[i].getAllSimulationContexts(); - for (Iterator j=contexts.iterator(); j.hasNext();) { - SimulationContext context = j.next(); - String type = String.valueOf(context.getType().getIndex()); - String value = context.getValue(); - entry.add( new Field(type, value, Field.Store.NO, Field.Index.NOT_ANALYZED) ); - } - } - } - private void setActorsOf (Study study) - { -//RKV: This set is always not null. Let's assume that it must be initialized before reindexing: Set actors = study.getActors(); - Set actors = study.getActor(); //RKV - for (Iterator i=actors.iterator(); i.hasNext(); ) { - String value = i.next().toString(); - entry.add( new Field("actor", value, Field.Store.NO, Field.Index.NOT_ANALYZED) ); - } - } - } - public static class ObjectProxy implements Proxy, Serializable { -// -------------------------------------------------------------- - private Long rid; - private String sid; - private ProgressState state; - private String title; - private String type; - private String name; - private static final long serialVersionUID = -4386494192709562221L; - - public ObjectProxy (org.apache.lucene.document.Document ludoc) { - rid = Long.valueOf(ludoc.get("index")); - sid = ludoc.get("ref"); - state = ProgressState.valueOf(ludoc.get("state")); - title = ludoc.get("title"); - name = ludoc.get("author"); - } - public String getAuthorName () { - return name; - } - public Long getIndex () { - return rid; - } - public ProgressState getProgressState () { - return state; - } - public String getReference () { - return sid; - } - public String getTitle () { - return title; - } - public String getType () { - return type; - } - } - -// ============================================================================================================================== -// Construction -// ============================================================================================================================== - - public void configure () throws IOException { - File indir = getRepositoryService().getRepositoryIndexDirectory(); - index = FSDirectory.open(indir); - body = new org.apache.lucene.document.Document(); - body.add( new Field("index", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("class", "", Field.Store.NO, Field.Index.NOT_ANALYZED) ); - body.add( new Field("type", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("ref", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("area", "", Field.Store.NO, Field.Index.NOT_ANALYZED) ); - body.add( new Field("state", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("author", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("title", "", Field.Store.YES, Field.Index.NOT_ANALYZED) ); - body.add( new Field("contents","", Field.Store.NO, Field.Index.ANALYZED) ); - if ( !this.exists() ) this.create(); // Happens when re-indexing all studies - } - - public void create () throws IOException { -// ------------------------------- - Directory index = FSDirectory.open(getRepositoryService().getRepositoryIndexDirectory()); - IndexWriter writer = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); - writer.close(); // ==== Creates an empty index - } - -// ============================================================================================================================== -// Member functions -// ============================================================================================================================== - - public void add (Study study) throws IOException { -// -------------------------------- - IndexServiceImpl.Entry entry = new Entry(study); - entry.add(); - if (logger.isInfoEnabled()) { - logger.info("Study \"" + study.getIndex() + "\" indexed."); - } - } - - public void add (KnowledgeElement kelm) throws IOException { -// ------------------------------------------ - IndexServiceImpl.Entry entry = new Entry(kelm); - entry.add(); - if (logger.isInfoEnabled()) { - logger.info("Knowledge \"" + kelm.getIndex() + "\" indexed."); - } - } - - public boolean exists () { -// --------------------------- - try { - return IndexReader.indexExists(index); - } - catch (IOException error) { - error.printStackTrace(); - return false; + private RepositoryService _repositoryService; + + protected static StandardAnalyzer analyzer = new StandardAnalyzer( + Version.LUCENE_29); + private static final Logger logger = Logger + .getLogger(IndexServiceImpl.class); + + private class Entry extends IndexWriter { + private org.apache.lucene.document.Document entry; + + private Entry(Study study) throws CorruptIndexException, + LockObtainFailedException, IOException { + super(index, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); + + // Addition of mandatory fields + entry = new org.apache.lucene.document.Document(); + Field field; + field = body.getField("index"); + field.setValue(String.valueOf(study.getIndex())); + entry.add(field); + field = body.getField("class"); + field.setValue("Study"); + entry.add(field); + field = body.getField("type"); + field.setValue(""); // Reserved for configurable Study type + entry.add(field); + field = body.getField("ref"); + field.setValue(study.getReference()); + entry.add(field); + field = body.getField("area"); + field.setValue(study.getVisibility().toString()); + entry.add(field); + field = body.getField("state"); + field.setValue(study.getProgressState().toString()); + entry.add(field); + field = body.getField("author"); + field.setValue(study.getAuthor().toString()); + entry.add(field); + field = body.getField("title"); + field.setValue(study.getTitle()); + entry.add(field); + field = body.getField("contents"); + field.setValue(study.getTitle()); + entry.add(field); + + // Addition of optional fields + setActorsOf(study); + setContextAt(getProjectElementService().getSteps(study)); + } + + private Entry(KnowledgeElement kelm) throws CorruptIndexException, + LockObtainFailedException, IOException { + super(index, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); + + // Addition of mandatory fields + entry = new org.apache.lucene.document.Document(); + Field field; + field = body.getField("index"); + field.setValue(String.valueOf(kelm.getIndex())); + entry.add(field); + field = body.getField("class"); + field.setValue("KnowledgeElement"); + entry.add(field); + field = body.getField("type"); + field.setValue(kelm.getType().getName()); + entry.add(field); + field = body.getField("ref"); + field.setValue(kelm.getReference()); + entry.add(field); + field = body.getField("area"); + field.setValue(kelm.getVisibility().toString()); + entry.add(field); + field = body.getField("state"); + field.setValue(kelm.getProgressState().toString()); + entry.add(field); + field = body.getField("author"); + field.setValue(kelm.getAuthor().toString()); + entry.add(field); + field = body.getField("title"); + field.setValue(kelm.getTitle()); + entry.add(field); + field = body.getField("contents"); + field.setValue(kelm.getTitle()); + entry.add(field); + + // TODO: Addition of optional fields + Scenario scene = kelm.getOwnerScenario(); + Study study = scene.getOwnerStudy(); + setActorsOf(study); // For restricting the visibility of knowledges attached to private studies + setContextAt(getProjectElementService().getSteps(study)); + setContextAt(getProjectElementService().getSteps(scene)); + } + + private void add() throws CorruptIndexException, IOException { + addDocument(entry); + // Save the new entry + optimize(); // Should be called before committing the index + close(); // Commits the index + } + + private void update() throws CorruptIndexException, IOException { + String value = entry.getField("ref").stringValue(); // Only field with unique value + Term term = new Term("ref").createTerm(value); + updateDocument(term, entry); + // Save the updated entry + optimize(); // Should be called before committing the index + close(); // Commits the index + } + + private void setContextAt(Step[] step) { + for (int i = 0; i < step.length; i++) { + List contexts = step[i] + .getAllSimulationContexts(); + for (Iterator j = contexts.iterator(); j + .hasNext();) { + SimulationContext context = j.next(); + String type = String.valueOf(context.getType().getIndex()); + String value = context.getValue(); + entry.add(new Field(type, value, Field.Store.NO, + Field.Index.NOT_ANALYZED)); + } + } + } + + private void setActorsOf(Study study) { + // RKV: This set is always not null. Let's assume that it must be initialized before reindexing: Set actors = + // study.getActors(); + Set actors = study.getActor(); // RKV + if (logger.isDebugEnabled()) { + logger.debug("Study " + study.getReference() + + " actors number to be added to the lucen index: " + + actors.size()); + } + for (Iterator i = actors.iterator(); i.hasNext();) { + String value = i.next().toString(); + entry.add(new Field("actor", value, Field.Store.NO, + Field.Index.NOT_ANALYZED)); + if (logger.isDebugEnabled()) { + logger.debug(" actor added to the lucen index: " + value); + } + } + } + } + + public static class ObjectProxy implements Proxy, Serializable { + // -------------------------------------------------------------- + private Long rid; + private String sid; + private ProgressState state; + private String title; + private String type; + private String name; + private static final long serialVersionUID = -4386494192709562221L; + + public ObjectProxy(org.apache.lucene.document.Document ludoc) { + rid = Long.valueOf(ludoc.get("index")); + sid = ludoc.get("ref"); + state = ProgressState.valueOf(ludoc.get("state")); + title = ludoc.get("title"); + name = ludoc.get("author"); + } + + public String getAuthorName() { + return name; + } + + public Long getIndex() { + return rid; + } + + public ProgressState getProgressState() { + return state; + } + + public String getReference() { + return sid; + } + + public String getTitle() { + return title; + } + + public String getType() { + return type; + } + } + + // ============================================================================================================================== + // Construction + // ============================================================================================================================== + + public void configure() throws IOException { + File indir = getRepositoryService().getRepositoryIndexDirectory(); + index = FSDirectory.open(indir); + body = new org.apache.lucene.document.Document(); + body.add(new Field("index", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body.add(new Field("class", "", Field.Store.NO, + Field.Index.NOT_ANALYZED)); + body.add(new Field("type", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body + .add(new Field("ref", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body + .add(new Field("area", "", Field.Store.NO, + Field.Index.NOT_ANALYZED)); + body.add(new Field("state", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body.add(new Field("author", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body.add(new Field("title", "", Field.Store.YES, + Field.Index.NOT_ANALYZED)); + body + .add(new Field("contents", "", Field.Store.NO, + Field.Index.ANALYZED)); + if (!this.exists()) + this.create(); // Happens when re-indexing all studies + } + + public void create() throws IOException { + // ------------------------------- + Directory index = FSDirectory.open(getRepositoryService() + .getRepositoryIndexDirectory()); + IndexWriter writer = new IndexWriter(index, analyzer, true, + IndexWriter.MaxFieldLength.UNLIMITED); + writer.close(); // ==== Creates an empty index + } + + // ============================================================================================================================== + // Member functions + // ============================================================================================================================== + + public void add(Study study) throws IOException { + // -------------------------------- + IndexServiceImpl.Entry entry = new Entry(study); + entry.add(); + if (logger.isInfoEnabled()) { + logger.info("Study \"" + study.getIndex() + "\" indexed."); + } + } + + public void add(KnowledgeElement kelm) throws IOException { + // ------------------------------------------ + IndexServiceImpl.Entry entry = new Entry(kelm); + entry.add(); + if (logger.isInfoEnabled()) { + logger.info("Knowledge \"" + kelm.getIndex() + "\" indexed."); + } + } + + public boolean exists() { + // --------------------------- + try { + return IndexReader.indexExists(index); + } catch (IOException error) { + error.printStackTrace(); + return false; + } } - } - - public void update (Study study) throws IOException { -// ----------------------------------- - IndexServiceImpl.Entry entry = new Entry(study); - entry.update(); - if (logger.isInfoEnabled()) { - logger.info("Study \"" + study.getIndex() + "\" re-indexed."); - } - } - - public void update (KnowledgeElement kelm) throws IOException { -// --------------------------------------------- - IndexServiceImpl.Entry entry = new Entry(kelm); - entry.update(); - if (logger.isInfoEnabled()) { - logger.info("Knowledge \"" + kelm.getIndex() + "\" re-indexed."); - } - } + + public void update(Study study) throws IOException { + // ----------------------------------- + IndexServiceImpl.Entry entry = new Entry(study); + entry.update(); + if (logger.isInfoEnabled()) { + logger.info("Study \"" + study.getIndex() + "\" re-indexed."); + } + } + + public void update(KnowledgeElement kelm) throws IOException { + // --------------------------------------------- + IndexServiceImpl.Entry entry = new Entry(kelm); + entry.update(); + if (logger.isInfoEnabled()) { + logger.info("Knowledge \"" + kelm.getIndex() + "\" re-indexed."); + } + } + /** * Get the projectElementService. + * * @return the projectElementService */ public ProjectElementService getProjectElementService() { @@ -293,14 +330,18 @@ public class IndexServiceImpl implements IndexService { /** * Set the projectElementService. - * @param projectElementService the projectElementService to set + * + * @param projectElementService + * the projectElementService to set */ - public void setProjectElementService(ProjectElementService projectElementService) { + public void setProjectElementService( + ProjectElementService projectElementService) { _projectElementService = projectElementService; } /** * Get the repositoryService. + * * @return the repositoryService */ public RepositoryService getRepositoryService() { @@ -309,7 +350,9 @@ public class IndexServiceImpl implements IndexService { /** * Set the repositoryService. - * @param repositoryService the repositoryService to set + * + * @param repositoryService + * the repositoryService to set */ public void setRepositoryService(RepositoryService repositoryService) { _repositoryService = repositoryService; diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 6ad603f..d4abfbc 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -85,7 +85,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + diff --git a/Workspace/Siman/WebContent/jsp/searchForm.jsp b/Workspace/Siman/WebContent/jsp/searchForm.jsp index c75c17a..4e8e668 100644 --- a/Workspace/Siman/WebContent/jsp/searchForm.jsp +++ b/Workspace/Siman/WebContent/jsp/searchForm.jsp @@ -63,10 +63,10 @@
- - + + - + diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index ed1df7a..af7bd67 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -606,7 +606,7 @@ public class ApplicationSettings { fprop.put("visibility", "PRIVATE"); fprop.put("matchamong", "all"); fprop.put("matcontext", "all"); - fprop.put("state", "END"); + fprop.put("state", "APPROVED"); fprop.put("author", "0"); fprop.put("reference", ""); fprop.put("title", ""); diff --git a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java index 188e5f0..e6e8c06 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java @@ -3,11 +3,8 @@ package org.splat.simer; import java.util.List; import java.util.Map; -import org.hibernate.Session; -import org.hibernate.Transaction; import org.splat.kernel.InvalidPropertyException; import org.splat.dal.bo.kernel.User; -import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.ProgressState; import org.splat.service.SearchService; import org.splat.service.SimulationContextService; @@ -18,17 +15,27 @@ import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Visibility; - +/** + * Search studies form action. + * + * @author Roman Kozlov (RKV) + */ public class SearchStudyAction extends SearchBaseAction { - private String visibility = null; // "Private", "Public", "All" - private String state = null; // "In-Work", "In-Draft", "In-Check"... - private String matchamong = null; // "all" or "any" - private String matcontext = null; // "all" or "any" - private String refid = null; // Study reference - private String words = null; // Full text search words - private SearchService _searchService; + private String visibility = null; // "Private", "Public", "All" + private String state = null; // "In-Work", "In-Draft", "In-Check"... + private String matchamong = null; // "all" or "any" + private String matcontext = null; // "all" or "any" + private String refid = null; // Study reference + private String words = null; // Full text search words + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected search service. + */ + private SearchService _searchService; /** * Injected simulation context service. */ @@ -43,184 +50,207 @@ public class SearchStudyAction extends SearchBaseAction { */ private static final long serialVersionUID = -1910481357051393077L; - enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext } - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doInitialize () { -// ----------------------------- - Session connex = Database.getCurSession(); - Transaction transax = connex.beginTransaction(); - try { - loadFilter(); - doSearch(); - -// Final initialization of the form - setCandidates(); - setContextTypeOptions(getInvolvedContexts()); - - transax.commit(); - return SUCCESS; - } - catch (Exception error) { -// No need to roll back the transaction as it is read only - logger.error("Reason: ", error); - return ERROR; - } - } - - protected String doSearch () throws InvalidPropertyException { -// ---------------------------- - Map session = getSession(); - User user = getConnectedUser(); - - Study.Properties sprop = new Study.Properties(); - -// Search matching all criteria - if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) ); - if (words.length() > 0) sprop.setTitle(words); - if (refid.length() > 0) sprop.setReference(refid); - if (context.size() > 0) sprop.setSimulationContexts(context); - int index = Integer.valueOf(author); - if (index > 0) { - User him = getUserService().selectUser(index); - sprop.setManager(him); - } -// Set of the visibility - if (visibility.equals("all")) { - Study.Properties other = sprop.copy(); - - other.setVisibility(Visibility.PUBLIC); - sprop.setVisibility(Visibility.PRIVATE); - sprop.setActor(user); - - result = getSearchService().selectStudiesWhere(sprop, other); - } - else { - Visibility reparea = null; - if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC; - else reparea = Visibility.valueOf(visibility); - sprop.setVisibility(reparea); - if (reparea == Visibility.PRIVATE) sprop.setActor(user); - - result = getSearchService().selectStudiesWhere(sprop); - } - session.put("search.result", result); // For redisplaying the page without re-executing the search - return "refresh"; - } - -// ============================================================================================================================== -// Getters -// ============================================================================================================================== - - public String getContextMatch () { -// -------------------------------- - return matcontext; - } - public String getCriteriaMatch () { -// --------------------------------- - return matchamong; - } - public String getReference () { -// ----------------------------- - return refid; - } - public String getState () { -// ------------------------- - return state; - } - public String getVisibility () { -// ------------------------------ - return visibility; - } - public String getWords () { -// ------------------------- - return words; - } - -// ============================================================================================================================== -// Setters -// ============================================================================================================================== - - public void setContextMatch (String value) { -// ------------------------------------------ - this.matcontext = value; - } - public void setCriteriaMatch (String value) { -// ------------------------------------------- - this.matchamong = value; - } - public void setReference (String value) { -// --------------------------------------- - this.refid = value; - } - public void setState (String value) { -// ----------------------------------- - this.state = value; - } - public void setVisibility (String value) { -// ---------------------------------------- - this.visibility = value; - } - public void setWords (String value) { -// ----------------------------------- - this.words = value; - } - -// ============================================================================================================================== -// Implementation of abstract services -// ============================================================================================================================== - - protected List getInvolvedContexts () { -// ------------------------------------------------------------ - List steps = getProjectSettings().getStepsOf(Study.class); - ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]); - - return getSimulationContextService().selectTypesOf(number); + enum UserAction { + refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext + } + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== + + /** + * Initialize study search form. + * @return SUCCESS if no exception, otherwise return ERROR + */ + public String doInitialize() { + try { + loadFilter(); + doSearch(); + + // Final initialization of the form + setCandidates(); + setContextTypeOptions(getInvolvedContexts()); + + return SUCCESS; + } catch (Exception error) { + // No need to roll back the transaction as it is read only + logger.error("Reason: ", error); + return ERROR; + } + } + + protected String doSearch() throws InvalidPropertyException { + // ---------------------------- + Map session = getSession(); + User user = getConnectedUser(); + + Study.Properties sprop = new Study.Properties(); + + // Search matching all criteria + if (!this.state.equals("ANY")) + sprop.setState(ProgressState.valueOf(this.state)); + if (words.length() > 0) + sprop.setTitle(words); + if (refid.length() > 0) + sprop.setReference(refid); + if (context.size() > 0) + sprop.setSimulationContexts(context); + int index = Integer.valueOf(author); + if (index > 0) { + User him = getUserService().selectUser(index); + sprop.setManager(him); + } + // Set of the visibility + if (visibility.equals("all")) { + Study.Properties other = sprop.copy(); + + other.setVisibility(Visibility.PUBLIC); + sprop.setVisibility(Visibility.PRIVATE); + sprop.setActor(user); + + result = getSearchService().selectStudiesWhere(sprop, other); + } else { + Visibility reparea = null; + if (visibility.equals("onlypublic")) + reparea = Visibility.PUBLIC; + else + reparea = Visibility.valueOf(visibility); + sprop.setVisibility(reparea); + if (reparea == Visibility.PRIVATE) + sprop.setActor(user); + + result = getSearchService().selectStudiesWhere(sprop); + } + session.put("search.result", result); // For redisplaying the page without re-executing the search + return "refresh"; + } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + public String getContextMatch() { + // -------------------------------- + return matcontext; + } + + public String getCriteriaMatch() { + // --------------------------------- + return matchamong; + } + + public String getReference() { + // ----------------------------- + return refid; + } + + public String getState() { + // ------------------------- + return state; + } + + public String getVisibility() { + // ------------------------------ + return visibility; + } + + public String getWords() { + // ------------------------- + return words; + } + + // ============================================================================================================================== + // Setters + // ============================================================================================================================== + + public void setContextMatch(String value) { + // ------------------------------------------ + this.matcontext = value; } - @SuppressWarnings("unchecked") - protected void loadFilter () { -// ---------------------------- - Map session = getSession(); - User user = getConnectedUser(); - Map filter = (Map)session.get("study.filter"); // A default filter is supposed being set at start - - visibility = (String)filter.get("visibility"); - matchamong = (String)filter.get("matchamong"); - matcontext = (String)filter.get("matcontext"); - state = (String)filter.get("state"); - author = (String)filter.get("author"); - refid = (String)filter.get("reference"); - words = (String)filter.get("title"); - context = (List)filter.get("context"); - - if (user == null) { - visibility = "onlypublic"; - } - } - - @SuppressWarnings("unchecked") - protected void saveFilter () { -// ---------------------------- - Map session = getSession(); - Map filter = (Map)session.get("study.filter"); // A default filter is supposed being set at start - - filter.put("visibility", this.visibility); - filter.put("matchamong", this.matchamong); - filter.put("matcontext", this.matcontext); - filter.put("state", this.state); - filter.put("author", this.author); - filter.put("reference", this.refid); - filter.put("title", this.words); - - context = (List)filter.get("context"); // Only criteria not part of the form - - } - /** + public void setCriteriaMatch(String value) { + // ------------------------------------------- + this.matchamong = value; + } + + public void setReference(String value) { + // --------------------------------------- + this.refid = value; + } + + public void setState(String value) { + // ----------------------------------- + this.state = value; + } + + public void setVisibility(String value) { + // ---------------------------------------- + this.visibility = value; + } + + public void setWords(String value) { + // ----------------------------------- + this.words = value; + } + + // ============================================================================================================================== + // Implementation of abstract services + // ============================================================================================================================== + + protected List getInvolvedContexts() { + // ------------------------------------------------------------ + List steps = getProjectSettings() + .getStepsOf(Study.class); + ProjectSettingsService.Step[] number = steps + .toArray(new ProjectSettingsService.Step[steps.size()]); + + return getSimulationContextService().selectTypesOf(number); + } + + @SuppressWarnings("unchecked") + protected void loadFilter() { + // ---------------------------- + Map session = getSession(); + User user = getConnectedUser(); + Map filter = (Map) session + .get("study.filter"); // A default filter is supposed being set at start + + visibility = (String) filter.get("visibility"); + matchamong = (String) filter.get("matchamong"); + matcontext = (String) filter.get("matcontext"); + state = (String) filter.get("state"); + author = (String) filter.get("author"); + refid = (String) filter.get("reference"); + words = (String) filter.get("title"); + context = (List) filter.get("context"); + + if (user == null) { + visibility = "onlypublic"; + } + } + + @SuppressWarnings("unchecked") + protected void saveFilter() { + // ---------------------------- + Map session = getSession(); + Map filter = (Map) session + .get("study.filter"); // A default filter is supposed being set at start + + filter.put("visibility", this.visibility); + filter.put("matchamong", this.matchamong); + filter.put("matcontext", this.matcontext); + filter.put("state", this.state); + filter.put("author", this.author); + filter.put("reference", this.refid); + filter.put("title", this.words); + + context = (List) filter.get("context"); // Only criteria not part of the form + + } + + /** * Get the searchService. + * * @return the searchService */ public SearchService getSearchService() { @@ -229,13 +259,17 @@ public class SearchStudyAction extends SearchBaseAction { /** * Set the searchService. - * @param searchService the searchService to set + * + * @param searchService + * the searchService to set */ public void setSearchService(SearchService searchService) { _searchService = searchService; } - /** - * Get project settings. + + /** + * Get project settings. + * * @return Project settings service */ private ProjectSettingsService getProjectSettings() { @@ -244,10 +278,11 @@ public class SearchStudyAction extends SearchBaseAction { /** * Set project settings service. - * @param projectSettingsService project settings service + * + * @param projectSettingsService + * project settings service */ - public void setProjectSettings( - ProjectSettingsService projectSettingsService) { + public void setProjectSettings(ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } @@ -273,6 +308,7 @@ public class SearchStudyAction extends SearchBaseAction { /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -281,7 +317,9 @@ public class SearchStudyAction extends SearchBaseAction { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ public void setUserService(UserService userService) { _userService = userService; diff --git a/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java b/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java index e0cb6c9..f862a14 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java @@ -3,100 +3,75 @@ package org.splat.simer.admin; import java.util.List; import java.util.Map; -import org.hibernate.Session; -import org.hibernate.Transaction; import org.splat.service.SearchService; -import org.splat.service.SearchServiceImpl; -import org.splat.service.StudyService; import org.splat.simer.Action; -import org.splat.dal.dao.som.Database; -import org.splat.dal.bo.som.Study; - +/** + * Action for updating lucene index. + * + * @author Roman Kozlov (RKV) + */ public class DatabaseIndexingAction extends Action { /** * Serial version ID. */ - private static final long serialVersionUID = 4194268823457749655L; + private static final long serialVersionUID = 4194268823457749655L; - private List newstudies; - private String indices; - private SearchService _searchService; + private List newstudies; + private String indices; private ImportedStudy _importedStudy; - private StudyService _studyService; - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doInitialize () { -// ----------------------------- - Session connex = Database.getCurSession(); - Transaction transax = connex.beginTransaction(); - - newstudies = getImportedStudy().selectAll(); - indices = ""; - - transax.commit(); - return SUCCESS; - } - - public String doIndexing () { -// --------------------------- - Session connex = Database.getCurSession(); - Transaction transax = connex.beginTransaction(); - String[] ridlist = indices.split(","); - @SuppressWarnings("unchecked") - Map filter = (Map)getSession().get("study.filter"); - - for (int i=0; i getNewStudies () { -// ------------------------------------------- - return newstudies; - } - public String getIndices () { -// --------------------------- - return indices; - } - - public void setIndices (String indices) { -// --------------------------------------- - this.indices = indices; - } + /** + * Injected search service. + */ + private SearchService _searchService; + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== /** - * Get the searchService. - * @return the searchService + * Initialize the action. + * @return SUCCESS */ - public SearchService getSearchService() { - return _searchService; + public String doInitialize() { + newstudies = getImportedStudy().selectAll(); + indices = ""; + return SUCCESS; } /** - * Set the searchService. - * @param searchService the searchService to set + * Reindex studies. + * @return SUCCESS */ - public void setSearchService(SearchService searchService) { - _searchService = searchService; + public String doIndexing() { + String[] ridlist = indices.split(","); + @SuppressWarnings("unchecked") + Map filter = (Map) getSession().get( + "study.filter"); + getSearchService().reindexStudies(ridlist); + filter.put("owner", "all"); // Just in case of 1st study search + + return SUCCESS; + } + + // ============================================================================================================================== + // Getters and setters + // ============================================================================================================================== + + /** + * Get the new studies. + * + * @return the new studies + */ + public List getNewStudies() { + // ------------------------------------------- + return newstudies; } /** * Get the importedStudy. + * * @return the importedStudy */ public ImportedStudy getImportedStudy() { @@ -105,28 +80,46 @@ public class DatabaseIndexingAction extends Action { /** * Set the importedStudy. - * @param importedStudy the importedStudy to set + * + * @param importedStudy + * the importedStudy to set */ public void setImportedStudy(ImportedStudy importedStudy) { _importedStudy = importedStudy; } /** - * Get the studyService. + * Get the indices. + * @return the indices + */ + public String getIndices() { + return indices; + } + + /** + * Set the indices. + * @param indices the indices to set + */ + public void setIndices(String indices) { + this.indices = indices; + } + + /** + * Get the searchService. * - * @return the studyService + * @return the searchService */ - public StudyService getStudyService() { - return _studyService; + public SearchService getSearchService() { + return _searchService; } /** - * Set the studyService. + * Set the searchService. * - * @param studyService - * the studyService to set + * @param searchService + * the searchService to set */ - public void setStudyService(StudyService studyService) { - _studyService = studyService; + public void setSearchService(SearchService searchService) { + _searchService = searchService; } } \ No newline at end of file diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 71782db..33a9369 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -1,6 +1,7 @@ - + - + + scope="prototype"> + + - + - + - - + + - + - - + + - + - + @@ -84,20 +92,24 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - - + + - + @@ -105,52 +117,63 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - + - + - - + + - + - + - + - - - + + + - + @@ -158,36 +181,41 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> scope="prototype"> - + - + - + - - + + - + - - - + + + - + - - + + - + - - - + - + - - + - + - - + - + -- 2.30.2