Skip to content
Snippets Groups Projects
Commit 476aa66d authored by jakubs's avatar jakubs
Browse files

BIS-173 improve entity validation, to stop validation when some validation have already failed

SVN: 26621
parent 649ce5fb
No related branches found
No related tags found
No related merge requests found
...@@ -72,6 +72,8 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements ...@@ -72,6 +72,8 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements
totalEntitiesToValidateCount = 0; totalEntitiesToValidateCount = 0;
entitiesValidatedCount = 0; entitiesValidatedCount = 0;
isRolledBack = false;
} }
IHibernateTransactionManagerCallback callback; IHibernateTransactionManagerCallback callback;
...@@ -104,6 +106,12 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements ...@@ -104,6 +106,12 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements
int entitiesValidatedCount; int entitiesValidatedCount;
/**
* if true - than it means that at least one validation has failed, and we don't need to do any
* additional validations
*/
private boolean isRolledBack;
private void updateListener() private void updateListener()
{ {
progressListener = ServiceConversationsThreadContext.getProgressListener(); progressListener = ServiceConversationsThreadContext.getProgressListener();
...@@ -143,12 +151,11 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements ...@@ -143,12 +151,11 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements
IEntityInformationWithPropertiesHolder entity = nextItemToValidate(); IEntityInformationWithPropertiesHolder entity = nextItemToValidate();
validateEntity(tx, entity); validateEntity(tx, entity);
} }
} }
private boolean hasMoreItemsToValidate() private boolean hasMoreItemsToValidate()
{ {
return entitiesToValidate.size() > 0; return entitiesToValidate.size() > 0 && false == isRolledBack;
} }
private IEntityInformationWithPropertiesHolder nextItemToValidate() private IEntityInformationWithPropertiesHolder nextItemToValidate()
...@@ -218,15 +225,19 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements ...@@ -218,15 +225,19 @@ public class EntityValidationInterceptor extends EmptyInterceptor implements
result = calculate(script, entity, isNewEntity); result = calculate(script, entity, isNewEntity);
} catch (Throwable e) } catch (Throwable e)
{ {
callback.rollbackTransaction(tx, "Validation of " + entityDescription(entity) setRollback(tx, entity, " resulted in error. " + e.getMessage());
+ " resulted in error. " + e.getMessage());
} }
if (result != null) if (result != null)
{ {
callback.rollbackTransaction(tx, "Validation of " + entityDescription(entity) setRollback(tx, entity, " failed. " + result);
+ " failed. " + result);
} }
}
private void setRollback(Transaction tx, IEntityInformationWithPropertiesHolder entity,
String msg)
{
callback.rollbackTransaction(tx, "Validation of " + entityDescription(entity) + msg);
isRolledBack = true;
} }
private String entityDescription(IEntityInformationWithPropertiesHolder entity) private String entityDescription(IEntityInformationWithPropertiesHolder entity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment