public AbstractConversionExecutor(final TemplateParameterContextProvider contextProvider, final ExecuteStrategyFactory executeStrategyFactory) { this.contextProvider = contextProvider; this.executeStrategyFactory = executeStrategyFactory; this.skipOperationResolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); }
private List<OperationInfo> getSubPipeOperations(SubPipeType subPipe) { return subPipe.getExecOnce().stream() .map(execOnce -> new OperationInfo(execOnce.getValue(), execOnce.getName(), ContextInfo.EMPTY, skipOperationResolver .setContextInfo(ContextInfo.EMPTY) .isSkip(execOnce))) .collect(Collectors.toList()); }
@Test(expected = TemplateParameterNotFoundException.class) public void testInvalidContextParameter() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ExecOnceType exec = new ExecOnceType(); exec.setIf("%{dynamic.null}"); resolver.setContextInfo(ContextInfo.EMPTY).isSkip(exec); }
public boolean isSkip(ConditionalSimpleType execType, ConditionalComplexType... parentExecTypes) { if (parentExecTypes == null || parentExecTypes.length == 0) { return isSkip(execType); } return Arrays.asList(parentExecTypes).stream().anyMatch((execComplexType) -> isSkip(execComplexType)) || isSkip(execType); }
@Test(expected = UnknownTemplateParameterContextException.class) public void testInvalidContext() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ExecOnceType exec = new ExecOnceType(); exec.setIf("%{null.true}"); resolver.setContextInfo(ContextInfo.EMPTY).isSkip(exec); }
@Override public void execute() throws IOException { contextProvider.getDynamicContext() .addParameter(dynamicParameter, ContextInfo.EMPTY, skipOperationResolver.isSkip(dynamicParameter)); }
@Test public void testDamagedContextParameter() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ExecOnceType exec = new ExecOnceType(); exec.setIf("%{dynamic.damagedParam}"); // convert to false in result assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(exec)); }
private OperationInfo getExecOnceOperation(ExecOnceType execOnce) { return new OperationInfo(execOnce.getValue(), execOnce.getName(), ContextInfo.EMPTY, skipOperationResolver .setContextInfo(ContextInfo.EMPTY) .isSkip(execOnce)); }
public boolean isSkip(ConditionalSimpleType execType) { return isSkip(execType.getIf(), execType.getUnless()); }
@Test public void testEmptyParameter() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ExecOnceType exec = new ExecOnceType(); exec.setIf(""); // convert to false in result assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(exec)); }
private List<OperationInfo> getSubPipeOperations(SubPipeType subPipe) { ContextInfo contextInfo = new ContextInfoBuilder() .setSegmentUuid(currentSegmentUuid) .build(); return subPipe.getExecOnce().stream() .map(execOnce -> new OperationInfo(execOnce.getValue(), execOnce.getName(), contextInfo, skipOperationResolver .setContextInfo(contextInfo) .isSkip(execOnce, execEachSegm))) .collect(Collectors.toList()); }
public boolean isSkip(ConditionalComplexType execType) { return isSkip(execType.getIf(), execType.getUnless()); }
@Test public void testOperationNotSkipped() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ConditionalSimpleType trueExec = new ExecOnceType(); trueExec.setUnless("false"); ConditionalSimpleType ifParamExec = new ExecOnceType(); ifParamExec.setIf("%{dynamic.trueParam}"); ConditionalComplexType unlessParamExec = new ExecEachSequenceType(); unlessParamExec.setUnless("%{dynamic.falseParam}"); ConditionalComplexType ifUnlessParamExec = new ExecEachSegmentSequenceType(); ifUnlessParamExec.setIf("%{dynamic.trueParam}"); ifUnlessParamExec.setUnless("%{dynamic.falseParam}"); assertFalse(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(trueExec)); assertFalse(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(ifParamExec)); assertFalse(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(unlessParamExec)); assertFalse(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(ifUnlessParamExec)); }
private List<OperationInfo> getSubPipeOperations(SubPipeType subPipe) { List<OperationInfo> result = new ArrayList<>(); ContextInfo contextInfo = new ContextInfoBuilder() .setSequenceUuid(currentSeqUuid) .setSequenceType(seqType) .build(); result.addAll(subPipe.getExecOnce().stream() .map(execOnce -> new OperationInfo(execOnce.getValue(), execOnce.getName(), contextInfo, skipOperationResolver .setContextInfo(contextInfo) .isSkip(execOnce, execEachSeq))) .collect(Collectors.toList())); return result; }
/** * Resolves dynamic parameter name and value and add to dynamic context. * * @param dynParam dynamic parameter to add */ private void addDynamicParameter(DynamicParameterConcatType dynParam, Map<String, Integer> iterators) { DynamicParameterConcatType resolvedParameter = contextProvider.getDynamicContext().cloneParameter(dynParam); resolvedParameter.setName(parameterResolver.resolveIteratorParameter(resolvedParameter.getName(), iterators)); resolvedParameter.setValue(parameterResolver.resolveIteratorParameter(resolvedParameter.getValue(), iterators)); resolvedParameter.setAdd(parameterResolver.resolveIteratorParameter(resolvedParameter.getAdd(), iterators)); contextProvider.getDynamicContext().addParameter(resolvedParameter, ContextInfo.EMPTY, skipOperationResolver.isSkip(dynParam)); }
@Test public void testOperationSkipped() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ConditionalSimpleType falseExec = new ExecOnceType(); falseExec.setIf("false"); ConditionalSimpleType ifParamExec = new ExecOnceType(); ifParamExec.setIf("%{dynamic.falseParam}"); ConditionalComplexType unlessParamExec = new ExecEachSequenceType(); unlessParamExec.setUnless("%{dynamic.trueParam}"); ConditionalComplexType ifUnlessParamExec = new ExecEachSegmentSequenceType(); ifUnlessParamExec.setIf("%{dynamic.trueParam}"); // not skipped ifUnlessParamExec.setUnless("%{dynamic.trueParam}"); // skipped assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(falseExec)); assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(ifParamExec)); assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(unlessParamExec)); assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(ifUnlessParamExec)); }
@Override public void execute() throws IOException { OperationInfo operationInfo = new OperationInfo(operation.getValue(), operation.getName(), ContextInfo.EMPTY, skipOperationResolver .setContextInfo(ContextInfo.EMPTY) .isSkip(operation)); executeStrategyFactory.createExecuteOnceStrategy(contextProvider).execute(operationInfo); }
@Test public void testInvalidBoolean() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ExecOnceType ifInvalidExec = new ExecOnceType(); ifInvalidExec.setIf("true"); ifInvalidExec.setUnless("123"); // convert to false in result assertFalse(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(ifInvalidExec)); }
private void addDynamicParameter(DynamicParameterConcatType dynamicParam) { ContextInfo contextInfo = new ContextInfoBuilder() .setSegmentUuid(currentSegmentUuid) .build(); contextProvider.getDynamicContext().addParameter(dynamicParam, contextInfo, skipOperationResolver .setContextInfo(contextInfo) .isSkip(dynamicParam, execEachSegm)); }
@Test public void testFewOperationsSkipped() { SkipOperationResolver resolver = new SkipOperationResolver(new TemplateParameterResolver(contextProvider)); ConditionalSimpleType trueExec1 = new ExecOnceType(); trueExec1.setUnless("false"); ConditionalComplexType trueExec2 = new ConditionalComplexType(); trueExec2.setIf("true"); ConditionalComplexType falseExec = new ConditionalComplexType(); falseExec.setIf("false"); assertTrue(resolver.setContextInfo(ContextInfo.EMPTY).isSkip(trueExec1, trueExec2, falseExec)); }