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

The following examples show how to use com.alibaba.fastjson.JSONObject#remove() . 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: RecycleRestore.java    From rebuild with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 转换成 Record 对象,返回多条是可能存在明细
 *
 * @param content
 * @param recordId
 * @return
 */
private List<Record> conver2Record(JSONObject content, ID recordId) {
    if (!MetadataHelper.containsEntity(recordId.getEntityCode())) {
        return Collections.emptyList();
    }

    JSONArray slaveList = content.getJSONArray(RecycleBean.NAME_SLAVELIST);
    if (slaveList != null) {
        content.remove(RecycleBean.NAME_SLAVELIST);
    }

    List<Record> records = new ArrayList<>();

    Entity entity = MetadataHelper.getEntity(recordId.getEntityCode());
    Record record = new RestoreRecordCreator(entity, content).create(true);
    records.add(record);

    Entity slaveEntity = entity.getSlaveEntity();
    if (slaveList != null && slaveEntity != null) {
        for (Object o : slaveList) {
            Record slave = new RestoreRecordCreator(slaveEntity, (JSONObject) o).create(true);
            records.add(slave);
        }
    }
    return records;
}
 
Example 2
Source File: RpcServerDefaultHandler.java    From xian with Apache License 2.0 6 votes vote down vote up
/**
 * 打印rpc消息传输耗时等信息:术语rpcFly
 *
 * @deprecated 打印日志消耗性能,即使是debug级别也是,因此废弃,请不要再调用本方法
 */
private void logRpcFly(JSONObject msgJson, String msgStr, ChannelHandlerContext ctx) {
    try {
        String ssid = msgJson.getString("$ssid");
        String from = msgJson.getString("$LOCAL_NODE_ID");
        String msgType = msgJson.getString("$msgType");
        if (ssid != null) {
            long start = (long) msgJson.remove("$timestampMs");//目前是用完删掉,避免传递到业务层
            LOG.debug(new JSONObject() {{
                put("cost", System.currentTimeMillis() - start);
                put("type", "rpcFly");
                put("ssid", ssid);
                put("from", from);
                put("length", msgStr.length());
                put("payload", msgStr);
                put("msgType", msgType);
                put("client", ctx.channel().remoteAddress());
                put("server", ctx.channel().localAddress());
            }});
        }
    } catch (Throwable e) {
        LOG.error(e);
    }
}
 
Example 3
Source File: PptxReaderImpl.java    From tephra with MIT License 6 votes vote down vote up
private void parseBackground(ReaderContext readerContext, XSLFBackground xslfBackground, JSONObject slide,
                             Map<Integer, String> layout) {
    JSONObject background = layout.containsKey(0) ? json.toObject(layout.get(0)) : new JSONObject();
    parser.parseShape(readerContext, xslfBackground, background);
    background.remove("anchor");

    if (xslfBackground.getFillColor() != null)
        background.put("color", officeHelper.colorToJson(xslfBackground.getFillColor()));

    if (background.isEmpty())
        return;

    if (readerContext.isLayout())
        layout.put(0, json.toString(background));
    else
        slide.put("background", background);
}
 
Example 4
Source File: BeanUtils.java    From yuzhouwan with Apache License 2.0 6 votes vote down vote up
/**
     * Deal with tail that will be format as {..., "metric": "xxx", "value": yyy}.
     *
     * @param obj
     * @param tail
     * @param rows
     * @param jsonObject
     * @param <T>
     */
    public static <T> void dealWithTail4Druid(T obj, Set<Field> tail, LinkedList<String> rows, JSONObject jsonObject) {
        boolean isFirst = true;
        for (Field t : tail)
            try {
                t.setAccessible(true);
                if (!isFirst) {
                    jsonObject.remove(DRUID_METRICS);
                    jsonObject.remove(DRUID_VALUE);
                }
                if (isFirst) isFirst = false;
                jsonObject.put(DRUID_METRICS, t.getName());
//                jsonObject.put("value_".concat(t.getType().getSimpleName()), t.get(obj));
                // then should use double sum/max/min with Aggregation in Druid
                jsonObject.put(DRUID_VALUE, t.get(obj));
                rows.add(jsonObject.toJSONString());
            } catch (IllegalAccessException e) {
                LOGGER.error(ExceptionUtils.errorInfo(e));
            }
    }
 
Example 5
Source File: DiscEngine.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private static String getWeiyunPostJson(String in) {
    JSONObject inObj = JSON.parseObject(in);
    JSONObject outObj = JSON.parseObject(JSON_STR_WEIYUN);

    JSONObject body = outObj.getJSONObject("req_body").getJSONObject("ReqMsg_body")
            .getJSONObject("weiyun.WeiyunSharePartDownloadMsgReq_body");

    body.put("share_key", inObj.getString("share_key"));
    body.put("pack_name", inObj.getString("share_name"));
    body.put("pdir_key", inObj.getString("pdir_key"));

    JSONArray fileList = inObj.getJSONArray("file_list");
    for (int i = 0, n = fileList.size(); i < n; i++) {
        JSONObject file = fileList.getJSONObject(i);
        file.remove("file_name");
        file.remove("file_size");
    }

    body.put("file_list", fileList);

    return outObj.toString();
}
 
Example 6
Source File: UserRealm.java    From SpringBoot-Shiro-Vue with MIT License 6 votes vote down vote up
/**
 * 验证当前登录的Subject
 * LoginController.login()方法中执行Subject.login()时 执行此方法
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
	String loginName = (String) authcToken.getPrincipal();
	// 获取用户密码
	String password = new String((char[]) authcToken.getCredentials());
	JSONObject user = loginService.getUser(loginName, password);
	if (user == null) {
		//没找到帐号
		throw new UnknownAccountException();
	}
	//交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现
	SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
			user.getString("username"),
			user.getString("password"),
			//ByteSource.Util.bytes("salt"), salt=username+salt,采用明文访问时,不需要此句
			getName()
	);
	//session中不需要保存密码
	user.remove("password");
	//将用户信息放入session中
	SecurityUtils.getSubject().getSession().setAttribute(Constants.SESSION_USER_INFO, user);
	return authenticationInfo;
}
 
Example 7
Source File: TypeDefineOperator.java    From ES-Fastloader with Apache License 2.0 5 votes vote down vote up
private static void dealHighLevelType(JSONObject define) {
    if (isLowVersionString(define)) {
        // 处理String
        if (define.containsKey(INDEX_STR)) {
            if (ES_LOW_STRING_NOT_ANALYZED_STR.equals(define.get(INDEX_STR))) {
                // keyword
                define.remove(INDEX_STR);
                define.put(TYPE_STR, ES_HIGH_TYPE_KEYWORD_STR);
            } else if ("no".equals(define.get(INDEX_STR))) {
                // keyword and not index
                define.put(INDEX_STR, false);
                define.remove(IGNORE_ABOVE_STR);
                define.put(DOC_VALUES_STR, false);
                define.put(TYPE_STR, ES_HIGH_TYPE_KEYWORD_STR);
            } else {
                define.remove(INDEX_STR);
                define.remove(IGNORE_ABOVE_STR);
                define.put(TYPE_STR, ES_HIGH_TYPE_TEXT_STR);
            }
        } else {
            define.remove(IGNORE_ABOVE_STR);
            define.put(TYPE_STR, ES_HIGH_TYPE_TEXT_STR);
        }
    } else {
        // 处理其他字段
        if (define.containsKey(INDEX_STR) && "no".equals(define.get(INDEX_STR))) {
            define.put(INDEX_STR, false);
            define.put(DOC_VALUES_STR, false);
        }
    }

    // 移除高版本不兼容字段
    define.remove(ES_LOW_STRING_FIELDDATA_STR);
    define.remove(INCLUDE_IN_ALL_STR);
    define.remove(PRECISION_STEP_STR);
}
 
Example 8
Source File: CommonUtil.java    From SpringBoot-Shiro-Vue with MIT License 5 votes vote down vote up
/**
 * 在分页查询之前,为查询条件里加上分页参数
 *
 * @param paramObject    查询条件json
 * @param defaultPageRow 默认的每页条数,即前端不传pageRow参数时的每页条数
 */
private static void fillPageParam(final JSONObject paramObject, int defaultPageRow) {
	int pageNum = paramObject.getIntValue("pageNum");
	pageNum = pageNum == 0 ? 1 : pageNum;
	int pageRow = paramObject.getIntValue("pageRow");
	pageRow = pageRow == 0 ? defaultPageRow : pageRow;
	paramObject.put("offSet", (pageNum - 1) * pageRow);
	paramObject.put("pageRow", pageRow);
	paramObject.put("pageNum", pageNum);
	//删除此参数,防止前端传了这个参数,pageHelper分页插件检测到之后,拦截导致SQL错误
	paramObject.remove("pageSize");
}
 
Example 9
Source File: AutoDeployDataLineService.java    From DBus with Apache License 2.0 5 votes vote down vote up
public void deleteCanalConf(String dsName) throws Exception {
    JSONObject canalConfJson = getZKNodeData(Constants.CANAL_PROPERTIES_ROOT);
    JSONObject dsCanalConf = canalConfJson.getJSONObject(KeeperConstants.DS_CANAL_CONF);
    if (dsCanalConf != null) {
        dsCanalConf.remove(dsName);
    }
    zkService.setData(Constants.CANAL_PROPERTIES_ROOT,
            JsonFormatUtils.toPrettyFormat(canalConfJson.toJSONString()).getBytes(KeeperConstants.UTF8));
}
 
Example 10
Source File: CommonUtil.java    From SpringBoot-Shiro-Vue-master-20180625 with Apache License 2.0 5 votes vote down vote up
/**
 * 在分页查询之前,为查询条件里加上分页参数
 *
 * @param paramObject    查询条件json
 * @param defaultPageRow 默认的每页条数,即前端不传pageRow参数时的每页条数
 */
public static void fillPageParam(final JSONObject paramObject, int defaultPageRow) {
    int pageNum = paramObject.getIntValue("pageNum");
    pageNum = pageNum == 0 ? 1 : pageNum;
    int pageRow = paramObject.getIntValue("pageRow");
    pageRow = pageRow == 0 ? defaultPageRow : pageRow;
    paramObject.put("offSet", (pageNum - 1) * pageRow);
    paramObject.put("pageRow", pageRow);
    paramObject.put("pageNum", pageNum);
    //删除此参数,防止前端传了这个参数,pageHelper分页插件检测到之后,拦截导致SQL错误
    paramObject.remove("pageSize");
}
 
Example 11
Source File: ConfigServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public String getGlobalConfig() {
    JSONObject jsonObject = (JSONObject) EfoApplication.settings.getObjectUseEval(ConfigConsts
            .GLOBAL_OF_SETTINGS).clone();
    jsonObject.remove(ConfigConsts.UPLOAD_PATH_OF_GLOBAL);
    jsonObject.remove(ConfigConsts.TOKEN_PATH_OF_GLOBAL);
    jsonObject.remove(ConfigConsts.UPLOAD_FORM_OF_SETTING);
    return jsonObject.toString();
}
 
Example 12
Source File: ElasticsearchHighRestFactory.java    From database-transform-tool with Apache License 2.0 5 votes vote down vote up
public String bulkUpsert(String index,String type,List<Object> jsons){
		try {
			if(xclient==null){
				init();
			}
			BulkRequest request = new BulkRequest();
			for (Object json : jsons) {
				JSONObject obj = JSON.parseObject(JSON.toJSONString(json));
				String id = UUIDs.base64UUID();
				if(obj.containsKey("id")){
					id = obj.getString("id");
					obj.remove("id");
				}
//				if(obj.containsKey("id")){
//					request.add(new UpdateRequest(index, type, id).doc(obj.toJSONString(),XContentType.JSON));
//				}else{
//					request.add(new IndexRequest(index, type).source(obj.toJSONString(),XContentType.JSON));
//				}
				request.add(new UpdateRequest(index, type, id).upsert(obj.toJSONString(),XContentType.JSON));
			}
			BulkResponse result = xclient.bulk(request);
			return result.toString();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
 
Example 13
Source File: TypeDefineOperator.java    From ES-Fastloader with Apache License 2.0 5 votes vote down vote up
/**
 * 设置成检索
 *
 */
public static void setIndexOn(JSONObject define) {
    if (isHighVersionString(define)) {
        define.remove(INDEX_STR);
        define.put(TYPE_STR, ES_HIGH_TYPE_KEYWORD_STR);
    } else {
        define.put(TYPE_STR, ES_LOW_STRING_NOT_ANALYZED_STR);
    }
}
 
Example 14
Source File: MongoTest.java    From tephra with MIT License 5 votes vote down vote up
@Test
public void insert() {
    create();

    mongo.delete(null, "t_mongo", null);

    JSONObject object1 = new JSONObject();
    object1.put("id", generator.uuid());
    object1.put("name", "hello");
    Assert.assertTrue(mongo.find(null, "t_mongo", JSON.parseObject("{\"id\":\"" + object1.getString("id") + "\"}")).isEmpty());
    mongo.insert(null, "t_mongo", object1);
    JSONObject object2 = mongo.findOne(null, "t_mongo", JSON.parseObject("{\"id\":\"" + object1.getString("id") + "\"}"));
    Assert.assertEquals(object1.getString("name"), object2.getString("name"));

    JSONArray array1 = new JSONArray();
    array1.add(object1);
    object2.remove("_id");
    object2.put("id", generator.uuid());
    object2.put("name", "name 2");
    array1.add(object2);
    mongo.insert(null, "t_mongo", array1);
    JSONArray array2 = mongo.find(null, "t_mongo", null);
    Assert.assertEquals(3, array2.size());
    JSONObject object3 = array2.getJSONObject(0);
    Assert.assertEquals(object1.getString("id"), object3.getString("id"));
    Assert.assertEquals(object1.getString("name"), object3.getString("name"));
    JSONObject object4 = array2.getJSONObject(1);
    Assert.assertEquals(object1.getString("id"), object4.getString("id"));
    Assert.assertEquals(object1.getString("name"), object4.getString("name"));
    JSONObject object5 = array2.getJSONObject(2);
    Assert.assertEquals(object2.getString("id"), object5.getString("id"));
    Assert.assertEquals(object2.getString("name"), object5.getString("name"));
}
 
Example 15
Source File: TypeDefineOperator.java    From ES-Fastloader with Apache License 2.0 5 votes vote down vote up
private static void removeDefaultValue(JSONObject def, String typeName, String defaultValue) {
    if(!def.containsKey(typeName)) {
        return;
    }

    String value = def.getString(typeName);
    if(defaultValue.equals(value)) {
        def.remove(typeName);
    }
}
 
Example 16
Source File: ConfigServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public String getUserConfig() {
    JSONObject jsonObject = (JSONObject) EfoApplication.settings.getObjectUseEval(ConfigConsts.USER_OF_SETTINGS)
            .clone();
    jsonObject.remove(ConfigConsts.EMAIL_CONFIG_OF_USER);
    return jsonObject.toString();
}
 
Example 17
Source File: ResponseUtil.java    From java-unified-sdk with Apache License 2.0 4 votes vote down vote up
private static void removeType(JSONObject object) {
  if (object.containsKey("className") && object.containsKey(TYPE)) {
    object.remove("className");
    object.remove(TYPE);
  }
}
 
Example 18
Source File: JsonConfigUtil.java    From framework with Apache License 2.0 4 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @param obj
 * @return <br>
 */
@SuppressWarnings("rawtypes")
public static FlowConfig getFlowConfig(final JSONObject obj) {

    FlowConfig config = new FlowConfig();

    String component = obj.getString("component");
    if (StringUtils.isNotEmpty(component)) {
        FlowComponent flowComponent = ContextHolder.getContext().getBean(component, FlowComponent.class);
        Assert.notNull(flowComponent, ErrorCodeDef.FLOW_COMPONENT_NOT_FOUND, component);
        config.setComponent(flowComponent);
    }

    String name = obj.getString("name");
    if (StringUtils.isEmpty(name)) {
        name = component;
    }
    config.setName(name);

    String version = obj.getString("version");
    if (StringUtils.isEmpty(version)) {
        version = "1.0";
    }

    JSONArray children = obj.getJSONArray("children");

    if (CollectionUtils.isNotEmpty(children)) {
        List<FlowConfig> childConfigList = new ArrayList<FlowConfig>();
        for (int i = 0, size = children.size(); i < size; i++) {
            childConfigList.add(getFlowConfig(children.getJSONObject(i)));
        }
        config.setChildrenConfigList(childConfigList);
    }

    obj.remove("component");
    obj.remove("name");
    obj.remove("version");
    obj.remove("children");
    config.setConfigAttrMap(obj);
    return config;
}
 
Example 19
Source File: DashboardControll.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping("/dash-new")
public void dashNew(HttpServletRequest request, HttpServletResponse response) throws IOException {
	ID user = getRequestUser(request);
	JSONObject formJson = (JSONObject) ServletUtils.getRequestJson(request);
	JSONArray dashCopy = formJson.getJSONArray("__copy");
	if (dashCopy != null) {
		formJson.remove("__copy");
	}
	formJson.put("config", JSONUtils.EMPTY_ARRAY_STR);
	
	Record dashRecord = EntityHelper.parse(formJson, user);
	
	// 复制当前面板
	if (dashCopy != null) {
		for (Object o : dashCopy) {
			JSONObject item = (JSONObject) o;
			Record chart = Application.createQueryNoFilter(
					"select config,belongEntity,chartType,title,createdBy from ChartConfig where chartId = ?")
					.setParameter(1, ID.valueOf(item.getString("chart")))
					.record();
			if (chart == null) {
				continue;
			}
			// 自己的直接使用,不是自己的复制一份
			if (ShareToManager.isSelf(user, chart.getID("createdBy"))) {
				continue;
			}

			chart.removeValue("createdBy");
			Record chartRecord = EntityHelper.forNew(EntityHelper.ChartConfig, user);
			for (Iterator<String> iter = chart.getAvailableFieldIterator(); iter.hasNext(); ) {
				String field = iter.next();
				chartRecord.setObjectValue(field, chart.getObjectValue(field));
			}
			chartRecord = Application.getCommonService().create(chartRecord);
			item.put("chart", chartRecord.getPrimary());
		}
		dashRecord.setString("config", dashCopy.toJSONString());
	}
	
	dashRecord = Application.getBean(DashboardConfigService.class).create(dashRecord);
	
	JSON ret = JSONUtils.toJSONObject("id", dashRecord.getPrimary());
	writeSuccess(response, ret);
}
 
Example 20
Source File: FlattenJsonArrayRule.java    From DBus with Apache License 2.0 4 votes vote down vote up
private static List<String> flattenJsonArray(String wkVal, String path) {
    List<String> rows = new ArrayList<>();
    JSONObject json = JSONObject.parseObject(wkVal);
    String parentPath = StringUtils.substringBeforeLast(path, ".");
    String currentPath = StringUtils.substringAfterLast(path, ".");
    if (json.containsKey(path)) {
        parentPath = StringUtils.EMPTY;
        currentPath = path;
    }
    Object currentJsonObj = JSONPath.read(wkVal, path);
    Object parentJsonObj = null;
    if (StringUtils.isBlank(parentPath)) {
        parentJsonObj = json;
    } else {
        parentJsonObj = JSONPath.read(wkVal, parentPath);
    }

    if (currentJsonObj instanceof JSONArray) {
        JSONArray retJsonArray = new JSONArray();
        JSONArray currentJsonArray = (JSONArray) currentJsonObj;
        for (int i = 0; i < currentJsonArray.size(); i++) {
            JSONObject jsonItemWk = new JSONObject();
            if (parentJsonObj instanceof JSONObject) {
                jsonItemWk = JSONObject.parseObject(((JSONObject) parentJsonObj).toJSONString());
                jsonItemWk.remove(currentPath);
            }
            jsonItemWk.put(currentPath, currentJsonArray.get(i));
            retJsonArray.add(jsonItemWk);
        }
        if (json.containsKey(path)) {
            for (int i = 0; i < retJsonArray.size(); i++) {
                JSONObject item = (JSONObject) retJsonArray.get(i);
                rows.add(item.toJSONString());
            }
        } else {
            JSONPath.set(json, parentPath, retJsonArray);
            rows.add(json.toJSONString());
        }
    }
    return rows;
}