Search in sources :

Example 21 with WorkItemDefinition

use of org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition 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 22 with WorkItemDefinition

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

the class WorkItemDefinitionParser method parse.

public static WorkItemDefinition parse(final WorkDefinitionImpl workDefinition, final Function<String, String> dataUriProvider) {
    final WorkItemDefinition workItem = new WorkItemDefinition();
    // Attributes..
    workItem.setName(workDefinition.getName());
    workItem.setCategory(workDefinition.getCategory());
    workItem.setDocumentation(workDefinition.getDocumentation());
    workItem.setDescription(workDefinition.getDescription());
    workItem.setDefaultHandler(workDefinition.getDefaultHandler());
    workItem.setDisplayName(workDefinition.getDisplayName());
    // Icon.
    final String iconEncoded = workDefinition.getIconEncoded();
    final String icon = workDefinition.getIcon();
    String iconData = null;
    if (null != iconEncoded && iconEncoded.trim().length() > 0) {
        iconData = iconEncoded;
    } else if (null != icon && icon.trim().length() > 0) {
        final String iconUrl = workDefinition.getPath() + "/" + icon;
        iconData = dataUriProvider.apply(iconUrl);
    }
    workItem.setIconData(iconData);
    // Parameters.
    workItem.setParameters(parseParameters(workDefinition.getParameters()));
    // Results..
    workItem.setResults(parseParameters(workDefinition.getResults()));
    return workItem;
}
Also used : WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition)

Example 23 with WorkItemDefinition

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

the class WorkItemDefinitionClientParser method convertMvelToWid.

private static List<WorkItemDefinition> convertMvelToWid(List<Map<String, Object>> widFile) {
    List<WorkItemDefinition> wids = new ArrayList<>();
    for (Map<String, Object> widItem : widFile) {
        WorkItemDefinition wid = emptyWid();
        if (widItem.get(NAME) != null) {
            wid.setName(widItem.get(NAME).toString());
        }
        if (widItem.get(DISPLAY_NAME) != null) {
            wid.setDisplayName(widItem.get(DISPLAY_NAME).toString());
        }
        if (widItem.get(ICON) != null) {
            wid.getIconDefinition().setUri(widItem.get(ICON).toString());
            if (widItem.get(ICON).toString().startsWith(ICON_PREFIX)) {
                wid.getIconDefinition().setIconData(widItem.get(ICON).toString());
            }
        }
        if (widItem.get(DOCUMENTATION) != null) {
            wid.setDocumentation(widItem.get(DOCUMENTATION).toString());
        }
        if (widItem.get(CATEGORY) != null) {
            wid.setCategory(widItem.get(CATEGORY).toString());
        }
        if (isEmpty(wid.getCategory())) {
            wid.setCategory(BPMNCategories.CUSTOM_TASKS);
        }
        if (widItem.get(DEFAULT_HANDLER) != null) {
            // It has no visual representation in the Designer so far but model already done, so parsing it
            wid.setDefaultHandler(widItem.get(DEFAULT_HANDLER).toString());
        }
        if (widItem.get(DESCRIPTION) != null) {
            wid.setDescription(widItem.get(DESCRIPTION).toString());
        }
        if (widItem.get(PARAMETERS) != null) {
            wid.setParameters(retrieveParameters((Map<String, Object>) widItem.get(PARAMETERS)));
        }
        if (widItem.get(RESULTS) != null) {
            wid.setResults(retrieveParameters((Map<String, Object>) widItem.get(RESULTS)));
        }
        wids.add(wid);
    }
    return wids;
}
Also used : WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with WorkItemDefinition

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

the class WorkItemDefinitionClientParser method emptyWid.

public static WorkItemDefinition emptyWid() {
    WorkItemDefinition wid = new WorkItemDefinition();
    wid.setIconDefinition(new IconDefinition());
    wid.getIconDefinition().setUri("");
    wid.getIconDefinition().setIconData(getDefaultIconData());
    wid.setUri("");
    wid.setName("");
    wid.setCategory("");
    wid.setDescription("");
    wid.setDocumentation("");
    wid.setDisplayName("");
    wid.setResults("");
    wid.setDefaultHandler("");
    wid.setDependencies(new Dependencies(Collections.emptyList()));
    wid.setParameters("");
    return wid;
}
Also used : WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Dependencies(org.guvnor.common.services.project.model.Dependencies) IconDefinition(org.kie.workbench.common.stunner.bpmn.workitem.IconDefinition)

Example 25 with WorkItemDefinition

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

the class WorkItemDefinitionParser method parse.

public static WorkItemDefinition parse(final WorkDefinitionImpl workDefinition, final Function<WorkDefinitionImpl, String> uriProvider, final Function<String, String> dataUriProvider) {
    final WorkItemDefinition workItem = new WorkItemDefinition();
    // Attributes..
    workItem.setUri(uriProvider.apply(workDefinition));
    workItem.setName(workDefinition.getName());
    workItem.setCategory(workDefinition.getCategory());
    workItem.setDocumentation(workDefinition.getDocumentation());
    workItem.setDescription(workDefinition.getDescription());
    workItem.setDefaultHandler(workDefinition.getDefaultHandler());
    workItem.setDisplayName(workDefinition.getDisplayName());
    // Icon.
    final IconDefinition iconDefinition = new IconDefinition();
    final String iconEncoded = workDefinition.getIconEncoded();
    final String icon = workDefinition.getIcon();
    String iconData = null;
    if (null != iconEncoded && iconEncoded.trim().length() > 0) {
        iconData = iconEncoded;
    } else if (null != icon && icon.trim().length() > 0) {
        final String iconUrl = workDefinition.getPath() + "/" + icon;
        iconData = dataUriProvider.apply(iconUrl);
    }
    iconDefinition.setUri(icon);
    iconDefinition.setIconData(iconData);
    workItem.setIconDefinition(iconDefinition);
    // Parameters.
    workItem.setParameters(parseParameters(workDefinition.getParameters()));
    // Results.
    workItem.setResults(parseParameters(workDefinition.getResults()));
    // Dependencies.
    final String[] dependencies = workDefinition.getMavenDependencies();
    final List<Dependency> dependencyList = null == dependencies ? Collections.emptyList() : Stream.of(dependencies).map(WorkItemDefinitionParser::parseDependency).filter(Objects::nonNull).collect(Collectors.toList());
    workItem.setDependencies(new Dependencies(dependencyList));
    return workItem;
}
Also used : WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Objects(java.util.Objects) Dependency(org.guvnor.common.services.project.model.Dependency) Dependencies(org.guvnor.common.services.project.model.Dependencies) IconDefinition(org.kie.workbench.common.stunner.bpmn.workitem.IconDefinition)

Aggregations

WorkItemDefinition (org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition)33 Test (org.junit.Test)18 IconDefinition (org.kie.workbench.common.stunner.bpmn.workitem.IconDefinition)5 Collection (java.util.Collection)4 Dependencies (org.guvnor.common.services.project.model.Dependencies)4 WorkItemDefinitionRegistry (org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry)4 Map (java.util.Map)3 Consumer (java.util.function.Consumer)3 Function (java.util.function.Function)3 Inject (javax.inject.Inject)3 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)3 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)3 NoneTask (org.kie.workbench.common.stunner.bpmn.definition.NoneTask)3 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2