Sandbox-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 1825 discussions
r308 - in wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src: main/java/org/sharengo/wikitty/jdbc main/resources test/java/org/sharengo/wikitty/jdbc test/resources
by kmorin@users.nuiton.org 04 Nov '09
by kmorin@users.nuiton.org 04 Nov '09
04 Nov '09
Author: kmorin
Date: 2009-11-04 11:19:47 +0100 (Wed, 04 Nov 2009)
New Revision: 308
Added:
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEngineTest.java
Removed:
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEnginTest.java
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/resources/solrconfig.xml
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/jdbc.properties
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/solrconfig.xml
Log:
Separation of solr
Deleted: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -1,389 +0,0 @@
-package org.sharengo.wikitty.jdbc;
-
-import org.apache.solr.client.solrj.SolrQuery;
-import org.apache.solr.client.solrj.SolrServer;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrDocumentList;
-import org.mortbay.log.Log;
-import org.sharengo.wikitty.WikittyException;
-import org.sharengo.wikitty.search.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author "Nicolas Chapurlat" <nicolas.chapurlat(a)logica.com>
- * @author "Guillaume Dufrêne" <dufrene(a)argia.fr>
- * <p/>
- * This class is used to parse Restriction to create lucene request on
- * content. Every operators describe in RestrictionName is handle. Parsing may
- * throw exception when restriction parameters are incorrect.
- */
-public class Restriction2Solr {
-
- private static final int MAX_SUBQUERY_RESULT = 100;
-
- /**
- * use to permit client to modify fieldname during query generation
- */
- static public interface FieldModifier {
- public String convertToSolr(String fieldname);
-
- public String convertToField(String solrName);
- }
-
- final static protected FieldModifier dummyFieldModifier = new FieldModifier() {
- public String convertToSolr(String fieldname) {
- return fieldname;
- }
-
- public String convertToField(String solrName) {
- return solrName;
- }
- };
-
- protected FieldModifier fieldModifer;
-
- public Restriction2Solr() {
- this(dummyFieldModifier);
- }
-
- public Restriction2Solr(FieldModifier fieldModifer) {
- this.fieldModifer = fieldModifer;
- }
-
- public String toSolr(Restriction restriction) {
- return toSolr(restriction, null);
- }
-
- public String toSolr(Restriction restriction, SolrServer solr)
- throws WikittyException {
- // ParameterValidator.checkNullParameter(restriction, "restriction");
- switch (restriction.getName()) {
- case TRUE:
- return true2solr();
- case FALSE:
- return false2solr();
- case NOT:
- Not not = (Not) restriction;
- return not2solr(not);
- case AND:
- And and = (And) restriction;
- return and2solr(and);
- case OR:
- Or or = (Or) restriction;
- return or2solr(or);
- case EQUALS:
- Equals eq = (Equals) restriction;
- return eq2solr(eq);
- case NOT_EQUALS:
- NotEquals neq = (NotEquals) restriction;
- return neq2solr(neq);
- case LESS:
- Less less = (Less) restriction;
- return less2solr(less);
- case LESS_OR_EQUAL:
- LessOrEqual lessEq = (LessOrEqual) restriction;
- return lessEq2solr(lessEq);
- case GREATER:
- Greater great = (Greater) restriction;
- return great2solr(great);
- case GREATER_OR_EQUAL:
- GreaterOrEqual greatEq = (GreaterOrEqual) restriction;
- return greatEq2solr(greatEq);
- case BETWEEN:
- Between between = (Between) restriction;
- return between2solr(between);
- case CONTAINS:
- Contains contains = (Contains) restriction;
- return contains2solr(contains);
- case IN:
- In in = (In) restriction;
- return in2solr(in);
- case STARTS_WITH:
- StartsWith start = (StartsWith) restriction;
- return start2solr(start);
- case ENDS_WITH:
- EndsWith end = (EndsWith) restriction;
- return end2solr(end);
- case ASSOCIATED:
- AssociatedRestriction associated = (AssociatedRestriction) restriction;
- return associated2solr(associated, solr);
- case KEYWORD:
- Keyword keyword = (Keyword) restriction;
- return keyword2solr(keyword);
- default:
- throw new WikittyException("this kind of restriction is not supported : "
- + restriction.getName().toString());
- }
- }
-
- private String in2solr(In in) {
- boolean first = true;
- String result = in.getElement().getName() + ":[";
- for (String value : in.getValue()) {
- if (!first) {
- result += ", ";
- first = false;
- }
- result += value;
- }
- result += "]";
- return result;
- }
-
- private String associated2solr(AssociatedRestriction associated, SolrServer solr) throws WikittyException {
- String subQuery = toSolr(associated.getRestriction());
- SolrQuery query = new SolrQuery(subQuery);
- query.setRows(MAX_SUBQUERY_RESULT);
- QueryResponse resp = null;
- try {
- Log.info("Execute sub-query : " + subQuery);
- resp = solr.query(query);
- } catch (SolrServerException e) {
- throw new WikittyException("Unable to execute associative query on " + associated.getElement().getName(), e);
- }
- SolrDocumentList solrResults = resp.getResults();
-
- Restriction generatedRestriction = null;
- long size = solrResults.size();
- if (size == 0) {
- throw new WikittyException("Associated " + associated.getElement().getName() + " do not retrieved any result");
- }
- if (size == 1) {
- generatedRestriction = RestrictionHelper.eq(associated.getElement(), (String) solrResults.get(0).getFieldValue("id"));
- } else {
- List<String> ids = new ArrayList<String>(solrResults.size());
- for (SolrDocument doc : solrResults) {
- String id = (String) doc.getFieldValue("id"); // FIXME : set a constant field reference
- ids.add(id);
- }
- generatedRestriction = new In(associated.getElement(), ids);
- }
- Restriction parent = associated.getParentRestrictionDto();
- And and;
- if (parent instanceof And) {
- and = (And) parent;
- and.getRestrictions().add(generatedRestriction);
- } else {
- and = RestrictionHelper.and(Arrays.asList(new Restriction[]{associated.getParentRestrictionDto(), generatedRestriction}));
- }
- return toSolr(and);
- }
-
- private String not2solr(Not not) throws WikittyException {
- if (not.getRestriction() == null) {
- throw new WikittyException("not.restriction");
- }
- return "( *:* - " + toSolr(not.getRestriction()) + " )";
- }
-
- private String and2solr(And and) throws WikittyException {
- if (and.getRestrictions() == null) {
- throw new WikittyException("and.restrictions is null");
- }
- if (and.getRestrictions().size() < 2) {
- throw new WikittyException("AND is an operator that handle 2 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (Restriction restriction : and.getRestrictions()) {
- if (first) {
- result.append("( ").append(toSolr(restriction));
- first = false;
- } else {
- result.append(" AND ").append(toSolr(restriction));
- }
- }
- return result.append(" )").toString();
- }
-
- private String or2solr(Or or) throws WikittyException {
- if (or.getRestrictions() == null) {
- throw new WikittyException("or.restrictions is null");
- }
- if (or.getRestrictions().size() < 2) {
- throw new WikittyException("OR is an operator that handle 2 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (Restriction restriction : or.getRestrictions()) {
- if (first) {
- result.append("( ");
- first = false;
- } else {
- result.append(" OR ");
- }
- result.append(toSolr(restriction));
- }
- return result.append(" )").toString();
- }
-
- private String eq2solr(Equals eq) throws WikittyException {
- return element2solr(eq.getElement()) + ":" + value2solr(eq.getValue());
- }
-
- private String neq2solr(NotEquals neq)
- throws WikittyException {
- return "( *:* - " + element2solr(neq.getElement()) + ":"
- + value2solr(neq.getValue()) + " )";
- }
-
- private String less2solr(Less less) throws WikittyException {
- return element2solr(less.getElement()) + ":{* TO "
- + value2solr(less.getValue()) + "}";
- }
-
- private String lessEq2solr(LessOrEqual lessEq)
- throws WikittyException {
- return element2solr(lessEq.getElement()) + ":[* TO "
- + value2solr(lessEq.getValue()) + "]";
- }
-
- private String great2solr(Greater great)
- throws WikittyException {
- return element2solr(great.getElement()) + ":{"
- + value2solr(great.getValue()) + " TO *}";
- }
-
- private String greatEq2solr(GreaterOrEqual greatEq)
- throws WikittyException {
- return element2solr(greatEq.getElement()) + ":["
- + value2solr(greatEq.getValue()) + " TO *]";
- }
-
- private String between2solr(Between between)
- throws WikittyException {
- if (between.getElement() == null) {
- throw new WikittyException("contains.element");
- }
- if (between.getMin() == null) {
- throw new WikittyException("contains.min");
- }
- if (between.getMax() == null) {
- throw new WikittyException("contains.max");
- }
- return element2solr(between.getElement()) + ":["
- + value2solr(between.getMin()) + " TO "
- + value2solr(between.getMax()) + "]";
- }
-
- private String contains2solr(Contains contains)
- throws WikittyException {
- if (contains.getElement() == null) {
- throw new WikittyException("contains.element");
- }
- if (contains.getValue() == null) {
- throw new WikittyException("contains.values");
- }
- if (contains.getValue().size() < 1) {
- throw new WikittyException("CONTAINS is an operator that handle 1 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (String value : contains.getValue()) {
- if (first) {
- result.append("( ");
- first = false;
- } else {
- result.append(" AND ");
- }
- result.append("( ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" OR ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" OR ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" )");
- }
- return result.append(" )").toString();
- }
-
- private String start2solr(StartsWith start)
- throws WikittyException {
- return element2solr(start.getElement()) + ":"
- + value2solr(start.getValue(), true, false);
- }
-
- private String end2solr(EndsWith end) {
- return element2solr(end.getElement()) + ":" + value2solr(end.getValue());
- }
-
- private String true2solr() {
- return "( *:* )";
- }
-
- private String false2solr() {
- return "( *:* - *:* )";
- }
-
- private String keyword2solr(Keyword keyword) {
- return value2solr(keyword.getValue());
- }
-
- private String value2solr(String value) {
- return value2solr(value, false, false);
- }
-
- private String value2solr(String value, boolean starOnEnd,
- boolean revert) {
- String result;
- if (value != null) {
- if (value.equals("*")) {
- return "*";
- }
-
- if (revert) {
- result = Restriction2Solr.escapeValue(reverse(value));
- } else {
- result = Restriction2Solr.escapeValue(value);
- // result = value;
- }
- } else {
- result = "";
- }
- if (starOnEnd) {
- result += "*";
- }
- if (result.contains(" ")) {
- result = "\"" + result + "\"";
- }
- return result;
- }
-
- private String element2solr(Element element) throws WikittyException {
- String result = element.getName();
- if (Element.ELT_EXTENSION.equals(result)) {
- result = WikittySearchEnginSolr.SOLR_EXTENSIONS;
- } else if (Element.ELT_ID.equals(result)) {
- result = WikittySearchEnginSolr.SOLR_ID;
- } else {
- result = element.getName();
- }
- result = fieldModifer.convertToSolr(result);
- return result;
- }
-
- private static String escapeValue(String value) {
- final String LUCENE_REPLACE_PATTERN = "\\+" + "|-" + "|&&" + "|\\|\\|"
- + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\\^" + "|\""
- + "|\\~" + "|\\*" + "|\\?" + "|:" + "|\\\\";
- return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0");
- }
-
- private String reverse(String source) {
- int i, len = source.length();
- StringBuffer dest = new StringBuffer(len);
-
- for (i = (len - 1); i >= 0; i--)
- dest.append(source.charAt(i));
- return dest.toString();
- }
-}
-
Deleted: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -1,71 +0,0 @@
-package org.sharengo.wikitty.jdbc;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.LuceneQParserPlugin;
-import org.apache.solr.search.QParser;
-import org.apache.solr.search.QueryParsing;
-import org.apache.solr.search.SolrQueryParser;
-
-
-/**
- * Add allow leading wildcard
- * setAllowLeadingWildcard(true);
- * setLowercaseExpandedTerms(true);
- * <br>Example: <code>{!wikitty q.op=AND df=text sort='price asc'}myfield:foo +bar -baz</code>
- * More information @see LuceneQParserPlugin
- */
-public class WikittyQueryParser extends LuceneQParserPlugin {
-
- public static String NAME = "wikitty";
-
- @Override
- public void init(NamedList args) {
- }
-
- @Override
- public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
- return new SolrQParser(qstr, localParams, params, req);
- }
-}
-
-class SolrQParser extends QParser {
-
- static private Log log = LogFactory.getLog(SolrQParser.class);
- String sortStr;
- SolrQueryParser lparser;
-
- public SolrQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
- super(qstr, localParams, params, req);
- }
-
- @Override
- public Query parse() throws ParseException {
-
- String defaultField = getParam(CommonParams.DF);
- lparser = new SolrQueryParser(this, defaultField);
- lparser.setAllowLeadingWildcard(true);
- lparser.setLowercaseExpandedTerms(true);
-
- String opParam = getParam(QueryParsing.OP);
- if (opParam != null) {
- lparser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR);
- }
-
- String qstr = getString();
- log.debug("Query parse : " + qstr);
- return lparser.parse(qstr);
- }
-
- @Override
- public String[] getDefaultHighlightFields() {
- return new String[]{lparser.getField()};
- }
-}
Deleted: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -1,659 +0,0 @@
-/* *##%
- * Copyright (c) 2009 poussin. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *##%*/
-
-package org.sharengo.wikitty.jdbc;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.solr.client.solrj.SolrQuery;
-import org.apache.solr.client.solrj.SolrServer;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.solr.client.solrj.response.FacetField;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.core.CoreContainer;
-import org.sharengo.wikitty.*;
-import org.sharengo.wikitty.FieldType.TYPE;
-import org.sharengo.wikitty.search.Search;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * @author poussin
- * @version $Revision$
- * <p/>
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittySearchEnginSolr implements WikittySearchEngin {
-
- /**
- * to use log facility, just put in your code: log.info(\"...\");
- */
- static private Log log = LogFactory.getLog(WikittySearchEnginSolr.class);
-
- /**
- * id field in solr
- */
- static final protected String SOLR_ID = "id";
-
- /**
- * extensions field name in solr
- */
- static final public String SOLR_EXTENSIONS = "extensions";
-
- /**
- * extension use to store field without extension to search on all extesnion
- */
- static final public String SOLR_ALL_EXTENSIONS = "all";
-
- /**
- * Precise the query parser to use, is allow leading wildcard
- */
- static final public String SOLR_QUERY_PARSER = "{!wikitty}";
-
- // Use for indexation tree node
- static final public String TREENODE_PREFIX = TreeNode.EXT_TREENODE + ".";
- static final public String TREENODE_CHILD = TREENODE_PREFIX + "wikittyId";
- static final public String TREENODE_EMPTY = TREENODE_PREFIX + "empty";
- static final public String TREENODE_ROOT = TREENODE_PREFIX + "root";
-
- static protected class CommandSolr implements Command {
- /**
- * if is store command toStore is true, if is delete toStore is false
- */
- boolean toStore;
- String id;
- Wikitty wikitty;
-
- /**
- * use to store command
- */
- public CommandSolr(Wikitty wikitty) {
- this.wikitty = wikitty;
- this.toStore = true;
- }
-
- /**
- * use for deletion command
- */
- public CommandSolr(String id) {
- this.id = id;
- this.toStore = false;
- }
- }
-
- static protected class TypeFieldModifer implements Restriction2Solr.FieldModifier {
- protected WikittyExtensionStorage extensionStorage;
-
- public TypeFieldModifer(WikittyExtensionStorage extensionStorage) {
- this.extensionStorage = extensionStorage;
- }
-
- public String convertToSolr(String fqfieldname) {
- String result = fqfieldname;
- String[] searchField = fqfieldname.split("\\.");
-
- if (searchField.length == 2) {
- String extName = searchField[0];
- String fieldName = searchField[1];
-
- String version = extensionStorage.getLastVersion(extName);
- if (version != null) { // not valid extension is version == null
- WikittyExtension ext = extensionStorage.restore(
- WikittyExtension.computeId(extName, version));
- FieldType type = ext.getFieldType(fieldName);
- if (type != null) { // type can be null if extension version differ
- result = WikittySearchEnginSolr.getSolrFieldName(
- fqfieldname, type);
- } else {
- log.debug(String.format(
- "Field '%s' could not be found in '%s'",
- fqfieldname, extName));
- }
- } else {
- log.warn("No version for extension " + extName);
- }
- }
-
- if (searchField.length == 3) {
- String extName = searchField[0];
- String fieldName = searchField[1];
- String fieldType = searchField[2];
-
- if (Criteria.ALL_EXTENSIONS.equals(extName)) {
- TYPE type = FieldType.TYPE.valueOf(fieldType);
- String solrFieldName = SOLR_ALL_EXTENSIONS + "." + fieldName;
- result = WikittySearchEnginSolr.getSolrFieldName(solrFieldName, type);
- } else {
- log.warn("All extension not found " + extName);
- }
- }
-
- return result;
- }
-
- public String convertToField(String solrName) {
- String fieldname = solrName.replaceAll("(_b$)|(_dt$)|(_t$)|(_l$)", "");
- return fieldname;
- }
-
- }
-
- /**
- * Store parent for each node and search in index if not known parent
- */
- protected static class ParentMap extends HashMap<String, String> {
-
- protected WikittySearchEnginSolr searchEnginSolr;
-
- public ParentMap(WikittySearchEnginSolr searchEnginSolr) {
- this.searchEnginSolr = searchEnginSolr;
- }
-
- @Override
- public String get(Object key) {
- String id = String.valueOf(key);
- String parent = super.get(id);
-
- // If not found in map, search in index
- if (parent == null) {
- SolrDocument doc = searchEnginSolr.findById(id);
- if (doc == null) {
- // is root
- return null;
- }
- parent = (String) doc.getFieldValue(TreeNode.FQ_FIELD_PARENT);
- put(id, parent);
- }
- return parent;
- }
-
- /**
- * Add parent map in transaction if is not exists and return it
- */
- public static ParentMap getParentMap(
- WikittySearchEnginSolr searchEnginSolr,
- WikittyTransaction transaction) {
- ParentMap value = (ParentMap) transaction.getTagValue(ParentMap.class);
- if (value == null) {
- value = new ParentMap(searchEnginSolr);
- transaction.setTagValue(ParentMap.class, value);
- }
- return value;
- }
- }
-
- /**
- * solr server
- */
- protected SolrServer solrServer;
- /**
- * Criteria transformer to solr
- */
- protected Restriction2Solr restriction2Solr;
- /**
- * Field modifier use to transform to solr format
- */
- protected TypeFieldModifer fieldModifier;
-
- public WikittySearchEnginSolr(WikittyExtensionStorage extensionStorage) {
- super();
- try {
- CoreContainer.Initializer initializer = new CoreContainer.Initializer();
- CoreContainer coreContainer = initializer.initialize();
- solrServer = new EmbeddedSolrServer(coreContainer, "");
-
- fieldModifier = new TypeFieldModifer(extensionStorage);
- restriction2Solr = new Restriction2Solr(fieldModifier);
-
- } catch (Exception eee) {
- throw new WikittyException(eee);
- }
- }
-
- public void clear() {
- try {
- solrServer.deleteByQuery("*:*");
- solrServer.commit(true, true);
- } catch (Exception eee) {
- throw new WikittyException(eee);
- }
- }
-
- public List<Command> prepare(WikittyTransaction transaction,
- Collection<Wikitty> wikitties) {
- List<Command> result = new ArrayList<Command>(wikitties.size());
- for (Wikitty w : wikitties) {
-
- // Store known parent in transaction
- if (w.hasExtension(TreeNode.EXT_TREENODE)) {
- ParentMap parentMap = ParentMap.getParentMap(this, transaction);
- String wikittyId = w.getId();
- String parentId = w.getFieldAsWikitty(
- TreeNode.EXT_TREENODE, TreeNode.FIELD_PARENT);
- parentMap.put(wikittyId, parentId);
- }
-
- result.add(new CommandSolr(w));
- }
- return result;
- }
-
- public UpdateResponse commit(WikittyTransaction transaction,
- List<Command> wikittyIndexationCommandList) {
- try {
- for (Command c : wikittyIndexationCommandList) {
- CommandSolr cs = (CommandSolr) c;
- if (cs.toStore) {
- SolrInputDocument doc = createIndexDocument(cs.wikitty);
- solrServer.add(doc);
-
- Collection<SolrInputDocument> docs = createTreeNodeIndex(transaction, cs.wikitty);
- if (!docs.isEmpty()) {
- solrServer.add(docs);
- }
-
- } else {
- // Delete all reference on tree
- solrServer.deleteByQuery(TREENODE_CHILD + ":" + cs.id);
- // FIXME: jru 20091027 delete node in middle in tree
- solrServer.deleteByQuery(TREENODE_PREFIX + cs.id + ":" + TREENODE_EMPTY);
-
- solrServer.deleteById(cs.id);
- }
- }
- solrServer.commit();
-
- // no specific result needed
- UpdateResponse result = new UpdateResponse();
- return result;
- } catch (Exception eee) {
- throw new WikittyException(eee);
- }
- }
-
- public List<Command> delete(WikittyTransaction transaction,
- List<String> idList) throws WikittyException {
- List<Command> result = new ArrayList<Command>(idList.size());
- for (String id : idList) {
- result.add(new CommandSolr(id));
- }
- return result;
- }
-
- public PagedResult<String> findAllByCriteria(Criteria criteria) {
- try {
-
- // Create query with restriction
- String queryString = restriction2Solr.toSolr(criteria.getRestriction(), solrServer);
- SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + queryString);
-
- // Add pagged
- int firstIndex = criteria.getFirstIndex();
- int endIndex = criteria.getEndIndex();
-
- query.setStart(firstIndex);
- int nbRows;
- if (endIndex == -1) {
- // WARNING It is necessary to substract 'start' otherwise, there is a capacity overlow in solR
- nbRows = Integer.MAX_VALUE - firstIndex;
- } else {
- nbRows = endIndex - firstIndex + 1;
- }
- query.setRows(nbRows);
-
- // Add sorting
- List<String> sortAscending = criteria.getSortAscending();
- if (sortAscending != null) {
- for (String sort : sortAscending) {
- String tranform = fieldModifier.convertToSolr(sort);
- query.setSortField(tranform, SolrQuery.ORDER.asc);
- }
- }
-
- List<String> sortDescending = criteria.getSortDescending();
- if (sortDescending != null) {
- for (String sort : sortDescending) {
- String tranform = fieldModifier.convertToSolr(sort);
- query.setSortField(tranform, SolrQuery.ORDER.desc);
- }
- }
-
- // Add faceting
- List<String> facetField = criteria.getFacetField();
- List<Criteria> facetCriteria = criteria.getFacetCriteria();
-
- // use to map query string to criteria facet name
- Map<String, String> facetQueryToName = new HashMap<String, String>();
-
- if ((facetField != null && !facetField.isEmpty())
- || (facetCriteria != null && !facetCriteria.isEmpty())) {
- query.setFacet(true);
- query.setFacetMinCount(1);
- // query.setFacetLimit(8); // no limit actualy
-
- // field facetisation
- if (facetField != null) {
- for (String fqfieldName : facetField) {
- String tranform = fieldModifier.convertToSolr(fqfieldName);
- query.addFacetField(tranform);
- }
- }
-
- // query facetisation
- if (facetCriteria != null) {
- for (Criteria facet : facetCriteria) {
- String queryFacet =
- restriction2Solr.toSolr(facet.getRestriction());
- facetQueryToName.put(queryFacet, facet.getName());
- query.addFacetQuery(queryFacet);
- }
- }
- }
-
- QueryResponse resp = solrServer.query(query);
- SolrDocumentList solrResults = resp.getResults();
-
- Map<String, List<FacetTopic>> facets = new HashMap<String, List<FacetTopic>>();
- if (facetField != null && !facetField.isEmpty()) {
- for (FacetField facet : resp.getFacetFields()) {
- String facetName = fieldModifier.convertToField(facet.getName());
- List<FacetTopic> topics = new ArrayList<FacetTopic>();
- if (facet.getValues() != null) {
- for (FacetField.Count value : facet.getValues()) {
- String topicName = value.getName();
- if (!topicName.endsWith(TREENODE_EMPTY)) {
- int topicCount = (int) value.getCount();
- FacetTopic topic = new FacetTopic(facetName, topicName, topicCount);
- topics.add(topic);
- }
- }
- }
- facets.put(facetName, topics);
- }
- }
- if (facetCriteria != null && !facetCriteria.isEmpty()) {
- for (Map.Entry<String, Integer> facet : resp.getFacetQuery().entrySet()) {
- String facetName = facet.getKey();
- // don't use contains because, map can have key with null value
- if (null != facetQueryToName.get(facetName)) {
- facetName = facetQueryToName.get(facetName);
- }
- Integer count = facet.getValue();
- List<FacetTopic> topics = new ArrayList<FacetTopic>();
- FacetTopic topic = new FacetTopic(facetName, facetName, count);
- topics.add(topic);
- facets.put(facetName, topics);
- }
- }
-
- List<String> ids = new ArrayList<String>(solrResults.size());
- for (SolrDocument doc : solrResults) {
- String id = (String) doc.getFieldValue(SOLR_ID);
- ids.add(id);
- }
-
- int numFound = (int) resp.getResults().getNumFound();
- PagedResult<String> result = new PagedResult<String>(
- firstIndex, numFound, queryString, facets, ids);
-
- return result;
- } catch (SolrServerException e) {
- throw new WikittyException(e);
- }
- }
-
- public Map<String, Integer> findAllChildren(Wikitty w) {
- String wikittyId = w.getId();
-
- String parent = w.getFieldAsWikitty(TreeNode.EXT_TREENODE, TreeNode.FIELD_PARENT);
- if (parent == null) {
- parent = TREENODE_ROOT;
- } else {
- parent = TREENODE_PREFIX + parent;
- }
-
- // Find count with facet, if the node not contain recurcively content,
- // the node not found with facet
- Criteria criteria = Search.query().eq(parent, wikittyId).criteria()
- .setFirstIndex(0).setEndIndex(0)
- .addFacetField(TREENODE_PREFIX + wikittyId);
- PagedResult<String> search = findAllByCriteria(criteria);
-
- Map<String, Integer> counts = new HashMap<String, Integer>();
- List<FacetTopic> topics = search.getTopic(TREENODE_PREFIX + wikittyId);
- if (topics != null) {
- for (FacetTopic topic : topics) {
- String topicName = topic.getTopicName();
- int topicCount = topic.getCount();
- counts.put(topicName, topicCount);
- }
- }
-
- log.debug("Facet result " + counts);
-
- // Find all children, add the other node not found with facet
- criteria = Search.query().eq(TreeNode.FQ_FIELD_PARENT, wikittyId).criteria()
- .setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS);
- search = findAllByCriteria(criteria);
-
- List<String> children = search.getAll();
- for (String child : children) {
- if (!counts.containsKey(child)) {
- counts.put(child, 0);
- }
- }
-
- return counts;
- }
-
- /**
- * Create all index document to used to modify indexation.
- * this method don't modify index
- *
- * @param wikitties all wikitties object to index
- * @return list of SolrInputDocument used to modify index
- */
- protected SolrInputDocument createIndexDocument(Wikitty w) {
- log.debug("index wikitty " + w.getId());
-
- SolrInputDocument doc = new SolrInputDocument();
- doc.addField(SOLR_ID, w.getId());
-
- for (String name : w.getExtensionNames()) {
- doc.addField(SOLR_EXTENSIONS, name);
- }
-
- for (String fqfieldName : w.fieldNames()) {
- FieldType type = w.getFieldType(fqfieldName);
- // do not index wikitty field reference
-// if (type.getType() == FieldType.TYPE.WIKITTY) {
-// continue;
-// }
- String solrFqFieldName = getSolrFieldName(fqfieldName, type);
- String[] extAndName = solrFqFieldName.split("\\.");
- String solrFieldName = SOLR_ALL_EXTENSIONS + "." + extAndName[1];
- if (type.isCollection()) {
- Collection collection = (Collection) w.getFqField(fqfieldName);
- for (Object objectValue : collection) {
- if (objectValue != null) {
- // String value = WikittyUtil.toString(type, objectValue);
- Object value = objectValue;
- doc.addField(solrFqFieldName, value);
- doc.addField(solrFieldName, value);
- }
- }
- } else {
- Object objectValue = w.getFqField(fqfieldName);
- if (objectValue != null) {
- // String value = WikittyUtil.toString(type, objectValue);
- Object value = objectValue;
- log.debug("index field " + solrFqFieldName + " with value '" + value + "'");
- doc.addField(solrFqFieldName, value);
- doc.addField(solrFieldName, value);
- }
- }
- }
-
- return doc;
- }
-
- /**
- * Create a doc for each child for a tree node, his contains the path for
- * the child. Update old doc when the node is moved and child is deleted.
- */
- protected Collection<SolrInputDocument> createTreeNodeIndex(
- WikittyTransaction transaction, Wikitty w)
- throws IOException, SolrServerException {
-
- Collection<SolrInputDocument> result = new ArrayList<SolrInputDocument>();
- if (w.hasExtension(TreeNode.EXT_TREENODE)) {
- String treeNodeId = w.getId();
- ParentMap parentMap = (ParentMap) transaction.getTagValue(ParentMap.class);
-
- // Init new children with all children in node
- List<String> children = w.getFieldAsList(TreeNode.EXT_TREENODE,
- TreeNode.FIELD_CHILDREN, String.class);
- List<String> newChildren = new ArrayList<String>();
- if (children != null) {
- newChildren.addAll(children);
- }
-
- // Find old document to do diff
- SolrDocument treeNodeDoc = findById(treeNodeId);
- if (treeNodeDoc != null) {
- Collection oldChildren = treeNodeDoc.
- getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_t");
-
- // Remove old children not in current node
- List<String> removeChildren = new ArrayList<String>();
- if (oldChildren != null) {
- removeChildren.addAll(oldChildren);
- removeChildren.removeAll(children);
- for (String removeChild : removeChildren) {
- solrServer.deleteByQuery(TREENODE_CHILD + ":" + removeChild);
- }
-
- // Remove old child in new children
- newChildren.removeAll(oldChildren);
- }
-
- // Update path other node refer to current node
- // FIXME jru 20091926 test change path
- SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + TREENODE_PREFIX + treeNodeId + ":*");
- QueryResponse response = solrServer.query(query);
- SolrDocumentList updateDocs = response.getResults();
- for (Iterator<SolrDocument> iterator = updateDocs.iterator(); iterator.hasNext();) {
- SolrDocument solrDocument = iterator.next();
- String child = (String) solrDocument.getFieldValue(TreeNode.EXT_TREENODE + ".wikittyId");
- // Child is not deleted
- if (!removeChildren.contains(child)) {
- SolrInputDocument doc = createTreeNodeDocument(treeNodeId, child, parentMap);
-
- // Copy other field after node
- String parent = TREENODE_PREFIX + treeNodeId;
- String childParent = (String) solrDocument.getFieldValue(parent);
- while (childParent != null) {
- doc.setField(parent, childParent);
- parent = TREENODE_PREFIX + childParent;
- childParent = (String) solrDocument.getFieldValue(parent);
- }
- result.add(doc);
- }
- }
- }
-
- // New children
- for (String newChild : newChildren) {
- SolrInputDocument doc = createTreeNodeDocument(treeNodeId, newChild, parentMap);
- result.add(doc);
- }
-
- }
- return result;
- }
-
- /**
- * Create a doc between node and child
- */
- public SolrInputDocument createTreeNodeDocument(String treeNodeId, String child, ParentMap parentMap) {
- SolrInputDocument doc = new SolrInputDocument();
- doc.setField(SOLR_ID, TreeNode.EXT_TREENODE + "-" + treeNodeId + "-" + child);
- doc.setField(TREENODE_CHILD, child);
- doc.setField(TREENODE_PREFIX + treeNodeId, TREENODE_EMPTY);
-
- // Add path
- String childParent = treeNodeId;
- String parent = parentMap.get(childParent);
- while (parent != null) {
- doc.setField(TREENODE_PREFIX + parent, childParent);
- childParent = parent;
- parent = parentMap.get(childParent);
- }
- doc.setField(TREENODE_ROOT, childParent);
-
- return doc;
- }
-
- /**
- * Find solr document by id
- */
- protected SolrDocument findById(String id) {
- SolrQuery query = new SolrQuery("id:" + id);
- QueryResponse response;
- try {
- response = solrServer.query(query);
- } catch (SolrServerException eee) {
- throw new WikittyException(eee);
- }
-
- SolrDocumentList results = response.getResults();
- long numFound = results.getNumFound();
- if (numFound == 1) {
- return results.get(0);
- }
-
- return null;
- }
-
- static public String getSolrFieldName(String fqfieldName, FieldType fieldType) {
- TYPE type = fieldType.getType();
- String result = getSolrFieldName(fqfieldName, type);
- return result;
- }
-
- public static String getSolrFieldName(String fqfieldName, TYPE type) {
- switch (type) {
- case BOOLEAN:
- return fqfieldName + "_b";
- case DATE:
- return fqfieldName + "_dt";
- case STRING:
- return fqfieldName + "_t";
- case NUMERIC:
- return fqfieldName + "_d";
- default:
- return fqfieldName;
- }
- }
-}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -19,10 +19,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.sharengo.wikitty.AbstractWikittyService;
-import org.sharengo.wikitty.WikittyExtensionStorage;
-import org.sharengo.wikitty.WikittySearchEngin;
-import org.sharengo.wikitty.WikittyStorage;
+import org.sharengo.wikitty.*;
+import org.sharengo.wikitty.solr.WikittySearchEngineSolr;
/**
* HBase must have 2 definitions, one for extension and one for wikitty object.
@@ -65,7 +63,7 @@
public WikittyServiceJDBC() {
extensionStorage = new WikittyExtensionStorageJDBC();
wikittyStorage = new WikittyStorageJDBC(extensionStorage);
- searchEngin = new WikittySearchEnginSolr(extensionStorage);
+ searchEngin = new WikittySearchEngineSolr(extensionStorage);
}
@Override
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/resources/solrconfig.xml
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/resources/solrconfig.xml 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/resources/solrconfig.xml 2009-11-04 10:19:47 UTC (rev 308)
@@ -678,7 +678,7 @@
</queryResponseWriter>
- <queryParser name="wikitty" class="org.sharengo.wikitty.jdbc.WikittyQueryParser"/>
+ <queryParser name="wikitty" class="org.sharengo.wikitty.solr.WikittyQueryParser"/>
<!-- example of registering a query parser
<queryParser name="lucene" class="org.apache.solr.search.LuceneQParserPlugin"/>
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -21,7 +21,6 @@
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.Wikitty;
import org.sharengo.wikitty.WikittyService;
-import org.sharengo.wikitty.search.Element;
import org.sharengo.wikitty.search.Search;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -37,7 +36,7 @@
public void testExport() throws Exception {
final List<Wikitty> wikitties = createSampleWikitty(ws);
- Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, EXTNAME).criteria();
+ Criteria criteria = Search.query().eqExt(EXTNAME).criteria();
String result = ws.syncExportAllByCriteria(criteria);
log.debug("[XML] " + result);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -26,18 +26,19 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.sharengo.internal.TreeNodeImpl;
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.ExtensionFactory;
import org.sharengo.wikitty.FacetTopic;
import org.sharengo.wikitty.PagedResult;
import org.sharengo.wikitty.Tree;
import org.sharengo.wikitty.TreeNode;
-import org.sharengo.wikitty.TreeNodeImpl;
import org.sharengo.wikitty.Wikitty;
import org.sharengo.wikitty.WikittyExtension;
import org.sharengo.wikitty.WikittyService;
import org.sharengo.wikitty.FieldType.TYPE;
import org.sharengo.wikitty.search.Search;
+import org.sharengo.wikitty.solr.WikittySearchEngineSolr;
import org.sharengo.wikitty.test.StorageTest;
/**
@@ -95,8 +96,8 @@
Wikitty found = findNode(name);
if(found == null) {
TreeNodeImpl node = new TreeNodeImpl();
- node.setName(name);
- node.setParent(parent);
+ node.setTreeNodeName(name);
+ node.setTreeNodeParent(parent);
found = node.getWikitty();
log.debug("[Storing] " + name + " with id " + found.getId());
@@ -161,7 +162,7 @@
Wikitty root = findNode("root");
String rootId = root.getId();
- Criteria criteria = Search.query().eq(WikittySearchEnginSolr.TREENODE_ROOT, rootId).criteria()
+ Criteria criteria = Search.query().eq(WikittySearchEngineSolr.TREENODE_ROOT, rootId).criteria()
.setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
.addFacetField(rootId);
PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
Deleted: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEnginTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEnginTest.java 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEnginTest.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -1,292 +0,0 @@
-/* *##%
- * Copyright (c) 2009 poussin. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *##%*/
-
-package org.sharengo.wikitty.jdbc;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import junit.framework.TestCase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.sharengo.wikitty.Criteria;
-import org.sharengo.wikitty.FacetTopic;
-import org.sharengo.wikitty.PagedResult;
-import org.sharengo.wikitty.Wikitty;
-import org.sharengo.wikitty.WikittyService;
-import org.sharengo.wikitty.WikittyUtil;
-import org.sharengo.wikitty.search.Search;
-import org.sharengo.wikitty.test.util.GenTestData;
-import org.sharengo.wikitty.test.util.ImportFeedback;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittySearchEnginTest extends TestCase {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittySearchEnginTest.class);
-
- /** 10 search by field */
- static final int MAX = 10;
-
- static String[] allFieldNames = new String[]{
- "Personne.civilite",
- "Personne.nom",
- "Personne.prenom",
- "Personne.date_naissance",
- "Personne.poids",
- "Employe.matricule",
- "Employe.arrivee",
- "Employe.salaire"
- };
-
- /**
- * used to count some element during data loading, this information
- * is used to assert statement
- */
- static public class AssertReference implements ImportFeedback {
-
- /** total number imported elements */
- public int count = 0;
- /** key: fqfieldname value: map(fieldvalue, count this value) */
- public Map<String, Map<Object, Integer>> fieldValueCounters =
- new HashMap<String, Map<Object, Integer>>();
-
- public void importPerformed(long nbImportedElements, long deltaTime) {
- // do nothing
- }
-
- public void parsed(Wikitty w) {
- count++;
-
- for (String fqf : allFieldNames) {
- Map<Object, Integer> fvc = fieldValueCounters.get(fqf);
- if (fvc == null) {
- fvc = new HashMap<Object, Integer>();
- fieldValueCounters.put(fqf, fvc);
- }
- Object key = w.getFqField(fqf);
- Integer n = fvc.get(key);
- if (n == null) {
- n = 1;
- } else {
- n = n + 1;
- }
- fvc.put(key, n);
- }
- }
-
- }
-
- WikittyService ws;
- AssertReference assertReference;
-
- // TODO poussin 20090901 this method is call for each test method, this method can be call only once for all test methods
- @Override
- public void setUp() throws Exception {
- // import data and prepare expected result
- ws = new WikittyServiceJDBC();
- ((WikittyServiceJDBC)ws).getSearchEngin().clear();
- assertReference = new AssertReference();
- GenTestData.importGeneratedFile(
- GenTestData.getDataFile("selected-data.txt"), ws, assertReference);
-
- }
-
- /**
- * Do MAX search for each field in object and compare result size with
- * number found during import
- *
- * @throws Exception
- */
- public void testFindByExample() throws Exception {
- for (String fqf : allFieldNames) {
- int cpt = 0; // cpt to stop loop after amount of test
- Wikitty w = new Wikitty();
- w.addExtension(GenTestData.ext_personne);
- w.addExtension(GenTestData.ext_employe);
-
- Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
- for (Object value : fvc.keySet()) {
- System.out.println("search on: " + fqf + " with value: " + value);
- if(++cpt >= MAX) {
- break;
- }
- int nb = fvc.get(value);
- w.setFqField(fqf, value);
- Criteria criteria = Search.query(w).criteria()
- .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
- System.out.println("Count: " + result.size() + " Query: " + result.getQueryString());
- assertEquals(nb, result.size());
- }
- }
- }
-
- /**
- * Do MAX search for each field in object and compare result size with
- * number found during import
- *
- * @throws Exception
- */
- public void testFindByCriteria() throws Exception {
- for (String fqf : allFieldNames) {
- int cpt = 0; // cpt to stop loop after amount of test
-
- int sum = 0; // sum number of finding object for this fqf
- List values = new LinkedList();
-
- Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
- for (Object value : fvc.keySet()) {
- if(++cpt >= MAX) {
- break;
- }
- int nb = fvc.get(value);
-
- // stock number and value for last test
- sum += nb;
- values.add(value);
-
- Criteria criteria = Search.query()
- .eq(fqf, WikittyUtil.toString(value))
- .criteria()
- .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
-
- assertEquals(nb, result.size());
- }
-
- Search query = Search.query().or();
- for (Object value : values) {
- query.eq(fqf, WikittyUtil.toString(value));
- }
- Criteria criteria = query.criteria()
- .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
- System.out.println("query: " + result.getQueryString());
- assertEquals(sum, result.size());
- }
- }
-
- /**
- * Do search for 'Personne.nom==*' for limited result number, total number
- * available in solr must be equals to number found during import
- *
- * @throws Exception
- */
- public void testFindByCriteriaNumFound() throws Exception {
- String fqf = "Personne.nom";
- Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
- .setFirstIndex(0).setEndIndex(2);
-
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
-
- assertEquals(assertReference.count, result.getNumFound());
- }
-
- /**
- * Do search on Personne.nom and ask facet for Personne.nom, all Topic
- * must be equals (name and count) to name and number found during import
- *
- * @throws Exception
- */
- public void testFindByCriteriaFieldFacet() throws Exception {
- String fqf = "Personne.nom";
- Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
- Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
- .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
- .addFacetField(fqf);
-
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
-
- assertEquals(new ArrayList(Arrays.asList(fqf)),
- new ArrayList(result.getFacetNames()));
- List<FacetTopic> topics = result.getTopic(fqf);
-
- for (FacetTopic t : topics) {
- String name = t.getTopicName();
- int num = t.getCount();
-
- System.out.println("name: " + name + " keys: " + fvc.keySet());
- assertNotNull(fvc.get(name));
- int realNum = fvc.get(name);
- assertEquals(realNum, num);
- }
- }
-
- /**
- * Do search on Personne.nom and ask facet for Personne.civilite 2
- * named facet criteria:
- * - homme (civilite==Mr)
- * - femme (civilite==Me OR civilite==Mlle)
- *
- * @throws Exception
- */
- public void testFindByCriteriaCriteriaFacet() throws Exception {
- String fqf = "Personne.nom";
- String facetName = "Personne.civilite";
-
- Criteria homme = Search.query().eq(facetName, "Mr").criteria("homme");
- Criteria femme = Search.query()
- .eq(facetName, "Me").or().eq(facetName, "Mlle")
- .criteria("femme");
-
- Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
- .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
- .addFacetCriteria(homme).addFacetCriteria(femme);
-
- PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
-
- assertEquals(2, result.getFacetNames().size());
-
- System.out.println("facet names: " + result.getFacetNames());
-
- assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Mr"));
- assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Me"));
- assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Mlle"));
-
- int numMr = assertReference.fieldValueCounters.get(facetName).get("Mr");
- int numMe = assertReference.fieldValueCounters.get(facetName).get("Me");
- int numMlle = assertReference.fieldValueCounters.get(facetName).get("Mlle");
-
- log.info("numMr: " + numMr);
- log.info("numMe: " + numMe);
- log.info("numMlle: " + numMlle);
-
- List<FacetTopic> hommeTopics = result.getTopic("homme");
- List<FacetTopic> femmeTopics = result.getTopic("femme");
-
- assertEquals(1, hommeTopics.size());
- assertEquals(1, femmeTopics.size());
-
- FacetTopic hommeTopic = hommeTopics.get(0);
- FacetTopic femmeTopic = femmeTopics.get(0);
-
- assertEquals(numMr, hommeTopic.getCount());
- assertEquals(numMe + numMlle, femmeTopic.getCount());
- }
-}
Added: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEngineTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEngineTest.java (rev 0)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/WikittySearchEngineTest.java 2009-11-04 10:19:47 UTC (rev 308)
@@ -0,0 +1,292 @@
+/* *##%
+ * Copyright (c) 2009 poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *##%*/
+
+package org.sharengo.wikitty.jdbc;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.sharengo.wikitty.Criteria;
+import org.sharengo.wikitty.FacetTopic;
+import org.sharengo.wikitty.PagedResult;
+import org.sharengo.wikitty.Wikitty;
+import org.sharengo.wikitty.WikittyService;
+import org.sharengo.wikitty.WikittyUtil;
+import org.sharengo.wikitty.search.Search;
+import org.sharengo.wikitty.test.util.GenTestData;
+import org.sharengo.wikitty.test.util.ImportFeedback;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittySearchEngineTest extends TestCase {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittySearchEngineTest.class);
+
+ /** 10 search by field */
+ static final int MAX = 10;
+
+ static String[] allFieldNames = new String[]{
+ "Personne.civilite",
+ "Personne.nom",
+ "Personne.prenom",
+ "Personne.date_naissance",
+ "Personne.poids",
+ "Employe.matricule",
+ "Employe.arrivee",
+ "Employe.salaire"
+ };
+
+ /**
+ * used to count some element during data loading, this information
+ * is used to assert statement
+ */
+ static public class AssertReference implements ImportFeedback {
+
+ /** total number imported elements */
+ public int count = 0;
+ /** key: fqfieldname value: map(fieldvalue, count this value) */
+ public Map<String, Map<Object, Integer>> fieldValueCounters =
+ new HashMap<String, Map<Object, Integer>>();
+
+ public void importPerformed(long nbImportedElements, long deltaTime) {
+ // do nothing
+ }
+
+ public void parsed(Wikitty w) {
+ count++;
+
+ for (String fqf : allFieldNames) {
+ Map<Object, Integer> fvc = fieldValueCounters.get(fqf);
+ if (fvc == null) {
+ fvc = new HashMap<Object, Integer>();
+ fieldValueCounters.put(fqf, fvc);
+ }
+ Object key = w.getFqField(fqf);
+ Integer n = fvc.get(key);
+ if (n == null) {
+ n = 1;
+ } else {
+ n = n + 1;
+ }
+ fvc.put(key, n);
+ }
+ }
+
+ }
+
+ WikittyService ws;
+ AssertReference assertReference;
+
+ // TODO poussin 20090901 this method is call for each test method, this method can be call only once for all test methods
+ @Override
+ public void setUp() throws Exception {
+ // import data and prepare expected result
+ ws = new WikittyServiceJDBC();
+ ((WikittyServiceJDBC)ws).getSearchEngin().clear();
+ assertReference = new AssertReference();
+ GenTestData.importGeneratedFile(
+ GenTestData.getDataFile("selected-data.txt"), ws, assertReference);
+
+ }
+
+ /**
+ * Do MAX search for each field in object and compare result size with
+ * number found during import
+ *
+ * @throws Exception
+ */
+ public void testFindByExample() throws Exception {
+ for (String fqf : allFieldNames) {
+ int cpt = 0; // cpt to stop loop after amount of test
+ Wikitty w = new Wikitty();
+ w.addExtension(GenTestData.ext_personne);
+ w.addExtension(GenTestData.ext_employe);
+
+ Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
+ for (Object value : fvc.keySet()) {
+ System.out.println("search on: " + fqf + " with value: " + value);
+ if(++cpt >= MAX) {
+ break;
+ }
+ int nb = fvc.get(value);
+ w.setFqField(fqf, value);
+ Criteria criteria = Search.query(w).criteria()
+ .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+ System.out.println("Count: " + result.size() + " Query: " + result.getQueryString());
+ assertEquals(nb, result.size());
+ }
+ }
+ }
+
+ /**
+ * Do MAX search for each field in object and compare result size with
+ * number found during import
+ *
+ * @throws Exception
+ */
+ public void testFindByCriteria() throws Exception {
+ for (String fqf : allFieldNames) {
+ int cpt = 0; // cpt to stop loop after amount of test
+
+ int sum = 0; // sum number of finding object for this fqf
+ List values = new LinkedList();
+
+ Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
+ for (Object value : fvc.keySet()) {
+ if(++cpt >= MAX) {
+ break;
+ }
+ int nb = fvc.get(value);
+
+ // stock number and value for last test
+ sum += nb;
+ values.add(value);
+
+ Criteria criteria = Search.query()
+ .eq(fqf, WikittyUtil.toString(value))
+ .criteria()
+ .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+
+ assertEquals(nb, result.size());
+ }
+
+ Search query = Search.query().or();
+ for (Object value : values) {
+ query.eq(fqf, WikittyUtil.toString(value));
+ }
+ Criteria criteria = query.criteria()
+ .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS);
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+ System.out.println("query: " + result.getQueryString());
+ assertEquals(sum, result.size());
+ }
+ }
+
+ /**
+ * Do search for 'Personne.nom==*' for limited result number, total number
+ * available in solr must be equals to number found during import
+ *
+ * @throws Exception
+ */
+ public void testFindByCriteriaNumFound() throws Exception {
+ String fqf = "Personne.nom";
+ Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
+ .setFirstIndex(0).setEndIndex(2);
+
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+
+ assertEquals(assertReference.count, result.getNumFound());
+ }
+
+ /**
+ * Do search on Personne.nom and ask facet for Personne.nom, all Topic
+ * must be equals (name and count) to name and number found during import
+ *
+ * @throws Exception
+ */
+ public void testFindByCriteriaFieldFacet() throws Exception {
+ String fqf = "Personne.nom";
+ Map<Object, Integer> fvc = assertReference.fieldValueCounters.get(fqf);
+ Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
+ .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
+ .addFacetField(fqf);
+
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+
+ assertEquals(new ArrayList(Arrays.asList(fqf)),
+ new ArrayList(result.getFacetNames()));
+ List<FacetTopic> topics = result.getTopic(fqf);
+
+ for (FacetTopic t : topics) {
+ String name = t.getTopicName();
+ int num = t.getCount();
+
+ System.out.println("name: " + name + " keys: " + fvc.keySet());
+ assertNotNull(fvc.get(name));
+ int realNum = fvc.get(name);
+ assertEquals(realNum, num);
+ }
+ }
+
+ /**
+ * Do search on Personne.nom and ask facet for Personne.civilite 2
+ * named facet criteria:
+ * - homme (civilite==Mr)
+ * - femme (civilite==Me OR civilite==Mlle)
+ *
+ * @throws Exception
+ */
+ public void testFindByCriteriaCriteriaFacet() throws Exception {
+ String fqf = "Personne.nom";
+ String facetName = "Personne.civilite";
+
+ Criteria homme = Search.query().eq(facetName, "Mr").criteria("homme");
+ Criteria femme = Search.query()
+ .eq(facetName, "Me").or().eq(facetName, "Mlle")
+ .criteria("femme");
+
+ Criteria criteria = Search.query().neq(fqf, "aaaaa").criteria()
+ .setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
+ .addFacetCriteria(homme).addFacetCriteria(femme);
+
+ PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
+
+ assertEquals(2, result.getFacetNames().size());
+
+ System.out.println("facet names: " + result.getFacetNames());
+
+ assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Mr"));
+ assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Me"));
+ assertNotNull(assertReference.fieldValueCounters.get(facetName).get("Mlle"));
+
+ int numMr = assertReference.fieldValueCounters.get(facetName).get("Mr");
+ int numMe = assertReference.fieldValueCounters.get(facetName).get("Me");
+ int numMlle = assertReference.fieldValueCounters.get(facetName).get("Mlle");
+
+ log.info("numMr: " + numMr);
+ log.info("numMe: " + numMe);
+ log.info("numMlle: " + numMlle);
+
+ List<FacetTopic> hommeTopics = result.getTopic("homme");
+ List<FacetTopic> femmeTopics = result.getTopic("femme");
+
+ assertEquals(1, hommeTopics.size());
+ assertEquals(1, femmeTopics.size());
+
+ FacetTopic hommeTopic = hommeTopics.get(0);
+ FacetTopic femmeTopic = femmeTopics.get(0);
+
+ assertEquals(numMr, hommeTopic.getCount());
+ assertEquals(numMe + numMlle, femmeTopic.getCount());
+ }
+}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/jdbc.properties
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/jdbc.properties 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/jdbc.properties 2009-11-04 10:19:47 UTC (rev 308)
@@ -8,8 +8,7 @@
jdbc.queries.creation.extension.admin=CREATE TABLE IF NOT EXISTS extension_admin (\
id text NOT NULL,\
name text NOT NULL,\
-version varchar(8) NOT NULL,\
-requires text);\
+version varchar(8) NOT NULL);\
ALTER TABLE extension_admin ADD PRIMARY KEY (id);
#table extension_data creation query
@@ -66,7 +65,7 @@
(id, fieldName, %s) VALUES ('%s', '%s.%s', %s);
#extension insertion in the admin table query
jdbc.queries.insert.extension.admin=INSERT INTO extension_admin\
-(id, name, version, requires) VALUES ('%s', '%s', '%s', %s);
+(id, name, version) VALUES ('%s', '%s', '%s');
#extension insertion in the data table query
jdbc.queries.insert.extension.data=INSERT INTO extension_data\
(id, fieldName, fieldType) VALUES ('%s', '%s', '%s');
\ No newline at end of file
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/solrconfig.xml
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/solrconfig.xml 2009-11-04 10:18:51 UTC (rev 307)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/resources/solrconfig.xml 2009-11-04 10:19:47 UTC (rev 308)
@@ -675,9 +675,11 @@
-->
<queryResponseWriter name="xslt" class="org.apache.solr.request.XSLTResponseWriter">
<int name="xsltCacheLifetimeSeconds">5</int>
- </queryResponseWriter>
+ </queryResponseWriter>
+ <queryParser name="wikitty" class="org.sharengo.wikitty.solr.WikittyQueryParser"/>
+
<!-- example of registering a query parser
<queryParser name="lucene" class="org.apache.solr.search.LuceneQParserPlugin"/>
-->
1
0
r307 - in wikengo_core-wikitty/wikengo_core-wikitty-api/src: main/java/org/sharengo/wikitty test/java/org/sharengo/wikitty test/java/org/sharengo/wikitty/test/api test/java/org/sharengo/wikitty/test/conform
by kmorin@users.nuiton.org 04 Nov '09
by kmorin@users.nuiton.org 04 Nov '09
04 Nov '09
Author: kmorin
Date: 2009-11-04 11:18:51 +0100 (Wed, 04 Nov 2009)
New Revision: 307
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java
Log:
Separation of solr
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -1,16 +1,16 @@
/* *##%
* Copyright (c) 2009 poussin. All rights reserved.
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*##%*/
@@ -252,7 +252,7 @@
getSearchEngin().commit(transaction, indexCommands);
}
-
+
public PagedResult<Wikitty> findAllByCriteria(Criteria criteria) {
PagedResult<String> resultId = getSearchEngin().findAllByCriteria(criteria);
PagedResult<Wikitty> result = resultId.cast(getWikittyStorage());
@@ -270,7 +270,7 @@
}
}
-
+
public void addLabel(String wikittyId, String label) {
Wikitty w = restore(wikittyId);
w.addExtension(LabelImpl.extensions);
@@ -279,7 +279,7 @@
store(l.getWikitty());
}
-
+
public PagedResult<Wikitty> findAllByLabel(String label, int firstIndex, int endIndex) {
LabelImpl l = new LabelImpl();
l.addLabels(label);
@@ -289,7 +289,7 @@
return result;
}
-
+
public Wikitty findByLabel(String label) {
LabelImpl l = new LabelImpl();
l.addLabels(label);
@@ -298,7 +298,7 @@
return result;
}
-
+
public Set<String> findAllAppliedLabels(String wikittyId) {
Wikitty w = restore(wikittyId);
Label l = new LabelImpl(w);
@@ -306,7 +306,7 @@
return result;
}
-
+
public Tree restoreTree(String wikittyId) {
Wikitty w = restore(wikittyId);
if(w == null) {
@@ -321,7 +321,7 @@
Tree tree = new Tree();
TreeNode node = new TreeNodeImpl( w );
tree.setNode( node );
-
+
TreeNodeImpl exempleNode = new TreeNodeImpl();
exempleNode.setParent(wikittyId);
@@ -337,7 +337,7 @@
tree.addElement(childrenId);
}
}
-
+
return tree;
}
@@ -346,7 +346,7 @@
if(w == null) {
return null;
}
-
+
if ( !w.hasExtension(TreeNode.EXT_TREENODE) ) {
throw new WikittyException(String.format(
"Wikitty '%s' do not handle extension %s",
@@ -369,7 +369,7 @@
return result;
}
-
+
public Wikitty restoreVersion(String wikittyId, String version) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -433,7 +433,7 @@
}
}
-
+
public void syncImportFromXml(String xml) {
Reader reader = new StringReader(xml);
ImportTask task = new ImportTask(this, reader);
@@ -452,7 +452,7 @@
}
}
-
+
public String asyncImportFromUri(String uri) {
try {
URL url = new URL(uri);
@@ -460,7 +460,7 @@
ImportTask task = new ImportTask(this, reader);
FutureTask<String> future = new FutureTask<String>(task, null);
importExportExecutor.submit(future);
-
+
String jobId = UUID.randomUUID().toString();
importExportTask.put(jobId, future);
return jobId;
@@ -478,7 +478,7 @@
this.ws = ws;
this.reader = reader;
}
-
+
public void run() {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
@@ -558,7 +558,7 @@
}
}
} // end ImportTask
-
+
public String asyncExportAllByCriteria(Criteria criteria) {
try {
criteria.setFirstIndex(0).setEndIndex(ALL_ELEMENTS);
@@ -580,7 +580,7 @@
}
}
-
+
public String syncExportAllByCriteria(Criteria criteria) {
criteria.setFirstIndex(0).setEndIndex(ALL_ELEMENTS);
PagedResult<Wikitty> pageResult = findAllByCriteria(criteria);
@@ -589,8 +589,8 @@
task.run();
return result.toString();
}
-
+
static public class ExportTask implements Runnable {
protected PagedResult<Wikitty> pageResult;
protected Writer result;
@@ -599,7 +599,7 @@
this.pageResult = pageResult;
this.result = result;
}
-
+
public void run() {
try {
// keep extension already done
@@ -644,7 +644,7 @@
}
} // end ExportTask
-
+
public JobState infoJob(String jobId) {
try {
Future<String> future = importExportTask.get(jobId);
@@ -663,13 +663,13 @@
}
}
-
+
public void cancelJob(String jobId) {
Future future = importExportTask.get(jobId);
future.cancel(true); // true to kill process, perhaps to strong ?
}
-
+
public void freeJobResource(String jobId) {
Future<String> future = importExportTask.remove(jobId);
if (future != null) {
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -9,22 +9,22 @@
TreeNode node;
List<Tree> children;
// List<String> elements;
-
+
public void setNode(TreeNode node) {
this.node = node;
}
-
+
public void addChild(Tree tree) {
getChildren().add( tree );
}
-
+
public List<Tree> getChildren() {
if ( children == null ) {
children = new ArrayList<Tree>();
}
return children;
}
-
+
public void addElement(String id) {
node.addChildren(id);
}
@@ -32,7 +32,7 @@
public Set<String> getElements() {
return node.getChildren();
}
-
+
public String getName() {
return node.getName();
}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -42,7 +42,7 @@
static final public int ALL_ELEMENTS = WikittyService.ALL_ELEMENTS;
protected WikittyService wikittyService;
-
+
public WikittyService getWikittyService() {
return wikittyService;
}
@@ -206,8 +206,6 @@
* needed by BusinessEntity (clazz).
* @param clazz
* @param criteria
- * @param firstIndex
- * @param endIndex
* @return
*/
public <E extends BusinessEntity> PagedResult<E> findAllByCriteria(
@@ -226,7 +224,7 @@
serviceCriteria.setFirstIndex(criteria.getFirstIndex());
serviceCriteria.setEndIndex(criteria.getEndIndex());
PagedResult<Wikitty> pagedResult = wikittyService.findAllByCriteria(serviceCriteria);
-
+
// we can cast with autoconvert true because we have add restriction
// on extension
PagedResult<E> result = (PagedResult<E>)pagedResult.cast(sample.getClass(), true);
@@ -296,11 +294,11 @@
} catch (Exception eee) {
throw new WikittyException(eee);
}
-
+
// WikittyUtil.newInstance instanciate only BusinessEntityWikittyImpl
BusinessEntityWikitty businessEntityImpl = (BusinessEntityWikitty) businessEntity;
Collection<WikittyExtension> staticExtensions = businessEntityImpl.getStaticExtensions();
-
+
boolean goodType = true;
for (Iterator<WikittyExtension> iterator = staticExtensions.iterator(); iterator.hasNext() && goodType;) {
WikittyExtension ext = iterator.next();
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -1,16 +1,16 @@
/* *##%
* Copyright (c) 2009 poussin. All rights reserved.
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*##%*/
@@ -60,13 +60,18 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceInMemory.class);
+ @Override
+ public List<WikittyExtension> getAllExtensions(boolean lastVersion) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
class WikittyStorageInMemory implements WikittyStorage {
protected Map<String, Wikitty> wikitties = new LinkedHashMap<String, Wikitty>();
public List<Command> prepare(WikittyTransaction transaction,
Collection<Wikitty> wikitties,
boolean disableAutoVersionIncrement) throws WikittyException {
-
+
List<Command> result = new ArrayList<Command>(wikitties.size());
for (Wikitty w : wikitties) {
result.add(new CommandInMemory(w, true));
@@ -223,7 +228,7 @@
public WikittySearchEnginInMemory(WikittyStorageInMemory wikittyStorage) {
this.wikittyStorage = wikittyStorage;
}
-
+
public void clear() {
// do nothing
}
@@ -245,15 +250,15 @@
// do nothing
return new ArrayList<Command>();
}
-
+
public boolean checkRestriction( Restriction restriction, Wikitty w ) {
if ( restriction instanceof BinaryOperator ) {
BinaryOperator binOp = (BinaryOperator) restriction;
-
+
if ( binOp.getElement().equals(Element.ELT_EXTENSION) ) {
return w.hasExtension( (String) binOp.getValue() );
}
-
+
String fqfieldName = binOp.getElement().getName();
Object o = w.getFqField( fqfieldName );
FieldType t = w.getFieldType(fqfieldName);
@@ -279,13 +284,13 @@
checked = !value.equals(o);
break;
case ENDS_WITH:
- if ( t.getType() != TYPE.STRING )
+ if ( t.getType() != TYPE.STRING )
throw new WikittyException("Can't search for contents that 'ends with' on attribute type different of String. " +
"Attribute " + fqfieldName + " is " + t.getType().name() );
checked = ((String) o).endsWith( (String) value );
break;
case STARTS_WITH:
- if ( t.getType() != TYPE.STRING )
+ if ( t.getType() != TYPE.STRING )
throw new WikittyException("Can't search for contents that 'starts with' on attribute type different of String. " +
"Attribute " + fqfieldName + " is " + t.getType().name() );
checked = ((String) o).startsWith( (String) value );
@@ -306,24 +311,24 @@
public PagedResult<String> findAllByCriteria(
Criteria criteria) {
// throw new UnsupportedOperationException("Not supported yet.");
-
+
int firstIndex = criteria.getFirstIndex();
int endIndex = criteria.getEndIndex();
-
+
List<String> ids = new LinkedList<String>();
int currentIndex = 0;
-
+
for( Entry<String, Wikitty> entry : wikittyStorage.wikitties.entrySet() ) {
Wikitty w = entry.getValue();
String id = entry.getKey();
Restriction dto = criteria.getRestriction();
-
+
if ( checkRestriction(dto, w) ) {
currentIndex++;
if ( currentIndex > firstIndex ) ids.add( id );
if ( endIndex >= 0 && currentIndex >= endIndex ) break;
}
-
+
}
return new PagedResult<String>(firstIndex, endIndex, criteria.getRestriction().toString(), null, ids );
}
@@ -412,4 +417,4 @@
}
}
-}
+}
\ No newline at end of file
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -1,16 +1,16 @@
/* *##%
* Copyright (c) 2009 poussin. All rights reserved.
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*##%*/
@@ -53,7 +53,7 @@
public class WikittyUtil {
public static final String DEFAULT_VERSION = "0.0";
-
+
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyUtil.class);
@@ -69,7 +69,7 @@
setTimeZone(CANONICAL_TZ);
}
}
-
+
/** All date format parser used to convert string to date */
static final protected DateFormat[] parserDateFormats = new DateFormat[]{
solrDateFormat,
@@ -533,8 +533,10 @@
* @param clazz class of the new instance
* @param w wikitty object to use internaly for in new instance
* @return
+ * @deprecated You should use <name>Impl.toBean() and new <name>Impl(Bean)
*/
// E extends BeanDto to permit business interface as parameter
+ @Deprecated
static public <E extends BusinessEntity> E newInstance(Class<E> clazz, Wikitty w) {
try {
Class clazzInstanciable = clazz;
@@ -744,10 +746,10 @@
byte[] b = new byte[16];
for ( int i = 0; i < 16; i++ ) {
b[i] = (byte) (current & 0xff);
- current = current >> 8;
+ current = current >> 8;
if ( i == 7 ) current = leastSignificant;
}
return enc.encode(b);
*/
}
-}
+}
\ No newline at end of file
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -6,6 +6,7 @@
import org.sharengo.wikitty.test.api.CommonTest;
import org.sharengo.wikitty.test.api.ExtensionFactoryTest;
import org.sharengo.wikitty.test.api.SearchCriteriaTest;
+import org.sharengo.wikitty.test.api.WikittyUtilTest;
import org.sharengo.wikitty.test.conform.SearchApiTest;
import org.sharengo.wikitty.test.conform.StorageTest;
import org.sharengo.wikitty.test.memory.InMemoryStorageTest;
@@ -18,6 +19,7 @@
CommonTest.class,
ExtensionFactoryTest.class,
SearchCriteriaTest.class,
+ WikittyUtilTest.class,
/*
* Conformance Tests
*/
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -19,22 +19,15 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;
import java.math.BigDecimal;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.List;
+import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.sharengo.wikitty.FieldType;
-import org.sharengo.wikitty.Label;
-import org.sharengo.wikitty.LabelImpl;
-import org.sharengo.wikitty.TreeNodeBean;
-import org.sharengo.wikitty.TreeNodeImpl;
import org.sharengo.wikitty.WikittyExtension;
import org.sharengo.wikitty.WikittyUtil;
@@ -381,15 +374,13 @@
assertNotNull( ext.getFieldType("buildDate") );
}
- // use in testNewInstance
- static class MonLabel extends LabelImpl {
- }
/**
* test newInstance method, and verify that we can configure implementation
* for specifique interface
* @throws Exception
*/
+ /* Deprecated operation no more tested
@Test
public void testNewInstance() throws Exception {
Label label = WikittyUtil.newInstance(Label.class, null);
@@ -399,15 +390,6 @@
label = WikittyUtil.newInstance(Label.class, null);
assertNull(label);
}
+ */
- @Test
- public void testConvert() throws Exception {
- TreeNodeImpl impl = new TreeNodeImpl();
- impl.setName("toto");
- impl.setParent("idparent");
-
- TreeNodeBean bean = WikittyUtil.wikittyToBean(TreeNodeBean.class, impl);
- assertEquals(impl.getName(), bean.getName());
- assertEquals(impl.getParent(), bean.getParent());
- }
}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java 2009-11-04 10:15:49 UTC (rev 306)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java 2009-11-04 10:18:51 UTC (rev 307)
@@ -413,7 +413,7 @@
}
-
+
private void assign(Wikitty wikitty, TreeNodeImpl root, String path) {
String[] nodeNames = path.split("/");
TreeNodeImpl currentNode = root;
1
0
r306 - in testmavenvalidators/trunk: . src src/main src/main/java src/main/java/org src/main/java/org/nuiton src/main/java/org/nuiton/test src/main/resources src/main/resources/META-INF src/main/resources/META-INF/plexus
by echatellier@users.nuiton.org 04 Nov '09
by echatellier@users.nuiton.org 04 Nov '09
04 Nov '09
Author: echatellier
Date: 2009-11-04 11:15:49 +0100 (Wed, 04 Nov 2009)
New Revision: 306
Added:
testmavenvalidators/trunk/pom.xml
testmavenvalidators/trunk/src/
testmavenvalidators/trunk/src/main/
testmavenvalidators/trunk/src/main/java/
testmavenvalidators/trunk/src/main/java/org/
testmavenvalidators/trunk/src/main/java/org/nuiton/
testmavenvalidators/trunk/src/main/java/org/nuiton/test/
testmavenvalidators/trunk/src/main/java/org/nuiton/test/NonSnapshotValidator.java
testmavenvalidators/trunk/src/main/resources/
testmavenvalidators/trunk/src/main/resources/META-INF/
testmavenvalidators/trunk/src/main/resources/META-INF/plexus/
testmavenvalidators/trunk/src/main/resources/META-INF/plexus/components.xml
Modified:
testmavenvalidators/trunk/
Log:
Add test about additionnals maven validators (not working)
Property changes on: testmavenvalidators/trunk
___________________________________________________________________
Added: svn:ignore
+ .settings
target
.classpath
.project
Added: testmavenvalidators/trunk/pom.xml
===================================================================
--- testmavenvalidators/trunk/pom.xml (rev 0)
+++ testmavenvalidators/trunk/pom.xml 2009-11-04 10:15:49 UTC (rev 306)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!--The version of maven's project object model-->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!--A unique name for this project-->
+ <groupId>org.nuiton</groupId>
+ <artifactId>test</artifactId>
+ <name>test</name>
+
+ <!--ejb, jar, war...-->
+ <packaging>jar</packaging>
+
+ <!--Version-->
+ <version>0.0.0</version>
+
+ <!--Description-->
+ <description>test</description>
+ <inceptionYear>2009</inceptionYear>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project </artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: testmavenvalidators/trunk/src/main/java/org/nuiton/test/NonSnapshotValidator.java
===================================================================
--- testmavenvalidators/trunk/src/main/java/org/nuiton/test/NonSnapshotValidator.java (rev 0)
+++ testmavenvalidators/trunk/src/main/java/org/nuiton/test/NonSnapshotValidator.java 2009-11-04 10:15:49 UTC (rev 306)
@@ -0,0 +1,40 @@
+package org.nuiton.test;
+
+import org.apache.maven.model.Activation;
+import org.apache.maven.model.ActivationProperty;
+import org.apache.maven.model.Profile;
+import org.apache.maven.profiles.activation.DetectedProfileActivator;
+
+public class NonSnapshotValidator extends DetectedProfileActivator
+{
+
+ /*
+ * @see org.apache.maven.profiles.activation.DetectedProfileActivator#canDetectActivation(org.apache.maven.model.Profile)
+ */
+ @Override
+ protected boolean canDetectActivation(Profile profile) {
+ Activation activation = profile.getActivation();
+ return activation != null && activation.getProperty() != null;
+ }
+
+ public boolean isActive( Profile profile )
+ {
+ Activation activation = profile.getActivation();
+ ActivationProperty property = activation.getProperty();
+
+ boolean result = false;
+ if ("version".equals(property.getName())) {
+ System.out.println("Test property.getName() : " + property.getName());
+ if (property.getValue() != null && !property.getValue().endsWith("-SNAPSHOT")) {
+ result = true;
+ }
+ }
+
+ System.out.println("Test property.getName() : " + property.getName() + " : " + result) ;
+
+ return result;
+ }
+
+
+
+}
Property changes on: testmavenvalidators/trunk/src/main/java/org/nuiton/test/NonSnapshotValidator.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testmavenvalidators/trunk/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- testmavenvalidators/trunk/src/main/resources/META-INF/plexus/components.xml (rev 0)
+++ testmavenvalidators/trunk/src/main/resources/META-INF/plexus/components.xml 2009-11-04 10:15:49 UTC (rev 306)
@@ -0,0 +1,10 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.profiles.activation.ProfileActivator</role>
+ <role-hint>non-snapshot</role-hint>
+ <implementation>org.nuiton.test.NonSnapshotValidator</implementation>
+ </component>
+ </components>
+</component-set>
+
\ No newline at end of file
1
0
Author: echatellier
Date: 2009-11-04 11:14:55 +0100 (Wed, 04 Nov 2009)
New Revision: 305
Added:
testmavenvalidators/
testmavenvalidators/trunk/
Log:
Initial import.
1
0
r304 - wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc
by kmorin@users.nuiton.org 03 Nov '09
by kmorin@users.nuiton.org 03 Nov '09
03 Nov '09
Author: kmorin
Date: 2009-11-03 12:00:39 +0100 (Tue, 03 Nov 2009)
New Revision: 304
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
Log:
permits to have fields with spaces
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-11-02 08:13:33 UTC (rev 303)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-11-03 11:00:39 UTC (rev 304)
@@ -84,6 +84,8 @@
*/
protected Properties conf = loadProperties();
+ public static String WORD_SEPARATOR = "_";
+
class CommandJDBC implements Command {
protected String queries;
@@ -165,7 +167,7 @@
for (String fieldName : ext.getFieldNames()) {
FieldType type = ext.getFieldType(fieldName);
batch.append(String.format(conf.getProperty(dataInsertQ),
- ext.getId(), fieldName, type.toDefinition(fieldName)));
+ ext.getId(), fieldName.replace(" ", WORD_SEPARATOR), type.toDefinition(fieldName.replace(" ", WORD_SEPARATOR))));
}
} else {
log.warn("The extension is found " + id);
@@ -358,7 +360,7 @@
String fieldDef = dataResultSet.getString(COL_FIELDTYPE);
FieldType fieldType = new FieldType();
String fieldName = WikittyUtil.parseField(fieldDef, fieldType);
- fieldTypes.put(fieldName, fieldType);
+ fieldTypes.put(fieldName.replace(WORD_SEPARATOR, " "), fieldType);
}
result = new WikittyExtension(extName, extVersion, extRequires, fieldTypes);
1
0
Author: tchemit
Date: 2009-11-02 09:13:33 +0100 (Mon, 02 Nov 2009)
New Revision: 303
Removed:
jredmine/
Log:
remove old jredmine from sandbox
1
0
r302 - wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc
by kmorin@users.nuiton.org 30 Oct '09
by kmorin@users.nuiton.org 30 Oct '09
30 Oct '09
Author: kmorin
Date: 2009-10-30 15:36:35 +0100 (Fri, 30 Oct 2009)
New Revision: 302
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
Log:
Correction in the getAllExtensions(true) method
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-10-29 18:53:59 UTC (rev 301)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-10-30 14:36:35 UTC (rev 302)
@@ -269,7 +269,8 @@
adminResultSet.beforeFirst();
while (adminResultSet.next()) {
String extName = adminResultSet.getString(COL_NAME);
- String extId = getLastVersion(extName);
+ String extVersion = getLastVersion(extName);
+ String extId = WikittyExtension.computeId(extName, extVersion);
result.add(restore(extId));
}
} else {
1
0
r301 - in wikengo_core-wikitty: . wikengo_core-wikitty-api wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty wikengo_core-wikitty-jdbc-impl
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 19:53:59 +0100 (Thu, 29 Oct 2009)
New Revision: 301
Modified:
wikengo_core-wikitty/
wikengo_core-wikitty/wikengo_core-wikitty-api/
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntity.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityWikitty.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/
Log:
remove all PCS on Wikitty + svn:ignore on target + *.iml
Property changes on: wikengo_core-wikitty
___________________________________________________________________
Added: svn:ignore
+ target
*.iml
Property changes on: wikengo_core-wikitty/wikengo_core-wikitty-api
___________________________________________________________________
Added: svn:ignore
+ target
*.iml
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntity.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntity.java 2009-10-29 15:12:30 UTC (rev 300)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntity.java 2009-10-29 18:53:59 UTC (rev 301)
@@ -17,7 +17,6 @@
package org.sharengo.wikitty;
-import java.beans.PropertyChangeListener;
import java.io.Serializable;
import java.util.Collection;
@@ -78,17 +77,4 @@
* @return
*/
public FieldType getFieldType(String ext, String fieldName);
-
- public void addPropertyChangeListener(
- PropertyChangeListener listener);
-
- public void removePropertyChangeListener(
- PropertyChangeListener listener);
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
-
}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java 2009-10-29 15:12:30 UTC (rev 300)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java 2009-10-29 18:53:59 UTC (rev 301)
@@ -17,8 +17,6 @@
package org.sharengo.wikitty;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -39,9 +37,6 @@
protected String id;
protected String version;
- /** used to add property change support to wikitty object */
- protected PropertyChangeSupport propertyChange = new PropertyChangeSupport(this);
-
/**
* Map is LinkedHashMap to maintains order like user want
* key: extension name
@@ -88,31 +83,10 @@
public void setField(String ext, String fieldName, Object value) {
String key = ext + "$" + fieldName;
fieldValue.put(key, value);
- propertyChange.firePropertyChange(fieldName, null, value);
}
public FieldType getFieldType(String ext, String fieldName) {
throw new UnsupportedOperationException("Not supported yet.");
}
- public void addPropertyChangeListener(
- PropertyChangeListener listener) {
- propertyChange.addPropertyChangeListener(listener);
}
-
- public void removePropertyChangeListener(
- PropertyChangeListener listener) {
- propertyChange.removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- propertyChange.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- propertyChange.removePropertyChangeListener(propertyName, listener);
- }
-
- }
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityWikitty.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityWikitty.java 2009-10-29 15:12:30 UTC (rev 300)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityWikitty.java 2009-10-29 18:53:59 UTC (rev 301)
@@ -17,8 +17,6 @@
package org.sharengo.wikitty;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Collection;
import java.util.Collections;
@@ -33,7 +31,7 @@
* Last update: $Date$
* by : $Author$
*/
-public class BusinessEntityWikitty implements BusinessEntity,PropertyChangeListener {
+public class BusinessEntityWikitty implements BusinessEntity {
private static final long serialVersionUID = 1L;
@@ -48,36 +46,8 @@
public BusinessEntityWikitty() {
setWikitty( new Wikitty() );
- // on ecoute les changement du wikkity
- wikitty.addPropertyChangeListener(this);
}
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- propertyChange.firePropertyChange(evt);
- }
-
- public void addPropertyChangeListener(
- PropertyChangeListener listener) {
- propertyChange.addPropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(
- PropertyChangeListener listener) {
- propertyChange.removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- System.out.println("addPRopertyChangeListener "+propertyName+" = "+listener);
- propertyChange.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- propertyChange.removePropertyChangeListener(propertyName, listener);
- }
-
public String getWikittyId() {
String result = getWikitty().getId();
return result;
Property changes on: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl
___________________________________________________________________
Added: svn:ignore
+ target
*.iml
1
0
r300 - in wikengo_core-wikitty: wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc
by kmorin@users.nuiton.org 29 Oct '09
by kmorin@users.nuiton.org 29 Oct '09
29 Oct '09
Author: kmorin
Date: 2009-10-29 16:12:30 +0100 (Thu, 29 Oct 2009)
New Revision: 300
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyExtensionStorage.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyService.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyJDBCUtil.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyStorageJDBC.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java
wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java
Log:
add getAllExtensions(boolean) method + few corrections
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -105,7 +105,7 @@
/**
* Store and index wikitties object
- * @param wikitty
+ * @param wikitties
*/
public UpdateResponse store(Collection<Wikitty> wikitties) {
return store(wikitties, false);
@@ -113,8 +113,8 @@
/**
* Store and index wikitties object
- * @param wikitty
- * @param TODO
+ * @param wikitties
+ * @param disableAutoVersionIncrement
*/
public UpdateResponse store(Collection<Wikitty> wikitties, boolean disableAutoVersionIncrement) {
try {
@@ -166,9 +166,14 @@
return result;
}
+ public List<WikittyExtension> getAllExtensions(boolean lastVersion) {
+ List<WikittyExtension> result = getExtensionStorage().getAllExtensions(lastVersion);
+ return result;
+ }
+
/**
* Save just one extension
- * @param ext
+ * @param exts
* @throws java.io.IOException
*/
public UpdateResponse storeExtension(Collection<WikittyExtension> exts) {
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyExtensionStorage.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyExtensionStorage.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyExtensionStorage.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -61,6 +61,13 @@
public List<String> getAllExtensionIds();
/**
+ * Return all extensions (ex: "extName[version])")
+ * @param lastVersion if true, returns only the last version of each extension
+ * @return
+ */
+ public List<WikittyExtension> getAllExtensions(boolean lastVersion);
+
+ /**
* return last version available for specified extension name
* @param extName name of extension
* @return last version availble for this version, or null if extension
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyService.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyService.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyService.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -17,6 +17,7 @@
package org.sharengo.wikitty;
+import javax.swing.tree.TreeNode;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -72,6 +73,13 @@
*/
List<String> getAllExtensionIds();
+ /**
+ * Return all extensions (ex: "extName[version])")
+ * @param lastVersion if true, returns only the last version of each extension
+ * @return
+ */
+ List<WikittyExtension> getAllExtensions(boolean lastVersion);
+
/**
* Manage Update and creation.
*
@@ -149,7 +157,7 @@
/**
*
- * @param addLabel
+ * @param label
* @return
*/
Wikitty findByLabel(String label);
@@ -183,7 +191,7 @@
* @param wikittyId
* @return
*/
- Map<TreeNode, Integer> restoreChildren(String wikittyId);
+ Map<org.sharengo.wikitty.TreeNode, Integer> restoreChildren(String wikittyId);
/*
@@ -203,7 +211,7 @@
/**
* synchonous or not ?
*
- * @param xmlData data to import
+ * @param xml data to import
*/
void syncImportFromXml(String xml);
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -191,6 +191,11 @@
return result;
}
+ @Override
+ public List<WikittyExtension> getAllExtensions(boolean lastVersion) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
public WikittyExtension restore(String id) throws WikittyException {
WikittyExtension result = extensions.get(id);
if (result == null) {
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/Restriction2Solr.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -1,9 +1,5 @@
package org.sharengo.wikitty.jdbc;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
@@ -12,47 +8,38 @@
import org.apache.solr.common.SolrDocumentList;
import org.mortbay.log.Log;
import org.sharengo.wikitty.WikittyException;
-import org.sharengo.wikitty.search.And;
-import org.sharengo.wikitty.search.AssociatedRestriction;
-import org.sharengo.wikitty.search.Between;
-import org.sharengo.wikitty.search.Contains;
-import org.sharengo.wikitty.search.Element;
-import org.sharengo.wikitty.search.EndsWith;
-import org.sharengo.wikitty.search.Equals;
-import org.sharengo.wikitty.search.Greater;
-import org.sharengo.wikitty.search.GreaterOrEqual;
-import org.sharengo.wikitty.search.In;
-import org.sharengo.wikitty.search.Keyword;
-import org.sharengo.wikitty.search.Less;
-import org.sharengo.wikitty.search.LessOrEqual;
-import org.sharengo.wikitty.search.Not;
-import org.sharengo.wikitty.search.NotEquals;
-import org.sharengo.wikitty.search.Or;
-import org.sharengo.wikitty.search.Restriction;
-import org.sharengo.wikitty.search.RestrictionHelper;
-import org.sharengo.wikitty.search.StartsWith;
+import org.sharengo.wikitty.search.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
/**
* @author "Nicolas Chapurlat" <nicolas.chapurlat(a)logica.com>
* @author "Guillaume Dufrêne" <dufrene(a)argia.fr>
- *
- * This class is used to parse Restriction to create lucene request on
- * content. Every operators describe in RestrictionName is handle. Parsing may
- * throw exception when restriction parameters are incorrect.
+ * <p/>
+ * This class is used to parse Restriction to create lucene request on
+ * content. Every operators describe in RestrictionName is handle. Parsing may
+ * throw exception when restriction parameters are incorrect.
*/
public class Restriction2Solr {
-
- private static final int MAX_SUBQUERY_RESULT = 100;
- /** use to permit client to modify fieldname during query generation */
+ private static final int MAX_SUBQUERY_RESULT = 100;
+
+ /**
+ * use to permit client to modify fieldname during query generation
+ */
static public interface FieldModifier {
public String convertToSolr(String fieldname);
+
public String convertToField(String solrName);
}
+
final static protected FieldModifier dummyFieldModifier = new FieldModifier() {
public String convertToSolr(String fieldname) {
return fieldname;
}
+
public String convertToField(String solrName) {
return solrName;
}
@@ -69,331 +56,334 @@
}
public String toSolr(Restriction restriction) {
- return toSolr(restriction, null);
+ return toSolr(restriction, null);
}
-
- public String toSolr(Restriction restriction, SolrServer solr)
- throws WikittyException {
- // ParameterValidator.checkNullParameter(restriction, "restriction");
- switch (restriction.getName()) {
- case TRUE:
- return true2solr();
- case FALSE:
- return false2solr();
- case NOT:
- Not not = (Not) restriction;
- return not2solr(not);
- case AND:
- And and = (And) restriction;
- return and2solr(and);
- case OR:
- Or or = (Or) restriction;
- return or2solr(or);
- case EQUALS:
- Equals eq = (Equals) restriction;
- return eq2solr(eq);
- case NOT_EQUALS:
- NotEquals neq = (NotEquals) restriction;
- return neq2solr(neq);
- case LESS:
- Less less = (Less) restriction;
- return less2solr(less);
- case LESS_OR_EQUAL:
- LessOrEqual lessEq = (LessOrEqual) restriction;
- return lessEq2solr(lessEq);
- case GREATER:
- Greater great = (Greater) restriction;
- return great2solr(great);
- case GREATER_OR_EQUAL:
- GreaterOrEqual greatEq = (GreaterOrEqual) restriction;
- return greatEq2solr(greatEq);
- case BETWEEN:
- Between between = (Between) restriction;
- return between2solr(between);
- case CONTAINS:
- Contains contains = (Contains) restriction;
- return contains2solr(contains);
- case IN:
- In in = (In) restriction;
- return in2solr(in);
- case STARTS_WITH:
- StartsWith start = (StartsWith) restriction;
- return start2solr(start);
- case ENDS_WITH:
- EndsWith end = (EndsWith) restriction;
- return end2solr(end);
- case ASSOCIATED:
- AssociatedRestriction associated = (AssociatedRestriction) restriction;
- return associated2solr(associated, solr);
- case KEYWORD:
- Keyword keyword = (Keyword) restriction;
- return keyword2solr(keyword);
- default:
- throw new WikittyException("this kind of restriction is not supported : "
- + restriction.getName().toString());
- }
- }
- private String in2solr(In in) {
- boolean first = true;
- String result = in.getElement().getName() + ":[";
- for( String value : in.getValue() ) {
- if ( !first ) { result += ", "; first = false; }
- result += value;
- }
- result +="]";
- return result;
- }
+ public String toSolr(Restriction restriction, SolrServer solr)
+ throws WikittyException {
+ // ParameterValidator.checkNullParameter(restriction, "restriction");
+ switch (restriction.getName()) {
+ case TRUE:
+ return true2solr();
+ case FALSE:
+ return false2solr();
+ case NOT:
+ Not not = (Not) restriction;
+ return not2solr(not);
+ case AND:
+ And and = (And) restriction;
+ return and2solr(and);
+ case OR:
+ Or or = (Or) restriction;
+ return or2solr(or);
+ case EQUALS:
+ Equals eq = (Equals) restriction;
+ return eq2solr(eq);
+ case NOT_EQUALS:
+ NotEquals neq = (NotEquals) restriction;
+ return neq2solr(neq);
+ case LESS:
+ Less less = (Less) restriction;
+ return less2solr(less);
+ case LESS_OR_EQUAL:
+ LessOrEqual lessEq = (LessOrEqual) restriction;
+ return lessEq2solr(lessEq);
+ case GREATER:
+ Greater great = (Greater) restriction;
+ return great2solr(great);
+ case GREATER_OR_EQUAL:
+ GreaterOrEqual greatEq = (GreaterOrEqual) restriction;
+ return greatEq2solr(greatEq);
+ case BETWEEN:
+ Between between = (Between) restriction;
+ return between2solr(between);
+ case CONTAINS:
+ Contains contains = (Contains) restriction;
+ return contains2solr(contains);
+ case IN:
+ In in = (In) restriction;
+ return in2solr(in);
+ case STARTS_WITH:
+ StartsWith start = (StartsWith) restriction;
+ return start2solr(start);
+ case ENDS_WITH:
+ EndsWith end = (EndsWith) restriction;
+ return end2solr(end);
+ case ASSOCIATED:
+ AssociatedRestriction associated = (AssociatedRestriction) restriction;
+ return associated2solr(associated, solr);
+ case KEYWORD:
+ Keyword keyword = (Keyword) restriction;
+ return keyword2solr(keyword);
+ default:
+ throw new WikittyException("this kind of restriction is not supported : "
+ + restriction.getName().toString());
+ }
+ }
- private String associated2solr(AssociatedRestriction associated, SolrServer solr) throws WikittyException {
- String subQuery = toSolr( associated.getRestriction() );
- SolrQuery query = new SolrQuery(subQuery);
+ private String in2solr(In in) {
+ boolean first = true;
+ String result = in.getElement().getName() + ":[";
+ for (String value : in.getValue()) {
+ if (!first) {
+ result += ", ";
+ first = false;
+ }
+ result += value;
+ }
+ result += "]";
+ return result;
+ }
+
+ private String associated2solr(AssociatedRestriction associated, SolrServer solr) throws WikittyException {
+ String subQuery = toSolr(associated.getRestriction());
+ SolrQuery query = new SolrQuery(subQuery);
query.setRows(MAX_SUBQUERY_RESULT);
QueryResponse resp = null;
try {
- Log.info("Execute sub-query : " + subQuery);
- resp = solr.query(query);
- } catch (SolrServerException e) {
- throw new WikittyException("Unable to execute associative query on " + associated.getElement().getName(), e);
- }
+ Log.info("Execute sub-query : " + subQuery);
+ resp = solr.query(query);
+ } catch (SolrServerException e) {
+ throw new WikittyException("Unable to execute associative query on " + associated.getElement().getName(), e);
+ }
SolrDocumentList solrResults = resp.getResults();
-
+
Restriction generatedRestriction = null;
long size = solrResults.size();
- if ( size == 0 ) {
- throw new WikittyException("Associated " + associated.getElement().getName() + " do not retrieved any result");
+ if (size == 0) {
+ throw new WikittyException("Associated " + associated.getElement().getName() + " do not retrieved any result");
}
- if ( size == 1 ) {
- generatedRestriction = RestrictionHelper.eq( associated.getElement(), (String) solrResults.get(0).getFieldValue("id") );
+ if (size == 1) {
+ generatedRestriction = RestrictionHelper.eq(associated.getElement(), (String) solrResults.get(0).getFieldValue("id"));
} else {
- List<String> ids = new ArrayList<String>(solrResults.size());
- for (SolrDocument doc : solrResults) {
- String id = (String) doc.getFieldValue("id"); // FIXME : set a constant field reference
- ids.add(id);
- }
- generatedRestriction = new In(associated.getElement(), ids);
+ List<String> ids = new ArrayList<String>(solrResults.size());
+ for (SolrDocument doc : solrResults) {
+ String id = (String) doc.getFieldValue("id"); // FIXME : set a constant field reference
+ ids.add(id);
+ }
+ generatedRestriction = new In(associated.getElement(), ids);
}
Restriction parent = associated.getParentRestrictionDto();
And and;
- if ( parent instanceof And ) {
- and = (And) parent;
- and.getRestrictions().add( generatedRestriction );
+ if (parent instanceof And) {
+ and = (And) parent;
+ and.getRestrictions().add(generatedRestriction);
} else {
- and = RestrictionHelper.and( Arrays.asList(new Restriction[]{ associated.getParentRestrictionDto(), generatedRestriction }) );
+ and = RestrictionHelper.and(Arrays.asList(new Restriction[]{associated.getParentRestrictionDto(), generatedRestriction}));
}
- return toSolr(and);
- }
+ return toSolr(and);
+ }
- private String not2solr(Not not) throws WikittyException {
- if (not.getRestriction() == null) {
- throw new WikittyException( "not.restriction" );
- }
- return "( *:* - " + toSolr(not.getRestriction()) + " )";
- }
+ private String not2solr(Not not) throws WikittyException {
+ if (not.getRestriction() == null) {
+ throw new WikittyException("not.restriction");
+ }
+ return "( *:* - " + toSolr(not.getRestriction()) + " )";
+ }
- private String and2solr(And and) throws WikittyException {
- if (and.getRestrictions() == null) {
- throw new WikittyException( "and.restrictions is null" );
- }
- if (and.getRestrictions().size() < 2) {
- throw new WikittyException( "AND is an operator that handle 2 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (Restriction restriction : and.getRestrictions()) {
- if (first) {
- result.append("( ").append(toSolr(restriction));
- first = false;
- } else {
- result.append(" AND ").append(toSolr(restriction));
- }
- }
- return result.append(" )").toString();
- }
+ private String and2solr(And and) throws WikittyException {
+ if (and.getRestrictions() == null) {
+ throw new WikittyException("and.restrictions is null");
+ }
+ if (and.getRestrictions().size() < 2) {
+ throw new WikittyException("AND is an operator that handle 2 operand at least");
+ }
+ boolean first = true;
+ StringBuffer result = new StringBuffer();
+ for (Restriction restriction : and.getRestrictions()) {
+ if (first) {
+ result.append("( ").append(toSolr(restriction));
+ first = false;
+ } else {
+ result.append(" AND ").append(toSolr(restriction));
+ }
+ }
+ return result.append(" )").toString();
+ }
- private String or2solr(Or or) throws WikittyException {
- if (or.getRestrictions() == null) {
- throw new WikittyException("or.restrictions is null");
- }
- if (or.getRestrictions().size() < 2) {
- throw new WikittyException("OR is an operator that handle 2 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (Restriction restriction : or.getRestrictions()) {
- if (first) {
- result.append("( ");
- first = false;
- } else {
- result.append(" OR ");
- }
- result.append(toSolr(restriction));
- }
- return result.append(" )").toString();
- }
+ private String or2solr(Or or) throws WikittyException {
+ if (or.getRestrictions() == null) {
+ throw new WikittyException("or.restrictions is null");
+ }
+ if (or.getRestrictions().size() < 2) {
+ throw new WikittyException("OR is an operator that handle 2 operand at least");
+ }
+ boolean first = true;
+ StringBuffer result = new StringBuffer();
+ for (Restriction restriction : or.getRestrictions()) {
+ if (first) {
+ result.append("( ");
+ first = false;
+ } else {
+ result.append(" OR ");
+ }
+ result.append(toSolr(restriction));
+ }
+ return result.append(" )").toString();
+ }
- private String eq2solr(Equals eq) throws WikittyException {
- return element2solr(eq.getElement()) + ":" + value2solr(eq.getValue());
- }
+ private String eq2solr(Equals eq) throws WikittyException {
+ return element2solr(eq.getElement()) + ":" + value2solr(eq.getValue());
+ }
- private String neq2solr(NotEquals neq)
- throws WikittyException {
- return "( *:* - " + element2solr(neq.getElement()) + ":"
- + value2solr(neq.getValue()) + " )";
- }
+ private String neq2solr(NotEquals neq)
+ throws WikittyException {
+ return "( *:* - " + element2solr(neq.getElement()) + ":"
+ + value2solr(neq.getValue()) + " )";
+ }
- private String less2solr(Less less) throws WikittyException {
- return element2solr(less.getElement()) + ":{* TO "
- + value2solr(less.getValue()) + "}";
- }
+ private String less2solr(Less less) throws WikittyException {
+ return element2solr(less.getElement()) + ":{* TO "
+ + value2solr(less.getValue()) + "}";
+ }
- private String lessEq2solr(LessOrEqual lessEq)
- throws WikittyException {
- return element2solr(lessEq.getElement()) + ":[* TO "
- + value2solr(lessEq.getValue()) + "]";
- }
+ private String lessEq2solr(LessOrEqual lessEq)
+ throws WikittyException {
+ return element2solr(lessEq.getElement()) + ":[* TO "
+ + value2solr(lessEq.getValue()) + "]";
+ }
- private String great2solr(Greater great)
- throws WikittyException {
- return element2solr(great.getElement()) + ":{"
- + value2solr(great.getValue()) + " TO *}";
- }
+ private String great2solr(Greater great)
+ throws WikittyException {
+ return element2solr(great.getElement()) + ":{"
+ + value2solr(great.getValue()) + " TO *}";
+ }
- private String greatEq2solr(GreaterOrEqual greatEq)
- throws WikittyException {
- return element2solr(greatEq.getElement()) + ":["
- + value2solr(greatEq.getValue()) + " TO *]";
- }
+ private String greatEq2solr(GreaterOrEqual greatEq)
+ throws WikittyException {
+ return element2solr(greatEq.getElement()) + ":["
+ + value2solr(greatEq.getValue()) + " TO *]";
+ }
- private String between2solr(Between between)
- throws WikittyException {
- if (between.getElement() == null) {
- throw new WikittyException("contains.element");
- }
- if (between.getMin() == null) {
- throw new WikittyException("contains.min");
- }
- if (between.getMax() == null) {
- throw new WikittyException("contains.max");
- }
- return element2solr(between.getElement()) + ":["
- + value2solr(between.getMin()) + " TO "
- + value2solr(between.getMax()) + "]";
- }
+ private String between2solr(Between between)
+ throws WikittyException {
+ if (between.getElement() == null) {
+ throw new WikittyException("contains.element");
+ }
+ if (between.getMin() == null) {
+ throw new WikittyException("contains.min");
+ }
+ if (between.getMax() == null) {
+ throw new WikittyException("contains.max");
+ }
+ return element2solr(between.getElement()) + ":["
+ + value2solr(between.getMin()) + " TO "
+ + value2solr(between.getMax()) + "]";
+ }
- private String contains2solr(Contains contains)
- throws WikittyException {
- if (contains.getElement() == null) {
- throw new WikittyException("contains.element");
- }
- if (contains.getValue() == null) {
- throw new WikittyException("contains.values");
- }
- if (contains.getValue().size() < 1) {
- throw new WikittyException("CONTAINS is an operator that handle 1 operand at least");
- }
- boolean first = true;
- StringBuffer result = new StringBuffer();
- for (String value : contains.getValue()) {
- if (first) {
- result.append("( ");
- first = false;
- } else {
- result.append(" AND ");
- }
- result.append("( ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" OR ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" OR ");
- result.append(element2solr(contains.getElement()))
- .append(":").append(value2solr(value));
- result.append(" )");
- }
- return result.append(" )").toString();
- }
+ private String contains2solr(Contains contains)
+ throws WikittyException {
+ if (contains.getElement() == null) {
+ throw new WikittyException("contains.element");
+ }
+ if (contains.getValue() == null) {
+ throw new WikittyException("contains.values");
+ }
+ if (contains.getValue().size() < 1) {
+ throw new WikittyException("CONTAINS is an operator that handle 1 operand at least");
+ }
+ boolean first = true;
+ StringBuffer result = new StringBuffer();
+ for (String value : contains.getValue()) {
+ if (first) {
+ result.append("( ");
+ first = false;
+ } else {
+ result.append(" AND ");
+ }
+ result.append("( ");
+ result.append(element2solr(contains.getElement()))
+ .append(":").append(value2solr(value));
+ result.append(" OR ");
+ result.append(element2solr(contains.getElement()))
+ .append(":").append(value2solr(value));
+ result.append(" OR ");
+ result.append(element2solr(contains.getElement()))
+ .append(":").append(value2solr(value));
+ result.append(" )");
+ }
+ return result.append(" )").toString();
+ }
- private String start2solr(StartsWith start)
- throws WikittyException {
- return element2solr(start.getElement()) + ":"
- + value2solr(start.getValue(), true, false);
- }
+ private String start2solr(StartsWith start)
+ throws WikittyException {
+ return element2solr(start.getElement()) + ":"
+ + value2solr(start.getValue(), true, false);
+ }
- private String end2solr(EndsWith end) {
- return element2solr(end.getElement()) + ":" + value2solr(end.getValue());
- }
+ private String end2solr(EndsWith end) {
+ return element2solr(end.getElement()) + ":" + value2solr(end.getValue());
+ }
- private String true2solr() {
- return "( *:* )";
- }
+ private String true2solr() {
+ return "( *:* )";
+ }
- private String false2solr() {
- return "( *:* - *:* )";
- }
+ private String false2solr() {
+ return "( *:* - *:* )";
+ }
private String keyword2solr(Keyword keyword) {
return value2solr(keyword.getValue());
}
- private String value2solr(String value) {
- return value2solr(value, false, false);
- }
+ private String value2solr(String value) {
+ return value2solr(value, false, false);
+ }
- private String value2solr(String value, boolean starOnEnd,
- boolean revert) {
- String result;
- if (value != null) {
- if (value.equals("*")) {
- return "*";
- }
+ private String value2solr(String value, boolean starOnEnd,
+ boolean revert) {
+ String result;
+ if (value != null) {
+ if (value.equals("*")) {
+ return "*";
+ }
- if (revert) {
- result = Restriction2Solr.escapeValue(reverse(value));
- } else {
- result = Restriction2Solr.escapeValue(value);
- // result = value;
- }
- } else {
- result = "";
- }
- if (starOnEnd) {
- result += "*";
- }
- if (result.contains(" ")) {
- result = "\"" + result + "\"";
- }
- return result;
- }
+ if (revert) {
+ result = Restriction2Solr.escapeValue(reverse(value));
+ } else {
+ result = Restriction2Solr.escapeValue(value);
+ // result = value;
+ }
+ } else {
+ result = "";
+ }
+ if (starOnEnd) {
+ result += "*";
+ }
+ if (result.contains(" ")) {
+ result = "\"" + result + "\"";
+ }
+ return result;
+ }
- private String element2solr(Element element) throws WikittyException {
+ private String element2solr(Element element) throws WikittyException {
String result = element.getName();
- if(Element.ELT_EXTENSION.equals(result)) {
+ if (Element.ELT_EXTENSION.equals(result)) {
result = WikittySearchEnginSolr.SOLR_EXTENSIONS;
- } else if(Element.ELT_ID.equals(result)) {
+ } else if (Element.ELT_ID.equals(result)) {
result = WikittySearchEnginSolr.SOLR_ID;
} else {
result = element.getName();
}
result = fieldModifer.convertToSolr(result);
return result;
- }
+ }
- private static String escapeValue(String value) {
- final String LUCENE_REPLACE_PATTERN = "\\+" + "|-" + "|&&" + "|\\|\\|"
- + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\\^" + "|\""
- + "|\\~" + "|\\*" + "|\\?" + "|:" + "|\\\\";
- return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0");
- }
+ private static String escapeValue(String value) {
+ final String LUCENE_REPLACE_PATTERN = "\\+" + "|-" + "|&&" + "|\\|\\|"
+ + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\\^" + "|\""
+ + "|\\~" + "|\\*" + "|\\?" + "|:" + "|\\\\";
+ return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0");
+ }
- private String reverse(String source) {
- int i, len = source.length();
- StringBuffer dest = new StringBuffer(len);
+ private String reverse(String source) {
+ int i, len = source.length();
+ StringBuffer dest = new StringBuffer(len);
- for (i = (len - 1); i >= 0; i--)
- dest.append(source.charAt(i));
- return dest.toString();
- }
+ for (i = (len - 1); i >= 0; i--)
+ dest.append(source.charAt(i));
+ return dest.toString();
+ }
}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -16,62 +16,72 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*##%*/
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.sharengo.wikitty.*;
import static org.sharengo.wikitty.jdbc.WikittyJDBCUtil.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.sharengo.wikitty.FieldType;
-import org.sharengo.wikitty.UpdateResponse;
-import org.sharengo.wikitty.WikittyException;
-import org.sharengo.wikitty.WikittyExtension;
-import org.sharengo.wikitty.WikittyExtensionStorage;
-import org.sharengo.wikitty.WikittyTransaction;
-import org.sharengo.wikitty.WikittyUtil;
+import java.util.*;
/**
- *
* @author morin
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class WikittyExtensionStorageJDBC implements WikittyExtensionStorage {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static protected Log log = LogFactory.getLog(WikittyExtensionStorageJDBC.class);
- /** JDBC driver property name */
+ /**
+ * JDBC driver property name
+ */
static protected String driver = "jdbc.con.driver";
- /** extension_admin table creation query property name */
+ /**
+ * extension_admin table creation query property name
+ */
static protected String extAdminCreationQ = "jdbc.queries.creation.extension.admin";
- /** extension_data table creation query property name */
+ /**
+ * extension_data table creation query property name
+ */
static protected String extDataCreationQ = "jdbc.queries.creation.extension.data";
- /** basic selection without where clause query property name */
+ /**
+ * basic selection without where clause query property name
+ */
static protected String selectionQ = "jdbc.queries.select";
- /** basic selection with where clause query property name */
+ /**
+ * basic selection with where clause query property name
+ */
static protected String whereSelectionQ = "jdbc.queries.select.where";
- /** insertion in the admin table query property name */
+ /**
+ * insertion in the admin table query property name
+ */
static protected String adminInsertQ = "jdbc.queries.insert.extension.admin";
- /** insertion in the data table query property name */
+ /**
+ * insertion in the data table query property name
+ */
static protected String dataInsertQ = "jdbc.queries.insert.extension.data";
- /** admin table name */
+ /**
+ * admin table name
+ */
static protected String adminTable = "extension_admin";
- /** data table name */
+ /**
+ * data table name
+ */
static protected String dataTable = "extension_data";
-
- /** Properties file */
+
+ /**
+ * Properties file
+ */
protected Properties conf = loadProperties();
class CommandJDBC implements Command {
@@ -81,12 +91,16 @@
this.queries = queries;
}
}
-
- /** cache for extension key: ext id (extname[extversion]) value: WikittyExtension */
+
+ /**
+ * cache for extension key: ext id (extname[extversion]) value: WikittyExtension
+ */
protected Map<String, WikittyExtension> extensionCache =
new HashMap<String, WikittyExtension>();
-
- /** cache for last extension version; key: extName value: extVersion */
+
+ /**
+ * cache for last extension version; key: extName value: extVersion
+ */
protected Map<String, String> lastVersion = null;
public WikittyExtensionStorageJDBC() {
@@ -110,7 +124,7 @@
statement.execute(conf.getProperty(extAdminCreationQ));
statement.execute(conf.getProperty(extDataCreationQ));
con.commit();
- } catch(SQLException eee) {
+ } catch (SQLException eee) {
con.rollback();
}
closeConnection(con);
@@ -126,7 +140,7 @@
@Override
public List<Command> prepare(WikittyTransaction transaction,
- Collection<WikittyExtension> extensions)
+ Collection<WikittyExtension> extensions)
throws WikittyException {
Connection con = null;
try {
@@ -140,7 +154,7 @@
//select all the data with the id "id"
ResultSet versionResultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ),
- COL_VERSION, adminTable, COL_ID, "'" + id + "'"));
+ COL_VERSION, adminTable, COL_ID, "'" + id + "'"));
StringBuffer batch = new StringBuffer();
//if the data is not already recorded
@@ -170,13 +184,13 @@
@Override
public UpdateResponse commit(WikittyTransaction transaction,
- List<Command> extensionStorageCommandList) {
+ List<Command> extensionStorageCommandList) {
Connection con = null;
try {
con = getConnection();
Statement statement = con.createStatement();
- for(Command command : extensionStorageCommandList) {
- CommandJDBC commandJDBC = (CommandJDBC)command;
+ for (Command command : extensionStorageCommandList) {
+ CommandJDBC commandJDBC = (CommandJDBC) command;
statement.execute(commandJDBC.queries);
}
con.commit();
@@ -202,7 +216,7 @@
//select the data with teh id "id" in the admin table
ResultSet resultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ), adminTable,
- COL_ID, "'" + id + "'"));
+ COL_ID, "'" + id + "'"));
boolean result = resultSet.first();
closeConnection(con);
return result;
@@ -222,8 +236,8 @@
Statement statement = con.createStatement();
//get all extensions names and versions
ResultSet resultSet = statement.executeQuery(
- String.format(conf.getProperty(selectionQ),
- COL_ID, adminTable));
+ String.format(conf.getProperty(selectionQ),
+ COL_ID, adminTable));
resultSet.beforeFirst();
while (resultSet.next()) {
String id = resultSet.getString(COL_ID);
@@ -238,26 +252,64 @@
}
+ @Override
+ public List<WikittyExtension> getAllExtensions(boolean lastVersion) {
+ Connection con = null;
+ try {
+ con = getConnection();
+
+ List<WikittyExtension> result = new ArrayList<WikittyExtension>();
+ Statement statement = con.createStatement();
+ //get all extensions names and versions
+ ResultSet adminResultSet;
+ if (lastVersion) {
+ adminResultSet = statement.executeQuery(
+ String.format(conf.getProperty(selectionQ), "DISTINCT " + COL_NAME,
+ adminTable));
+ adminResultSet.beforeFirst();
+ while (adminResultSet.next()) {
+ String extName = adminResultSet.getString(COL_NAME);
+ String extId = getLastVersion(extName);
+ result.add(restore(extId));
+ }
+ } else {
+ adminResultSet = statement.executeQuery(
+ String.format(conf.getProperty(selectionQ), COL_ID,
+ adminTable));
+ adminResultSet.beforeFirst();
+ while (adminResultSet.next()) {
+ String extId = adminResultSet.getString(COL_ID);
+ result.add(restore(extId));
+ }
+ }
+ closeConnection(con);
+ return result;
+ } catch (SQLException eee) {
+ closeConnection(con);
+ throw new WikittyException(eee);
+ }
+ }
+
/**
* return last version available for specified extension name
- * @param name name of extension
+ *
+ * @param extName name of extension
* @return last version availble for this version, or null if extension
- * doesn't exist
+ * doesn't exist
*/
@Override
- public String getLastVersion(
- String extName) {
+ public String getLastVersion(String extName) {
if (lastVersion == null) {
// create cache for futur call
lastVersion = new HashMap<String, String>();
Connection con = null;
- try {
- con = getConnection();
+ try {
+ con = getConnection();
Statement statement = con.createStatement();
//get all extensions names and versions
ResultSet resultSet = statement.executeQuery(
String.format(conf.getProperty(selectionQ),
- COL_NAME + "," + COL_VERSION, adminTable));
+ COL_NAME + "," + COL_VERSION, adminTable));
resultSet.beforeFirst();
while (resultSet.next()) {
String name = resultSet.getString(COL_NAME);
@@ -280,8 +332,7 @@
}
@Override
- public WikittyExtension restore(
- String id) throws WikittyException {
+ public WikittyExtension restore(String id) throws WikittyException {
WikittyExtension result = extensionCache.get(id);
if (result == null) {
Connection con = null;
@@ -291,7 +342,7 @@
//get the data with the id "id" in the admin table
ResultSet adminResultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ), "*",
- adminTable, COL_ID, "'" + id + "'"));
+ adminTable, COL_ID, "'" + id + "'"));
if (adminResultSet.first()) {
String extName = adminResultSet.getString(COL_NAME);
String extVersion = adminResultSet.getString(COL_VERSION);
@@ -300,7 +351,7 @@
//get the data with the id "id" in the data table
ResultSet dataResultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ), "*",
- dataTable, COL_ID, "'" + id + "'"));
+ dataTable, COL_ID, "'" + id + "'"));
dataResultSet.beforeFirst();
while (dataResultSet.next()) {
String fieldDef = dataResultSet.getString(COL_FIELDTYPE);
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyJDBCUtil.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyJDBCUtil.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyJDBCUtil.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -18,61 +18,95 @@
package org.sharengo.wikitty.jdbc;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
- *
* @author morin
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class WikittyJDBCUtil {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static private Log log = LogFactory.getLog(WikittyJDBCUtil.class);
- /** extension list column in the wikitty_admin table */
- static final public String COL_EXTENSION = "extension_list";
- /** requires column in the extension_admin table */
- static final public String COL_REQUIRES = "requires";
- /** version column in the admin tables */
+ /**
+ * extension list column in the wikitty_admin table
+ */
+ static final public String COL_EXTENSION = "extension_list";
+ /**
+ * requires column in the extension_admin table
+ */
+ static final public String COL_REQUIRES = "requires";
+ /**
+ * version column in the admin tables
+ */
static final public String COL_VERSION = "version";
- /** id column in all the tables */
+ /**
+ * id column in all the tables
+ */
static final public String COL_ID = "id";
- /** name column in the extension_admin table */
+ /**
+ * name column in the extension_admin table
+ */
static final public String COL_NAME = "name";
- /** field name column in the data tables */
+ /**
+ * field name column in the data tables
+ */
static final public String COL_FIELDNAME = "fieldName";
- /** field type column in the extension_data table */
+ /**
+ * field type column in the extension_data table
+ */
static final public String COL_FIELDTYPE = "fieldType";
- /** boolean value column in the wikitty_data table */
+ /**
+ * boolean value column in the wikitty_data table
+ */
static final public String COL_BOOLEAN_VALUE = "booleanValue";
- /** number value column in the wikitty_data table */
+ /**
+ * number value column in the wikitty_data table
+ */
static final public String COL_NUMBER_VALUE = "numberValue";
- /** text value column in the wikitty_data table */
+ /**
+ * text value column in the wikitty_data table
+ */
static final public String COL_TEXT_VALUE = "textValue";
- /** date value column in the wikitty_data table */
+ /**
+ * date value column in the wikitty_data table
+ */
static final public String COL_DATE_VALUE = "dateValue";
- /** deletion date column in wikitty_admin table */
+ /**
+ * deletion date column in wikitty_admin table
+ */
static final public String COL_DELETION_DATE = "deletionDate";
- /** host property name */
+ /**
+ * host property name
+ */
static protected String host = "jdbc.con.host";
- /** user name property name */
+ /**
+ * user name property name
+ */
static protected String userName = "jdbc.con.userName";
- /** password property name */
+ /**
+ * password property name
+ */
static protected String password = "jdbc.con.password";
- /** Properties file */
+ /**
+ * Properties file
+ */
protected static Properties conf = loadProperties();
/**
@@ -83,10 +117,10 @@
public static Properties loadProperties() {
Properties properties = new Properties();
try {
- URL url = ClassLoader.getSystemResource("jdbc.properties");
- properties.load(url.openStream());
- } catch(IOException eee) {
- if(log.isErrorEnabled()) {
+ URL url = ClassLoader.getSystemResource("jdbc.properties");
+ properties.load(url.openStream());
+ } catch (IOException eee) {
+ if (log.isErrorEnabled()) {
log.error("Unable to load property file");
}
}
@@ -101,7 +135,7 @@
*/
public static Connection getConnection() throws SQLException {
Connection con = DriverManager.getConnection(conf.getProperty(host),
- conf.getProperty(userName), conf.getProperty(password));
+ conf.getProperty(userName), conf.getProperty(password));
con.setAutoCommit(false);
return con;
}
@@ -122,20 +156,20 @@
* If the option rollback is true, then all the modification made in
* the transaction are canceled.
*
- * @param con the connection to close
+ * @param con the connection to close
* @param rollBack if true, all the modification made in
- * the transaction are canceled.
+ * the transaction are canceled.
*/
public static void closeConnection(Connection con, boolean rollBack) {
try {
- if(con != null) {
- if(rollBack) {
+ if (con != null) {
+ if (rollBack) {
con.rollback();
}
con.close();
}
- } catch(SQLException eee) {
- if(log.isErrorEnabled()) {
+ } catch (SQLException eee) {
+ if (log.isErrorEnabled()) {
log.error(eee);
}
}
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyQueryParser.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -11,7 +11,6 @@
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.LuceneQParserPlugin;
import org.apache.solr.search.QParser;
-import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.QueryParsing;
import org.apache.solr.search.SolrQueryParser;
@@ -36,6 +35,7 @@
return new SolrQParser(qstr, localParams, params, req);
}
}
+
class SolrQParser extends QParser {
static private Log log = LogFactory.getLog(SolrQParser.class);
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittySearchEnginSolr.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -18,14 +18,6 @@
package org.sharengo.wikitty.jdbc;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrQuery;
@@ -38,44 +30,45 @@
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
-import org.sharengo.wikitty.Criteria;
-import org.sharengo.wikitty.FacetTopic;
-import org.sharengo.wikitty.FieldType;
+import org.sharengo.wikitty.*;
import org.sharengo.wikitty.FieldType.TYPE;
-import org.sharengo.wikitty.PagedResult;
-import org.sharengo.wikitty.TreeNode;
-import org.sharengo.wikitty.UpdateResponse;
-import org.sharengo.wikitty.Wikitty;
-import org.sharengo.wikitty.WikittyException;
-import org.sharengo.wikitty.WikittyExtension;
-import org.sharengo.wikitty.WikittyExtensionStorage;
-import org.sharengo.wikitty.WikittySearchEngin;
-import org.sharengo.wikitty.WikittyTransaction;
import org.sharengo.wikitty.search.Search;
+import java.io.IOException;
+import java.util.*;
+
/**
- *
* @author poussin
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class WikittySearchEnginSolr implements WikittySearchEngin {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static private Log log = LogFactory.getLog(WikittySearchEnginSolr.class);
- /** id field in solr */
+ /**
+ * id field in solr
+ */
static final protected String SOLR_ID = "id";
- /** extensions field name in solr */
+ /**
+ * extensions field name in solr
+ */
static final public String SOLR_EXTENSIONS = "extensions";
- /** extension use to store field without extension to search on all extesnion */
+ /**
+ * extension use to store field without extension to search on all extesnion
+ */
static final public String SOLR_ALL_EXTENSIONS = "all";
- /** Precise the query parser to use, is allow leading wildcard */
+ /**
+ * Precise the query parser to use, is allow leading wildcard
+ */
static final public String SOLR_QUERY_PARSER = "{!wikitty}";
// Use for indexation tree node
@@ -85,16 +78,24 @@
static final public String TREENODE_ROOT = TREENODE_PREFIX + "root";
static protected class CommandSolr implements Command {
- /** if is store command toStore is true, if is delete toStore is false */
+ /**
+ * if is store command toStore is true, if is delete toStore is false
+ */
boolean toStore;
String id;
Wikitty wikitty;
- /** use to store command */
+
+ /**
+ * use to store command
+ */
public CommandSolr(Wikitty wikitty) {
this.wikitty = wikitty;
this.toStore = true;
}
- /** use for deletion command */
+
+ /**
+ * use for deletion command
+ */
public CommandSolr(String id) {
this.id = id;
this.toStore = false;
@@ -103,6 +104,7 @@
static protected class TypeFieldModifer implements Restriction2Solr.FieldModifier {
protected WikittyExtensionStorage extensionStorage;
+
public TypeFieldModifer(WikittyExtensionStorage extensionStorage) {
this.extensionStorage = extensionStorage;
}
@@ -138,7 +140,7 @@
String fieldName = searchField[1];
String fieldType = searchField[2];
- if(Criteria.ALL_EXTENSIONS.equals(extName)) {
+ if (Criteria.ALL_EXTENSIONS.equals(extName)) {
TYPE type = FieldType.TYPE.valueOf(fieldType);
String solrFieldName = SOLR_ALL_EXTENSIONS + "." + fieldName;
result = WikittySearchEnginSolr.getSolrFieldName(solrFieldName, type);
@@ -174,9 +176,9 @@
String parent = super.get(id);
// If not found in map, search in index
- if(parent == null) {
+ if (parent == null) {
SolrDocument doc = searchEnginSolr.findById(id);
- if(doc == null) {
+ if (doc == null) {
// is root
return null;
}
@@ -193,7 +195,7 @@
WikittySearchEnginSolr searchEnginSolr,
WikittyTransaction transaction) {
ParentMap value = (ParentMap) transaction.getTagValue(ParentMap.class);
- if(value == null) {
+ if (value == null) {
value = new ParentMap(searchEnginSolr);
transaction.setTagValue(ParentMap.class, value);
}
@@ -201,11 +203,17 @@
}
}
- /** solr server */
+ /**
+ * solr server
+ */
protected SolrServer solrServer;
- /** Criteria transformer to solr */
+ /**
+ * Criteria transformer to solr
+ */
protected Restriction2Solr restriction2Solr;
- /** Field modifier use to transform to solr format */
+ /**
+ * Field modifier use to transform to solr format
+ */
protected TypeFieldModifer fieldModifier;
public WikittySearchEnginSolr(WikittyExtensionStorage extensionStorage) {
@@ -233,12 +241,12 @@
}
public List<Command> prepare(WikittyTransaction transaction,
- Collection<Wikitty> wikitties) {
+ Collection<Wikitty> wikitties) {
List<Command> result = new ArrayList<Command>(wikitties.size());
for (Wikitty w : wikitties) {
// Store known parent in transaction
- if(w.hasExtension(TreeNode.EXT_TREENODE)) {
+ if (w.hasExtension(TreeNode.EXT_TREENODE)) {
ParentMap parentMap = ParentMap.getParentMap(this, transaction);
String wikittyId = w.getId();
String parentId = w.getFieldAsWikitty(
@@ -252,7 +260,7 @@
}
public UpdateResponse commit(WikittyTransaction transaction,
- List<Command> wikittyIndexationCommandList) {
+ List<Command> wikittyIndexationCommandList) {
try {
for (Command c : wikittyIndexationCommandList) {
CommandSolr cs = (CommandSolr) c;
@@ -261,7 +269,7 @@
solrServer.add(doc);
Collection<SolrInputDocument> docs = createTreeNodeIndex(transaction, cs.wikitty);
- if(!docs.isEmpty()) {
+ if (!docs.isEmpty()) {
solrServer.add(docs);
}
@@ -275,7 +283,7 @@
}
}
solrServer.commit();
-
+
// no specific result needed
UpdateResponse result = new UpdateResponse();
return result;
@@ -285,7 +293,7 @@
}
public List<Command> delete(WikittyTransaction transaction,
- List<String> idList) throws WikittyException {
+ List<String> idList) throws WikittyException {
List<Command> result = new ArrayList<Command>(idList.size());
for (String id : idList) {
result.add(new CommandSolr(id));
@@ -294,37 +302,37 @@
}
public PagedResult<String> findAllByCriteria(Criteria criteria) {
- try {
+ try {
// Create query with restriction
String queryString = restriction2Solr.toSolr(criteria.getRestriction(), solrServer);
- SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + queryString);
+ SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + queryString);
// Add pagged
int firstIndex = criteria.getFirstIndex();
int endIndex = criteria.getEndIndex();
- query.setStart(firstIndex);
- int nbRows;
- if (endIndex == -1) {
- // WARNING It is necessary to substract 'start' otherwise, there is a capacity overlow in solR
- nbRows = Integer.MAX_VALUE - firstIndex;
- } else {
- nbRows = endIndex - firstIndex + 1;
- }
- query.setRows(nbRows);
+ query.setStart(firstIndex);
+ int nbRows;
+ if (endIndex == -1) {
+ // WARNING It is necessary to substract 'start' otherwise, there is a capacity overlow in solR
+ nbRows = Integer.MAX_VALUE - firstIndex;
+ } else {
+ nbRows = endIndex - firstIndex + 1;
+ }
+ query.setRows(nbRows);
// Add sorting
List<String> sortAscending = criteria.getSortAscending();
- if(sortAscending != null) {
+ if (sortAscending != null) {
for (String sort : sortAscending) {
String tranform = fieldModifier.convertToSolr(sort);
query.setSortField(tranform, SolrQuery.ORDER.asc);
}
}
-
+
List<String> sortDescending = criteria.getSortDescending();
- if(sortDescending != null) {
+ if (sortDescending != null) {
for (String sort : sortDescending) {
String tranform = fieldModifier.convertToSolr(sort);
query.setSortField(tranform, SolrQuery.ORDER.desc);
@@ -338,11 +346,11 @@
// use to map query string to criteria facet name
Map<String, String> facetQueryToName = new HashMap<String, String>();
- if ((facetField != null && !facetField.isEmpty())
+ if ((facetField != null && !facetField.isEmpty())
|| (facetCriteria != null && !facetCriteria.isEmpty())) {
- query.setFacet(true);
- query.setFacetMinCount(1);
- // query.setFacetLimit(8); // no limit actualy
+ query.setFacet(true);
+ query.setFacetMinCount(1);
+ // query.setFacetLimit(8); // no limit actualy
// field facetisation
if (facetField != null) {
@@ -361,12 +369,12 @@
query.addFacetQuery(queryFacet);
}
}
- }
+ }
- QueryResponse resp = solrServer.query(query);
- SolrDocumentList solrResults = resp.getResults();
+ QueryResponse resp = solrServer.query(query);
+ SolrDocumentList solrResults = resp.getResults();
- Map<String, List<FacetTopic>> facets = new HashMap<String, List<FacetTopic>>();
+ Map<String, List<FacetTopic>> facets = new HashMap<String, List<FacetTopic>>();
if (facetField != null && !facetField.isEmpty()) {
for (FacetField facet : resp.getFacetFields()) {
String facetName = fieldModifier.convertToField(facet.getName());
@@ -374,7 +382,7 @@
if (facet.getValues() != null) {
for (FacetField.Count value : facet.getValues()) {
String topicName = value.getName();
- if(!topicName.endsWith(TREENODE_EMPTY)) {
+ if (!topicName.endsWith(TREENODE_EMPTY)) {
int topicCount = (int) value.getCount();
FacetTopic topic = new FacetTopic(facetName, topicName, topicCount);
topics.add(topic);
@@ -399,32 +407,32 @@
}
}
- List<String> ids = new ArrayList<String>(solrResults.size());
- for (SolrDocument doc : solrResults) {
- String id = (String) doc.getFieldValue(SOLR_ID);
- ids.add(id);
- }
+ List<String> ids = new ArrayList<String>(solrResults.size());
+ for (SolrDocument doc : solrResults) {
+ String id = (String) doc.getFieldValue(SOLR_ID);
+ ids.add(id);
+ }
- int numFound = (int)resp.getResults().getNumFound();
+ int numFound = (int) resp.getResults().getNumFound();
PagedResult<String> result = new PagedResult<String>(
firstIndex, numFound, queryString, facets, ids);
- return result;
- } catch (SolrServerException e) {
- throw new WikittyException(e);
- }
+ return result;
+ } catch (SolrServerException e) {
+ throw new WikittyException(e);
+ }
}
public Map<String, Integer> findAllChildren(Wikitty w) {
String wikittyId = w.getId();
-
+
String parent = w.getFieldAsWikitty(TreeNode.EXT_TREENODE, TreeNode.FIELD_PARENT);
- if(parent == null) {
+ if (parent == null) {
parent = TREENODE_ROOT;
} else {
parent = TREENODE_PREFIX + parent;
}
-
+
// Find count with facet, if the node not contain recurcively content,
// the node not found with facet
Criteria criteria = Search.query().eq(parent, wikittyId).criteria()
@@ -434,7 +442,7 @@
Map<String, Integer> counts = new HashMap<String, Integer>();
List<FacetTopic> topics = search.getTopic(TREENODE_PREFIX + wikittyId);
- if(topics != null) {
+ if (topics != null) {
for (FacetTopic topic : topics) {
String topicName = topic.getTopicName();
int topicCount = topic.getCount();
@@ -451,7 +459,7 @@
List<String> children = search.getAll();
for (String child : children) {
- if(!counts.containsKey(child)) {
+ if (!counts.containsKey(child)) {
counts.put(child, 0);
}
}
@@ -462,6 +470,7 @@
/**
* Create all index document to used to modify indexation.
* this method don't modify index
+ *
* @param wikitties all wikitties object to index
* @return list of SolrInputDocument used to modify index
*/
@@ -481,7 +490,7 @@
// if (type.getType() == FieldType.TYPE.WIKITTY) {
// continue;
// }
- String solrFqFieldName = getSolrFieldName(fqfieldName, type );
+ String solrFqFieldName = getSolrFieldName(fqfieldName, type);
String[] extAndName = solrFqFieldName.split("\\.");
String solrFieldName = SOLR_ALL_EXTENSIONS + "." + extAndName[1];
if (type.isCollection()) {
@@ -489,7 +498,7 @@
for (Object objectValue : collection) {
if (objectValue != null) {
// String value = WikittyUtil.toString(type, objectValue);
- Object value = objectValue;
+ Object value = objectValue;
doc.addField(solrFqFieldName, value);
doc.addField(solrFieldName, value);
}
@@ -498,7 +507,7 @@
Object objectValue = w.getFqField(fqfieldName);
if (objectValue != null) {
// String value = WikittyUtil.toString(type, objectValue);
- Object value = objectValue;
+ Object value = objectValue;
log.debug("index field " + solrFqFieldName + " with value '" + value + "'");
doc.addField(solrFqFieldName, value);
doc.addField(solrFieldName, value);
@@ -516,9 +525,9 @@
protected Collection<SolrInputDocument> createTreeNodeIndex(
WikittyTransaction transaction, Wikitty w)
throws IOException, SolrServerException {
-
+
Collection<SolrInputDocument> result = new ArrayList<SolrInputDocument>();
- if(w.hasExtension(TreeNode.EXT_TREENODE)) {
+ if (w.hasExtension(TreeNode.EXT_TREENODE)) {
String treeNodeId = w.getId();
ParentMap parentMap = (ParentMap) transaction.getTagValue(ParentMap.class);
@@ -526,19 +535,19 @@
List<String> children = w.getFieldAsList(TreeNode.EXT_TREENODE,
TreeNode.FIELD_CHILDREN, String.class);
List<String> newChildren = new ArrayList<String>();
- if(children != null) {
+ if (children != null) {
newChildren.addAll(children);
}
// Find old document to do diff
SolrDocument treeNodeDoc = findById(treeNodeId);
- if(treeNodeDoc != null) {
+ if (treeNodeDoc != null) {
Collection oldChildren = treeNodeDoc.
getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_t");
// Remove old children not in current node
List<String> removeChildren = new ArrayList<String>();
- if(oldChildren != null) {
+ if (oldChildren != null) {
removeChildren.addAll(oldChildren);
removeChildren.removeAll(children);
for (String removeChild : removeChildren) {
@@ -558,7 +567,7 @@
SolrDocument solrDocument = iterator.next();
String child = (String) solrDocument.getFieldValue(TreeNode.EXT_TREENODE + ".wikittyId");
// Child is not deleted
- if(!removeChildren.contains(child)) {
+ if (!removeChildren.contains(child)) {
SolrInputDocument doc = createTreeNodeDocument(treeNodeId, child, parentMap);
// Copy other field after node
@@ -620,7 +629,7 @@
SolrDocumentList results = response.getResults();
long numFound = results.getNumFound();
- if(numFound == 1) {
+ if (numFound == 1) {
return results.get(0);
}
@@ -631,7 +640,7 @@
TYPE type = fieldType.getType();
String result = getSolrFieldName(fqfieldName, type);
return result;
- }
+ }
public static String getSolrFieldName(String fqfieldName, TYPE type) {
switch (type) {
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyServiceJDBC.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -26,35 +26,36 @@
/**
* HBase must have 2 definitions, one for extension and one for wikitty object.
- *
+ * <p/>
* extension:
* - admin: id, version, ...
* - data: field definition
- *
+ * <p/>
* wikitty:
* - admin: id, version, extension name and version, ...
* - data: field value
- *
- *
+ * <p/>
+ * <p/>
* How to create this definition:
* <li> download and uncompress hbase distribution (from apache repository mirror)</li>
* <li> $hbase-0.19.3/bin/start-hbase.sh</li>
* <li> $hbase-0.19.3/bin/hbase shell</li>
* <li> in the shell
- * <li> create 'extension','admin','data'</li>
- * <li> create 'wikitty', 'admin', 'data'</li>
+ * <li> create 'extension','admin','data'</li>
+ * <li> create 'wikitty', 'admin', 'data'</li>
* </li>
*
- *
* @author poussin
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class WikittyServiceJDBC extends AbstractWikittyService {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static private Log log = LogFactory.getLog(WikittyServiceJDBC.class);
protected WikittySearchEngin searchEngin;
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyStorageJDBC.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc/WikittyStorageJDBC.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -16,79 +16,91 @@
*##%*/
package org.sharengo.wikitty.jdbc;
-import java.math.BigDecimal;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.sharengo.wikitty.*;
import static org.sharengo.wikitty.jdbc.WikittyJDBCUtil.*;
+import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.sharengo.wikitty.FieldType;
-import org.sharengo.wikitty.UpdateResponse;
-import org.sharengo.wikitty.Wikitty;
-import org.sharengo.wikitty.WikittyException;
-import org.sharengo.wikitty.WikittyExtension;
-import org.sharengo.wikitty.WikittyExtensionStorage;
-import org.sharengo.wikitty.WikittyStorage;
-import org.sharengo.wikitty.WikittyTransaction;
-import org.sharengo.wikitty.WikittyUtil;
/**
- *
* @author morin
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class WikittyStorageJDBC implements WikittyStorage {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static protected Log log = LogFactory.getLog(WikittyStorageJDBC.class);
- /** JDBC driver property name */
+ /**
+ * JDBC driver property name
+ */
static protected String driver = "jdbc.con.driver";
- /** wikitty_admin table creation query property name */
+ /**
+ * wikitty_admin table creation query property name
+ */
static protected String wikittyAdminCreationQ = "jdbc.queries.creation.wikitty.admin";
- /** wikitty_admin table creation query property name */
+ /**
+ * wikitty_admin table creation query property name
+ */
static protected String wikittyDataCreationQ = "jdbc.queries.creation.wikitty.data";
- /** basic selection with where clause query property name */
+ /**
+ * basic selection with where clause query property name
+ */
static protected String whereSelectionQ = "jdbc.queries.select.where";
- /** not dleeted data selection with where clause query property name */
+ /**
+ * not dleeted data selection with where clause query property name
+ */
static protected String notDeletedWhereSelectionQ = "jdbc.queries.select.where.notdeleted";
- /** insertion in the admin table query property name */
+ /**
+ * insertion in the admin table query property name
+ */
static protected String adminInsertQ = "jdbc.queries.insert.wikitty.admin";
- /** update in the admin table query property name */
+ /**
+ * update in the admin table query property name
+ */
static protected String adminUpdateQ = "jdbc.queries.update.wikitty.admin";
- /** insertion in the data table query property name */
+ /**
+ * insertion in the data table query property name
+ */
static protected String dataInsertQ = "jdbc.queries.insert.wikitty.data";
- /** deletion in the admin table query property name */
+ /**
+ * deletion in the admin table query property name
+ */
static protected String adminDeletionQ = "jdbc.queries.delete.wikitty.admin";
- /** deletion in the data table query property name */
+ /**
+ * deletion in the data table query property name
+ */
static protected String dataDeletionQ = "jdbc.queries.delete.wikitty.data";
- /** admin table name */
+ /**
+ * admin table name
+ */
static protected String adminTable = "wikitty_admin";
- /** data table name */
+ /**
+ * data table name
+ */
static protected String dataTable = "wikitty_data";
- /** Properties file */
+ /**
+ * Properties file
+ */
protected Properties conf = loadProperties();
- /** used to parse list field from hbase data. ex: extension.fieldname[11/15] */
+ /**
+ * used to parse list field from hbase data. ex: extension.fieldname[11/15]
+ */
static final private Pattern listFieldPattern =
Pattern.compile("(.*)\\[(\\d+)/(\\d+)\\]");
@@ -115,9 +127,9 @@
this.date = date;
}
}
-
+
protected WikittyExtensionStorage extensionStorage;
-
+
public WikittyStorageJDBC(WikittyExtensionStorage extensionStorage) {
this.extensionStorage = extensionStorage;
//check if driver ca be loaded
@@ -140,7 +152,7 @@
statement.execute(conf.getProperty(wikittyAdminCreationQ));
statement.execute(conf.getProperty(wikittyDataCreationQ));
con.commit();
- } catch(SQLException eee) {
+ } catch (SQLException eee) {
con.rollback();
}
closeConnection(con);
@@ -156,8 +168,8 @@
@Override
public List<Command> prepare(WikittyTransaction transaction,
- Collection<Wikitty> wikitties,
- boolean disableAutoVersionIncrement) throws WikittyException {
+ Collection<Wikitty> wikitties,
+ boolean disableAutoVersionIncrement) throws WikittyException {
Connection con = null;
try {
con = getConnection();
@@ -166,8 +178,8 @@
Statement statement = con.createStatement();
ResultSet versionResultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ),
- COL_VERSION, adminTable, COL_ID,
- "'" + wikitty.getId() + "'"));
+ COL_VERSION, adminTable, COL_ID,
+ "'" + wikitty.getId() + "'"));
StringBuffer batch = new StringBuffer();
String version = null;
String newVersion = null;
@@ -207,68 +219,68 @@
if (list != null) {
switch (type.getType()) {
case BOOLEAN:
- for (int i = 0 ; i < list.size() ; i++) {
- Boolean value = (Boolean)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ Boolean value = (Boolean) list.get(i);
batch.append(String.format(conf.getProperty(dataInsertQ),
- COL_BOOLEAN_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- value.toString()));
+ COL_BOOLEAN_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ value.toString()));
}
break;
case DATE:
- for (int i = 0 ; i < list.size() ; i++) {
- Date value = (Date)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ Date value = (Date) list.get(i);
batch.append(String.format(
conf.getProperty(dataInsertQ),
- COL_DATE_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- "'" + new java.sql.Date(value.getTime()) + "'"));
+ COL_DATE_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ "'" + new java.sql.Date(value.getTime()) + "'"));
}
break;
case NUMERIC:
- for (int i = 0 ; i < list.size() ; i++) {
- BigDecimal value = (BigDecimal)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ BigDecimal value = (BigDecimal) list.get(i);
batch.append(String.format(
conf.getProperty(dataInsertQ),
- COL_NUMBER_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- value.toString()));
+ COL_NUMBER_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ value.toString()));
}
break;
case STRING:
- for (int i = 0 ; i < list.size() ; i++) {
- String value = (String)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ String value = (String) list.get(i);
batch.append(String.format(
conf.getProperty(dataInsertQ),
- COL_TEXT_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- "'" + value + "'"));
+ COL_TEXT_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ "'" + value + "'"));
}
break;
case WIKITTY:
- for (int i = 0 ; i < list.size() ; i++) {
- String value = (String)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ String value = (String) list.get(i);
batch.append(String.format(
conf.getProperty(dataInsertQ),
- COL_TEXT_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- "'" + value + "'"));
+ COL_TEXT_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ "'" + value + "'"));
}
break;
default:
- for (int i = 0 ; i < list.size() ; i++) {
- String value = (String)list.get(i);
+ for (int i = 0; i < list.size(); i++) {
+ String value = (String) list.get(i);
batch.append(String.format(
conf.getProperty(dataInsertQ),
- COL_TEXT_VALUE, wikitty.getId(),
- ext.getName(),
- fieldName + "[" + i + "/" + list.size() + "]",
- "'" + value + "'"));
+ COL_TEXT_VALUE, wikitty.getId(),
+ ext.getName(),
+ fieldName + "[" + i + "/" + list.size() + "]",
+ "'" + value + "'"));
}
break;
}
@@ -410,16 +422,16 @@
@Override
public UpdateResponse commit(WikittyTransaction transaction,
- List<Command> wikittyStorageCommandList) {
+ List<Command> wikittyStorageCommandList) {
Connection con = null;
try {
con = getConnection();
Statement statement = con.createStatement();
UpdateResponse result = new UpdateResponse();
- for(Command command : wikittyStorageCommandList) {
- CommandJDBC commandJDBC = (CommandJDBC)command;
+ for (Command command : wikittyStorageCommandList) {
+ CommandJDBC commandJDBC = (CommandJDBC) command;
statement.execute(commandJDBC.queries);
-
+
if (commandJDBC.toStore) {
Wikitty wikitty = commandJDBC.wikitty;
String newVersion = commandJDBC.version;
@@ -452,7 +464,7 @@
//select the data with the id "id" in the admin table
ResultSet resultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ), COL_ID,
- adminTable, COL_ID, "'" + id + "'"));
+ adminTable, COL_ID, "'" + id + "'"));
// return true if the query has a result
boolean result = resultSet.first();
closeConnection(con);
@@ -472,18 +484,18 @@
//select the data with the id "id" in the admin table
ResultSet resultSet = statement.executeQuery(
String.format(conf.getProperty(whereSelectionQ),
- COL_DELETION_DATE, adminTable, COL_ID, "'" + id + "'"));
+ COL_DELETION_DATE, adminTable, COL_ID, "'" + id + "'"));
boolean result;
- if(resultSet.first()) {
+ if (resultSet.first()) {
result = resultSet.getDate(COL_DELETION_DATE) != null;
closeConnection(con);
return result;
} else {
closeConnection(con);
throw new WikittyException(String.format(
- "Wikitty with id '%s' doesn't exists", id));
+ "Wikitty with id '%s' doesn't exists", id));
}
-
+
} catch (SQLException eee) {
closeConnection(con);
throw new WikittyException(eee);
@@ -500,14 +512,14 @@
//select the data with the id "id" in the admin table
ResultSet adminResultSet = statement.executeQuery(
String.format(conf.getProperty(notDeletedWhereSelectionQ), "*",
- adminTable, COL_ID, "'" + id + "'"));
+ adminTable, COL_ID, "'" + id + "'"));
if (adminResultSet.first()) {
String version = adminResultSet.getString(COL_VERSION);
String extensionList = adminResultSet.getString(COL_EXTENSION);
//select the data with the id "id" in the data table
ResultSet dataResultSet = statement.executeQuery(
- String.format(conf.getProperty(whereSelectionQ), "*",
- dataTable, COL_ID, "'" + id + "'"));
+ String.format(conf.getProperty(whereSelectionQ), "*",
+ dataTable, COL_ID, "'" + id + "'"));
Wikitty result = constructWikitty(id, version, extensionList,
dataResultSet, fqFieldName);
return result;
@@ -523,7 +535,7 @@
@Override
public List<Wikitty> restore(Collection<String> ids,
- String... fqFieldName) throws WikittyException {
+ String... fqFieldName) throws WikittyException {
List<Wikitty> result = new ArrayList<Wikitty>(ids.size());
for (String id : ids) {
Wikitty w = restore(id, fqFieldName);
@@ -563,15 +575,16 @@
/**
* Create Wikitty from h2 tables
- * @param id the id of the wikitty to restore
- * @param version the version of the wikitty to restore
+ *
+ * @param id the id of the wikitty to restore
+ * @param version the version of the wikitty to restore
* @param extensionList the list of the extensions of the wikitty to restore
- * @param resulSet the ResultSet as the result of the selection of the in the data table
- * @param fqFieldName minimum field to restore
+ * @param resulSet the ResultSet as the result of the selection of the in the data table
+ * @param fqFieldName minimum field to restore
* @return
*/
protected Wikitty constructWikitty(String id, String version, String extensionList,
- ResultSet resultSet, String... fqFieldName) throws Exception {
+ ResultSet resultSet, String... fqFieldName) throws Exception {
Set<String> acceptedField = new HashSet<String>(Arrays.asList(fqFieldName));
Wikitty result = new Wikitty(id);
result.setVersion(version);
@@ -626,7 +639,7 @@
}
array[index] = value;
} else {
- if(log.isErrorEnabled()) {
+ if (log.isErrorEnabled()) {
log.error(String.format(
"Can't read list field correctly '%s'", fqfieldName));
}
@@ -641,7 +654,7 @@
for (String fieldName : listFieldMap.keySet()) {
Object[] array = listFieldMap.get(fieldName);
List list = new ArrayList(Arrays.asList(array));
- result.setFqField(fieldName, list );
+ result.setFqField(fieldName, list);
}
return result;
@@ -649,8 +662,9 @@
/**
* Test if fqfieldName is in acceptedField
+ *
* @param acceptedField list of all accepted field
- * @param fqfieldName fully qualified field name with potential [n/m] at end
+ * @param fqfieldName fully qualified field name with potential [n/m] at end
* @return if fqfieldName without potential [n/m] is in acceptedField or if acceptedField is empty
*/
protected boolean isAcceptedField(Set<String> acceptedField, String fqfieldName) {
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/JDBCStorageTest.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -21,6 +21,7 @@
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.Wikitty;
import org.sharengo.wikitty.WikittyService;
+import org.sharengo.wikitty.search.Element;
import org.sharengo.wikitty.search.Search;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -36,7 +37,7 @@
public void testExport() throws Exception {
final List<Wikitty> wikitties = createSampleWikitty(ws);
- Criteria criteria = Search.query().eqExt(EXTNAME).criteria();
+ Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, EXTNAME).criteria();
String result = ws.syncExportAllByCriteria(criteria);
log.debug("[XML] " + result);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java 2009-10-29 08:51:03 UTC (rev 299)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/test/java/org/sharengo/wikitty/jdbc/TreeTest.java 2009-10-29 15:12:30 UTC (rev 300)
@@ -161,7 +161,7 @@
Wikitty root = findNode("root");
String rootId = root.getId();
- Criteria criteria = Search.query().eq(WikittySearchEngineSolr.TREENODE_ROOT, rootId).criteria()
+ Criteria criteria = Search.query().eq(WikittySearchEnginSolr.TREENODE_ROOT, rootId).criteria()
.setFirstIndex(0).setEndIndex(WikittyService.ALL_ELEMENTS)
.addFacetField(rootId);
PagedResult<Wikitty> result = ws.findAllByCriteria(criteria);
1
0
r299 - wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty
by sletellier@users.nuiton.org 29 Oct '09
by sletellier@users.nuiton.org 29 Oct '09
29 Oct '09
Author: sletellier
Date: 2009-10-29 09:51:03 +0100 (Thu, 29 Oct 2009)
New Revision: 299
Modified:
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java
wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Wikitty.java
Log:
Adding fire
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java 2009-10-29 01:53:08 UTC (rev 298)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/BusinessEntityBean.java 2009-10-29 08:51:03 UTC (rev 299)
@@ -88,6 +88,7 @@
public void setField(String ext, String fieldName, Object value) {
String key = ext + "$" + fieldName;
fieldValue.put(key, value);
+ propertyChange.firePropertyChange(fieldName, null, value);
}
public FieldType getFieldType(String ext, String fieldName) {
@@ -114,4 +115,4 @@
propertyChange.removePropertyChangeListener(propertyName, listener);
}
-}
+ }
Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Wikitty.java
===================================================================
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Wikitty.java 2009-10-29 01:53:08 UTC (rev 298)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Wikitty.java 2009-10-29 08:51:03 UTC (rev 299)
@@ -266,6 +266,8 @@
// mark field dirty and call listener
setFieldDirty(ext, fieldName, oldValue, validValue);
+
+ propertyChange.firePropertyChange(fieldName, oldValue, validValue);
}
public Object getFieldAsObject(String ext, String fieldName) {
1
0