예제 #1
0
 private void appendTraceHeader(
     StringBuilder sb,
     ExpressionEvaluationContext context,
     ExpressionVariables processedVariables) {
   sb.append("---[ EXPRESSION in ");
   sb.append(context.getContextDescription());
   sb.append("]---------------------------");
   sb.append("\nSources:");
   Collection<Source<?, ?>> sources = context.getSources();
   if (sources == null) {
     sb.append(" null");
   } else {
     for (Source<?, ?> source : sources) {
       sb.append("\n");
       sb.append(source.debugDump(1));
     }
   }
   sb.append("\nVariables:");
   if (processedVariables == null) {
     sb.append(" null");
   } else {
     sb.append("\n");
     sb.append(processedVariables.debugDump(1));
   }
   sb.append("\nOutput definition: ").append(MiscUtil.toString(outputDefinition));
   sb.append("\nEvaluators: ");
   sb.append(shortDebugDump());
 }
예제 #2
0
  @Test
  public void testIterationCondition() throws Exception {
    final String TEST_NAME = "testIterationCondition";
    TestUtil.displayTestTile(TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(TestExpression.class.getName() + "." + TEST_NAME);

    rememberScriptExecutionCount();

    ExpressionType expressionType =
        PrismTestUtil.parseAtomicValue(
            EXPRESSION_ITERATION_CONDITION_FILE, ExpressionType.COMPLEX_TYPE);

    PrismPropertyDefinition<Boolean> outputDefinition =
        new PrismPropertyDefinitionImpl<Boolean>(
            ExpressionConstants.OUTPUT_ELMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression =
        expressionFactory.makeExpression(expressionType, outputDefinition, TEST_NAME, null, result);

    ExpressionVariables variables = new ExpressionVariables();
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
    variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, user);
    variables.addVariableDefinition(ExpressionConstants.VAR_USER, user);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMYFILE);
    variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, account);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, 1);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, "001");

    ExpressionEvaluationContext expressionContext =
        new ExpressionEvaluationContext(null, variables, TEST_NAME, null, result);

    // WHEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple =
        expression.evaluate(expressionContext);

    // THEN
    assertNotNull(outputTriple);
    outputTriple.checkConsistence();

    // Make sure that the script is executed only once. There is no delta in the variables, no need
    // to do it twice.
    assertScriptExecutionIncrement(1);
  }
예제 #3
0
 private ExpressionVariables processInnerVariables(
     ExpressionVariables variables, String contextDescription, Task task, OperationResult result)
     throws SchemaException, ObjectNotFoundException {
   if (expressionType == null
       || expressionType.getVariable() == null
       || expressionType.getVariable().isEmpty()) {
     // shortcut
     return variables;
   }
   ExpressionVariables newVariables = new ExpressionVariables();
   for (Entry<QName, Object> entry : variables.entrySet()) {
     newVariables.addVariableDefinition(entry.getKey(), entry.getValue());
   }
   for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
     QName varName = variableDefType.getName();
     if (varName == null) {
       throw new SchemaException("No variable name in expression in " + contextDescription);
     }
     if (variableDefType.getObjectRef() != null) {
       ObjectReferenceType ref = variableDefType.getObjectRef();
       ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
       ObjectType varObject =
           objectResolver.resolve(
               ref,
               ObjectType.class,
               null,
               "variable " + varName + " in " + contextDescription,
               task,
               result);
       newVariables.addVariableDefinition(varName, varObject);
     } else if (variableDefType.getValue() != null) {
       // Only string is supported now
       Object valueObject = variableDefType.getValue();
       if (valueObject instanceof String) {
         newVariables.addVariableDefinition(varName, valueObject);
       } else if (valueObject instanceof Element) {
         newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent());
       } else if (valueObject instanceof RawType) {
         newVariables.addVariableDefinition(
             varName, ((RawType) valueObject).getParsedValue(null, varName));
       } else {
         throw new SchemaException(
             "Unexpected type "
                 + valueObject.getClass()
                 + " in variable definition "
                 + varName
                 + " in "
                 + contextDescription);
       }
     } else if (variableDefType.getPath() != null) {
       ItemPath itemPath = variableDefType.getPath().getItemPath();
       Object resolvedValue =
           ExpressionUtil.resolvePath(
               itemPath, variables, null, objectResolver, contextDescription, task, result);
       newVariables.addVariableDefinition(varName, resolvedValue);
     } else {
       throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
     }
   }
   return newVariables;
 }