Skip to content

Commit

Permalink
Merge e433bac into a2d79d2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tirla-Alin committed Jul 30, 2019
2 parents a2d79d2 + e433bac commit dd96bd9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public interface SlangTextualKeys {
String SEQ_STEP_HIGHLIGHT_ID_KEY = "highlight_id";
String SEQ_STEP_SNAPSHOT_KEY = "snapshot";
String SEQ_OUTPUT_ROBOT_KEY = "robot";
String SEQ_EXTERNAL_KEY = "external";

//inputs
String VALUE_KEY = "value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import static io.cloudslang.lang.compiler.CompilerConstants.DEFAULT_SENSITIVITY_LEVEL;
import static io.cloudslang.lang.compiler.SlangTextualKeys.SEQ_ACTION_KEY;
import static io.cloudslang.lang.compiler.modeller.transformers.Transformer.Scope.ACTION;
import static java.util.Collections.emptySet;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static java.util.Collections.singletonList;

public class SeqActionTransformer extends AbstractTransformer
Expand All @@ -44,9 +45,9 @@ public SeqActionTransformer(DependencyFormatValidator dependencyFormatValidator,
this.seqStepsTransformer = seqStepsTransformer;
}

private static final Set<String> MANDATORY_KEY_SET = newHashSet(SlangTextualKeys.SEQ_ACTION_GAV_KEY,
SlangTextualKeys.SEQ_STEPS_KEY);
private static final Set<String> OPTIONAL_KEY_SET = emptySet();
private static final Set<String> MANDATORY_KEY_SET = newHashSet(SlangTextualKeys.SEQ_ACTION_GAV_KEY);
private static final Set<String> OPTIONAL_KEY_SET = newHashSet(SlangTextualKeys.SEQ_STEPS_KEY,
SlangTextualKeys.SEQ_EXTERNAL_KEY);

@Override
public TransformModellingResult<Map<String, Serializable>> transform(Map<String, Serializable> rawData) {
Expand Down Expand Up @@ -82,14 +83,21 @@ private void transformGav(Map<String, Serializable> rawData) {
private void transformSteps(Map<String, Serializable> rawData,
List<RuntimeException> errors,
SensitivityLevel sensitivityLevel) {
Boolean external = (Boolean) rawData.remove(SlangTextualKeys.SEQ_EXTERNAL_KEY);
Boolean externalSl = external != null ? external : FALSE;
rawData.put(ScoreLangConstants.SEQ_EXTERNAL_KEY, externalSl);

List<Map<String, Map<String, String>>> steps = preCompileValidator
.validateSeqActionSteps(rawData.remove(SlangTextualKeys.SEQ_STEPS_KEY), errors);
.validateSeqActionSteps(rawData.remove(SlangTextualKeys.SEQ_STEPS_KEY), errors, externalSl);
TransformModellingResult<ArrayList<SeqStep>> transformedSteps = seqStepsTransformer
.transform(steps, sensitivityLevel);
errors.addAll(transformedSteps.getErrors());
ArrayList<SeqStep> transformedData = transformedSteps.getTransformedData();
if (transformedData.isEmpty()) {
errors.add(new RuntimeException("Missing sequential operation steps."));

if (transformedData.isEmpty() && externalSl == FALSE) {
errors.add(new RuntimeException("Missing sequential operation steps in sequential operation."));
} else if (!transformedData.isEmpty() && externalSl == TRUE) {
errors.add(new RuntimeException("Found sequential operation steps in external sequential operation."));
}
rawData.put(ScoreLangConstants.SEQ_STEPS_KEY, transformedData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ List<Map<String, Map<String, Object>>> validateWorkflowRawData(ParsedSlang parse
List<RuntimeException> errors);

List<Map<String, Map<String, String>>> validateSeqActionSteps(Object oSeqActionStepsRawData,
List<RuntimeException> errors);
List<RuntimeException> errors,
boolean external);

ExecutableModellingResult validateResult(ParsedSlang parsedSlang,
String executableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ public List<Map<String, Map<String, Object>>> validateWorkflowRawData(ParsedSlan

@Override
public List<Map<String, Map<String, String>>> validateSeqActionSteps(Object oSeqActionStepsRawData,
List<RuntimeException> errors) {
List<RuntimeException> errors,
boolean external) {
if (oSeqActionStepsRawData == null) {
oSeqActionStepsRawData = new ArrayList<>();
errors.add(new RuntimeException("Error compiling sequential operation: missing '" +
SEQ_STEPS_KEY + "' property."));
if (!external) {
errors.add(new RuntimeException("Error compiling sequential operation: missing '" +
SEQ_STEPS_KEY + "' property."));
}
}
List<Map<String, Map<String, String>>> stepsRawData;
try {
Expand All @@ -130,9 +133,12 @@ public List<Map<String, Map<String, String>>> validateSeqActionSteps(Object oSeq
errors.add(new RuntimeException("Error compiling sequential operation: syntax is illegal.\n" +
"Below '" + SEQ_STEPS_KEY + "' property there should be a list of steps and not a map."));
}
if (CollectionUtils.isEmpty(stepsRawData)) {
if (CollectionUtils.isEmpty(stepsRawData) && !external) {
errors.add(new RuntimeException("Error compiling sequential operation: missing '" +
SEQ_STEPS_KEY + "' data."));
} else if (!CollectionUtils.isEmpty(stepsRawData) && external) {
errors.add(new RuntimeException("Error compiling sequential operation: property '" +
SEQ_STEPS_KEY + "' is not supported for external operations."));
}
for (Map<String, Map<String, String>> step : stepsRawData) {
if (step.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@

import static com.google.common.collect.Lists.newArrayList;
import static io.cloudslang.lang.entities.ScoreLangConstants.SEQ_ACTION_GAV_KEY;
import static io.cloudslang.lang.entities.ScoreLangConstants.SEQ_EXTERNAL_KEY;
import static io.cloudslang.lang.entities.ScoreLangConstants.SEQ_STEPS_KEY;
import static java.lang.Boolean.FALSE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.collection.IsEmptyCollection.empty;
Expand Down Expand Up @@ -86,6 +88,7 @@ public void testTransformSimple() {
Map<String, Serializable> expectedSeqActionSimple = new LinkedHashMap<>();
expectedSeqActionSimple.put(SEQ_ACTION_GAV_KEY, "seq:seqf.simple_valid_seq_op:1.0.0");
expectedSeqActionSimple.put(SEQ_STEPS_KEY, newArrayList(new SeqStep()));
expectedSeqActionSimple.put(SEQ_EXTERNAL_KEY, FALSE);

TransformModellingResult<Map<String, Serializable>> transformedAction = seqActionTransformer
.transform(new HashMap<>(initialSeqActionSimple));
Expand Down Expand Up @@ -140,7 +143,7 @@ public void testTransformWithMissingKeys() {
assertNull(transformedAction.getTransformedData());
assertThat(transformedAction.getErrors(), is(not(empty())));
assertEquals(transformedAction.getErrors().get(0).getMessage(),
"Following tags are missing: [gav, steps]");
"Following tags are missing: [gav]");
}

@Test
Expand All @@ -153,6 +156,7 @@ public void testTransformWithNoSteps() {
Map<String, Serializable> expectedSeqActionSimple = new LinkedHashMap<>();
expectedSeqActionSimple.put(SEQ_ACTION_GAV_KEY, "seq:seqf.simple_valid_seq_op:1.0.0");
expectedSeqActionSimple.put(SEQ_STEPS_KEY, newArrayList());
expectedSeqActionSimple.put(SEQ_EXTERNAL_KEY, FALSE);

TransformModellingResult<Map<String, Serializable>> transformedAction = seqActionTransformer
.transform(rawData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface ScoreLangConstants {

String SEQ_ACTION_GAV_KEY = "gav";
String SEQ_STEPS_KEY = "steps";
String SEQ_EXTERNAL_KEY = "external";

//navigation
String NEXT_STEP_ID_KEY = "nextStepId";
Expand Down

0 comments on commit dd96bd9

Please sign in to comment.