本文整理汇总了Java中com.redhat.lightblue.util.JsonUtils类的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils类的具体用法?Java JsonUtils怎么用?Java JsonUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonUtils类属于com.redhat.lightblue.util包,在下文中一共展示了JsonUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSimpleRequest
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
public static FindRequest buildSimpleRequest(String entity, String version, String q, String p, String s, Long from, Long to, Long maxResults)
throws IOException {
// spec -> https://github.com/lightblue-platform/lightblue/wiki/Rest-Spec-Data#get-simple-find
String sq = QueryTemplateUtils.buildQueryFieldsTemplate(q);
LOGGER.debug("query: {} -> {}", q, sq);
String sp = QueryTemplateUtils.buildProjectionsTemplate(p);
LOGGER.debug("projection: {} -> {}", p, sp);
String ss = QueryTemplateUtils.buildSortsTemplate(s);
LOGGER.debug("sort:{} -> {}", s, ss);
FindRequest findRequest = new FindRequest();
findRequest.setEntityVersion(new EntityVersion(entity, version));
findRequest.setQuery(sq == null ? null : QueryExpression.fromJson(JsonUtils.json(sq)));
findRequest.setProjection(sp == null ? null : Projection.fromJson(JsonUtils.json(sp)));
findRequest.setSort(ss == null ? null : Sort.fromJson(JsonUtils.json(ss)));
findRequest.setFrom(from);
if(to!=null) {
findRequest.setTo(to);
} else if(maxResults!=null&&maxResults>0) {
findRequest.setTo((from == null ? 0 : from) + maxResults - 1);
}
return findRequest;
}
示例2: getSearchesForEntity
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@GET
@LZF
@Path("/search/{entity}")
public Response getSearchesForEntity(@PathParam("entity") String entity,
@QueryParam("P") String projection,
@QueryParam("S") String sort) {
FindRequest freq=new FindRequest();
freq.setEntityVersion(new EntityVersion(RestConfiguration.getSavedSearchCache().savedSearchEntity,
RestConfiguration.getSavedSearchCache().savedSearchVersion));
try {
freq.setProjection(projection==null?FieldProjection.ALL:Projection.fromJson(JsonUtils.json(QueryTemplateUtils.buildProjectionsTemplate(projection))));
freq.setSort(sort==null?new SortKey(new com.redhat.lightblue.util.Path("name"),false):Sort.fromJson(JsonUtils.json(QueryTemplateUtils.buildSortsTemplate(sort))));
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()).build();
}
CallStatus st=new FindCommand(freq.getEntityVersion().getEntity(),
freq.getEntityVersion().getVersion(),
freq.toJson().toString(), METRICS).run();
return Response.status(st.getHttpStatus()).entity(st.toString()).build();
}
示例3: buildSimpleRequest
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
private FindRequest buildSimpleRequest(String entity,String version, String q,String p, String s, Long from, Long to,Long maxResults)
throws IOException {
// spec -> https://github.com/lightblue-platform/lightblue/wiki/Rest-Spec-Data#get-simple-find
String sq = QueryTemplateUtils.buildQueryFieldsTemplate(q);
LOGGER.debug("query: {} -> {}", q, sq);
String sp = QueryTemplateUtils.buildProjectionsTemplate(p);
LOGGER.debug("projection: {} -> {}", p, sp);
String ss = QueryTemplateUtils.buildSortsTemplate(s);
LOGGER.debug("sort:{} -> {}", s, ss);
FindRequest findRequest = new FindRequest();
findRequest.setEntityVersion(new EntityVersion(entity, version));
findRequest.setQuery(sq == null ? null : QueryExpression.fromJson(JsonUtils.json(sq)));
findRequest.setProjection(sp == null ? null : Projection.fromJson(JsonUtils.json(sp)));
findRequest.setSort(ss == null ? null : Sort.fromJson(JsonUtils.json(ss)));
findRequest.setFrom(from);
if(to!=null) {
findRequest.setTo(to);
} else if(maxResults!=null&&maxResults>0) {
findRequest.setTo((from == null ? 0 : from) + maxResults - 1);
}
return findRequest;
}
示例4: testListSavedSearch
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testListSavedSearch() throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, URISyntaxException, JSONException {
Assert.assertNotNull("CrudResource was not injected by the container", cutCrudResource);
// Saved search metadata
System.out.println("Insert saved search md");
String metadata = readFile("lb-saved-search.json");
EntityMetadata em = RestConfiguration.getFactory().getJSONParser().parseEntityMetadata(JsonUtils.json(metadata));
RestConfiguration.getFactory().getMetadata().createNewMetadata(em);
System.out.println("saved search md inserted");
// insert saved search
System.out.println("Insert savedSearch");
cutCrudResource.insert("savedSearch","1.0.0","{'data':{'name':'test','entity':'country','parameters':[{'name':'iso'}],'query':{'field':'iso2code','op':'=','rvalue':'${iso}'}}}".
replaceAll("'","\""));
System.out.println("savedSearch inserted");
// get saved search
String result = cutCrudResource.getSearchesForEntity("country",null,null).getEntity().toString();
assertTrue(result.indexOf("\"matchCount\":1")!=-1);
System.out.println("result:" + result);
}
示例5: setResultSizeThresholds
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
public void setResultSizeThresholds(int maxResultSetSizeB, int warnResultSetSizeB, final QueryExpression forQuery) {
this.memoryMonitor = new MemoryMonitor<>((doc) -> {
int size = JsonUtils.size(doc.getRoot());
// account for docs copied by DocCtx.startModifications()
if (doc.getOriginalDocument() != null) {
size += JsonUtils.size(doc.getOriginalDocument().getRoot());
}
if (doc.getUpdatedDocument() != null) {
size += JsonUtils.size(doc.getUpdatedDocument().getRoot());
}
return size;
});
memoryMonitor.registerMonitor(new ThresholdMonitor<DocCtx>(maxResultSetSizeB, (current, threshold, doc) -> {
throw Error.get(MongoCrudConstants.ERROR_RESULT_SIZE_TOO_LARGE, current+"B > "+threshold+"B");
}));
memoryMonitor.registerMonitor(new ThresholdMonitor<DocCtx>(warnResultSetSizeB, (current, threshold, doc) -> {
LOGGER.warn("{}: query={}, responseDataSizeB={}", MongoCrudConstants.WARN_RESULT_SIZE_LARGE,forQuery, current);
}));
}
示例6: readPreference
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void readPreference() throws IOException {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("parse-test-datasources.json")) {
JsonNode node = JsonUtils.json(is);
MongoConfiguration metadataConfig = new MongoConfiguration();
metadataConfig.initializeFromJson(node.get("metadata_readPreference"));
MongoConfiguration dataConfig = new MongoConfiguration();
dataConfig.initializeFromJson(node.get("mongodata_readPreference"));
assertEquals(ReadPreference.nearest(), metadataConfig.getMongoClientOptions().getReadPreference());
assertEquals(ReadPreference.secondary(), dataConfig.getMongoClientOptions().getReadPreference());
assertEquals(WriteConcern.SAFE, metadataConfig.getWriteConcern());
}
}
示例7: toString
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Override
public String toString() {
JsonNodeFactory jsonNodeFactory = JsonNodeFactory.withExactBigDecimals(true);
ObjectNode objectNode = jsonNodeFactory.objectNode();
JsonNode jsonNode = keyName == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(keyName);
objectNode.set("keyName", jsonNode);
jsonNode = value == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(value.toString());
objectNode.set("value", jsonNode);
jsonNode = valueClass == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(valueClass.getCanonicalName());
objectNode.set("valueClass", jsonNode);
jsonNode = column == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(column.toString());
objectNode.set("column", jsonNode);
return JsonUtils.prettyPrint(objectNode);
}
示例8: toString
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Override
public String toString() {
JsonNodeFactory jsonNodeFactory = JsonNodeFactory.withExactBigDecimals(true);
ObjectNode objectNode = jsonNodeFactory.objectNode();
JsonNode jsonNode = jsonNodeFactory.numberNode(position);
objectNode.set("position", jsonNode);
jsonNode = name == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(name);
objectNode.set("name", jsonNode);
jsonNode = alias == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(alias);
objectNode.set("alias", jsonNode);
jsonNode = clazz == null? jsonNodeFactory.nullNode() : jsonNodeFactory.textNode(clazz);
objectNode.set("clazz", jsonNode);
jsonNode = jsonNodeFactory.numberNode(type);
objectNode.set("type", jsonNode);
jsonNode = jsonNodeFactory.booleanNode(temp);
objectNode.set("temp", jsonNode);
return JsonUtils.prettyPrint(objectNode);
}
示例9: testParse_EmptyDialect
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testParse_EmptyDialect() throws IOException{
expectedEx.expect(com.redhat.lightblue.util.Error.class);
expectedEx.expectMessage("{\"objectType\":\"error\",\"errorCode\":\""
+ RDBMSConstants.ERR_FIELD_REQUIRED
+ "\",\"msg\":\"No field informed\"}");
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{\"dialect\":\"\"}");
new RDBMSPropertyParserImpl<JsonNode>().parse(RDBMSPropertyParserImpl.NAME, p, emptyNode);
}
示例10: testConvert_WithNullValues
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testConvert_WithNullValues() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
RDBMSDataStore ds = new RDBMSDataStore(null, null);
new RDBMSDataStoreParser<JsonNode>().convert(p, emptyNode, ds);
assertNull(p.getStringProperty(emptyNode, "database"));
assertNull(p.getStringProperty(emptyNode, "datasource"));
}
示例11: parseMissingOneOfOperations
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void parseMissingOneOfOperations() throws IOException {
String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"ke\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]}}}";
Throwable error = null;
Object r = null;
try {
r = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms"));
} catch (Throwable ex) {
ex.printStackTrace();
error = ex;
} finally {
Assert.assertNull(error);
Assert.assertNotNull(r);
Assert.assertTrue(r instanceof RDBMS);
}
}
示例12: testParse_NoDialect
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testParse_NoDialect() throws IOException{
expectedEx.expect(com.redhat.lightblue.util.Error.class);
expectedEx.expectMessage("{\"objectType\":\"error\",\"errorCode\":\""
+ RDBMSConstants.ERR_FIELD_REQUIRED
+ "\",\"msg\":\"No field informed\"}");
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
new RDBMSPropertyParserImpl<JsonNode>().parse(RDBMSPropertyParserImpl.NAME, p, emptyNode);
}
示例13: testParse_NoOperation
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testParse_NoOperation() throws IOException{
expectedEx.expect(com.redhat.lightblue.util.Error.class);
expectedEx.expectMessage("{\"objectType\":\"error\",\"errorCode\":\""
+ RDBMSConstants.ERR_FIELD_REQUIRED
+ "\",\"msg\":\"No Operation informed\"}");
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{\"dialect\":\""+ DialectOperators.ORACLE + "\"}");
new RDBMSPropertyParserImpl<JsonNode>().parse(RDBMSPropertyParserImpl.NAME, p, emptyNode);
}
示例14: testConvert
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
@Test
public void testConvert() throws IOException{
String databaseName = "fakeDatabase";
String datasourceName = "fakeDatasource";
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
RDBMSDataStore ds = new RDBMSDataStore(databaseName, datasourceName);
new RDBMSDataStoreParser<JsonNode>().convert(p, emptyNode, ds);
assertEquals(databaseName, p.getStringProperty(emptyNode, "database"));
assertEquals(datasourceName, p.getStringProperty(emptyNode, "datasource"));
}
示例15: readLdapConfiguration
import com.redhat.lightblue.util.JsonUtils; //导入依赖的package包/类
private static JsonNode readLdapConfiguration() throws IOException {
JsonNode root = null;
try (InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(LdapConfiguration.FILENAME)) {
if (null == is) {
throw new FileNotFoundException(LdapConfiguration.FILENAME);
}
root = JsonUtils.json(is, true);
}
return root;
}