Java Code Examples for com.alibaba.fastjson.JSONObject#clone()

The following examples show how to use com.alibaba.fastjson.JSONObject#clone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static boolean isEquals(JSONObject define, Object obj) {
    if (!(obj instanceof TypeDefine)) {
        return false;
    }

    TypeDefine t = (TypeDefine) obj;

    JSONObject j1 = (JSONObject) define.clone();
    JSONObject j2 = (JSONObject) t.getDefine().clone();

    j1.remove(IGNORE_ABOVE_STR);
    j2.remove(IGNORE_ABOVE_STR);

    // 去除默认值配置
    removeDefaultValue(j1, ENABLED, "true");
    removeDefaultValue(j1, DYNAMIC, "false");
    removeDefaultValue(j1, DOC_VALUE, "true");
    removeDefaultValue(j1, INDEX, "true");

    removeDefaultValue(j2, ENABLED, "true");
    removeDefaultValue(j2, DYNAMIC, "false");
    removeDefaultValue(j2, DOC_VALUE, "true");
    removeDefaultValue(j2, INDEX, "true");

    return j1.equals(j2);
}
 
Example 2
public static boolean isEquals(JSONObject define, Object obj) {
    if (!(obj instanceof TypeDefine)) {
        return false;
    }

    TypeDefine t = (TypeDefine) obj;

    JSONObject j1 = (JSONObject) define.clone();
    JSONObject j2 = (JSONObject) t.getDefine().clone();

    j1.remove(IGNORE_ABOVE_STR);
    j2.remove(IGNORE_ABOVE_STR);

    // 去除默认值配置
    removeDefaultValue(j1, ENABLED, "true");
    removeDefaultValue(j1, DYNAMIC, "false");
    removeDefaultValue(j1, DOC_VALUE, "true");
    removeDefaultValue(j1, INDEX, "true");

    removeDefaultValue(j2, ENABLED, "true");
    removeDefaultValue(j2, DYNAMIC, "false");
    removeDefaultValue(j2, DOC_VALUE, "true");
    removeDefaultValue(j2, INDEX, "true");

    return j1.equals(j2);
}
 
Example 3
Source Project: Jpom   File: OutGivingProjectEditController.java    License: MIT License 4 votes vote down vote up
/**
 * 处理页面数据
 *
 * @param outGivingModel 分发实体
 * @param edit           是否为编辑模式
 * @return json
 */
private String doData(OutGivingModel outGivingModel, boolean edit) {
    outGivingModel.setName(getParameter("name"));
    if (StrUtil.isEmpty(outGivingModel.getName())) {
        return JsonMessage.getString(405, "分发名称不能为空");
    }
    String reqId = getParameter("reqId");
    List<NodeModel> nodeModelList = nodeService.getNodeModel(reqId);
    if (nodeModelList == null) {
        return JsonMessage.getString(401, "当前页面请求超时");
    }
    //
    String afterOpt = getParameter("afterOpt");
    AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
    if (afterOpt1 == null) {
        return JsonMessage.getString(400, "请选择分发后的操作");
    }
    outGivingModel.setAfterOpt(afterOpt1.getCode());
    Object object = getDefData(outGivingModel, edit);
    if (object instanceof String) {
        return object.toString();
    }
    JSONObject defData = (JSONObject) object;
    UserModel userModel = getUser();
    //
    List<OutGivingModel> outGivingModels = outGivingServer.list();
    List<OutGivingNodeProject> outGivingNodeProjects = new ArrayList<>();
    OutGivingNodeProject outGivingNodeProject;
    //
    Iterator<NodeModel> iterator = nodeModelList.iterator();
    Map<NodeModel, JSONObject> cache = new HashMap<>(nodeModelList.size());
    while (iterator.hasNext()) {
        NodeModel nodeModel = iterator.next();
        String add = getParameter("add_" + nodeModel.getId());
        if (!nodeModel.getId().equals(add)) {
            iterator.remove();
            continue;
        }
        // 判断项目是否已经被使用过啦
        if (outGivingModels != null) {
            for (OutGivingModel outGivingModel1 : outGivingModels) {
                if (outGivingModel1.getId().equalsIgnoreCase(outGivingModel.getId())) {
                    continue;
                }
                if (outGivingModel1.checkContains(nodeModel.getId(), outGivingModel.getId())) {
                    return JsonMessage.getString(405, "已经存在相同的分发项目:" + outGivingModel.getId());
                }
            }
        }
        outGivingNodeProject = outGivingModel.getNodeProject(nodeModel.getId(), outGivingModel.getId());
        if (outGivingNodeProject == null) {
            outGivingNodeProject = new OutGivingNodeProject();
        }
        outGivingNodeProject.setNodeId(nodeModel.getId());
        outGivingNodeProject.setProjectId(outGivingModel.getId());
        outGivingNodeProjects.add(outGivingNodeProject);
        // 检查数据
        JSONObject allData = (JSONObject) defData.clone();
        String token = getParameter(StrUtil.format("{}_token", nodeModel.getId()));
        allData.put("token", token);
        String jvm = getParameter(StrUtil.format("{}_jvm", nodeModel.getId()));
        allData.put("jvm", jvm);
        String args = getParameter(StrUtil.format("{}_args", nodeModel.getId()));
        allData.put("args", args);
        // 项目副本
        String javaCopyIds = getParameter(StrUtil.format("{}_javaCopyIds", nodeModel.getId()));
        allData.put("javaCopyIds", javaCopyIds);
        if (StrUtil.isNotEmpty(javaCopyIds)) {
            String[] split = StrUtil.split(javaCopyIds, StrUtil.COMMA);
            for (String copyId : split) {
                String copyJvm = getParameter(StrUtil.format("{}_jvm_{}", nodeModel.getId(), copyId));
                String copyArgs = getParameter(StrUtil.format("{}_args_{}", nodeModel.getId(), copyId));
                allData.put("jvm_" + copyId, copyJvm);
                allData.put("args_" + copyId, copyArgs);
            }
        }
        JsonMessage<String> jsonMessage = sendData(nodeModel, userModel, allData, false);
        if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
            return JsonMessage.getString(406, nodeModel.getName() + "节点失败:" + jsonMessage.getMsg());
        }
        cache.put(nodeModel, allData);
    }
    // 删除已经删除的项目
    String error = deleteProject(outGivingModel, outGivingNodeProjects, userModel);
    if (error != null) {
        return error;
    }
    outGivingModel.setOutGivingNodeProjectList(outGivingNodeProjects);
    outGivingModel.setTempCacheMap(cache);
    return null;
}