Дерево страниц
Skip to end of metadata
Go to start of metadata

Вы просматриваете старую версию данной страницы. Смотрите текущую версию.

Сравнить с текущим просмотр истории страницы

« Предыдущий Версия 3 Следующий »

Постановка задачи

Запустить процесс
Инструмент: Палитра XML
Статус

ГОТОВО

РазделWorkFlow
Комментарий

Реализация

<Сопроводительная информация>

Необходимо сначало выполнить Старт процесса

Создать handler (JS-Обработчик операций)

Обработчик операций
<?xml version='1.0' encoding='UTF-8'?>
<ui xmlns="http://www.intertrust.ru/schema/palette/tn-ui">
    <handler name="WF-кнопка" id="WFCustomHandlerName">
        <meta>
            <documentation></documentation>
        </meta>
        <script lang="JavaScript"><![CDATA[код кнопки]]></script>
	</handler>
</ui>
Шаблон кода кнопки
importClass(Packages.ru.intertrust.cmj.af.core.AFSession);
importClass(Packages.ru.intertrust.cmj.af.exceptions.AFDaoBadParameterException);
importClass(Packages.ru.intertrust.cmj.rest.tunable.object.TunableObjectREST);
importClass(Packages.ru.intertrust.cmj.rest.tunable.object.TunableObjectREST.Resource);
importClass(Packages.ru.intertrust.cmj.rest.tunable.object.action.TunableOperation);
importClass(Packages.ru.intertrust.cmj.tunable.object.AnyTunableObject);
importClass(Packages.ru.intertrust.cmj.tunable.object.TunableObjectApplication);
importClass(Packages.ru.intertrust.cmj.tunable.object.TunableObjectApplication.ClientContextKey);
importClass(Packages.ru.intertrust.cmj.tunable.object.common.TunableObjectHelper);
importClass(Packages.ru.intertrust.cmj.rest.tunable.object.action.OperationJScriptREST);
importClass(Packages.ru.intertrust.cmj.rest.tunable.object.action.OperationJScriptREST.ReturnParamsResource);
importClass(Packages.ru.intertrust.cmj.dp.DPApplication);
importClass(Packages.ru.intertrust.cmj.rest.rkk.RkkResource);
importClass(Packages.ru.intertrust.cmj.af.utils.BeansUtils);
importClass(Packages.ru.intertrust.cmj.wf.impl.WorkflowProcessServiceImpl);
importClass(Packages.ru.intertrust.cmj.wf.api.ProcessUserTask);
importClass(Packages.ru.intertrust.cmj.wf.api.TaskVariables);
importClass(Packages.ru.intertrust.cmj.af.misc.AFDateTime);
importPackage(Packages.ru.intertrust.cmj.af.utils);
importPackage(Packages.ru.intertrust.cmj.af.tuning.impl);
importPackage(Packages.ru.intertrust.cmj.af.tuning);
importPackage(Packages.ru.intertrust.cmj.rest.tuning);
importPackage(Packages.java.util);
importPackage(Packages.java.lang);
importClass(Packages.org.apache.commons.lang3.exception.ExceptionUtils);

function process(paramsResource, returnResource) {

    if (paramsResource == null) {
        throw new IllegalArgumentException("paramsResource must no be null.");
    }

	var dialogNameList = new ArrayList();
	dialogNameList.add("ClientContextRequest");
	dialogNameList.add("ExampleDialogStandart");
	dialogNameList.add("SystemDialogInfo");

	paramPackageId = "";
	paramSchemaName = paramsResource.tuning().getSchema().getName();
	if (dialogNameList.contains(paramSchemaName)) {
		paramPackageId = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("counter"));
	} else {
		paramPackageId = "contextWithResource";
	}

	if (paramPackageId.equals("context")) {
		createContextResourceRequest(returnResource);
	} else if (paramPackageId.equals("contextWithResource")) {
		process_context(paramsResource, returnResource);
	} else if (paramPackageId.equals("answer")) {
		process_dialog(paramsResource, returnResource);
	} else if (paramPackageId.equals("exit")) {
		process_refresh(paramsResource, returnResource);
	}
}

/**
 * Обработка первого пакета данных с клиента.
 * @return возвращение контекста открытого документа
 */
function createContextResourceRequest(returnResource) {
  var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
  var afObjectContextRequest = appTNObject.createClientContextRequest(TunableObjectApplication.ClientContextKey.resourceid, TunableObjectApplication.ClientContextKey.resource);

  TunableObjectHelper.putAFInstanceValue(afObjectContextRequest, "counter", "contextWithResource");
  returnResource.setResource(TunableObjectREST.Resource.create(afObjectContextRequest));
}

/**
 * Обработка первого пакета данных с клиента.
 * @param paramsResource
 * @return ресурс первого диалога сценария
 */
function process_refresh(paramsResource, returnResource) {
    var ids = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("selectIds"));

	var appdp = AFSession.get().getApplication(DPApplication.class);
	var obj = appdp.getEntityByUNID(ids.get(0));

	var res = RkkResource.valueOf(obj);
	returnResource.setResource(res);
}

/**
 * Диалог Информации
 * @ids текущий идентификатор документа
 * @resultMessage сообщение
 * @return ресурс
 */
function process_dlginfo(ids, resultMessage,returnResource){
    var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
    var message = appTNObject.composeDialog("SystemDialogInfo", null, null, null);
    TunableObjectHelper.putAFInstanceValue(message.tuning(), "message", resultMessage);
    TunableObjectHelper.putAFInstanceValue(message, "counter", "exit");
    returnResource.resource = TunableObjectREST.Resource.create(message);
    return returnResource.resource;
}

/**
 * Обработка первого пакета данных с клиента.
 * @param paramsResource
 * @return ресурс первого диалога сценария
 */
function process_context(paramsResource, returnResource) {
	var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
	var id = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("$id"));
	var ids = Utils.newArrayList();
	ids.add(id);

	var appdp = AFSession.get().getApplication(DPApplication.class);
	var obj = appdp.getEntityByUNID(id);

	//Проверка на актуальность документа
    var version = paramsResource.getVersion();
	var versionParts = version.split('$$');
	var versionContext = versionParts[0];

	var versionCurrent = obj.getVersionStamp().toString();

    if (versionContext != versionCurrent){
        process_dlginfo(ids,"Данная версия объекта/документа была изменена. Требуется обновить!",returnResource);
        return returnResource.resource;
    }

	var message = appTNObject.composeDialog("ExampleDialogStandart", null, null, null);
	TunableObjectHelper.putAFInstanceValue(message.tuning(), "message", "Комментарий:");
	TunableObjectHelper.putAFInstanceValue(message.tuning(), "selectIds", ids);
	TunableObjectHelper.putAFInstanceValue(message.tuning(), "versionContext", versionContext);
	TunableObjectHelper.putAFInstanceValue(message, "counter", "answer");

	returnResource.setResource(TunableObjectREST.Resource.create(message));
}

/**
 * Обработка данных первого диалога сценария
 * @param paramsResource
 * @return ресурс
 */
function process_dialog(paramsResource, returnResource) {
    var ids = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("selectIds"));
	var comment = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("comment"));
	var versionContext = TunableObjectHelper.getAFInstanceValue(paramsResource.tuning().getValues().get("versionContext"));

	var appdp = AFSession.get().getApplication(DPApplication.class);
	var obj = appdp.getEntityByUNID(ids.get(0));
    var versionCurrent = obj.getVersionStamp().toString();

	if (versionContext != versionCurrent){
        process_dlginfo(ids,"Данная версия объекта/документа была изменена. Требуется обновить!",returnResource);
        return returnResource.resource;
	}

	if (obj.tuning().getValues().containsKey("wf") && obj.tuning().getValues().get("wf") != null) {

		var wf = obj.tuning().getValues().get("wf");
		var task_name = wf.getValues().get("task").getValue();

		var wf_status = "-";
		if (wf.getValues().containsKey("status")  && wf.getValues().get("status") != null ) {
			wf_status = wf.getValues().get("status").getValue();
		}

		var wf_starttime = new AFDateTime(Calendar.getInstance());
		if (wf.getValues().containsKey("actiontime")  && wf.getValues().get("actiontime") != null ) {
		  wf_starttime = wf.getValues().get("actiontime").getValue();
		} else if (wf.getValues().containsKey("starttime")  && wf.getValues().get("starttime") != null ){
		  wf_starttime = wf.getValues().get("starttime").getValue();
		}

		// Получаем задачу
		var taskId = wf.getValues().get("task_id").getValue();
		var workflowProcessService = BeansUtils.getBean("workflowProcessServiceImpl");
		var task = workflowProcessService.getTaskById(taskId);

		// Должна быть только одна задача, завершаем ее, установив переменную
		if (task != null){

		    //Запускаем WF
			task.getTaskVariables().put(task_name + "Result", true);
			var ProcessActionResult = workflowProcessService.completeUserTask(task);
			if (ProcessActionResult.hasError()) {
				rollbackWF(appdp, ids.get(0), obj);
				var exception = ProcessActionResult.getException();
				var stacktrace = ExceptionUtils.getStackTrace(exception);
				throw new RuntimeException("Не удалось продолжить процесс. Обратитесь к администратору. Ошибка: " + stacktrace);
			}

			obj = appdp.getEntityByUNID(ids.get(0));

			//запись в Жизненный цикл
			var currentUser = AFSession.get().currentUser().getBeard();
			var executors = wf.getValues().get("assignee").getValues();
			var executor = executors.get(0).getValue();
			var startDate = wf_starttime;
			var endDate = new AFDateTime(Calendar.getInstance());
			var result = "Исполнено";
			var information = comment;

			setLifeCycle(obj, startDate, endDate, wf_status, executor, currentUser, result, information);

            var time = new AFDateTime(Calendar.getInstance());
	        TunableObjectHelper.putAFInstanceValue(obj.tuning(), "wf.actiontime",time);

			try {
	             obj.save();
	        } catch (e) {
		        var resultMessage = "При сохранении произошел конфликт, сохранение изменений невозможно.\nБудет переоткрыт в актуальном состоянии."
		        process_dlginfo(ids,resultMessage,returnResource);
	            return returnResource.resource;
	        }

			obj = appdp.getEntityByUNID(ids.get(0));
			var res = RkkResource.valueOf(obj);
			returnResource.setResource(res);
		} else {
			throw new RuntimeException("Не найдена задача. Обратитесь к администратору. Идентификатор: " + taskId);
		}
	} else {
		throw new RuntimeException("Не запущен процесс согласования. Обратитесь к администратору. Идентификатор: " + ids.get(0));
	}
}

/**
 * Откатить статусное состояние WF
 * @obj объект
 * id идентификатор объекта
 * @appdp приложение
 */
function rollbackWF(appdp, id, obj){
	var document = appdp.getEntityByUNID(id);

	var wf = obj.tuning().getValues().get("wf");

	var assignee = null;
	var task = "";
	var status = wf.getValues().get("status").getValue();
	var stage = "";
	var duration = null;
	var starttime = null;
	var finishtime = null;

	if (wf.getValues().get("assignee") != null) {
		assignee = wf.getValues().get("assignee").getValues();
		task = wf.getValues().get("task").getValue();
		stage = wf.getValues().get("stage").getValue();
		duration = wf.getValues().get("duration").getValue();
		starttime = wf.getValues().get("starttime").getValue();
		if (wf.getValues().get("finishtime") != null) {
			finishtime = wf.getValues().get("finishtime").getValue();
		}
	}

	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.assignee", assignee);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.task", task);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.status", status);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.stage", stage);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.duration", duration);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.starttime", starttime);
	TunableObjectHelper.putAFInstanceValue(document.tuning(), "wf.finishtime", finishtime);

	document.save();
}

/**
 * Запись в Жизненный цикл
 * @obj объект
 * @startDate дата начала действия
 * @endDate дата окончания действия
 * @action действие
 * @assignee исполнитель
 * @currentUser пользователь, выполнивший действие
 * @result Результат
 * @information Доп. информация
 */
function setLifeCycle(obj, startDate, endDate, action, assignee, currentUser, result, information) {

	var propertyLifecycle = obj.tuning().getSchema().getProperty("wfLifeCycle");
	var lifecycle = null;

	if (obj.tuning().getValues().containsKey("wfLifeCycle") && obj.tuning().getValues().get("wfLifeCycle") != null) {
		lifecycle = obj.tuning().getValues().get("wfLifeCycle").getValues();
	} else {
		lifecycle = Utils.newArrayList();
	}

	var propertyStartDate = propertyLifecycle.getSchema().getProperty("lifecycle_start_date");
	var propertyDate = propertyLifecycle.getSchema().getProperty("lifecycle_date");
	var propertyAction = propertyLifecycle.getSchema().getProperty("lifecycle_action");
	var propertyAssignee = propertyLifecycle.getSchema().getProperty("lifecycle_assignee");
	var propertyCurrentUser = propertyLifecycle.getSchema().getProperty("lifecycle_current_user");
	var propertyResult = propertyLifecycle.getSchema().getProperty("lifecycle_result");
	var propertyInformation = propertyLifecycle.getSchema().getProperty("lifecycle_information");

	var startDateValue = TuningHelper.createPropertyValue(startDate, propertyStartDate);
	var endDateValue = TuningHelper.createPropertyValue(endDate, propertyDate);
	var actionValue = TuningHelper.createPropertyValue(action, propertyAction);
	var currentUserValue = TuningHelper.createPropertyValue(currentUser, propertyCurrentUser);
	var assigneeValue = TuningHelper.createPropertyValue(assignee, propertyAssignee);
	var resultValue = TuningHelper.createPropertyValue(result, propertyResult);
	var informationValue = TuningHelper.createPropertyValue(information, propertyInformation);

	var wf_lifecycle = new AFInstanceObjectImpl(propertyLifecycle.getSchema());
	wf_lifecycle.getValues().put("lifecycle_start_date", startDateValue);
	wf_lifecycle.getValues().put("lifecycle_date", endDateValue);
	wf_lifecycle.getValues().put("lifecycle_action", actionValue);
	wf_lifecycle.getValues().put("lifecycle_assignee", assigneeValue);
	wf_lifecycle.getValues().put("lifecycle_current_user", currentUserValue);
	wf_lifecycle.getValues().put("lifecycle_result", resultValue);
	wf_lifecycle.getValues().put("lifecycle_information", informationValue);

	lifecycle.add(wf_lifecycle);

	var lifecycleValue = new AFInstanceArrayImpl(propertyLifecycle.getSchema(), lifecycle);
	obj.tuning().getValues().put("wfLifeCycle", lifecycleValue);
}


Добавить кастомную кнопку и подключить кастомную операцию

  1. В форме создать секцию RootMenu
  2. В RootMenu создать button и подключить к нему handler


<section id="RootMenu">
    <component>
        <button name="${<Form Name>.RootMenu.button.<Name>:Новая кнопка}">
            <icon code="37"/>
            <action>
                <custom>
                    <operation>
                        <handler-ref ref="WFCustomHandlerName"/>
                    </operation>
                </custom>
            </action>
        </button>
    </component>
</section>



  • Нет меток