public static void mergeOutputDataParams(
      Map<String, Parameter> allParams, Map<String, Parameter> params) {
    params.forEach(
        (name, param) -> {
          if (!allParams.containsKey(name)) {
            throw new MaestroValidationException(
                "Invalid output parameter [%s], not defined in params", name);
          }
          MergeContext context = MergeContext.stepCreate(ParamSource.OUTPUT_PARAMETER);
          if (param.getType() == ParamType.MAP && param.isLiteral()) {
            ParamDefinition baseDef = allParams.get(name).toDefinition();
            Map<String, ParamDefinition> baseMap = baseDef.asMapParamDef().getValue();
            ParamDefinition toMergeDef = param.toDefinition();
            Map<String, ParamDefinition> toMergeMap = toMergeDef.asMapParamDef().getValue();

            mergeParams(baseMap, toMergeMap, context);
            Parameter mergedParam =
                buildMergedParamDefinition(name, toMergeDef, baseDef, context, baseMap)
                    .toParameter();
            populateEvaluatedResultAndTime(mergedParam, param.getEvaluatedTime());
            allParams.put(name, mergedParam);
          } else if (param.getType() == ParamType.STRING_MAP && param.isLiteral()) {
            ParamDefinition baseDef = allParams.get(name).toDefinition();
            Map<String, String> baseMap = baseDef.asStringMapParamDef().getValue();
            ParamDefinition toMergeDef = param.toDefinition();
            Map<String, String> toMergeMap = toMergeDef.asStringMapParamDef().getValue();

            baseMap.putAll(toMergeMap);
            Parameter mergedParam =
                buildMergedParamDefinition(name, toMergeDef, baseDef, context, baseMap)
                    .toParameter();
            populateEvaluatedResultAndTime(mergedParam, param.getEvaluatedTime());
            allParams.put(name, mergedParam);
          } else {
            ParamDefinition paramDefinition =
                ParamsMergeHelper.buildMergedParamDefinition(
                    name,
                    param.toDefinition(),
                    allParams.get(name).toDefinition(),
                    MergeContext.stepCreate(ParamSource.OUTPUT_PARAMETER),
                    param.getValue());
            Parameter parameter = paramDefinition.toParameter();
            parameter.setEvaluatedResult(param.getEvaluatedResult());
            parameter.setEvaluatedTime(param.getEvaluatedTime());
            allParams.put(name, parameter);
          }
        });
  }
@Test
  public void testMergeOutputDataParamsOtherParams() throws JsonProcessingException {
    Map<String, Parameter> allParams =
        parseParamMap(
            "{\"long_array_param\":{\"evaluated_result\":[1,2,3],\"evaluated_time\":1626893775979,\"type\":\"LONG_ARRAY\",\"value\":[1,2,3]},\"long_param\":{\"evaluated_result\":21,\"evaluated_time\":1626893775979,\"type\":\"LONG\",\"value\":21},\"str_param\":{\"evaluated_result\":\"hello\",\"evaluated_time\":1626893775979,\"type\":\"STRING\",\"value\":\"hello\"},\"double_param\":{\"evaluated_result\":3.14,\"evaluated_time\":1626893775979,\"type\":\"DOUBLE\",\"value\":3.14},\"double_array_param\":{\"evaluated_result\":[1.1,-0.5,3.2],\"evaluated_time\":1626893775979,\"type\":\"DOUBLE_ARRAY\",\"value\":[1.1,-0.5,3.2]},\"boolean_param\":{\"evaluated_result\":false,\"evaluated_time\":1626893775979,\"type\":\"BOOLEAN\",\"value\":false},\"boolean_array_param\":{\"evaluated_result\":[true,false,true],\"evaluated_time\":1626893775979,\"type\":\"BOOLEAN_ARRAY\",\"value\":[true,false,true]}}");
    Map<String, Parameter> paramsToMerge =
        parseParamMap(
            "{\"long_array_param\":{\"evaluated_result\":[4,5],\"evaluated_time\":1626893775979,\"type\":\"LONG_ARRAY\",\"value\":[4,5]},\"long_param\":{\"evaluated_result\":21,\"evaluated_time\":1626893775979,\"type\":\"LONG\",\"value\":21},\"double_param\":{\"evaluated_result\":3.14,\"evaluated_time\":1626893775979,\"type\":\"DOUBLE\",\"value\":3.14},\"double_array_param\":{\"evaluated_result\":[1.1],\"evaluated_time\":1626893775979,\"type\":\"DOUBLE_ARRAY\",\"value\":[1.1]},\"boolean_param\":{\"evaluated_result\":false,\"evaluated_time\":1626893775979,\"type\":\"BOOLEAN\",\"value\":false},\"boolean_array_param\":{\"evaluated_result\":[true,true],\"evaluated_time\":1626893775979,\"type\":\"BOOLEAN_ARRAY\",\"value\":[true,true]}}");
    ParamsMergeHelper.mergeOutputDataParams(allParams, paramsToMerge);
    assertArrayEquals(
        new long[] {4, 5}, allParams.get("long_array_param").asLongArrayParam().getValue());
    assertEquals(21, (long) allParams.get("long_param").asLongParam().getValue());
    assertEquals("hello", allParams.get("str_param").asStringParam().getValue());
    assertEquals(
        3.14, allParams.get("double_param").asDoubleParam().getValue().doubleValue(), 0.01);
    assertArrayEquals(
        new double[] {1.1},
        allParams.get("double_array_param").asDoubleArrayParam().getEvaluatedResult(),
        0.01);
    assertEquals(false, allParams.get("boolean_param").asBooleanParam().getValue());
    assertArrayEquals(
        new boolean[] {true, true},
        allParams.get("boolean_array_param").asBooleanArrayParam().getValue());
  }