Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/TypeConverter.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/TypeConverter.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/TypeConverter.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/TypeConverter.java Fri May 13 15:29:20 2011 @@ -18,47 +18,62 @@ package org.apache.stanbol.entityhub.yar /** * The Converter Interface used by the {@link IndexValueFactory}. + * * @author Rupert Westenthaler - * - * @param <T> the generic type of the java-object that can be converted to - * {@link IndexValue}s. + * + * @param <T> + * the generic type of the java-object that can be converted to {@link IndexValue}s. */ public interface TypeConverter<T> { /** * Converts the parsed java instance to an index value - * @param value the java instance + * + * @param value + * the java instance * @return the index value representing the parsed java instance */ IndexValue createIndexValue(T value); + /** * Creates an java instance representing the parsed <code>IndexValue</code> - * @param value the index value + * + * @param value + * the index value * @return the java instance representing the parsed index value - * @throws if the <code>IndexType</code> of the parsed value is not compatible - * with this converter. + * @throws if + * the <code>IndexType</code> of the parsed value is not compatible with this converter. */ - T createObject(IndexValue value) throws UnsupportedIndexTypeException,UnsupportedValueException; + T createObject(IndexValue value) throws UnsupportedIndexTypeException, UnsupportedValueException; + /** - * Creates an java instance representing the parsed value as returned by the - * index. - * @param type the index data type of the value. MUST NOT be <code>null</code> - * @param value the value within the index. If <code>null</code> this method - * returns <code>null</code>. - * @param lang the language + * Creates an java instance representing the parsed value as returned by the index. + * + * @param type + * the index data type of the value. MUST NOT be <code>null</code> + * @param value + * the value within the index. If <code>null</code> this method returns <code>null</code>. + * @param lang + * the language * @return the java instance representing the parsed index value - * @throws UnsupportedValueException if the value can not be processed by the - * Converter - * @throws NullPointerException of the parsed {@link IndexDataType} is - * <code>null</code> + * @throws UnsupportedValueException + * if the value can not be processed by the Converter + * @throws NullPointerException + * of the parsed {@link IndexDataType} is <code>null</code> */ - T createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,UnsupportedValueException, NullPointerException; + T createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, + UnsupportedValueException, + NullPointerException; + /** * Getter for the java type + * * @return the java class of the instances created by this converter */ Class<T> getJavaType(); + /** * Getter for the index type + * * @return the index type of index values created by this converter */ IndexDataType getIndexType();
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedIndexTypeException.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedIndexTypeException.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedIndexTypeException.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedIndexTypeException.java Fri May 13 15:29:20 2011 @@ -18,7 +18,7 @@ package org.apache.stanbol.entityhub.yar /** * Thrown when the index value type is not compatible with the converter - * + * * @author Rupert Westenthaler */ public class UnsupportedIndexTypeException extends RuntimeException { @@ -27,23 +27,28 @@ public class UnsupportedIndexTypeExcepti * default serial version UID */ private static final long serialVersionUID = 1L; + /** - * Constructs the exception to be thrown when a an IndexType is not supported - * by the current configuration of the {@link IndexValueFactory} - * - * @param indexType the unsupported <code>IndexType</code> + * Constructs the exception to be thrown when a an IndexType is not supported by the current configuration + * of the {@link IndexValueFactory} + * + * @param indexType + * the unsupported <code>IndexType</code> */ public UnsupportedIndexTypeException(IndexDataType indexType) { - super(String.format("No Converter for IndexType %s registered!",indexType)); + super(String.format("No Converter for IndexType %s registered!", indexType)); } + /** - * Constructs the exception to be thrown if a converter does not support the - * {@link IndexDataType} of the parsed {@link IndexValue}. - * @param converter the converter (implement the {@link TypeConverter#toString()} method!) - * @param type the unsupported {@link IndexDataType} + * Constructs the exception to be thrown if a converter does not support the {@link IndexDataType} of the + * parsed {@link IndexValue}. + * + * @param converter + * the converter (implement the {@link TypeConverter#toString()} method!) + * @param type + * the unsupported {@link IndexDataType} */ public UnsupportedIndexTypeException(TypeConverter<?> converter, IndexDataType type) { - super(String.format("%s does not support the IndexType %s!", - converter,type)); + super(String.format("%s does not support the IndexType %s!", converter, type)); } } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedValueException.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedValueException.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedValueException.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/UnsupportedValueException.java Fri May 13 15:29:20 2011 @@ -18,7 +18,7 @@ package org.apache.stanbol.entityhub.yar /** * Thrown when a parsed object value can not be converted by the converter - * + * * @author Rupert Westenthaler */ public class UnsupportedValueException extends RuntimeException { @@ -27,26 +27,42 @@ public class UnsupportedValueException e * default serial version UID */ private static final long serialVersionUID = 1L; + /** - * Constructs the exception to be thrown if a converter does not support the - * the parsed value {@link IndexValue}. - * @param converter the converter (implement the {@link TypeConverter#toString()} method!) - * @param type the IndexDataType - * @param value the value + * Constructs the exception to be thrown if a converter does not support the the parsed value + * {@link IndexValue}. + * + * @param converter + * the converter (implement the {@link TypeConverter#toString()} method!) + * @param type + * the IndexDataType + * @param value + * the value */ public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value) { - this(converter, type, value,null); + this(converter, type, value, null); } + /** - * Constructs the exception to be thrown if a converter does not support the - * the parsed value {@link IndexValue}. - * @param converter the converter (implement the {@link TypeConverter#toString()} method!) - * @param type the IndexDataType - * @param value the value - * @param cause the cause + * Constructs the exception to be thrown if a converter does not support the the parsed value + * {@link IndexValue}. + * + * @param converter + * the converter (implement the {@link TypeConverter#toString()} method!) + * @param type + * the IndexDataType + * @param value + * the value + * @param cause + * the cause */ - public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value,Throwable cause) { - super(String.format("%s does not support the parsed value %s! Value is not compatible with the parsed IndexDataType %s", - converter,value,type),cause); + public UnsupportedValueException(TypeConverter<?> converter, + IndexDataType type, + Object value, + Throwable cause) { + super( + String.format( + "%s does not support the parsed value %s! Value is not compatible with the parsed IndexDataType %s", + converter, value, type), cause); } } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java Fri May 13 15:29:20 2011 @@ -17,27 +17,29 @@ package org.apache.stanbol.entityhub.yard.solr.query; /** - * The position of a constraint type within the constraint for an index field.<p> - * This position consists of two parts<ol> - * <li> the {@link PositionType} defining if general position of the constraint - * <li> an integer that defines the ordering of constraints within one position. - * This is e.g. needed when encoding range constraints because both the - * lower and upper bound need to be encoded in the {@link PositionType#value} - * category, the lower bound need to be encoded in front of the upper - * bound. + * The position of a constraint type within the constraint for an index field. + * <p> + * This position consists of two parts + * <ol> + * <li>the {@link PositionType} defining if general position of the constraint + * <li>an integer that defines the ordering of constraints within one position. This is e.g. needed when + * encoding range constraints because both the lower and upper bound need to be encoded in the + * {@link PositionType#value} category, the lower bound need to be encoded in front of the upper bound. * </ol> + * * @author Rupert Westenthaler - * + * */ -public class ConstraintTypePosition implements Comparable<ConstraintTypePosition>{ +public class ConstraintTypePosition implements Comparable<ConstraintTypePosition> { /** - * The possible positions of constraints within a Index Constraint.<p> + * The possible positions of constraints within a Index Constraint. + * <p> * The ordinal number of the elements is used to sort the constraints in the - * {@link EncodedConstraintParts}. So ensure, that the ordering in this - * enumeration corresponds with the ordering in a constraint within the - * index + * {@link EncodedConstraintParts}. So ensure, that the ordering in this enumeration corresponds with the + * ordering in a constraint within the index + * * @author Rupert Westenthaler - * + * */ public enum PositionType { prefix, @@ -46,15 +48,16 @@ public class ConstraintTypePosition impl assignment, value } + private PositionType type; private int pos; public ConstraintTypePosition(PositionType type) { - this(type,0); + this(type, 0); } - public ConstraintTypePosition(PositionType type,int pos) { - if(type == null){ + public ConstraintTypePosition(PositionType type, int pos) { + if (type == null) { throw new IllegalArgumentException("The ConstraintPosition MUST NOT be NULL!"); } this.type = type; @@ -63,19 +66,22 @@ public class ConstraintTypePosition impl @Override public int compareTo(ConstraintTypePosition other) { - return type == other.type?pos-other.pos:type.ordinal()-other.type.ordinal(); + return type == other.type ? pos - other.pos : type.ordinal() - other.type.ordinal(); } + @Override public int hashCode() { - return type.hashCode()+pos; + return type.hashCode() + pos; } + @Override public boolean equals(Object obj) { - return obj instanceof ConstraintTypePosition - && ((ConstraintTypePosition)obj).type == type && ((ConstraintTypePosition)obj).pos == pos; + return obj instanceof ConstraintTypePosition && ((ConstraintTypePosition) obj).type == type + && ((ConstraintTypePosition) obj).pos == pos; } + @Override public String toString() { - return String.format("constraintPosition %s,%d", type,pos); + return String.format("constraintPosition %s,%d", type, pos); } } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java Fri May 13 15:29:20 2011 @@ -25,46 +25,48 @@ import java.util.TreeMap; import java.util.Map.Entry; /** - * This class is used to store the encoded parts of the index field constraints - * created by the {@link IndexConstraintTypeEncoder}.<p> - * The processing of this parts is specific to the used Index, therefore such - * processing is not implemented by this Class.<p> - * Constraints parts can be encoded in the following part of an index field: - * <code><per> + * This class is used to store the encoded parts of the index field constraints created by the + * {@link IndexConstraintTypeEncoder}. + * <p> + * The processing of this parts is specific to the used Index, therefore such processing is not implemented by + * this Class. + * <p> + * Constraints parts can be encoded in the following part of an index field: <code><per> * <prefix>.field.<prefix><assignment><value> - * </pre></code> - * The: <ul> + * </pre></code> The: + * <ul> * <li> <code>prefix</code> is used for the data type and language constraints * <li> <code>field</code> is predefined by by the field of the constraint * <li> <code>suffix</code> is currently unused - * <li> <code>assignment</code> is used for checking static values or just adding - * ':' in the case that values of that field are filtered. - * <li> <code>value</code> is used to define filters like value ranges or - * wildcard searches. + * <li> <code>assignment</code> is used for checking static values or just adding ':' in the case that values + * of that field are filtered. + * <li> <code>value</code> is used to define filters like value ranges or wildcard searches. * </ul> - * The {@link ConstraintTypePosition} defines such position in ordinal numbers - * from left to right. This ordinal numbers are also used sort the elements - * of the {@link Iterable} interface implemented by this class. - * + * The {@link ConstraintTypePosition} defines such position in ordinal numbers from left to right. This + * ordinal numbers are also used sort the elements of the {@link Iterable} interface implemented by this + * class. + * * @author Rupert Westenthaler - * + * */ -public class EncodedConstraintParts implements Iterable<Entry<ConstraintTypePosition,Set<Set<String>>>>{ +public class EncodedConstraintParts implements Iterable<Entry<ConstraintTypePosition,Set<Set<String>>>> { /** * This maps contains all the encoded parts of the query. */ - private SortedMap<ConstraintTypePosition,Set<Set<String>>> constraintMap = new TreeMap<ConstraintTypePosition, Set<Set<String>>>(); + private SortedMap<ConstraintTypePosition,Set<Set<String>>> constraintMap = new TreeMap<ConstraintTypePosition,Set<Set<String>>>(); + /** * Adds an constraint type + * * @param pos * @param values */ - public void addEncoded(ConstraintTypePosition pos,String...values){ - if(values == null || values.length<1){ + public void addEncoded(ConstraintTypePosition pos, String... values) { + if (values == null || values.length < 1) { return; } else { Set<Set<String>> constraints = constraintMap.get(pos); - if(constraints == null){ + if (constraints == null) { constraints = new HashSet<Set<String>>(); constraintMap.put(pos, constraints); } @@ -74,19 +76,22 @@ public class EncodedConstraintParts impl @Override public String toString() { - return "Encoded Constraints: "+constraintMap.toString(); + return "Encoded Constraints: " + constraintMap.toString(); } @Override - public Iterator<Entry<ConstraintTypePosition, Set<Set<String>>>> iterator() { + public Iterator<Entry<ConstraintTypePosition,Set<Set<String>>>> iterator() { return constraintMap.entrySet().iterator(); } + @Override public int hashCode() { return constraintMap.hashCode(); } + @Override public boolean equals(Object obj) { - return obj instanceof EncodedConstraintParts && ((EncodedConstraintParts)obj).constraintMap.equals(constraintMap); + return obj instanceof EncodedConstraintParts + && ((EncodedConstraintParts) obj).constraintMap.equals(constraintMap); } } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEncoder.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEncoder.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEncoder.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEncoder.java Fri May 13 15:29:20 2011 @@ -22,86 +22,92 @@ import java.util.Collections; import org.apache.stanbol.entityhub.yard.solr.model.IndexField; - - /** - * Interface used to encode constraints for a logical {@link IndexField}.<p> - * Typically a single constraint in a query needs to converted to several - * constraints in the index. Do give some examples let's assume, that we are - * interested in documents that contains "life" in there English title. - * This constraint would be represented by the following constraints in the - * index<ul> - * <li> A {@link IndexConstraintTypeEnum#LANG} set to be English - * <li> A {@link IndexConstraintTypeEnum#FIELD} set to "dc:title" (dublin core) - * <li> A {@link IndexConstraintTypeEnum#WILDCARD} set to life* or alternatively + * Interface used to encode constraints for a logical {@link IndexField}. + * <p> + * Typically a single constraint in a query needs to converted to several constraints in the index. Do give + * some examples let's assume, that we are interested in documents that contains "life" in there English + * title. This constraint would be represented by the following constraints in the index + * <ul> + * <li>A {@link IndexConstraintTypeEnum#LANG} set to be English + * <li>A {@link IndexConstraintTypeEnum#FIELD} set to "dc:title" (dublin core) + * <li>A {@link IndexConstraintTypeEnum#WILDCARD} set to life* or alternatively * <li> {@link IndexConstraintTypeEnum#EQ} set to life. * </ul> - * In addition it can be the case that for encoding one kind of constraint one - * needs also an other constraint to be present. e.g. when encoding a range - * constraint one needs always to have both the upper and lower bound to be - * present. Because of that implementations of this interface can define there - * {@link #dependsOn()} other {@link IndexConstraintTypeEnum} to be present. - * Such types are than added with the default constraint <code>null</code> if - * missing. Implementations can indicate with {@link #supportsDefault()} if - * they are able to encode the constraint type when set to the default value - * <code>null</code>.<p> - * Finally different constraints need different types of values to be parsed. - * Therefore this interface uses a generic type and the {@link #acceptsValueType()} - * method can be used to check if the type of the parsed value is compatible - * with the implementation registered for the current - * {@link IndexConstraintTypeEnum}.<p> - * Please note that implementations of this interface need to be thread save, - * because typically there will only be one instance that is shared for all - * encoding taks.<p> - * TODO: Currently there is no generic implementation that implements the - * processing steps described here. However the SolrQueryFactory provides a - * Solr specific implementation. + * In addition it can be the case that for encoding one kind of constraint one needs also an other constraint + * to be present. e.g. when encoding a range constraint one needs always to have both the upper and lower + * bound to be present. Because of that implementations of this interface can define there + * {@link #dependsOn()} other {@link IndexConstraintTypeEnum} to be present. Such types are than added with + * the default constraint <code>null</code> if missing. Implementations can indicate with + * {@link #supportsDefault()} if they are able to encode the constraint type when set to the default value + * <code>null</code>. + * <p> + * Finally different constraints need different types of values to be parsed. Therefore this interface uses a + * generic type and the {@link #acceptsValueType()} method can be used to check if the type of the parsed + * value is compatible with the implementation registered for the current {@link IndexConstraintTypeEnum}. + * <p> + * Please note that implementations of this interface need to be thread save, because typically there will + * only be one instance that is shared for all encoding taks. + * <p> + * TODO: Currently there is no generic implementation that implements the processing steps described here. + * However the SolrQueryFactory provides a Solr specific implementation. + * * @author Rupert Westenthaler - * @param T the type of supported values! + * @param T + * the type of supported values! */ public interface IndexConstraintTypeEncoder<T> { /** - * Encodes the parsed value and adds it to the IndexQueryConstraint. <p> - * If the encoder supports default values (meaning that - * {@link #supportsDefault()} returns <code>true</code>, than parsing - * <code>null</code> as value MUST result in returning the - * default value. Otherwise the encode method might throw an - * {@link IllegalArgumentException} if <code>null</code> is parsed.<p> - * Please note that <code>null</code> might also be a valid parameter even - * if an Encoder does not support a default value! - * @param value the value for the constraint - * @throws IllegalArgumentException if the parsed value is not supported. - * Especially if <code>null</code> is parsed and the implementation does not - * {@link #supportsDefault()}! + * Encodes the parsed value and adds it to the IndexQueryConstraint. + * <p> + * If the encoder supports default values (meaning that {@link #supportsDefault()} returns + * <code>true</code>, than parsing <code>null</code> as value MUST result in returning the default value. + * Otherwise the encode method might throw an {@link IllegalArgumentException} if <code>null</code> is + * parsed. + * <p> + * Please note that <code>null</code> might also be a valid parameter even if an Encoder does not support + * a default value! + * + * @param value + * the value for the constraint + * @throws IllegalArgumentException + * if the parsed value is not supported. Especially if <code>null</code> is parsed and the + * implementation does not {@link #supportsDefault()}! */ - void encode(EncodedConstraintParts constraint,T value) throws IllegalArgumentException; + void encode(EncodedConstraintParts constraint, T value) throws IllegalArgumentException; + /** - * Returns <code>true</code> if this Encoder supports a default value. This - * would be e.g. an open ended upper or lower bound for range constraints or - * any language for text constraints. - * @return if the encoder supports a default encoding if no constraint of that - * type is provided by the query. + * Returns <code>true</code> if this Encoder supports a default value. This would be e.g. an open ended + * upper or lower bound for range constraints or any language for text constraints. + * + * @return if the encoder supports a default encoding if no constraint of that type is provided by the + * query. */ boolean supportsDefault(); + /** - * A set of other Constraints that need to be present, that the encoding provided - * by this encoder results in a valid query constraint. e.g. A range constraint - * always need a lower and an upper bound. So even if the query only defines - * an upper bound, than there MUST BE also a open ended lower bound encoded to + * A set of other Constraints that need to be present, that the encoding provided by this encoder results + * in a valid query constraint. e.g. A range constraint always need a lower and an upper bound. So even if + * the query only defines an upper bound, than there MUST BE also a open ended lower bound encoded to * result in a valid query constraint. - * @return set of other index constraint types that must be present. If none - * return {@link Collections#emptySet()}. This Method should return an - * unmodifiable collection (e.g. {@link Arrays#asList(Object...)} or using - * {@link Collections#unmodifiableCollection(Collection)}) + * + * @return set of other index constraint types that must be present. If none return + * {@link Collections#emptySet()}. This Method should return an unmodifiable collection (e.g. + * {@link Arrays#asList(Object...)} or using + * {@link Collections#unmodifiableCollection(Collection)}) */ Collection<IndexConstraintTypeEnum> dependsOn(); + /** * The type of the constraint this implementation encodes + * * @return the type of the constraints encoded by this implementation */ IndexConstraintTypeEnum encodes(); + /** * Getter for the type of values this encoder accepts. + * * @return the generic type of the index constraint type encoder */ Class<T> acceptsValueType(); Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEnum.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEnum.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEnum.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEnum.java Fri May 13 15:29:20 2011 @@ -18,16 +18,17 @@ package org.apache.stanbol.entityhub.yar import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType; - /** - * Constraint Types defined for IndexFields<p> - * This could be replaced by a more flexible way to register supported - * constraint types in future versions + * Constraint Types defined for IndexFields + * <p> + * This could be replaced by a more flexible way to register supported constraint types in future versions + * * @author Rupert Westenthaler */ -public enum IndexConstraintTypeEnum{ +public enum IndexConstraintTypeEnum { /** * constraints the DataType of values + * * @see IndexDataType */ DATATYPE, Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java Fri May 13 15:29:20 2011 @@ -21,56 +21,57 @@ import java.util.regex.Pattern; import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum; import org.apache.stanbol.entityhub.yard.solr.model.IndexValue; - public final class SolrUtil { - private SolrUtil(){} + private SolrUtil() {} private static final String LUCENE_ESCAPE_CHARS = "[\\\\+\\-\\!\\(\\)\\:\\^\\[\\]\\{\\}\\~\\*\\?]"; private static final Pattern LUCENE_PATTERN = Pattern.compile(LUCENE_ESCAPE_CHARS); private static final String REPLACEMENT_STRING = "\\\\$0"; - /** - * Escapes all special chars in an string (field name or constraint) to be - * used in an SolrQuery. - * @param string the string to be escaped + * Escapes all special chars in an string (field name or constraint) to be used in an SolrQuery. + * + * @param string + * the string to be escaped * @return the escaped string */ public static String escapeSolrSpecialChars(String string) { - return string != null?LUCENE_PATTERN.matcher(string).replaceAll(REPLACEMENT_STRING):null; + return string != null ? LUCENE_PATTERN.matcher(string).replaceAll(REPLACEMENT_STRING) : null; } + /** - * This method encodes a parsed index value as needed for queries.<p> - * In case of TXT it is assumed that a whitespace tokenizer is used - * by the index. Therefore values with multiple words need to be - * treated and connected with AND to find only values that contain all. - * In case of STR no whitespace is assumed. Therefore spaces need to - * be replaced with '+' to search for tokens with the exact name. - * In all other cases the string need not to be converted. + * This method encodes a parsed index value as needed for queries. + * <p> + * In case of TXT it is assumed that a whitespace tokenizer is used by the index. Therefore values with + * multiple words need to be treated and connected with AND to find only values that contain all. In case + * of STR no whitespace is assumed. Therefore spaces need to be replaced with '+' to search for tokens + * with the exact name. In all other cases the string need not to be converted. * * Note also that text queries are converted to lower case - * @param value the index value + * + * @param value + * the index value * @return the (possible multiple) values that need to be connected with AND */ - public static String[] encodeQueryValue(IndexValue indexValue,boolean escape){ - if(indexValue == null){ + public static String[] encodeQueryValue(IndexValue indexValue, boolean escape) { + if (indexValue == null) { return null; } String[] queryConstraints; String value; - if(escape){ + if (escape) { value = SolrUtil.escapeSolrSpecialChars(indexValue.getValue()); } else { value = indexValue.getValue(); } - if(IndexDataTypeEnum.TXT.getIndexType().equals(indexValue.getType())){ + if (IndexDataTypeEnum.TXT.getIndexType().equals(indexValue.getType())) { value = value.toLowerCase(); queryConstraints = value.split(" "); - } else if(IndexDataTypeEnum.STR.equals(indexValue.getType())){ + } else if (IndexDataTypeEnum.STR.equals(indexValue.getType())) { value = value.toLowerCase(); - queryConstraints = new String[]{value.replace(' ', '+')}; + queryConstraints = new String[] {value.replace(' ', '+')}; } else { - queryConstraints = new String[]{value}; + queryConstraints = new String[] {value}; } return queryConstraints; } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java Fri May 13 15:29:20 2011 @@ -37,76 +37,77 @@ import org.slf4j.LoggerFactory; public class SolrDirectoryManagerTest { private static final Logger log = LoggerFactory.getLogger(SolrDirectoryManagerTest.class); - + private static SolrDirectoryManager solrDirectoryManager; - + private static File expectedManagedDirectory; - private static Collection<String> expectedIndexNames = Arrays.asList("entityhub","cache"); - + private static Collection<String> expectedIndexNames = Arrays.asList("entityhub", "cache"); + @BeforeClass - public static void init(){ - //set to "${basedir}/some/rel/path" to test if property substitution works! - String solrServerDir = "${basedir}"+SolrYardTest.TEST_INDEX_REL_PATH; - log.info("configured directory: "+solrServerDir); + public static void init() { + // set to "${basedir}/some/rel/path" to test if property substitution works! + String solrServerDir = "${basedir}" + SolrYardTest.TEST_INDEX_REL_PATH; + log.info("configured directory: " + solrServerDir); System.setProperty(SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, solrServerDir); - //store the expected managed directory for later testing - expectedManagedDirectory = new File(System.getProperty("basedir"),SolrYardTest.TEST_INDEX_REL_PATH); - log.info("expected managed directory: "+expectedManagedDirectory); - //create the SolrDirectoryManager used for the tests - Iterator<SolrDirectoryManager> providerIt = - ServiceLoader.load(SolrDirectoryManager.class,SolrDirectoryManager.class.getClassLoader()).iterator(); - if(providerIt.hasNext()){ + // store the expected managed directory for later testing + expectedManagedDirectory = new File(System.getProperty("basedir"), SolrYardTest.TEST_INDEX_REL_PATH); + log.info("expected managed directory: " + expectedManagedDirectory); + // create the SolrDirectoryManager used for the tests + Iterator<SolrDirectoryManager> providerIt = ServiceLoader.load(SolrDirectoryManager.class, + SolrDirectoryManager.class.getClassLoader()).iterator(); + if (providerIt.hasNext()) { solrDirectoryManager = providerIt.next(); } else { - throw new IllegalStateException("Unable to instantiate "+SolrDirectoryManager.class.getSimpleName()+" service by using "+ServiceLoader.class.getName()+"!"); + throw new IllegalStateException("Unable to instantiate " + + SolrDirectoryManager.class.getSimpleName() + + " service by using " + ServiceLoader.class.getName() + "!"); } } - + @Test - public void testManagedDirectoryInitialisation(){ - //the managed directory must be set based on the - expectedManagedDirectory.equals( - solrDirectoryManager.getManagedDirectory()); - } - - @Test(expected=IllegalArgumentException.class) - public void testNullIndexName(){ - solrDirectoryManager.getSolrIndexDirectory(null,true); + public void testManagedDirectoryInitialisation() { + // the managed directory must be set based on the + expectedManagedDirectory.equals(solrDirectoryManager.getManagedDirectory()); } - @Test(expected=IllegalArgumentException.class) - public void testEmptyIndexName(){ - solrDirectoryManager.getSolrIndexDirectory("",true); + @Test(expected = IllegalArgumentException.class) + public void testNullIndexName() { + solrDirectoryManager.getSolrIndexDirectory(null, true); + } + + @Test(expected = IllegalArgumentException.class) + public void testEmptyIndexName() { + solrDirectoryManager.getSolrIndexDirectory("", true); } @Test - public void testGetManagedIndexes(){ + public void testGetManagedIndexes() { Set<String> expected = new HashSet<String>(expectedIndexNames); - for(Entry<String,File> index : solrDirectoryManager.getManagedIndices().entrySet()){ + for (Entry<String,File> index : solrDirectoryManager.getManagedIndices().entrySet()) { expected.remove(index.getKey()); - //test that the index dir is the expected location - File expectedLocation = new File(expectedManagedDirectory,index.getKey()); + // test that the index dir is the expected location + File expectedLocation = new File(expectedManagedDirectory, index.getKey()); assertEquals(expectedLocation, index.getValue()); } - //test that the expected indexes where returned + // test that the expected indexes where returned assertTrue(expected.isEmpty()); } - + @Test - public void testIsManagedIndex(){ - for(String name : expectedIndexNames){ + public void testIsManagedIndex() { + for (String name : expectedIndexNames) { assertTrue(solrDirectoryManager.isManagedIndex(name)); } - assertFalse(solrDirectoryManager.isManagedIndex("notAnIndex"+System.currentTimeMillis())); + assertFalse(solrDirectoryManager.isManagedIndex("notAnIndex" + System.currentTimeMillis())); } - + @Test - public void testDefaultIndexInitialisation(){ - //this is actually tested already by the initialisation of the - //SolrYardTest ... - String indexName = "testIndexInitialisation_"+System.currentTimeMillis(); - File indexDir = solrDirectoryManager.getSolrIndexDirectory(indexName,true); - assertEquals(new File(expectedManagedDirectory,indexName), indexDir); + public void testDefaultIndexInitialisation() { + // this is actually tested already by the initialisation of the + // SolrYardTest ... + String indexName = "testIndexInitialisation_" + System.currentTimeMillis(); + File indexDir = solrDirectoryManager.getSolrIndexDirectory(indexName, true); + assertEquals(new File(expectedManagedDirectory, indexName), indexDir); assertTrue(indexDir.isDirectory()); } } Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java?rev=1102791&r1=1102790&r2=1102791&view=diff ============================================================================== --- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java (original) +++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java Fri May 13 15:29:20 2011 @@ -30,12 +30,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This test uses the system property "basedir" to configure an embedded Solr - * Server. This property is set by the mvn surefire plugin. When using this - * Unit Test within a build environment that does not set this property one need - * to set it manually to the base directory of this module.<p> + * This test uses the system property "basedir" to configure an embedded Solr Server. This property is set by + * the mvn surefire plugin. When using this Unit Test within a build environment that does not set this + * property one need to set it manually to the base directory of this module. + * <p> + * * @author Rupert Westenthaler - * + * */ public class SolrYardTest extends YardTest { /** @@ -47,55 +48,56 @@ public class SolrYardTest extends YardTe */ public static final String TEST_YARD_ID = "testYard"; public static final String TEST_SOLR_CORE_NAME = "test"; - protected static final String TEST_INDEX_REL_PATH = - File.separatorChar + "target"+ - File.separatorChar + SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR; + protected static final String TEST_INDEX_REL_PATH = File.separatorChar + "target" + File.separatorChar + + SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR; private static final Logger log = LoggerFactory.getLogger(SolrYardTest.class); - + @BeforeClass public static final void initYard() throws YardException { - //get the working directory - //use property substitution to test this feature! - String solrServerDir = "${basedir}"+TEST_INDEX_REL_PATH; - log.info("Test Solr Server Directory: "+solrServerDir); + // get the working directory + // use property substitution to test this feature! + String solrServerDir = "${basedir}" + TEST_INDEX_REL_PATH; + log.info("Test Solr Server Directory: " + solrServerDir); System.setProperty(SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, solrServerDir); - SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID,TEST_SOLR_CORE_NAME); + SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME); config.setName("Solr Yard Test"); config.setDescription("The Solr Yard instance used to execute the Unit Tests defined for the Yard Interface"); - //create the Yard used for the tests + // create the Yard used for the tests yard = new SolrYard(config); } - + @Override protected Yard getYard() { return yard; } + /* - * Three unit tests that check that SolrYardConfig does throw - * IllegalArgumentExceptions when parsing an illegal parameters. + * Three unit tests that check that SolrYardConfig does throw IllegalArgumentExceptions when parsing an + * illegal parameters. */ - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testSolrYardConfigInitWithNullParams() { - new SolrYardConfig(null, null); + new SolrYardConfig(null, null); } - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void testSolrYardConfigInitWithNullUrl() { - new SolrYardConfig(TEST_YARD_ID, null); + new SolrYardConfig(TEST_YARD_ID, null); } - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void testSolrYardConfigInitWithNullID() { - new SolrYardConfig(null, TEST_SOLR_CORE_NAME); + new SolrYardConfig(null, TEST_SOLR_CORE_NAME); } - + /** * This Method removes all Representations create via {@link #create()} or - * {@link #create(String, boolean)} from the tested {@link Yard}. - * It also removes all Representations there ID was manually added to the - * {@link #representationIds} list. + * {@link #create(String, boolean)} from the tested {@link Yard}. It also removes all Representations + * there ID was manually added to the {@link #representationIds} list. */ @AfterClass public static final void clearUpRepresentations() throws YardException { yard.remove(representationIds); } - + }
