diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index c01b9a07f104225bb0e203e184cbbdc7da74a185..1f08764ec9bc8d3e83ea943baa7bed41bc4bea6a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -2499,8 +2499,6 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt { final List<String> objectsWhichValidationWouldBeForced = new LinkedList<String>(); - // TODO: refactor the check for type of entity requested for validation to the code of - // the caller to avoid duplication beetween here and EntityValidationInterceptor EntityValidationCalculator calculator = EntityValidationCalculator.create(info.getScript(), new IValidationRequestDelegate() @@ -2508,16 +2506,6 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt @Override public void requestValidation(Object o) { - if (o == null) - { - return; - } - if (!(o instanceof IEntityInformationWithPropertiesHolder)) - { - throw new IllegalArgumentException( - "Would try to force validation if illegal object " - + o.getClass()); - } objectsWhichValidationWouldBeForced .add(((IEntityInformationWithPropertiesHolder) o) .getIdentifier()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityValidationInterceptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityValidationInterceptor.java index 84bc81bad255d9527c40cf9a21cae73fc9076ea0..0fea59db33c97452138cfb5ce2d29c031297202a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityValidationInterceptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityValidationInterceptor.java @@ -209,29 +209,19 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements @Override public void requestValidation(Object entity) { - if (entity == null) - { - return; - } - - if (false == entity instanceof IEntityInformationWithPropertiesHolder) - { - throw new IllegalArgumentException( - "Trying to force the validation of an object of invalid type " - + entity.getClass()); - } - if (validatedEntities.contains(entity) || newEntities.contains(entity) || modifiedEntities.contains(entity)) { // forcing validation of entity already listed for validation } else { + IEntityInformationWithPropertiesHolder typedEntity = + (IEntityInformationWithPropertiesHolder) entity; + // we update modified entities to know that we will validate this entity - modifiedEntities.add((IEntityInformationWithPropertiesHolder) entity); + modifiedEntities.add(typedEntity); // we add to the actual validation queue - entitiesToValidate.add((IEntityInformationWithPropertiesHolder) entity); + entitiesToValidate.add(typedEntity); } } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityValidationCalculator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityValidationCalculator.java index 16a64f3129976bf46537c8c17eda6050b2750971..908e39f1ecd6920aa897bdd67435921e8e0a5df3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityValidationCalculator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityValidationCalculator.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calc import ch.systemsx.cisd.common.evaluator.Evaluator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; import ch.systemsx.cisd.openbis.generic.shared.calculator.AbstractCalculator; +import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityInformationWithPropertiesHolder; /** * @author Jakub Straszewski @@ -32,10 +33,10 @@ public class EntityValidationCalculator extends AbstractCalculator private static final String INVOKE_CALCULATE_EXPR = "validate(" + ENTITY_VARIABLE_NAME + ", " + IS_NEW_ENTITY_VARIABLE_NAME + ")"; - private static final String REQUEST_DELEGATE_VARIABLE = "__entityValidationRequestDelegate"; + private static final String CALCULATOR_VARIABLE = "__calculator"; private static final String VALIDATION_REQUEST_FUNCTION = "def requestValidation(entity):\n " - + REQUEST_DELEGATE_VARIABLE + ".requestValidation(entity)\n"; + + CALCULATOR_VARIABLE + ".requestValidation(entity)\n"; public interface IValidationRequestDelegate { @@ -49,22 +50,47 @@ public class EntityValidationCalculator extends AbstractCalculator * "isNewEntity" */ public static EntityValidationCalculator create(String expression, - IValidationRequestDelegate validationRequestedDelegate) + final IValidationRequestDelegate validationRequestedDelegate) { String initialScript = getBasicInitialScript(); initialScript += importFunctions(EntityValidationCalculator.class) + NEWLINE; initialScript += VALIDATION_REQUEST_FUNCTION + NEWLINE; initialScript += expression; String calculatedExpression = INVOKE_CALCULATE_EXPR; + return new EntityValidationCalculator(new Evaluator(calculatedExpression, Math.class, initialScript), validationRequestedDelegate); } public EntityValidationCalculator(Evaluator evaluator, - IValidationRequestDelegate validationRequested) + final IValidationRequestDelegate validationRequested) { super(evaluator); - evaluator.set(REQUEST_DELEGATE_VARIABLE, validationRequested); + + // wrap the request validation with argument checking, so that the implementators of the + // interface can focus on logic + IValidationRequestDelegate wrappedValidationRequestedDelegate = + new IValidationRequestDelegate() + { + @Override + public void requestValidation(Object entity) + { + if (entity == null) + { + return; + } + + if (false == entity instanceof IEntityInformationWithPropertiesHolder) + { + throw new IllegalArgumentException( + "Trying to force the validation of an object of invalid type " + + entity.getClass()); + } + validationRequested.requestValidation(entity); + } + }; + + evaluator.set(CALCULATOR_VARIABLE, wrappedValidationRequestedDelegate); } public void setEntity(IEntityAdaptor entity)