You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/03 08:17:49 UTC

[GitHub] [inlong] healchow opened a new pull request, #5343: [INLONG-4750][Manager] Merge the workflow util classes into one class

healchow opened a new pull request, #5343:
URL: https://github.com/apache/inlong/pull/5343

   ### Prepare a Pull Request
   
   - Fixes #4750
   
   ### Motivation
   
   Merge the workflow util classes into one class.
   
   ### Modifications
   
   1. Move the task and listener log classes from the service module to the pojo module.
   2. Merge the workflow util classes into one class.
   
   ### Verifying this change
   
   - [x] This change is a trivial rework/code cleanup without any test coverage.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] healchow merged pull request #5343: [INLONG-4750][Manager] Merge the workflow util classes into one class

Posted by GitBox <gi...@apache.org>.
healchow merged PR #5343:
URL: https://github.com/apache/inlong/pull/5343


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] healchow commented on a diff in pull request #5343: [INLONG-4750][Manager] Merge the workflow util classes into one class

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #5343:
URL: https://github.com/apache/inlong/pull/5343#discussion_r937285629


##########
inlong-manager/manager-workflow/src/main/java/org/apache/inlong/manager/workflow/util/WorkflowUtils.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.workflow.util;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.common.enums.ProcessStatus;
+import org.apache.inlong.manager.common.enums.TaskStatus;
+import org.apache.inlong.manager.common.exceptions.FormParseException;
+import org.apache.inlong.manager.common.exceptions.JsonException;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowProcessEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowTaskEntity;
+import org.apache.inlong.manager.pojo.workflow.ListenerExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.ProcessResponse;
+import org.apache.inlong.manager.pojo.workflow.TaskExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.TaskResponse;
+import org.apache.inlong.manager.pojo.workflow.WorkflowResult;
+import org.apache.inlong.manager.pojo.workflow.form.process.ProcessForm;
+import org.apache.inlong.manager.pojo.workflow.form.task.TaskForm;
+import org.apache.inlong.manager.workflow.WorkflowContext;
+import org.apache.inlong.manager.workflow.WorkflowContext.ActionContext;
+import org.apache.inlong.manager.workflow.definition.UserTask;
+import org.apache.inlong.manager.workflow.definition.WorkflowProcess;
+import org.apache.inlong.manager.workflow.definition.WorkflowTask;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+
+/**
+ * Workflow utils
+ */
+public class WorkflowUtils {
+
+    public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+    private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowUtils.class);
+
+    /**
+     * Build workflow context from WorkflowProcess and WorkflowProcessEntity
+     */
+    public static WorkflowContext buildContext(ObjectMapper objectMapper, WorkflowProcess process,
+            WorkflowProcessEntity processEntity) {
+        try {
+            ProcessForm form = WorkflowUtils.parseProcessForm(objectMapper, processEntity.getFormData(), process);
+            return new WorkflowContext().setProcess(process)
+                    .setOperator(processEntity.getApplicant())
+                    .setProcessForm(form)
+                    .setProcessEntity(processEntity);
+        } catch (Exception e) {
+            LOGGER.error("build context from process form failed with id=" + processEntity.getId(), e);
+            return null;
+        }
+    }
+
+    /**
+     * Get the workflow result from the given workflow context
+     */
+    public static WorkflowResult getResult(WorkflowContext context) {
+        if (context == null) {
+            return null;
+        }
+
+        WorkflowResult workflowResult = new WorkflowResult();
+        workflowResult.setProcessInfo(WorkflowUtils.getProcessResponse(context.getProcessEntity()));
+        if (context.getActionContext() != null) {
+            ActionContext newAction = context.getActionContext();
+            workflowResult.setNewTasks(Lists.newArrayList(WorkflowUtils.getTaskResponse(newAction.getTaskEntity())));
+        }
+        return workflowResult;
+    }
+
+    /**
+     * Get process response from process entity
+     */
+    public static ProcessResponse getProcessResponse(WorkflowProcessEntity entity) {
+        if (entity == null) {
+            return null;
+        }
+
+        ProcessResponse processResponse = ProcessResponse.builder()
+                .id(entity.getId())
+                .name(entity.getName())
+                .displayName(entity.getDisplayName())
+                .type(entity.getType())
+                .title(entity.getTitle())
+                .applicant(entity.getApplicant())
+                .status(ProcessStatus.valueOf(entity.getStatus()))
+                .startTime(entity.getStartTime())
+                .endTime(entity.getEndTime())
+                .build();
+        try {
+            if (StringUtils.isNotBlank(entity.getFormData())) {
+                processResponse.setFormData(OBJECT_MAPPER.readTree(entity.getFormData()));
+            }
+            if (StringUtils.isNotBlank(entity.getExtParams())) {
+                processResponse.setExtParams(OBJECT_MAPPER.readTree(entity.getExtParams()));
+            }
+        } catch (Exception e) {
+            LOGGER.error("parse process form error: ", e);

Review Comment:
   The exception stack trace will print all info, such as:
   
   <img width="1241" alt="image" src="https://user-images.githubusercontent.com/31994335/182747891-8010fd0d-71db-4360-a10d-b98f834c680a.png">
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] leosanqing commented on a diff in pull request #5343: [INLONG-4750][Manager] Merge the workflow util classes into one class

Posted by GitBox <gi...@apache.org>.
leosanqing commented on code in PR #5343:
URL: https://github.com/apache/inlong/pull/5343#discussion_r936826380


##########
inlong-manager/manager-workflow/src/main/java/org/apache/inlong/manager/workflow/util/WorkflowUtils.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.workflow.util;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.common.enums.ProcessStatus;
+import org.apache.inlong.manager.common.enums.TaskStatus;
+import org.apache.inlong.manager.common.exceptions.FormParseException;
+import org.apache.inlong.manager.common.exceptions.JsonException;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowProcessEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowTaskEntity;
+import org.apache.inlong.manager.pojo.workflow.ListenerExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.ProcessResponse;
+import org.apache.inlong.manager.pojo.workflow.TaskExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.TaskResponse;
+import org.apache.inlong.manager.pojo.workflow.WorkflowResult;
+import org.apache.inlong.manager.pojo.workflow.form.process.ProcessForm;
+import org.apache.inlong.manager.pojo.workflow.form.task.TaskForm;
+import org.apache.inlong.manager.workflow.WorkflowContext;
+import org.apache.inlong.manager.workflow.WorkflowContext.ActionContext;
+import org.apache.inlong.manager.workflow.definition.UserTask;
+import org.apache.inlong.manager.workflow.definition.WorkflowProcess;
+import org.apache.inlong.manager.workflow.definition.WorkflowTask;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+
+/**
+ * Workflow utils
+ */
+public class WorkflowUtils {
+
+    public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+    private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowUtils.class);
+
+    /**
+     * Build workflow context from WorkflowProcess and WorkflowProcessEntity
+     */
+    public static WorkflowContext buildContext(ObjectMapper objectMapper, WorkflowProcess process,
+            WorkflowProcessEntity processEntity) {
+        try {
+            ProcessForm form = WorkflowUtils.parseProcessForm(objectMapper, processEntity.getFormData(), process);
+            return new WorkflowContext().setProcess(process)
+                    .setOperator(processEntity.getApplicant())
+                    .setProcessForm(form)
+                    .setProcessEntity(processEntity);
+        } catch (Exception e) {
+            LOGGER.error("build context from process form failed with id=" + processEntity.getId(), e);
+            return null;
+        }
+    }
+
+    /**
+     * Get the workflow result from the given workflow context
+     */
+    public static WorkflowResult getResult(WorkflowContext context) {
+        if (context == null) {
+            return null;
+        }
+
+        WorkflowResult workflowResult = new WorkflowResult();
+        workflowResult.setProcessInfo(WorkflowUtils.getProcessResponse(context.getProcessEntity()));
+        if (context.getActionContext() != null) {
+            ActionContext newAction = context.getActionContext();
+            workflowResult.setNewTasks(Lists.newArrayList(WorkflowUtils.getTaskResponse(newAction.getTaskEntity())));
+        }
+        return workflowResult;
+    }
+
+    /**
+     * Get process response from process entity
+     */
+    public static ProcessResponse getProcessResponse(WorkflowProcessEntity entity) {
+        if (entity == null) {
+            return null;
+        }
+
+        ProcessResponse processResponse = ProcessResponse.builder()
+                .id(entity.getId())
+                .name(entity.getName())
+                .displayName(entity.getDisplayName())
+                .type(entity.getType())
+                .title(entity.getTitle())
+                .applicant(entity.getApplicant())
+                .status(ProcessStatus.valueOf(entity.getStatus()))
+                .startTime(entity.getStartTime())
+                .endTime(entity.getEndTime())
+                .build();
+        try {
+            if (StringUtils.isNotBlank(entity.getFormData())) {
+                processResponse.setFormData(OBJECT_MAPPER.readTree(entity.getFormData()));
+            }
+            if (StringUtils.isNotBlank(entity.getExtParams())) {
+                processResponse.setExtParams(OBJECT_MAPPER.readTree(entity.getExtParams()));
+            }
+        } catch (Exception e) {
+            LOGGER.error("parse process form error: ", e);
+            throw new JsonException("parse process form or ext params error, please contact administrator");
+        }
+
+        return processResponse;
+    }
+
+    /**
+     * Get task response from task entity
+     */
+    public static TaskResponse getTaskResponse(WorkflowTaskEntity taskEntity) {
+        if (taskEntity == null) {
+            return null;
+        }
+
+        TaskResponse taskResponse = TaskResponse.builder()
+                .id(taskEntity.getId())
+                .type(taskEntity.getType())
+                .processId(taskEntity.getProcessId())
+                .processName(taskEntity.getProcessName())
+                .processDisplayName(taskEntity.getProcessDisplayName())
+                .name(taskEntity.getName())
+                .displayName(taskEntity.getDisplayName())
+                .applicant(taskEntity.getApplicant())
+                .approvers(Arrays.asList(taskEntity.getApprovers().split(WorkflowTaskEntity.APPROVERS_DELIMITER)))
+                .operator(taskEntity.getOperator())
+                .status(TaskStatus.valueOf(taskEntity.getStatus()))
+                .remark(taskEntity.getRemark())
+                .startTime(taskEntity.getStartTime())
+                .endTime(taskEntity.getEndTime())
+                .build();
+
+        try {
+            JsonNode formData = null;
+            if (StringUtils.isNotBlank(taskEntity.getFormData())) {
+                formData = OBJECT_MAPPER.readTree(taskEntity.getFormData());
+            }
+            taskResponse.setFormData(formData);
+        } catch (Exception e) {
+            LOGGER.error("parse task form error: ", e);

Review Comment:
   Same as above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] leosanqing commented on a diff in pull request #5343: [INLONG-4750][Manager] Merge the workflow util classes into one class

Posted by GitBox <gi...@apache.org>.
leosanqing commented on code in PR #5343:
URL: https://github.com/apache/inlong/pull/5343#discussion_r936825887


##########
inlong-manager/manager-workflow/src/main/java/org/apache/inlong/manager/workflow/util/WorkflowUtils.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.workflow.util;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.common.enums.ProcessStatus;
+import org.apache.inlong.manager.common.enums.TaskStatus;
+import org.apache.inlong.manager.common.exceptions.FormParseException;
+import org.apache.inlong.manager.common.exceptions.JsonException;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowProcessEntity;
+import org.apache.inlong.manager.dao.entity.WorkflowTaskEntity;
+import org.apache.inlong.manager.pojo.workflow.ListenerExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.ProcessResponse;
+import org.apache.inlong.manager.pojo.workflow.TaskExecuteLog;
+import org.apache.inlong.manager.pojo.workflow.TaskResponse;
+import org.apache.inlong.manager.pojo.workflow.WorkflowResult;
+import org.apache.inlong.manager.pojo.workflow.form.process.ProcessForm;
+import org.apache.inlong.manager.pojo.workflow.form.task.TaskForm;
+import org.apache.inlong.manager.workflow.WorkflowContext;
+import org.apache.inlong.manager.workflow.WorkflowContext.ActionContext;
+import org.apache.inlong.manager.workflow.definition.UserTask;
+import org.apache.inlong.manager.workflow.definition.WorkflowProcess;
+import org.apache.inlong.manager.workflow.definition.WorkflowTask;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+
+/**
+ * Workflow utils
+ */
+public class WorkflowUtils {
+
+    public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+    private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowUtils.class);
+
+    /**
+     * Build workflow context from WorkflowProcess and WorkflowProcessEntity
+     */
+    public static WorkflowContext buildContext(ObjectMapper objectMapper, WorkflowProcess process,
+            WorkflowProcessEntity processEntity) {
+        try {
+            ProcessForm form = WorkflowUtils.parseProcessForm(objectMapper, processEntity.getFormData(), process);
+            return new WorkflowContext().setProcess(process)
+                    .setOperator(processEntity.getApplicant())
+                    .setProcessForm(form)
+                    .setProcessEntity(processEntity);
+        } catch (Exception e) {
+            LOGGER.error("build context from process form failed with id=" + processEntity.getId(), e);
+            return null;
+        }
+    }
+
+    /**
+     * Get the workflow result from the given workflow context
+     */
+    public static WorkflowResult getResult(WorkflowContext context) {
+        if (context == null) {
+            return null;
+        }
+
+        WorkflowResult workflowResult = new WorkflowResult();
+        workflowResult.setProcessInfo(WorkflowUtils.getProcessResponse(context.getProcessEntity()));
+        if (context.getActionContext() != null) {
+            ActionContext newAction = context.getActionContext();
+            workflowResult.setNewTasks(Lists.newArrayList(WorkflowUtils.getTaskResponse(newAction.getTaskEntity())));
+        }
+        return workflowResult;
+    }
+
+    /**
+     * Get process response from process entity
+     */
+    public static ProcessResponse getProcessResponse(WorkflowProcessEntity entity) {
+        if (entity == null) {
+            return null;
+        }
+
+        ProcessResponse processResponse = ProcessResponse.builder()
+                .id(entity.getId())
+                .name(entity.getName())
+                .displayName(entity.getDisplayName())
+                .type(entity.getType())
+                .title(entity.getTitle())
+                .applicant(entity.getApplicant())
+                .status(ProcessStatus.valueOf(entity.getStatus()))
+                .startTime(entity.getStartTime())
+                .endTime(entity.getEndTime())
+                .build();
+        try {
+            if (StringUtils.isNotBlank(entity.getFormData())) {
+                processResponse.setFormData(OBJECT_MAPPER.readTree(entity.getFormData()));
+            }
+            if (StringUtils.isNotBlank(entity.getExtParams())) {
+                processResponse.setExtParams(OBJECT_MAPPER.readTree(entity.getExtParams()));
+            }
+        } catch (Exception e) {
+            LOGGER.error("parse process form error: ", e);

Review Comment:
   It is strongly recommended to print entity when there is an error, which is convenient for troubleshooting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org