use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class PMMLIncludedModelHandler method destroy.
@Override
public void destroy(final String oldModelName) {
final List<Decision> decisions = getDecisions();
final List<BusinessKnowledgeModel> businessKnowledgeModels = getBusinessKnowledgeModels();
final List<FunctionDefinition> functions = getPMMLFunctionDefinitions(decisions, businessKnowledgeModels);
final Map<FunctionDefinition, Context> contexts = getPMMLContexts(functions);
// The values in the DMN model are stored with quotes
final String quotedOldModelName = StringUtils.createQuotedString(oldModelName);
for (final Map.Entry<FunctionDefinition, Context> entry : contexts.entrySet()) {
final Context context = entry.getValue();
for (final ContextEntry contextEntry : context.getContextEntry()) {
if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, contextEntry.getVariable().getName().getValue())) {
final Expression expression = contextEntry.getExpression();
if (expression instanceof IsLiteralExpression) {
final IsLiteralExpression ile = (IsLiteralExpression) expression;
if (Objects.nonNull(ile.getText())) {
final Text text = ile.getText();
if (Objects.equals(quotedOldModelName, text.getValue())) {
clearContextValues(context);
entry.getKey().getFormalParameter().clear();
}
}
}
}
}
}
// Refresh cached grids from the DMN model
refreshCachedExpressionGrids(decisions, businessKnowledgeModels);
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DMNCommonActionsToolboxFactoryTest method testBuildToolboxForBusinessKnowledgeModelType.
@Test
@SuppressWarnings("unchecked")
public void testBuildToolboxForBusinessKnowledgeModelType() {
final Node<View<BusinessKnowledgeModel>, Edge> bkmNode = new NodeImpl<>("bkmNode1");
final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel();
final Bounds bounds = Bounds.create(0d, 0d, 100d, 150d);
final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
bkmNode.setContent(nodeContent);
final Optional<Toolbox<?>> _toolbox = tested.build(canvasHandler, bkmNode);
assertTrue(_toolbox.isPresent());
Toolbox<?> toolbox = _toolbox.get();
assertTrue(toolbox instanceof ActionsToolbox);
final ActionsToolbox actionsToolbox = (ActionsToolbox) toolbox;
assertEquals("bkmNode1", actionsToolbox.getElementUUID());
assertEquals(3, actionsToolbox.size());
final Iterator<ToolboxAction> actionsIt = actionsToolbox.iterator();
assertEquals(deleteNodeAction, actionsIt.next());
assertEquals(editBusinessKnowledgeModelToolboxActionInstance, actionsIt.next());
assertTrue(actionsIt.hasNext());
verify(viewInstance, times(1)).init(eq(actionsToolbox));
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DMNCommonActionsToolboxFactoryTest method testAddEditBusinessKnowledgeModelAction.
@Test
public void testAddEditBusinessKnowledgeModelAction() {
final List<ToolboxAction<AbstractCanvasHandler>> actions = new ArrayList<>();
final Element element = mock(Element.class);
final Node node = mock(Node.class);
final Definition definition = mock(Definition.class);
final BusinessKnowledgeModel bkm = mock(BusinessKnowledgeModel.class);
when(element.asNode()).thenReturn(node);
when(element.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(bkm);
tested.addEditAction(element, actions);
assertEquals(1, actions.size());
assertTrue(DMNEditBusinessKnowledgeModelToolboxAction.class.isInstance(actions.get(0)));
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxActionTest method setup.
@Before
public void setup() throws Exception {
bkmNode = new NodeImpl<>(E_UUID);
bkm = new BusinessKnowledgeModel();
final Bounds bounds = Bounds.create(0d, 0d, 100d, 150d);
final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
bkmNode.setContent(nodeContent);
when(canvasHandler.getGraphIndex()).thenReturn(graphIndex);
when(graphIndex.get(eq(E_UUID))).thenReturn(bkmNode);
when(sessionManager.getCurrentSession()).thenReturn(session);
this.tested = new DMNEditBusinessKnowledgeModelToolboxAction(sessionManager, translationService, editExpressionEvent, readOnlyProvider);
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method testUpdateEncapsulatedLogicFromDefinition.
@Test
public void testUpdateEncapsulatedLogicFromDefinition() {
final Element element = mock(Element.class);
final View elementContent = mock(View.class);
final BusinessKnowledgeModel newBusinessKnowledgeModel = mock(BusinessKnowledgeModel.class);
final BusinessKnowledgeModel businessKnowledgeModel = mock(BusinessKnowledgeModel.class);
final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
when(element.getContent()).thenReturn(elementContent);
when(elementContent.getDefinition()).thenReturn(newBusinessKnowledgeModel);
when(businessKnowledgeModel.getEncapsulatedLogic()).thenReturn(functionDefinition);
when(newBusinessKnowledgeModel.getName()).thenReturn(new Name());
when(businessKnowledgeModel.getName()).thenReturn(new Name());
when(newBusinessKnowledgeModel.getId()).thenReturn(new Id());
when(businessKnowledgeModel.getId()).thenReturn(new Id());
observerBuilderControl.updateElementFromDefinition(element, businessKnowledgeModel);
verify(newBusinessKnowledgeModel).setEncapsulatedLogic(functionDefinition);
}
Aggregations