Commit 572ee0fc authored by simon824's avatar simon824
Browse files

Using Jackson instead of Fastjson

parent 6205e687
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -755,8 +756,13 @@ public class ProcessDefinitionService extends BaseDAGService {
    public Map<String, Object> importProcessDefinition(User loginUser, MultipartFile file, String currentProjectName) {
        Map<String, Object> result = new HashMap<>(5);
        String processMetaJson = FileUtils.file2String(file);
        List<ProcessMeta> processMetaList = JSONUtils.toList(processMetaJson, ProcessMeta.class);
        List<ProcessMeta> processMetaList = new ArrayList<>();

        try {
            processMetaList = JSONUtils.getMapper().readValue(processMetaJson, new TypeReference<List<ProcessMeta>>() {});
        } catch (Exception e) {
            logger.error("parse list exception!", e);
        }
        //check file content
        if (CollectionUtils.isEmpty(processMetaList)) {
            putMsg(result, Status.DATA_IS_NULL, "fileContent");
+18 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.api.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.dolphinscheduler.api.dto.gantt.GanttDto;
import org.apache.dolphinscheduler.api.dto.gantt.Task;
import org.apache.dolphinscheduler.api.enums.Status;
@@ -531,7 +532,11 @@ public class ProcessInstanceService extends BaseDAGService {
        List<Property> globalParams = new ArrayList<>();

        if (userDefinedParams != null && userDefinedParams.length() > 0) {
            globalParams = JSONUtils.toList(userDefinedParams, Property.class);
            try {
                globalParams = JSONUtils.getMapper().readValue(userDefinedParams, new TypeReference<List<Property>>() {});
            } catch (Exception e) {
                logger.error("parse list exception!", e);
            }
        }


@@ -540,7 +545,11 @@ public class ProcessInstanceService extends BaseDAGService {
        // global param string
        String globalParamStr = JSONUtils.toJsonString(globalParams);
        globalParamStr = ParameterUtils.convertParameterPlaceholders(globalParamStr, timeParams);
        globalParams = JSONUtils.toList(globalParamStr, Property.class);
        try {
            globalParams = JSONUtils.getMapper().readValue(globalParamStr, new TypeReference<List<Property>>() {});
        } catch (Exception e) {
            logger.error("parse list exception!", e);
        }
        for (Property property : globalParams) {
            timeParams.put(property.getProp(), property.getValue());
        }
@@ -553,7 +562,13 @@ public class ProcessInstanceService extends BaseDAGService {
            String localParams = map.get(LOCAL_PARAMS);
            if (localParams != null && !localParams.isEmpty()) {
                localParams = ParameterUtils.convertParameterPlaceholders(localParams, timeParams);
                List<Property> localParamsList = JSONUtils.toList(localParams, Property.class);
                List<Property> localParamsList = new ArrayList<>();
                try {
                    localParamsList = JSONUtils.getMapper().readValue(localParams, new TypeReference<List<Property>>() {});
                } catch (Exception e) {
                    logger.error("parse list exception!", e);
                }

                Map<String,Object> localParamsMap = new HashMap<>();
                localParamsMap.put("taskType",taskNode.getType());
                localParamsMap.put("localParamsList",localParamsList);
+6 −1
Original line number Diff line number Diff line
@@ -50,6 +50,11 @@ public class JSONUtils {
        objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true).setTimeZone(TimeZone.getDefault());
    }

    public static ObjectMapper getMapper() {
        return objectMapper;
    }


    public static ArrayNode createArrayNode() {
        return objectMapper.createArrayNode();
    }
@@ -124,7 +129,7 @@ public class JSONUtils {
            return objectMapper.readValue(json, new TypeReference<List<T>>() {
            });
        } catch (Exception e) {
            logger.error("JSONArray.parseArray exception!", e);
            logger.error("parse list exception!", e);
        }

        return new ArrayList<>();
+26 −8
Original line number Diff line number Diff line
@@ -21,15 +21,21 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
@@ -37,6 +43,8 @@ import java.util.stream.Collectors;
 */
@TableName("t_ds_process_definition")
public class ProcessDefinition {
    private static final Logger logger = LoggerFactory.getLogger(ProcessDefinition.class);

    /**
     * id
     */
@@ -271,7 +279,11 @@ public class ProcessDefinition {
    }

    public void setGlobalParams(String globalParams) {
        this.globalParamList = JSONUtils.toList(globalParams, Property.class);
        try {
            this.globalParamList = JSONUtils.getMapper().readValue(globalParams, new TypeReference<List<Property>>() {});
        } catch (IOException e) {
            logger.error("json parse exception!", e);
        }
        this.globalParams = globalParams;
    }

@@ -285,10 +297,16 @@ public class ProcessDefinition {
    }

    public Map<String, String> getGlobalParamMap() {
        List<Property> propList;
        List<Property> propList = new ArrayList<> ();

        if (globalParamMap == null && StringUtils.isNotEmpty(globalParams)) {
            propList = JSONUtils.toList(globalParams, Property.class);
            try {
                propList = JSONUtils.getMapper().readValue(globalParams, new TypeReference<List<Property>>() {
                });
            } catch (IOException e) {
                logger.error("json parse exception!", e);
            }

            globalParamMap = propList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue));
        }

+39 −0
Original line number Diff line number Diff line
/*
 * 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.dolphinscheduler.dao.entity;

import org.junit.Assert;
import org.junit.Test;

public class ProcessDefinitionTest {

    /**
     * task instance sub process
     */
    @Test
    public void getGlobalParamMapTest() {
        ProcessDefinition taskInstance = new ProcessDefinition();

        //sub process
        taskInstance.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]");

        Assert.assertEquals(taskInstance.getGlobalParamMap().toString(),"{selenium_global_parameters_1=selenium_global_parameters_value_1}");



    }
}
Loading