if (!object.has(TYPE) || !object.get(TYPE).isTextual() || !object.get(TYPE).getTextValue().equals("record")) { throw new IllegalArgumentException("The data provided is not a record!"); if (!object.has(NAMESPACE) || !object.get(NAMESPACE).isTextual()) { throw new IllegalArgumentException("No namespace specified!"); } else if (!object.has(NAME) || !object.get(NAME).isTextual()) { throw new IllegalArgumentException("No name specified!"); } else { schema.setMetaInfo(metaInfo); if (!object.has(VERSION) || !object.get(VERSION).isInt()) { object.put(VERSION, 1); if (!object.has(DEPENDENCIES)) { schema.setDependencySet(dependencies); } else if (!object.get(DEPENDENCIES).isArray()) {
@Override public boolean has(String key) { return wrapped.has(key); }
@Override public boolean has(String key) { return wrapped.has(key); }
@Override public boolean hasField(String fieldName) { return getNode().has(fieldName); }
private String determinePostType(ObjectNode node) { if (node.has("type")) { try { String type = node.get("type").getTextValue(); PostType.valueOf(type.toUpperCase()); return type; } catch (IllegalArgumentException e) { return "post"; } } return "post"; }
@Override public boolean hasFieldProperty(String fieldName, String propertyName) { FieldProperty property = FieldProperty.fromQueryName(propertyName); CheckConditions.checkNotNull(property, "Can not find field property %s!", propertyName); String propertyFullName = fieldName + PROPERTY_CONNECTOR + propertyName; return getNode().has(propertyFullName); }
@Override public PosTag parse(ObjectNode jValue, AnalysedText at) { PosTagInfo tagInfo = new PosTagInfo(); JsonNode tag = jValue.path("tag"); if(!tag.isTextual()){ throw new IllegalStateException("Unable to parse PosTag. The value of the " +"'tag' field MUST have a textual value (json: "+jValue+")"); } tagInfo.tag = tag.getTextValue(); if(jValue.has("lc")){ tagInfo.categories = JsonUtils.parseEnum(jValue, "lc",LexicalCategory.class); } else { tagInfo.categories = EnumSet.noneOf(LexicalCategory.class); } if(jValue.has("pos")){ tagInfo.pos = JsonUtils.parseEnum(jValue, "pos", Pos.class); } else { tagInfo.pos = EnumSet.noneOf(Pos.class); } PosTag posTag = posTagCache.get(tagInfo); if(posTag == null){ posTag = new PosTag(tagInfo.tag,tagInfo.categories,tagInfo.pos); posTagCache.put(tagInfo, posTag); } return posTag; }
@Override public PosTag parse(ObjectNode jValue, AnalysedText at) { PosTagInfo tagInfo = new PosTagInfo(); JsonNode tag = jValue.path("tag"); if(!tag.isTextual()){ throw new IllegalStateException("Unable to parse PosTag. The value of the " +"'tag' field MUST have a textual value (json: "+jValue+")"); } tagInfo.tag = tag.getTextValue(); if(jValue.has("lc")){ tagInfo.categories = JsonUtils.parseEnum(jValue, "lc",LexicalCategory.class); } else { tagInfo.categories = EnumSet.noneOf(LexicalCategory.class); } if(jValue.has("pos")){ tagInfo.pos = JsonUtils.parseEnum(jValue, "pos", Pos.class); } else { tagInfo.pos = EnumSet.noneOf(Pos.class); } PosTag posTag = posTagCache.get(tagInfo); if(posTag == null){ posTag = new PosTag(tagInfo.tag,tagInfo.categories,tagInfo.pos); posTagCache.put(tagInfo, posTag); } return posTag; }
public boolean mapHas(final String key) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } ObjectNode node = asObjectNode(); final String[] paths = key.split("\\."); for (int i = 0; i < paths.length; i++) { final String path = paths[i]; final boolean has = node.has(path); if (!has) { return false; } if (i + 1 < paths.length) { // not on last final JsonNode subNode = node.get(path); if (!subNode.isObject()) { return false; } node = (ObjectNode) subNode; } } return true; }
public boolean mapHas(final String key) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } ObjectNode node = asObjectNode(); final String[] paths = key.split("\\."); for (int i = 0; i < paths.length; i++) { final String path = paths[i]; final boolean has = node.has(path); if (!has) { return false; } if (i + 1 < paths.length) { // not on last final JsonNode subNode = node.get(path); if (!subNode.isObject()) { return false; } node = (ObjectNode) subNode; } } return true; }
new IndexerDefinitionBuilder().startFrom(oldIndexer)).build(); IndexerDefinition.LifecycleState lifecycleState = json.has("lifecycleState") ? IndexerDefinition.LifecycleState.valueOf(json.get("lifecycleState").getTextValue()) : null;
new IndexerDefinitionBuilder().startFrom(oldIndexer)).build(); IndexerDefinition.LifecycleState lifecycleState = json.has("lifecycleState") ? IndexerDefinition.LifecycleState.valueOf(json.get("lifecycleState").getTextValue()) : null;
@Test public void testProject06() { // case 0 : aggregation String query = "NetworkAddress<@healthState>{@healthState, $max(@address), $count()}"; cmsdbContext.setAllowFullTableScan(true); cmsdbContext.setShowDisplayMeta(true); IQueryResult result = queryService.query(query, cmsdbContext); ArrayNode display = result.getDisplayMeta(); ObjectNode na = (ObjectNode) display.get(0).get("fields"); Assert.assertEquals(5, na.size()); Assert.assertTrue(na.has("healthState")); Assert.assertTrue(na.has("$count")); Assert.assertTrue(na.has("$max_address")); }
@Test public void testQueryExplanation_typeCast2() { String query = "ResourceGroup.<ResourceGroup>children{*}"; QueryContext qc = newQueryContext(CMSDB_REPO, IBranch.DEFAULT_BRANCH); qc.setAllowFullTableScan(true); qc.setExplain(true); IQueryResult queryResult = queryService.query(query, qc); Assert.assertNotNull(queryResult.getExplanations()); List<IQueryExplanation> explans = queryResult.getExplanations(); Assert.assertEquals(3, explans.size()); // first two is search explanation, the last one is the join explanation ObjectNode objectNode = (ObjectNode) explans.get(0).getJsonExplanation(); String queryType0 = objectNode.get("criteria").get("$and").get(0).get("_t").getTextValue(); Assert.assertTrue(queryType0.equals("ResourceGroup")); Assert.assertTrue(objectNode.has("usedTime")); Assert.assertTrue(objectNode.has("limit")); Assert.assertTrue(objectNode.has("sort")); objectNode = (ObjectNode) explans.get(1).getJsonExplanation(); String queryType1 = objectNode.get("criteria").get("$and").get(0).get("_t").getTextValue(); Assert.assertTrue(queryType1.equals("ResourceGroup")); }
@Test public void testAggregationQuery_noFullTableScan() { String query = "Rack[@_oid=\"5199c9450cf2359a4ea29a62\"].assets<@resourceId>.asset!AssetServer"; cmsdbContext.setAllowFullTableScan(false); cmsdbContext.setExplain(true); IQueryResult result = queryService.query(query, cmsdbContext); Assert.assertEquals(6, result.getEntities().size()); List<IQueryExplanation> queryExplanation = result.getExplanations(); JsonNode explainNode = queryExplanation.get(2).getJsonExplanation(); Assert.assertEquals("AssetServer", explainNode.get("criteria").get("$and").get(0).get("_t").getTextValue()); JsonNode refereInNode = explainNode.get("criteria").get("$and").get(2); Assert.assertNotNull(refereInNode); // FIXME: flatten will have different explanation if (cmsdbContext.getRegistration().registrationId.equals("hierarchy")) { String dbValueName = cmsdbMetaService.getMetaClass("AssetServer").getFieldByName("asset").getValueDbName() + "._i"; Assert.assertTrue(((ObjectNode) refereInNode).has(dbValueName)); } }
@Test public void testFieldProperty() { raptorContext.setAllowFullTableScan(true); String query = "ServiceInstance{@runsOn, @runsOn.$_lastmodified}"; IQueryResult result = queryService.query(query, raptorContext); Assert.assertEquals(12, result.getEntities().size()); int noRunsOnCount = 0; for (IEntity serv : result.getEntities()) { if (!serv.hasField("runsOn")) { noRunsOnCount++; } else { Assert.assertTrue(((JsonEntity) serv).getNode().has("runsOn")); Assert.assertTrue(((JsonEntity) serv).getNode().has("runsOn._lastmodified")); } } Assert.assertEquals(1, noRunsOnCount); }
/** * CMS 3617 :: */ @Test @SuppressWarnings("unchecked") public void testLeftReverse() { cmsdbContext.setAllowFullTableScan(true); String query = "Rack{*}+.assets[@assetType=\"Server\"]{@resourceId,@assetType,@healthState,@healthState,@_lastmodified,@manufacturer,@locationCode}.asset!AssetServer{@resourceId}"; IQueryResult result = queryService.query(query, cmsdbContext); Assert.assertEquals(1, result.getEntities().size()); IEntity rack = result.getEntities().get(0); List<JsonEntity> assets = (List<JsonEntity>) rack.getFieldValues("assets"); Assert.assertEquals(7, assets.size()); int assetWihtoutAssetServerCount = 0; int assetWithAssetServerCount = 0; for (JsonEntity asset : assets) { if (!asset.getNode().has("asset!AssetServer")) { assetWihtoutAssetServerCount++; } else { assetWithAssetServerCount++; } } Assert.assertEquals(1, assetWihtoutAssetServerCount); Assert.assertEquals(assets.size() - assetWihtoutAssetServerCount, assetWithAssetServerCount); }
if (node.has("valueType") && node.get("valueType").isObject() && node.get("valueType").has("primitive")) { throw new JsonFormatException("Lily 1.1 format change: the valueType should now be specified as a string" + " rather than a nested object with the 'primitive' property.");
public JsonNode toJson() throws LeanException { ObjectNode json = JsonUtils.getObjectMapper().createObjectNode(); json.put("kind", kind); if (!filters.isEmpty()) { ObjectNode jsonFilters = JsonUtils.getObjectMapper().createObjectNode(); for (QueryFilter filter : filters) { ObjectNode jsonFilter; if (jsonFilters.has(filter.getProperty())) { jsonFilter = (ObjectNode) jsonFilters.get(filter.getProperty()); } else { jsonFilter = JsonUtils.getObjectMapper().createObjectNode(); } JsonUtils.addTypedNode(jsonFilter, filter.getOperator().toJSON(), filter.getValue()); jsonFilters.put(filter.getProperty(), jsonFilter); } json.put("filter", jsonFilters); } if (!sorts.isEmpty()) { ObjectNode jsonSorts = JsonUtils.getObjectMapper().createObjectNode(); for (QuerySort sort : sorts) { jsonSorts.put(sort.getProperty(), sort.getDirection().toJSON()); } json.put("sort", jsonSorts); } if (this.cursor != null) { json.put("cursor", cursor.toWebSafeString()); } return json; }
for (final QueryClause clause : clauses) { if (clause instanceof BasicQueryClause) { if (!twig.has(ChildPropertyParser.CHILD_PROPERTY)) { // avoid to create an empty array in the JSON childArray = twig.putArray(ChildPropertyParser.CHILD_PROPERTY); if (!twig.has(DescendantPropertyParser.DESCENDANT_PROPERTY)) { // avoid to create an empty array in the JSON descendantArray = twig.putArray(DescendantPropertyParser.DESCENDANT_PROPERTY);