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;
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[])
- */
- @Deprecated
- public List<Proxy> selectKnowledgeElementsWhere(
- final KnowledgeElement.Properties... kprop) {
- List<Proxy> result = new ArrayList<Proxy>();
- 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<SimulationContext> context = kprop[i]
- .getSimulationContexts();
- if (context != null && context.size() > 0) {
- BooleanQuery critext = new BooleanQuery();
- for (Iterator<SimulationContext> 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}
*
} 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));
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());
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)*", ""));
/* 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 },
/* 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 */
* 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()));
}
}