diff options
author | Morgan E. Cook | 2017-03-27 19:03:05 +0000 |
---|---|---|
committer | donald.g.dunne | 2017-04-26 16:24:32 +0000 |
commit | 04f10383525df3879005b5b548fbf752b9ae1b1f (patch) | |
tree | 2b12df04ef2ac1eb5ef0f4210df6dea1a8415f25 /plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee | |
parent | 04678c58c38cc3beaf0e02be268ff9c7b5b06102 (diff) | |
download | org.eclipse.osee-04f10383525df3879005b5b548fbf752b9ae1b1f.tar.gz org.eclipse.osee-04f10383525df3879005b5b548fbf752b9ae1b1f.tar.xz org.eclipse.osee-04f10383525df3879005b5b548fbf752b9ae1b1f.zip |
refactor: Condense ats Number Validation
Signed-off-by: Morgan E. Cook <Morgan.e.cook@boeing.com>
Change-Id: Ic9c268fc90044042af4dac584082777cbae471e7
Diffstat (limited to 'plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee')
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsCoreXWidgetValidatorProvider.java | 3 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXIntegerValidator.java | 41 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXNumberValidator.java (renamed from plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXFloatValidator.java) | 11 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXWidgetValidator.java | 153 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionFloatMinMaxConstraint.java | 51 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionIntMinMaxConstraint.java | 51 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionListMinMaxSelectedConstraint.java | 51 |
7 files changed, 26 insertions, 335 deletions
diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsCoreXWidgetValidatorProvider.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsCoreXWidgetValidatorProvider.java index 9e93b030b88..7e86e2b7984 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsCoreXWidgetValidatorProvider.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsCoreXWidgetValidatorProvider.java @@ -27,8 +27,7 @@ public class AtsCoreXWidgetValidatorProvider implements IAtsXWidgetValidatorProv public Collection<IAtsXWidgetValidator> getValidators() { if (atsValidators == null) { atsValidators = new ArrayList<>(); - atsValidators.add(new AtsXIntegerValidator()); - atsValidators.add(new AtsXFloatValidator()); + atsValidators.add(new AtsXNumberValidator()); atsValidators.add(new AtsXTextValidator()); atsValidators.add(new AtsXDateValidator()); atsValidators.add(new AtsXComboValidator()); diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXIntegerValidator.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXIntegerValidator.java deleted file mode 100644 index 20311f728d1..00000000000 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXIntegerValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ats.core.validator; - -import org.eclipse.osee.ats.api.IAtsServices; -import org.eclipse.osee.ats.api.IAtsWorkItem; -import org.eclipse.osee.ats.api.util.IValueProvider; -import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition; -import org.eclipse.osee.ats.api.workdef.WidgetResult; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; - -/** - * @author Donald G. Dunne - */ -public class AtsXIntegerValidator extends AtsXWidgetValidator { - - @Override - public WidgetResult validateTransition(IAtsWorkItem workItem, IValueProvider provider, IAtsWidgetDefinition widgetDef, IAtsStateDefinition fromStateDef, IAtsStateDefinition toStateDef, IAtsServices atsServices) throws OseeCoreException { - WidgetResult result = WidgetResult.Valid; - if ("XIntegerDam".equals(widgetDef.getXWidgetName())) { - result = validateWidgetIsRequired(provider, widgetDef, fromStateDef, toStateDef); - if (!result.isValid()) { - return result; - } - result = isValidInteger(provider, widgetDef); - if (!result.isValid()) { - return result; - } - } - return result; - } -} diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXFloatValidator.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXNumberValidator.java index 814bee964b9..d976842fdb3 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXFloatValidator.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXNumberValidator.java @@ -21,20 +21,19 @@ import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; /** * @author Donald G. Dunne */ -public class AtsXFloatValidator extends AtsXWidgetValidator { +public class AtsXNumberValidator extends AtsXWidgetValidator { @Override public WidgetResult validateTransition(IAtsWorkItem workItem, IValueProvider provider, IAtsWidgetDefinition widgetDef, IAtsStateDefinition fromStateDef, IAtsStateDefinition toStateDef, IAtsServices atsServices) throws OseeCoreException { WidgetResult result = WidgetResult.Valid; - if ("XFloatDam".equals(widgetDef.getXWidgetName())) { + String name = widgetDef.getXWidgetName(); + + if ("XFloatDam".equals(name) || "XIntegerDam".equals(name)) { result = validateWidgetIsRequired(provider, widgetDef, fromStateDef, toStateDef); if (!result.isValid()) { return result; } - result = isValidFloat(provider, widgetDef); - if (!result.isValid()) { - return result; - } + return isValid(provider, widgetDef); } return result; } diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXWidgetValidator.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXWidgetValidator.java index a7fa8ada8fc..eb6b4da0b7a 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXWidgetValidator.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/validator/AtsXWidgetValidator.java @@ -15,17 +15,14 @@ import org.eclipse.osee.ats.api.IAtsServices; import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.ats.api.util.IValueProvider; import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; -import org.eclipse.osee.ats.api.workdef.IAtsWidgetConstraint; import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition; -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionFloatMinMaxConstraint; -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionIntMinMaxConstraint; -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionListMinMaxSelectedConstraint; import org.eclipse.osee.ats.api.workdef.WidgetOption; import org.eclipse.osee.ats.api.workdef.WidgetResult; import org.eclipse.osee.ats.api.workdef.WidgetStatus; import org.eclipse.osee.ats.api.workflow.transition.IAtsXWidgetValidator; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.DateUtil; +import org.eclipse.osee.framework.jdk.core.util.Lib; /** * @author Donald G. Dunne @@ -62,16 +59,6 @@ public abstract class AtsXWidgetValidator implements IAtsXWidgetValidator { @Override public abstract WidgetResult validateTransition(IAtsWorkItem workItem, IValueProvider valueProvider, IAtsWidgetDefinition widgetDef, IAtsStateDefinition fromStateDef, IAtsStateDefinition toStateDef, IAtsServices services) throws OseeCoreException; - @SuppressWarnings("unchecked") - public <A> A getConstraintOfType(IAtsWidgetDefinition widgetDef, Class<A> clazz) { - for (IAtsWidgetConstraint constraint : widgetDef.getConstraints()) { - if (clazz.isInstance(constraint)) { - return (A) constraint; - } - } - return null; - } - public WidgetResult isValidDate(IValueProvider valueProvider, IAtsWidgetDefinition widgetDef) throws OseeCoreException { for (Date date : valueProvider.getDateValues()) { if (widgetDef.is(WidgetOption.FUTURE_DATE_REQUIRED)) { @@ -84,139 +71,39 @@ public abstract class AtsXWidgetValidator implements IAtsXWidgetValidator { return WidgetResult.Valid; } - public WidgetResult isValidInteger(IValueProvider valueProvider, IAtsWidgetDefinition widgetDef) throws OseeCoreException { + public WidgetResult isValid(IValueProvider valueProvider, IAtsWidgetDefinition widgetDef) { for (String attrStr : valueProvider.getValues()) { - if (!isInteger(attrStr)) { - return new WidgetResult(WidgetStatus.Invalid_Type, widgetDef, "[%s] value [%s] is not a valid integer", - valueProvider.getName(), attrStr); - } - Integer value = getInteger(attrStr); - - Integer minValue = getIntMinValueSet(widgetDef); - Integer maxValue = getIntMaxValueSet(widgetDef); - if (minValue != null && value < minValue) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%d] must be >= [%d]", - valueProvider.getName(), value, minValue); - } else if (maxValue != null && value > maxValue) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%d] must be < [%d]", - valueProvider.getName(), value, maxValue); - } - } - return WidgetResult.Valid; - } - public boolean isInteger(String text) { - return getInteger(text) != null; - } - - public Integer getInteger(String text) { - try { - return new Integer(text); - } catch (NumberFormatException e) { - return null; - } - } - - public WidgetResult isValidFloat(IValueProvider valueProvider, IAtsWidgetDefinition widgetDef) throws OseeCoreException { - for (String attrStr : valueProvider.getValues()) { - if (!isFloat(attrStr)) { - return new WidgetResult(WidgetStatus.Invalid_Type, widgetDef, "[%s] value [%s] is not a valid float", + if (attrStr.matches("[-+]?\\d*\\.?\\d*")) { + WidgetResult result = checkValid(widgetDef, Double.parseDouble(attrStr), valueProvider.getName()); + if(!result.isValid()) { + return result; + } + } else { + return new WidgetResult(WidgetStatus.Invalid_Type, widgetDef, "[%s] value [%s] is not a valid number", valueProvider.getName(), attrStr); } - Double value = getFloat(attrStr); - - Double minValue = getFloatMinValueSet(widgetDef); - Double maxValue = getFloatMaxValueSet(widgetDef); - if (minValue != null && value < minValue) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%f] must be >= [%f]", - valueProvider.getName(), value, minValue); - } else if (maxValue != null && value > maxValue) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%f] must be < [%f]", - valueProvider.getName(), value, maxValue); - } } return WidgetResult.Valid; } - public boolean isFloat(String text) { - return getFloat(text) != null; - } - - public Double getFloat(String text) { - try { - return new Double(text); - } catch (NumberFormatException e) { - return null; - } - } - - public Integer getIntMinValueSet(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionIntMinMaxConstraint intCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionIntMinMaxConstraint.class); - if (intCon != null) { - return intCon.getMinValue(); - } - return null; - } + private WidgetResult checkValid(IAtsWidgetDefinition widgetDef, double value, String valueProviderName) { + Double minValue = widgetDef.getMin(); + Double maxValue = widgetDef.getMax(); - public Integer getIntMaxValueSet(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionIntMinMaxConstraint intCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionIntMinMaxConstraint.class); - if (intCon != null) { - return intCon.getMaxValue(); + if (minValue != null && Lib.lessThan(value, minValue)) { + return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%s] must be >= [%s]", + valueProviderName, value, minValue); + } else if (maxValue != null && Lib.greaterThan(value, maxValue)) { + return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] value [%s] must be <= [%s]", + valueProviderName, value, minValue, maxValue); } - return null; - } - public Double getFloatMinValueSet(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionFloatMinMaxConstraint floatCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionFloatMinMaxConstraint.class); - if (floatCon != null) { - return floatCon.getMinValue(); - } - return null; - } - - public Double getFloatMaxValueSet(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionFloatMinMaxConstraint floatCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionFloatMinMaxConstraint.class); - if (floatCon != null) { - return floatCon.getMaxValue(); - } - return null; - } - - public Integer getListMinSelected(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionListMinMaxSelectedConstraint intCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionListMinMaxSelectedConstraint.class); - if (intCon != null) { - return intCon.getMinSelected(); - } - return null; - } - - public Integer getListMaxSelected(IAtsWidgetDefinition widgetDef) { - IAtsWidgetDefinitionListMinMaxSelectedConstraint intCon = - getConstraintOfType(widgetDef, IAtsWidgetDefinitionListMinMaxSelectedConstraint.class); - if (intCon != null) { - return intCon.getMaxSelected(); - } - return null; + return WidgetResult.Valid; } public WidgetResult isValidList(IValueProvider valueProvider, IAtsWidgetDefinition widgetDef) throws OseeCoreException { - int selected = valueProvider.getValues().size(); - - Integer minSelected = getListMinSelected(widgetDef); - Integer maxSelected = getListMaxSelected(widgetDef); - if (minSelected != null && selected < minSelected) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] values selected [%d] must be >= [%d]", - valueProvider.getName(), selected, minSelected); - } else if (maxSelected != null && selected > maxSelected) { - return new WidgetResult(WidgetStatus.Invalid_Range, widgetDef, "[%s] values selected [%d] must be < [%d]", - valueProvider.getName(), selected, maxSelected); - } - return WidgetResult.Valid; + return checkValid(widgetDef, valueProvider.getValues().size(), valueProvider.getName()); } } diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionFloatMinMaxConstraint.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionFloatMinMaxConstraint.java deleted file mode 100644 index aaaad5e47b0..00000000000 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionFloatMinMaxConstraint.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ats.core.workdef; - -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionFloatMinMaxConstraint; - -/** - * @author Donald G. Dunne - */ -public class SimpleWidgetDefinitionFloatMinMaxConstraint implements IAtsWidgetDefinitionFloatMinMaxConstraint { - private Double minValue = null; - private Double maxValue = null; - - public SimpleWidgetDefinitionFloatMinMaxConstraint(Double minValue, Double maxValue) { - set(minValue, maxValue); - } - - public SimpleWidgetDefinitionFloatMinMaxConstraint(String minValue, String maxValue) { - if (minValue != null) { - this.minValue = new Double(minValue); - } - if (maxValue != null) { - this.maxValue = new Double(maxValue); - } - } - - @Override - public void set(Double minValue, Double maxValue) { - this.minValue = minValue; - this.maxValue = maxValue; - } - - @Override - public Double getMinValue() { - return minValue; - } - - @Override - public Double getMaxValue() { - return maxValue; - } - -} diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionIntMinMaxConstraint.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionIntMinMaxConstraint.java deleted file mode 100644 index 1a95dd4812d..00000000000 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionIntMinMaxConstraint.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ats.core.workdef; - -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionIntMinMaxConstraint; - -/** - * @author Donald G. Dunne - */ -public class SimpleWidgetDefinitionIntMinMaxConstraint implements IAtsWidgetDefinitionIntMinMaxConstraint { - private Integer minValue = null; - private Integer maxValue = null; - - public SimpleWidgetDefinitionIntMinMaxConstraint(Integer minValue, Integer maxValue) { - set(minValue, maxValue); - } - - public SimpleWidgetDefinitionIntMinMaxConstraint(String minValue, String maxValue) { - if (minValue != null) { - this.minValue = new Integer(minValue); - } - if (maxValue != null) { - this.maxValue = new Integer(maxValue); - } - } - - @Override - public void set(Integer minValue, Integer maxValue) { - this.minValue = minValue; - this.maxValue = maxValue; - } - - @Override - public Integer getMinValue() { - return minValue; - } - - @Override - public Integer getMaxValue() { - return maxValue; - } - -} diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionListMinMaxSelectedConstraint.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionListMinMaxSelectedConstraint.java deleted file mode 100644 index 8bbe674cad8..00000000000 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workdef/SimpleWidgetDefinitionListMinMaxSelectedConstraint.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ats.core.workdef; - -import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinitionListMinMaxSelectedConstraint; - -/** - * @author Donald G. Dunne - */ -public class SimpleWidgetDefinitionListMinMaxSelectedConstraint implements IAtsWidgetDefinitionListMinMaxSelectedConstraint { - private Integer minSelected = null; - private Integer maxSelected = null; - - public SimpleWidgetDefinitionListMinMaxSelectedConstraint(Integer minSelected, Integer maxSelected) { - set(minSelected, maxSelected); - } - - public SimpleWidgetDefinitionListMinMaxSelectedConstraint(String minSelected, String maxSelected) { - if (minSelected != null) { - this.minSelected = new Integer(minSelected); - } - if (maxSelected != null) { - this.maxSelected = new Integer(maxSelected); - } - } - - @Override - public void set(Integer minSelected, Integer maxSelected) { - this.minSelected = minSelected; - this.maxSelected = maxSelected; - } - - @Override - public Integer getMinSelected() { - return minSelected; - } - - @Override - public Integer getMaxSelected() { - return maxSelected; - } - -} |