Search in sources :

Example 1 with Expression

use of org.talend.hadoop.distribution.condition.Expression in project tbd-studio-se by Talend.

the class DistributionVersion method getDisplayShowIf.

public String getDisplayShowIf() {
    final Expression trueExp = new BooleanExpression(true);
    final Expression falseExp = new BooleanExpression(false);
    ComponentCondition additionalCondition = displayCondition;
    if (additionalCondition != null && (trueExp.getExpressionString().equals(additionalCondition.getConditionString()) || falseExp.getExpressionString().equals(additionalCondition.getConditionString()))) {
        // Don't show a version if it's display condition is a BooleanCondition.
        return trueExp.getExpressionString().equals(additionalCondition.getConditionString()) ? Boolean.TRUE.toString() : Boolean.FALSE.toString();
    } else {
        // Compose the ComponentCondition to display a version.
        ComponentCondition condition;
        org.talend.hadoop.distribution.condition.Expression e = new BasicExpression(distribution.componentType.getDistributionParameter(), EqualityOperator.EQ, distribution.name);
        if (additionalCondition != null) {
            condition = new MultiComponentCondition(new SimpleComponentCondition(e), BooleanOperator.AND, new NestedComponentCondition(additionalCondition));
        } else {
            condition = new SimpleComponentCondition(e);
        }
        return condition.getConditionString();
    }
}
Also used : BooleanExpression(org.talend.hadoop.distribution.condition.BooleanExpression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) Expression(org.talend.hadoop.distribution.condition.Expression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) BooleanExpression(org.talend.hadoop.distribution.condition.BooleanExpression) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition) ComponentCondition(org.talend.hadoop.distribution.condition.ComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition) Expression(org.talend.hadoop.distribution.condition.Expression)

Example 2 with Expression

use of org.talend.hadoop.distribution.condition.Expression in project tbd-studio-se by Talend.

the class ComponentConditionTest method testGetConditionString.

@Test
public void testGetConditionString() throws Exception {
    ComponentCondition dc1 = new SimpleComponentCondition(new BasicExpression(PARAM_1, VALUE_1, EqualityOperator.EQ));
    assertEquals(dc1.getConditionString(), LEFT_PAR + PARAM_1 + EQ + SINGLE_QUOTE + VALUE_1 + SINGLE_QUOTE + RIGHT_PAR);
    // $NON-NLS-1$ //$NON-NLS-2$
    Expression e1 = new BasicExpression("A", "aaa", EqualityOperator.EQ);
    // $NON-NLS-1$ //$NON-NLS-2$
    Expression e2 = new BasicExpression("Z", "ccc", EqualityOperator.EQ);
    // $NON-NLS-1$ //$NON-NLS-2$
    Expression e3 = new BasicExpression("A", "bbb", EqualityOperator.EQ);
    // $NON-NLS-1$ //$NON-NLS-2$
    Expression e4 = new BasicExpression("B", "ccc", EqualityOperator.NOT_EQ);
    dc1 = new NestedComponentCondition(new MultiComponentCondition(new SimpleComponentCondition(e1), new NestedComponentCondition(new MultiComponentCondition(new SimpleComponentCondition(e4), new NestedComponentCondition(new MultiComponentCondition(new SimpleComponentCondition(e2), new SimpleComponentCondition(e3), BooleanOperator.AND)), BooleanOperator.OR)), BooleanOperator.AND));
    assertEquals(dc1.getConditionString(), result1);
    dc1 = new MultiComponentCondition(new SimpleComponentCondition(e1), new MultiComponentCondition(new SimpleComponentCondition(e2), new NestedComponentCondition(new MultiComponentCondition(new SimpleComponentCondition(e4), new SimpleComponentCondition(e3), BooleanOperator.OR)), BooleanOperator.AND), BooleanOperator.AND);
    assertEquals(dc1.getConditionString(), result2);
}
Also used : BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) Expression(org.talend.hadoop.distribution.condition.Expression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition) ComponentCondition(org.talend.hadoop.distribution.condition.ComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition) Test(org.junit.Test)

Example 3 with Expression

use of org.talend.hadoop.distribution.condition.Expression in project tbd-studio-se by Talend.

the class DistributionVersionModule method getModuleRequiredIf.

public ComponentCondition getModuleRequiredIf() {
    ComponentCondition condition;
    // The import is needed only if the good version and the good distribution are selected, and
    // if the Distribution is shown. The second condition to take the
    // USE_EXISTING_CONNECTIOn into account.
    final ComponentType componentType = distributionVersion.distribution.componentType;
    Expression distributionSelected = new BasicExpression(componentType.getDistributionParameter(), EqualityOperator.EQ, distributionVersion.distribution.name);
    Expression distributionVersionSelected = new BasicExpression(componentType.getVersionParameter(), EqualityOperator.EQ, distributionVersion.version);
    Expression distributionShown = new ShowExpression(componentType.getDistributionParameter());
    condition = new MultiComponentCondition(new SimpleComponentCondition(distributionSelected), BooleanOperator.AND, new MultiComponentCondition(new SimpleComponentCondition(distributionVersionSelected), BooleanOperator.AND, new SimpleComponentCondition(distributionShown)));
    if (moduleGroup.getRequiredIf() != null) {
        condition = new MultiComponentCondition(condition, BooleanOperator.AND, new NestedComponentCondition(moduleGroup.getRequiredIf()));
    }
    return condition;
}
Also used : ComponentType(org.talend.hadoop.distribution.ComponentType) ShowExpression(org.talend.hadoop.distribution.condition.ShowExpression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) ShowExpression(org.talend.hadoop.distribution.condition.ShowExpression) LinkedNodeExpression(org.talend.hadoop.distribution.condition.LinkedNodeExpression) Expression(org.talend.hadoop.distribution.condition.Expression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) RawExpression(org.talend.hadoop.distribution.condition.RawExpression) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) SimpleComponentCondition(org.talend.hadoop.distribution.condition.SimpleComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition) ComponentCondition(org.talend.hadoop.distribution.condition.ComponentCondition) MultiComponentCondition(org.talend.hadoop.distribution.condition.MultiComponentCondition) NestedComponentCondition(org.talend.hadoop.distribution.condition.NestedComponentCondition)

Example 4 with Expression

use of org.talend.hadoop.distribution.condition.Expression in project tbd-studio-se by Talend.

the class ExpressionTest method testGetExpressionString.

@Test
public void testGetExpressionString() throws Exception {
    Expression e1 = new BasicExpression(PARAM_1, VALUE_1, EqualityOperator.EQ);
    assertEquals(e1.getExpressionString(), LEFT_PAR + PARAM_1 + EQ + SINGLE_QUOTE + VALUE_1 + SINGLE_QUOTE + RIGHT_PAR);
    e1 = new BasicExpression(PARAM_1, VALUE_1, EqualityOperator.NOT_EQ);
    assertEquals(e1.getExpressionString(), LEFT_PAR + PARAM_1 + NEQ + SINGLE_QUOTE + VALUE_1 + SINGLE_QUOTE + RIGHT_PAR);
    e1 = new LinkedNodeExpression(SparkBatchConstant.SPARK_BATCH_SPARKCONFIGURATION_LINKEDPARAMETER, SparkBatchConstant.SPARK_BATCH_AZURE_SPARKCONFIGURATION_LINKEDPARAMETER, EqualityOperator.GE, ESparkVersion.SPARK_3_0.getSparkVersion());
    // $NON-NLS-1$
    assertEquals("(#LINK@NODE.SPARK_CONFIGURATION.STORAGE_CONFIGURATION ge 'SPARK_3_0_x')", e1.getExpressionString());
}
Also used : BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) BasicExpression(org.talend.hadoop.distribution.condition.BasicExpression) LinkedNodeExpression(org.talend.hadoop.distribution.condition.LinkedNodeExpression) Expression(org.talend.hadoop.distribution.condition.Expression) LinkedNodeExpression(org.talend.hadoop.distribution.condition.LinkedNodeExpression) Test(org.junit.Test)

Aggregations

BasicExpression (org.talend.hadoop.distribution.condition.BasicExpression)4 Expression (org.talend.hadoop.distribution.condition.Expression)4 ComponentCondition (org.talend.hadoop.distribution.condition.ComponentCondition)3 MultiComponentCondition (org.talend.hadoop.distribution.condition.MultiComponentCondition)3 NestedComponentCondition (org.talend.hadoop.distribution.condition.NestedComponentCondition)3 SimpleComponentCondition (org.talend.hadoop.distribution.condition.SimpleComponentCondition)3 Test (org.junit.Test)2 LinkedNodeExpression (org.talend.hadoop.distribution.condition.LinkedNodeExpression)2 ComponentType (org.talend.hadoop.distribution.ComponentType)1 BooleanExpression (org.talend.hadoop.distribution.condition.BooleanExpression)1 RawExpression (org.talend.hadoop.distribution.condition.RawExpression)1 ShowExpression (org.talend.hadoop.distribution.condition.ShowExpression)1