use of org.jbpm.services.api.DefinitionService in project droolsjbpm-integration by kiegroup.
the class FormRendererBaseTest method testGenerateDefaultForm.
@Test
public void testGenerateDefaultForm() {
DefinitionService definitionService = mock(DefinitionService.class);
UserTaskService userTaskService = mock(UserTaskService.class);
FormManagerService formManagerService = mock(FormManagerService.class);
CaseRuntimeDataService caseRuntimeDataService = mock(CaseRuntimeDataService.class);
KieServerRegistry registry = mock(KieServerRegistry.class);
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getId()).thenReturn("testprocess");
when(processDefinition.getName()).thenReturn("Test Process");
FormRendererBase rendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);
when(registry.getContainerId(any(), any())).thenReturn("test");
when(definitionService.getProcessDefinition(eq("test"), eq("test-process"))).thenReturn(processDefinition);
String result = rendererBase.getProcessRenderedForm("patternfly", "test", "test-process");
logger.debug("Form content is '{}'", result);
assertThat(result).isNotNull().isNotEmpty();
// it has the patternfly (default renderer) css
assertThat(result).contains("/files/patternfly/css/patternfly.min.css\" rel=\"stylesheet\">");
assertThat(result).contains("/files/patternfly/css/patternfly-additions.min.css\" rel=\"stylesheet\">");
// it has required js files
assertThat(result).contains("/files/patternfly/js/jquery.min.js\"></script>");
assertThat(result).contains("/files/patternfly/js/patternfly.min.js\"></script>");
assertThat(result).contains("/files/js/kieserver-ui.js\"></script>");
// it has the form header
assertThat(result).contains("<h3 class=\"panel-title\">Default form - Test Process</h3>");
}
use of org.jbpm.services.api.DefinitionService in project droolsjbpm-integration by kiegroup.
the class FormRendererBaseTest method testGenerateDefaultFormWithVariables.
@Test
public void testGenerateDefaultFormWithVariables() {
DefinitionService definitionService = mock(DefinitionService.class);
UserTaskService userTaskService = mock(UserTaskService.class);
FormManagerService formManagerService = mock(FormManagerService.class);
CaseRuntimeDataService caseRuntimeDataService = mock(CaseRuntimeDataService.class);
KieServerRegistry registry = mock(KieServerRegistry.class);
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getId()).thenReturn("testprocess");
when(processDefinition.getName()).thenReturn("Test Process");
Map<String, String> variables = new HashMap<>();
variables.put("name", "java.lang.String");
variables.put("age", "java.lang.Integer");
variables.put("maried", "java.lang.Boolean");
when(processDefinition.getProcessVariables()).thenReturn(variables);
Map<String, Set<String>> tags = new HashMap<>();
Set<String> tags1 = new HashSet<>();
tags1.add("required");
Set<String> tags2 = new HashSet<>();
tags2.add("readonly");
tags.put("name", tags1);
tags.put("maried", tags2);
when(processDefinition.getTagsInfo()).thenReturn(tags);
when(processDefinition.getTagsForVariable(eq("name"))).thenReturn(tags1);
when(processDefinition.getTagsForVariable(eq("maried"))).thenReturn(tags2);
FormRendererBase rendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);
when(registry.getContainerId(any(), any())).thenReturn("test");
when(definitionService.getProcessDefinition(eq("test"), eq("test-process"))).thenReturn(processDefinition);
String result = rendererBase.getProcessRenderedForm("patternfly", "test", "test-process");
// it has the patternfly (default renderer) css
assertThat(result).contains("/files/patternfly/css/patternfly.min.css\" rel=\"stylesheet\">");
assertThat(result).contains("/files/patternfly/css/patternfly-additions.min.css\" rel=\"stylesheet\">");
// it has required js files
assertThat(result).contains("/files/patternfly/js/jquery.min.js\"></script>");
assertThat(result).contains("/files/patternfly/js/patternfly.min.js\"></script>");
assertThat(result).contains("/files/js/kieserver-ui.js\"></script>");
// it has the form header
assertThat(result).contains("<h3 class=\"panel-title\">Default form - Test Process</h3>");
// it has all three variables rendered
Pattern namePattern = Pattern.compile("<input name=\"name\" type=\"text\" class=\"form-control\".*required.*>");
Matcher nameMatcher = namePattern.matcher(result);
assertTrue(nameMatcher.find());
Pattern mariedPattern = Pattern.compile("<input name=\"maried\" type=\"checkbox\" class=\"form-control\".*readonly.*>");
Matcher mariedMatcher = mariedPattern.matcher(result);
assertTrue(mariedMatcher.find());
assertThat(result).contains("<input name=\"age\" type=\"text\" class=\"form-control\" ");
// it has start process button
assertThat(result).contains("<button type=\"button\" class=\"btn btn-primary\" onclick=\"startProcess(this);\">Submit</button>");
}
use of org.jbpm.services.api.DefinitionService in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtension method configureServices.
protected void configureServices(KieServerImpl kieServer, KieServerRegistry registry) {
KieServerConfig config = registry.getConfig();
// loaded from system property as callback info isn't stored as configuration in kie server repository
String callbackConfig = System.getProperty(KieServerConstants.CFG_HT_CALLBACK);
// if no other callback set, use Elytron or jaas by default
if (callbackConfig == null || callbackConfig.isEmpty()) {
if (ElytronIdentityProvider.available()) {
System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "custom");
String name = ElytronUserGroupCallbackImpl.class.getName();
ElytronUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
System.setProperty(KieServerConstants.CFG_HT_CALLBACK_CLASS, name);
} else {
System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "jaas");
JAASUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
}
}
this.isExecutorAvailable = isExecutorOnClasspath();
EntityManagerFactory emf = build(getPersistenceProperties(config));
EntityManagerFactoryManager.get().addEntityManagerFactory(persistenceUnitName, emf);
formManagerService = new FormManagerServiceImpl();
// build definition service
definitionService = new BPMN2DataServiceImpl();
// build deployment service
deploymentService = new KModuleDeploymentService();
((KModuleDeploymentService) deploymentService).setBpmn2Service(definitionService);
((KModuleDeploymentService) deploymentService).setEmf(emf);
((KModuleDeploymentService) deploymentService).setIdentityProvider(registry.getIdentityProvider());
((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
// configure user group callback
UserGroupCallback userGroupCallback = UserDataServiceProvider.getUserGroupCallback();
UserInfo userInfo = UserDataServiceProvider.getUserInfo();
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(userGroupCallback).userInfo(userInfo).getTaskService();
// build runtime data service
runtimeDataService = new RuntimeDataServiceImpl();
((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(registry.getIdentityProvider());
((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
// build process service
processService = new ProcessServiceImpl();
((ProcessServiceImpl) processService).setDataService(runtimeDataService);
((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
// build user task service
userTaskService = new UserTaskServiceImpl();
((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
// build query service
queryService = new QueryServiceImpl();
((QueryServiceImpl) queryService).setIdentityProvider(registry.getIdentityProvider());
((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
Function<String, String> kieServerDataSourceResolver = input -> {
String dataSource = input;
Matcher matcher = PARAMETER_MATCHER.matcher(dataSource);
while (matcher.find()) {
String paramName = matcher.group(1);
KieServerConfig configuration = context.getStateRepository().load(KieServerEnvironment.getServerId()).getConfiguration();
dataSource = configuration.getConfigItemValue(paramName, "java:jboss/datasources/ExampleDS");
logger.info("Data source expression {} resolved to {}", input, dataSource);
}
return dataSource;
};
((QueryServiceImpl) queryService).setDataSourceResolver(kieServerDataSourceResolver);
((QueryServiceImpl) queryService).init();
// set runtime data service as listener on deployment service
((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) definitionService));
((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
if (config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_DISABLED, "false").equalsIgnoreCase("false")) {
String executorQueueName = config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_JMS_QUEUE, "queue/KIE.SERVER.EXECUTOR");
// build executor service
executorService = ExecutorServiceFactory.newExecutorService(emf);
executorService.setInterval(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_INTERVAL, "0")));
executorService.setRetries(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_RETRIES, "3")));
executorService.setThreadPoolSize(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_POOL, "1")));
executorService.setTimeunit(TimeUnit.valueOf(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_TIME_UNIT, "SECONDS")));
((ExecutorImpl) ((ExecutorServiceImpl) executorService).getExecutor()).setQueueName(executorQueueName);
((KModuleDeploymentService) deploymentService).setExecutorService(executorService);
}
// admin services
this.processInstanceMigrationService = new ProcessInstanceMigrationServiceImpl();
this.processInstanceAdminService = new ProcessInstanceAdminServiceImpl();
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setProcessService(processService);
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setRuntimeDataService(runtimeDataService);
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setCommandService(new TransactionalCommandService(emf));
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setIdentityProvider(registry.getIdentityProvider());
this.userTaskAdminService = new UserTaskAdminServiceImpl();
((UserTaskAdminServiceImpl) this.userTaskAdminService).setRuntimeDataService(runtimeDataService);
((UserTaskAdminServiceImpl) this.userTaskAdminService).setUserTaskService(userTaskService);
((UserTaskAdminServiceImpl) this.userTaskAdminService).setIdentityProvider(context.getIdentityProvider());
((UserTaskAdminServiceImpl) this.userTaskAdminService).setCommandService(new TransactionalCommandService(emf));
this.advanceRuntimeDataService = new AdvanceRuntimeDataServiceImpl();
((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setEmf(emf);
((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setCommandService(new TransactionalCommandService(emf));
this.kieContainerCommandService = new JBPMKieContainerCommandServiceImpl(context, deploymentService, new DefinitionServiceBase(definitionService, context), new ProcessServiceBase(processService, definitionService, runtimeDataService, context), new UserTaskServiceBase(userTaskService, context), new RuntimeDataServiceBase(runtimeDataService, advanceRuntimeDataService, context), new ExecutorServiceBase(executorService, context), new QueryDataServiceBase(queryService, context), new DocumentServiceBase(context), new ProcessAdminServiceBase(processInstanceMigrationService, processInstanceAdminService, runtimeDataService, context), new UserTaskAdminServiceBase(userTaskAdminService, context));
}
use of org.jbpm.services.api.DefinitionService in project droolsjbpm-integration by kiegroup.
the class JBPMUIKieServerExtension method init.
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
this.registry = registry;
KieServerExtension jbpmExtension = registry.getServerExtension("jBPM");
if (jbpmExtension == null) {
initialized = false;
logger.warn("jBPM extension not found, jBPM UI cannot work without jBPM extension, disabling itself");
return;
}
List<Object> jbpmServices = jbpmExtension.getServices();
RuntimeDataService runtimeDataService = null;
DefinitionService definitionService = null;
UserTaskService userTaskService = null;
FormManagerService formManagerService = null;
CaseRuntimeDataService caseRuntimeDataService = null;
for (Object object : jbpmServices) {
// in case given service is null (meaning was not configured) continue with next one
if (object == null) {
continue;
}
if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
runtimeDataService = (RuntimeDataService) object;
continue;
} else if (DefinitionService.class.isAssignableFrom(object.getClass())) {
definitionService = (DefinitionService) object;
continue;
} else if (UserTaskService.class.isAssignableFrom(object.getClass())) {
userTaskService = (UserTaskService) object;
continue;
} else if (FormManagerService.class.isAssignableFrom(object.getClass())) {
formManagerService = (FormManagerService) object;
continue;
} else if (DeploymentService.class.isAssignableFrom(object.getClass())) {
deploymentService = (DeploymentService) object;
continue;
}
}
KieServerExtension caseExtension = registry.getServerExtension("Case-Mgmt");
if (caseExtension != null) {
List<Object> caseMgmtServices = caseExtension.getServices();
for (Object object : caseMgmtServices) {
// in case given service is null (meaning was not configured) continue with next one
if (object == null) {
continue;
}
if (CaseRuntimeDataService.class.isAssignableFrom(object.getClass())) {
caseRuntimeDataService = (CaseRuntimeDataService) object;
continue;
}
}
} else {
logger.warn("Case-Mgmt extension not found, jBPM UI capabilities will be limited");
}
formServiceBase = new FormServiceBase(definitionService, runtimeDataService, userTaskService, formManagerService, registry);
imageServiceBase = new ImageServiceBase(runtimeDataService, imageReferences, registry);
formRendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);
services.add(formServiceBase);
services.add(imageServiceBase);
services.add(formRendererBase);
this.kieContainerCommandService = new JBPMUIKieContainerCommandServiceImpl(null, formServiceBase, imageServiceBase, formRendererBase);
initialized = true;
}
use of org.jbpm.services.api.DefinitionService in project droolsjbpm-integration by kiegroup.
the class JbpmRestApplicationComponentsService method getAppComponents.
@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
// skip calls from other than owning extension
if (!OWNER_EXTENSION.equals(extension)) {
return Collections.emptyList();
}
ProcessService processService = null;
RuntimeDataService runtimeDataService = null;
DefinitionService definitionService = null;
UserTaskService userTaskService = null;
ExecutorService executorService = null;
QueryService queryService = null;
ProcessInstanceMigrationService processInstanceMigrationService = null;
ProcessInstanceAdminService processInstanceAdminService = null;
UserTaskAdminService userTaskAdminService = null;
KieServerRegistry context = null;
AdvanceRuntimeDataService advanceRuntimeDataService = null;
for (Object object : services) {
// in case given service is null (meaning was not configured) continue with next one
if (object == null) {
continue;
}
if (ProcessService.class.isAssignableFrom(object.getClass())) {
processService = (ProcessService) object;
continue;
} else if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
runtimeDataService = (RuntimeDataService) object;
continue;
} else if (DefinitionService.class.isAssignableFrom(object.getClass())) {
definitionService = (DefinitionService) object;
continue;
} else if (UserTaskService.class.isAssignableFrom(object.getClass())) {
userTaskService = (UserTaskService) object;
continue;
} else if (ExecutorService.class.isAssignableFrom(object.getClass())) {
executorService = (ExecutorService) object;
continue;
} else if (QueryService.class.isAssignableFrom(object.getClass())) {
queryService = (QueryService) object;
continue;
} else if (ProcessInstanceMigrationService.class.isAssignableFrom(object.getClass())) {
processInstanceMigrationService = (ProcessInstanceMigrationService) object;
continue;
} else if (ProcessInstanceAdminService.class.isAssignableFrom(object.getClass())) {
processInstanceAdminService = (ProcessInstanceAdminService) object;
continue;
} else if (UserTaskAdminService.class.isAssignableFrom(object.getClass())) {
userTaskAdminService = (UserTaskAdminService) object;
continue;
} else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
context = (KieServerRegistry) object;
continue;
} else if (AdvanceRuntimeDataService.class.isAssignableFrom(object.getClass())) {
advanceRuntimeDataService = (AdvanceRuntimeDataService) object;
continue;
}
}
List<Object> components = new ArrayList<Object>(6);
DefinitionServiceBase definitionServiceBase = new DefinitionServiceBase(definitionService, context);
ProcessServiceBase processServiceBase = new ProcessServiceBase(processService, definitionService, runtimeDataService, context);
UserTaskServiceBase userTaskServiceBase = new UserTaskServiceBase(userTaskService, context);
RuntimeDataServiceBase runtimeDataServiceBase = new RuntimeDataServiceBase(runtimeDataService, advanceRuntimeDataService, context);
ExecutorServiceBase executorServiceBase = new ExecutorServiceBase(executorService, context);
QueryDataServiceBase queryDataServiceBase = new QueryDataServiceBase(queryService, context);
DocumentServiceBase documentServiceBase = new DocumentServiceBase(context);
ProcessAdminServiceBase processAdminServiceBase = new ProcessAdminServiceBase(processInstanceMigrationService, processInstanceAdminService, runtimeDataService, context);
UserTaskAdminServiceBase userTaskAdminServiceBase = new UserTaskAdminServiceBase(userTaskAdminService, context);
components.add(new ProcessResource(processServiceBase, runtimeDataServiceBase, context));
components.add(new RuntimeDataResource(runtimeDataServiceBase, context));
components.add(new DefinitionResource(definitionServiceBase, context));
components.add(new UserTaskResource(userTaskServiceBase, runtimeDataServiceBase, context));
components.add(new ExecutorResource(executorServiceBase, context));
components.add(new QueryDataResource(queryDataServiceBase, context));
components.add(new DocumentResource(documentServiceBase, context));
components.add(new ProcessAdminResource(processAdminServiceBase, context));
components.add(new UserTaskAdminResource(userTaskAdminServiceBase, context));
return components;
}
Aggregations