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

Added possibility to use dynamic properties to define the property range

of another dynamic property.
parent f2c650ef
......@@ -2,6 +2,7 @@
-----
* Catch exception thrown when trying to format a invalid float value (avoid a client crash : see brisp 03 nov 2016).
* 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
-----
......
......@@ -18,26 +18,30 @@
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.PropertyManager;
import fr.ill.ics.core.property.parser.descriptor.ConditionDescriptor;
import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.exception.PropertyNotFoundException;
public class RangePropertyDependentCondition implements IPropertyCondition {
private String minPropertyName;
private String maxPropertyName;
private Property property;
private Property minProperty;
private Property maxProperty;
private boolean minPropertyExcluded;
private boolean maxPropertyExcluded;
private boolean isDynamic; // concerns main property (the one stored in "property" attribute)
private int index;
public RangePropertyDependentCondition(Property property, ConditionDescriptor conditionDescriptor, boolean isDynamic) {
this.property = property;
......@@ -46,10 +50,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
this.minPropertyExcluded = conditionDescriptor.getMinPropertyExcluded();
this.maxPropertyExcluded = conditionDescriptor.getMaxPropertyExcluded();
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) {
try {
if (minProperty == null && maxProperty == null) {
int servantId = -1;
......@@ -59,20 +70,42 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
servantId = PropertyDatabase.getInstance().getServantIdForProperty(property.getPropertyID());
}
if (servantId != -1) {
int minPropertyId = PropertyDatabase.getInstance().getPropertyIdForServant(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);
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) {
double minValue = new Double(minProperty.getValue()).doubleValue();
double maxValue = new Double(maxProperty.getValue()).doubleValue();
double valueToTest = new Double(valueToBeTested).doubleValue();
if (minPropertyExcluded && maxPropertyExcluded) {
return (valueToTest > minValue && valueToTest < maxValue);
}
......@@ -92,17 +125,17 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
}
public String getErrorMessage(String propertyName) {
String minComparator = " >= ";
String maxComparator = " <= ";
if (minPropertyExcluded) {
minComparator = " > ";
}
if (maxPropertyExcluded) {
maxComparator = " < ";
}
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