public void reload(String type, Command onSuccess) { service.call(result -> { setFunctions((List<FunctionDef>) result); onSuccess.execute(); }).findAvailableFunctions(path, type); }
void onSimpleConditionChange(Condition oldValue, Condition newValue) { if (simpleConditionEditor.isValid()) { editorService.call(result -> onSimpleConditionChange((GenerateConditionResult) result), (message, throwable) -> onSimpleConditionChangeError(throwable)).generateCondition(newValue); } else { clearError(); } }
private void testParseConditionUnsuccessful(String function) { failingBinaryFunctionExpressions.forEach(binaryFunctionExpression -> { String expression = String.format(binaryFunctionExpression, "KieFunctions." + function); ParseConditionResult result = service.parseCondition(expression); assertTrue(result.hasError()); }); }
@Test public void testFindMetadata() { Set<String> types = new HashSet<>(); types.add(Bean1.class.getName()); types.add(Bean2.class.getName()); types.add("non.existing.class.Bean"); TypeMetadataQuery query = new TypeMetadataQuery(path, types); TypeMetadataQueryResult result = service.findMetadata(query); assertTrue(result.getMissingTypes().contains("non.existing.class.Bean")); TypeMetadata bean1Metadata = result.getTypeMetadatas().stream().filter(typeMetadata -> typeMetadata.getType().equals(Bean1.class.getName())).findFirst().orElse(null); TypeMetadata bean2Metadata = result.getTypeMetadatas().stream().filter(typeMetadata -> typeMetadata.getType().equals(Bean2.class.getName())).findFirst().orElse(null); assertNotNull(bean1Metadata); assertNotNull(bean2Metadata); assertHasField(bean1Metadata, "fieldBean1_1", String.class.getName(), "getFieldBean1_1", "setFieldBean1_1"); assertHasField(bean1Metadata, "fieldBean1_2", "int", "getFieldBean1_2", null); assertHasField(bean1Metadata, "fieldBean1_3", "boolean", "isFieldBean1_3", "setFieldBean1_3"); assertHasField(bean1Metadata, "fieldBean1_4", Integer.class.getName(), null, "setFieldBean1_4"); assertHasField(bean2Metadata, "fieldBean1_1", String.class.getName(), "getFieldBean1_1", "setFieldBean1_1"); assertHasField(bean2Metadata, "fieldBean1_2", "int", "getFieldBean1_2", null); assertHasField(bean2Metadata, "fieldBean1_3", "boolean", "isFieldBean1_3", "setFieldBean1_3"); assertHasField(bean2Metadata, "fieldBean1_4", Integer.class.getName(), null, "setFieldBean1_4"); assertHasField(bean2Metadata, "fieldBean2_1", String.class.getName(), "getFieldBean2_1", "setFieldBean2_1"); assertHasField(bean2Metadata, "fieldBean2_2", Object.class.getName(), "getFieldBean2_2", "setFieldBean2_2"); }
public void init(ClientSession session) { Diagram diagram = session.getCanvasHandler().getDiagram(); String canvasRootUUID = diagram.getMetadata().getCanvasRootUUID(); @SuppressWarnings("unchecked") Node<?, ? extends Edge> selectedNode = getSourceNode(diagram, getSelectedElementUUID(session)); if (selectedNode != null) { Map<String, VariableMetadata> collectedVariables = new HashMap<>(); Set<String> collectedTypes = new HashSet<>(); Node<?, ? extends Edge> parentNode = getParent(selectedNode).asNode(); String parentVariables; while (parentNode != null) { parentVariables = getVariables(parentNode); if (!isEmpty(parentVariables)) { addVariables(parentVariables, collectedVariables, collectedTypes); } if (parentNode.getUUID().equals(canvasRootUUID)) { parentNode = null; } else { parentNode = getParent(parentNode).asNode(); } } Path path = session.getCanvasHandler().getDiagram().getMetadata().getPath(); TypeMetadataQuery query = new TypeMetadataQuery(path, collectedTypes); service.call(result -> initVariables(collectedVariables.values(), ((TypeMetadataQueryResult) result))).findMetadata(query); } }
void onSimpleConditionSelected() { clearError(); if (value != null && !isEmpty(value.getScript())) { editorService.call(result -> onSimpleConditionSelected((ParseConditionResult) result), (message, throwable) -> onSimpleConditionSelectedError(throwable)).parseCondition(value.getScript()); } else { simpleConditionEditor.setValue(null); showSimpleConditionEditor(); } }
private void testGenerateConditionSuccessful(String function) { for (int i = 0; i < variableParams.size(); i++) { Condition condition = new Condition(function); condition.addParam(variableParams.get(i)); condition.addParam(stringParams.get(i)); GenerateConditionResult result = service.generateCondition(condition); assertFalse(result.hasError()); String expectedScript = buildBinaryConditionScript(function, variableParams.get(i), stringParams.get(i)); assertEquals(expectedScript, result.getExpression()); } } }
private void testFindAvailableFunctions(String clazz, String[] expectedFunctions) { List<FunctionDef> functionDefs = service.findAvailableFunctions(path, clazz); assertEquals(functionDefs.size(), expectedFunctions.length); for (String expectedFunction : expectedFunctions) { assertTrue(functionDefs.stream() .anyMatch(functionDef -> expectedFunction.equals(functionDef.getName()))); } }
private void testParseConditionSuccessful(String function) { List<String> conditions = buildBinaryConditionScripts(function); for (int i = 0; i < conditions.size(); i++) { ParseConditionResult result = service.parseCondition(conditions.get(i)); assertFalse(result.hasError()); assertEquals(function, result.getCondition().getFunction()); assertEquals(2, result.getCondition().getParams().size()); assertEquals(variableParams.get(i), result.getCondition().getParams().get(0)); assertEquals(stringParams.get(i), result.getCondition().getParams().get(1)); } }
@Test public void testGenerateConditionUnSuccessful() { GenerateConditionResult result = service.generateCondition(null); assertTrue(result.hasError()); assertEquals("A condition must be provided", result.getError()); Condition condition = new Condition("SomeNonExistingFunction"); result = service.generateCondition(condition); assertTrue(result.hasError()); assertEquals("Function SomeNonExistingFunction was not found in current functions definitions", result.getError()); condition = new Condition("startsWith"); condition.addParam("variable"); condition.addParam(null); result = service.generateCondition(condition); assertTrue(result.hasError()); assertEquals("Parameter can not be null nor empty", result.getError()); }
@Override public void setValue(ScriptTypeValue value) { super.setValue(value); scriptEditor.setValue(value); simpleConditionEditor.clear(); clearError(); if (value != null) { if (isInDefaultLanguage(value)) { if (!isEmpty(value.getScript())) { editorService.call(result -> onSetValue((ParseConditionResult) result), (message, throwable) -> onSetValueError(throwable)).parseCondition(value.getScript()); } else { showSimpleConditionEditor(); } } else { showScriptEditor(); } } else { simpleConditionEditor.setValue(null); showSimpleConditionEditor(); } }