use of org.kie.server.services.api.KieServerRegistry 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.kie.server.services.api.KieServerRegistry 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.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.
the class QueryDataServiceBaseTest method testLoadDefaultQueryDefinitions.
@Test
public void testLoadDefaultQueryDefinitions() {
Date today = new Date();
KieServerEnvironment.setServerId(UUID.randomUUID().toString());
QueryService queryService = Mockito.mock(QueryService.class);
KieServerRegistry context = new KieServerRegistryImpl();
context.registerStateRepository(new KieServerStateFileRepository(new File("target")));
JbpmKieServerExtension extension = new JbpmKieServerExtension();
extension.setQueryService(queryService);
extension.setContext(context);
extension.registerDefaultQueryDefinitions();
QueryDataServiceBase queryServiceBase = new QueryDataServiceBase(queryService, context);
QueryResultMapper<?> resultMapper = QueryMapperRegistry.get().mapperFor("UserTasksWithPotOwners", null);
List<UserTaskInstanceWithPotOwnerDesc> result = new ArrayList<UserTaskInstanceWithPotOwnerDesc>();
UserTaskInstanceWithPotOwnerDesc resultPO = new org.jbpm.kie.services.impl.model.UserTaskInstanceWithPotOwnerDesc("mcivantos", "mcivantos", today, today, Long.valueOf(1), "test-task", "task description", 0, Long.valueOf(1), "processId", "Reserved", "salaboy", "formName", "correlation-123", "subject", "container-1", "processDescription");
result.add(resultPO);
Object resultQueryBase = queryServiceBase.transform(result, resultMapper);
assertNotNull(resultQueryBase);
}
use of org.kie.server.services.api.KieServerRegistry in project businessautomation-cop by redhat-cop.
the class AbortExtensionComponentService method getAppComponents.
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;
KieServerRegistry registry = null;
for (Object object : services) {
if (ProcessService.class.isAssignableFrom(object.getClass())) {
processService = (ProcessService) object;
continue;
} else if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
runtimeDataService = (RuntimeDataService) object;
continue;
} else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
registry = (KieServerRegistry) object;
continue;
}
}
List<Object> components = new ArrayList<Object>(1);
if (SupportedTransports.REST.equals(type)) {
components.add(new AbortAllResource(processService, runtimeDataService, registry));
}
return components;
}
use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.
the class MarshallerHelperTest method testJsonMarshallWithEmptyRegistry.
@Test
public void testJsonMarshallWithEmptyRegistry() throws Exception {
KieServerRegistry kieServerRegistryMock = Mockito.mock(KieServerRegistry.class);
Mockito.when(kieServerRegistryMock.getExtraClasses()).thenReturn(new HashSet<Class<?>>());
MarshallerHelper helper = new MarshallerHelper(kieServerRegistryMock);
QueryFilterSpec queryFilterSpec = new QueryFilterSpecBuilder().get();
String marshalledQFS = helper.marshal(MarshallingFormat.JSON.toString(), queryFilterSpec);
System.out.println(marshalledQFS);
String expectedMarshalledTEC = "{\"order-by\" : null, \"order-asc\" : false, \"query-params\" : null, \"result-column-mapping\" : null}";
JSONAssert.assertEquals(expectedMarshalledTEC, marshalledQFS, false);
}
Aggregations