Java Code Examples for com.fasterxml.jackson.databind.node.ArrayNode#removeAll()
The following examples show how to use
com.fasterxml.jackson.databind.node.ArrayNode#removeAll() .
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: GeoPointTransformator.java From SkaETL with Apache License 2.0 | 6 votes |
public void apply(String idProcess, ParameterTransformation parameterTransformation, ObjectNode jsonValue) { if (has(parameterTransformation.getKeyField(),jsonValue)) { JsonNode jsonNode = at(parameterTransformation.getKeyField(), jsonValue); //GeoJSON spec :) if (jsonNode.isArray() && parameterTransformation.isFormatGeoJson()) { JsonNode latitude= jsonNode.get(0); JsonNode longitude =jsonNode.get(1); ArrayNode arrayNode = (ArrayNode) jsonNode; arrayNode.removeAll(); arrayNode.add(longitude); arrayNode.add(latitude); } put(jsonValue, parameterTransformation.getKeyField() + "_gp", jsonNode); remove(jsonValue,parameterTransformation.getKeyField()); } }
Example 2
Source File: AbstractIndexer.java From samantha with MIT License | 6 votes |
public void index(RequestContext requestContext) { JsonNode reqBody = requestContext.getRequestBody(); EntityDAO entityDAO = EntityDAOUtilities.getEntityDAO(daoConfigs, requestContext, reqBody.get(daoConfigKey), injector); ArrayNode toIndex = Json.newArray(); ExpandedEntityDAO expandedEntityDAO = new ExpandedEntityDAO(expanders, entityDAO, requestContext); while (expandedEntityDAO.hasNextEntity()) { toIndex.add(expandedEntityDAO.getNextEntity()); if (toIndex.size() >= batchSize) { index(toIndex, requestContext); notifyDataSubscribers(toIndex, requestContext); toIndex.removeAll(); } } if (toIndex.size() > 0) { index(toIndex, requestContext); notifyDataSubscribers(toIndex, requestContext); } expandedEntityDAO.close(); entityDAO.close(); }
Example 3
Source File: LargeTextNodeRemover.java From foxtrot with Apache License 2.0 | 6 votes |
private void handleArrayNode(final String table, final String documentId, final String parentKey, ArrayNode arrayNode) { if (arrayNode == null || arrayNode.isNull()) { return; } ArrayNode copy = objectMapper.createArrayNode(); arrayNode.elements() .forEachRemaining(node -> { boolean copyNode = true; if (node.isObject()) { handleObjectNode(table, documentId, (ObjectNode) node); } else if (node.isArray()) { handleArrayNode(table, documentId, parentKey, (ArrayNode) node); } else if (node.isTextual()) { copyNode = !evaluateForRemoval(table, documentId, parentKey, node); } if (copyNode) { copy.add(node); } }); arrayNode.removeAll(); arrayNode.addAll(copy); }
Example 4
Source File: APIAuthenticationPropertyHandler.java From apimanager-swagger-promote with Apache License 2.0 | 5 votes |
public JsonNode handleProperty(IAPI desired, IAPI actual, JsonNode response) throws AppException { preProcessAuthenticationProfiles(desired); ArrayNode devices = (ArrayNode) ((ArrayNode) response.findPath("securityProfiles")).get(0).get("devices"); // We put all security devices from the desired state into the request devices.removeAll(); //devices.addAll((ArrayNode)desired.getAuthentication().getJsonConfig()); return response; }
Example 5
Source File: JsonFilterReader.java From knox with Apache License 2.0 | 5 votes |
private void processValueString() throws IOException { Level child; Level parent; String value = null; if(stack.isEmpty()) { generator.writeString( parser.getText() ); return; } parent = stack.peek(); if( parent.isArray() ) { ArrayNode array = (ArrayNode)parent.node; array.add( parser.getText() ); if( bufferingLevel == null ) { value = filterStreamValue( parent ); array.set( array.size()-1, new TextNode( value ) ); } else { array.removeAll(); } } else { child = stack.pop(); parent = stack.peek(); ((ObjectNode)parent.node ).put( child.field, parser.getText() ); if( bufferingLevel == null ) { child.node = parent.node; // Populate the JsonNode of the child for filtering. value = filterStreamValue( child ); } } if( bufferingLevel == null ) { if( parent.node.isArray() ) { ((ArrayNode)parent.node).removeAll(); } else { ((ObjectNode)parent.node).removeAll(); } generator.writeString( value ); } }
Example 6
Source File: TensorFlowBatchIndexerTest.java From samantha with MIT License | 4 votes |
@Test public void testTensorFlowBatchIndex() { SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class); MockIndexer mockIndexer = new MockIndexer( config, configService, injector, "daoConfig", config); SpaceProducer spaceProducer = injector.instanceOf(SpaceProducer.class); List<FeatureExtractor> featureExtractors = new ArrayList<>(); FeatureExtractor itemExtractor = new SeparatedStringExtractor( "ITEM", "item", "item", "\\|", false, null, null ); featureExtractors.add(itemExtractor); FeatureExtractor attrExtractor = new SeparatedStringExtractor( "ATTR", "attr", "attr", "\\|", false, "null", null ); featureExtractors.add(attrExtractor); FeatureExtractor sizeExtractor = new SeparatedStringSizeExtractor( "SEQ_LEN", "item", "sequence_length", "|", null ); featureExtractors.add(sizeExtractor); TensorFlowModel model = new TensorFlowModelProducer(spaceProducer) .createTensorFlowModelModelFromGraphDef( "name", SpaceMode.DEFAULT, "shouldNotExist.graph", null, new ArrayList<>(), null, Lists.newArrayList("ITEM", "ATTR", "SEQ_LEN"), featureExtractors, "loss", "update", "output", "init", "top_k", "topKId", "topKValue", "ITEM"); TensorFlowBatchIndexer batchIndexer = new TensorFlowBatchIndexer( configService, config, injector, config, "daoConfig", mockIndexer, model, 1, "tstamp"); ArrayNode batch = Json.newArray(); ObjectNode user1 = Json.newObject(); user1.put("item", "20|49|10|2|4"); user1.put("attr", "jid|cjk|je|je|cjk"); batch.add(user1); ObjectNode user2 = Json.newObject(); user2.put("item", "14|19|2|5|20|15|2"); user2.put("attr", "cjk|mn|je|lk|jid|null|je"); batch.add(user2); RequestContext requestContext = new RequestContext(Json.newObject(), "test"); batchIndexer.index(batch, requestContext); ArrayNode indexed = mockIndexer.getIndexed(); assertEquals("1,2,3,4,5,6,7,4,8,1,9,4", indexed.get(0).get("item_idx").asText()); assertEquals("1,2,3,3,2,2,4,3,5,1,6,3", indexed.get(0).get("attr_idx").asText()); assertEquals("5.0,7.0", indexed.get(0).get("sequence_length_val").asText()); batch.removeAll(); indexed.removeAll(); ObjectNode item1 = Json.newObject(); item1.put("item", "20"); item1.put("attr", "jid"); batch.add(item1); ObjectNode item2 = Json.newObject(); item2.put("item", "15"); batch.add(item2); ObjectNode item3 = Json.newObject(); item3.put("item", "40"); item3.put("attr", "cjk"); batch.add(item3); ObjectNode item4 = Json.newObject(); item4.put("item", "41"); item4.put("attr", "djkfds"); batch.add(item4); batchIndexer.index(batch, requestContext); assertEquals("1,9,10,11", indexed.get(0).get("item_idx").asText()); assertEquals("1,6,2,7", indexed.get(0).get("attr_idx").asText()); }
Example 7
Source File: AdminConfigFile.java From glowroot with Apache License 2.0 | 4 votes |
private static void upgradeRolesIfNeeded(ObjectNode adminRootObjectNode) { // upgrade from 0.9.1 to 0.9.2 JsonNode rolesNode = adminRootObjectNode.get("roles"); if (rolesNode == null || !rolesNode.isArray()) { return; } for (JsonNode roleNode : rolesNode) { JsonNode permissionsNode = roleNode.get("permissions"); if (permissionsNode == null || !permissionsNode.isArray()) { continue; } List<String> permissions = Lists.newArrayList(); ArrayNode permissionsArrayNode = (ArrayNode) permissionsNode; for (int i = 0; i < permissionsArrayNode.size(); i++) { JsonNode permissionNode = permissionsArrayNode.get(i); if (!permissionNode.isTextual()) { continue; } permissions.add(permissionNode.asText()); } boolean upgraded = PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(permissions); if (upgraded && permissions.contains("admin:view") && permissions.contains("admin:edit")) { // only apply these updates if upgrading from 0.9.1 to 0.9.2 permissions.remove("admin:view"); permissions.remove("admin:edit"); permissions.add("admin"); } // upgrade from 0.9.19 to 0.9.20 update(permissions, "agent:alert", "agent:incident"); // upgrade from 0.10.12 to 0.11.0 update(permissions, "agent:transaction:profile", "agent:transaction:threadProfile"); update(permissions, "agent:config:edit:gauge", "agent:config:edit:gauges"); update(permissions, "agent:config:edit:syntheticMonitor", "agent:config:edit:syntheticMonitors"); update(permissions, "agent:config:edit:alert", "agent:config:edit:alerts"); update(permissions, "agent:config:edit:plugin", "agent:config:edit:plugins"); update(permissions, "agent:config:edit:ui", "agent:config:edit:uiDefaults"); permissionsArrayNode.removeAll(); for (String permission : permissions) { permissionsArrayNode.add(new TextNode(permission)); } } }