Search in sources :

Example 1 with ServiceTask

use of org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask in project kie-wb-common by kiegroup.

the class BPMNPaletteDefinitionBuilderTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(definitionUtils.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(widAdapter);
    when(widAdapter.getId(eq(serviceTask))).thenReturn(WID_NAME);
    when(widAdapter.getCategory(eq(serviceTask))).thenReturn(WID_CAT);
    when(widAdapter.getTitle(eq(serviceTask))).thenReturn(WID_DISPLAY_NAME);
    when(widAdapter.getDescription(eq(serviceTask))).thenReturn(WID_DESC);
    ExpandedPaletteDefinitionBuilder paletteDefinitionBuilder = spy(new ExpandedPaletteDefinitionBuilder(definitionUtils, clientFactoryServices, translationService));
    doAnswer(invocationOnMock -> {
        Consumer<DefaultPaletteDefinition> definitionConsumer = (Consumer<DefaultPaletteDefinition>) invocationOnMock.getArguments()[1];
        definitionConsumer.accept(PALETTE_DEFINITION);
        return null;
    }).when(paletteDefinitionBuilder).build(eq(canvasHandler), any(Consumer.class));
    Function<WorkItemDefinition, ServiceTask> serviceTaskBuilder = wid -> WID.equals(wid) ? serviceTask : null;
    tested = new BPMNPaletteDefinitionBuilder(definitionManager, paletteDefinitionBuilder, translationService, () -> workItemDefinitionRegistry, serviceTaskBuilder);
    tested.init();
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) DefaultPaletteDefinition(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) ArrayList(java.util.ArrayList) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) DefaultPaletteDefinitionProviders.getId(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.getId) Before(org.junit.Before) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) EndSignalEvent(org.kie.workbench.common.stunner.bpmn.definition.EndSignalEvent) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Mockito.times(org.mockito.Mockito.times) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) Mockito.when(org.mockito.Mockito.when) ClientFactoryService(org.kie.workbench.common.stunner.core.client.service.ClientFactoryService) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) Assert.assertFalse(org.junit.Assert.assertFalse) WorkItemDefinitionRegistry(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Consumer(java.util.function.Consumer) DefaultPaletteDefinition(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) Before(org.junit.Before)

Example 2 with ServiceTask

use of org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask in project kie-wb-common by kiegroup.

the class ServiceTaskNodeBuilder method doBuild.

@Override
protected Node<View<BPMNDefinition>, Edge> doBuild(final BuilderContext context) {
    final Node<View<BPMNDefinition>, Edge> node = super.doBuild(context);
    final ServiceTask serviceTask = (ServiceTask) node.getContent().getDefinition();
    // Oryx handles the taskName property, use it for populating the service task.
    final String taskName = serviceTask.getExecutionSet().getTaskName().getValue();
    final WorkItemDefinition workItemDefinition = workItemDefinitionRegistry.get().get(taskName);
    ServiceTaskFactory.ServiceTaskBuilder.setProperties(workItemDefinition, serviceTask);
    return node;
}
Also used : ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 3 with ServiceTask

use of org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask in project kie-wb-common by kiegroup.

the class ServiceTaskShapeViewHandlerTest method init.

@Before
@SuppressWarnings("unchecked")
public void init() {
    this.task = new ServiceTask();
    this.task.setName(WID_ID);
    when(registry.items()).thenReturn(Collections.singleton(DEF));
    when(registry.get(eq(WID_ID))).thenReturn(DEF);
    when(view.getChildren()).thenReturn(Collections.singletonList(imageSvgPrimitive));
    when(imageSvgPrimitive.getId()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID);
    when(imageSvgPrimitive.get()).thenReturn(imagePrimitive);
    when(imagePrimitive.getID()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID);
    when(imagePrimitive.getImageProxy()).thenReturn(imageProxy);
    this.tested = new ServiceTaskShapeViewHandler(() -> registry);
}
Also used : ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) Before(org.junit.Before)

Example 4 with ServiceTask

use of org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask in project kie-wb-common by kiegroup.

the class BPMNPaletteDefinitionBuilder method createPaletteServiceTasksCategory.

private void createPaletteServiceTasksCategory(final DefaultPaletteDefinition paletteDefinition, final Consumer<DefaultPaletteDefinition> callback) {
    final ExpandedPaletteDefinitionBuilder.ItemMessageProvider categoryMessageProvider = paletteDefinitionBuilder.getCategoryMessageProvider();
    final Function<String, Glyph> categoryGlyphProvider = paletteDefinitionBuilder.getCategoryGlyphProvider();
    final Collection<WorkItemDefinition> workItemDefinitions = workItemDefinitionRegistry.get().items();
    if (!workItemDefinitions.isEmpty()) {
        final String serviceTasksTitle = categoryMessageProvider.getTitle(BPMNCategories.SERVICE_TASKS);
        final String serviceTasksDesc = categoryMessageProvider.getDescription(BPMNCategories.SERVICE_TASKS);
        final DefaultPaletteCategory workItemsCategory = new CategoryBuilder().setItemId(BPMNCategories.SERVICE_TASKS).setTitle(serviceTasksTitle).setDescription(serviceTasksDesc).setTooltip(serviceTasksTitle).setGlyph(categoryGlyphProvider.apply(BPMNCategories.SERVICE_TASKS)).build();
        int i = 0;
        for (final WorkItemDefinition workItemDefinition : workItemDefinitions) {
            final ServiceTask serviceTask = serviceTaskBuilder.apply(workItemDefinition);
            final DefinitionAdapter<Object> adapter = definitionManager.adapters().registry().getDefinitionAdapter(serviceTask.getClass());
            final String category = adapter.getCategory(serviceTask);
            DefaultPaletteGroup subcategoryGroup = null;
            final Optional<DefaultPaletteItem> subcategoryGroupOp = workItemsCategory.getItems().stream().filter(item -> category.equals(item.getId())).findFirst();
            if (!subcategoryGroupOp.isPresent()) {
                subcategoryGroup = new GroupBuilder().setItemId(category).setTitle(category).setDescription(category).build();
                workItemsCategory.getItems().add(subcategoryGroup);
            } else {
                subcategoryGroup = (DefaultPaletteGroup) subcategoryGroupOp.get();
            }
            final String defId = adapter.getId(serviceTask);
            final String title = adapter.getTitle(serviceTask);
            final String description = adapter.getDescription(serviceTask);
            final DefaultPaletteItem item = new ItemBuilder().setItemId(defId).setDefinitionId(defId).setTitle(title).setDescription(description).build();
            subcategoryGroup.getItems().add(item);
            // Link the first work item definition found to the work item's palette category.
            if (0 == i) {
                workItemsCategory.setDefinitionId(defId);
            }
            i++;
        }
        paletteDefinition.getItems().add(workItemsCategory);
    }
    callback.accept(paletteDefinition);
}
Also used : StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) DefaultPaletteDefinition(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) BPMNImageResources(org.kie.workbench.common.stunner.bpmn.client.resources.BPMNImageResources) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) HashMap(java.util.HashMap) ParallelGateway(org.kie.workbench.common.stunner.bpmn.definition.ParallelGateway) Function(java.util.function.Function) Supplier(java.util.function.Supplier) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Inject(javax.inject.Inject) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) Map(java.util.Map) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) ReusableSubprocess(org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) CategoryDefinitionProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.CategoryDefinitionProvider) Builder(org.kie.workbench.common.stunner.core.client.shape.SvgDataUriGlyph.Builder) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ServiceTaskFactory(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTaskFactory) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) PaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.PaletteDefinitionBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) DefaultPaletteDefinitionProviders(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders) Consumer(java.util.function.Consumer) BPMNCategories(org.kie.workbench.common.stunner.bpmn.definition.BPMNCategories) DefaultPaletteDefinitionProviders.isType(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.isType) BPMN(org.kie.workbench.common.stunner.bpmn.qualifiers.BPMN) AbstractPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.AbstractPaletteDefinitionBuilder) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) IntermediateTimerEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateTimerEvent) WorkItemDefinitionRegistry(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry) ApplicationScoped(javax.enterprise.context.ApplicationScoped) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph)

Example 5 with ServiceTask

use of org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask in project kie-wb-common by kiegroup.

the class ServiceTaskShapeDefTest method init.

@Before
@SuppressWarnings("unchecked")
public void init() throws Exception {
    this.task = new ServiceTask();
    task.getDimensionsSet().getWidth().setValue(WIDTH);
    task.getDimensionsSet().getHeight().setValue(HEIGHT);
    this.task.setName(WID_ID);
    when(node.getDefinition()).thenReturn(task);
    when(node.getBounds()).thenReturn(BOUNDS);
    when(registry.items()).thenReturn(Collections.singleton(DEF));
    when(registry.get(eq(WID_ID))).thenReturn(DEF);
    when(view.getChildren()).thenReturn(Collections.singletonList(imageSvgPrimitive));
    when(imageSvgPrimitive.getId()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID);
    when(imageSvgPrimitive.get()).thenReturn(imagePrimitive);
    when(imagePrimitive.getID()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID);
    when(imagePrimitive.getImageProxy()).thenReturn(imageProxy);
    this.tested = new ServiceTaskShapeDef(() -> registry, iconDataGlyphGenerator);
}
Also used : ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) Before(org.junit.Before)

Aggregations

ServiceTask (org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask)6 Before (org.junit.Before)3 WorkItemDefinition (org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition)3 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Test (org.junit.Test)2 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)2 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)2 NoneTask (org.kie.workbench.common.stunner.bpmn.definition.NoneTask)2 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)2 StartNoneEvent (org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent)2 WorkItemDefinitionRegistry (org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry)2 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 DefaultPaletteDefinition (org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1