Java Code Examples for com.alibaba.fastjson.JSONArray#toJSONString()

The following examples show how to use com.alibaba.fastjson.JSONArray#toJSONString() . 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
Source File: ServiceConfigPushHistoryConditionImpl.java    From AthenaServing with Apache License 2.0 6 votes vote down vote up
@Override
public ServiceConfigPushHistory add(ServiceConfig serviceConfig, PushResult cacheCenterPushResult) {

    List<ServiceConfigText> serviceConfigTexts = new ArrayList<>();
    ServiceConfigText serviceConfigText = new ServiceConfigText();
    serviceConfigText.setName(serviceConfig.getName());
    serviceConfigTexts.add(serviceConfigText);

    //构造推送历史记录实体
    ServiceConfigPushHistory servicePushHistory = new ServiceConfigPushHistory(
            cacheCenterPushResult.getPushId(), this.getUserId(), serviceConfig.getGrayId(),
            serviceConfig.getProject().getName(), serviceConfig.getCluster().getName(), serviceConfig.getService().getName(),
            serviceConfig.getServiceVersion().getVersion(), cacheCenterPushResult.getResult(), JSONArray.toJSONString(serviceConfigTexts),
            new Date());

    //新增
    this.servicePushHistoryMapper.insert(servicePushHistory);
    return servicePushHistory;
}
 
Example 2
Source File: FastjsonUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * JSON String 缩进处理
 * @param json JSON String
 * @return JSON String
 */
public static String toJsonIndent(final String json) {
    if (json != null) {
        try {
            // 保持 JSON 字符串次序
            Object object = JSON.parse(json, Feature.OrderedField);
            if (object instanceof JSONObject) {
                return JSONObject.toJSONString(object, true);
            } else if (object instanceof JSONArray) {
                return JSONArray.toJSONString(object, true);
            }
        } catch (Exception e) {
            JCLogUtils.eTag(TAG, e, "toJsonIndent");
        }
    }
    return null;
}
 
Example 3
Source File: OfflineMessageServiceImplement.java    From withme3.0 with MIT License 6 votes vote down vote up
@Override
    @Transactional
    public Response getOfflineMessageTo(Integer userId) {
        try {
            List<OfflineMessage> messages = offlineMessageRepository.findAllByToId(userId);

            offlineMessageRepository.deleteAllByToId(userId);
//            Response response = restTemplate.postForEntity(CONSTANT.MESSAGE_SERVICE_ADD_MESSAGES, messages, Response.class).getBody();
//            if(response.getStatus() != 1){
//                throw new Exception();
//            }

            List<OfflineGroupMessage> groupMessages = offlineGroupMessageRepository.findAllByToId(userId);
            for(OfflineGroupMessage offlineGroupMessage : groupMessages){
                messages.add(new OfflineMessage(offlineGroupMessage));
            }
            offlineMessageRepository.deleteAllByToId(userId);
            return new Response(1, "Get offline messages success", JSONArray.toJSONString(messages, SerializerFeature.UseSingleQuotes));
        } catch (Exception e) {
            e.printStackTrace();
            return new Response(-1, "Get offline messages error", null);
        }
    }
 
Example 4
Source File: UserServiceImplement.java    From withme3.0 with MIT License 6 votes vote down vote up
@Override
    public Response getUsersByUserIds(String userIds) {
        try {
            String[] users = userIds.split(",");
//            ArrayList<Integer> intIds = new ArrayList<>();
            List<AuthUser> userList = new ArrayList<>();
            for (String userId : users) {
                //TODO 优化为不使用循环
                User user = userRepository.findByUserId(Integer.valueOf(userId));
                AuthUser authUser = new AuthUser(user.getUserId(), user.getUserName(), user.getUserNickName(), Common.getCurrentTime());
                userList.add(authUser);
            }
            return new Response(1, "获取用户成功", JSONArray.toJSONString(userList));
        } catch (Exception e){
            e.printStackTrace();
            return new Response(-1, "获取用户失败", null);
        }
    }
 
Example 5
Source File: UserServiceImplement.java    From withme3.0 with MIT License 6 votes vote down vote up
@Override
public Response getRelations(Integer userId) {
    try {
        List<User> userList = new ArrayList<>();
        User user = userRepository.findByUserId(userId);
        if (!Common.isNull(user)) {
            if (!Common.isEmpty(user.getUserRelations())) {
                String[] relation = user.getUserRelations().split(",");
                for (String friendId : relation) {
                    User user1 = userRepository.findByUserId(Integer.valueOf(friendId));
                    userList.add(user1);
                }
            }
        }
        return new Response(1, "获取好友成功", JSONArray.toJSONString(userList));
    } catch (Exception e) {
        e.printStackTrace();
        return new Response(-1, "获取好友异常", null);
    }
}
 
Example 6
Source File: RwMain.java    From rainbow with Apache License 2.0 6 votes vote down vote up
public void savePipelineState(Pipeline pipeline, String state) {
    String time = DateUtil.formatTime(new Date());
    State s = new State(time, state);
    Process p = searchProcessByPno(pipeline.getNo());
    if (p != null) {
        p.getPipelineState().add(s);
    } else {
        List<State> PipelineState = new ArrayList<>();
        PipelineState.add(s);
        p = new Process(pipeline.getNo(), PipelineState);
        SysConfig.ProcessList.add(p);
    }
    String processListJson = JSONArray.toJSONString(SysConfig.ProcessList);
    try {
        FileUtil.writeFile(processListJson, SysConfig.Catalog_Project + "cashe/process.txt");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: BackRightController.java    From Cynthia with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @Title:initUserFlowRight
 * @Type:BackRightController
 * @description:init user flow rights
 * @date:2014-5-5 下午8:04:34
 * @version:v1.0
 * @param request
 * @param httpSession
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/initUserFlowRight.do")
public String initUserFlowRight(HttpServletRequest request,HttpSession httpSession) throws Exception {
	
	Key key = (Key)httpSession.getAttribute("key");
	String userMail = key.getUsername();
	
	Map<String, String> temMap = das.queryUserTemplateRights(userMail);
	Set<String> flowSet = new HashSet<String>();
	for (String templateId : temMap.keySet()) {
		Template template = das.queryTemplate(DataAccessFactory.getInstance().createUUID(templateId));
		if (template != null) {
			flowSet.add(template.getFlowId().getValue());
		}
	}
	
	//自己创建的表单具有编辑权限
	for (Flow flow : das.queryAllFlows()) {
		if (flow != null && flow.getCreateUser() != null && flow.getCreateUser().equals(key.getUsername())) {
			flowSet.add(flow.getId().getValue());
		}
	}
	return JSONArray.toJSONString(flowSet);
}
 
Example 8
Source File: BugVersionMoveController.java    From Cynthia with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @description:get datas by template id
 * @date:2014-5-5 下午8:17:05
 * @version:v1.0
 * @param templateId
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getTemplateDatas.do")
public String getTempalteDatas(@RequestParam("templateId") String templateId) throws Exception {
	Map<String, String> templateIdTitleMap = new DataAccessSessionMySQL().queryIdAndFieldOfTemplate(templateId, "title");
	
	List<DataVO> templateDataList = new ArrayList<DataVO>();
	for(String dataId : templateIdTitleMap.keySet())
	{
		DataVO dataVO = new DataVO();
		dataVO.setId(dataId);
		dataVO.setName(templateIdTitleMap.get(dataId));
		templateDataList.add(dataVO);
	}
	return JSONArray.toJSONString(templateDataList);
}
 
Example 9
Source File: QuitBugMoveController.java    From Cynthia with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @description:get the quit users from template
 * @date:2014-5-5 下午8:35:55
 * @version:v1.0
 * @param templateIdStr
 * @param roleIdStr
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getQuitUser.do")
public String getQuitUser(@RequestParam("templateId") String templateIdStr , @RequestParam("roleId") String roleIdStr) throws Exception {
	if (roleIdStr == null || roleIdStr.length() == 0 || templateIdStr == null || templateIdStr.length() == 0) {
		return "";
	}
	UUID roleId = DataAccessFactory.getInstance().createUUID(roleIdStr);
	
	Template template = das.queryTemplate(DataAccessFactory.getInstance().createUUID(templateIdStr));
	
	Flow flow = das.queryFlow(template.getFlowId());
	
	List<UserInfo> allQuitUserList = getAllQuitUser(template, flow, roleId);
	
	return JSONArray.toJSONString(allQuitUserList);
}
 
Example 10
Source File: JSONFunction.java    From kafka-eagle with Apache License 2.0 5 votes vote down vote up
/** Parse a JSONArray. */
public String JSONS(String jsonArray, String key) {
	JSONArray object = com.alibaba.fastjson.JSON.parseArray(jsonArray);
	JSONArray target = new JSONArray();
	for (Object tmp : object) {
		JSONObject result = (JSONObject) tmp;
		JSONObject value = new JSONObject();
		value.put(key, result.getString(key));
		target.add(value);
	}
	return target.toJSONString();
}
 
Example 11
Source File: RwMain.java    From rainbow with Apache License 2.0 5 votes vote down vote up
private void changeState(String pno, int state) {
    for (Pipeline p : SysConfig.PipelineList) {
        if (p.getNo().equals(pno)) {
            p.setState(state);
            break;
        }
    }
    String aJson = JSONArray.toJSONString(SysConfig.PipelineList);
    try {
        FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/cashe.txt");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: ConfigRestApi.java    From txle with Apache License 2.0 5 votes vote down vote up
@GetMapping("/readSystemConfigCache")
public String readSystemConfigCache() {
    JSONArray jsonArray = new JSONArray();
    Map<String, String> systemConfigCache = this.consistencyCache.getSystemConfigCache();
    systemConfigCache.keySet().forEach(key -> {
        JSONObject json = new JSONObject();
        json.put(key, systemConfigCache.get(key));
        jsonArray.add(json);
    });
    return jsonArray.toJSONString();
}
 
Example 13
Source File: GroupServiceImplement.java    From withme3.0 with MIT License 5 votes vote down vote up
@Override
public Response findGroupByIds(String ids) {
    String[] strIds = ids.split(",");
    List<Integer> intIds = new ArrayList<>();
    for(String groupId : strIds){
        intIds.add(Integer.valueOf(groupId));
    }
    List<Groups> groups = groupRepository.findByIdIn(intIds);
    return new Response(1, "获取群组成功", JSONArray.toJSONString(groups));
}
 
Example 14
Source File: KafkaServiceImpl.java    From kafka-eagle with Apache License 2.0 5 votes vote down vote up
/**
 * Get zookeeper cluster information.
 */
public String zkCluster(String clusterAlias) {
	String[] zks = SystemConfigUtils.getPropertyArray(clusterAlias + ".zk.list", ",");
	JSONArray targets = new JSONArray();
	int id = 1;
	for (String zk : zks) {
		JSONObject object = new JSONObject();
		object.put("id", id++);
		object.put("ip", zk.split(":")[0]);
		object.put("port", zk.split(":")[1]);
		object.put("mode", zkService.status(zk.split(":")[0], zk.split(":")[1]));
		targets.add(object);
	}
	return targets.toJSONString();
}
 
Example 15
Source File: BatchModifyController.java    From Cynthia with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @Title:getCloseActionAndUser
 * @Type:BatchModifyController
 * @description:return the usable actions and users for batch close data
 * @date:2014-5-5 下午8:07:58
 * @version:v1.0
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping("/getCloseActionAndUser.do")
@ResponseBody
public String getCloseActionAndUser(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	
	String[] dataIdStrArray = request.getParameterValues("dataIds[]");
	if(dataIdStrArray == null || dataIdStrArray.length == 0){
		return "";
	}
	
	UUID[] dataIdArray = new UUID[dataIdStrArray.length];
	for(int i = 0; i < dataIdArray.length; i++){
		dataIdArray[i] = DataAccessFactory.getInstance().createUUID(dataIdStrArray[i]);
	}
	
	DataAccessSession das = DataAccessFactory.getInstance().createDataAccessSession(session.getAttribute("userName").toString(), ConfigUtil.magic);
	
	String actionsXML = DataManager.getInstance().getBatchCloseActionsXML(dataIdArray, das);
	
	if(actionsXML == null){
		return "";
	}
	
	Map<String, Set<String>> actionUserMap = new LinkedHashMap<String, Set<String>>();
	
	Document document = XMLUtil.string2Document(actionsXML, "UTF-8");
	List<Node> actionNodeList = XMLUtil.getNodes(document, "actions/action");
	for(Node actionNode : actionNodeList){
		String actionName = XMLUtil.getSingleNodeTextContent(actionNode, "name");
		actionUserMap.put(actionName, new LinkedHashSet<String>());
	}
	
	return JSONArray.toJSONString(actionUserMap);
}
 
Example 16
Source File: HtmlToJson.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取转换后的JSON 数组 有多级子节点
 *
 * @return
 */
public String get() {
    if (StrKit.isBlank(html)) {
        return null;
    }
    Document document = null;
    try {
        //判断是否需要绝对路径URL
        if (needAbsUrl) {
            document = Jsoup.parseBodyFragment(html, params.getBaseUri());
        } else {
            document = Jsoup.parseBodyFragment(html);
        }
    } finally {
        if (document == null) {
            return null;
        }
    }
    //以前使用Element元素会把无标签包裹的textNode节点给抛弃,这里改为选用Node节点实现
    //Node节点可以将一段html的所有标签和无标签文本区分 都转为Node
    List<Node> nodes = document.body().childNodes();
    //如果获取的Node为空 直接返回Null不处理
    if (nodes.isEmpty()) {
        return null;
    }
    //整个HTML转为JSON其实是转为一个JSON数组传递给前端html2wxml组件模板 循环解析
    JSONArray array = new JSONArray();
    JSONObject jsonObject = null;
    String tag = null;
    for (Node node : nodes) {
        tag = node.nodeName().toLowerCase();
        jsonObject = convertNodeToJsonObject(node, tag, "pre".equals(tag));
        if (jsonObject != null) {
            array.add(jsonObject);
        }
    }
    return array.toJSONString();
}
 
Example 17
Source File: BugVersionMoveController.java    From Cynthia with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @description:get tasks of template
 * @date:2014-5-5 下午8:16:31
 * @version:v1.0
 * @param oldTaskId
 * @param bugTaskFieldId
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getTaskBugTemplate.do")
public String getTaskBugTemplate(@RequestParam("oldTaskId") String oldTaskId ,@RequestParam("bugTaskField") String bugTaskFieldId ) throws Exception {
	
	Data oldTask = das.queryData(DataAccessFactory.getInstance().createUUID(oldTaskId));
	UUID [] bugs = oldTask.getMultiReference(DataAccessFactory.getInstance().createUUID(bugTaskFieldId));
	Map<String,Template> bugTemplateMap = new HashMap<String,Template>();
	Data bugData = null;
	
	Map<UUID, Template> allTemplateMap = new HashMap<UUID, Template>();
	
	if(bugs!=null&&bugs.length>0){
		for(UUID id : bugs){
		 bugData = das.queryData(id);	
		 if(bugData!=null){
			if (allTemplateMap.get(bugData.getTemplateId()) == null) {
				allTemplateMap.put(bugData.getTemplateId(), das.queryTemplate(bugData.getTemplateId()));
			} 
			Template template = allTemplateMap.get(bugData.getTemplateId());
			if(template!=null)
				bugTemplateMap.put(template.getId().toString(), template);
		 }
		}
	}
	
	return JSONArray.toJSONString(bugTemplateMap);
}
 
Example 18
Source File: ApiCmsController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 返回栏目数据
 * @param query
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/menu", method = { RequestMethod.GET, RequestMethod.POST })
public @ResponseBody String menu(HttpServletRequest request, HttpServletResponse response) throws Exception {
	//根据MainId过滤数据
	String mainId = request.getParameter("mainId");
	String ishref = request.getParameter("ishref");
	List<CmsMenu> list = cmsMenuService.getFirstMenu(mainId, ishref);
	return JSONArray.toJSONString(list);
}
 
Example 19
Source File: ProjectController.java    From Cynthia with GNU General Public License v2.0 3 votes vote down vote up
/**
 * @Title: getAllTemplate
 * @Description: 通过产品获取项目
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 * @return: String
 */
@RequestMapping("/getProjects.do")
@ResponseBody
public String getProjects(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	Map<String, String> allProjectsMap = new HashMap<String, String>();
	String userName = (String)request.getSession().getAttribute("userName");
	String productId = request.getParameter("productId");
	allProjectsMap = ProjectInvolveManager.getInstance().getProjectMap(userName, productId);
	return JSONArray.toJSONString(allProjectsMap);
}
 
Example 20
Source File: StatisticController.java    From Cynthia with GNU General Public License v2.0 3 votes vote down vote up
/**
 * @description:query all statistics of user
 * @date:2014-5-5 下午8:39:58
 * @version:v1.0
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping("/queryAllStatistics.do")
@ResponseBody
public String queryAllStatistics(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	String userName = ((Key)session.getAttribute("key")).getUsername();
	List<TimerAction> allTimerActions = new ArrayList<TimerAction>();
	allTimerActions.addAll(Arrays.asList(das.queryStatisticByUser(userName)));
	return JSONArray.toJSONString(allTimerActions);
}