Map<SLeftOperand, LeftOperandUpdateStatus> executeOperators(final List<SOperation> operations, final SExpressionContext expressionContext) throws SOperationExecutionException { final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandsToUpdate = new HashMap<>(); for (int i = 0; i < operations.size(); i++) { final SOperation currentOperation = operations.get(i); final boolean shouldPersistValue = persistRightOperandResolver.shouldPersistByPosition(i, operations); final LeftOperandUpdateStatus currentUpdateStatus = calculateRightOperandValue(currentOperation, expressionContext, shouldPersistValue); if (shouldUpdateLeftOperandContext(leftOperandsToUpdate, currentOperation.getLeftOperand(), currentUpdateStatus)) { leftOperandsToUpdate.put(currentOperation.getLeftOperand(), currentUpdateStatus); } } return leftOperandsToUpdate; }
@Override public void execute(final SOperation operation, final long containerId, final String containerType, final SExpressionContext expressionContext) throws SOperationExecutionException { execute(Arrays.asList(operation), containerId, containerType, expressionContext); }
@Override public void execute(final List<SOperation> operations, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { if (operations.isEmpty()) { return; } // retrieve all left operand to set and put it in context retrieveLeftOperandsAndPutItInExpressionContextIfNotIn(operations, leftOperandContainerId, leftOperandContainerType, expressionContext); // execute operation and put it in context again final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandUpdates = executeOperators(operations, expressionContext); // update data updateLeftOperands(leftOperandUpdates, leftOperandContainerId, leftOperandContainerType, expressionContext); }
private LeftOperandUpdateStatus calculateRightOperandValue(final SOperation operation, final SExpressionContext expressionContext, boolean shouldPersistValue) throws SOperationExecutionException { final SLeftOperand leftOperand = operation.getLeftOperand(); final LeftOperandUpdateStatus currentUpdateStatus = new LeftOperandUpdateStatus(operation.getType()); if (currentUpdateStatus.shouldUpdate()) { final OperationExecutorStrategy operationExecutorStrategy = operationExecutorStrategyProvider.getOperationExecutorStrategy(operation); final Object rightOperandValue = evaluateRightOperandExpression(operation, expressionContext, operation.getRightOperand()); shouldPersistValue = persistRightOperandResolver .shouldPersistByValue(rightOperandValue, shouldPersistValue, operationExecutorStrategy.shouldPersistOnNullValue()); final Object value = operationExecutorStrategy.computeNewValueForLeftOperand(operation, rightOperandValue, expressionContext, shouldPersistValue); expressionContext.getInputValues().put(leftOperand.getName(), value); logOperation(TechnicalLogSeverity.DEBUG, operation, rightOperandValue, expressionContext); } return currentUpdateStatus; }
void updateLeftOperands(final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandUpdates, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { for (final Entry<SLeftOperand, LeftOperandUpdateStatus> update : leftOperandUpdates.entrySet()) { final SLeftOperand leftOperand = update.getKey(); final LeftOperandHandler leftOperandHandler = getLeftOperandHandler(leftOperand.getType()); if (update.getValue().shouldUpdate()) { leftOperandHandler.update(leftOperand, expressionContext.getInputValues(), expressionContext.getInputValues().get(leftOperand.getName()), leftOperandContainerId, leftOperandContainerType); } else { leftOperandHandler.delete(leftOperand, leftOperandContainerId, leftOperandContainerType); } } }
private void logOperation(final TechnicalLogSeverity severity, final SOperation operation, final Object operationValue, final SExpressionContext expressionContext) { if (logger.isLoggable(this.getClass(), severity)) { final String message = buildLogMessage(operation, operationValue, expressionContext); logger.log(this.getClass(), severity, message); } }
private LeftOperandUpdateStatus calculateRightOperandValue(final SOperation operation, final SExpressionContext expressionContext, boolean shouldPersistValue) throws SOperationExecutionException { final SLeftOperand leftOperand = operation.getLeftOperand(); final LeftOperandUpdateStatus currentUpdateStatus = new LeftOperandUpdateStatus(operation.getType()); if (currentUpdateStatus.shouldUpdate()) { final OperationExecutorStrategy operationExecutorStrategy = operationExecutorStrategyProvider.getOperationExecutorStrategy(operation); final Object rightOperandValue = evaluateRightOperandExpression(operation, expressionContext, operation.getRightOperand()); shouldPersistValue = persistRightOperandResolver .shouldPersistByValue(rightOperandValue, shouldPersistValue, operationExecutorStrategy.shouldPersistOnNullValue()); final Object value = operationExecutorStrategy.computeNewValueForLeftOperand(operation, rightOperandValue, expressionContext, shouldPersistValue); expressionContext.getInputValues().put(leftOperand.getName(), value); logOperation(TechnicalLogSeverity.DEBUG, operation, rightOperandValue, expressionContext); } return currentUpdateStatus; }
void updateLeftOperands(final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandUpdates, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { for (final Entry<SLeftOperand, LeftOperandUpdateStatus> update : leftOperandUpdates.entrySet()) { final SLeftOperand leftOperand = update.getKey(); final LeftOperandHandler leftOperandHandler = getLeftOperandHandler(leftOperand.getType()); if (update.getValue().shouldUpdate()) { leftOperandHandler.update(leftOperand, expressionContext.getInputValues(), expressionContext.getInputValues().get(leftOperand.getName()), leftOperandContainerId, leftOperandContainerType); } else { leftOperandHandler.delete(leftOperand, leftOperandContainerId, leftOperandContainerType); } } }
private void logOperation(final TechnicalLogSeverity severity, final SOperation operation, final Object operationValue, final SExpressionContext expressionContext) { if (logger.isLoggable(this.getClass(), severity)) { final String message = buildLogMessage(operation, operationValue, expressionContext); logger.log(this.getClass(), severity, message); } }
@Override public void execute(final List<SOperation> operations, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { if (operations.isEmpty()) { return; } // retrieve all left operand to set and put it in context retrieveLeftOperandsAndPutItInExpressionContextIfNotIn(operations, leftOperandContainerId, leftOperandContainerType, expressionContext); // execute operation and put it in context again final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandUpdates = executeOperators(operations, expressionContext); // update data updateLeftOperands(leftOperandUpdates, leftOperandContainerId, leftOperandContainerType, expressionContext); }
Map<SLeftOperand, LeftOperandUpdateStatus> executeOperators(final List<SOperation> operations, final SExpressionContext expressionContext) throws SOperationExecutionException { final Map<SLeftOperand, LeftOperandUpdateStatus> leftOperandsToUpdate = new HashMap<>(); for (int i = 0; i < operations.size(); i++) { final SOperation currentOperation = operations.get(i); final boolean shouldPersistValue = persistRightOperandResolver.shouldPersistByPosition(i, operations); final LeftOperandUpdateStatus currentUpdateStatus = calculateRightOperandValue(currentOperation, expressionContext, shouldPersistValue); if (shouldUpdateLeftOperandContext(leftOperandsToUpdate, currentOperation.getLeftOperand(), currentUpdateStatus)) { leftOperandsToUpdate.put(currentOperation.getLeftOperand(), currentUpdateStatus); } } return leftOperandsToUpdate; }
@Override public void execute(final SOperation operation, final long containerId, final String containerType, final SExpressionContext expressionContext) throws SOperationExecutionException { execute(Arrays.asList(operation), containerId, containerType, expressionContext); }
void retrieveLeftOperandsAndPutItInExpressionContextIfNotIn(final List<SOperation> operations, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { //if the container where we execute the operation is not the same than the container of the expression (call activity data mapping) we skip the loading of left operand final String containerType = expressionContext.getContainerType(); final Long containerId = expressionContext.getContainerId(); if (containerId == null || containerType == null) { return; } final HashMap<String, List<SLeftOperand>> leftOperandHashMap = new HashMap<>(); for (final SOperation operation : operations) { if (!operation.getType().equals(SOperatorType.ASSIGNMENT)) { // this operation will set a data, we retrieve it and put it in context final SLeftOperand leftOperand = operation.getLeftOperand(); if (!leftOperandHashMap.containsKey(leftOperand.getType())) { leftOperandHashMap.put(leftOperand.getType(), new ArrayList<>()); } leftOperandHashMap.get(leftOperand.getType()).add(leftOperand); } } for (final Entry<String, List<SLeftOperand>> leftOperandByType : leftOperandHashMap.entrySet()) { try { getLeftOperandHandler(leftOperandByType.getKey()) .loadLeftOperandInContext(leftOperandByType.getValue(), leftOperandContainerId, leftOperandContainerType, expressionContext); } catch (final SBonitaReadException e) { throw new SOperationExecutionException("Unable to retrieve value for operation " + leftOperandByType.getValue(), e); } } }
@Override public void execute(final List<SOperation> operations, final SExpressionContext expressionContext) throws SOperationExecutionException { execute(operations, expressionContext.getContainerId(), expressionContext.getContainerType(), expressionContext); }
void retrieveLeftOperandsAndPutItInExpressionContextIfNotIn(final List<SOperation> operations, final long leftOperandContainerId, final String leftOperandContainerType, final SExpressionContext expressionContext) throws SOperationExecutionException { //if the container where we execute the operation is not the same than the container of the expression (call activity data mapping) we skip the loading of left operand final String containerType = expressionContext.getContainerType(); final Long containerId = expressionContext.getContainerId(); if (containerId == null || containerType == null) { return; } final HashMap<String, List<SLeftOperand>> leftOperandHashMap = new HashMap<>(); for (final SOperation operation : operations) { if (!operation.getType().equals(SOperatorType.ASSIGNMENT)) { // this operation will set a data, we retrieve it and put it in context final SLeftOperand leftOperand = operation.getLeftOperand(); if (!leftOperandHashMap.containsKey(leftOperand.getType())) { leftOperandHashMap.put(leftOperand.getType(), new ArrayList<>()); } leftOperandHashMap.get(leftOperand.getType()).add(leftOperand); } } for (final Entry<String, List<SLeftOperand>> leftOperandByType : leftOperandHashMap.entrySet()) { try { getLeftOperandHandler(leftOperandByType.getKey()) .loadLeftOperandInContext(leftOperandByType.getValue(), leftOperandContainerId, leftOperandContainerType, expressionContext); } catch (final SBonitaReadException e) { throw new SOperationExecutionException("Unable to retrieve value for operation " + leftOperandByType.getValue(), e); } } }
@Override public void execute(final List<SOperation> operations, final SExpressionContext expressionContext) throws SOperationExecutionException { execute(operations, expressionContext.getContainerId(), expressionContext.getContainerType(), expressionContext); }