Package com.mossle.form.keyvalue

Examples of com.mossle.form.keyvalue.KeyValue


    public String execute(CommandContext commandContext) {
        String taskId = getParameter(OPERATION_TASK_ID);
        String businessKey = getParameter(OPERATION_BUSINESS_KEY);
        String bpmProcessId = getParameter(OPERATION_BPM_PROCESS_ID);
        String userId = SpringSecurityUtils.getCurrentUserId();
        KeyValue keyValue = getKeyValue();

        if (this.notEmpty(taskId)) {
            // 如果是任务草稿,直接通过processInstanceId获得record,更新数据
            // TODO: 分支肯定有问题
            Task task = getProcessEngine().getTaskService().createTaskQuery()
                    .taskId(taskId).singleResult();

            if (task == null) {
                throw new IllegalStateException("任务不存在");
            }

            String processInstanceId = task.getProcessInstanceId();
            Record record = keyValue.findByRef(processInstanceId);

            if (record != null) {
                record = new RecordBuilder().build(record, STATUS_DRAFT_TASK,
                        getParameters());
                keyValue.save(record);
                businessKey = record.getCode();
            }
        } else if (this.notEmpty(businessKey)) {
            // 如果是流程草稿,直接通过businessKey获得record,更新数据
            Record record = keyValue.findByCode(businessKey);

            record = new RecordBuilder().build(record, STATUS_DRAFT_PROCESS,
                    getParameters());
            keyValue.save(record);
        } else {
            // 如果是第一次保存草稿,肯定是流程草稿,先初始化record,再保存数据
            Record record = new RecordBuilder().build(bpmProcessId,
                    STATUS_DRAFT_PROCESS, getParameters(), userId);
            keyValue.save(record);
            businessKey = record.getCode();
        }

        return businessKey;
    }
View Full Code Here


    }

    public Void execute(CommandContext commandContext) {
        ProcessEngine processEngine = getProcessEngine();
        FormTemplateManager formTemplateManager = getFormTemplateManager();
        KeyValue keyValue = getKeyValue();
        String taskId = getParameter(OPERATION_TASK_ID);

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

        // 处理抄送任务
        if ("copy".equals(task.getCategory())) {
            new DeleteTaskWithCommentCmd(taskId, "已阅").execute(commandContext);

            return null;
        }

        // 先保存草稿
        new SaveDraftOperation().execute(getParameters());

        // 先设置登录用户
        IdentityService identityService = processEngine.getIdentityService();
        identityService.setAuthenticatedUserId(SpringSecurityUtils
                .getCurrentUsername());

        if (task == null) {
            throw new IllegalStateException("任务不存在");
        }

        logger.info("{}", task.getDelegationState());

        // 处理委办任务
        if (DelegationState.PENDING == task.getDelegationState()) {
            taskService.resolveTask(taskId);

            return null;
        }

        // 处理子任务
        if ("subtask".equals(task.getCategory())) {
            new DeleteTaskWithCommentCmd(taskId, "完成").execute(commandContext);

            int count = getJdbcTemplate().queryForObject(
                    "select count(*) from ACT_RU_TASK where PARENT_TASK_ID_=?",
                    Integer.class, task.getParentTaskId());

            if (count > 1) {
                return null;
            }

            taskId = task.getParentTaskId();
        }

        FormService formService = processEngine.getFormService();
        String taskFormKey = formService.getTaskFormKey(
                task.getProcessDefinitionId(), task.getTaskDefinitionKey());
        FormInfo formInfo = new FormInfo();
        formInfo.setTaskId(taskId);
        formInfo.setFormKey(taskFormKey);

        // 尝试根据表单里字段的类型,进行转换
        Map<String, String> formTypeMap = new HashMap<String, String>();

        if (formInfo.isFormExists()) {
            FormTemplate formTemplate = formTemplateManager.findUniqueBy(
                    "code", formInfo.getFormKey());

            String content = formTemplate.getContent();
            formTypeMap = this.fetchFormTypeMap(content);
        }

        String processInstanceId = task.getProcessInstanceId();
        Record record = keyValue.findByRef(processInstanceId);
        Map<String, Object> processParameters = new HashMap<String, Object>();

        if (record == null) {
            new CompleteTaskWithCommentCmd(taskId, processParameters,
                    OPERATION_COMMENT).execute(commandContext);

            return null;
        }

        // 如果有表单,就从数据库获取数据
        for (Prop prop : record.getProps().values()) {
            String key = prop.getCode();
            String value = prop.getValue();
            String formType = this.getFormType(formTypeMap, key);

            if ("userpicker".equals(formType)) {
                processParameters.put(key,
                        new ArrayList(Arrays.asList(value.split(","))));
            } else if (formType != null) {
                processParameters.put(key, value);
            }
        }

        new CompleteTaskWithCommentCmd(taskId, processParameters,
                OPERATION_COMMENT).execute(commandContext);
        record = new RecordBuilder().build(record, STATUS_RUNNING,
                processInstanceId);
        keyValue.save(record);

        return null;
    }
View Full Code Here

    }

    public Void execute(CommandContext commandContext) {
        ProcessEngine processEngine = getProcessEngine();
        FormTemplateManager formTemplateManager = getFormTemplateManager();
        KeyValue keyValue = getKeyValue();
        String bpmProcessId = getParameter(OPERATION_BPM_PROCESS_ID);
        BpmProcess bpmProcess = getBpmProcessManager().get(
                Long.parseLong(bpmProcessId));
        String processDefinitionId = bpmProcess.getBpmConfBase()
                .getProcessDefinitionId();

        // 先保存草稿
        String businessKey = new ConfAssigneeOperation()
                .execute(getParameters());

        // 先设置登录用户
        IdentityService identityService = processEngine.getIdentityService();
        identityService.setAuthenticatedUserId(SpringSecurityUtils
                .getCurrentUserId());

        // 获得form的信息
        FormInfo formInfo = new FindStartFormCmd(processDefinitionId)
                .execute(commandContext);

        // 尝试根据表单里字段的类型,进行转换
        Map<String, String> formTypeMap = new HashMap<String, String>();

        if (formInfo.isFormExists()) {
            FormTemplate formTemplate = formTemplateManager.findUniqueBy(
                    "code", formInfo.getFormKey());

            String content = formTemplate.getContent();
            formTypeMap = this.fetchFormTypeMap(content);
        }

        Record record = keyValue.findByCode(businessKey);

        Map<String, Object> processParameters = new HashMap<String, Object>();

        // 如果有表单,就从数据库获取数据
        for (Prop prop : record.getProps().values()) {
            String key = prop.getCode();
            String value = prop.getValue();
            String formType = this.getFormType(formTypeMap, key);

            if ("userpicker".equals(formType)) {
                processParameters.put(key,
                        new ArrayList(Arrays.asList(value.split(","))));
            } else if (formType != null) {
                processParameters.put(key, value);
            }
        }

        ProcessInstance processInstance = processEngine.getRuntimeService()
                .startProcessInstanceById(processDefinitionId, businessKey,
                        processParameters);
        record = new RecordBuilder().build(record, STATUS_RUNNING,
                processInstance.getId());
        keyValue.save(record);

        return null;
    }
View Full Code Here

TOP

Related Classes of com.mossle.form.keyvalue.KeyValue

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.