From: rkv Date: Mon, 11 Mar 2013 07:18:52 +0000 (+0000) Subject: Old knowledge lucene search has been removed. X-Git-Tag: Root_Delivery2_2013_04_22~116 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f1610d9f37ba4c45a17c39e660a2f47d37528f6a;p=tools%2Fsiman.git Old knowledge lucene search has been removed. --- diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchService.java b/Workspace/Siman-Common/src/org/splat/service/SearchService.java index 3bd9edc..b644c5f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchService.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchService.java @@ -11,7 +11,6 @@ package org.splat.service; import java.util.List; -import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.Study; import org.splat.service.dto.ImportedStudyDTO; import org.splat.service.dto.KnowledgeSearchFilterDTO; @@ -50,16 +49,6 @@ public interface SearchService { List selectKnowledgeElementsWhere( final KnowledgeSearchFilterDTO filter); - /** - * Find knowledge elements with given properties. - * - * @param kprop - * search filter parameters - * @return the list of found knowledge elements as proxiy results of lucene search - */ - List selectKnowledgeElementsWhere( - KnowledgeElement.Properties... kprop); - /** * Find studies with given properties. * diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java index 3405356..eccbccc 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java @@ -41,7 +41,6 @@ import org.hibernate.criterion.Restrictions; import org.hibernate.type.Type; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.KnowledgeElement; -import org.splat.dal.bo.som.KnowledgeElementType; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; @@ -233,134 +232,6 @@ public class SearchServiceImpl implements SearchService { } } - /** - * {@inheritDoc} - * - * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[]) - */ - @Deprecated - public List selectKnowledgeElementsWhere( - final 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 (LOG.isInfoEnabled()) { - LOG.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 < hits.length; i++) { - result.add(new IndexServiceImpl.ObjectProxy(searcher - .doc(hits[i].doc))); - } - searcher.close(); - } catch (Exception error) { - LOG.error("Error during Lucene search, reason:", error); - } - return result; - } - /** * {@inheritDoc} * @@ -433,7 +304,7 @@ public class SearchServiceImpl implements SearchService { } else { // OR topJunction = Restrictions.disjunction(); } - if (!StudySearchFilterDTO.ANY_STATE.equals(filter.getState())) { + if (!SearchFilterDTO.ANY_STATE.equals(filter.getState())) { ProgressState state = ProgressState.valueOf(filter.getState()); // State if (state != null) { topJunction.add(Restrictions.eq("state", state)); @@ -444,7 +315,17 @@ public class SearchServiceImpl implements SearchService { topJunction.add(Restrictions.eq("sid", refid)); } - addDatesCriteria(topJunction, filter); + // Filter by creation date + addCreationDateCriteria(topJunction, filter, "credate"); + // Filter by modification date + if (filter.getUpdatedAfter() != null) { + topJunction.add(Restrictions + .gt("lasdate", filter.getUpdatedAfter())); + } + if (filter.getUpdatedBefore() != null) { + topJunction.add(Restrictions.lt("lasdate", filter + .getUpdatedBefore())); + } // Filter by study author long authorId = Long.valueOf(filter.getAuthor()); @@ -476,6 +357,13 @@ public class SearchServiceImpl implements SearchService { topJunction.add(Restrictions.eq("kelm.type.rid", ktypeId)); } + if (!SearchFilterDTO.ANY_STATE.equals(filter.getState())) { + ProgressState state = ProgressState.valueOf(filter.getState()); // State + if (state != null) { + topJunction.add(Restrictions.eq("kelm.state", state)); + } + } + String refid = filter.getReference(); // Reference if (refid != null && !refid.isEmpty()) { long id = Long.valueOf(refid.replaceAll("^KE(0)*", "")); @@ -521,7 +409,12 @@ public class SearchServiceImpl implements SearchService { /* If the user is a validation cycle participant */ Restrictions .sqlRestriction( - "{alias}.rid in (select vcrel.owner from cycle_rel vcrel inner join cycle vc on vcrel.refer = vc.rid where {alias}.rid = vcrel.owner AND (vc.publisher = ? OR vc.reviewer = ? OR vc.approver = ? OR vc.signatory = ?) group by vcrel.owner)", + "{alias}.rid in (" + + "select vcrel.owner from cycle_rel vcrel " + + "inner join cycle vc on vcrel.refer = vc.rid " + + "where {alias}.rid = vcrel.owner " + + "AND (vc.publisher = ? OR vc.reviewer = ? OR vc.approver = ? OR vc.signatory = ?) " + + "group by vcrel.owner)", new Object[] { actorId, actorId, actorId, actorId }, @@ -534,7 +427,9 @@ public class SearchServiceImpl implements SearchService { /* If the user is contributor */ Restrictions .sqlRestriction( - "{alias}.rid in (select rel.owner from contributor_rel rel where {alias}.rid = rel.owner AND rel.refer = ?)", + "{alias}.rid in (" + + "select rel.owner from contributor_rel rel " + + "where {alias}.rid = rel.owner AND rel.refer = ?)", actorId, Hibernate.LONG)) .add( /* If the user is author */ @@ -557,41 +452,19 @@ public class SearchServiceImpl implements SearchService { * the junction filter condition * @param filter * search criteria - */ - private void addDatesCriteria(final Junction topJunction, - final StudySearchFilterDTO filter) { - // Filter by creation date - addCreationDateCriteria(topJunction, filter, "credate"); - // Filter by modification date - if (filter.getUpdatedAfter() != null) { - topJunction.add(Restrictions - .gt("lasdate", filter.getUpdatedAfter())); - } - if (filter.getUpdatedBefore() != null) { - topJunction.add(Restrictions.lt("lasdate", filter - .getUpdatedBefore())); - } - - } - - /** - * Add search criteria by dates to the junction filter condition. - * - * @param topJunction - * the junction filter condition - * @param filter - * search criteria + * @param propName + * creation date property name */ private void addCreationDateCriteria(final Junction topJunction, final SearchFilterDTO filter, final String propName) { // Filter by creation date if (filter.getCreatedAfter() != null) { - topJunction.add(Restrictions - .gt(propName, filter.getCreatedAfter())); + topJunction + .add(Restrictions.gt(propName, filter.getCreatedAfter())); } if (filter.getCreatedBefore() != null) { - topJunction.add(Restrictions.lt(propName, filter - .getCreatedBefore())); + topJunction.add(Restrictions + .lt(propName, filter.getCreatedBefore())); } } diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java index 1fd296e..81cf396 100644 --- a/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java +++ b/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.SimulationContext; /** @@ -31,6 +32,10 @@ public class SearchFilterDTO { * "any": match any criteria. */ public final static String MATCH_ANY = "any"; + /** + * "ANY": match any status. + */ + public final static String ANY_STATE = "ANY"; /** * Study author id to search. */ @@ -67,6 +72,10 @@ public class SearchFilterDTO { * Currently connected user id. */ private long _connectedUserId = 0; + /** + * "In-Work", "In-Draft", "In-Check"... + */ + private String _state = ANY_STATE; /** * Get author id of objects to find. @@ -259,4 +268,37 @@ public class SearchFilterDTO { public void setConnectedUserId(final long connectedUserId) { _connectedUserId = connectedUserId; } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + /** + * Get progress state criteria. + * + * @return study progress state to search + */ + public String getState() { + return _state; + } + + /** + * Set progress state criteria. + * + * @param value + * the progress state to search + */ + public void setState(final String value) { + this._state = value; + } + + /** + * Set progress state criteria. + * + * @param value + * the progress state to search + */ + public void setState(final ProgressState value) { + this._state = value.toString(); + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java index f83c171..4ee3972 100644 --- a/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java +++ b/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java @@ -19,14 +19,6 @@ import java.util.Date; */ public class StudySearchFilterDTO extends SearchFilterDTO { - /** - * "ANY": match any status. - */ - public final static String ANY_STATE = "ANY"; - /** - * "In-Work", "In-Draft", "In-Check"... - */ - private String _state = ANY_STATE; /** * Search studies updated after this date. */ @@ -40,25 +32,6 @@ public class StudySearchFilterDTO extends SearchFilterDTO { // Getters // ============================================================================================================================== - /** - * Get progress state criteria. - * - * @return study progress state to search - */ - public String getState() { - return _state; - } - - /** - * Set progress state criteria. - * - * @param value - * the progress state to search - */ - public void setState(final String value) { - this._state = value; - } - /** * Get the updatedAfter. * diff --git a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java index d4cc3b9..43cc310 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java @@ -21,6 +21,7 @@ import org.splat.dal.dao.som.Database; import org.splat.service.KnowledgeElementService; import org.splat.service.SearchService; import org.splat.service.SimulationContextService; +import org.splat.service.dto.KnowledgeSearchFilterDTO; import org.splat.service.dto.Proxy; import org.splat.service.dto.SimulationContextFacade; import org.splat.service.technical.ProjectSettingsService; @@ -190,10 +191,15 @@ public class SimulationContextAction extends Action { _tocheck.add(new SimulationContextFacade(next, getProjectSettings().getAllSteps())); } - KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); - List kelm = getSearchService().selectKnowledgeElementsWhere( - kprop.setSimulationContexts(selected).setState( - ProgressState.inWORK)); +// KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); +// List kelm = getSearchService().selectKnowledgeElementsWhere( +// kprop.setSimulationContexts(selected).setState( +// ProgressState.inWORK)); + KnowledgeSearchFilterDTO knowFilter = new KnowledgeSearchFilterDTO(); + knowFilter.setSimContexts(selected); + knowFilter.setState(ProgressState.inWORK); + List kelm = getSearchService().selectKnowledgeElementsWhere(knowFilter); + _step = getSimulationContextService().getAttachedStep( _edition.getType());