Commit 2ad3a039 authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Added possibility to use dynamic properties to define the property range

of another dynamic property.
parent f2c650ef
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
----- -----
* Catch exception thrown when trying to format a invalid float value (avoid a client crash : see brisp 03 nov 2016). * Catch exception thrown when trying to format a invalid float value (avoid a client crash : see brisp 03 nov 2016).
* Replaced Corba with Cameo. * Replaced Corba with Cameo.
* Added possibility to use dynamic properties to define a property range ("min_property" and "max_property") of a dynamic property.
3.0.4 3.0.4
----- -----
......
...@@ -18,26 +18,30 @@ ...@@ -18,26 +18,30 @@
package fr.ill.ics.core.property.condition; package fr.ill.ics.core.property.condition;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.core.property.Property; import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.PropertyManager; import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.core.property.parser.descriptor.ConditionDescriptor; import fr.ill.ics.core.property.parser.descriptor.ConditionDescriptor;
import fr.ill.ics.nscclient.dataprovider.PropertyDatabase; import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.util.ConfigManager; import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.exception.PropertyNotFoundException;
public class RangePropertyDependentCondition implements IPropertyCondition { public class RangePropertyDependentCondition implements IPropertyCondition {
private String minPropertyName; private String minPropertyName;
private String maxPropertyName; private String maxPropertyName;
private Property property; private Property property;
private Property minProperty; private Property minProperty;
private Property maxProperty; private Property maxProperty;
private boolean minPropertyExcluded; private boolean minPropertyExcluded;
private boolean maxPropertyExcluded; private boolean maxPropertyExcluded;
private boolean isDynamic; // concerns main property (the one stored in "property" attribute) private boolean isDynamic; // concerns main property (the one stored in "property" attribute)
private int index;
public RangePropertyDependentCondition(Property property, ConditionDescriptor conditionDescriptor, boolean isDynamic) { public RangePropertyDependentCondition(Property property, ConditionDescriptor conditionDescriptor, boolean isDynamic) {
this.property = property; this.property = property;
...@@ -46,10 +50,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition { ...@@ -46,10 +50,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
this.minPropertyExcluded = conditionDescriptor.getMinPropertyExcluded(); this.minPropertyExcluded = conditionDescriptor.getMinPropertyExcluded();
this.maxPropertyExcluded = conditionDescriptor.getMaxPropertyExcluded(); this.maxPropertyExcluded = conditionDescriptor.getMaxPropertyExcluded();
this.isDynamic = isDynamic; this.isDynamic = isDynamic;
if (isDynamic) {
try {
this.index = Integer.valueOf(property.getName().substring(property.getName().indexOf(".")+1));
} catch (Exception e) {
this.index = -1;
}
}
} }
public boolean isOk(String valueToBeTested) { public boolean isOk(String valueToBeTested) {
try { try {
if (minProperty == null && maxProperty == null) { if (minProperty == null && maxProperty == null) {
int servantId = -1; int servantId = -1;
...@@ -59,20 +70,42 @@ public class RangePropertyDependentCondition implements IPropertyCondition { ...@@ -59,20 +70,42 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
servantId = PropertyDatabase.getInstance().getServantIdForProperty(property.getPropertyID()); servantId = PropertyDatabase.getInstance().getServantIdForProperty(property.getPropertyID());
} }
if (servantId != -1) { if (servantId != -1) {
int minPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, minPropertyName); int minPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, minPropertyName);
minProperty = PropertyManager.getInstance().getProperty(servantId, minPropertyName); minProperty = PropertyManager.getInstance().getProperty(servantId, minPropertyName);
if (minProperty == null) {
try {
if (index != -1) {
Controller controller = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
minProperty = PropertyManager.getInstance().getDynamicProperty(controller, minPropertyName+"."+index);
}
} catch (PropertyNotFoundException e) {
// not a real problem...
}
}
int maxPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, maxPropertyName); int maxPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, maxPropertyName);
maxProperty = PropertyManager.getInstance().getProperty(servantId, maxPropertyName); maxProperty = PropertyManager.getInstance().getProperty(servantId, maxPropertyName);
if (maxProperty == null) {
try {
if (index != -1) {
Controller controller = ControllerManager.getInstance().getController(property.getControllerNameForDynamic());
maxProperty = PropertyManager.getInstance().getDynamicProperty(controller, maxPropertyName+"."+index);
}
} catch (PropertyNotFoundException e) {
// not a real problem...
}
}
} }
} }
if (minProperty != null && maxProperty != null) { if (minProperty != null && maxProperty != null) {
double minValue = new Double(minProperty.getValue()).doubleValue(); double minValue = new Double(minProperty.getValue()).doubleValue();
double maxValue = new Double(maxProperty.getValue()).doubleValue(); double maxValue = new Double(maxProperty.getValue()).doubleValue();
double valueToTest = new Double(valueToBeTested).doubleValue(); double valueToTest = new Double(valueToBeTested).doubleValue();
if (minPropertyExcluded && maxPropertyExcluded) { if (minPropertyExcluded && maxPropertyExcluded) {
return (valueToTest > minValue && valueToTest < maxValue); return (valueToTest > minValue && valueToTest < maxValue);
} }
...@@ -92,17 +125,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition { ...@@ -92,17 +125,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
} }
public String getErrorMessage(String propertyName) { public String getErrorMessage(String propertyName) {
String minComparator = " >= "; String minComparator = " >= ";
String maxComparator = " <= "; String maxComparator = " <= ";
if (minPropertyExcluded) { if (minPropertyExcluded) {
minComparator = " > "; minComparator = " > ";
} }
if (maxPropertyExcluded) { if (maxPropertyExcluded) {
maxComparator = " < "; maxComparator = " < ";
} }
return propertyName + " " + ConfigManager.getInstance().getString("rangeErrorMessage1") + minComparator + minProperty.getValue() + " " + ConfigManager.getInstance().getString("rangeErrorMessage2") + maxComparator + maxProperty.getValue(); return propertyName + " " + ConfigManager.getInstance().getString("rangeErrorMessage1") + minComparator + minProperty.getValue() + " " + ConfigManager.getInstance().getString("rangeErrorMessage2") + maxComparator + maxProperty.getValue();
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment