Package org.joget.apps.form.service

Examples of org.joget.apps.form.service.FormService


    /**
     * Handles data form submission.
     */
    protected Form submitDataForm(FormData formData, Form form) {
        ApplicationContext ac = AppUtil.getApplicationContext();
        FormService formService = (FormService) ac.getBean("formService");
        formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());
        formData = formService.executeFormActions(form, formData);

        setProperty("submitted", Boolean.TRUE);
        setProperty("redirectUrlAfterComplete", getPropertyString("redirectUrlAfterComplete"));

        return form;
View Full Code Here


        return "Save As Draft Button";
    }

    @Override
    public FormData actionPerformed(Form form, FormData formData) {
        FormService formService = (FormService) FormUtil.getApplicationContext().getBean("formService");
        FormData updatedFormData = formService.submitForm(form, formData, true);
        return updatedFormData;
    }
View Full Code Here

     * @throws BeansException
     */
    protected Form loadSubForm(FormData parentFormData) throws BeansException {
        FormData formData = new FormData();
        Form subForm = null;
        FormService formService = (FormService) FormUtil.getApplicationContext().getBean("formService");

        String json = getPropertyString("json");
        String formDefId = getPropertyString("formDefId");
        if (formDefId != null && !formDefId.isEmpty()) {
            // load subform
            AppDefinition appDef = AppUtil.getCurrentAppDefinition();
            FormDefinitionDao formDefinitionDao = (FormDefinitionDao) FormUtil.getApplicationContext().getBean("formDefinitionDao");
            FormDefinition formDef = formDefinitionDao.loadById(formDefId, appDef);
            if (formDef != null) {
                json = formDef.getJson();
            }
        }
        if (json != null && json.trim().length() > 0) {
            if (parentFormData != null && parentFormData.getProcessId() != null && !parentFormData.getProcessId().isEmpty()) {
                formData.setProcessId(parentFormData.getProcessId());
                WorkflowManager wm = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
                WorkflowAssignment wfAssignment = wm.getAssignmentByProcess(parentFormData.getProcessId());
                json = AppUtil.processHashVariable(json, wfAssignment, StringUtil.TYPE_JSON, null);
            }
           
            // use the json definition to create the subform
            try {
                subForm = (Form) formService.createElementFromJson(json);
               
                //if id field not exist, automatically add an id hidden field
                Element idElement = FormUtil.findElement(FormUtil.PROPERTY_ID, subForm, formData);
                if (idElement == null) {
                    Collection<Element> subFormElements = subForm.getChildren();
View Full Code Here

    }

    private void viewProcess() {
        ApplicationContext ac = AppUtil.getApplicationContext();
        AppService appService = (AppService) ac.getBean("appService");
        FormService formService = (FormService) ac.getBean("formService");

        WorkflowProcess process = appService.getWorkflowProcessForApp(getRequestParameterString("appId"), getRequestParameterString("appVersion"), getPropertyString("processDefId"));
        setProperty("process", process);

        if (isUnauthorized(process.getId())) {
            // check for start mapped form
            String formUrl = getUrl() + "?_action=start";
            FormData formData = new FormData();
            formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());

            String primaryKey = getRequestParameterString("recordId");
            if (primaryKey != null && primaryKey.trim().length() > 0) {
                formData.setPrimaryKeyValue(primaryKey);
            }

            if (getPropertyString("keyName") != null && getPropertyString("keyName").trim().length() > 0 && getKey() != null) {
                formData.addRequestParameterValues(getPropertyString("keyName"), new String[]{getKey()});
            }

            PackageActivityForm startFormDef = appService.viewStartProcessForm(getRequestParameterString("appId"), getRequestParameterString("appVersion"), getPropertyString("processDefId"), formData, formUrl);
            if (startFormDef != null && (startFormDef.getForm() != null || PackageActivityForm.ACTIVITY_FORM_TYPE_EXTERNAL.equals(startFormDef.getType()))) {
                Form startForm = startFormDef.getForm();

                // generate form HTML
                String formHtml = formService.retrieveFormHtml(startForm, formData);
                AppDefinition appDef = appService.getAppDefinition(getRequestParameterString("appId"), getRequestParameterString("appVersion"));

                // show form
                setProperty("headerTitle", process.getName());
                setProperty("view", "formView");
View Full Code Here

    }

    private void startProcess() {
        ApplicationContext ac = AppUtil.getApplicationContext();
        AppService appService = (AppService) ac.getBean("appService");
        FormService formService = (FormService) ac.getBean("formService");

        WorkflowProcess process = appService.getWorkflowProcessForApp(getRequestParameterString("appId"), getRequestParameterString("appVersion"), getPropertyString("processDefId"));
        setProperty("process", process);

        if (isUnauthorized(process.getId())) {
            // extract form values from request
            FormData formData = new FormData();

            String recordId = getRequestParameterString("recordId");
            if (recordId != null && recordId.trim().length() == 0) {
                recordId = null;
            }

            formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());

            if (getPropertyString("keyName") != null && getPropertyString("keyName").trim().length() > 0 && getKey() != null) {
                formData.addRequestParameterValues(getPropertyString("keyName"), new String[]{getKey()});
            }

            // get workflow variables
            Map<String, String> variableMap = AppUtil.retrieveVariableDataFromMap(getRequestParameters());
            String formUrl = getUrl() + "?_action=start";
            WorkflowProcessResult result = appService.submitFormToStartProcess(getRequestParameterString("appId"), getRequestParameterString("appVersion"), getPropertyString("processDefId"), formData, variableMap, recordId, formUrl);
            PackageActivityForm startFormDef = appService.viewStartProcessForm(getRequestParameterString("appId"), getRequestParameterString("appVersion"), getPropertyString("processDefId"), formData, formUrl);
            if (startFormDef != null && (startFormDef.getForm() != null || PackageActivityForm.ACTIVITY_FORM_TYPE_EXTERNAL.equals(startFormDef.getType()))) {
                if (result == null) {
                    // validation error, get form
                    Form startForm = startFormDef.getForm();

                    // generate form HTML
                    String formHtml = formService.retrieveFormErrorHtml(startForm, formData);
                    AppDefinition appDef = appService.getAppDefinition(getRequestParameterString("appId"), getRequestParameterString("appVersion"));

                    // show form
                    setProperty("headerTitle", process.getName());
                    setProperty("view", "formView");
View Full Code Here

    private void assignmentView() {
        String activityId = getRequestParameterString("activityId");
        ApplicationContext ac = AppUtil.getApplicationContext();
        AppService appService = (AppService) ac.getBean("appService");
        FormService formService = (FormService) ac.getBean("formService");
        WorkflowManager workflowManager = (WorkflowManager) ac.getBean("workflowManager");

        if (isAssignmentExist(activityId)) {
            try {
                WorkflowAssignment assignment = workflowManager.getAssignment(activityId);
                // set process instance ID as primary key
                FormData formData = new FormData();

                formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());

                if (getPropertyString("keyName") != null && getPropertyString("keyName").trim().length() > 0 && getKey() != null) {
                    formData.addRequestParameterValues(getPropertyString("keyName"), new String[]{getKey()});
                }

                // get form
                String formUrl = getUrl() + "?_action=assignmentSubmit&activityId=" + activityId;
                PackageActivityForm activityForm = appService.viewAssignmentForm(getRequestParameterString("appId"), getRequestParameterString("appVersion"), activityId, formData, formUrl);
                Form form = activityForm.getForm();
                AppDefinition appDef = appService.getAppDefinition(getRequestParameterString("appId"), getRequestParameterString("appVersion"));

                // generate form HTML
                String formHtml = formService.retrieveFormHtml(form, formData);

                // show form
                setProperty("headerTitle", assignment.getProcessName() + " - " + assignment.getActivityName());
                setProperty("view", "formView");
                setProperty("formHtml", formHtml);
View Full Code Here

    }

    private void assignmentSubmit() {
        ApplicationContext ac = AppUtil.getApplicationContext();
        AppService appService = (AppService) ac.getBean("appService");
        FormService formService = (FormService) ac.getBean("formService");
        WorkflowManager workflowManager = (WorkflowManager) ac.getBean("workflowManager");
        String activityId = getRequestParameterString("activityId");
        if (isAssignmentExist(activityId)) {
            try {
                WorkflowAssignment assignment = workflowManager.getAssignment(activityId);
                // set process instance ID as primary key
                FormData formData = new FormData();
                formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());
                String processId = assignment.getProcessId();

                // get form
                String formUrl = getUrl() + "?_action=assignmentSubmit&activityId=" + activityId;
                PackageActivityForm activityForm = appService.viewAssignmentForm(getRequestParameterString("appId"), getRequestParameterString("appVersion"), activityId, formData, formUrl);
                Form form = activityForm.getForm();

                // submit form
                FormData formResult = formService.executeFormActions(form, formData);

                // check for validation errors
                if (formResult.getFormResult(AssignmentWithdrawButton.DEFAULT_ID) != null) {
                    // withdraw assignment
                    workflowManager.assignmentWithdraw(activityId);
                } else if (formResult.getFormResult(AssignmentCompleteButton.DEFAULT_ID) != null) {
                    // complete assignment
                    Map<String, String> variableMap = AppUtil.retrieveVariableDataFromMap(getRequestParameters());
                    formResult = appService.completeAssignmentForm(form, assignment, formData, variableMap);

                    Map<String, String> errors = formResult.getFormErrors();
                    if (!formResult.getStay() && errors.isEmpty() && activityForm.isAutoContinue()) {
                        setAlertMessage(getPropertyString("messageShowAfterComplete"));
                        // redirect to next activity if available
                        WorkflowAssignment nextActivity = workflowManager.getAssignmentByProcess(processId);
                        if (nextActivity != null) {
                            setProperty("view", "redirect");
                            setProperty("messageShowAfterComplete", "");
                            String redirectUrl = getUrl() + "?_action=assignmentView&activityId=" + nextActivity.getActivityId();
                            setAlertMessage("");
                            setRedirectUrl(redirectUrl);
                            return;
                        }
                    }
                }

                String html = null;

                // check for validation errors
                Map<String, String> errors = formResult.getFormErrors();
                int errorCount = 0;
                if (!formResult.getStay() && errors == null || errors.isEmpty()) {
                    // render normal template
                    html = formService.generateElementHtml(form, formResult);
                } else {
                    // render error template
                    html = formService.generateElementErrorHtml(form, formResult);
                    errorCount = errors.size();
                }

                // show form
                setProperty("headerTitle", assignment.getProcessName() + " - " + assignment.getActivityName());
View Full Code Here

        return "Submit Button";
    }

    @Override
    public FormData actionPerformed(Form form, FormData formData) {
        FormService formService = (FormService) FormUtil.getApplicationContext().getBean("formService");
        FormData updatedFormData = formService.submitForm(form, formData, false);
        return updatedFormData;
    }
View Full Code Here

TOP

Related Classes of org.joget.apps.form.service.FormService

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.