コード例 #1
0
  protected static List<OrganizationalEntity> getOrganizationalEntityListFromParams(
      Map<String, String[]> params, boolean required, String operation) {
    List<OrganizationalEntity> orgEntList = new ArrayList<OrganizationalEntity>();

    String[] users = getStringListParam("user", false, params, operation);
    String[] groups = getStringListParam("group", false, params, operation);
    if (required && (users.length == 0) && (groups.length == 0)) {
      throw KieRemoteRestOperationException.badRequest(
          "At least 1 query parameter (either 'user' or 'group') is required for the '"
              + operation
              + "' operation.");
    }

    for (String user : users) {
      User newuser = TaskModelProvider.getFactory().newUser();
      ((InternalOrganizationalEntity) newuser).setId(user);
      orgEntList.add(newuser);
    }
    for (String group : groups) {
      Group newuser = TaskModelProvider.getFactory().newGroup();
      ((InternalOrganizationalEntity) newuser).setId(group);
      orgEntList.add(newuser);
    }

    return orgEntList;
  }
コード例 #2
0
ファイル: AddGroupCommand.java プロジェクト: hmilywb/jbpm
  public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;

    Group group = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) group).setId(groupId);

    context.getTaskIdentityService().addGroup(group);
    return null;
  }
コード例 #3
0
  private Notification buildDefaultNotification(TaskData taskData, Task task) {
    EmailNotification emailNotificationImpl = TaskModelProvider.getFactory().newEmialNotification();
    Map<Language, EmailNotificationHeader> map = new HashMap<Language, EmailNotificationHeader>();
    EmailNotificationHeader emailNotificationHeaderImpl =
        TaskModelProvider.getFactory().newEmailNotificationHeader();
    emailNotificationHeaderImpl.setBody(buildDefafultEmailBody(taskData, task));
    emailNotificationHeaderImpl.setFrom(fromUser);
    emailNotificationHeaderImpl.setReplyTo(fromUser);
    emailNotificationHeaderImpl.setLanguage("en-UK");
    emailNotificationHeaderImpl.setSubject(buildDefafultEmailSubject(taskData, task));
    Language language = TaskModelProvider.getFactory().newLanguage();
    language.setMapkey("en-UK");
    map.put(language, emailNotificationHeaderImpl);
    emailNotificationImpl.setEmailHeaders(map);

    List<OrganizationalEntity> recipients = new ArrayList<OrganizationalEntity>();
    recipients.add(taskData.getActualOwner());
    emailNotificationImpl.setRecipients(recipients);

    return emailNotificationImpl;
  }
コード例 #4
0
ファイル: LDAPUserInfoImpl.java プロジェクト: bobolau/jbpm
  public Iterator<OrganizationalEntity> getMembersForGroup(Group group) {
    InitialLdapContext ctx = null;
    List<OrganizationalEntity> memebers = new ArrayList<OrganizationalEntity>();
    try {
      ctx = buildInitialLdapContext();

      String roleContext = this.config.getProperty(ROLE_CTX);
      String roleFilter =
          this.config.getProperty(ROLE_MEMBERS_FILTER, this.config.getProperty(ROLE_FILTER));
      String roleAttrId = this.config.getProperty(MEMBER_ATTR_ID, "member");

      String entityId = group.getId();
      if (Boolean.parseBoolean(this.config.getProperty(IS_ENTITY_ID_DN, "false"))) {
        entityId = extractUserId(entityId, group);
      }

      roleFilter = roleFilter.replaceAll("\\{0\\}", entityId);

      SearchControls constraints = new SearchControls();
      String searchScope = this.config.getProperty(SEARCH_SCOPE);
      if (searchScope != null) {
        constraints.setSearchScope(parseSearchScope(searchScope));
      }

      NamingEnumeration<SearchResult> result = ctx.search(roleContext, roleFilter, constraints);
      while (result.hasMore()) {
        SearchResult sr = result.next();
        Attribute member = sr.getAttributes().get(roleAttrId);
        for (int i = 0; i < member.size(); i++) {
          User user = TaskModelProvider.getFactory().newUser();
          ((InternalOrganizationalEntity) user).setId(member.get(i).toString());
          memebers.add(user);
        }
      }
      result.close();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (ctx != null) {
        try {
          ctx.close();
        } catch (NamingException e) {
          e.printStackTrace();
        }
      }
    }
    return memebers.iterator();
  }
コード例 #5
0
ファイル: DBUserInfoImpl.java プロジェクト: ibek/jbpm
  @Override
  public Iterator<OrganizationalEntity> getMembersForGroup(Group group) {
    List<OrganizationalEntity> roles = new ArrayList<OrganizationalEntity>();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      conn = ds.getConnection();

      ps = conn.prepareStatement(this.config.getProperty(MEMBERS_QUERY));
      try {
        ps.setString(1, group.getId());
      } catch (ArrayIndexOutOfBoundsException ignore) {

      }
      rs = ps.executeQuery();
      while (rs.next()) {
        roles.add(TaskModelProvider.getFactory().newUser(rs.getString(1)));
      }
    } catch (Exception e) {
      logger.error("Error when fetching members of a group from db, groups id: ", group.getId(), e);
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
        }
      }
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException e) {
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (Exception ex) {
        }
      }
    }
    return roles.iterator();
  }
コード例 #6
0
  @SuppressWarnings("unchecked")
  public long addOutputContent(long taskId, Map<String, Object> params) {
    Task task = persistenceContext.findTask(taskId);
    long outputContentId = task.getTaskData().getOutputContentId();
    Content outputContent = persistenceContext.findContent(outputContentId);

    long contentId = -1;
    if (outputContent == null) {
      ContentMarshallerContext context = getMarshallerContext(task);
      ContentData outputContentData =
          ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
      Content content = TaskModelProvider.getFactory().newContent();
      ((InternalContent) content).setContent(outputContentData.getContent());
      persistenceContext.persistContent(content);

      ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
      contentId = content.getId();
    } else {
      // I need to merge it if it already exist
      ContentMarshallerContext context = getMarshallerContext(task);
      Object unmarshalledObject =
          ContentMarshallerHelper.unmarshall(
              outputContent.getContent(), context.getEnvironment(), context.getClassloader());
      if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
        ((Map<String, Object>) unmarshalledObject).putAll(params);
      }
      ContentData outputContentData =
          ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
      ((InternalContent) outputContent).setContent(outputContentData.getContent());
      persistenceContext.persistContent(outputContent);
      contentId = outputContentId;
    }
    ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
    taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);

    return contentId;
  }
コード例 #7
0
  public void taskOperation(
      final Operation operation,
      final long taskId,
      final String userId,
      final String targetEntityId,
      final Map<String, Object> data,
      List<String> groupIds,
      OrganizationalEntity... entities)
      throws TaskException {

    try {
      final List<OperationCommand> commands = operations.get(operation);

      Task task = persistenceContext.findTask(taskId);
      if (task == null) {
        String errorMessage = "Task '" + taskId + "' not found";
        throw new PermissionDeniedException(errorMessage);
      }
      User user = persistenceContext.findUser(userId);
      OrganizationalEntity targetEntity = null;
      if (targetEntityId != null && !targetEntityId.equals("")) {
        targetEntity = persistenceContext.findOrgEntity(targetEntityId);
      }

      switch (operation) {
        case Activate:
          {
            taskEventSupport.fireBeforeTaskActivated(task, context);
            break;
          }
        case Claim:
          {
            taskEventSupport.fireBeforeTaskClaimed(task, context);
            break;
          }
        case Complete:
          {
            taskEventSupport.fireBeforeTaskCompleted(task, context);
            break;
          }
        case Delegate:
          {
            taskEventSupport.fireBeforeTaskDelegated(task, context);
            break;
          }
        case Exit:
          {
            taskEventSupport.fireBeforeTaskExited(task, context);
            break;
          }

        case Fail:
          {
            if (data != null) {

              FaultData faultData = ContentMarshallerHelper.marshalFault(data, null);
              Content content = TaskModelProvider.getFactory().newContent();
              ((InternalContent) content).setContent(faultData.getContent());
              persistenceContext.persistContent(content);
              ((InternalTaskData) task.getTaskData()).setFault(content.getId(), faultData);
            }
            taskEventSupport.fireBeforeTaskFailed(task, context);
            break;
          }
        case Forward:
          {
            taskEventSupport.fireBeforeTaskForwarded(task, context);
            break;
          }
        case Nominate:
          {
            taskEventSupport.fireBeforeTaskNominated(task, context);
            break;
          }
        case Release:
          {
            taskEventSupport.fireBeforeTaskReleased(task, context);
            break;
          }
        case Resume:
          {
            taskEventSupport.fireBeforeTaskResumed(task, context);
            break;
          }
        case Skip:
          {
            taskEventSupport.fireBeforeTaskSkipped(task, context);
            break;
          }
        case Start:
          {
            taskEventSupport.fireBeforeTaskStarted(task, context);
            break;
          }
        case Stop:
          {
            taskEventSupport.fireBeforeTaskStopped(task, context);
            break;
          }
        case Suspend:
          {
            taskEventSupport.fireBeforeTaskSuspended(task, context);
            break;
          }
      }

      evalCommand(operation, commands, task, user, targetEntity, groupIds, entities);

      switch (operation) {
        case Activate:
          {
            taskEventSupport.fireAfterTaskActivated(task, context);
            break;
          }
        case Claim:
          {
            taskEventSupport.fireAfterTaskClaimed(task, context);
            break;
          }
        case Complete:
          {
            if (data != null) {

              taskContentService.addOutputContent(taskId, data);
            }
            taskEventSupport.fireAfterTaskCompleted(task, context);
            break;
          }
        case Delegate:
          {
            // This is a really bad hack to execut the correct behavior
            ((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
            taskEventSupport.fireAfterTaskDelegated(task, context);
            break;
          }
        case Exit:
          {
            taskEventSupport.fireAfterTaskExited(task, context);
            break;
          }
        case Fail:
          {
            taskEventSupport.fireAfterTaskFailed(task, context);
            break;
          }
        case Forward:
          {
            taskEventSupport.fireAfterTaskForwarded(task, context);
            break;
          }
        case Nominate:
          {
            taskEventSupport.fireAfterTaskNominated(task, context);
            break;
          }
        case Release:
          {
            taskEventSupport.fireAfterTaskReleased(task, context);
            break;
          }
        case Resume:
          {
            taskEventSupport.fireAfterTaskResumed(task, context);
            break;
          }
        case Start:
          {
            taskEventSupport.fireAfterTaskStarted(task, context);
            break;
          }
        case Skip:
          {
            taskEventSupport.fireAfterTaskSkipped(task, context);
            break;
          }
        case Stop:
          {
            taskEventSupport.fireAfterTaskStopped(task, context);
            break;
          }
        case Suspend:
          {
            taskEventSupport.fireAfterTaskSuspended(task, context);
            break;
          }
      }
    } catch (RuntimeException re) {
      throw re;
    }
  }
コード例 #8
0
  @Test
  public void testSessionPerProcessInstance() throws Exception {
    RuntimeEnvironment environment =
        RuntimeEnvironmentBuilder.Factory.get()
            .newDefaultBuilder()
            .entityManagerFactory(emf)
            .userGroupCallback(userGroupCallback)
            .addAsset(
                ResourceFactory.newClassPathResource(
                    "org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"),
                ResourceType.BPMN2)
            .schedulerService(globalScheduler)
            .get();

    long startTimeStamp = System.currentTimeMillis();
    long maxEndTime = startTimeStamp + maxWaitTime;

    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    // prepare task service with users and groups
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = engine.getTaskService();

    Group grouphr = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) grouphr).setId("HR");

    User mary = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) mary).setId("mary");
    User john = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) john).setId("john");

    ((InternalTaskService) taskService).addGroup(grouphr);
    ((InternalTaskService) taskService).addUser(mary);
    ((InternalTaskService) taskService).addUser(john);

    manager.disposeRuntimeEngine(engine);

    completedStart = 0;
    for (int i = 0; i < nbThreadsProcess; i++) {
      new StartProcessPerProcessInstanceRunnable(manager, i).run();
    }
    completedTask = 0;
    for (int i = 0; i < nbThreadsTask; i++) {
      new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start();
    }
    while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) {
      Thread.sleep(100);
      if (System.currentTimeMillis() > maxEndTime) {
        fail("Failure, did not finish in time most likely hanging");
      }
    }
    // make sure all process instance were completed
    engine = manager.getRuntimeEngine(EmptyContext.get());
    AuditService logService = engine.getAuditService();
    // active
    List<? extends ProcessInstanceLog> logs =
        logService.findActiveProcessInstances("IntermediateCatchEvent");
    assertNotNull(logs);
    for (ProcessInstanceLog log : logs) {
      logger.debug("Left over {}", log.getProcessInstanceId());
    }
    assertEquals(0, logs.size());

    // completed
    logs = logService.findProcessInstances("IntermediateCatchEvent");
    assertNotNull(logs);
    assertEquals(nbThreadsProcess, logs.size());
    manager.disposeRuntimeEngine(engine);

    logger.debug("Done");
  }