diff --git a/licence.txt b/licence.txt index 654f7988..b474b01e 100644 --- a/licence.txt +++ b/licence.txt @@ -6,4 +6,4 @@ Redistributions of source code must retain the above copyright notice, this list Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Quadratica SRL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pom.xml b/pom.xml index dc73fa9b..3d46500b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,68 +1,68 @@ - 4.0.0 + 4.0.0 - com.googlecode - jira-suite-utilities - JIRA Suite Utilities - 0.7.14-SNAPSHOT + com.googlecode + jira-suite-utilities + JIRA Suite Utilities + 0.7.14-SNAPSHOT atlassian-plugin - - Quadratica SRL - http://www.quadratica.com.ar/ - - - Many objects to extend JIRA - 2007 - - - - Gustavo Martin - gmartin - gmartin@quadratica.com.ar - Quadratica SRL - - Developer - - - - Bettina Zucker - bettina - bettina.zucker@eu.panasonic.com - PASE GmbH - - Developer - - - - Alexey Abashev - abashev - abashev at gmail dot com - - Developer - - - - Cristiane Fontana - cfontana - no_spam@no_spam.com - - Developer - - - + + Quadratica SRL + http://www.quadratica.com.ar/ + - - - - maven-compiler-plugin - - 1.5 - 1.5 - - - + Many objects to extend JIRA + 2007 + + + + Gustavo Martin + gmartin + gmartin@quadratica.com.ar + Quadratica SRL + + Developer + + + + Bettina Zucker + bettina + bettina.zucker@eu.panasonic.com + PASE GmbH + + Developer + + + + Alexey Abashev + abashev + abashev at gmail dot com + + Developer + + + + Cristiane Fontana + cfontana + no_spam@no_spam.com + + Developer + + + + + + + + maven-compiler-plugin + + 1.5 + 1.5 + + + com.atlassian.maven.plugins maven-jira-plugin 3.2 @@ -72,7 +72,7 @@ ${jira.data.version} - + maven-source-plugin @@ -83,7 +83,7 @@ - + maven-jar-plugin @@ -94,101 +94,101 @@ - - org.apache.maven.plugins - maven-release-plugin + + org.apache.maven.plugins + maven-release-plugin 2.0-beta-9 - - https://jira-suite-utilities.googlecode.com/svn/tags - release - gcupload:gcupload - - - - org.riedelcastro - gcupload-maven-plugin - 0.9 - - jira-suite-utilities - - - ${project.name} version ${project.version} (binaries) - jar - Type-Package,OpSys-All,Featured - - - ${project.name} version ${project.version} (sources) - sources - jar - Type-Source,OpSys-All - - - - - - - - src/main/resources - true - - - + + https://jira-suite-utilities.googlecode.com/svn/tags + release + gcupload:gcupload + + + + org.riedelcastro + gcupload-maven-plugin + 0.9 + + jira-suite-utilities + + + ${project.name} version ${project.version} (binaries) + jar + Type-Package,OpSys-All,Featured + + + ${project.name} version ${project.version} (sources) + sources + jar + Type-Source,OpSys-All + + + + + + + + src/main/resources + true + + + + + + + com.atlassian.jira + atlassian-jira + ${jira.version} + + + junit + junit + + + provided + + + junit + junit + 4.8.1 + test + + - - - com.atlassian.jira - atlassian-jira - ${jira.version} - - - junit - junit - - - provided - - - junit - junit - 4.8.1 - test - - - - - ${scm.connection} - ${scm.connection} - - - - - atlassian-m2 - https://m2proxy.atlassian.com/repository/public - - true - always - - - true - - - - - - - atlassian-m2 - https://m2proxy.atlassian.com/repository/public - - - repository.riedelcastro.org - http://repository.riedelcastro.org - - + + ${scm.connection} + ${scm.connection} + - + + + atlassian-m2 + https://m2proxy.atlassian.com/repository/public + + true + always + + + true + + + + + + + atlassian-m2 + https://m2proxy.atlassian.com/repository/public + + + repository.riedelcastro.org + http://repository.riedelcastro.org + + + + 4.1.2 4.1.1 - - scm:hg:git+ssh://git@github.com:abashev/jira-suite-utilities.git - + + scm:hg:git+ssh://git@github.com:abashev/jira-suite-utilities.git + diff --git a/src/main/java/com/googlecode/jsu/annotation/AbstractVisitor.java b/src/main/java/com/googlecode/jsu/annotation/AbstractVisitor.java index fbae976a..5d93d3a4 100644 --- a/src/main/java/com/googlecode/jsu/annotation/AbstractVisitor.java +++ b/src/main/java/com/googlecode/jsu/annotation/AbstractVisitor.java @@ -8,8 +8,8 @@ * @version $Id: AbstractVisitor.java 105 2007-10-09 13:34:25Z abashev $ */ public abstract class AbstractVisitor { - public abstract Class getAnnotation(); - - public void visitField(Object source, Field field, Annotation annotation) { - } + public abstract Class getAnnotation(); + + public void visitField(Object source, Field field, Annotation annotation) { + } } diff --git a/src/main/java/com/googlecode/jsu/annotation/AnnotationProcessor.java b/src/main/java/com/googlecode/jsu/annotation/AnnotationProcessor.java index af218fc7..0499f117 100644 --- a/src/main/java/com/googlecode/jsu/annotation/AnnotationProcessor.java +++ b/src/main/java/com/googlecode/jsu/annotation/AnnotationProcessor.java @@ -10,23 +10,23 @@ * @version $Id: AnnotationProcessor.java 105 2007-10-09 13:34:25Z abashev $ */ public class AnnotationProcessor { - private List visitors = new ArrayList(); - - public void addVisitor(AbstractVisitor visitor) { - this.visitors.add(visitor); - } - - public void processAnnotations(Object object) { - Class clazz = object.getClass(); - - for (Field field : clazz.getDeclaredFields()) { - for (AbstractVisitor visitor : visitors) { - Annotation a = field.getAnnotation(visitor.getAnnotation()); - - if (a != null) { - visitor.visitField(object, field, a); - } - } - } - } + private List visitors = new ArrayList(); + + public void addVisitor(AbstractVisitor visitor) { + this.visitors.add(visitor); + } + + public void processAnnotations(Object object) { + Class clazz = object.getClass(); + + for (Field field : clazz.getDeclaredFields()) { + for (AbstractVisitor visitor : visitors) { + Annotation a = field.getAnnotation(visitor.getAnnotation()); + + if (a != null) { + visitor.visitField(object, field, a); + } + } + } + } } diff --git a/src/main/java/com/googlecode/jsu/annotation/Argument.java b/src/main/java/com/googlecode/jsu/annotation/Argument.java index e60fbbda..ee1f0437 100644 --- a/src/main/java/com/googlecode/jsu/annotation/Argument.java +++ b/src/main/java/com/googlecode/jsu/annotation/Argument.java @@ -17,5 +17,5 @@ @Retention(RUNTIME) @Target(FIELD) public @interface Argument { - String value() default ""; + String value() default ""; } diff --git a/src/main/java/com/googlecode/jsu/annotation/MapFieldProcessor.java b/src/main/java/com/googlecode/jsu/annotation/MapFieldProcessor.java index 1cc3f564..f7af4fb2 100644 --- a/src/main/java/com/googlecode/jsu/annotation/MapFieldProcessor.java +++ b/src/main/java/com/googlecode/jsu/annotation/MapFieldProcessor.java @@ -13,68 +13,68 @@ * @version $Id: MapFieldProcessor.java 105 2007-10-09 13:34:25Z abashev $ */ public class MapFieldProcessor extends AbstractVisitor { - private final Logger log = Logger.getLogger(MapFieldProcessor.class); - - private final Class annotation; - private final Map values; - - /** - * @param annotation - * @param values - */ - public MapFieldProcessor(Class annotation, Map values) { - super(); - - this.annotation = annotation; - this.values = values; - } + private final Logger log = Logger.getLogger(MapFieldProcessor.class); - public Class getAnnotation() { - return annotation; - } + private final Class annotation; + private final Map values; - /* (non-Javadoc) - * @see com.googlecode.jsu.annotation.AbstractVisitor#visitField(java.lang.reflect.Field) - */ - public void visitField(Object source, Field field, Annotation sourceAnnon) { - String fieldName = getAnnotationValue(sourceAnnon); - - if ((fieldName == null) || ("".equals(fieldName))) { - fieldName = field.getName(); - } - - try { - boolean access = field.isAccessible(); - - field.setAccessible(true); - field.set(source, values.get(fieldName)); - field.setAccessible(access); - } catch (IllegalArgumentException e) { - log.error("Unable to set class field - " + fieldName, e); - } catch (IllegalAccessException e) { - log.error("Unable to set class field - " + fieldName, e); - } - } - - protected String getAnnotationValue(Annotation annotation) { - String result = null; - - try { - Method valueMethod = annotation.getClass().getDeclaredMethod("value", new Class[] {}); - - result = (String) valueMethod.invoke(annotation, new Object[] {}); - } catch (SecurityException e) { - // Everything ok - } catch (NoSuchMethodException e) { - // Everything ok - } catch (IllegalArgumentException e) { - // Everything ok - } catch (IllegalAccessException e) { - // Everything ok - } catch (InvocationTargetException e) { - // Everything ok - } - - return result; - } + /** + * @param annotation + * @param values + */ + public MapFieldProcessor(Class annotation, Map values) { + super(); + + this.annotation = annotation; + this.values = values; + } + + public Class getAnnotation() { + return annotation; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.annotation.AbstractVisitor#visitField(java.lang.reflect.Field) + */ + public void visitField(Object source, Field field, Annotation sourceAnnon) { + String fieldName = getAnnotationValue(sourceAnnon); + + if ((fieldName == null) || ("".equals(fieldName))) { + fieldName = field.getName(); + } + + try { + boolean access = field.isAccessible(); + + field.setAccessible(true); + field.set(source, values.get(fieldName)); + field.setAccessible(access); + } catch (IllegalArgumentException e) { + log.error("Unable to set class field - " + fieldName, e); + } catch (IllegalAccessException e) { + log.error("Unable to set class field - " + fieldName, e); + } + } + + protected String getAnnotationValue(Annotation annotation) { + String result = null; + + try { + Method valueMethod = annotation.getClass().getDeclaredMethod("value", new Class[] {}); + + result = (String) valueMethod.invoke(annotation, new Object[] {}); + } catch (SecurityException e) { + // Everything ok + } catch (NoSuchMethodException e) { + // Everything ok + } catch (IllegalArgumentException e) { + // Everything ok + } catch (IllegalAccessException e) { + // Everything ok + } catch (InvocationTargetException e) { + // Everything ok + } + + return result; + } } diff --git a/src/main/java/com/googlecode/jsu/annotation/TransientVariable.java b/src/main/java/com/googlecode/jsu/annotation/TransientVariable.java index 90511b34..aa81bbf5 100644 --- a/src/main/java/com/googlecode/jsu/annotation/TransientVariable.java +++ b/src/main/java/com/googlecode/jsu/annotation/TransientVariable.java @@ -10,7 +10,7 @@ /** * This annotation is used for marking fields as container for transient field in validators, * conditions and post-function. - * + * * @author Alexey Abashev * @version $Id: TransientVariable.java 105 2007-10-09 13:34:25Z abashev $ */ @@ -18,5 +18,5 @@ @Retention(RUNTIME) @Target(FIELD) public @interface TransientVariable { - String value() default ""; + String value() default ""; } diff --git a/src/main/java/com/googlecode/jsu/customfields/LocationSelectCFType.java b/src/main/java/com/googlecode/jsu/customfields/LocationSelectCFType.java index e1d8b808..d360f186 100644 --- a/src/main/java/com/googlecode/jsu/customfields/LocationSelectCFType.java +++ b/src/main/java/com/googlecode/jsu/customfields/LocationSelectCFType.java @@ -11,21 +11,21 @@ /** * Wrapper on Jira SelectCFType for using inside plugins v2. - * + * * @author Alexey Abashev * @version $Id$ */ public class LocationSelectCFType extends SelectCFType { - /** - * Default constructor without injection. - */ - public LocationSelectCFType() { - super( - getComponent(CustomFieldValuePersister.class), - getComponent(StringConverter.class), - getComponent(SelectConverter.class), - getComponent(OptionsManager.class), - getComponent(GenericConfigManager.class) - ); - } + /** + * Default constructor without injection. + */ + public LocationSelectCFType() { + super( + getComponent(CustomFieldValuePersister.class), + getComponent(StringConverter.class), + getComponent(SelectConverter.class), + getComponent(OptionsManager.class), + getComponent(GenericConfigManager.class) + ); + } } diff --git a/src/main/java/com/googlecode/jsu/customfields/LocationTextCFType.java b/src/main/java/com/googlecode/jsu/customfields/LocationTextCFType.java index 31c9cb4a..692e1019 100644 --- a/src/main/java/com/googlecode/jsu/customfields/LocationTextCFType.java +++ b/src/main/java/com/googlecode/jsu/customfields/LocationTextCFType.java @@ -9,19 +9,19 @@ /** * Wrapper on Jira RenderableTextCFType for using inside plugins v2. - * + * * @author Alexey Abashev * @version $Id$ */ public class LocationTextCFType extends RenderableTextCFType { - /** - * Default constructor without injection. - */ - public LocationTextCFType() { - super( - getComponent(CustomFieldValuePersister.class), - getComponent(StringConverter.class), - getComponent(GenericConfigManager.class) - ); - } + /** + * Default constructor without injection. + */ + public LocationTextCFType() { + super( + getComponent(CustomFieldValuePersister.class), + getComponent(StringConverter.class), + getComponent(GenericConfigManager.class) + ); + } } diff --git a/src/main/java/com/googlecode/jsu/customfields/TextSearcher.java b/src/main/java/com/googlecode/jsu/customfields/TextSearcher.java index 16b3f4f6..a680a57e 100644 --- a/src/main/java/com/googlecode/jsu/customfields/TextSearcher.java +++ b/src/main/java/com/googlecode/jsu/customfields/TextSearcher.java @@ -8,19 +8,19 @@ /** * Wrapper on Jira TextSearcher for using inside plugins v2. - * + * * @author Alexey Abashev * @version $Id$ */ public class TextSearcher extends com.atlassian.jira.issue.customfields.searchers.TextSearcher { - /** - * Default constructor without injection. - */ - public TextSearcher() { - super( - getComponent(FieldVisibilityManager.class), - getComponent(JqlOperandResolver.class), - getComponent(CustomFieldInputHelper.class) - ); - } + /** + * Default constructor without injection. + */ + public TextSearcher() { + super( + getComponent(FieldVisibilityManager.class), + getComponent(JqlOperandResolver.class), + getComponent(CustomFieldInputHelper.class) + ); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/ComparisonType.java b/src/main/java/com/googlecode/jsu/helpers/ComparisonType.java index 4b7b0d46..a5a595d2 100644 --- a/src/main/java/com/googlecode/jsu/helpers/ComparisonType.java +++ b/src/main/java/com/googlecode/jsu/helpers/ComparisonType.java @@ -2,74 +2,74 @@ /** * @author Gustavo Martin - * + * * This class represents a Comparison Type. This will be used in Workflow Condition, Validator, or Function. - * + * */ public class ComparisonType { - private final int id; - private final String value; - private final String mnemonic; - - /** - * @param id - * @param value - */ - public ComparisonType(int id, String value, String mnemonic) { - this.id = id; - this.value = value; - this.mnemonic = mnemonic; - } - - /** - * Get comparision id. - * @return - */ - public Integer getId() { - return id; - } - - /** - * Get name of comparision. - * - * @return - */ - public String getValue() { - return value; - } + private final int id; + private final String value; + private final String mnemonic; - /** - * @return the mnemonic - */ - public String getMnemonic() { - return mnemonic; - } + /** + * @param id + * @param value + */ + public ComparisonType(int id, String value, String mnemonic) { + this.id = id; + this.value = value; + this.mnemonic = mnemonic; + } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - return result; - } + /** + * Get comparision id. + * @return + */ + public Integer getId() { + return id; + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof ComparisonType)) - return false; - ComparisonType other = (ComparisonType) obj; - if (id != other.id) - return false; - return true; - } + /** + * Get name of comparision. + * + * @return + */ + public String getValue() { + return value; + } + + /** + * @return the mnemonic + */ + public String getMnemonic() { + return mnemonic; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ComparisonType)) + return false; + ComparisonType other = (ComparisonType) obj; + if (id != other.id) + return false; + return true; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/ConditionChecker.java b/src/main/java/com/googlecode/jsu/helpers/ConditionChecker.java index 70a482c3..a3529859 100644 --- a/src/main/java/com/googlecode/jsu/helpers/ConditionChecker.java +++ b/src/main/java/com/googlecode/jsu/helpers/ConditionChecker.java @@ -2,17 +2,17 @@ /** * Interface for checking conditions. Used as strategy pattern. - * + * * @author Alexey Abashev * @version $Id$ */ public interface ConditionChecker { - /** - * Check two values and return true if condition success or false is not. - * - * @param value1 - * @param value2 - * @return - */ - boolean checkValues(Object value1, Object value2); + /** + * Check two values and return true if condition success or false is not. + * + * @param value1 + * @param value2 + * @return + */ + boolean checkValues(Object value1, Object value2); } diff --git a/src/main/java/com/googlecode/jsu/helpers/ConditionCheckerFactory.java b/src/main/java/com/googlecode/jsu/helpers/ConditionCheckerFactory.java index 7d153b33..84858a7f 100644 --- a/src/main/java/com/googlecode/jsu/helpers/ConditionCheckerFactory.java +++ b/src/main/java/com/googlecode/jsu/helpers/ConditionCheckerFactory.java @@ -11,102 +11,102 @@ /** * Return object for checking conditions. - * + * * @author Alexey Abashev * @version $Id: GenericValidator.java 173 2008-10-14 13:04:43Z abashev $ */ public class ConditionCheckerFactory { - public static final ConditionType GREATER = new ConditionType(1, ">", "greater than", "G"); - public static final ConditionType GREATER_EQUAL = new ConditionType(2, ">=", "greater than or equal to", "GE"); - public static final ConditionType EQUAL = new ConditionType(3, "=", "equal to", "E"); - public static final ConditionType LESS_EQUAL = new ConditionType(4, "<=", "less than or equal to", "LE"); - public static final ConditionType LESS = new ConditionType(5, "<", "less than", "L"); - public static final ConditionType NOT_EQUAL = new ConditionType(6, "!=", "not equal to", "NE"); - - public static final ComparisonType STRING = new ComparisonType(1, "String", "String"); - public static final ComparisonType NUMBER = new ComparisonType(2, "Number", "Number"); - public static final ComparisonType DATE = new ComparisonType(3, "Date with time", "Date"); - public static final ComparisonType DATE_WITHOUT_TIME = new ComparisonType(4, "Date without time", "DateWithoutTime"); - - /** Template for checker class. */ - private static final String PACKAGE = ConditionCheckerFactory.class.getPackage().getName(); - private static final String CONDITION_CLASS_TEMPLATE = PACKAGE + ".checkers.Snipet"; - private static final String COMPARISON_CLASS_TEMPLATE = PACKAGE + ".checkers.Converter"; - - /** Cache for searching through conditions */ - private static final Map CONDITIONS_CACHE = - new LinkedHashMap() {{ - put(GREATER.getId(), GREATER); - put(GREATER_EQUAL.getId(), GREATER_EQUAL); - put(EQUAL.getId(), EQUAL); - put(LESS_EQUAL.getId(), LESS_EQUAL); - put(LESS.getId(), LESS); - put(NOT_EQUAL.getId(), NOT_EQUAL); - }}; - - /** Cache for searching through types */ - private static final Map COMPARISONS_CACHE = - new LinkedHashMap() {{ - put(STRING.getId(), STRING); - put(NUMBER.getId(), NUMBER); - put(DATE.getId(), DATE); - put(DATE_WITHOUT_TIME.getId(), DATE_WITHOUT_TIME); - }}; - - private final Logger log = Logger.getLogger(ConditionCheckerFactory.class); - private final CheckerCompositeFactory checkerCompositeFactory = new CheckerCompositeFactory(); - - public ConditionChecker getChecker(ComparisonType type, ConditionType condition) { - String conditionClassName = CONDITION_CLASS_TEMPLATE + condition.getMnemonic(); - String comparisonClassName = COMPARISON_CLASS_TEMPLATE + type.getMnemonic(); - - if (log.isDebugEnabled()) { - log.debug( - "Using class [" + conditionClassName + - "] for condition [" + condition.getValue() + - "]; class [" + comparisonClassName + - "] for type [" + type.getValue() + - "]" - ); - } - - return checkerCompositeFactory.getComposite(comparisonClassName, conditionClassName); - } - - /** - * Get all possible condition types. - * - * @return - */ - public List getConditionTypes() { - return new ArrayList(CONDITIONS_CACHE.values()); - } - - /** - * Get all possible comparison types. - * @return - */ - public List getComparisonTypes() { - return new ArrayList(COMPARISONS_CACHE.values()); - } - - /** - * Find condition by id. - * - * @param id - * @return - */ - public ConditionType findConditionById(String id) { - return CONDITIONS_CACHE.get(Integer.valueOf(id)); - } - - /** - * Find comparison by id. - * - * @param id - * @return - */ - public ComparisonType findComparisonById(String id) { - return COMPARISONS_CACHE.get(Integer.valueOf(id)); - } + public static final ConditionType GREATER = new ConditionType(1, ">", "greater than", "G"); + public static final ConditionType GREATER_EQUAL = new ConditionType(2, ">=", "greater than or equal to", "GE"); + public static final ConditionType EQUAL = new ConditionType(3, "=", "equal to", "E"); + public static final ConditionType LESS_EQUAL = new ConditionType(4, "<=", "less than or equal to", "LE"); + public static final ConditionType LESS = new ConditionType(5, "<", "less than", "L"); + public static final ConditionType NOT_EQUAL = new ConditionType(6, "!=", "not equal to", "NE"); + + public static final ComparisonType STRING = new ComparisonType(1, "String", "String"); + public static final ComparisonType NUMBER = new ComparisonType(2, "Number", "Number"); + public static final ComparisonType DATE = new ComparisonType(3, "Date with time", "Date"); + public static final ComparisonType DATE_WITHOUT_TIME = new ComparisonType(4, "Date without time", "DateWithoutTime"); + + /** Template for checker class. */ + private static final String PACKAGE = ConditionCheckerFactory.class.getPackage().getName(); + private static final String CONDITION_CLASS_TEMPLATE = PACKAGE + ".checkers.Snipet"; + private static final String COMPARISON_CLASS_TEMPLATE = PACKAGE + ".checkers.Converter"; + + /** Cache for searching through conditions */ + private static final Map CONDITIONS_CACHE = + new LinkedHashMap() {{ + put(GREATER.getId(), GREATER); + put(GREATER_EQUAL.getId(), GREATER_EQUAL); + put(EQUAL.getId(), EQUAL); + put(LESS_EQUAL.getId(), LESS_EQUAL); + put(LESS.getId(), LESS); + put(NOT_EQUAL.getId(), NOT_EQUAL); + }}; + + /** Cache for searching through types */ + private static final Map COMPARISONS_CACHE = + new LinkedHashMap() {{ + put(STRING.getId(), STRING); + put(NUMBER.getId(), NUMBER); + put(DATE.getId(), DATE); + put(DATE_WITHOUT_TIME.getId(), DATE_WITHOUT_TIME); + }}; + + private final Logger log = Logger.getLogger(ConditionCheckerFactory.class); + private final CheckerCompositeFactory checkerCompositeFactory = new CheckerCompositeFactory(); + + public ConditionChecker getChecker(ComparisonType type, ConditionType condition) { + String conditionClassName = CONDITION_CLASS_TEMPLATE + condition.getMnemonic(); + String comparisonClassName = COMPARISON_CLASS_TEMPLATE + type.getMnemonic(); + + if (log.isDebugEnabled()) { + log.debug( + "Using class [" + conditionClassName + + "] for condition [" + condition.getValue() + + "]; class [" + comparisonClassName + + "] for type [" + type.getValue() + + "]" + ); + } + + return checkerCompositeFactory.getComposite(comparisonClassName, conditionClassName); + } + + /** + * Get all possible condition types. + * + * @return + */ + public List getConditionTypes() { + return new ArrayList(CONDITIONS_CACHE.values()); + } + + /** + * Get all possible comparison types. + * @return + */ + public List getComparisonTypes() { + return new ArrayList(COMPARISONS_CACHE.values()); + } + + /** + * Find condition by id. + * + * @param id + * @return + */ + public ConditionType findConditionById(String id) { + return CONDITIONS_CACHE.get(Integer.valueOf(id)); + } + + /** + * Find comparison by id. + * + * @param id + * @return + */ + public ComparisonType findComparisonById(String id) { + return COMPARISONS_CACHE.get(Integer.valueOf(id)); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/ConditionType.java b/src/main/java/com/googlecode/jsu/helpers/ConditionType.java index f3752dc6..0616ef6d 100644 --- a/src/main/java/com/googlecode/jsu/helpers/ConditionType.java +++ b/src/main/java/com/googlecode/jsu/helpers/ConditionType.java @@ -2,77 +2,77 @@ /** * @author Gustavo Martin - * + * * This class represents a Condition Type. This will be used in Workflow Condition, Validator, or Function. - * + * */ public class ConditionType { - private final int id; - private final String shortText; - private final String displayText; - private final String mnemonic; - - /** - * @param id - * @param value - * @param displayValue - */ - public ConditionType( - int id, String shortText, String displayText, String mnemonic - ) { - this.id = id; - this.shortText = shortText; - this.displayText = displayText; - this.mnemonic = mnemonic; - } + private final int id; + private final String shortText; + private final String displayText; + private final String mnemonic; - public Integer getId() { - return id; - } + /** + * @param id + * @param value + * @param displayValue + */ + public ConditionType( + int id, String shortText, String displayText, String mnemonic + ) { + this.id = id; + this.shortText = shortText; + this.displayText = displayText; + this.mnemonic = mnemonic; + } - public String getValue() { - return shortText; - } - - /** - * @return the mnemonic - */ - public String getMnemonic() { - return mnemonic; - } + public Integer getId() { + return id; + } - /** - * Get display name for condition. - */ - public String toString() { - return displayText; - } + public String getValue() { + return shortText; + } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - return result; - } + /** + * @return the mnemonic + */ + public String getMnemonic() { + return mnemonic; + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof ConditionType)) - return false; - ConditionType other = (ConditionType) obj; - if (id != other.id) - return false; - return true; - } + /** + * Get display name for condition. + */ + public String toString() { + return displayText; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ConditionType)) + return false; + ConditionType other = (ConditionType) obj; + if (id != other.id) + return false; + return true; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/NameComparatorEx.java b/src/main/java/com/googlecode/jsu/helpers/NameComparatorEx.java index ea7a31f8..0b1426b0 100644 --- a/src/main/java/com/googlecode/jsu/helpers/NameComparatorEx.java +++ b/src/main/java/com/googlecode/jsu/helpers/NameComparatorEx.java @@ -7,9 +7,9 @@ /** * @author Gustavo Martin - * + * * This Comparator is used to compare two fields by its internationalized name. - * + * */ public class NameComparatorEx implements Comparator { private final I18nBean i18nBean; @@ -29,4 +29,4 @@ public int compare(Field o1, Field o2) { return name1.compareTo(name2); } -} \ No newline at end of file +} diff --git a/src/main/java/com/googlecode/jsu/helpers/YesNoType.java b/src/main/java/com/googlecode/jsu/helpers/YesNoType.java index 801174e9..df57d3c2 100644 --- a/src/main/java/com/googlecode/jsu/helpers/YesNoType.java +++ b/src/main/java/com/googlecode/jsu/helpers/YesNoType.java @@ -2,60 +2,60 @@ /** * @author Gustavo Martin - * - * This class represents a Yes/No Type. Its values could be YES or NO. + * + * This class represents a Yes/No Type. Its values could be YES or NO. * It will be used in Workflow Condition, Validator, or Function. - * + * */ public class YesNoType { - public static final YesNoType YES = new YesNoType(1, "Yes"); - public static final YesNoType NO = new YesNoType(2, "No"); - - private final int id; - private final String value; - - /** - * @param id - * @param value - */ - private YesNoType(int id, String value) { - this.id = id; - this.value = value; - } + public static final YesNoType YES = new YesNoType(1, "Yes"); + public static final YesNoType NO = new YesNoType(2, "No"); - public Integer getId() { - return id; - } + private final int id; + private final String value; - public String getValue() { - return value; - } + /** + * @param id + * @param value + */ + private YesNoType(int id, String value) { + this.id = id; + this.value = value; + } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - return result; - } + public Integer getId() { + return id; + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof YesNoType)) - return false; - YesNoType other = (YesNoType) obj; - if (id != other.id) - return false; - return true; - } + public String getValue() { + return value; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof YesNoType)) + return false; + YesNoType other = (YesNoType) obj; + if (id != other.id) + return false; + return true; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerComposite.java b/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerComposite.java index 4e703569..31328f2b 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerComposite.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerComposite.java @@ -9,59 +9,59 @@ * @version $Id$ */ class CheckerComposite implements ConditionChecker { - private final Logger log = Logger.getLogger(CheckerComposite.class); - - private final ValueConverter valueConverter; - private final ComparingSnipet comparingSnipet; + private final Logger log = Logger.getLogger(CheckerComposite.class); - /** - * @param valueConverter - * @param comparingSnipet - */ - public CheckerComposite( - ValueConverter valueConverter, ComparingSnipet comparingSnipet - ) { - this.valueConverter = valueConverter; - this.comparingSnipet = comparingSnipet; - } + private final ValueConverter valueConverter; + private final ComparingSnipet comparingSnipet; - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.ConditionChecker#checkValues(java.lang.Object, java.lang.Object) - */ - @SuppressWarnings("unchecked") - public final boolean checkValues(Object value1, Object value2) { - final Comparable comp1, comp2; - - try { - comp1 = valueConverter.getComparable(value1); - } catch (NumberFormatException e) { - log.warn("Wrong number format at [" + value1 + "]"); - - return false; - } catch (Exception e) { - log.warn("Unable to get comparable from [" + value1 + "]", e); - - return false; - } + /** + * @param valueConverter + * @param comparingSnipet + */ + public CheckerComposite( + ValueConverter valueConverter, ComparingSnipet comparingSnipet + ) { + this.valueConverter = valueConverter; + this.comparingSnipet = comparingSnipet; + } - try { - comp2 = valueConverter.getComparable(value2); - } catch (NumberFormatException e) { - log.warn("Wrong number format at [" + value2 + "]"); - - return false; - } catch (Exception e) { - log.warn("Unable to get comparable from [" + value2 + "]", e); - - return false; - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.ConditionChecker#checkValues(java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public final boolean checkValues(Object value1, Object value2) { + final Comparable comp1, comp2; - boolean result = comparingSnipet.compareObjects(comp1, comp2); + try { + comp1 = valueConverter.getComparable(value1); + } catch (NumberFormatException e) { + log.warn("Wrong number format at [" + value1 + "]"); - if (log.isDebugEnabled()) { - log.debug("Compare values [" + comp1 + "] and [" + comp2 + "] with result [" + result + "]"); - } + return false; + } catch (Exception e) { + log.warn("Unable to get comparable from [" + value1 + "]", e); - return result; - } + return false; + } + + try { + comp2 = valueConverter.getComparable(value2); + } catch (NumberFormatException e) { + log.warn("Wrong number format at [" + value2 + "]"); + + return false; + } catch (Exception e) { + log.warn("Unable to get comparable from [" + value2 + "]", e); + + return false; + } + + boolean result = comparingSnipet.compareObjects(comp1, comp2); + + if (log.isDebugEnabled()) { + log.debug("Compare values [" + comp1 + "] and [" + comp2 + "] with result [" + result + "]"); + } + + return result; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerCompositeFactory.java b/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerCompositeFactory.java index 757f9f5c..38bc5c4d 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerCompositeFactory.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/CheckerCompositeFactory.java @@ -7,45 +7,45 @@ * @version $Id$ */ public class CheckerCompositeFactory { - private static final Logger log = Logger.getLogger(CheckerCompositeFactory.class); - - /** - * Create composite for checking values. - * - * @param converterClass - * @param snipetClass - * @return - */ - public CheckerComposite getComposite(String converterClass, String snipetClass) { - ComparingSnipet snipet = getInstance(snipetClass); - - if (snipet == null) { - return null; - } - - ValueConverter converter = getInstance(converterClass); - - if (converter == null) { - return null; - } - - return (new CheckerComposite(converter, snipet)); - } - - @SuppressWarnings("unchecked") - private T getInstance(String className) { - T instance = null; - - try { - instance = (T) Class.forName(className).newInstance(); - } catch (InstantiationException e) { - log.error("Unable to initialize class [" + className + "]", e); - } catch (IllegalAccessException e) { - log.error("Unable to initialize class [" + className + "]", e); - } catch (ClassNotFoundException e) { - log.error("Unable to initialize class [" + className + "]", e); - } - - return instance; - } + private static final Logger log = Logger.getLogger(CheckerCompositeFactory.class); + + /** + * Create composite for checking values. + * + * @param converterClass + * @param snipetClass + * @return + */ + public CheckerComposite getComposite(String converterClass, String snipetClass) { + ComparingSnipet snipet = getInstance(snipetClass); + + if (snipet == null) { + return null; + } + + ValueConverter converter = getInstance(converterClass); + + if (converter == null) { + return null; + } + + return (new CheckerComposite(converter, snipet)); + } + + @SuppressWarnings("unchecked") + private T getInstance(String className) { + T instance = null; + + try { + instance = (T) Class.forName(className).newInstance(); + } catch (InstantiationException e) { + log.error("Unable to initialize class [" + className + "]", e); + } catch (IllegalAccessException e) { + log.error("Unable to initialize class [" + className + "]", e); + } catch (ClassNotFoundException e) { + log.error("Unable to initialize class [" + className + "]", e); + } + + return instance; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ComparingSnipet.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ComparingSnipet.java index 859992b3..763ffb4e 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ComparingSnipet.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ComparingSnipet.java @@ -6,13 +6,13 @@ */ @SuppressWarnings("unchecked") interface ComparingSnipet { - /** - * Execute comparing action for objects. - * - * @param - * @param comp1 - * @param comp2 - * @return - */ - boolean compareObjects(Comparable comp1, Comparable comp2); + /** + * Execute comparing action for objects. + * + * @param + * @param comp1 + * @param comp2 + * @return + */ + boolean compareObjects(Comparable comp1, Comparable comp2); } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDate.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDate.java index 5bf4a734..c117134d 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDate.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDate.java @@ -7,24 +7,24 @@ * @version $Id$ */ class ConverterDate implements ValueConverter { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) - */ - @SuppressWarnings("unchecked") - public Comparable getComparable(Object object) { - if (object == null) { - return null; - } - - if (object instanceof Calendar) { - Calendar cal = (Calendar) object; - - cal.clear(Calendar.SECOND); - cal.clear(Calendar.MILLISECOND); - - return cal; - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public Comparable getComparable(Object object) { + if (object == null) { + return null; + } - throw new UnsupportedOperationException("Unsupported value type " + object); - } + if (object instanceof Calendar) { + Calendar cal = (Calendar) object; + + cal.clear(Calendar.SECOND); + cal.clear(Calendar.MILLISECOND); + + return cal; + } + + throw new UnsupportedOperationException("Unsupported value type " + object); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDateWithoutTime.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDateWithoutTime.java index 85c18ca8..ff5d44b7 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDateWithoutTime.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterDateWithoutTime.java @@ -7,23 +7,23 @@ * @version $Id$ */ class ConverterDateWithoutTime extends ConverterDate { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ConverterDate#getComparable(java.lang.Object) - */ - @SuppressWarnings("unchecked") - @Override - public Comparable getComparable(Object object) { - if (object == null) { - return null; - } - - Calendar cal = (Calendar) super.getComparable(object); + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ConverterDate#getComparable(java.lang.Object) + */ + @SuppressWarnings("unchecked") + @Override + public Comparable getComparable(Object object) { + if (object == null) { + return null; + } - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); + Calendar cal = (Calendar) super.getComparable(object); - return cal; - } + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + + return cal; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterNumber.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterNumber.java index 3ee1323d..456a0a3a 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterNumber.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterNumber.java @@ -5,32 +5,32 @@ * @version $Id$ */ class ConverterNumber implements ValueConverter { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) - */ - @SuppressWarnings("unchecked") - public Comparable getComparable(Object object) { - if (object == null) { - return null; - } - - Double numberValue; + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public Comparable getComparable(Object object) { + if (object == null) { + return null; + } - if (object instanceof String) { - final String s = (String) object; - - if (s.trim().length() == 0) { - return null; - } - - numberValue = Double.valueOf(s); - } else if (object instanceof Number) { - numberValue = ((Number) object).doubleValue(); - } else { - throw new NumberFormatException(); - } - - return numberValue; - } + Double numberValue; + + if (object instanceof String) { + final String s = (String) object; + + if (s.trim().length() == 0) { + return null; + } + + numberValue = Double.valueOf(s); + } else if (object instanceof Number) { + numberValue = ((Number) object).doubleValue(); + } else { + throw new NumberFormatException(); + } + + return numberValue; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterString.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterString.java index 8ebded01..87440ea8 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterString.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ConverterString.java @@ -10,29 +10,29 @@ * @version $Id$ */ class ConverterString implements ValueConverter { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) - */ - @SuppressWarnings("unchecked") - public Comparable getComparable(Object object) { - if (object == null) { - return null; - } - - String result; - + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ValueConverter#getComparable(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public Comparable getComparable(Object object) { + if (object == null) { + return null; + } + + String result; + if (object instanceof IssueConstant) { - result = ((IssueConstant) object).getName(); + result = ((IssueConstant) object).getName(); } else if (object instanceof Entity) { - result = ((Entity) object).getName(); - } else { - result = object.toString(); - } - + result = ((Entity) object).getName(); + } else { + result = object.toString(); + } + if (StringUtils.isBlank(result)) { - return null; + return null; } - - return result; - } + + return result; + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetE.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetE.java index 6599115a..349b6775 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetE.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetE.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetE implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return (comp2 == null); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return (comp2 == null); + } - if (comp2 == null) { - return false; - } - - return (comp1.compareTo(comp2) == 0); - } + if (comp2 == null) { + return false; + } + + return (comp1.compareTo(comp2) == 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetG.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetG.java index 1d12b2db..912ef13d 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetG.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetG.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetG implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return false; - } - - if (comp2 == null) { - return false; - } - - return (comp1.compareTo(comp2) > 0); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return false; + } + + if (comp2 == null) { + return false; + } + + return (comp1.compareTo(comp2) > 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetGE.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetGE.java index 5b231d62..90d79de0 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetGE.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetGE.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetGE implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return (comp2 == null); - } - - if (comp2 == null) { - return false; - } - - return (comp1.compareTo(comp2) >= 0); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return (comp2 == null); + } + + if (comp2 == null) { + return false; + } + + return (comp1.compareTo(comp2) >= 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetL.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetL.java index 0dcb7568..2f76ff37 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetL.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetL.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetL implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return false; - } - - if (comp2 == null) { - return false; - } - - return (comp1.compareTo(comp2) < 0); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return false; + } + + if (comp2 == null) { + return false; + } + + return (comp1.compareTo(comp2) < 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetLE.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetLE.java index 27e31e76..d5c7c930 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetLE.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetLE.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetLE implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return (comp2 == null); - } - - if (comp2 == null) { - return false; - } - - return (comp1.compareTo(comp2) <= 0); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return (comp2 == null); + } + + if (comp2 == null) { + return false; + } + + return (comp1.compareTo(comp2) <= 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetNE.java b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetNE.java index 80ed3d4b..9f3d6842 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetNE.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/SnipetNE.java @@ -5,19 +5,19 @@ * @version $Id$ */ class SnipetNE implements ComparingSnipet { - /* (non-Javadoc) - * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) - */ - @SuppressWarnings("unchecked") - public boolean compareObjects(Comparable comp1, Comparable comp2) { - if (comp1 == null) { - return (comp2 != null); - } - - if (comp2 == null) { - return true; - } - - return (comp1.compareTo(comp2) != 0); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.helpers.checkers.ComparingSnipet#compareObjects(java.lang.Comparable, java.lang.Comparable) + */ + @SuppressWarnings("unchecked") + public boolean compareObjects(Comparable comp1, Comparable comp2) { + if (comp1 == null) { + return (comp2 != null); + } + + if (comp2 == null) { + return true; + } + + return (comp1.compareTo(comp2) != 0); + } } diff --git a/src/main/java/com/googlecode/jsu/helpers/checkers/ValueConverter.java b/src/main/java/com/googlecode/jsu/helpers/checkers/ValueConverter.java index 7d04566f..6948e1bd 100644 --- a/src/main/java/com/googlecode/jsu/helpers/checkers/ValueConverter.java +++ b/src/main/java/com/googlecode/jsu/helpers/checkers/ValueConverter.java @@ -5,12 +5,12 @@ * @version $Id$ */ interface ValueConverter { - /** - * Get comparable value from object. - * @param - * @param object - * @return - */ - @SuppressWarnings("unchecked") - Comparable getComparable(Object object); + /** + * Get comparable value from object. + * @param + * @param object + * @return + */ + @SuppressWarnings("unchecked") + Comparable getComparable(Object object); } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/RemovedStatusImpl.java b/src/main/java/com/googlecode/jsu/transitionssummary/RemovedStatusImpl.java index c2d29fcb..ac314e62 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/RemovedStatusImpl.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/RemovedStatusImpl.java @@ -9,77 +9,77 @@ import com.opensymphony.module.propertyset.PropertySet; public class RemovedStatusImpl implements Status { - public void deleteTranslation(String issueConstantPrefix, Locale locale) { - } + public void deleteTranslation(String issueConstantPrefix, Locale locale) { + } - public String getDescription() { - return "Status representing an old Status removed from Database"; - } + public String getDescription() { + return "Status representing an old Status removed from Database"; + } - public String getDescTranslation() { - return getDescription(); - } + public String getDescTranslation() { + return getDescription(); + } - public String getDescTranslation(I18nHelper i18n) { - return getDescription(); - } + public String getDescTranslation(I18nHelper i18n) { + return getDescription(); + } - public String getDescTranslation(String locale) { - return getDescription(); - } + public String getDescTranslation(String locale) { + return getDescription(); + } - public GenericValue getGenericValue() { - return null; - } + public GenericValue getGenericValue() { + return null; + } - public String getIconUrl() { - return null; - } + public String getIconUrl() { + return null; + } - public String getId() { - return "-1"; - } + public String getId() { + return "-1"; + } - public String getName() { - return "Removed Status"; - } + public String getName() { + return "Removed Status"; + } - public String getNameTranslation() { - return getName(); - } + public String getNameTranslation() { + return getName(); + } - public String getNameTranslation(I18nHelper i18n) { - return getName(); - } + public String getNameTranslation(I18nHelper i18n) { + return getName(); + } - public String getNameTranslation(String locale) { - return getName(); - } + public String getNameTranslation(String locale) { + return getName(); + } - public PropertySet getPropertySet() { - return null; - } + public PropertySet getPropertySet() { + return null; + } - public Long getSequence() { - return null; - } + public Long getSequence() { + return null; + } - public void setDescription(String description) { - } + public void setDescription(String description) { + } - public void setIconUrl(String iconURL) { - } + public void setIconUrl(String iconURL) { + } - public void setName(String name) { - } + public void setName(String name) { + } - public void setSequence(Long sequence) { - } + public void setSequence(Long sequence) { + } - public void setTranslation(String translatedName, String translatedDesc, String issueConstantPrefix, Locale locale) { - } + public void setTranslation(String translatedName, String translatedDesc, String issueConstantPrefix, Locale locale) { + } - public int compareTo(Object arg0) { - return 0; - } + public int compareTo(Object arg0) { + return 0; + } } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/Transition.java b/src/main/java/com/googlecode/jsu/transitionssummary/Transition.java index c9e646d0..58886e33 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/Transition.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/Transition.java @@ -7,69 +7,69 @@ /** * @author Gustavo Martin - * + * * This class represent a Workflow Transition. And it will keep, temporarily, all its values. * It obtains the values, reading the Change History. - * + * */ public class Transition { - private final Status removedStatus = new RemovedStatusImpl(); + private final Status removedStatus = new RemovedStatusImpl(); - private String changedBy; - private Timestamp changedAt; - private Status fromStatus; - private Status toStatus; - private Timestamp startAt; - private Long duration; - - public Transition () { - this.startAt = null; - } - - public Long getDurationInMillis(){ - return this.duration; - } - - private void setDuration(){ - Long retVal = new Long("-1"); - - // It calculates the duration since the transition began until the next one is executed. - if (this.startAt != null) { - retVal = new Long(this.changedAt.getTime() - this.startAt.getTime()); - } - - this.duration = retVal; - } - - public Timestamp getChangedAt() { - return changedAt; - } - public void setChangedAt(Timestamp changedAt) { - this.changedAt = changedAt; - } - public String getChangedBy() { - return changedBy; - } - public void setChangedBy(String changedBy) { - this.changedBy = changedBy; - } - public Status getFromStatus() { - return (fromStatus == null ? removedStatus : fromStatus); - } - public void setFromStatus(Long fromStatus) { - this.fromStatus = ManagerFactory.getConstantsManager().getStatusObject(String.valueOf(fromStatus)); - } - public Status getToStatus() { - return (toStatus == null ? removedStatus : toStatus); - } - public void setToStatus(Long toStatus) { - this.toStatus = ManagerFactory.getConstantsManager().getStatusObject(String.valueOf(toStatus)); - } - public Timestamp getStartAt() { - return startAt; - } - public void setStartAt(Timestamp startAt) { - this.startAt = startAt; - setDuration(); - } + private String changedBy; + private Timestamp changedAt; + private Status fromStatus; + private Status toStatus; + private Timestamp startAt; + private Long duration; + + public Transition () { + this.startAt = null; + } + + public Long getDurationInMillis(){ + return this.duration; + } + + private void setDuration(){ + Long retVal = new Long("-1"); + + // It calculates the duration since the transition began until the next one is executed. + if (this.startAt != null) { + retVal = new Long(this.changedAt.getTime() - this.startAt.getTime()); + } + + this.duration = retVal; + } + + public Timestamp getChangedAt() { + return changedAt; + } + public void setChangedAt(Timestamp changedAt) { + this.changedAt = changedAt; + } + public String getChangedBy() { + return changedBy; + } + public void setChangedBy(String changedBy) { + this.changedBy = changedBy; + } + public Status getFromStatus() { + return (fromStatus == null ? removedStatus : fromStatus); + } + public void setFromStatus(Long fromStatus) { + this.fromStatus = ManagerFactory.getConstantsManager().getStatusObject(String.valueOf(fromStatus)); + } + public Status getToStatus() { + return (toStatus == null ? removedStatus : toStatus); + } + public void setToStatus(Long toStatus) { + this.toStatus = ManagerFactory.getConstantsManager().getStatusObject(String.valueOf(toStatus)); + } + public Timestamp getStartAt() { + return startAt; + } + public void setStartAt(Timestamp startAt) { + this.startAt = startAt; + setDuration(); + } } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/TransitionSummary.java b/src/main/java/com/googlecode/jsu/transitionssummary/TransitionSummary.java index 986b0885..fa9f2791 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/TransitionSummary.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/TransitionSummary.java @@ -9,146 +9,146 @@ /** * @author Gustavo Martin - * + * * This class represents the summary of a set of Transitions. - * - * Allowing to obtain the total duration, how many times it happened through her, + * + * Allowing to obtain the total duration, how many times it happened through her, * and who/when it was the last update. - * + * */ public class TransitionSummary { - private String id; - private Status fromStatus; - private Status toStatus; - private Long duration; - private String lastUpdater; - private Timestamp lastUpdate; - private List transitions = new ArrayList(); - - /** - * @param id an external ID generate. - * @param fromStatus - * @param toStatus - */ - public TransitionSummary(String id, Status fromStatus, Status toStatus){ - setId(id); - setFromStatus(fromStatus); - setToStatus(toStatus); - setDuration(new Long("0")); - } - - /** - * @param tran a simple Transition. - * - * Allows to add a transition and recalculate the summary values. - */ - public void addTransition(Transition tran){ - transitions.add(tran); - - setLastUpdater(tran.getChangedBy()); - setLastupdate(tran.getChangedAt()); - - addTime(tran.getDurationInMillis()); - } - - /** - * @return a nice String format of the duration. - */ - public String getDurationAsString(){ - String retVal = ""; - Long duration = this.getDurationInMillis(); - - if(duration!=new Long("0")){ - Long days = new Long(duration.longValue() / 86400000); - Long restDay = new Long(duration.longValue() % 86400000); - - Long hours = new Long(restDay.longValue() / 3600000); - Long resthours = new Long(restDay.longValue() % 3600000); - - Long minutes = new Long(resthours.longValue() / 60000); - Long restMinutes = new Long(resthours.longValue() % 60000); - - Long seconds = new Long(restMinutes.longValue() / 1000); - - // If it has been days, it does not have sense to show the seconds. - retVal = days.equals(new Long("0"))?"":String.valueOf(days) + "d "; - retVal = retVal + (hours.equals(new Long("0"))?"":String.valueOf(hours) + "h "); - retVal = retVal + (minutes.equals(new Long("0"))?"":String.valueOf(minutes) + "m "); - if((days.equals(new Long("0"))) && (hours.equals(new Long("0")))){ - retVal = retVal + (seconds.equals(new Long("0"))?"":String.valueOf(seconds) + "s"); - } - - }else{ - retVal = "0s"; - } - - return retVal; - } - - public int getTimesToTransition(){ - return transitions.size(); - } - - private void addTime(Long timeInMillis){ - setDuration(new Long(getDurationInMillis().longValue() + timeInMillis.longValue())); - } - - public String getId() { - return id; - } - - public Status getFromStatus() { - return fromStatus; - } - - public Status getToStatus() { - return toStatus; - } - - /** - * @return a nice formatted date as String. - */ - public String getLastUpdateAsString(){ - return CommonPluginUtils.getNiceDate(lastUpdate); - } - - /** - * @return the lastUpdate - */ - public Timestamp getLastUpdate() { - return lastUpdate; - } - - public String getLastUpdater() { - return lastUpdater; - } - - private void setId(String id) { - this.id = id; - } - - public Long getDurationInMillis() { - return duration; - } - - private void setFromStatus(Status fromStatus) { - this.fromStatus = fromStatus; - } - - private void setToStatus(Status toStatus) { - this.toStatus = toStatus; - } - - private void setLastupdate(Timestamp lastupdate) { - this.lastUpdate = lastupdate; - } - - private void setLastUpdater(String lastUpdater) { - this.lastUpdater = lastUpdater; - } - - private void setDuration(Long duration) { - this.duration = duration; - } - + private String id; + private Status fromStatus; + private Status toStatus; + private Long duration; + private String lastUpdater; + private Timestamp lastUpdate; + private List transitions = new ArrayList(); + + /** + * @param id an external ID generate. + * @param fromStatus + * @param toStatus + */ + public TransitionSummary(String id, Status fromStatus, Status toStatus){ + setId(id); + setFromStatus(fromStatus); + setToStatus(toStatus); + setDuration(new Long("0")); + } + + /** + * @param tran a simple Transition. + * + * Allows to add a transition and recalculate the summary values. + */ + public void addTransition(Transition tran){ + transitions.add(tran); + + setLastUpdater(tran.getChangedBy()); + setLastupdate(tran.getChangedAt()); + + addTime(tran.getDurationInMillis()); + } + + /** + * @return a nice String format of the duration. + */ + public String getDurationAsString(){ + String retVal = ""; + Long duration = this.getDurationInMillis(); + + if(duration!=new Long("0")){ + Long days = new Long(duration.longValue() / 86400000); + Long restDay = new Long(duration.longValue() % 86400000); + + Long hours = new Long(restDay.longValue() / 3600000); + Long resthours = new Long(restDay.longValue() % 3600000); + + Long minutes = new Long(resthours.longValue() / 60000); + Long restMinutes = new Long(resthours.longValue() % 60000); + + Long seconds = new Long(restMinutes.longValue() / 1000); + + // If it has been days, it does not have sense to show the seconds. + retVal = days.equals(new Long("0"))?"":String.valueOf(days) + "d "; + retVal = retVal + (hours.equals(new Long("0"))?"":String.valueOf(hours) + "h "); + retVal = retVal + (minutes.equals(new Long("0"))?"":String.valueOf(minutes) + "m "); + if((days.equals(new Long("0"))) && (hours.equals(new Long("0")))){ + retVal = retVal + (seconds.equals(new Long("0"))?"":String.valueOf(seconds) + "s"); + } + + }else{ + retVal = "0s"; + } + + return retVal; + } + + public int getTimesToTransition(){ + return transitions.size(); + } + + private void addTime(Long timeInMillis){ + setDuration(new Long(getDurationInMillis().longValue() + timeInMillis.longValue())); + } + + public String getId() { + return id; + } + + public Status getFromStatus() { + return fromStatus; + } + + public Status getToStatus() { + return toStatus; + } + + /** + * @return a nice formatted date as String. + */ + public String getLastUpdateAsString(){ + return CommonPluginUtils.getNiceDate(lastUpdate); + } + + /** + * @return the lastUpdate + */ + public Timestamp getLastUpdate() { + return lastUpdate; + } + + public String getLastUpdater() { + return lastUpdater; + } + + private void setId(String id) { + this.id = id; + } + + public Long getDurationInMillis() { + return duration; + } + + private void setFromStatus(Status fromStatus) { + this.fromStatus = fromStatus; + } + + private void setToStatus(Status toStatus) { + this.toStatus = toStatus; + } + + private void setLastupdate(Timestamp lastupdate) { + this.lastUpdate = lastupdate; + } + + private void setLastUpdater(String lastUpdater) { + this.lastUpdater = lastUpdater; + } + + private void setDuration(Long duration) { + this.duration = duration; + } + } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/TransitionsManager.java b/src/main/java/com/googlecode/jsu/transitionssummary/TransitionsManager.java index c596e681..967f0298 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/TransitionsManager.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/TransitionsManager.java @@ -19,108 +19,108 @@ /** * @author Gustavo Martin - * + * * This class is in charge to obtain the changes from the Change History, and to summarized them. - * + * */ public class TransitionsManager { - private static final Logger log = Logger.getLogger(TransitionsManager.class); - - /** - * @param gvIssue the current issue. - * @return a List with the Transition Summaries. - * - * It obtains all Transition Summaries. - */ - public static List getTransitionSummary(Issue issue){ - Timestamp tsCreated = issue.getTimestamp("created"); - // Reads all status changes, associated with the execution of transitions. - List statusChanges = getStatusChanges(issue, tsCreated); - - if (statusChanges.isEmpty()) { - return Collections.emptyList(); - } - - Map summary = new TreeMap(); - List retList = new ArrayList(); - - for (Transition trans : statusChanges) { - // Sets an ID for the Transition. - String transitionId = trans.getFromStatus().getId().toString() + "to" + trans.getToStatus().getId().toString(); - - log.debug("Transition found [" + transitionId + "] for issue " + issue.getKey()); - - TransitionSummary tranSummary = null; - - if (summary.containsKey(transitionId)) { - tranSummary = (TransitionSummary) summary.get(transitionId); - } else { - tranSummary = new TransitionSummary(transitionId, trans.getFromStatus(), trans.getToStatus()); - - summary.put(transitionId, tranSummary); - retList.add(tranSummary); - } - - // Adds the current Transition to the corresponding TransitionSummary. - tranSummary.addTransition(trans); - } - - return retList; - } - - /** - * @param issue the current issue. - * @param tsCreated when the issue was created. It allows to calculate the duration of the first transition. - * @return a List with the Status Changes. - * - * It obtains all status changes data from the Change History. - */ - private static List getStatusChanges(Issue issue, Timestamp tsCreated){ - OfBizDelegator delegator = new DefaultOfBizDelegator(CoreFactory.getGenericDelegator()); - @SuppressWarnings("unchecked") - Map params = EasyMap.build("issue", issue.getLong("id")); - List changeGroups = delegator.findByAnd("ChangeGroup", params); - - // Added by caisd_1998 at hotmail dot com - Collections.sort(changeGroups, - new Comparator() { - public int compare(GenericValue o1, GenericValue o2) { - return o1.getTimestamp("created").compareTo(o2.getTimestamp("created")); - } - } - ); - - List retList = new ArrayList(); - Timestamp tsStartDate = new Timestamp(tsCreated.getTime()); - - for (GenericValue changeGroup : changeGroups) { - // Obtains all ChangeItems that contains an status change. - @SuppressWarnings("unchecked") - Map paramsItem = EasyMap.build( - "group", changeGroup.getLong("id"), - "field", "status", - "fieldtype", "jira" - ); - - List changeItems = delegator.findByAnd("ChangeItem", paramsItem); - - for (GenericValue changeItem : changeItems) { - // And it creates the corresponding Transition. - Transition tran = new Transition(); - - tran.setChangedBy(changeGroup.getString("author")); - tran.setChangedAt(changeGroup.getTimestamp("created")); - tran.setFromStatus(Long.valueOf(changeItem.getString("oldvalue"))); - tran.setToStatus(Long.valueOf(changeItem.getString("newvalue"))); - tran.setStartAt(tsStartDate); - - retList.add(tran); - - // It is used to calculate the duration of the next transition. - tsStartDate = new Timestamp(changeGroup.getTimestamp("created").getTime()); - } - } - - return retList; - } + private static final Logger log = Logger.getLogger(TransitionsManager.class); + + /** + * @param gvIssue the current issue. + * @return a List with the Transition Summaries. + * + * It obtains all Transition Summaries. + */ + public static List getTransitionSummary(Issue issue){ + Timestamp tsCreated = issue.getTimestamp("created"); + // Reads all status changes, associated with the execution of transitions. + List statusChanges = getStatusChanges(issue, tsCreated); + + if (statusChanges.isEmpty()) { + return Collections.emptyList(); + } + + Map summary = new TreeMap(); + List retList = new ArrayList(); + + for (Transition trans : statusChanges) { + // Sets an ID for the Transition. + String transitionId = trans.getFromStatus().getId().toString() + "to" + trans.getToStatus().getId().toString(); + + log.debug("Transition found [" + transitionId + "] for issue " + issue.getKey()); + + TransitionSummary tranSummary = null; + + if (summary.containsKey(transitionId)) { + tranSummary = (TransitionSummary) summary.get(transitionId); + } else { + tranSummary = new TransitionSummary(transitionId, trans.getFromStatus(), trans.getToStatus()); + + summary.put(transitionId, tranSummary); + retList.add(tranSummary); + } + + // Adds the current Transition to the corresponding TransitionSummary. + tranSummary.addTransition(trans); + } + + return retList; + } + + /** + * @param issue the current issue. + * @param tsCreated when the issue was created. It allows to calculate the duration of the first transition. + * @return a List with the Status Changes. + * + * It obtains all status changes data from the Change History. + */ + private static List getStatusChanges(Issue issue, Timestamp tsCreated){ + OfBizDelegator delegator = new DefaultOfBizDelegator(CoreFactory.getGenericDelegator()); + @SuppressWarnings("unchecked") + Map params = EasyMap.build("issue", issue.getLong("id")); + List changeGroups = delegator.findByAnd("ChangeGroup", params); + + // Added by caisd_1998 at hotmail dot com + Collections.sort(changeGroups, + new Comparator() { + public int compare(GenericValue o1, GenericValue o2) { + return o1.getTimestamp("created").compareTo(o2.getTimestamp("created")); + } + } + ); + + List retList = new ArrayList(); + Timestamp tsStartDate = new Timestamp(tsCreated.getTime()); + + for (GenericValue changeGroup : changeGroups) { + // Obtains all ChangeItems that contains an status change. + @SuppressWarnings("unchecked") + Map paramsItem = EasyMap.build( + "group", changeGroup.getLong("id"), + "field", "status", + "fieldtype", "jira" + ); + + List changeItems = delegator.findByAnd("ChangeItem", paramsItem); + + for (GenericValue changeItem : changeItems) { + // And it creates the corresponding Transition. + Transition tran = new Transition(); + + tran.setChangedBy(changeGroup.getString("author")); + tran.setChangedAt(changeGroup.getTimestamp("created")); + tran.setFromStatus(Long.valueOf(changeItem.getString("oldvalue"))); + tran.setToStatus(Long.valueOf(changeItem.getString("newvalue"))); + tran.setStartAt(tsStartDate); + + retList.add(tran); + + // It is used to calculate the duration of the next transition. + tsStartDate = new Timestamp(changeGroup.getTimestamp("created").getTime()); + } + } + + return retList; + } } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryAction.java b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryAction.java index 000777ad..041e0213 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryAction.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryAction.java @@ -17,64 +17,64 @@ /** * @author Gustavo Martin - * + * * This is a valid Action, that it allows to visualize the Transition Summaries. */ public class TransitionSummaryAction extends AbstractIssueAction { - protected final IssueTabPanelModuleDescriptor descriptor; - protected List tranSummaries; - protected Timestamp timePerformed; - - /** - * @param issue current issue. - * @param remoteUser current user (logged in). - * @param tranSummaries List containing TransitionSummary objects. - * @param descriptor - */ - public TransitionSummaryAction(List tranSummaries, IssueTabPanelModuleDescriptor descriptor){ - super(descriptor); - - this.tranSummaries = tranSummaries; - this.descriptor = descriptor; - this.timePerformed = new Timestamp(Calendar.getInstance().getTimeInMillis()); - } - - /** - * @return a List - * - * It allows Velocity to obtain the List of Transition Summaries. - */ - public List getTransitions() { - return tranSummaries; - } - - /* (non-Javadoc) - * @see com.atlassian.jira.issue.action.IssueAction#getTimePerformed() - */ - public Date getTimePerformed() { - return (Date) this.timePerformed; - } - - /* (non-Javadoc) - * @see com.atlassian.jira.issue.action.IssueAction#getHtml(com.atlassian.jira.web.action.JiraWebActionSupport) - */ - public String getHtml(JiraWebActionSupport webAction) { - Map params = UtilMisc.toMap("webAction", webAction, "action", this); - - return descriptor.getHtml("view", params); - } - - protected void populateVelocityParams(Map params) { - params.put("action", this); - } - - public boolean isUserExists(String username) { - try { - UserUtils.getUser(username); - } catch (EntityNotFoundException e) { - return false; - } - - return true; - } + protected final IssueTabPanelModuleDescriptor descriptor; + protected List tranSummaries; + protected Timestamp timePerformed; + + /** + * @param issue current issue. + * @param remoteUser current user (logged in). + * @param tranSummaries List containing TransitionSummary objects. + * @param descriptor + */ + public TransitionSummaryAction(List tranSummaries, IssueTabPanelModuleDescriptor descriptor){ + super(descriptor); + + this.tranSummaries = tranSummaries; + this.descriptor = descriptor; + this.timePerformed = new Timestamp(Calendar.getInstance().getTimeInMillis()); + } + + /** + * @return a List + * + * It allows Velocity to obtain the List of Transition Summaries. + */ + public List getTransitions() { + return tranSummaries; + } + + /* (non-Javadoc) + * @see com.atlassian.jira.issue.action.IssueAction#getTimePerformed() + */ + public Date getTimePerformed() { + return (Date) this.timePerformed; + } + + /* (non-Javadoc) + * @see com.atlassian.jira.issue.action.IssueAction#getHtml(com.atlassian.jira.web.action.JiraWebActionSupport) + */ + public String getHtml(JiraWebActionSupport webAction) { + Map params = UtilMisc.toMap("webAction", webAction, "action", this); + + return descriptor.getHtml("view", params); + } + + protected void populateVelocityParams(Map params) { + params.put("action", this); + } + + public boolean isUserExists(String username) { + try { + UserUtils.getUser(username); + } catch (EntityNotFoundException e) { + return false; + } + + return true; + } } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryComparator.java b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryComparator.java index 3badad96..22d2178f 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryComparator.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionSummaryComparator.java @@ -11,26 +11,26 @@ * @version $Id$ */ final class TransitionSummaryComparator implements Comparator { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(TransitionSummary summary1, TransitionSummary summary2) { - if (summary1 == summary2) { - return 0; - } + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(TransitionSummary summary1, TransitionSummary summary2) { + if (summary1 == summary2) { + return 0; + } - int result = (-1); + int result = (-1); - if ((summary1 != null) && (summary1.getLastUpdate() != null)) { - Timestamp ts = summary1.getLastUpdate(); - - if (summary2 != null) { - return ts.compareTo(summary2.getLastUpdate()); - } else { - return ts.compareTo(null); - } - } - - return result; - } + if ((summary1 != null) && (summary1.getLastUpdate() != null)) { + Timestamp ts = summary1.getLastUpdate(); + + if (summary2 != null) { + return ts.compareTo(summary2.getLastUpdate()); + } else { + return ts.compareTo(null); + } + } + + return result; + } } diff --git a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionsSummaryTabPanel.java b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionsSummaryTabPanel.java index a1031acc..66aaf0b5 100644 --- a/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionsSummaryTabPanel.java +++ b/src/main/java/com/googlecode/jsu/transitionssummary/issuetabpanel/TransitionsSummaryTabPanel.java @@ -15,48 +15,48 @@ /** * @author Gustavo Martin - * + * * It will be add a new Issue Tab Panel. - * + * */ public class TransitionsSummaryTabPanel implements IssueTabPanel { - - protected IssueTabPanelModuleDescriptor descriptor; - - /* (non-Javadoc) - * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#init(com.googlecode.jsu.issuetabpanel.IssueTabPanelModuleDescriptor) - */ - public void init(IssueTabPanelModuleDescriptor descriptor) { - this.descriptor = descriptor; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#getActions(org.ofbiz.core.entity.GenericValue, com.opensymphony.user.User) - */ - public List getActions(Issue issue, User remoteUser) { - List retList = new ArrayList(); - List transitions = TransitionsManager.getTransitionSummary(issue); - - // Allway adds only one record to the tab. This is thus, because if there are transition sumeries, - // it exposes the List with all Transition Summaries. Then, velocity will be in charge of render it properly. - if (transitions == null || transitions.isEmpty()) { - GenericMessageAction action = new GenericMessageAction("There aren't workflow transitions executed yet."); - - retList.add(action); - } else { - Collections.sort(transitions, new TransitionSummaryComparator()); - - retList.add(new TransitionSummaryAction(transitions, descriptor)); - } - - return retList; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#showPanel(org.ofbiz.core.entity.GenericValue) - */ - public boolean showPanel(Issue issue, User remoteUser) { - return true; - } - + + protected IssueTabPanelModuleDescriptor descriptor; + + /* (non-Javadoc) + * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#init(com.googlecode.jsu.issuetabpanel.IssueTabPanelModuleDescriptor) + */ + public void init(IssueTabPanelModuleDescriptor descriptor) { + this.descriptor = descriptor; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#getActions(org.ofbiz.core.entity.GenericValue, com.opensymphony.user.User) + */ + public List getActions(Issue issue, User remoteUser) { + List retList = new ArrayList(); + List transitions = TransitionsManager.getTransitionSummary(issue); + + // Allway adds only one record to the tab. This is thus, because if there are transition sumeries, + // it exposes the List with all Transition Summaries. Then, velocity will be in charge of render it properly. + if (transitions == null || transitions.isEmpty()) { + GenericMessageAction action = new GenericMessageAction("There aren't workflow transitions executed yet."); + + retList.add(action); + } else { + Collections.sort(transitions, new TransitionSummaryComparator()); + + retList.add(new TransitionSummaryAction(transitions, descriptor)); + } + + return retList; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.issuetabpanel.IssueTabPanel#showPanel(org.ofbiz.core.entity.GenericValue) + */ + public boolean showPanel(Issue issue, User remoteUser) { + return true; + } + } diff --git a/src/main/java/com/googlecode/jsu/util/CommonPluginUtils.java b/src/main/java/com/googlecode/jsu/util/CommonPluginUtils.java index e95acbe4..fbf989c1 100644 --- a/src/main/java/com/googlecode/jsu/util/CommonPluginUtils.java +++ b/src/main/java/com/googlecode/jsu/util/CommonPluginUtils.java @@ -53,392 +53,392 @@ * @author Gustavo Martin. * * This utils class exposes common methods to plugin. - * + * */ public class CommonPluginUtils { - private static final Logger log = Logger.getLogger(CommonPluginUtils.class); - - private static final Collection TIME_TRACKING_FIELDS = Arrays.asList( - IssueFieldConstants.TIME_ESTIMATE, - IssueFieldConstants.TIME_ORIGINAL_ESTIMATE, - IssueFieldConstants.TIME_SPENT, - IssueFieldConstants.TIMETRACKING - ); - - /** - * @return a complete list of fields, including custom fields. - */ - public static List getAllFields() { - final FieldManager fieldManager = ManagerFactory.getFieldManager(); - Set allFieldsSet = new TreeSet(getComparator()); - - allFieldsSet.addAll(fieldManager.getOrderableFields()); - - try { - allFieldsSet.addAll(fieldManager.getAllAvailableNavigableFields()); - } catch (FieldException e) { - log.error("Unable to load navigable fields", e); - } - - return new ArrayList(allFieldsSet); - } - - /** - * @return a list of fields, including custom fields, which could be modified. - */ - public static List getAllEditableFields(){ - final FieldManager fieldManager = ManagerFactory.getFieldManager(); - Set allFields = new TreeSet(getComparator()); - - try { - final Set fields = fieldManager.getAllAvailableNavigableFields(); - - for (Field f : fields) { - allFields.add(f); - } - } catch (FieldException e) { - log.error("Unable to load navigable fields", e); - } - - return new ArrayList(allFields); - } - - /** - * @param allFields list of fields to be sorted. - * @return a list with fields sorted by name. - */ - public static List sortFields(List allFields) { - Collections.sort(allFields, getComparator()); - - return allFields; - } - - /** - * @return a list of all fields of type date and datetime. - */ - public static List getAllDateFields() { - List allDateFields = new ArrayList(); - - List fields = ManagerFactory.getCustomFieldManager().getCustomFieldObjects(); - - for (CustomField cfDate : fields) { - CustomFieldType customFieldType = cfDate.getCustomFieldType(); - - if ((customFieldType instanceof DateCFType) || (customFieldType instanceof DateTimeCFType)){ - allDateFields.add(cfDate); - } - } - - // Obtain all fields type date from model. - ModelEntity modelIssue = CoreFactory.getGenericDelegator().getModelEntity("Issue"); - Iterator modelFields = modelIssue.getFieldsIterator(); - - while (modelFields.hasNext()) { - ModelField modelField = modelFields.next(); - - if(modelField.getType().equals("date-time")){ - Field fldDate = ManagerFactory.getFieldManager().getField(modelField.getName()); - allDateFields.add(fldDate); - } - } - - return sortFields(allDateFields); - } - - /** - * @param issue: issue to which the field belongs - * @param field wished field - * @param fieldScreen wished screen - * @return if a field is displayed in a screen. - */ - public static boolean isFieldOnScreen(Issue issue, Field field, FieldScreen fieldScreen){ - final FieldManager fieldManager = ComponentManager.getInstance().getFieldManager(); - - if (fieldManager.isCustomField(field)) { - CustomFieldType type = ((CustomField) field).getCustomFieldType(); - - if ((type instanceof ReadOnlyCFType) || - (type instanceof ImportIdLinkCFType)) { - return false; - } - } - - boolean retVal = false; - Iterator itTabs = fieldScreen.getTabs().iterator(); - - while(itTabs.hasNext() && !retVal){ - FieldScreenTab tab = itTabs.next(); - Iterator itFields = tab.getFieldScreenLayoutItems().iterator(); - - while(itFields.hasNext() && !retVal){ - FieldScreenLayoutItem fieldScreenLayoutItem = itFields.next(); - - if (field.getId().equals(fieldScreenLayoutItem.getFieldId()) && isIssueHasField(issue, field)) { - retVal = true; - } - } - } - - return retVal; - } - - /** - * Check is the issue has the field. - * - * @param issue: issue to which the field belongs - * @param field: wished field - * @return if a field is available. - */ - public static boolean isIssueHasField(Issue issue, Field field) { - final FieldManager fieldManager = ManagerFactory.getFieldManager(); - final String fieldId = field.getId(); - - boolean isHidden = false; - - if (TIME_TRACKING_FIELDS.contains(fieldId)) { - isHidden = !fieldManager.isTimeTrackingOn(); - } else { - FieldVisibilityManager fvManager = ComponentManager.getComponentInstanceOfType( - FieldVisibilityManager.class - ); - - isHidden = fvManager.isFieldHidden(field.getId(), issue); - } - - if (isHidden) { - // Looks like we found hidden field - return false; - } - - if (fieldManager.isCustomField(field)) { - CustomField customField = (CustomField) field; - FieldConfig config = customField.getRelevantConfig(issue); - - return (config != null); - } - - return true; - } - - public static FieldLayoutItem getFieldLayoutItem(Issue issue, Field field) throws FieldLayoutStorageException { - final FieldLayoutManager fieldLayoutManager = ComponentManager.getInstance().getFieldLayoutManager(); - - FieldLayout layout = fieldLayoutManager.getFieldLayout( - issue.getProjectObject().getGenericValue(), - issue.getIssueTypeObject().getId() - ); - - if (layout.getId() == null) { - layout = fieldLayoutManager.getEditableDefaultFieldLayout(); - } - - return layout.getFieldLayoutItem(field.getId()); - } - - /** - * @param issue: issue to which the field belongs - * @param field: wished field - * @return if a field is required. - */ - public static boolean isFieldRequired(Issue issue, Field field){ - boolean retVal = false; - - try { - retVal = getFieldLayoutItem(issue, field).isRequired(); - } catch (FieldLayoutStorageException e) { - log.error("Unable to check is field required", e); - } - - return retVal; - } - - /** - * @return a list of fields that could be chosen to copy their value. - */ - public static List getCopyFromFields(){ - List allFields = getAllFields(); - - allFields.removeAll(getNonCopyFromFields()); - - return allFields; - } - - /** - * @return a list of fields that will be eliminated from getCopyFromFields(). - */ - private static List getNonCopyFromFields(){ - return asFields( - ATTACHMENT, - COMMENT, - COMPONENTS, + private static final Logger log = Logger.getLogger(CommonPluginUtils.class); + + private static final Collection TIME_TRACKING_FIELDS = Arrays.asList( + IssueFieldConstants.TIME_ESTIMATE, + IssueFieldConstants.TIME_ORIGINAL_ESTIMATE, + IssueFieldConstants.TIME_SPENT, + IssueFieldConstants.TIMETRACKING + ); + + /** + * @return a complete list of fields, including custom fields. + */ + public static List getAllFields() { + final FieldManager fieldManager = ManagerFactory.getFieldManager(); + Set allFieldsSet = new TreeSet(getComparator()); + + allFieldsSet.addAll(fieldManager.getOrderableFields()); + + try { + allFieldsSet.addAll(fieldManager.getAllAvailableNavigableFields()); + } catch (FieldException e) { + log.error("Unable to load navigable fields", e); + } + + return new ArrayList(allFieldsSet); + } + + /** + * @return a list of fields, including custom fields, which could be modified. + */ + public static List getAllEditableFields(){ + final FieldManager fieldManager = ManagerFactory.getFieldManager(); + Set allFields = new TreeSet(getComparator()); + + try { + final Set fields = fieldManager.getAllAvailableNavigableFields(); + + for (Field f : fields) { + allFields.add(f); + } + } catch (FieldException e) { + log.error("Unable to load navigable fields", e); + } + + return new ArrayList(allFields); + } + + /** + * @param allFields list of fields to be sorted. + * @return a list with fields sorted by name. + */ + public static List sortFields(List allFields) { + Collections.sort(allFields, getComparator()); + + return allFields; + } + + /** + * @return a list of all fields of type date and datetime. + */ + public static List getAllDateFields() { + List allDateFields = new ArrayList(); + + List fields = ManagerFactory.getCustomFieldManager().getCustomFieldObjects(); + + for (CustomField cfDate : fields) { + CustomFieldType customFieldType = cfDate.getCustomFieldType(); + + if ((customFieldType instanceof DateCFType) || (customFieldType instanceof DateTimeCFType)){ + allDateFields.add(cfDate); + } + } + + // Obtain all fields type date from model. + ModelEntity modelIssue = CoreFactory.getGenericDelegator().getModelEntity("Issue"); + Iterator modelFields = modelIssue.getFieldsIterator(); + + while (modelFields.hasNext()) { + ModelField modelField = modelFields.next(); + + if(modelField.getType().equals("date-time")){ + Field fldDate = ManagerFactory.getFieldManager().getField(modelField.getName()); + allDateFields.add(fldDate); + } + } + + return sortFields(allDateFields); + } + + /** + * @param issue: issue to which the field belongs + * @param field wished field + * @param fieldScreen wished screen + * @return if a field is displayed in a screen. + */ + public static boolean isFieldOnScreen(Issue issue, Field field, FieldScreen fieldScreen){ + final FieldManager fieldManager = ComponentManager.getInstance().getFieldManager(); + + if (fieldManager.isCustomField(field)) { + CustomFieldType type = ((CustomField) field).getCustomFieldType(); + + if ((type instanceof ReadOnlyCFType) || + (type instanceof ImportIdLinkCFType)) { + return false; + } + } + + boolean retVal = false; + Iterator itTabs = fieldScreen.getTabs().iterator(); + + while(itTabs.hasNext() && !retVal){ + FieldScreenTab tab = itTabs.next(); + Iterator itFields = tab.getFieldScreenLayoutItems().iterator(); + + while(itFields.hasNext() && !retVal){ + FieldScreenLayoutItem fieldScreenLayoutItem = itFields.next(); + + if (field.getId().equals(fieldScreenLayoutItem.getFieldId()) && isIssueHasField(issue, field)) { + retVal = true; + } + } + } + + return retVal; + } + + /** + * Check is the issue has the field. + * + * @param issue: issue to which the field belongs + * @param field: wished field + * @return if a field is available. + */ + public static boolean isIssueHasField(Issue issue, Field field) { + final FieldManager fieldManager = ManagerFactory.getFieldManager(); + final String fieldId = field.getId(); + + boolean isHidden = false; + + if (TIME_TRACKING_FIELDS.contains(fieldId)) { + isHidden = !fieldManager.isTimeTrackingOn(); + } else { + FieldVisibilityManager fvManager = ComponentManager.getComponentInstanceOfType( + FieldVisibilityManager.class + ); + + isHidden = fvManager.isFieldHidden(field.getId(), issue); + } + + if (isHidden) { + // Looks like we found hidden field + return false; + } + + if (fieldManager.isCustomField(field)) { + CustomField customField = (CustomField) field; + FieldConfig config = customField.getRelevantConfig(issue); + + return (config != null); + } + + return true; + } + + public static FieldLayoutItem getFieldLayoutItem(Issue issue, Field field) throws FieldLayoutStorageException { + final FieldLayoutManager fieldLayoutManager = ComponentManager.getInstance().getFieldLayoutManager(); + + FieldLayout layout = fieldLayoutManager.getFieldLayout( + issue.getProjectObject().getGenericValue(), + issue.getIssueTypeObject().getId() + ); + + if (layout.getId() == null) { + layout = fieldLayoutManager.getEditableDefaultFieldLayout(); + } + + return layout.getFieldLayoutItem(field.getId()); + } + + /** + * @param issue: issue to which the field belongs + * @param field: wished field + * @return if a field is required. + */ + public static boolean isFieldRequired(Issue issue, Field field){ + boolean retVal = false; + + try { + retVal = getFieldLayoutItem(issue, field).isRequired(); + } catch (FieldLayoutStorageException e) { + log.error("Unable to check is field required", e); + } + + return retVal; + } + + /** + * @return a list of fields that could be chosen to copy their value. + */ + public static List getCopyFromFields(){ + List allFields = getAllFields(); + + allFields.removeAll(getNonCopyFromFields()); + + return allFields; + } + + /** + * @return a list of fields that will be eliminated from getCopyFromFields(). + */ + private static List getNonCopyFromFields(){ + return asFields( + ATTACHMENT, + COMMENT, + COMPONENTS, // For issue #65 // IssueFieldConstants.FIX_FOR_VERSIONS, // IssueFieldConstants.AFFECTED_VERSIONS, - ISSUE_LINKS, - SECURITY, - SUBTASKS, - THUMBNAIL, - TIMETRACKING - ); - } - - /** - * @return a list of fields that could be chosen to copy their value. - */ - public static List getCopyToFields(){ - List allFields = getAllEditableFields(); - allFields.removeAll(getNonCopyToFields()); - - return allFields; - } - - /** - * @return a list of fields that will be eliminated from getCopyFromFields(). - */ - private static List getNonCopyToFields(){ - return asFields( - ATTACHMENT, - COMMENT, - COMPONENTS, - CREATED, - TIMETRACKING, - TIME_ORIGINAL_ESTIMATE, - TIME_ESTIMATE, - TIME_SPENT, - AGGREGATE_TIME_ORIGINAL_ESTIMATE, - AGGREGATE_TIME_ESTIMATE, - AGGREGATE_PROGRESS, - ISSUE_KEY, - ISSUE_LINKS, - ISSUE_TYPE, - PRIORITY, - PROJECT, - SECURITY, - STATUS, - SUBTASKS, - THUMBNAIL, - UPDATED, - VOTES, - WORKRATIO - ); - } - - /** - * @return a list of fields that could be chosen like required. - */ - public static List getRequirableFields(){ - List allFields = getAllFields(); - - allFields.removeAll(getNonRequirableFields()); - - return allFields; - } - - /** - * @return a list of fields that will be eliminated from getRequirableFields(). - */ - private static List getNonRequirableFields(){ - return asFields( - CREATED, - TIMETRACKING, - TIME_ORIGINAL_ESTIMATE, - PROGRESS, - AGGREGATE_TIME_ORIGINAL_ESTIMATE, - AGGREGATE_PROGRESS, - ISSUE_KEY, - ISSUE_LINKS, - ISSUE_TYPE, - PROJECT, - STATUS, - SUBTASKS, - THUMBNAIL, - UPDATED, - VOTES, - WORKRATIO, - SECURITY - ); - } - - /** - * @return a list of fields that could be chosen in Value-Field Condition. - */ - public static List getValueFieldConditionFields(){ - List allFields = getAllFields(); - - allFields.removeAll(getNonValueFieldConditionFields()); - // Date fields are removed, because date comparison is not implemented yet. - allFields.removeAll(getAllDateFields()); - - return allFields; - } - - /** - * @return a list of fields that will be eliminated from getValueFieldConditionFields(). - */ - private static List getNonValueFieldConditionFields(){ - return asFields( - ATTACHMENT, - COMMENT, - CREATED, - ISSUE_KEY, - ISSUE_LINKS, - SUBTASKS, - THUMBNAIL, - TIMETRACKING, - UPDATED, - WORKRATIO - ); - } - - /** - * @param cal - * - * Clear the time part from a given Calendar. - * - */ - public static void clearCalendarTimePart(Calendar cal) { - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - } - - /** - * @param tsDate - * @return a String. - * - * It formats to a date nice. - */ - public static String getNiceDate(Timestamp tsDate){ - Date timePerformed = new Date(tsDate.getTime()); - I18nHelper i18n = new I18nBean(); - return ManagerFactory.getOutlookDateManager().getOutlookDate(i18n.getLocale()).formatDMYHMS(timePerformed); - } - - /** - * Get comparator for sorting fields. - * @return - */ - private static Comparator getComparator() { - ApplicationProperties ap = new ApplicationPropertiesImpl(); - I18nBean i18n = new I18nBean(ap.getDefaultLocale().getDisplayName()); - - return new NameComparatorEx(i18n); - } - - /** - * Convert array of names into list of fields - * @param names - * @return - */ - private static List asFields(String ... names) { - final FieldManager fieldManager = ManagerFactory.getFieldManager(); - List result = new ArrayList(names.length); - - for (String name : names) { - result.add(fieldManager.getField(name)); - } - - return result; - } -} \ No newline at end of file + ISSUE_LINKS, + SECURITY, + SUBTASKS, + THUMBNAIL, + TIMETRACKING + ); + } + + /** + * @return a list of fields that could be chosen to copy their value. + */ + public static List getCopyToFields(){ + List allFields = getAllEditableFields(); + allFields.removeAll(getNonCopyToFields()); + + return allFields; + } + + /** + * @return a list of fields that will be eliminated from getCopyFromFields(). + */ + private static List getNonCopyToFields(){ + return asFields( + ATTACHMENT, + COMMENT, + COMPONENTS, + CREATED, + TIMETRACKING, + TIME_ORIGINAL_ESTIMATE, + TIME_ESTIMATE, + TIME_SPENT, + AGGREGATE_TIME_ORIGINAL_ESTIMATE, + AGGREGATE_TIME_ESTIMATE, + AGGREGATE_PROGRESS, + ISSUE_KEY, + ISSUE_LINKS, + ISSUE_TYPE, + PRIORITY, + PROJECT, + SECURITY, + STATUS, + SUBTASKS, + THUMBNAIL, + UPDATED, + VOTES, + WORKRATIO + ); + } + + /** + * @return a list of fields that could be chosen like required. + */ + public static List getRequirableFields(){ + List allFields = getAllFields(); + + allFields.removeAll(getNonRequirableFields()); + + return allFields; + } + + /** + * @return a list of fields that will be eliminated from getRequirableFields(). + */ + private static List getNonRequirableFields(){ + return asFields( + CREATED, + TIMETRACKING, + TIME_ORIGINAL_ESTIMATE, + PROGRESS, + AGGREGATE_TIME_ORIGINAL_ESTIMATE, + AGGREGATE_PROGRESS, + ISSUE_KEY, + ISSUE_LINKS, + ISSUE_TYPE, + PROJECT, + STATUS, + SUBTASKS, + THUMBNAIL, + UPDATED, + VOTES, + WORKRATIO, + SECURITY + ); + } + + /** + * @return a list of fields that could be chosen in Value-Field Condition. + */ + public static List getValueFieldConditionFields(){ + List allFields = getAllFields(); + + allFields.removeAll(getNonValueFieldConditionFields()); + // Date fields are removed, because date comparison is not implemented yet. + allFields.removeAll(getAllDateFields()); + + return allFields; + } + + /** + * @return a list of fields that will be eliminated from getValueFieldConditionFields(). + */ + private static List getNonValueFieldConditionFields(){ + return asFields( + ATTACHMENT, + COMMENT, + CREATED, + ISSUE_KEY, + ISSUE_LINKS, + SUBTASKS, + THUMBNAIL, + TIMETRACKING, + UPDATED, + WORKRATIO + ); + } + + /** + * @param cal + * + * Clear the time part from a given Calendar. + * + */ + public static void clearCalendarTimePart(Calendar cal) { + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + } + + /** + * @param tsDate + * @return a String. + * + * It formats to a date nice. + */ + public static String getNiceDate(Timestamp tsDate){ + Date timePerformed = new Date(tsDate.getTime()); + I18nHelper i18n = new I18nBean(); + return ManagerFactory.getOutlookDateManager().getOutlookDate(i18n.getLocale()).formatDMYHMS(timePerformed); + } + + /** + * Get comparator for sorting fields. + * @return + */ + private static Comparator getComparator() { + ApplicationProperties ap = new ApplicationPropertiesImpl(); + I18nBean i18n = new I18nBean(ap.getDefaultLocale().getDisplayName()); + + return new NameComparatorEx(i18n); + } + + /** + * Convert array of names into list of fields + * @param names + * @return + */ + private static List asFields(String ... names) { + final FieldManager fieldManager = ManagerFactory.getFieldManager(); + List result = new ArrayList(names.length); + + for (String name : names) { + result.add(fieldManager.getField(name)); + } + + return result; + } +} diff --git a/src/main/java/com/googlecode/jsu/util/ComponentUtils.java b/src/main/java/com/googlecode/jsu/util/ComponentUtils.java index db11adba..4cdba098 100644 --- a/src/main/java/com/googlecode/jsu/util/ComponentUtils.java +++ b/src/main/java/com/googlecode/jsu/util/ComponentUtils.java @@ -6,30 +6,30 @@ /** * Utils class for loading components. That's dirty hack for new 2nd plugins version. - * + * * @author Alexey Abashev * @version $Id$ */ public final class ComponentUtils { - /** - * Get components from different containers. - * - * @param - * @param clazz - * @return - */ - public static T getComponent(Class clazz) { - notNull("class", clazz); - - T component = getComponentInstanceOfType(clazz); - - if (component == null) { - // Didn't find in pico container - component = getOSGiComponentInstanceOfType(clazz); - } + /** + * Get components from different containers. + * + * @param + * @param clazz + * @return + */ + public static T getComponent(Class clazz) { + notNull("class", clazz); - notNull(clazz.getSimpleName(), component); - - return component; - } + T component = getComponentInstanceOfType(clazz); + + if (component == null) { + // Didn't find in pico container + component = getOSGiComponentInstanceOfType(clazz); + } + + notNull(clazz.getSimpleName(), component); + + return component; + } } diff --git a/src/main/java/com/googlecode/jsu/util/ValidatorErrorsBuilder.java b/src/main/java/com/googlecode/jsu/util/ValidatorErrorsBuilder.java index 369caa3c..90b20163 100644 --- a/src/main/java/com/googlecode/jsu/util/ValidatorErrorsBuilder.java +++ b/src/main/java/com/googlecode/jsu/util/ValidatorErrorsBuilder.java @@ -9,58 +9,58 @@ /** * Container for storing and processing validator errors. - * + * * @author Alexey Abashev */ public class ValidatorErrorsBuilder { - private List fields = new ArrayList(); - private List messages = new ArrayList(); - private boolean forScreen; - - /** - * @param forScreen is we throwing exception for screen - */ - public ValidatorErrorsBuilder(boolean forScreen) { - this.forScreen = forScreen; - } + private List fields = new ArrayList(); + private List messages = new ArrayList(); + private boolean forScreen; - public void addError(Field field, String message) { - this.fields.add(field); - this.messages.add(message); - } + /** + * @param forScreen is we throwing exception for screen + */ + public ValidatorErrorsBuilder(boolean forScreen) { + this.forScreen = forScreen; + } - public void addError(String message) { - this.addError(null, message); - } + public void addError(Field field, String message) { + this.fields.add(field); + this.messages.add(message); + } - public void process() throws WorkflowException, InvalidInputException { - if (this.fields.size() == 0) { - return; - } - - if (forScreen) { - InvalidInputException e = new InvalidInputException(); - - for (int i = 0; i < fields.size(); i++) { - Field f = this.fields.get(i); - String m = this.messages.get(i); - - if (f == null) { - e.addError(m); - } else { - e.addError(f.getId(), m); - } - } - - throw e; - } else { - StringBuilder sb = new StringBuilder(); - - for (String message : this.messages) { - sb.append(message).append(" "); - } - - throw new WorkflowException(sb.toString()); - } - } + public void addError(String message) { + this.addError(null, message); + } + + public void process() throws WorkflowException, InvalidInputException { + if (this.fields.size() == 0) { + return; + } + + if (forScreen) { + InvalidInputException e = new InvalidInputException(); + + for (int i = 0; i < fields.size(); i++) { + Field f = this.fields.get(i); + String m = this.messages.get(i); + + if (f == null) { + e.addError(m); + } else { + e.addError(f.getId(), m); + } + } + + throw e; + } else { + StringBuilder sb = new StringBuilder(); + + for (String message : this.messages) { + sb.append(message).append(" "); + } + + throw new WorkflowException(sb.toString()); + } + } } diff --git a/src/main/java/com/googlecode/jsu/util/WorkflowFactoryUtils.java b/src/main/java/com/googlecode/jsu/util/WorkflowFactoryUtils.java index 53102ac6..a4992a06 100644 --- a/src/main/java/com/googlecode/jsu/util/WorkflowFactoryUtils.java +++ b/src/main/java/com/googlecode/jsu/util/WorkflowFactoryUtils.java @@ -10,15 +10,15 @@ * @author Alexey Abashev */ public class WorkflowFactoryUtils { - @SuppressWarnings("unchecked") - public static Field getFieldByName(AbstractDescriptor descriptor, String name) { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; - Map args = functionDescriptor.getArgs(); - String fieldKey = (String) args.get(name); + @SuppressWarnings("unchecked") + public static Field getFieldByName(AbstractDescriptor descriptor, String name) { + FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; + Map args = functionDescriptor.getArgs(); + String fieldKey = (String) args.get(name); - return (Field) WorkflowUtils.getFieldFromKey(fieldKey); - } - - private WorkflowFactoryUtils() { - } + return (Field) WorkflowUtils.getFieldFromKey(fieldKey); + } + + private WorkflowFactoryUtils() { + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowClearFieldValueFunctionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowClearFieldValueFunctionPluginFactory.java index 3955bf99..e892b02d 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowClearFieldValueFunctionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowClearFieldValueFunctionPluginFactory.java @@ -16,57 +16,57 @@ /** * @author Alexey Abashev */ -public class WorkflowClearFieldValueFunctionPluginFactory - extends AbstractWorkflowPluginFactory - implements WorkflowPluginFunctionFactory { +public class WorkflowClearFieldValueFunctionPluginFactory + extends AbstractWorkflowPluginFactory + implements WorkflowPluginFunctionFactory { - public static final String FIELD = "field"; - public static final String SELECTED_FIELD = "selectedField"; - public static final String FIELD_LIST = "fieldList"; - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - @SuppressWarnings("unchecked") - protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { - this.getVelocityParamsForInput(velocityParams); - - velocityParams.put(SELECTED_FIELD, getFieldByName(descriptor, FIELD)); - } + public static final String FIELD = "field"; + public static final String SELECTED_FIELD = "selectedField"; + public static final String FIELD_LIST = "fieldList"; - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - @SuppressWarnings("unchecked") - protected void getVelocityParamsForInput(Map velocityParams) { - List fields = CommonPluginUtils.getAllEditableFields(); - - velocityParams.put(FIELD_LIST, Collections.unmodifiableList(fields)); - } + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + @SuppressWarnings("unchecked") + protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { + this.getVelocityParamsForInput(velocityParams); - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - @SuppressWarnings("unchecked") - protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { - velocityParams.put(SELECTED_FIELD, getFieldByName(descriptor, FIELD)); - } + velocityParams.put(SELECTED_FIELD, getFieldByName(descriptor, FIELD)); + } - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - @SuppressWarnings("unchecked") - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - try{ - String sourceField = extractSingleParam(conditionParams, FIELD); - - params.put(FIELD, sourceField); - } catch(IllegalArgumentException e) { - // Aggregate so that Transitions can be added. - } - - return params; - } + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + @SuppressWarnings("unchecked") + protected void getVelocityParamsForInput(Map velocityParams) { + List fields = CommonPluginUtils.getAllEditableFields(); + + velocityParams.put(FIELD_LIST, Collections.unmodifiableList(fields)); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + @SuppressWarnings("unchecked") + protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { + velocityParams.put(SELECTED_FIELD, getFieldByName(descriptor, FIELD)); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + @SuppressWarnings("unchecked") + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + try{ + String sourceField = extractSingleParam(conditionParams, FIELD); + + params.put(FIELD, sourceField); + } catch(IllegalArgumentException e) { + // Aggregate so that Transitions can be added. + } + + return params; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory.java index 3b03e7bd..2c4559a8 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory.java @@ -15,61 +15,61 @@ /** * This class defines the parameters available for Copy Value From Other Field Post Function. - * + * * @author Gustavo Martin. */ public class WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory { - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - List sourceFields = CommonPluginUtils.getCopyFromFields(); - List destinationFields = CommonPluginUtils.getCopyToFields(); - - velocityParams.put("val-sourceFieldsList", Collections.unmodifiableList(sourceFields)); - velocityParams.put("val-destinationFieldsList", Collections.unmodifiableList(destinationFields)); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { - getVelocityParamsForInput(velocityParams); - - Field sourceFieldId = getFieldByName(descriptor, "sourceField"); - Field destinationField = getFieldByName(descriptor, "destinationField"); - - velocityParams.put("val-sourceFieldSelected", sourceFieldId); - velocityParams.put("val-destinationFieldSelected", destinationField); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { - Field sourceFieldId = getFieldByName(descriptor, "sourceField"); - Field destinationField = getFieldByName(descriptor, "destinationField"); - - velocityParams.put("val-sourceFieldSelected", sourceFieldId); - velocityParams.put("val-destinationFieldSelected", destinationField); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - try{ - String sourceField = extractSingleParam(conditionParams, "sourceFieldsList"); - String destinationField = extractSingleParam(conditionParams, "destinationFieldsList"); - - params.put("sourceField", sourceField); - params.put("destinationField", destinationField); - } catch (IllegalArgumentException iae) { - // Aggregate so that Transitions can be added. - } - - return params; - } + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + List sourceFields = CommonPluginUtils.getCopyFromFields(); + List destinationFields = CommonPluginUtils.getCopyToFields(); + + velocityParams.put("val-sourceFieldsList", Collections.unmodifiableList(sourceFields)); + velocityParams.put("val-destinationFieldsList", Collections.unmodifiableList(destinationFields)); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { + getVelocityParamsForInput(velocityParams); + + Field sourceFieldId = getFieldByName(descriptor, "sourceField"); + Field destinationField = getFieldByName(descriptor, "destinationField"); + + velocityParams.put("val-sourceFieldSelected", sourceFieldId); + velocityParams.put("val-destinationFieldSelected", destinationField); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { + Field sourceFieldId = getFieldByName(descriptor, "sourceField"); + Field destinationField = getFieldByName(descriptor, "destinationField"); + + velocityParams.put("val-sourceFieldSelected", sourceFieldId); + velocityParams.put("val-destinationFieldSelected", destinationField); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + try{ + String sourceField = extractSingleParam(conditionParams, "sourceFieldsList"); + String destinationField = extractSingleParam(conditionParams, "destinationFieldsList"); + + params.put("sourceField", sourceField); + params.put("destinationField", destinationField); + } catch (IllegalArgumentException iae) { + // Aggregate so that Transitions can be added. + } + + return params; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowDateCompareValidatorPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowDateCompareValidatorPluginFactory.java index 04b99dd7..ae560628 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowDateCompareValidatorPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowDateCompareValidatorPluginFactory.java @@ -21,106 +21,106 @@ /** * @author Gustavo Martin. - * + * * This class defines the parameters available for Date Compare Validator. - * + * */ public class WorkflowDateCompareValidatorPluginFactory extends - AbstractWorkflowPluginFactory implements WorkflowPluginValidatorFactory { - - private final ConditionCheckerFactory conditionCheckerFactory; - - /** - * @param conditionCheckerFactory - */ - public WorkflowDateCompareValidatorPluginFactory(ConditionCheckerFactory conditionCheckerFactory) { - this.conditionCheckerFactory = conditionCheckerFactory; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - List allDateFields = CommonPluginUtils.getAllDateFields(); - List conditionList = conditionCheckerFactory.getConditionTypes(); - - velocityParams.put("val-date1FieldsList", allDateFields); - velocityParams.put("val-date2FieldsList", allDateFields); - velocityParams.put("val-conditionList", conditionList); - velocityParams.put("val-includeTime", asList(YES, NO)); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit(Map velocityParams, - AbstractDescriptor descriptor) { - getVelocityParamsForInput(velocityParams); - - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - String date1 = (String) args.get("date1Selected"); - String date2 = (String) args.get("date2Selected"); - String conditionId = (String) args.get("conditionSelected"); - String includeTime = (String) args.get("includeTimeSelected"); - - ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); - YesNoType ynTime = (Integer.parseInt(includeTime) == 1) ? YES : NO; - - velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); - velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); - velocityParams.put("val-conditionSelected", condition); - velocityParams.put("val-includeTimeSelected", ynTime); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView(Map velocityParams, - AbstractDescriptor descriptor) { - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - String date1 = (String) args.get("date1Selected"); - String date2 = (String) args.get("date2Selected"); - String conditionId = (String) args.get("conditionSelected"); - String includeTime = (String) args.get("includeTimeSelected"); - - ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); - YesNoType ynTime = (Integer.parseInt(includeTime) == 1) ? YES : NO; - - velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); - velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); - velocityParams.put("val-conditionSelected", condition); - velocityParams.put("val-includeTimeSelected", ynTime); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map validatorParams) { - Map params = new HashMap(); - - try{ - String date1 = extractSingleParam(validatorParams, "date1FieldsList"); - String date2 = extractSingleParam(validatorParams, "date2FieldsList"); - String condition = extractSingleParam(validatorParams, "conditionList"); - String includeTime = extractSingleParam(validatorParams, "includeTimeList"); - - params.put("date1Selected", date1); - params.put("date2Selected", date2); - params.put("conditionSelected", condition); - params.put("includeTimeSelected", includeTime); - - }catch(IllegalArgumentException iae){ - // Aggregate so that Transitions can be added. - } - - return params; - } - + AbstractWorkflowPluginFactory implements WorkflowPluginValidatorFactory { + + private final ConditionCheckerFactory conditionCheckerFactory; + + /** + * @param conditionCheckerFactory + */ + public WorkflowDateCompareValidatorPluginFactory(ConditionCheckerFactory conditionCheckerFactory) { + this.conditionCheckerFactory = conditionCheckerFactory; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + List allDateFields = CommonPluginUtils.getAllDateFields(); + List conditionList = conditionCheckerFactory.getConditionTypes(); + + velocityParams.put("val-date1FieldsList", allDateFields); + velocityParams.put("val-date2FieldsList", allDateFields); + velocityParams.put("val-conditionList", conditionList); + velocityParams.put("val-includeTime", asList(YES, NO)); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit(Map velocityParams, + AbstractDescriptor descriptor) { + getVelocityParamsForInput(velocityParams); + + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + String date1 = (String) args.get("date1Selected"); + String date2 = (String) args.get("date2Selected"); + String conditionId = (String) args.get("conditionSelected"); + String includeTime = (String) args.get("includeTimeSelected"); + + ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); + YesNoType ynTime = (Integer.parseInt(includeTime) == 1) ? YES : NO; + + velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); + velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); + velocityParams.put("val-conditionSelected", condition); + velocityParams.put("val-includeTimeSelected", ynTime); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView(Map velocityParams, + AbstractDescriptor descriptor) { + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + String date1 = (String) args.get("date1Selected"); + String date2 = (String) args.get("date2Selected"); + String conditionId = (String) args.get("conditionSelected"); + String includeTime = (String) args.get("includeTimeSelected"); + + ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); + YesNoType ynTime = (Integer.parseInt(includeTime) == 1) ? YES : NO; + + velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); + velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); + velocityParams.put("val-conditionSelected", condition); + velocityParams.put("val-includeTimeSelected", ynTime); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map validatorParams) { + Map params = new HashMap(); + + try{ + String date1 = extractSingleParam(validatorParams, "date1FieldsList"); + String date2 = extractSingleParam(validatorParams, "date2FieldsList"); + String condition = extractSingleParam(validatorParams, "conditionList"); + String includeTime = extractSingleParam(validatorParams, "includeTimeList"); + + params.put("date1Selected", date1); + params.put("date2Selected", date2); + params.put("conditionSelected", condition); + params.put("includeTimeSelected", includeTime); + + }catch(IllegalArgumentException iae){ + // Aggregate so that Transitions can be added. + } + + return params; + } + } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowFieldsRequiredValidatorPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowFieldsRequiredValidatorPluginFactory.java index 3ff43939..b8097c14 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowFieldsRequiredValidatorPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowFieldsRequiredValidatorPluginFactory.java @@ -15,85 +15,85 @@ /** * This class defines the parameters available for Fields Required Validator. - * + * * @author Gustavo Martin. */ -public class WorkflowFieldsRequiredValidatorPluginFactory - extends AbstractWorkflowPluginFactory - implements WorkflowPluginValidatorFactory { - - public static final String SELECTED_FIELDS = "hidFieldsList"; - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - List allFields = CommonPluginUtils.getRequirableFields(); - - velocityParams.put("val-fieldsList", allFields); - velocityParams.put("val-splitter", WorkflowUtils.SPLITTER); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit( - Map velocityParams, AbstractDescriptor descriptor - ) { - getVelocityParamsForInput(velocityParams); - - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - velocityParams.remove("val-fieldsList"); - - Collection fieldsSelected = getSelectedFields(args); - List allFields = CommonPluginUtils.getRequirableFields(); - - allFields.removeAll(fieldsSelected); - - velocityParams.put("val-fieldsListSelected", fieldsSelected); - velocityParams.put("val-hidFieldsList", WorkflowUtils.getStringField(fieldsSelected, WorkflowUtils.SPLITTER)); - velocityParams.put("val-fieldsList", allFields); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView( - Map velocityParams, AbstractDescriptor descriptor - ) { - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - velocityParams.put("val-fieldsListSelected", getSelectedFields(args)); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map validatorParams) { - Map params = new HashMap(); - String strFieldsSelected = extractSingleParam(validatorParams, SELECTED_FIELDS); - - if ("".equals(strFieldsSelected)) { - throw new IllegalArgumentException("At least one field must be selected"); - } - - params.put(SELECTED_FIELDS, strFieldsSelected); - - return params; - } - - /** - * Get fields were selected in UI. - * - * @param args - * @return - */ - public static Collection getSelectedFields(Map args) { - String strFieldsSelected = (String) args.get(SELECTED_FIELDS); - - return WorkflowUtils.getFields(strFieldsSelected, WorkflowUtils.SPLITTER); - } +public class WorkflowFieldsRequiredValidatorPluginFactory + extends AbstractWorkflowPluginFactory + implements WorkflowPluginValidatorFactory { + + public static final String SELECTED_FIELDS = "hidFieldsList"; + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + List allFields = CommonPluginUtils.getRequirableFields(); + + velocityParams.put("val-fieldsList", allFields); + velocityParams.put("val-splitter", WorkflowUtils.SPLITTER); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit( + Map velocityParams, AbstractDescriptor descriptor + ) { + getVelocityParamsForInput(velocityParams); + + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + velocityParams.remove("val-fieldsList"); + + Collection fieldsSelected = getSelectedFields(args); + List allFields = CommonPluginUtils.getRequirableFields(); + + allFields.removeAll(fieldsSelected); + + velocityParams.put("val-fieldsListSelected", fieldsSelected); + velocityParams.put("val-hidFieldsList", WorkflowUtils.getStringField(fieldsSelected, WorkflowUtils.SPLITTER)); + velocityParams.put("val-fieldsList", allFields); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView( + Map velocityParams, AbstractDescriptor descriptor + ) { + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + velocityParams.put("val-fieldsListSelected", getSelectedFields(args)); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map validatorParams) { + Map params = new HashMap(); + String strFieldsSelected = extractSingleParam(validatorParams, SELECTED_FIELDS); + + if ("".equals(strFieldsSelected)) { + throw new IllegalArgumentException("At least one field must be selected"); + } + + params.put(SELECTED_FIELDS, strFieldsSelected); + + return params; + } + + /** + * Get fields were selected in UI. + * + * @param args + * @return + */ + public static Collection getSelectedFields(Map args) { + String strFieldsSelected = (String) args.get(SELECTED_FIELDS); + + return WorkflowUtils.getFields(strFieldsSelected, WorkflowUtils.SPLITTER); + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowUpdateIssueCustomFieldFunctionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowUpdateIssueCustomFieldFunctionPluginFactory.java index 96587eec..18a1d1a5 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowUpdateIssueCustomFieldFunctionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowUpdateIssueCustomFieldFunctionPluginFactory.java @@ -14,80 +14,80 @@ /** * Class responsible for setting up all that is necessary for the execution of * the plugin. - * + * * @author Cristiane Fontana * @version 1.0 Plugin creation. */ public class WorkflowUpdateIssueCustomFieldFunctionPluginFactory extends - AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory { - - public static final String PARAM_FIELD_ID = "fieldId"; - public static final String PARAM_FIELD_VALUE = "fieldValue"; - public static final String TARGET_FIELD_NAME = "field.name"; - public static final String TARGET_FIELD_VALUE = "field.value"; - - private final CustomFieldManager customFieldManager; - - public WorkflowUpdateIssueCustomFieldFunctionPluginFactory(CustomFieldManager customFieldManager) { - this.customFieldManager = customFieldManager; - } - - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - String fieldId = extractSingleParam(conditionParams, PARAM_FIELD_ID); - params.put(TARGET_FIELD_NAME, fieldId); - - String fieldValue = extractSingleParam(conditionParams, PARAM_FIELD_VALUE); - params.put(TARGET_FIELD_VALUE, fieldValue.trim()); - - return params; - } - - protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { - getVelocityParamsForInput(velocityParams); - - if (!(descriptor instanceof FunctionDescriptor)) { - throw new IllegalArgumentException("Descriptor must be a FunctionDescriptor."); - } - - FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; - - velocityParams.put(PARAM_FIELD_ID, functionDescriptor.getArgs().get(TARGET_FIELD_NAME)); - - String value = (String) functionDescriptor.getArgs().get(TARGET_FIELD_VALUE); - - if (value == null || value.equals("null")) { - velocityParams.put(PARAM_FIELD_VALUE, null); - } else { - velocityParams.put(PARAM_FIELD_VALUE, value.trim()); - } - } - - protected void getVelocityParamsForInput(Map velocityParams) { - List customFields = customFieldManager.getCustomFieldObjects(); - - velocityParams.put("fields", customFields); - } - - protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { - if (!(descriptor instanceof FunctionDescriptor)) { - throw new IllegalArgumentException("Descriptor must be a FunctionDescriptor."); - } else { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; - - String fieldName = (String) functionDescriptor.getArgs().get("field.name"); - - velocityParams.put( - PARAM_FIELD_ID, - customFieldManager.getCustomFieldObject(fieldName).getNameKey() - ); - velocityParams.put( - PARAM_FIELD_VALUE, - functionDescriptor.getArgs().get(TARGET_FIELD_VALUE) - ); - - return; - } - } + AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory { + + public static final String PARAM_FIELD_ID = "fieldId"; + public static final String PARAM_FIELD_VALUE = "fieldValue"; + public static final String TARGET_FIELD_NAME = "field.name"; + public static final String TARGET_FIELD_VALUE = "field.value"; + + private final CustomFieldManager customFieldManager; + + public WorkflowUpdateIssueCustomFieldFunctionPluginFactory(CustomFieldManager customFieldManager) { + this.customFieldManager = customFieldManager; + } + + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + String fieldId = extractSingleParam(conditionParams, PARAM_FIELD_ID); + params.put(TARGET_FIELD_NAME, fieldId); + + String fieldValue = extractSingleParam(conditionParams, PARAM_FIELD_VALUE); + params.put(TARGET_FIELD_VALUE, fieldValue.trim()); + + return params; + } + + protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { + getVelocityParamsForInput(velocityParams); + + if (!(descriptor instanceof FunctionDescriptor)) { + throw new IllegalArgumentException("Descriptor must be a FunctionDescriptor."); + } + + FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; + + velocityParams.put(PARAM_FIELD_ID, functionDescriptor.getArgs().get(TARGET_FIELD_NAME)); + + String value = (String) functionDescriptor.getArgs().get(TARGET_FIELD_VALUE); + + if (value == null || value.equals("null")) { + velocityParams.put(PARAM_FIELD_VALUE, null); + } else { + velocityParams.put(PARAM_FIELD_VALUE, value.trim()); + } + } + + protected void getVelocityParamsForInput(Map velocityParams) { + List customFields = customFieldManager.getCustomFieldObjects(); + + velocityParams.put("fields", customFields); + } + + protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { + if (!(descriptor instanceof FunctionDescriptor)) { + throw new IllegalArgumentException("Descriptor must be a FunctionDescriptor."); + } else { + FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; + + String fieldName = (String) functionDescriptor.getArgs().get("field.name"); + + velocityParams.put( + PARAM_FIELD_ID, + customFieldManager.getCustomFieldObject(fieldName).getNameKey() + ); + velocityParams.put( + PARAM_FIELD_VALUE, + functionDescriptor.getArgs().get(TARGET_FIELD_VALUE) + ); + + return; + } + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInAnyGroupsConditionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInAnyGroupsConditionPluginFactory.java index 9fce8b9b..167c6cd9 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInAnyGroupsConditionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInAnyGroupsConditionPluginFactory.java @@ -14,79 +14,79 @@ /** * @author Gustavo Martin. - * + * * This class defines the parameters available for User Is In Any Group Condition. * */ public class WorkflowUserIsInAnyGroupsConditionPluginFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginConditionFactory { - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - Collection groups = GroupUtils.getGroups(); - - velocityParams.put("val-groupsList", Collections.unmodifiableCollection(groups)); - velocityParams.put("val-splitter", WorkflowUtils.SPLITTER); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit(Map velocityParams, - AbstractDescriptor descriptor) { - - getVelocityParamsForInput(velocityParams); - - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - velocityParams.remove("val-groupsList"); - - String strGroupsSelected = (String)args.get("hidGroupsList"); - Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); - - Collection groups = GroupUtils.getGroups(); - groups.removeAll(groupsSelected); - - velocityParams.put("val-groupsListSelected", Collections.unmodifiableCollection(groupsSelected)); - velocityParams.put("val-hidGroupsList", WorkflowUtils.getStringGroup(groupsSelected, WorkflowUtils.SPLITTER)); - velocityParams.put("val-groupsList", Collections.unmodifiableCollection(groups)); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView(Map velocityParams, - AbstractDescriptor descriptor) { - - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - String strGroupsSelected = (String)args.get("hidGroupsList"); - Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); - - velocityParams.put("val-groupsListSelected", Collections.unmodifiableCollection(groupsSelected)); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - try{ - String strGroupsSelected = extractSingleParam(conditionParams, "hidGroupsList"); - params.put("hidGroupsList", strGroupsSelected); - - }catch(IllegalArgumentException iae){ - // Aggregate so that Transitions can be added. - } - - return params; - } - + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + Collection groups = GroupUtils.getGroups(); + + velocityParams.put("val-groupsList", Collections.unmodifiableCollection(groups)); + velocityParams.put("val-splitter", WorkflowUtils.SPLITTER); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit(Map velocityParams, + AbstractDescriptor descriptor) { + + getVelocityParamsForInput(velocityParams); + + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + velocityParams.remove("val-groupsList"); + + String strGroupsSelected = (String)args.get("hidGroupsList"); + Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); + + Collection groups = GroupUtils.getGroups(); + groups.removeAll(groupsSelected); + + velocityParams.put("val-groupsListSelected", Collections.unmodifiableCollection(groupsSelected)); + velocityParams.put("val-hidGroupsList", WorkflowUtils.getStringGroup(groupsSelected, WorkflowUtils.SPLITTER)); + velocityParams.put("val-groupsList", Collections.unmodifiableCollection(groups)); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView(Map velocityParams, + AbstractDescriptor descriptor) { + + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + String strGroupsSelected = (String)args.get("hidGroupsList"); + Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); + + velocityParams.put("val-groupsListSelected", Collections.unmodifiableCollection(groupsSelected)); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + try{ + String strGroupsSelected = extractSingleParam(conditionParams, "hidGroupsList"); + params.put("hidGroupsList", strGroupsSelected); + + }catch(IllegalArgumentException iae){ + // Aggregate so that Transitions can be added. + } + + return params; + } + } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInCustomFieldConditionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInCustomFieldConditionPluginFactory.java index 5149a966..c8b2282e 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInCustomFieldConditionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowUserIsInCustomFieldConditionPluginFactory.java @@ -14,89 +14,89 @@ /** * @author Anton Afanassiev */ -public class WorkflowUserIsInCustomFieldConditionPluginFactory - extends AbstractWorkflowPluginFactory - implements WorkflowPluginConditionFactory { - - private final CustomFieldManager customFieldManager; - - public WorkflowUserIsInCustomFieldConditionPluginFactory(CustomFieldManager customFieldManager) { - this.customFieldManager = customFieldManager; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - - protected void getVelocityParamsForInput(Map velocityParams) { - velocityParams.put("val-fieldsList", customFieldManager.getCustomFieldObjects()); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - - protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { - getVelocityParamsForInput(velocityParams); - - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - String sField = (String) args.get("fieldsList"); - - Field field = null; - - try { - field = WorkflowUtils.getFieldFromKey(sField); - } catch (Exception e) { - } - - if (field != null) { - velocityParams.put("val-fieldSelected", field); - } - } - - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - - protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - String sField = (String) args.get("fieldsList"); - - Field field = null; - - try { - field = WorkflowUtils.getFieldFromKey(sField); - } catch (Exception e) { - } - - if (field != null) { - velocityParams.put("val-fieldSelected", field); - } else { - velocityParams.put("val-errorMessage", "Unable to find field '" + sField + "'"); - } - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - try { - String field = extractSingleParam(conditionParams, "fieldsList"); - - params.put("fieldsList", field); - - } catch(IllegalArgumentException iae) { - // Aggregate so that Transitions can be added. - } - - return params; - } +public class WorkflowUserIsInCustomFieldConditionPluginFactory + extends AbstractWorkflowPluginFactory + implements WorkflowPluginConditionFactory { + + private final CustomFieldManager customFieldManager; + + public WorkflowUserIsInCustomFieldConditionPluginFactory(CustomFieldManager customFieldManager) { + this.customFieldManager = customFieldManager; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + + protected void getVelocityParamsForInput(Map velocityParams) { + velocityParams.put("val-fieldsList", customFieldManager.getCustomFieldObjects()); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + + protected void getVelocityParamsForEdit(Map velocityParams, AbstractDescriptor descriptor) { + getVelocityParamsForInput(velocityParams); + + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + String sField = (String) args.get("fieldsList"); + + Field field = null; + + try { + field = WorkflowUtils.getFieldFromKey(sField); + } catch (Exception e) { + } + + if (field != null) { + velocityParams.put("val-fieldSelected", field); + } + } + + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + + protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + String sField = (String) args.get("fieldsList"); + + Field field = null; + + try { + field = WorkflowUtils.getFieldFromKey(sField); + } catch (Exception e) { + } + + if (field != null) { + velocityParams.put("val-fieldSelected", field); + } else { + velocityParams.put("val-errorMessage", "Unable to find field '" + sField + "'"); + } + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + try { + String field = extractSingleParam(conditionParams, "fieldsList"); + + params.put("fieldsList", field); + + } catch(IllegalArgumentException iae) { + // Aggregate so that Transitions can be added. + } + + return params; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowValueFieldConditionPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowValueFieldConditionPluginFactory.java index f2ae98df..7cf33c4b 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowValueFieldConditionPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowValueFieldConditionPluginFactory.java @@ -17,123 +17,123 @@ /** * @author Gustavo Martin. - * + * * This class defines the parameters available for Value Field Condition. - * + * */ public class WorkflowValueFieldConditionPluginFactory extends - AbstractWorkflowPluginFactory implements WorkflowPluginConditionFactory { - - private final ConditionCheckerFactory conditionCheckerFactory; - - /** - * @param conditionCheckerFactory - */ - public WorkflowValueFieldConditionPluginFactory(ConditionCheckerFactory conditionCheckerFactory) { - this.conditionCheckerFactory = conditionCheckerFactory; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - List fields = CommonPluginUtils.getValueFieldConditionFields(); - - List conditionList = conditionCheckerFactory.getConditionTypes(); - List comparisonList = conditionCheckerFactory.getComparisonTypes(); - - velocityParams.put("val-fieldsList", fields); - velocityParams.put("val-conditionList", conditionList); - velocityParams.put("val-comparisonList", comparisonList); - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit( - Map velocityParams, AbstractDescriptor descriptor - ) { - getVelocityParamsForInput(velocityParams); - - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - String sField = (String) args.get("fieldsList"); - String conditionTypeId = (String) args.get("conditionList"); - String comparisonTypeId = (String) args.get("comparisonType"); - String fieldValue = (String) args.get("fieldValue"); - - Field field = null; - - try { - field = WorkflowUtils.getFieldFromKey(sField); - } catch (Exception e) { - } - - if (field != null) { - ComparisonType comparisonType = conditionCheckerFactory.findComparisonById(comparisonTypeId); - ConditionType conditionType = conditionCheckerFactory.findConditionById(conditionTypeId); - - velocityParams.put("val-fieldSelected", field); - velocityParams.put("val-conditionSelected", conditionType); - velocityParams.put("val-comparisonTypeSelected", comparisonType); - velocityParams.put("val-fieldValue", fieldValue); - } - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { - ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; - Map args = conditionDescriptor.getArgs(); - - String sField = (String) args.get("fieldsList"); - String conditionTypeId = (String) args.get("conditionList"); - String comparisonTypeId = (String) args.get("comparisonType"); - String fieldValue = (String) args.get("fieldValue"); - - Field field = null; - - try { - field = WorkflowUtils.getFieldFromKey(sField); - } catch (Exception e) { - } - - if (field != null) { - ComparisonType comparisonType = conditionCheckerFactory.findComparisonById(comparisonTypeId); - ConditionType conditionType = conditionCheckerFactory.findConditionById(conditionTypeId); - - velocityParams.put("val-fieldSelected", field); - velocityParams.put("val-conditionSelected", conditionType); - velocityParams.put("val-comparisonTypeSelected", comparisonType); - velocityParams.put("val-fieldValue", fieldValue); - } else { - velocityParams.put("val-errorMessage", "Unable to find field '" + sField + "'"); - } - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map conditionParams) { - Map params = new HashMap(); - - try { - String field = extractSingleParam(conditionParams, "fieldsList"); - String fieldCondition = extractSingleParam(conditionParams, "conditionList"); - String comparisonType = extractSingleParam(conditionParams, "comparisonType"); - String fieldValue = extractSingleParam(conditionParams, "fieldValue"); - - params.put("fieldsList", field); - params.put("conditionList", fieldCondition); - params.put("comparisonType", comparisonType); - params.put("fieldValue", fieldValue); - - } catch(IllegalArgumentException iae) { - // Aggregate so that Transitions can be added. - } - - return params; - } + AbstractWorkflowPluginFactory implements WorkflowPluginConditionFactory { + + private final ConditionCheckerFactory conditionCheckerFactory; + + /** + * @param conditionCheckerFactory + */ + public WorkflowValueFieldConditionPluginFactory(ConditionCheckerFactory conditionCheckerFactory) { + this.conditionCheckerFactory = conditionCheckerFactory; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + List fields = CommonPluginUtils.getValueFieldConditionFields(); + + List conditionList = conditionCheckerFactory.getConditionTypes(); + List comparisonList = conditionCheckerFactory.getComparisonTypes(); + + velocityParams.put("val-fieldsList", fields); + velocityParams.put("val-conditionList", conditionList); + velocityParams.put("val-comparisonList", comparisonList); + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit( + Map velocityParams, AbstractDescriptor descriptor + ) { + getVelocityParamsForInput(velocityParams); + + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + String sField = (String) args.get("fieldsList"); + String conditionTypeId = (String) args.get("conditionList"); + String comparisonTypeId = (String) args.get("comparisonType"); + String fieldValue = (String) args.get("fieldValue"); + + Field field = null; + + try { + field = WorkflowUtils.getFieldFromKey(sField); + } catch (Exception e) { + } + + if (field != null) { + ComparisonType comparisonType = conditionCheckerFactory.findComparisonById(comparisonTypeId); + ConditionType conditionType = conditionCheckerFactory.findConditionById(conditionTypeId); + + velocityParams.put("val-fieldSelected", field); + velocityParams.put("val-conditionSelected", conditionType); + velocityParams.put("val-comparisonTypeSelected", comparisonType); + velocityParams.put("val-fieldValue", fieldValue); + } + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView(Map velocityParams, AbstractDescriptor descriptor) { + ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor; + Map args = conditionDescriptor.getArgs(); + + String sField = (String) args.get("fieldsList"); + String conditionTypeId = (String) args.get("conditionList"); + String comparisonTypeId = (String) args.get("comparisonType"); + String fieldValue = (String) args.get("fieldValue"); + + Field field = null; + + try { + field = WorkflowUtils.getFieldFromKey(sField); + } catch (Exception e) { + } + + if (field != null) { + ComparisonType comparisonType = conditionCheckerFactory.findComparisonById(comparisonTypeId); + ConditionType conditionType = conditionCheckerFactory.findConditionById(conditionTypeId); + + velocityParams.put("val-fieldSelected", field); + velocityParams.put("val-conditionSelected", conditionType); + velocityParams.put("val-comparisonTypeSelected", comparisonType); + velocityParams.put("val-fieldValue", fieldValue); + } else { + velocityParams.put("val-errorMessage", "Unable to find field '" + sField + "'"); + } + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map conditionParams) { + Map params = new HashMap(); + + try { + String field = extractSingleParam(conditionParams, "fieldsList"); + String fieldCondition = extractSingleParam(conditionParams, "conditionList"); + String comparisonType = extractSingleParam(conditionParams, "comparisonType"); + String fieldValue = extractSingleParam(conditionParams, "fieldValue"); + + params.put("fieldsList", field); + params.put("conditionList", fieldCondition); + params.put("comparisonType", comparisonType); + params.put("fieldValue", fieldValue); + + } catch(IllegalArgumentException iae) { + // Aggregate so that Transitions can be added. + } + + return params; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/WorkflowWindowsDateValidatorPluginFactory.java b/src/main/java/com/googlecode/jsu/workflow/WorkflowWindowsDateValidatorPluginFactory.java index 31771f5b..25ae992e 100644 --- a/src/main/java/com/googlecode/jsu/workflow/WorkflowWindowsDateValidatorPluginFactory.java +++ b/src/main/java/com/googlecode/jsu/workflow/WorkflowWindowsDateValidatorPluginFactory.java @@ -14,82 +14,82 @@ /** * @author Gustavo Martin. - * + * * This class defines the parameters available for Windows Date Validator. - * + * */ public class WorkflowWindowsDateValidatorPluginFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginValidatorFactory { - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) - */ - protected void getVelocityParamsForInput(Map velocityParams) { - List allDateFiels = CommonPluginUtils.getAllDateFields(); - - velocityParams.put("val-date1FieldsList", Collections.unmodifiableList(allDateFiels)); - velocityParams.put("val-date2FieldsList", Collections.unmodifiableList(allDateFiels)); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForEdit(Map velocityParams, - AbstractDescriptor descriptor) { - getVelocityParamsForInput(velocityParams); - - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - String date1 = (String) args.get("date1Selected"); - String date2 = (String) args.get("date2Selected"); - String windowsDays = (String) args.get("windowsDays"); - - velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); - velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); - velocityParams.put("val-windowsDays", windowsDays); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) - */ - protected void getVelocityParamsForView(Map velocityParams, - AbstractDescriptor descriptor) { - ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; - Map args = validatorDescriptor.getArgs(); - - String date1 = (String) args.get("date1Selected"); - String date2 = (String) args.get("date2Selected"); - String windowsDays = (String) args.get("windowsDays"); - - velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); - velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); - velocityParams.put("val-windowsDays", windowsDays); - - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) - */ - public Map getDescriptorParams(Map validatorParams) { - Map params = new HashMap(); - - try{ - String date1 = extractSingleParam(validatorParams, "date1FieldsList"); - String date2 = extractSingleParam(validatorParams, "date2FieldsList"); - String windowsDays = extractSingleParam(validatorParams, "windowsDays"); - - params.put("date1Selected", date1); - params.put("date2Selected", date2); - params.put("windowsDays", windowsDays); - - }catch(IllegalArgumentException iae){ - // Aggregate so that Transitions can be added. - } - - return params; - } - + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map) + */ + protected void getVelocityParamsForInput(Map velocityParams) { + List allDateFiels = CommonPluginUtils.getAllDateFields(); + + velocityParams.put("val-date1FieldsList", Collections.unmodifiableList(allDateFiels)); + velocityParams.put("val-date2FieldsList", Collections.unmodifiableList(allDateFiels)); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForEdit(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForEdit(Map velocityParams, + AbstractDescriptor descriptor) { + getVelocityParamsForInput(velocityParams); + + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + String date1 = (String) args.get("date1Selected"); + String date2 = (String) args.get("date2Selected"); + String windowsDays = (String) args.get("windowsDays"); + + velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); + velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); + velocityParams.put("val-windowsDays", windowsDays); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForView(java.util.Map, com.opensymphony.workflow.loader.AbstractDescriptor) + */ + protected void getVelocityParamsForView(Map velocityParams, + AbstractDescriptor descriptor) { + ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor; + Map args = validatorDescriptor.getArgs(); + + String date1 = (String) args.get("date1Selected"); + String date2 = (String) args.get("date2Selected"); + String windowsDays = (String) args.get("windowsDays"); + + velocityParams.put("val-date1Selected", WorkflowUtils.getFieldFromKey(date1)); + velocityParams.put("val-date2Selected", WorkflowUtils.getFieldFromKey(date2)); + velocityParams.put("val-windowsDays", windowsDays); + + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.WorkflowPluginFactory#getDescriptorParams(java.util.Map) + */ + public Map getDescriptorParams(Map validatorParams) { + Map params = new HashMap(); + + try{ + String date1 = extractSingleParam(validatorParams, "date1FieldsList"); + String date2 = extractSingleParam(validatorParams, "date2FieldsList"); + String windowsDays = extractSingleParam(validatorParams, "windowsDays"); + + params.put("date1Selected", date1); + params.put("date2Selected", date2); + params.put("windowsDays", windowsDays); + + }catch(IllegalArgumentException iae){ + // Aggregate so that Transitions can be added. + } + + return params; + } + } diff --git a/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInAnyGroupsCondition.java b/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInAnyGroupsCondition.java index 9194e6ec..1824f8eb 100644 --- a/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInAnyGroupsCondition.java +++ b/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInAnyGroupsCondition.java @@ -17,22 +17,22 @@ /** * @author Gustavo Martin - * + * * This Condition validates if the current user is in any of the selected groups. - * + * */ public class UserIsInAnyGroupsCondition extends AbstractJiraCondition { - private final Logger log = Logger.getLogger(UserIsInAnyGroupsCondition.class); - - /* (non-Javadoc) - * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) - */ - public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { - boolean allowUser = false; - - try { - // Obtains the current user. - WorkflowContext context = (WorkflowContext) transientVars.get("context"); + private final Logger log = Logger.getLogger(UserIsInAnyGroupsCondition.class); + + /* (non-Javadoc) + * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) + */ + public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { + boolean allowUser = false; + + try { + // Obtains the current user. + WorkflowContext context = (WorkflowContext) transientVars.get("context"); String caller = context.getCaller(); if (caller == null) { @@ -41,24 +41,24 @@ public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { return false; } - User userLogged = UserManager.getInstance().getUser(caller); - - // If there aren't groups selected, hidGroupsList is equal to "". - // And groupsSelected will be an empty collection. - String strGroupsSelected = (String) args.get("hidGroupsList"); - Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); - - Iterator it = groupsSelected.iterator(); + User userLogged = UserManager.getInstance().getUser(caller); + + // If there aren't groups selected, hidGroupsList is equal to "". + // And groupsSelected will be an empty collection. + String strGroupsSelected = (String) args.get("hidGroupsList"); + Collection groupsSelected = WorkflowUtils.getGroups(strGroupsSelected, WorkflowUtils.SPLITTER); + + Iterator it = groupsSelected.iterator(); + + while (it.hasNext() && !allowUser){ + if (userLogged.inGroup(it.next())){ + allowUser = true; + } + } + } catch (EntityNotFoundException e) { + log.error("Unable to find user from context", e); + } - while (it.hasNext() && !allowUser){ - if (userLogged.inGroup(it.next())){ - allowUser = true; - } - } - } catch (EntityNotFoundException e) { - log.error("Unable to find user from context", e); - } - - return allowUser; - } + return allowUser; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInCustomFieldCondition.java b/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInCustomFieldCondition.java index 6095517d..7ea4504c 100644 --- a/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInCustomFieldCondition.java +++ b/src/main/java/com/googlecode/jsu/workflow/condition/UserIsInCustomFieldCondition.java @@ -19,43 +19,43 @@ * @author Anton Afanassiev */ public class UserIsInCustomFieldCondition extends AbstractJiraCondition { - private final Logger log = Logger.getLogger(UserIsInCustomFieldCondition.class); - - /* (non-Javadoc) - * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) - */ - public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { - boolean allowUser = false; - - try { - // Obtains the current user. - WorkflowContext context = (WorkflowContext) transientVars.get("context"); - User userLogged = UserManager.getInstance().getUser(context.getCaller()); - - // If there aren't groups selected, hidGroupsList is equal to "". - // And groupsSelected will be an empty collection. - String fieldKey = (String) args.get("fieldsList"); - - Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); - Issue issue = getIssue(transientVars); - - Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); - - if (fieldValue != null) { - if (fieldValue instanceof String) { - if (fieldValue.equals(userLogged.toString())) { - allowUser = true; - } - } else { - if (fieldValue.equals(userLogged)) { - allowUser = true; - } - } - } - } catch (EntityNotFoundException e) { - log.error("Unable to find user from context", e); - } - - return allowUser; - } + private final Logger log = Logger.getLogger(UserIsInCustomFieldCondition.class); + + /* (non-Javadoc) + * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) + */ + public boolean passesCondition(Map transientVars, Map args, PropertySet ps) { + boolean allowUser = false; + + try { + // Obtains the current user. + WorkflowContext context = (WorkflowContext) transientVars.get("context"); + User userLogged = UserManager.getInstance().getUser(context.getCaller()); + + // If there aren't groups selected, hidGroupsList is equal to "". + // And groupsSelected will be an empty collection. + String fieldKey = (String) args.get("fieldsList"); + + Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); + Issue issue = getIssue(transientVars); + + Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); + + if (fieldValue != null) { + if (fieldValue instanceof String) { + if (fieldValue.equals(userLogged.toString())) { + allowUser = true; + } + } else { + if (fieldValue.equals(userLogged)) { + allowUser = true; + } + } + } + } catch (EntityNotFoundException e) { + log.error("Unable to find user from context", e); + } + + return allowUser; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/condition/ValueFieldCondition.java b/src/main/java/com/googlecode/jsu/workflow/condition/ValueFieldCondition.java index e80730dc..c92f67de 100644 --- a/src/main/java/com/googlecode/jsu/workflow/condition/ValueFieldCondition.java +++ b/src/main/java/com/googlecode/jsu/workflow/condition/ValueFieldCondition.java @@ -17,52 +17,52 @@ /** * This condition evaluates if a given field fulfills the condition. - * + * * @author Gustavo Martin */ public class ValueFieldCondition extends AbstractJiraCondition { - private final Logger log = Logger.getLogger(ValueFieldCondition.class); + private final Logger log = Logger.getLogger(ValueFieldCondition.class); - /* (non-Javadoc) - * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) - */ - public boolean passesCondition( - @SuppressWarnings("rawtypes") Map transientVars, - @SuppressWarnings("rawtypes") Map args, - PropertySet ps - ) { - final ConditionCheckerFactory conditionCheckerFactory = getComponent(ConditionCheckerFactory.class); - final Issue issue = getIssue(transientVars); + /* (non-Javadoc) + * @see com.opensymphony.workflow.Condition#passesCondition(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) + */ + public boolean passesCondition( + @SuppressWarnings("rawtypes") Map transientVars, + @SuppressWarnings("rawtypes") Map args, + PropertySet ps + ) { + final ConditionCheckerFactory conditionCheckerFactory = getComponent(ConditionCheckerFactory.class); + final Issue issue = getIssue(transientVars); - String fieldId = (String) args.get("fieldsList"); - String valueForCompare = (String) args.get("fieldValue"); + String fieldId = (String) args.get("fieldsList"); + String valueForCompare = (String) args.get("fieldValue"); - ComparisonType comparison = conditionCheckerFactory.findComparisonById((String) args.get("comparisonType")); - ConditionType condition = conditionCheckerFactory.findConditionById((String) args.get("conditionList")); + ComparisonType comparison = conditionCheckerFactory.findComparisonById((String) args.get("comparisonType")); + ConditionType condition = conditionCheckerFactory.findConditionById((String) args.get("conditionList")); - boolean result = false; - - try { - Field field = WorkflowUtils.getFieldFromKey(fieldId); - Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); - - result = conditionCheckerFactory. - getChecker(comparison, condition). - checkValues(fieldValue, valueForCompare); - - if (log.isDebugEnabled()) { - log.debug( - "Comparing field '" + fieldId + - "': [" + fieldValue + "]" + - condition.getValue() + - "[" + valueForCompare + "] as " + - comparison.getValue() + " = " + result - ); - } - } catch (Exception e) { - log.error("Unable to compare values for field '" + fieldId + "'", e); - } - - return result; - } + boolean result = false; + + try { + Field field = WorkflowUtils.getFieldFromKey(fieldId); + Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); + + result = conditionCheckerFactory. + getChecker(comparison, condition). + checkValues(fieldValue, valueForCompare); + + if (log.isDebugEnabled()) { + log.debug( + "Comparing field '" + fieldId + + "': [" + fieldValue + "]" + + condition.getValue() + + "[" + valueForCompare + "] as " + + comparison.getValue() + " = " + result + ); + } + } catch (Exception e) { + log.error("Unable to compare values for field '" + fieldId + "'", e); + } + + return result; + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/function/AbstractPreserveChangesPostFunction.java b/src/main/java/com/googlecode/jsu/workflow/function/AbstractPreserveChangesPostFunction.java index 903ca6fd..be02541a 100644 --- a/src/main/java/com/googlecode/jsu/workflow/function/AbstractPreserveChangesPostFunction.java +++ b/src/main/java/com/googlecode/jsu/workflow/function/AbstractPreserveChangesPostFunction.java @@ -15,32 +15,32 @@ /** * Abstract post-function with transparent change tracking. - * + * * @author Alexey Abashev * @version $Id$ */ abstract class AbstractPreserveChangesPostFunction extends AbstractJiraFunctionProvider { - private static final String CHANGE_ITEMS = "changeItems"; - - protected final Logger log = Logger.getLogger(this.getClass()); - - /** - * Mirror for execute method but with holder for changes - * - * @param transientVars - * @param args - * @param ps - * @param holder - * @throws WorkflowException - */ - protected abstract void executeFunction( - Map transientVars, Map args, - PropertySet ps, IssueChangeHolder holder - ) throws WorkflowException; - - @SuppressWarnings("unchecked") - public final void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException { - IssueChangeHolder holder = createChangeHolder(transientVars); + private static final String CHANGE_ITEMS = "changeItems"; + + protected final Logger log = Logger.getLogger(this.getClass()); + + /** + * Mirror for execute method but with holder for changes + * + * @param transientVars + * @param args + * @param ps + * @param holder + * @throws WorkflowException + */ + protected abstract void executeFunction( + Map transientVars, Map args, + PropertySet ps, IssueChangeHolder holder + ) throws WorkflowException; + + @SuppressWarnings("unchecked") + public final void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException { + IssueChangeHolder holder = createChangeHolder(transientVars); if (log.isDebugEnabled()) { log.debug( @@ -53,51 +53,51 @@ public final void execute(Map transientVars, Map args, PropertySet ps) throws Wo "]" ); } - - try { - executeFunction(transientVars, args, ps, holder); - } finally { - releaseChangeHolder(holder, transientVars); - } - } - - /** - * Create new holder with changes from transient vars - * @param transientVars - * @return - */ - @SuppressWarnings("unchecked") - private IssueChangeHolder createChangeHolder(Map transientVars) { - List changeItems = (List) transientVars.get(CHANGE_ITEMS); - + + try { + executeFunction(transientVars, args, ps, holder); + } finally { + releaseChangeHolder(holder, transientVars); + } + } + + /** + * Create new holder with changes from transient vars + * @param transientVars + * @return + */ + @SuppressWarnings("unchecked") + private IssueChangeHolder createChangeHolder(Map transientVars) { + List changeItems = (List) transientVars.get(CHANGE_ITEMS); + if (changeItems == null) { changeItems = new LinkedList(); } if (log.isDebugEnabled()) { - log.debug("Create new holder with items - " + changeItems.toString()); - } - + log.debug("Create new holder with items - " + changeItems.toString()); + } + IssueChangeHolder holder = new DefaultIssueChangeHolder(); - + holder.setChangeItems(changeItems); - + return holder; - } - - /** - * Release holder for changes. - * @param holder - * @param transientVars - */ - @SuppressWarnings("unchecked") - private void releaseChangeHolder(IssueChangeHolder holder, Map transientVars) { - List items = holder.getChangeItems(); - - if (log.isDebugEnabled()) { - log.debug("Release holder with items - " + items.toString()); - } - - transientVars.put(CHANGE_ITEMS, items); - } + } + + /** + * Release holder for changes. + * @param holder + * @param transientVars + */ + @SuppressWarnings("unchecked") + private void releaseChangeHolder(IssueChangeHolder holder, Map transientVars) { + List items = holder.getChangeItems(); + + if (log.isDebugEnabled()) { + log.debug("Release holder with items - " + items.toString()); + } + + transientVars.put(CHANGE_ITEMS, items); + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/function/ClearFieldValuePostFunction.java b/src/main/java/com/googlecode/jsu/workflow/function/ClearFieldValuePostFunction.java index ad765cc9..6d645fdc 100644 --- a/src/main/java/com/googlecode/jsu/workflow/function/ClearFieldValuePostFunction.java +++ b/src/main/java/com/googlecode/jsu/workflow/function/ClearFieldValuePostFunction.java @@ -12,41 +12,41 @@ /** * This function clears field value. - * + * * @author Alexey Abashev */ public class ClearFieldValuePostFunction extends AbstractPreserveChangesPostFunction { - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) - */ - @Override - protected void executeFunction( - Map transientVars, Map args, - PropertySet ps, IssueChangeHolder holder - ) throws WorkflowException { - String fieldKey = (String) args.get(WorkflowClearFieldValueFunctionPluginFactory.FIELD); - Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); - - final String fieldName = (field != null) ? field.getName() : "null"; - - // It set the value to field. - try { - MutableIssue issue = getIssue(transientVars); - - if (log.isDebugEnabled()) { - log.debug(String.format( - "Clean field '%s - %s' in the issue [%s]", - fieldKey, fieldName, issue.getKey() - )); - } - - WorkflowUtils.setFieldValue(issue, fieldKey, null, holder); - } catch (Exception e) { - String message = "Unable to clean field - '" + fieldKey + " - " + fieldName + "'"; - - log.error(message, e); - - throw new WorkflowException(message); - } - } + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) + */ + @Override + protected void executeFunction( + Map transientVars, Map args, + PropertySet ps, IssueChangeHolder holder + ) throws WorkflowException { + String fieldKey = (String) args.get(WorkflowClearFieldValueFunctionPluginFactory.FIELD); + Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); + + final String fieldName = (field != null) ? field.getName() : "null"; + + // It set the value to field. + try { + MutableIssue issue = getIssue(transientVars); + + if (log.isDebugEnabled()) { + log.debug(String.format( + "Clean field '%s - %s' in the issue [%s]", + fieldKey, fieldName, issue.getKey() + )); + } + + WorkflowUtils.setFieldValue(issue, fieldKey, null, holder); + } catch (Exception e) { + String message = "Unable to clean field - '" + fieldKey + " - " + fieldName + "'"; + + log.error(message, e); + + throw new WorkflowException(message); + } + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/function/CopyValueFromOtherFieldPostFunction.java b/src/main/java/com/googlecode/jsu/workflow/function/CopyValueFromOtherFieldPostFunction.java index c2cca47d..d803a979 100644 --- a/src/main/java/com/googlecode/jsu/workflow/function/CopyValueFromOtherFieldPostFunction.java +++ b/src/main/java/com/googlecode/jsu/workflow/function/CopyValueFromOtherFieldPostFunction.java @@ -15,52 +15,52 @@ * This function copies the value from a field to another one. */ public class CopyValueFromOtherFieldPostFunction extends AbstractPreserveChangesPostFunction { - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) - */ - @Override - protected void executeFunction( - Map transientVars, Map args, - PropertySet ps, IssueChangeHolder holder - ) throws WorkflowException { - String fieldFromKey = (String) args.get("sourceField"); - String fieldToKey = (String) args.get("destinationField"); - - Field fieldFrom = (Field) WorkflowUtils.getFieldFromKey(fieldFromKey); - Field fieldTo = (Field) WorkflowUtils.getFieldFromKey(fieldToKey); + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) + */ + @Override + protected void executeFunction( + Map transientVars, Map args, + PropertySet ps, IssueChangeHolder holder + ) throws WorkflowException { + String fieldFromKey = (String) args.get("sourceField"); + String fieldToKey = (String) args.get("destinationField"); + + Field fieldFrom = (Field) WorkflowUtils.getFieldFromKey(fieldFromKey); + Field fieldTo = (Field) WorkflowUtils.getFieldFromKey(fieldToKey); String fieldFromName = (fieldFrom != null) ? fieldFrom.getName() : fieldFromKey; String fieldToName = (fieldTo != null) ? fieldTo.getName() : fieldToKey; - try { - MutableIssue issue = getIssue(transientVars); - - // It gives the value from the source field. - Object sourceValue = WorkflowUtils.getFieldValueFromIssue(issue, fieldFrom); + try { + MutableIssue issue = getIssue(transientVars); + + // It gives the value from the source field. + Object sourceValue = WorkflowUtils.getFieldValueFromIssue(issue, fieldFrom); - if (log.isDebugEnabled()) { - log.debug( - String.format( - "Copying value [%s] from issue %s field '%s' to '%s'", - sourceValue, issue.getKey(), - fieldFromName, + if (log.isDebugEnabled()) { + log.debug( + String.format( + "Copying value [%s] from issue %s field '%s' to '%s'", + sourceValue, issue.getKey(), + fieldFromName, fieldToName - ) - ); - } - - // It set the value to field. - WorkflowUtils.setFieldValue(issue, fieldToKey, sourceValue, holder); + ) + ); + } + + // It set the value to field. + WorkflowUtils.setFieldValue(issue, fieldToKey, sourceValue, holder); + + if (log.isDebugEnabled()) { + log.debug("Value was successfully copied"); + } + } catch (Exception e) { + String message = String.format("Unable to copy value from '%s' to '%s'", fieldFromName, fieldToName); + + log.error(message, e); - if (log.isDebugEnabled()) { - log.debug("Value was successfully copied"); - } - } catch (Exception e) { - String message = String.format("Unable to copy value from '%s' to '%s'", fieldFromName, fieldToName); - - log.error(message, e); - - throw new WorkflowException(message); - } - } + throw new WorkflowException(message); + } + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/function/UpdateIssueCustomFieldPostFunction.java b/src/main/java/com/googlecode/jsu/workflow/function/UpdateIssueCustomFieldPostFunction.java index dea838d7..71d3b0da 100644 --- a/src/main/java/com/googlecode/jsu/workflow/function/UpdateIssueCustomFieldPostFunction.java +++ b/src/main/java/com/googlecode/jsu/workflow/function/UpdateIssueCustomFieldPostFunction.java @@ -15,68 +15,68 @@ /** * Class related to the execution of the plugin. - * + * * @author Cristiane Fontana * @version 1.0 * */ public class UpdateIssueCustomFieldPostFunction extends AbstractPreserveChangesPostFunction { - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) - */ - @Override - protected void executeFunction( - Map transientVars, Map args, - PropertySet ps, IssueChangeHolder holder - ) throws WorkflowException { - String fieldKey = (String) args.get(TARGET_FIELD_NAME); - - final Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); - final String fieldName = (field != null) ? field.getName() : "null"; - - String fieldValue = (String) args.get(TARGET_FIELD_VALUE); - - if ((fieldValue != null) && ("null".equals(fieldValue))) { - fieldValue = null; - } - - if (fieldValue.equals("%%CURRENT_USER%%")) { + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.function.AbstractPreserveChangesPostFunction#executeFunction(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet, com.atlassian.jira.issue.util.IssueChangeHolder) + */ + @Override + protected void executeFunction( + Map transientVars, Map args, + PropertySet ps, IssueChangeHolder holder + ) throws WorkflowException { + String fieldKey = (String) args.get(TARGET_FIELD_NAME); + + final Field field = (Field) WorkflowUtils.getFieldFromKey(fieldKey); + final String fieldName = (field != null) ? field.getName() : "null"; + + String fieldValue = (String) args.get(TARGET_FIELD_VALUE); + + if ((fieldValue != null) && ("null".equals(fieldValue))) { + fieldValue = null; + } + + if (fieldValue.equals("%%CURRENT_USER%%")) { try { User currentUser = getCaller(transientVars, args); - fieldValue = currentUser.toString(); - } catch (Exception e) { - log.error("Unable to find caller for function", e); - } - } - - MutableIssue issue = null; - - try { - issue = getIssue(transientVars); - - if (log.isDebugEnabled()) { - log.debug(String.format( - "Updating custom field '%s - %s' in issue [%s] with value [%s]", - fieldKey, fieldName, + fieldValue = currentUser.toString(); + } catch (Exception e) { + log.error("Unable to find caller for function", e); + } + } + + MutableIssue issue = null; + + try { + issue = getIssue(transientVars); + + if (log.isDebugEnabled()) { + log.debug(String.format( + "Updating custom field '%s - %s' in issue [%s] with value [%s]", + fieldKey, fieldName, issueToString(issue), fieldValue - )); - } - - WorkflowUtils.setFieldValue(issue, fieldKey, fieldValue, holder); - } catch (Exception e) { - final String message = String.format( - "Unable to update custom field '%s - %s' in issue [%s]", - fieldKey, fieldName, + )); + } + + WorkflowUtils.setFieldValue(issue, fieldKey, fieldValue, holder); + } catch (Exception e) { + final String message = String.format( + "Unable to update custom field '%s - %s' in issue [%s]", + fieldKey, fieldName, issueToString(issue) - ); - - log.error(message, e); - - throw new WorkflowException(message); - } - } + ); + + log.error(message, e); + + throw new WorkflowException(message); + } + } private String issueToString(MutableIssue issue) { return ((issue != null) ? ((issue.getKey() == null) ? "new issue" : issue.getKey()) : "null"); diff --git a/src/main/java/com/googlecode/jsu/workflow/validator/DateCompareValidator.java b/src/main/java/com/googlecode/jsu/workflow/validator/DateCompareValidator.java index 873c2f7b..10d6e19c 100644 --- a/src/main/java/com/googlecode/jsu/workflow/validator/DateCompareValidator.java +++ b/src/main/java/com/googlecode/jsu/workflow/validator/DateCompareValidator.java @@ -23,177 +23,177 @@ import com.opensymphony.workflow.WorkflowException; /** - * This validator compare two datetime fields, using the given comparison type. + * This validator compare two datetime fields, using the given comparison type. * And returning an exception if it doesn't fulfill the condition. */ public class DateCompareValidator extends GenericValidator { - @Argument("date1Selected") - private String date1; - - @Argument("date2Selected") - private String date2; - - @Argument("conditionSelected") - private String conditionId; - - @Argument("includeTimeSelected") - private String includeTimeValue; - - private final Logger log = Logger.getLogger(DateCompareValidator.class); - private final ConditionCheckerFactory conditionCheckerFactory; - private final ApplicationProperties applicationProperties; - - /** - * @param conditionCheckerFactory - */ - public DateCompareValidator( - ConditionCheckerFactory conditionCheckerFactory, - ApplicationProperties applicationProperties - ) { - this.conditionCheckerFactory = conditionCheckerFactory; - this.applicationProperties = applicationProperties; - } - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.validator.GenericValidator#validate() - */ - protected void validate() throws InvalidInputException, WorkflowException { - Field field1 = WorkflowUtils.getFieldFromKey(date1); - Field field2 = WorkflowUtils.getFieldFromKey(date2); - - ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); - boolean includeTime = (Integer.parseInt(includeTimeValue) == 1) ? true : false; - - // Compare Dates. - if ((field1 != null) && (field2 != null)) { - Object objValue1 = WorkflowUtils.getFieldValueFromIssue(getIssue(), field1); - Object objValue2 = WorkflowUtils.getFieldValueFromIssue(getIssue(), field2); - Date objDate1, objDate2; - - try { - objDate1 = (Date) objValue1; - } catch (ClassCastException e) { - wrongDataErrorMessage(field1, objValue1); - - return; - } - - try { - objDate2 = (Date) objValue2; - } catch (ClassCastException e) { - wrongDataErrorMessage(field2, objValue2); - - return; - } - - if ((objDate1 != null) && (objDate2 != null)) { - ComparisonType comparison = (includeTime) ? DATE : DATE_WITHOUT_TIME; - ConditionChecker checker = conditionCheckerFactory.getChecker(comparison, condition); - - Calendar calDate1 = Calendar.getInstance(applicationProperties.getDefaultLocale()); - Calendar calDate2 = Calendar.getInstance(applicationProperties.getDefaultLocale()); - - calDate1.setTime((Date) objDate1); - calDate2.setTime((Date) objDate2); - - boolean result = checker.checkValues(calDate1, calDate2); - - if (log.isDebugEnabled()) { - log.debug( - "Compare field \"" + field1.getName() + - "\" and field \"" + field2.getName() + - "\" with values [" + calDate1 + - "] and [" + calDate2 + - "] with result " + result - ); - } - - if (!result) { - generateErrorMessage(field1, objDate1, field2, objDate2, condition, includeTime); - } - } else { - // If any of fields are null, validates if the field is required. Otherwise, doesn't throws an Exception. - if (objDate1 == null) { - validateRequired(field1); - } - - if (objDate2 == null) { - validateRequired(field2); - } - } - } else { - log.error("Unable to find field with ids [" + date1 + "] and [" + date2 + "]"); - } - } - - /** - * @param fldDate - * - * Throws an Exception if the field is null, but it is required. - */ - private void validateRequired(Field fldDate){ - if (CommonPluginUtils.isFieldRequired(getIssue(), fldDate)) { - this.setExceptionMessage( - fldDate, - fldDate.getName() + " is required.", - fldDate.getName() + " is required." - ); - } - } - - private void generateErrorMessage( - Field field1, Object fieldValue1, - Field field2, Object fieldValue2, - ConditionType condition, boolean includeTime - ) { - // Formats date to current locale to display the Exception. - SimpleDateFormat formatter = null; - SimpleDateFormat defaultFormatter = null; - - if (includeTime) { - defaultFormatter = new SimpleDateFormat( - applicationProperties.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT) - ); - formatter = new SimpleDateFormat( - applicationProperties.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT), - applicationProperties.getDefaultLocale() - ); - }else{ - defaultFormatter = new SimpleDateFormat( - applicationProperties.getDefaultString(APKeys.JIRA_DATE_TIME_PICKER_JAVA_FORMAT) - ); - formatter = new SimpleDateFormat( - applicationProperties.getDefaultString(APKeys.JIRA_DATE_TIME_PICKER_JAVA_FORMAT), - applicationProperties.getDefaultLocale() - ); - } - - String errorMsg = ""; - - try{ - errorMsg = " ( " + formatter.format(fieldValue2) + " )"; - } catch (IllegalArgumentException e) { - try { - errorMsg = " ( " + defaultFormatter.format(fieldValue2) + " )"; - } catch(Exception e1) { - errorMsg = " ( " + fieldValue2 + " )"; - } - } - - this.setExceptionMessage( - field1, - field1.getName() + " isn't " + condition.toString() + " " + field2.getName() + errorMsg, - field1.getName() + " isn't " + condition.toString() + " " + field2.getName() + errorMsg - ); - } - - private void wrongDataErrorMessage( - Field field, Object fieldValue - ) { - this.setExceptionMessage( - field, - field.getName() + " not a date value (" + fieldValue + ")", - field.getName() + " not a date value (" + fieldValue + ")" - ); - } + @Argument("date1Selected") + private String date1; + + @Argument("date2Selected") + private String date2; + + @Argument("conditionSelected") + private String conditionId; + + @Argument("includeTimeSelected") + private String includeTimeValue; + + private final Logger log = Logger.getLogger(DateCompareValidator.class); + private final ConditionCheckerFactory conditionCheckerFactory; + private final ApplicationProperties applicationProperties; + + /** + * @param conditionCheckerFactory + */ + public DateCompareValidator( + ConditionCheckerFactory conditionCheckerFactory, + ApplicationProperties applicationProperties + ) { + this.conditionCheckerFactory = conditionCheckerFactory; + this.applicationProperties = applicationProperties; + } + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.validator.GenericValidator#validate() + */ + protected void validate() throws InvalidInputException, WorkflowException { + Field field1 = WorkflowUtils.getFieldFromKey(date1); + Field field2 = WorkflowUtils.getFieldFromKey(date2); + + ConditionType condition = conditionCheckerFactory.findConditionById(conditionId); + boolean includeTime = (Integer.parseInt(includeTimeValue) == 1) ? true : false; + + // Compare Dates. + if ((field1 != null) && (field2 != null)) { + Object objValue1 = WorkflowUtils.getFieldValueFromIssue(getIssue(), field1); + Object objValue2 = WorkflowUtils.getFieldValueFromIssue(getIssue(), field2); + Date objDate1, objDate2; + + try { + objDate1 = (Date) objValue1; + } catch (ClassCastException e) { + wrongDataErrorMessage(field1, objValue1); + + return; + } + + try { + objDate2 = (Date) objValue2; + } catch (ClassCastException e) { + wrongDataErrorMessage(field2, objValue2); + + return; + } + + if ((objDate1 != null) && (objDate2 != null)) { + ComparisonType comparison = (includeTime) ? DATE : DATE_WITHOUT_TIME; + ConditionChecker checker = conditionCheckerFactory.getChecker(comparison, condition); + + Calendar calDate1 = Calendar.getInstance(applicationProperties.getDefaultLocale()); + Calendar calDate2 = Calendar.getInstance(applicationProperties.getDefaultLocale()); + + calDate1.setTime((Date) objDate1); + calDate2.setTime((Date) objDate2); + + boolean result = checker.checkValues(calDate1, calDate2); + + if (log.isDebugEnabled()) { + log.debug( + "Compare field \"" + field1.getName() + + "\" and field \"" + field2.getName() + + "\" with values [" + calDate1 + + "] and [" + calDate2 + + "] with result " + result + ); + } + + if (!result) { + generateErrorMessage(field1, objDate1, field2, objDate2, condition, includeTime); + } + } else { + // If any of fields are null, validates if the field is required. Otherwise, doesn't throws an Exception. + if (objDate1 == null) { + validateRequired(field1); + } + + if (objDate2 == null) { + validateRequired(field2); + } + } + } else { + log.error("Unable to find field with ids [" + date1 + "] and [" + date2 + "]"); + } + } + + /** + * @param fldDate + * + * Throws an Exception if the field is null, but it is required. + */ + private void validateRequired(Field fldDate){ + if (CommonPluginUtils.isFieldRequired(getIssue(), fldDate)) { + this.setExceptionMessage( + fldDate, + fldDate.getName() + " is required.", + fldDate.getName() + " is required." + ); + } + } + + private void generateErrorMessage( + Field field1, Object fieldValue1, + Field field2, Object fieldValue2, + ConditionType condition, boolean includeTime + ) { + // Formats date to current locale to display the Exception. + SimpleDateFormat formatter = null; + SimpleDateFormat defaultFormatter = null; + + if (includeTime) { + defaultFormatter = new SimpleDateFormat( + applicationProperties.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT) + ); + formatter = new SimpleDateFormat( + applicationProperties.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT), + applicationProperties.getDefaultLocale() + ); + }else{ + defaultFormatter = new SimpleDateFormat( + applicationProperties.getDefaultString(APKeys.JIRA_DATE_TIME_PICKER_JAVA_FORMAT) + ); + formatter = new SimpleDateFormat( + applicationProperties.getDefaultString(APKeys.JIRA_DATE_TIME_PICKER_JAVA_FORMAT), + applicationProperties.getDefaultLocale() + ); + } + + String errorMsg = ""; + + try{ + errorMsg = " ( " + formatter.format(fieldValue2) + " )"; + } catch (IllegalArgumentException e) { + try { + errorMsg = " ( " + defaultFormatter.format(fieldValue2) + " )"; + } catch(Exception e1) { + errorMsg = " ( " + fieldValue2 + " )"; + } + } + + this.setExceptionMessage( + field1, + field1.getName() + " isn't " + condition.toString() + " " + field2.getName() + errorMsg, + field1.getName() + " isn't " + condition.toString() + " " + field2.getName() + errorMsg + ); + } + + private void wrongDataErrorMessage( + Field field, Object fieldValue + ) { + this.setExceptionMessage( + field, + field.getName() + " not a date value (" + fieldValue + ")", + field.getName() + " not a date value (" + fieldValue + ")" + ); + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/validator/FieldsRequiredValidator.java b/src/main/java/com/googlecode/jsu/workflow/validator/FieldsRequiredValidator.java index d69f6451..5ad337c9 100644 --- a/src/main/java/com/googlecode/jsu/workflow/validator/FieldsRequiredValidator.java +++ b/src/main/java/com/googlecode/jsu/workflow/validator/FieldsRequiredValidator.java @@ -16,61 +16,61 @@ /** * This validator verifies that certain fields must be required at execution of a transition. - * + * * @author Gustavo Martin */ public class FieldsRequiredValidator extends GenericValidator { - private static final Logger log = Logger.getLogger(FieldsRequiredValidator.class); - - @Argument(SELECTED_FIELDS) - private String fieldList; - - /* (non-Javadoc) - * @see com.opensymphony.workflow.Validator#validate(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) - */ - protected void validate() throws InvalidInputException, WorkflowException { - // It obtains the fields that are required for the transition. - Collection fieldsSelected = WorkflowUtils.getFields(fieldList, WorkflowUtils.SPLITTER); - final Issue issue = getIssue(); - String issueKey = issue.getKey(); - - if (issueKey == null) { - issueKey = "'New issue'"; - } - - if (log.isDebugEnabled()) { - log.debug(issueKey + ": Found " + fieldsSelected.size() + " fields for validation"); - } - - for (Field field : fieldsSelected) { - if (isIssueHasField(issue, field)) { - Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); - - if (log.isDebugEnabled()) { - log.debug( - issueKey + ": Field '" + field.getName() + - " - " + field.getId() + - "' has value [" + fieldValue + "]" - ); - } - - if (fieldValue == null) { - // Sets Exception message. - this.setExceptionMessage( - field, - field.getName() + " is required.", - field.getName() + " is required. But it is not present on screen." - ); - } - } else { - if (log.isDebugEnabled()) { - log.debug( - issueKey + ": Field '" + field.getName() + - " - " + field.getId() + - "' is not assigned for the issue" - ); - } - } - } - } + private static final Logger log = Logger.getLogger(FieldsRequiredValidator.class); + + @Argument(SELECTED_FIELDS) + private String fieldList; + + /* (non-Javadoc) + * @see com.opensymphony.workflow.Validator#validate(java.util.Map, java.util.Map, com.opensymphony.module.propertyset.PropertySet) + */ + protected void validate() throws InvalidInputException, WorkflowException { + // It obtains the fields that are required for the transition. + Collection fieldsSelected = WorkflowUtils.getFields(fieldList, WorkflowUtils.SPLITTER); + final Issue issue = getIssue(); + String issueKey = issue.getKey(); + + if (issueKey == null) { + issueKey = "'New issue'"; + } + + if (log.isDebugEnabled()) { + log.debug(issueKey + ": Found " + fieldsSelected.size() + " fields for validation"); + } + + for (Field field : fieldsSelected) { + if (isIssueHasField(issue, field)) { + Object fieldValue = WorkflowUtils.getFieldValueFromIssue(issue, field); + + if (log.isDebugEnabled()) { + log.debug( + issueKey + ": Field '" + field.getName() + + " - " + field.getId() + + "' has value [" + fieldValue + "]" + ); + } + + if (fieldValue == null) { + // Sets Exception message. + this.setExceptionMessage( + field, + field.getName() + " is required.", + field.getName() + " is required. But it is not present on screen." + ); + } + } else { + if (log.isDebugEnabled()) { + log.debug( + issueKey + ": Field '" + field.getName() + + " - " + field.getId() + + "' is not assigned for the issue" + ); + } + } + } + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/validator/GenericValidator.java b/src/main/java/com/googlecode/jsu/workflow/validator/GenericValidator.java index 7ec707e7..29c59d15 100644 --- a/src/main/java/com/googlecode/jsu/workflow/validator/GenericValidator.java +++ b/src/main/java/com/googlecode/jsu/workflow/validator/GenericValidator.java @@ -26,99 +26,99 @@ * @version $Id: GenericValidator.java 173 2008-10-14 13:04:43Z abashev $ */ public abstract class GenericValidator implements Validator { - private final Logger log = Logger.getLogger(this.getClass()); - - private ValidatorErrorsBuilder errorBuilder; - private FieldScreen fieldScreen = null; - private Issue issue = null; - - protected abstract void validate() throws InvalidInputException, WorkflowException; - - @SuppressWarnings("unchecked") - public final void validate( - Map transientVars, Map args, PropertySet ps - ) throws InvalidInputException, WorkflowException { - if (log.isDebugEnabled()) { - log.debug( - "Validation request: [transientVars=" + - transientVars + - ";args=" + - args + - ";property=" + - ps + - "]" - ); - } - - initObject(transientVars, args); - - this.fieldScreen = initScreen(transientVars); - this.errorBuilder = new ValidatorErrorsBuilder(hasViewScreen()); - this.issue = (Issue) transientVars.get("issue"); - - this.validate(); - - this.errorBuilder.process(); - } - - /** - * Initialize object with maps of parameters. - * @param vars - * @param arguments - */ - protected void initObject(Map vars, Map arguments) { - final AnnotationProcessor processor = new AnnotationProcessor(); - - processor.addVisitor(new MapFieldProcessor(Argument.class, arguments)); - processor.addVisitor(new MapFieldProcessor(TransientVariable.class, vars)); - - processor.processAnnotations(this); - } - - protected final Issue getIssue() { - return this.issue; - } - - protected final boolean hasViewScreen() { - return (fieldScreen != null); - } - - protected final FieldScreen getFieldScreen() { - return this.fieldScreen; - } - - /** - * Setting error message for validator. - * - * @param issue - * @param field - * @param messageIfOnScreen - * @param messageIfHidden - */ - protected final void setExceptionMessage( - Field field, - String messageIfOnScreen, String messageIfHidden - ) { - if (hasViewScreen()) { - if (CommonPluginUtils.isFieldOnScreen(this.issue, field, getFieldScreen())) { - this.errorBuilder.addError(field, messageIfOnScreen); - } else { - this.errorBuilder.addError(messageIfHidden); - } - } else { - this.errorBuilder.addError(messageIfOnScreen); - } - } - - private FieldScreen initScreen(Map vars) { - if (vars.containsKey("descriptor") && vars.containsKey("actionId")) { - WorkflowDescriptor workflowDescriptor = (WorkflowDescriptor) vars.get("descriptor"); - Integer actionId = (Integer) vars.get("actionId"); - ActionDescriptor actionDescriptor = workflowDescriptor.getAction(actionId.intValue()); - - return WorkflowUtils.getFieldScreen(actionDescriptor); - } else { - return null; - } - } + private final Logger log = Logger.getLogger(this.getClass()); + + private ValidatorErrorsBuilder errorBuilder; + private FieldScreen fieldScreen = null; + private Issue issue = null; + + protected abstract void validate() throws InvalidInputException, WorkflowException; + + @SuppressWarnings("unchecked") + public final void validate( + Map transientVars, Map args, PropertySet ps + ) throws InvalidInputException, WorkflowException { + if (log.isDebugEnabled()) { + log.debug( + "Validation request: [transientVars=" + + transientVars + + ";args=" + + args + + ";property=" + + ps + + "]" + ); + } + + initObject(transientVars, args); + + this.fieldScreen = initScreen(transientVars); + this.errorBuilder = new ValidatorErrorsBuilder(hasViewScreen()); + this.issue = (Issue) transientVars.get("issue"); + + this.validate(); + + this.errorBuilder.process(); + } + + /** + * Initialize object with maps of parameters. + * @param vars + * @param arguments + */ + protected void initObject(Map vars, Map arguments) { + final AnnotationProcessor processor = new AnnotationProcessor(); + + processor.addVisitor(new MapFieldProcessor(Argument.class, arguments)); + processor.addVisitor(new MapFieldProcessor(TransientVariable.class, vars)); + + processor.processAnnotations(this); + } + + protected final Issue getIssue() { + return this.issue; + } + + protected final boolean hasViewScreen() { + return (fieldScreen != null); + } + + protected final FieldScreen getFieldScreen() { + return this.fieldScreen; + } + + /** + * Setting error message for validator. + * + * @param issue + * @param field + * @param messageIfOnScreen + * @param messageIfHidden + */ + protected final void setExceptionMessage( + Field field, + String messageIfOnScreen, String messageIfHidden + ) { + if (hasViewScreen()) { + if (CommonPluginUtils.isFieldOnScreen(this.issue, field, getFieldScreen())) { + this.errorBuilder.addError(field, messageIfOnScreen); + } else { + this.errorBuilder.addError(messageIfHidden); + } + } else { + this.errorBuilder.addError(messageIfOnScreen); + } + } + + private FieldScreen initScreen(Map vars) { + if (vars.containsKey("descriptor") && vars.containsKey("actionId")) { + WorkflowDescriptor workflowDescriptor = (WorkflowDescriptor) vars.get("descriptor"); + Integer actionId = (Integer) vars.get("actionId"); + ActionDescriptor actionDescriptor = workflowDescriptor.getAction(actionId.intValue()); + + return WorkflowUtils.getFieldScreen(actionDescriptor); + } else { + return null; + } + } } diff --git a/src/main/java/com/googlecode/jsu/workflow/validator/WindowsDateValidator.java b/src/main/java/com/googlecode/jsu/workflow/validator/WindowsDateValidator.java index 5ccd5abd..5d85cb07 100644 --- a/src/main/java/com/googlecode/jsu/workflow/validator/WindowsDateValidator.java +++ b/src/main/java/com/googlecode/jsu/workflow/validator/WindowsDateValidator.java @@ -17,130 +17,130 @@ /** * @author Gustavo Martin - * + * * This validator compare two datetime fields, and verifies if the first of them, - * is less than the second plus a number of days. + * is less than the second plus a number of days. * And returning an exception if it doesn't fulfill the condition. - * + * */ public class WindowsDateValidator extends GenericValidator { - @Argument("date1Selected") - private String date1; - - @Argument("date2Selected") - private String date2; - - @Argument - private String windowsDays; - - /* (non-Javadoc) - * @see com.googlecode.jsu.workflow.validator.GenericValidator#validate() - */ - protected void validate() throws InvalidInputException, WorkflowException { - Field fldDate1 = WorkflowUtils.getFieldFromKey(date1); - Field fldDate2 = WorkflowUtils.getFieldFromKey(date2); - - // Compare Dates. - if ((fldDate1 != null) && (fldDate2 != null)) { - checkDatesCondition(fldDate1, fldDate2, windowsDays); - } - } - - /** - * @param fldDate1 - * @param fldDate2 - * @param window - * - * It makes the comparison properly this. - */ - private void checkDatesCondition(Field fldDate1, Field fldDate2, String window) { - boolean condOK = false; - - Object objDate1 = WorkflowUtils.getFieldValueFromIssue(getIssue(), fldDate1); - Object objDate2 = WorkflowUtils.getFieldValueFromIssue(getIssue(), fldDate2); - - if ((objDate1 != null) && (objDate2 != null)) { - // It Takes the Locale for inicialize dates. - ApplicationProperties ap = ManagerFactory.getApplicationProperties(); - Locale locale = ap.getDefaultLocale(); - - Calendar calDate1 = Calendar.getInstance(locale); - Calendar calDate2 = Calendar.getInstance(locale); - Calendar calWindowsDate = Calendar.getInstance(locale); - - calDate1.setTime((Date) objDate1); - calDate2.setTime((Date) objDate2); - calWindowsDate.setTime((Date) objDate2); - calWindowsDate.add(Calendar.DATE, Integer.parseInt(window)); - - CommonPluginUtils.clearCalendarTimePart(calDate1); - CommonPluginUtils.clearCalendarTimePart(calDate2); - - Date date1 = calDate1.getTime(); - Date date2 = calDate2.getTime(); - Date windowsDate = calWindowsDate.getTime(); - - int comparacion = date1.compareTo(windowsDate); - - if(comparacion < 0){ - comparacion = date1.compareTo(date2); - - if(comparacion>=0){ - condOK = true; - } - } - - if (!condOK) { - // Formats date to current locale, for display the Exception. - SimpleDateFormat defaultFormatter = new SimpleDateFormat( - ap.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT) - ); - SimpleDateFormat formatter = new SimpleDateFormat( - ap.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT), locale - ); - - String errorMsg = ""; - - try { - errorMsg = " ( Between " + formatter.format(date2) + " and " + formatter.format(windowsDate) + " )"; - } catch (IllegalArgumentException e) { - try { - errorMsg = " ( Between " + defaultFormatter.format(date2) + " and " + defaultFormatter.format(windowsDate) + " )"; - } catch (Exception e1) { - errorMsg = " ( Between " + date2 + " and " + windowsDate + " )"; - } - } - - this.setExceptionMessage( - fldDate1, - fldDate1.getName() + " is not within " + fldDate2.getName() + ", more " + window + " days. " + errorMsg, - fldDate1.getName() + " is not within " + fldDate2.getName() + ", more " + window + " days. " + errorMsg - ); - } - } else { - // If any of fields are null, validates if the field is required. Otherwise, doesn't throws an Exception. - if (objDate1 == null) { - validateRequired(fldDate1); - } - - if (objDate2 == null) { - validateRequired(fldDate2); - } - } - } - - /** - * @param fldDate - * - * Throws an Exception if the field is null, but it is required. - */ - private void validateRequired(Field fldDate){ - if (CommonPluginUtils.isFieldRequired(getIssue(), fldDate)) { - this.setExceptionMessage( - fldDate, - fldDate.getName() + " is required.", - fldDate.getName() + " is required." - ); - } - } + @Argument("date1Selected") + private String date1; + + @Argument("date2Selected") + private String date2; + + @Argument + private String windowsDays; + + /* (non-Javadoc) + * @see com.googlecode.jsu.workflow.validator.GenericValidator#validate() + */ + protected void validate() throws InvalidInputException, WorkflowException { + Field fldDate1 = WorkflowUtils.getFieldFromKey(date1); + Field fldDate2 = WorkflowUtils.getFieldFromKey(date2); + + // Compare Dates. + if ((fldDate1 != null) && (fldDate2 != null)) { + checkDatesCondition(fldDate1, fldDate2, windowsDays); + } + } + + /** + * @param fldDate1 + * @param fldDate2 + * @param window + * + * It makes the comparison properly this. + */ + private void checkDatesCondition(Field fldDate1, Field fldDate2, String window) { + boolean condOK = false; + + Object objDate1 = WorkflowUtils.getFieldValueFromIssue(getIssue(), fldDate1); + Object objDate2 = WorkflowUtils.getFieldValueFromIssue(getIssue(), fldDate2); + + if ((objDate1 != null) && (objDate2 != null)) { + // It Takes the Locale for inicialize dates. + ApplicationProperties ap = ManagerFactory.getApplicationProperties(); + Locale locale = ap.getDefaultLocale(); + + Calendar calDate1 = Calendar.getInstance(locale); + Calendar calDate2 = Calendar.getInstance(locale); + Calendar calWindowsDate = Calendar.getInstance(locale); + + calDate1.setTime((Date) objDate1); + calDate2.setTime((Date) objDate2); + calWindowsDate.setTime((Date) objDate2); + calWindowsDate.add(Calendar.DATE, Integer.parseInt(window)); + + CommonPluginUtils.clearCalendarTimePart(calDate1); + CommonPluginUtils.clearCalendarTimePart(calDate2); + + Date date1 = calDate1.getTime(); + Date date2 = calDate2.getTime(); + Date windowsDate = calWindowsDate.getTime(); + + int comparacion = date1.compareTo(windowsDate); + + if(comparacion < 0){ + comparacion = date1.compareTo(date2); + + if(comparacion>=0){ + condOK = true; + } + } + + if (!condOK) { + // Formats date to current locale, for display the Exception. + SimpleDateFormat defaultFormatter = new SimpleDateFormat( + ap.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT) + ); + SimpleDateFormat formatter = new SimpleDateFormat( + ap.getDefaultString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT), locale + ); + + String errorMsg = ""; + + try { + errorMsg = " ( Between " + formatter.format(date2) + " and " + formatter.format(windowsDate) + " )"; + } catch (IllegalArgumentException e) { + try { + errorMsg = " ( Between " + defaultFormatter.format(date2) + " and " + defaultFormatter.format(windowsDate) + " )"; + } catch (Exception e1) { + errorMsg = " ( Between " + date2 + " and " + windowsDate + " )"; + } + } + + this.setExceptionMessage( + fldDate1, + fldDate1.getName() + " is not within " + fldDate2.getName() + ", more " + window + " days. " + errorMsg, + fldDate1.getName() + " is not within " + fldDate2.getName() + ", more " + window + " days. " + errorMsg + ); + } + } else { + // If any of fields are null, validates if the field is required. Otherwise, doesn't throws an Exception. + if (objDate1 == null) { + validateRequired(fldDate1); + } + + if (objDate2 == null) { + validateRequired(fldDate2); + } + } + } + + /** + * @param fldDate + * + * Throws an Exception if the field is null, but it is required. + */ + private void validateRequired(Field fldDate){ + if (CommonPluginUtils.isFieldRequired(getIssue(), fldDate)) { + this.setExceptionMessage( + fldDate, + fldDate.getName() + " is required.", + fldDate.getName() + " is required." + ); + } + } } diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml index 85e446b9..a399522b 100644 --- a/src/main/resources/atlassian-plugin.xml +++ b/src/main/resources/atlassian-plugin.xml @@ -1,35 +1,35 @@ - - + ${project.description} ${project.version} - + - - + - - + + Custom field type for saving locations and showing it at maps. - + - - - - + + + + A single select list for locations. @@ -37,126 +37,126 @@ - - - + + + Search for values using a free text search. - + - - + It allows only users in any given groups to execute the transition. - - com.googlecode.jsu.workflow.condition.UserIsInAnyGroupsCondition - + + com.googlecode.jsu.workflow.condition.UserIsInAnyGroupsCondition + - - - + + It allows to only execute the transition if the given value of the field is equal to a specified value. - - com.googlecode.jsu.workflow.condition.ValueFieldCondition - + + com.googlecode.jsu.workflow.condition.ValueFieldCondition + - - - + + It allows only users in custom field to execute the transition. - - com.googlecode.jsu.workflow.condition.UserIsInCustomFieldCondition - + + com.googlecode.jsu.workflow.condition.UserIsInCustomFieldCondition + - - - - - Compare two date fields during a workflow transition. - - - com.googlecode.jsu.workflow.validator.DateCompareValidator - - - - - - - - - Fields required during a workflow transition. - - - com.googlecode.jsu.workflow.validator.FieldsRequiredValidator - - - - - - - - - It compares two fields dates, adding a window of days to one of them. - - - com.googlecode.jsu.workflow.validator.WindowsDateValidator - - - - - - - - - + + + + + Compare two date fields during a workflow transition. + + + com.googlecode.jsu.workflow.validator.DateCompareValidator + + + + + + + + + Fields required during a workflow transition. + + + com.googlecode.jsu.workflow.validator.FieldsRequiredValidator + + + + + + + + + It compares two fields dates, adding a window of days to one of them. + + + com.googlecode.jsu.workflow.validator.WindowsDateValidator + + + + + + + + + It copies the value of one field to another. - com.googlecode.jsu.workflow.function.CopyValueFromOtherFieldPostFunction + com.googlecode.jsu.workflow.function.CopyValueFromOtherFieldPostFunction true false - true + true false - - - + + + - - + + Updates an issue custom field to a given value. - com.googlecode.jsu.workflow.function.UpdateIssueCustomFieldPostFunction + com.googlecode.jsu.workflow.function.UpdateIssueCustomFieldPostFunction true @@ -168,13 +168,13 @@ - + Clear field value. - com.googlecode.jsu.workflow.function.ClearFieldValuePostFunction + com.googlecode.jsu.workflow.function.ClearFieldValuePostFunction true @@ -185,34 +185,34 @@ - - - - - - - - - - - diff --git a/src/test/java/com/googlecode/jsu/helpers/ConditionCheckerFactoryTest.java b/src/test/java/com/googlecode/jsu/helpers/ConditionCheckerFactoryTest.java index 03d80c6c..3aac93d2 100644 --- a/src/test/java/com/googlecode/jsu/helpers/ConditionCheckerFactoryTest.java +++ b/src/test/java/com/googlecode/jsu/helpers/ConditionCheckerFactoryTest.java @@ -14,208 +14,208 @@ * @version $Id$ */ public class ConditionCheckerFactoryTest { - private ConditionCheckerFactory factory; - - @Before - public void initFactory() { - Logger.getLogger("com.googlecode.jsu").setLevel(Level.DEBUG); - - this.factory = new ConditionCheckerFactory(); - } - - @Test - public void numberComparisons() { - final String val1 = "5"; - final String val2 = "10"; - final String val3 = "sss"; - final String val4 = null; - - ConditionChecker checker = factory.getChecker(NUMBER, EQUAL); - - assertTrue(checker.checkValues(val1, val1)); - assertFalse(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val4, val2)); - - checker = factory.getChecker(NUMBER, NOT_EQUAL); - - assertFalse(checker.checkValues(val1, val1)); - assertTrue(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertTrue(checker.checkValues(val4, val2)); - - checker = factory.getChecker(NUMBER, LESS); - - assertFalse(checker.checkValues(val1, val1)); - assertTrue(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val4, val2)); - - checker = factory.getChecker(NUMBER, LESS_EQUAL); - - assertTrue(checker.checkValues(val1, val1)); - assertTrue(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val4, val2)); - - checker = factory.getChecker(NUMBER, GREATER); - - assertFalse(checker.checkValues(val1, val1)); - assertFalse(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val4, val2)); - - checker = factory.getChecker(NUMBER, GREATER_EQUAL); - - assertTrue(checker.checkValues(val1, val1)); - assertFalse(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val4, val2)); - } - - @Test - public void stringComparisons() { - final String val1 = "string_1"; - final String val2 = "string_2"; - final String val3 = "3333"; - final String val4 = null; - - ConditionChecker checker = factory.getChecker(STRING, EQUAL); - - assertTrue(checker.checkValues(val1, val1)); - assertFalse(checker.checkValues(val1, val2)); - assertFalse(checker.checkValues(val1, val3)); - assertFalse(checker.checkValues(val1, val4)); - assertFalse(checker.checkValues(val4, val1)); - - checker = factory.getChecker(STRING, NOT_EQUAL); - - assertFalse(checker.checkValues(val1, val1)); - assertTrue(checker.checkValues(val1, val2)); - assertTrue(checker.checkValues(val1, val3)); - assertTrue(checker.checkValues(val1, val4)); - assertTrue(checker.checkValues(val4, val1)); - } - - @Test - public void dateComparisons() { - final Calendar cal1 = Calendar.getInstance(); - final Calendar cal2 = Calendar.getInstance(); - final Calendar cal3 = Calendar.getInstance(); - final Calendar cal4 = null; - - cal2.add(Calendar.MINUTE, 5); - cal3.add(Calendar.DAY_OF_MONTH, 1); - - ConditionChecker checker = factory.getChecker(DATE, EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE, NOT_EQUAL); - - assertFalse(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertTrue(checker.checkValues(cal4, cal2)); - assertTrue(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE, LESS); - - assertFalse(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE, LESS_EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE, GREATER); - - assertFalse(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE, GREATER_EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - } - - @Test - public void dateWithoutTimeComparisons() { - final Calendar cal1 = Calendar.getInstance(); - final Calendar cal2 = Calendar.getInstance(); - final Calendar cal3 = Calendar.getInstance(); - final Calendar cal4 = null; - - cal1.set(2010, 3, 3, 10, 0, 45); - cal2.set(2010, 3, 3, 10, 0, 45); - cal3.set(2010, 3, 3, 10, 0, 45); - - cal2.add(Calendar.MINUTE, 5); - cal3.add(Calendar.DAY_OF_MONTH, 1); - - ConditionChecker checker = factory.getChecker(DATE_WITHOUT_TIME, EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE_WITHOUT_TIME, NOT_EQUAL); - - assertFalse(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertTrue(checker.checkValues(cal4, cal2)); - assertTrue(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE_WITHOUT_TIME, LESS); - - assertFalse(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE_WITHOUT_TIME, LESS_EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertTrue(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE_WITHOUT_TIME, GREATER); - - assertFalse(checker.checkValues(cal1, cal1)); - assertFalse(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - - checker = factory.getChecker(DATE_WITHOUT_TIME, GREATER_EQUAL); - - assertTrue(checker.checkValues(cal1, cal1)); - assertTrue(checker.checkValues(cal1, cal2)); - assertFalse(checker.checkValues(cal1, cal3)); - assertFalse(checker.checkValues(cal4, cal2)); - assertFalse(checker.checkValues(cal2, cal4)); - } + private ConditionCheckerFactory factory; + + @Before + public void initFactory() { + Logger.getLogger("com.googlecode.jsu").setLevel(Level.DEBUG); + + this.factory = new ConditionCheckerFactory(); + } + + @Test + public void numberComparisons() { + final String val1 = "5"; + final String val2 = "10"; + final String val3 = "sss"; + final String val4 = null; + + ConditionChecker checker = factory.getChecker(NUMBER, EQUAL); + + assertTrue(checker.checkValues(val1, val1)); + assertFalse(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val4, val2)); + + checker = factory.getChecker(NUMBER, NOT_EQUAL); + + assertFalse(checker.checkValues(val1, val1)); + assertTrue(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertTrue(checker.checkValues(val4, val2)); + + checker = factory.getChecker(NUMBER, LESS); + + assertFalse(checker.checkValues(val1, val1)); + assertTrue(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val4, val2)); + + checker = factory.getChecker(NUMBER, LESS_EQUAL); + + assertTrue(checker.checkValues(val1, val1)); + assertTrue(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val4, val2)); + + checker = factory.getChecker(NUMBER, GREATER); + + assertFalse(checker.checkValues(val1, val1)); + assertFalse(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val4, val2)); + + checker = factory.getChecker(NUMBER, GREATER_EQUAL); + + assertTrue(checker.checkValues(val1, val1)); + assertFalse(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val4, val2)); + } + + @Test + public void stringComparisons() { + final String val1 = "string_1"; + final String val2 = "string_2"; + final String val3 = "3333"; + final String val4 = null; + + ConditionChecker checker = factory.getChecker(STRING, EQUAL); + + assertTrue(checker.checkValues(val1, val1)); + assertFalse(checker.checkValues(val1, val2)); + assertFalse(checker.checkValues(val1, val3)); + assertFalse(checker.checkValues(val1, val4)); + assertFalse(checker.checkValues(val4, val1)); + + checker = factory.getChecker(STRING, NOT_EQUAL); + + assertFalse(checker.checkValues(val1, val1)); + assertTrue(checker.checkValues(val1, val2)); + assertTrue(checker.checkValues(val1, val3)); + assertTrue(checker.checkValues(val1, val4)); + assertTrue(checker.checkValues(val4, val1)); + } + + @Test + public void dateComparisons() { + final Calendar cal1 = Calendar.getInstance(); + final Calendar cal2 = Calendar.getInstance(); + final Calendar cal3 = Calendar.getInstance(); + final Calendar cal4 = null; + + cal2.add(Calendar.MINUTE, 5); + cal3.add(Calendar.DAY_OF_MONTH, 1); + + ConditionChecker checker = factory.getChecker(DATE, EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE, NOT_EQUAL); + + assertFalse(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertTrue(checker.checkValues(cal4, cal2)); + assertTrue(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE, LESS); + + assertFalse(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE, LESS_EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE, GREATER); + + assertFalse(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE, GREATER_EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + } + + @Test + public void dateWithoutTimeComparisons() { + final Calendar cal1 = Calendar.getInstance(); + final Calendar cal2 = Calendar.getInstance(); + final Calendar cal3 = Calendar.getInstance(); + final Calendar cal4 = null; + + cal1.set(2010, 3, 3, 10, 0, 45); + cal2.set(2010, 3, 3, 10, 0, 45); + cal3.set(2010, 3, 3, 10, 0, 45); + + cal2.add(Calendar.MINUTE, 5); + cal3.add(Calendar.DAY_OF_MONTH, 1); + + ConditionChecker checker = factory.getChecker(DATE_WITHOUT_TIME, EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE_WITHOUT_TIME, NOT_EQUAL); + + assertFalse(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertTrue(checker.checkValues(cal4, cal2)); + assertTrue(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE_WITHOUT_TIME, LESS); + + assertFalse(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE_WITHOUT_TIME, LESS_EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertTrue(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE_WITHOUT_TIME, GREATER); + + assertFalse(checker.checkValues(cal1, cal1)); + assertFalse(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + + checker = factory.getChecker(DATE_WITHOUT_TIME, GREATER_EQUAL); + + assertTrue(checker.checkValues(cal1, cal1)); + assertTrue(checker.checkValues(cal1, cal2)); + assertFalse(checker.checkValues(cal1, cal3)); + assertFalse(checker.checkValues(cal4, cal2)); + assertFalse(checker.checkValues(cal2, cal4)); + } } diff --git a/src/test/resources/cactus.properties b/src/test/resources/cactus.properties deleted file mode 100644 index 6825e498..00000000 --- a/src/test/resources/cactus.properties +++ /dev/null @@ -1 +0,0 @@ -cactus.contextURL = http://localhost:8081/ \ No newline at end of file