Package org.drools.task

Examples of org.drools.task.TaskData


                                UserInfo userInfo) {
      if (userInfo == null) {
        return;
      }
     
        TaskData data = task.getTaskData();
        User owner = data.getActualOwner();
        User creator = data.getCreatedBy();
        Date createdOn = data.getCreatedOn();

        if ( task.getDeadlines() == null ) {
            return;
        }
View Full Code Here


                buildMapByLanguage( users,
                                    (User) entity );
            }
        }

        TaskData taskData = task.getTaskData();
        Map<String, Object> doc = null;
        if ( taskData != null ) {
            Content content = em.find( Content.class,
                                       taskData.getDocumentContentId() );
            if ( content != null ) {
                ExpressionCompiler compiler = new ExpressionCompiler( new String( content.getContent() ) );
                doc = (Map<String, Object>) MVEL.executeExpression( compiler.compile() );
            } else {
                doc = Collections.emptyMap();
View Full Code Here

        // do nothing
      }
    }
    task.setPriority(priority);
   
    TaskData taskData = new TaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
        //Sub Task Data
        Long parentId = (Long) workItem.getParameter("ParentId");
        if(parentId != null){
            taskData.setParentId(parentId);
        }

        String subTaskStrategiesCommaSeparated = (String) workItem.getParameter("SubTaskStrategies");
        if(subTaskStrategiesCommaSeparated!= null && !subTaskStrategiesCommaSeparated.equals("")){
            String[] subTaskStrategies =  subTaskStrategiesCommaSeparated.split(",");
            List<SubTasksStrategy> strategies = new ArrayList<SubTasksStrategy>();
            for(String subTaskStrategyString : subTaskStrategies){
                SubTasksStrategy subTaskStrategy = SubTasksStrategyFactory.newStrategy(subTaskStrategyString);
                strategies.add(subTaskStrategy);
            }
            task.setSubTaskStrategies(strategies);
        }

        PeopleAssignments assignments = new PeopleAssignments();
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();

        String actorId = (String) workItem.getParameter("ActorId");
    if (actorId != null) {
     
      String[] actorIds = actorId.split(",");
      for (String id: actorIds) {
        User user = new User();
        user.setId(id.trim());
        potentialOwners.add(user);
      }
            //Set the first user as creator ID??? hmmm might be wrong
            if (potentialOwners.size() > 0){
                taskData.setCreatedBy((User)potentialOwners.get(0));
            }
        }
        String groupId = (String) workItem.getParameter("GroupId");
    if (groupId != null) {
     
View Full Code Here

        // do nothing
      }
    }
    task.setPriority(priority);
   
    TaskData taskData = new TaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
        //Sub Task Data
        Long parentId = (Long) workItem.getParameter("ParentId");
        if(parentId != null){
            taskData.setParentId(parentId);
        }

        String subTaskStrategiesCommaSeparated = (String) workItem.getParameter("SubTaskStrategies");
        if(subTaskStrategiesCommaSeparated!= null && !subTaskStrategiesCommaSeparated.equals("")){
            String[] subTaskStrategies =  subTaskStrategiesCommaSeparated.split(",");
            List<SubTasksStrategy> strategies = new ArrayList<SubTasksStrategy>();
            for(String subTaskStrategyString : subTaskStrategies){
                SubTasksStrategy subTaskStrategy = SubTasksStrategyFactory.newStrategy(subTaskStrategyString);
                strategies.add(subTaskStrategy);
            }
            task.setSubTaskStrategies(strategies);
        }

        PeopleAssignments assignments = new PeopleAssignments();
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();

        String actorId = (String) workItem.getParameter("ActorId");
    if (actorId != null) {
     
      String[] actorIds = actorId.split(",");
      for (String id: actorIds) {
        User user = new User();
        user.setId(id.trim());
        potentialOwners.add(user);
      }
            //Set the first user as creator ID??? hmmm might be wrong
            if (potentialOwners.size() > 0){
                taskData.setCreatedBy((User)potentialOwners.get(0));
            }
        }
        String groupId = (String) workItem.getParameter("GroupId");
    if (groupId != null) {
     
View Full Code Here

        // do nothing
      }
    }
    task.setPriority(priority);
   
    TaskData taskData = new TaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
        //Sub Task Data
        Long parentId = (Long) workItem.getParameter("ParentId");
        if(parentId != null){
            taskData.setParentId(parentId);
        }

        String subTaskStrategiesCommaSeparated = (String) workItem.getParameter("SubTaskStrategies");
        if(subTaskStrategiesCommaSeparated!= null && !subTaskStrategiesCommaSeparated.equals("")){
            String[] subTaskStrategies =  subTaskStrategiesCommaSeparated.split(",");
            List<SubTasksStrategy> strategies = new ArrayList<SubTasksStrategy>();
            for(String subTaskStrategyString : subTaskStrategies){
                SubTasksStrategy subTaskStrategy = SubTasksStrategyFactory.newStrategy(subTaskStrategyString);
                strategies.add(subTaskStrategy);
            }
            task.setSubTaskStrategies(strategies);
        }

        PeopleAssignments assignments = new PeopleAssignments();
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();

        String actorId = (String) workItem.getParameter("ActorId");
    if (actorId != null) {
     
      String[] actorIds = actorId.split(",");
      for (String id: actorIds) {
        User user = new User();
        user.setId(id.trim());
        potentialOwners.add(user);
      }
            //Set the first user as creator ID??? hmmm might be wrong
            if (potentialOwners.size() > 0){
                taskData.setCreatedBy((User)potentialOwners.get(0));
            }
        }
        String groupId = (String) workItem.getParameter("GroupId");
    if (groupId != null) {
     
View Full Code Here

        em.persist( group );
        em.getTransaction().commit();
    }

    public void addTask(Task task, ContentData contentData) {
        TaskData taskData = task.getTaskData();
        // new tasks start off with status created
        taskData.setStatus( Status.Created );

        // execute "addTask" rules
        if (ruleBases != null) {
          RuleBase ruleBase = ruleBases.get("addTask");
          if (ruleBase != null) {
            StatefulSession session = ruleBase.newStatefulSession();
          Map<String, Object> globals = this.globals.get("addTask");
          if (globals != null) {
            for (Map.Entry<String, Object> entry: globals.entrySet()) {
              session.setGlobal(entry.getKey(), entry.getValue());
            }
          }
          TaskServiceRequest request = new TaskServiceRequest("addTask", null, null);
          session.setGlobal("request", request);
            session.insert(task);
            session.insert(contentData);
            session.fireAllRules();
            if (!request.isAllowed()) {
              String error = "Cannot add Task:\n";
              if (request.getReasons() != null) {
                for (String reason: request.getReasons()) {
                  error += reason + "\n";
                }
              }
              throw new RuntimeException(error);
            }
          }
        }

        if ( task.getPeopleAssignments() != null ) {
            List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
            if ( potentialOwners.size() == 1 ) {
                // if there is a single potential owner, assign and set status to Reserved
                OrganizationalEntity potentialOwner = potentialOwners.get( 0 );
                // if there is a single potential user owner, assign and set status to Reserved
                if(potentialOwner instanceof User){
                taskData.setActualOwner( (User) potentialOwners.get( 0 ) );
                taskData.setStatus( Status.Reserved );
                }
                //If there is a group set as potentialOwners, set the status to Ready ??
                if(potentialOwner instanceof Group){

                    taskData.setStatus( Status.Ready );
                }
            } else if ( potentialOwners.size() > 1 ) {
                // multiple potential owners, so set to Ready so one can claim.
                taskData.setStatus( Status.Ready );
            } else {
                //@TODO we have no potential owners
            }
        } else {
            //@TODO we have no potential owners
        }

        // set the CreatedOn date if it's not already set
        if ( taskData.getCreatedOn() == null ) {
            taskData.setCreatedOn( new Date() );
        }

        //@FIXME for now we activate on creation, unless date is supplied
        if ( taskData.getActivationTime() == null ) {
            taskData.setActivationTime( taskData.getCreatedOn() );
        }
       
        em.getTransaction().begin();
        em.persist( task );
        if (contentData != null) {
          Content content = new Content();
          content.setContent(contentData.getContent());
          em.persist( content );
            taskData.setDocumentAccessType( contentData.getAccessType() );
            taskData.setDocumentType( contentData.getType() );
            taskData.setDocumentContentId( content.getId() );
        }
        em.getTransaction().commit();

        long now = System.currentTimeMillis();
        // schedule after it's been persisted, otherwise the id's won't be assigned
View Full Code Here

    public TaskError evalCommand(Operation operation,
                                 List<OperationCommand> commands,
                                 Task task,
                                 User user,
                                 OrganizationalEntity targetEntity) {
        TaskData taskData = task.getTaskData();
        boolean statusMatched = false;
        for ( OperationCommand command : commands ) {
            // first find out if we have a matching status
            if ( command.getStatus() != null ) {
                for ( Status status : command.getStatus() ) {
                    if ( taskData.getStatus() == status ) {
                        statusMatched = true;

                        // next find out if the user can execute this operation               
                        if ( !isAllowed( command,
                                         task,
                                         user,
                                         targetEntity ) ) {
                            return new TaskError( "User '" + user + "' does not have permissions to execution operation '" + operation + "' on task id " + task.getId() );

                        }

                        commands( command,
                                  task,
                                  user,
                                  targetEntity);
                        return null;
                    }
                }
            }

            if ( command.getPreviousStatus() != null ) {
                for ( Status status : command.getPreviousStatus() ) {
                    if ( taskData.getPreviousStatus() == status ) {
                        statusMatched = true;

                        // next find out if the user can execute this operation               
                        if ( !isAllowed( command,
                                         task,
View Full Code Here

    private boolean isAllowed(OperationCommand command,
                              Task task,
                              User user,
                              OrganizationalEntity targetEntity) {
        PeopleAssignments people = task.getPeopleAssignments();
        TaskData taskData = task.getTaskData();

        boolean operationAllowed = false;
        for ( Allowed allowed : command.getAllowed() ) {
            if ( operationAllowed ) {
                break;
            }
            switch ( allowed ) {
                case Owner : {
                    operationAllowed = (taskData.getActualOwner() != null && taskData.getActualOwner().getId() == user.getId());
                    break;
                }
                case Initiator : {
                    operationAllowed = (taskData.getCreatedBy() != null && taskData.getCreatedBy().getId() == user.getId());
                    break;
                }
                case PotentialOwner : {
                    operationAllowed = isAllowed( user,
                                                  people.getPotentialOwners() );
                    break;
                }
                case BusinessAdministrator : {
                    operationAllowed = isAllowed( user,
                                                  people.getBusinessAdministrators() );
                    break;
                }
            }
        }

        if ( operationAllowed && command.isUserIsExplicitPotentialOwner() ) {
            // if user has rights to execute the command, make sure user is explicitely specified (not as a group)
            operationAllowed = people.getPotentialOwners().contains( user );
        }
       
        if ( operationAllowed && command.isSkippable() ) {
          operationAllowed = taskData.isSkipable();
        }

        return operationAllowed;
    }
View Full Code Here

    private void commands(OperationCommand command,
                          Task task,
                          User user,
                          OrganizationalEntity targetEntity) {
        PeopleAssignments people = task.getPeopleAssignments();
        TaskData taskData = task.getTaskData();

        if ( command.getNewStatus() != null ) {
            taskData.setStatus( command.getNewStatus() );
        } else if ( command.isSetToPreviousStatus() ) {
            taskData.setStatus( taskData.getPreviousStatus() );
        }

        if ( command.isAddTargetEntityToPotentialOwners() && !people.getPotentialOwners().contains( targetEntity ) ) {
            people.getPotentialOwners().add( targetEntity );
        }

        if ( command.isRemoveUserFromPotentialOwners() ) {
            people.getPotentialOwners().remove( user );
        }

        if ( command.isSetNewOwnerToUser() ) {
            taskData.setActualOwner( (User) user );
        }

        if ( command.isSetNewOwnerToNull() ) {
            taskData.setActualOwner( null );
        }

        if ( command.getExec() != null ) {
            switch ( command.getExec() ) {
                case Claim : {
                    taskData.setActualOwner( (User) targetEntity );
                    // Task was reserved so owner should get icals
                    SendIcal.getInstance().sendIcalForTask( task,
                                                            service.getUserinfo() );

                    // trigger event support
View Full Code Here

                }
               
                case Complete : {
                  // set output data
                  if (data != null) {
                    TaskData taskData = task.getTaskData();
                    Content content = new Content();
                    content.setContent( data.getContent() );
                    em.persist( content );
                    taskData.setOutputContentId( content.getId() );
                    taskData.setOutputAccessType( data.getAccessType() );
                    taskData.setOutputType( data.getType() );
                  }

                  // trigger event support
                    service.getEventSupport().fireTaskCompleted( task.getId(),
                                                                 task.getTaskData().getActualOwner().getId() );
                    checkSubTaskStrategy(task);
                    break;
                }
               
                case Fail : {
                  // set fault data
                  if (data != null) {
                    TaskData taskData = task.getTaskData();
                    Content content = new Content();
                    content.setContent( data.getContent() );
                    em.persist( content );
                    taskData.setFaultContentId( content.getId() );
                    taskData.setFaultAccessType( data.getAccessType() );
                    taskData.setFaultType( data.getType() );
                    taskData.setFaultName( ((FaultData) data).getFaultName() );
                  }

                    // trigger event support
                    service.getEventSupport().fireTaskFailed( task.getId(),
                                                              task.getTaskData().getActualOwner().getId() );
View Full Code Here

TOP

Related Classes of org.drools.task.TaskData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.