Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -820,28 +820,29 @@ public Map<String, Object> viewVariables(long projectCode, Integer workflowInsta
Map<String, String> timeParams = BusinessTimeUtils
.getBusinessTime(workflowInstance.getCmdTypeIfComplement(),
workflowInstance.getScheduleTime(), timezone);
String userDefinedParams = workflowInstance.getGlobalParams();

// global params
List<Property> globalParams = new ArrayList<>();

// global param string
String globalParamStr =
ParameterUtils.convertParameterPlaceholders(GlobalParameterUtils.serializeGlobalParameter(globalParams),
timeParams);
globalParams = GlobalParameterUtils.deserializeGlobalParameter(globalParamStr);
for (Property property : globalParams) {
timeParams.put(property.getProp(), property.getValue());
}
String globalParamsJson = workflowInstance.getGlobalParams();
List<Property> finalGlobalParams = new ArrayList<>();

if (StringUtils.isNotEmpty(globalParamsJson)) {
String replacedJsonStr = ParameterUtils.convertParameterPlaceholders(globalParamsJson, timeParams);
finalGlobalParams = GlobalParameterUtils.deserializeGlobalParameter(replacedJsonStr);

if (userDefinedParams != null && userDefinedParams.length() > 0) {
globalParams = GlobalParameterUtils.deserializeGlobalParameter(userDefinedParams);
if (finalGlobalParams != null) {
for (Property property : finalGlobalParams) {
if (property.getProp() != null && property.getValue() != null) {
timeParams.put(property.getProp(), property.getValue());
}
}
}
}

Map<String, Map<String, Object>> localUserDefParams = getLocalParams(workflowInstance, timeParams);

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

resultMap.put(GLOBAL_PARAMS, globalParams);
resultMap.put(GLOBAL_PARAMS, finalGlobalParams);
resultMap.put(LOCAL_PARAMS, localUserDefParams);

result.put(DATA_LIST, resultMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -790,6 +791,89 @@ public void testViewVariables() {
Assertions.assertEquals(Status.WORKFLOW_INSTANCE_NOT_EXIST, processNotExist.get(Constants.STATUS));
}

@Test
public void testViewVariables_WithTimePlaceholders() {
String globalParamsJson = "[{\"prop\":\"biz_date\",\"value\":\"$[yyyyMMdd]\",\"type\":\"VARCHAR\"}," +
"{\"prop\":\"env\",\"value\":\"${ENV_TYPE}\",\"type\":\"VARCHAR\"}]";

WorkflowInstance workflowInstance = getProcessInstance();
workflowInstance.setId(1);
workflowInstance.setCommandType(CommandType.SCHEDULER);

Calendar calendar = Calendar.getInstance();
calendar.set(2026, Calendar.MARCH, 13, 10, 0, 0);
workflowInstance.setScheduleTime(calendar.getTime());
workflowInstance.setGlobalParams(globalParamsJson);
workflowInstance.setWorkflowDefinitionCode(100L);

when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance);

WorkflowDefinition workflowDefinition = new WorkflowDefinition();
workflowDefinition.setCode(100L);
workflowDefinition.setProjectCode(1L);
when(workflowDefinitionMapper.queryByCode(100L)).thenReturn(workflowDefinition);

Map<String, Object> result = workflowInstanceService.viewVariables(1L, 1);

Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));

Map<String, Object> dataList = (Map<String, Object>) result.get(Constants.DATA_LIST);
Assertions.assertNotNull(dataList);

List<Property> globalParams = (List<Property>) dataList.get(Constants.GLOBAL_PARAMS);
Assertions.assertNotNull(globalParams);
Assertions.assertEquals(2, globalParams.size());

Property dateParam = globalParams.stream()
.filter(p -> "biz_date".equals(p.getProp()))
.findFirst()
.orElse(null);
Assertions.assertNotNull(dateParam);
Assertions.assertEquals("20260313", dateParam.getValue(),
"Time placeholder $[yyyyMMdd] should be replaced with schedule time");

Property envParam = globalParams.stream()
.filter(p -> "env".equals(p.getProp()))
.findFirst()
.orElse(null);
Assertions.assertNotNull(envParam);
}

@Test
public void testViewVariables_InstanceNotFound() {
when(workflowInstanceMapper.queryDetailById(999)).thenReturn(null);

Map<String, Object> result = workflowInstanceService.viewVariables(1L, 999);

Assertions.assertEquals(Status.WORKFLOW_INSTANCE_NOT_EXIST, result.get(Constants.STATUS));
Assertions.assertNull(result.get(Constants.DATA_LIST));
}

@Test
public void testViewVariables_EmptyGlobalParams() {
WorkflowInstance workflowInstance = getProcessInstance();
workflowInstance.setId(2);
workflowInstance.setCommandType(CommandType.START_PROCESS);
workflowInstance.setScheduleTime(new Date());
workflowInstance.setGlobalParams("");
workflowInstance.setWorkflowDefinitionCode(101L);

when(workflowInstanceMapper.queryDetailById(2)).thenReturn(workflowInstance);

WorkflowDefinition workflowDefinition = new WorkflowDefinition();
workflowDefinition.setCode(101L);
workflowDefinition.setProjectCode(1L);
when(workflowDefinitionMapper.queryByCode(101L)).thenReturn(workflowDefinition);

Map<String, Object> result = workflowInstanceService.viewVariables(1L, 2);

Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));

Map<String, Object> dataList = (Map<String, Object>) result.get(Constants.DATA_LIST);
List<Property> globalParams = (List<Property>) dataList.get(Constants.GLOBAL_PARAMS);
Assertions.assertTrue(globalParams.isEmpty(), "Global params list should be empty when input is empty string");
}

@Test
public void testViewGantt() throws Exception {
WorkflowInstance workflowInstance = getProcessInstance();
Expand Down
Loading