Exemplo n.º 1
0
  public void testIsScalarParamReference() {
    assertTrue(ExpressionUtil.isScalarParamReference("params[\"aaa\"]"));
    assertFalse(ExpressionUtil.isScalarParamReference("params[\"\"]"));

    assertFalse(ExpressionUtil.isScalarParamReference("reparams[\"aaa\"]"));
    assertFalse(ExpressionUtil.isScalarParamReference("params[aaa]"));
  }
Exemplo n.º 2
0
 public void testCreateJSDimensionExpression() throws BirtException {
   assertEquals(
       ExpressionUtil.createJSDimensionExpression("abc", "def"), "dimension[\"abc\"][\"def\"]");
   assertEquals(ExpressionUtil.createJSDimensionExpression(null, null), "dimension[\"\"][\"\"]");
   assertEquals(
       ExpressionUtil.createJSDimensionExpression("abc", "def", "ghi"),
       "dimension[\"abc\"][\"def\"][\"ghi\"]");
 }
Exemplo n.º 3
0
 public void testReferedMeasureExpression() throws CoreException {
   assertEquals(ExpressionUtil.getReferencedMeasure("measure[\"m1\"]"), "m1");
   assertEquals(ExpressionUtil.getReferencedMeasure("measure[\"m1\"]+measure[\"m2\"]"), "m1");
   Set str =
       ExpressionUtil.getAllReferencedMeasures("measure[\"m1\"]+ measure[\"m2\"]*measure[\"m3\"]");
   assertEquals(str.contains("m1"), true);
   assertEquals(str.contains("m2"), true);
   assertEquals(str.contains("m3"), true);
   Set set =
       ExpressionUtil.getAllReferencedMeasures("measure[\"m1\"]/measure[\"m2\"]*measure[\"m2\"]");
   assertEquals(set.contains("m1"), true);
   assertEquals(set.contains("m2"), true);
   assertEquals(set.contains("m3"), false);
 }
Exemplo n.º 4
0
 public void testGetColumnBindingName() throws BirtException {
   assertTrue(ExpressionUtil.getColumnBindingName("100") == null);
   assertTrue(ExpressionUtil.getColumnBindingName("row[\"col1\"]").equals("col1"));
   assertTrue(ExpressionUtil.getColumnBindingName("row[\"col1\"+1]").equals("col11"));
   assertTrue(ExpressionUtil.getColumnBindingName("row[\"col1\"]+ \"abc\"") == null);
   assertTrue(ExpressionUtil.getColumnBindingName("row[0]") == null);
   assertTrue(ExpressionUtil.getColumnBindingName("row.col1").equals("col1"));
   assertTrue(ExpressionUtil.getColumnBindingName("100+row[\"col1\"]") == null);
   assertTrue(ExpressionUtil.getColumnBindingName("Total.sum( row[\"col1\"])") == null);
   assertTrue(ExpressionUtil.getColumnBindingName("row[\"col1\"]+ row[\"col2\"]") == null);
 }
 /**
  * When the import or the report language of the report changes then al the cache for the report
  * is discarded
  */
 @Override
 public void propertyChange(PropertyChangeEvent evt) {
   if (evt.getPropertyName().equals(JasperDesign.PROPERTY_IMPORTS)
       || evt.getPropertyName().equals(JasperDesign.PROPERTY_LANGUAGE)) {
     ExpressionUtil.removeAllReportInterpreters(reportConfiguration);
   }
 }
Exemplo n.º 6
0
  public static FieldValue evaluate(
      DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context) {
    List<ParameterField> parameterFields = defineFunction.getParameterFields();

    if (parameterFields.size() < 1) {
      throw new InvalidFeatureException(defineFunction);
    } // End if

    if (parameterFields.size() != values.size()) {
      throw new EvaluationException();
    }

    FunctionEvaluationContext functionContext = new FunctionEvaluationContext(context);

    for (int i = 0; i < parameterFields.size(); i++) {
      ParameterField parameterField = parameterFields.get(i);

      FieldValue value = FieldValueUtil.refine(parameterField, values.get(i));

      functionContext.declare(parameterField.getName(), value);
    }

    Expression expression = defineFunction.getExpression();
    if (expression == null) {
      throw new InvalidFeatureException(defineFunction);
    }

    FieldValue result = ExpressionUtil.evaluate(expression, functionContext);

    return FieldValueUtil.refine(defineFunction.getDataType(), defineFunction.getOptype(), result);
  }
Exemplo n.º 7
0
  public void testreplaceRowsExpression() {
    String[] oldExpressions =
        new String[] {
          null,
          "   " + Messages.getString("ExpressionUtilTest.old.13"),
          Messages.getString("ExpressionUtilTest.old.14"),
          Messages.getString("ExpressionUtilTest.old.15"),
          Messages.getString("ExpressionUtilTest.old.16"),
          Messages.getString("ExpressionUtilTest.old.17"),
          Messages.getString("ExpressionUtilTest.old.18"),
          Messages.getString("ExpressionUtilTest.old.19"),
          Messages.getString("ExpressionUtilTest.old.20"),
          Messages.getString("ExpressionUtilTest.old.21"),
          Messages.getString("ExpressionUtilTest.old.22"),
          Messages.getString("ExpressionUtilTest.old.23"),
          Messages.getString("ExpressionUtilTest.old.24"),
          Messages.getString("ExpressionUtilTest.old.25")
        };

    String[] newExpressions =
        new String[] {
          null,
          "   " + Messages.getString("ExpressionUtilTest.new.13"),
          Messages.getString("ExpressionUtilTest.new.14"),
          Messages.getString("ExpressionUtilTest.new.15"),
          Messages.getString("ExpressionUtilTest.new.16"),
          Messages.getString("ExpressionUtilTest.new.17"),
          Messages.getString("ExpressionUtilTest.new.18"),
          Messages.getString("ExpressionUtilTest.new.19"),
          Messages.getString("ExpressionUtilTest.new.20"),
          Messages.getString("ExpressionUtilTest.new.21"),
          Messages.getString("ExpressionUtilTest.new.22"),
          Messages.getString("ExpressionUtilTest.new.23"),
          Messages.getString("ExpressionUtilTest.new.24"),
          Messages.getString("ExpressionUtilTest.new.25"),
        };

    for (int i = 0; i < oldExpressions.length; i++) {
      assertEquals(
          ExpressionUtil.updateParentQueryReferenceExpression(oldExpressions[i], false),
          newExpressions[i]);
    }

    String paramBinding = "rows[0].abc";
    String result = "row.abc";
    assertEquals(ExpressionUtil.updateParentQueryReferenceExpression(paramBinding, true), result);
  }
Exemplo n.º 8
0
 // Even though this function applies generally to expressions and tables
 // and not just to TVEs as such, it is somewhat TVE-related because TVEs
 // represent the points where expression trees depend on tables.
 public static boolean isOperandDependentOnTable(AbstractExpression expr, String tableAlias) {
   assert (tableAlias != null);
   for (TupleValueExpression tve : ExpressionUtil.getTupleValueExpressions(expr)) {
     if (tableAlias.equals(tve.getTableAlias())) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 9
0
 // Even though this function applies generally to expressions and tables and not just to TVEs as
 // such,
 // this function is somewhat TVE-related because TVEs DO represent the points where expression
 // trees
 // depend on tables.
 public static boolean isOperandDependentOnTable(AbstractExpression expr, Table table) {
   for (TupleValueExpression tve : ExpressionUtil.getTupleValueExpressions(expr)) {
     // TODO: This clumsy testing of table names regardless of table aliases is
     // EXACTLY why we can't have nice things like self-joins.
     if (table.getTypeName().equals(tve.getTableName())) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 10
0
 public void testReplaceParameterExpression() {
   assertEquals(
       ExpressionUtil.replaceParameterName("params[\"param\"]", "param", "PARAM"),
       "params[\"PARAM\"]");
   assertEquals(
       ExpressionUtil.replaceParameterName(
           "params[\"param1\"]+ params[\"param2\"]", "param2", "PARAM2"),
       "params[\"param1\"]+ params[\"PARAM2\"]");
   assertEquals(
       ExpressionUtil.replaceParameterName("123+ params[\"param2\"]", "param2", "PARAM2"),
       "123+ params[\"PARAM2\"]");
   assertEquals(
       ExpressionUtil.replaceParameterName(
           "params.param1+ params[\"param2\"]", "param2", "PARAM2"),
       "params.param1+ params[\"PARAM2\"]");
   assertEquals(
       ExpressionUtil.replaceParameterName(
           "params.param1.value+ params.param2.value", "param2", "PARAM2"),
       "params.param1.value+ params.PARAM2.value");
 }
Exemplo n.º 11
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    iud.setId("A");
    iud.setVersion(Version.create("1.0.0"));

    String orExpression =
        "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && (pc.name == 'B' || pc.name == 'C'))";
    IExpression expr = ExpressionUtil.parse(orExpression);
    IMatchExpression matchExpression = ExpressionUtil.getFactory().matchExpression(expr);

    Collection<IMatchExpression<IInstallableUnit>> updateExpression =
        new ArrayList<IMatchExpression<IInstallableUnit>>();
    updateExpression.add(matchExpression);
    iud.setUpdateDescriptor(
        MetadataFactory.createUpdateDescriptor(
            updateExpression, IUpdateDescriptor.HIGH, (String) null, (URI) null));
    iua = MetadataFactory.createInstallableUnit(iud);

    Collection<IInstallableUnit> ius = new ArrayList<IInstallableUnit>();
    ius.add(iua);
    URI repoURI = getTempFolder().toURI();
    createMetadataRepository(repoURI, null).addInstallableUnits(ius);
    getMetadataRepositoryManager().removeRepository(repoURI);

    x =
        getMetadataRepositoryManager()
            .loadRepository(repoURI, null)
            .query(QueryUtil.ALL_UNITS, null)
            .iterator()
            .next()
            .getUpdateDescriptor()
            .getIUsBeingUpdated();
    assertEquals(matchExpression, x.iterator().next());
  }
Exemplo n.º 12
0
  public void testToNewExpression() {
    String[] oldExpressions =
        new String[] {
          null,
          "   " + Messages.getString("ExpressionUtilTest.old.0"),
          Messages.getString("ExpressionUtilTest.old.1"),
          Messages.getString("ExpressionUtilTest.old.2"),
          Messages.getString("ExpressionUtilTest.old.3"),
          Messages.getString("ExpressionUtilTest.old.4"),
          Messages.getString("ExpressionUtilTest.old.5"),
          Messages.getString("ExpressionUtilTest.old.6"),
          Messages.getString("ExpressionUtilTest.old.7"),
          Messages.getString("ExpressionUtilTest.old.8"),
          Messages.getString("ExpressionUtilTest.old.9"),
          Messages.getString("ExpressionUtilTest.old.10"),
          Messages.getString("ExpressionUtilTest.old.11"),
          Messages.getString("ExpressionUtilTest.old.12")
        };

    String[] newExpressions =
        new String[] {
          null,
          "   " + Messages.getString("ExpressionUtilTest.new.0"),
          Messages.getString("ExpressionUtilTest.new.1"),
          Messages.getString("ExpressionUtilTest.new.2"),
          Messages.getString("ExpressionUtilTest.new.3"),
          Messages.getString("ExpressionUtilTest.new.4"),
          Messages.getString("ExpressionUtilTest.new.5"),
          Messages.getString("ExpressionUtilTest.new.6"),
          Messages.getString("ExpressionUtilTest.new.7"),
          Messages.getString("ExpressionUtilTest.new.8"),
          Messages.getString("ExpressionUtilTest.new.9"),
          Messages.getString("ExpressionUtilTest.new.10"),
          Messages.getString("ExpressionUtilTest.new.11"),
          Messages.getString("ExpressionUtilTest.new.12"),
        };

    for (int i = 0; i < oldExpressions.length; i++) {
      IColumnBinding icb = ExpressionUtil.getColumnBinding(oldExpressions[i]);
      assertEquals(icb.getBoundExpression(), newExpressions[i]);
      assertEquals(icb.getResultSetColumnName(), "COLUMN_" + (i + 1));
    }
  }
  private double[] createInput(EvaluationContext context) {
    SupportVectorMachineModel supportVectorMachineModel = getModel();

    VectorDictionary vectorDictionary = supportVectorMachineModel.getVectorDictionary();

    VectorFields vectorFields = vectorDictionary.getVectorFields();

    List<FieldRef> fieldRefs = vectorFields.getFieldRefs();

    double[] result = new double[fieldRefs.size()];

    for (int i = 0; i < fieldRefs.size(); i++) {
      FieldRef fieldRef = fieldRefs.get(i);

      FieldValue value = ExpressionUtil.evaluate(fieldRef, context);
      if (value == null) {
        throw new MissingValueException(fieldRef.getField(), vectorFields);
      }

      result[i] = (value.asNumber()).doubleValue();
    }

    return result;
  }
Exemplo n.º 14
0
 public void testCreateJSMeasureExpression() throws BirtException {
   assertEquals(ExpressionUtil.createJSMeasureExpression("abc"), "measure[\"abc\"]");
   assertEquals(ExpressionUtil.createJSMeasureExpression(null), "measure[\"\"]");
 }
Exemplo n.º 15
0
  /**
   * Evaluates the {@link Output} element.
   *
   * @param predictions A map of {@link Evaluator#getTargetFields() target field} values.
   * @return A map of {@link Evaluator#getTargetFields() target field} values together with {@link
   *     Evaluator#getOutputFields() output field} values.
   */
  @SuppressWarnings(value = {"fallthrough"})
  public static Map<FieldName, ?> evaluate(
      Map<FieldName, ?> predictions, ModelEvaluationContext context) {
    ModelEvaluator<?> modelEvaluator = context.getModelEvaluator();

    Model model = modelEvaluator.getModel();

    Output output = model.getOutput();
    if (output == null) {
      return predictions;
    }

    Map<FieldName, Object> result = new LinkedHashMap<>(predictions);

    List<OutputField> outputFields = output.getOutputFields();

    outputFields:
    for (OutputField outputField : outputFields) {
      FieldName targetFieldName = outputField.getTargetField();

      Object targetValue = null;

      ResultFeature resultFeature = outputField.getResultFeature();

      String segmentId = outputField.getSegmentId();

      SegmentResult segmentPredictions = null;

      // Load the target value of the specified segment
      if (segmentId != null) {

        if (!(model instanceof MiningModel)) {
          throw new InvalidFeatureException(outputField);
        }

        MiningModelEvaluationContext miningModelContext = (MiningModelEvaluationContext) context;

        segmentPredictions = miningModelContext.getResult(segmentId);

        // "If there is no Segment matching segmentId or if the predicate of the matching Segment
        // evaluated to false, then the result delivered by this OutputField is missing"
        if (segmentPredictions == null) {
          continue outputFields;
        } // End if

        if (targetFieldName != null) {

          if (!segmentPredictions.containsKey(targetFieldName)) {
            throw new MissingValueException(targetFieldName, outputField);
          }

          targetValue = segmentPredictions.get(targetFieldName);
        } else {
          targetValue = segmentPredictions.getTargetValue();
        }
      } else

      // Load the target value
      {
        switch (resultFeature) {
          case ENTITY_ID:
            {
              // "Result feature entityId returns the id of the winning segment"
              if (model instanceof MiningModel) {
                targetValue = TypeUtil.cast(HasEntityId.class, predictions);

                break;
              }
            }
            // Falls through
          default:
            {
              if (targetFieldName == null) {
                targetFieldName = modelEvaluator.getTargetFieldName();
              } // End if

              if (!predictions.containsKey(targetFieldName)) {
                throw new MissingValueException(targetFieldName, outputField);
              }

              targetValue = predictions.get(targetFieldName);
            }
            break;
        }
      }

      // "If the target value is missing, then the result delivered by this OutputField is missing"
      if (targetValue == null) {
        continue outputFields;
      }

      Object value;

      // Perform the requested computation on the target value
      switch (resultFeature) {
        case PREDICTED_VALUE:
          {
            value = getPredictedValue(targetValue);
          }
          break;
        case PREDICTED_DISPLAY_VALUE:
          {
            DataField dataField = modelEvaluator.getDataField(targetFieldName);
            if (dataField == null) {
              throw new MissingFieldException(targetFieldName, outputField);
            }

            Target target = modelEvaluator.getTarget(targetFieldName);

            value = getPredictedDisplayValue(targetValue, dataField, target);
          }
          break;
        case TRANSFORMED_VALUE:
        case DECISION:
          {
            if (segmentId != null) {
              String name = outputField.getValue();
              if (name == null) {
                throw new InvalidFeatureException(outputField);
              }

              Expression expression = outputField.getExpression();
              if (expression != null) {
                throw new InvalidFeatureException(outputField);
              }

              value = segmentPredictions.get(FieldName.create(name));

              break;
            }

            Expression expression = outputField.getExpression();
            if (expression == null) {
              throw new InvalidFeatureException(outputField);
            }

            value = FieldValueUtil.getValue(ExpressionUtil.evaluate(expression, context));
          }
          break;
        case PROBABILITY:
          {
            value = getProbability(targetValue, outputField);
          }
          break;
        case RESIDUAL:
          {
            FieldValue expectedTargetValue = context.evaluate(targetFieldName);
            if (expectedTargetValue == null) {
              throw new MissingValueException(targetFieldName, outputField);
            }

            DataField dataField = modelEvaluator.getDataField(targetFieldName);

            OpType opType = dataField.getOpType();
            switch (opType) {
              case CONTINUOUS:
                value = getContinuousResidual(targetValue, expectedTargetValue);
                break;
              case CATEGORICAL:
                value = getCategoricalResidual(targetValue, expectedTargetValue);
                break;
              default:
                throw new UnsupportedFeatureException(dataField, opType);
            }
          }
          break;
        case CLUSTER_ID:
          {
            value = getClusterId(targetValue);
          }
          break;
        case ENTITY_ID:
          {
            if (targetValue instanceof HasRuleValues) {
              value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.RULE_ID);

              break;
            }

            value = getEntityId(targetValue, outputField);
          }
          break;
        case AFFINITY:
          {
            value = getAffinity(targetValue, outputField);
          }
          break;
        case CLUSTER_AFFINITY:
        case ENTITY_AFFINITY:
          {
            String entityId = outputField.getValue();

            // Select the specified entity instead of the winning entity
            if (entityId != null) {
              value = getAffinity(targetValue, outputField);

              break;
            }

            value = getEntityAffinity(targetValue);
          }
          break;
        case REASON_CODE:
          {
            value = getReasonCode(targetValue, outputField);
          }
          break;
        case RULE_VALUE:
          {
            value = getRuleValue(targetValue, outputField);
          }
          break;
        case ANTECEDENT:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.ANTECEDENT);
          }
          break;
        case CONSEQUENT:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.CONSEQUENT);
          }
          break;
        case RULE:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.RULE);
          }
          break;
        case RULE_ID:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.RULE_ID);
          }
          break;
        case CONFIDENCE:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.CONFIDENCE);
          }
          break;
        case SUPPORT:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.SUPPORT);
          }
          break;
        case LIFT:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.LIFT);
          }
          break;
        case LEVERAGE:
          {
            value = getRuleValue(targetValue, outputField, OutputField.RuleFeature.LEVERAGE);
          }
          break;
        case WARNING:
          {
            value = context.getWarnings();
          }
          break;
        default:
          throw new UnsupportedFeatureException(outputField, resultFeature);
      }

      FieldValue outputValue = FieldValueUtil.create(outputField, value);

      // The result of one output field becomes available to other output fields
      context.declare(outputField.getName(), outputValue);

      result.put(outputField.getName(), FieldValueUtil.getValue(outputValue));
    }

    return result;
  }
Exemplo n.º 16
0
  /** @throws TypeAnalysisException If the data type cannot be determined. */
  public static DataType getDataType(OutputField outputField, ModelEvaluator<?> modelEvaluator) {
    FieldName name = outputField.getName();

    DataType dataType = outputField.getDataType();
    if (dataType != null) {
      return dataType;
    }

    String segmentId = outputField.getSegmentId();
    if (segmentId != null) {
      throw new TypeAnalysisException(outputField);
    }

    ResultFeature resultFeature = outputField.getResultFeature();
    switch (resultFeature) {
      case PREDICTED_VALUE:
      case TRANSFORMED_VALUE:
      case DECISION:
        {
          OutputField evaluatorOutputField = modelEvaluator.getOutputField(name);

          if (!(outputField).equals(evaluatorOutputField)) {
            throw new TypeAnalysisException(outputField);
          }
        }
        break;
      default:
        break;
    } // End switch

    switch (resultFeature) {
      case PREDICTED_VALUE:
        {
          FieldName targetFieldName = outputField.getTargetField();
          if (targetFieldName == null) {
            targetFieldName = modelEvaluator.getTargetFieldName();
          }

          DataField dataField = modelEvaluator.getDataField(targetFieldName);
          if (dataField == null) {
            throw new MissingFieldException(targetFieldName, outputField);
          }

          return dataField.getDataType();
        }
      case PREDICTED_DISPLAY_VALUE:
        {
          return DataType.STRING; // XXX
        }
      case TRANSFORMED_VALUE:
      case DECISION:
        {
          Expression expression = outputField.getExpression();
          if (expression == null) {
            throw new InvalidFeatureException(outputField);
          }

          return ExpressionUtil.getDataType(expression, modelEvaluator);
        }
      case PROBABILITY:
      case RESIDUAL:
      case STANDARD_ERROR:
        {
          return DataType.DOUBLE;
        }
      case ENTITY_ID:
      case CLUSTER_ID:
        {
          return DataType.STRING;
        }
      case AFFINITY:
      case ENTITY_AFFINITY:
      case CLUSTER_AFFINITY:
        {
          return DataType.DOUBLE;
        }
      case REASON_CODE:
        {
          return DataType.STRING;
        }
      case RULE_VALUE:
        {
          return getRuleDataType(outputField);
        }
      case ANTECEDENT:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.ANTECEDENT);
        }
      case CONSEQUENT:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.CONSEQUENT);
        }
      case RULE:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.RULE);
        }
      case RULE_ID:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.RULE_ID);
        }
      case SUPPORT:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.SUPPORT);
        }
      case CONFIDENCE:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.CONFIDENCE);
        }
      case LIFT:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.LIFT);
        }
      case LEVERAGE:
        {
          return getRuleDataType(outputField, OutputField.RuleFeature.LEVERAGE);
        }
      case WARNING:
        {
          throw new TypeAnalysisException(outputField);
        }
      default:
        throw new UnsupportedFeatureException(outputField, resultFeature);
    }
  }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
0
 public void testCreateExpression() {
   assertEquals("row[\"abc\"]", ExpressionUtil.createRowExpression("abc"));
   assertEquals("row[\"\"]", ExpressionUtil.createRowExpression(null));
   assertEquals("dataSetRow[\"abc\"]", ExpressionUtil.createDataSetRowExpression("abc"));
   assertEquals("dataSetRow[\"\"]", ExpressionUtil.createDataSetRowExpression(null));
 }
Exemplo n.º 19
0
 public void testCreateJSParameterExpression() throws BirtException {
   assertEquals(ExpressionUtil.createJSParameterExpression("abc"), "params[\"abc\"]");
   assertEquals(ExpressionUtil.createJSParameterExpression(null), "params[\"\"]");
 }
Exemplo n.º 20
0
 public void testCreateJSDataSetRowExpression() throws BirtException {
   assertEquals(ExpressionUtil.createJSDataSetRowExpression("abc"), "dataSetRow[\"abc\"]");
   assertEquals(ExpressionUtil.createJSDataSetRowExpression(null), "dataSetRow[\"\"]");
 }