Search in sources :

Example 1 with TaskCommand

use of org.jbpm.services.task.commands.TaskCommand in project jbpm by kiegroup.

the class UserTaskServiceImpl method getRuntimeManager.

protected RuntimeManager getRuntimeManager(String deploymentId, Command<?> command) {
    if (deploymentId == null && command instanceof TaskCommand<?>) {
        Long taskId = ((TaskCommand<?>) command).getTaskId();
        if (taskId != null) {
            UserTaskInstanceDesc task = dataService.getTaskById(taskId);
            deploymentId = task.getDeploymentId();
        }
    }
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentId);
    if (manager == null) {
        InternalTaskService internalTaskService = getInternalTaskService();
        if (internalTaskService != null) {
            manager = new FalbackRuntimeManager(internalTaskService);
        } else {
            logger.warn("Cannot find runtime manager for deployment {}", deploymentId);
            throw new RuntimeException("No runtime manager found for deployment " + deploymentId);
        }
    }
    return manager;
}
Also used : RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) TaskCommand(org.jbpm.services.task.commands.TaskCommand) UpdateTaskCommand(org.jbpm.kie.services.impl.admin.commands.UpdateTaskCommand)

Example 2 with TaskCommand

use of org.jbpm.services.task.commands.TaskCommand in project jbpm by kiegroup.

the class JaxbTaskSerializationTest method compositeCommandXmlElementsAnnoTest.

@Test
public void compositeCommandXmlElementsAnnoTest() throws Exception {
    Field[] comCmdFields = CompositeCommand.class.getDeclaredFields();
    for (Field field : comCmdFields) {
        XmlElements xmlElemsAnno = field.getAnnotation(XmlElements.class);
        if (xmlElemsAnno != null) {
            Set<Class<? extends TaskCommand>> taskCmdSubTypes = reflections.getSubTypesOf(TaskCommand.class);
            Set<Class<? extends UserGroupCallbackTaskCommand>> userGrpTaskCmdSubTypes = reflections.getSubTypesOf(UserGroupCallbackTaskCommand.class);
            taskCmdSubTypes.addAll(userGrpTaskCmdSubTypes);
            Class[] exclTaskCmds = { UserGroupCallbackTaskCommand.class, CompositeCommand.class, GetCurrentTxTasksCommand.class };
            taskCmdSubTypes.removeAll(Arrays.asList(exclTaskCmds));
            for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
                Class xmlElemAnnoType = xmlElemAnno.type();
                assertTrue(xmlElemAnnoType.getName() + " does not extend the " + TaskCommand.class.getSimpleName() + " class!", taskCmdSubTypes.contains(xmlElemAnnoType));
            }
            for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
                Class xmlElemAnnoType = xmlElemAnno.type();
                taskCmdSubTypes.remove(xmlElemAnnoType);
            }
            if (!taskCmdSubTypes.isEmpty()) {
                System.out.println("##### " + taskCmdSubTypes.iterator().next().getCanonicalName());
                fail("(" + taskCmdSubTypes.iterator().next().getSimpleName() + ") Not all " + TaskCommand.class.getSimpleName() + " sub types have been added to the @XmlElements in the CompositeCommand." + field.getName() + " field.");
            }
        } else {
            assertFalse("TaskCommand fields need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(field.getType()));
            if (field.getType().isArray()) {
                Class arrElemType = field.getType().getComponentType();
                if (arrElemType != null) {
                    assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(arrElemType));
                }
            } else if (Collection.class.isAssignableFrom(field.getType())) {
                ParameterizedType fieldGenericType = (ParameterizedType) field.getGenericType();
                Type listType = fieldGenericType.getActualTypeArguments()[0];
                if (listType != null) {
                    assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(listType));
                }
            }
        }
    }
}
Also used : UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) XmlElements(javax.xml.bind.annotation.XmlElements) Type(java.lang.reflect.Type) AccessType(org.kie.internal.task.api.model.AccessType) TestType(org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlElement(javax.xml.bind.annotation.XmlElement) Collection(java.util.Collection) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskCommand(org.jbpm.services.task.commands.TaskCommand) Test(org.junit.Test)

Aggregations

TaskCommand (org.jbpm.services.task.commands.TaskCommand)2 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 UpdateTaskCommand (org.jbpm.kie.services.impl.admin.commands.UpdateTaskCommand)1 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 TestType (org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType)1 Test (org.junit.Test)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1 InternalTaskService (org.kie.internal.task.api.InternalTaskService)1 AccessType (org.kie.internal.task.api.model.AccessType)1