Java Code Examples for org.codehaus.jackson.node.ObjectNode#put()

The following examples show how to use org.codehaus.jackson.node.ObjectNode#put() . 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: JobHistoryEventHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Private
public JsonNode countersToJSON(Counters counters) {
  ObjectMapper mapper = new ObjectMapper();
  ArrayNode nodes = mapper.createArrayNode();
  if (counters != null) {
    for (CounterGroup counterGroup : counters) {
      ObjectNode groupNode = nodes.addObject();
      groupNode.put("NAME", counterGroup.getName());
      groupNode.put("DISPLAY_NAME", counterGroup.getDisplayName());
      ArrayNode countersNode = groupNode.putArray("COUNTERS");
      for (Counter counter : counterGroup) {
        ObjectNode counterNode = countersNode.addObject();
        counterNode.put("NAME", counter.getName());
        counterNode.put("DISPLAY_NAME", counter.getDisplayName());
        counterNode.put("VALUE", counter.getValue());
      }
    }
  }
  return nodes;
}
 
Example 2
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Override
public void exitUriShuffleCommand(UriShuffleCommandContext ctx)
{
    ObjectNode paramsNode = objMapper.createObjectNode();
    if (ctx.params() != null)
    {
        for (int i = 0; i < ctx.params().keyval().size(); i++)
        {
            List<TerminalNode> kv = ctx.params().keyval(i).STRING();
            paramsNode.put(CommonUtils.stripQuotes(kv.get(0).getText()),
                           CommonUtils.stripQuotes(kv.get(1).getText()));
        }
    }

    shuffleCommandNode = JsonUtils.createObjectNode("type", ctx.uri().getText(),
                                                    "name", ctx.ID().getText(),
                                                    "args", paramsNode);

    addLine(ctx, shuffleCommandNode);
}
 
Example 3
Source File: StencilsetServiceImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化分配策略
 * @param rootNode
 */
private void initAssigneeType(JsonNode rootNode){
	ArrayNode baseNodeArray = (ArrayNode)rootNode.get("propertyPackages");
       JsonNode taskAssignBase = JsonConverterUtil.getChildElementByProperty("taskassignbase", "name", baseNodeArray);
       taskAssignBase = taskAssignBase.get("properties");
       JsonNode assigneeType = JsonConverterUtil.getChildElementByProperty("assignpolicytype", "id", (ArrayNode)taskAssignBase);
       ArrayNode arrayNode = objectMapper.createArrayNode();
       
       
       AssignPolicyConfig assignPolicyConfig = ProcessEngineManagement.getDefaultProcessEngine().getProcessEngineConfiguration().getAssignPolicyConfig();
       List<AssignPolicy> assignPolicys = assignPolicyConfig.getAssignPolicy();
       for(AssignPolicy assignPolicy :assignPolicys){
       	 ObjectNode typeNode = objectMapper.createObjectNode();
   		 typeNode.put("id",assignPolicy.getId());
            typeNode.put("title", assignPolicy.getName());
            typeNode.put("value", assignPolicy.getId());
            arrayNode.add(typeNode);
       }
       ((ObjectNode)assigneeType).put("items", arrayNode);
}
 
Example 4
Source File: ClusterResource.java    From exhibitor with Apache License 2.0 6 votes vote down vote up
@Path("list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String   getClusterAsJson() throws Exception
{
    InstanceConfig      config = context.getExhibitor().getConfigManager().getConfig();

    ObjectNode          node = JsonNodeFactory.instance.objectNode();

    ArrayNode           serversNode = JsonNodeFactory.instance.arrayNode();
    ServerList          serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    for ( ServerSpec spec : serverList.getSpecs() )
    {
        serversNode.add(spec.getHostname());
    }
    node.put("servers", serversNode);
    node.put("port", config.getInt(IntConfigs.CLIENT_PORT));

    return JsonUtil.writeValueAsString(node);
}
 
Example 5
Source File: BoundaryEventJsonConverter.java    From fixflow with Apache License 2.0 6 votes vote down vote up
protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  
  
  BPMNShape graphicInfo = BpmnModelUtil.getBpmnShape(model, boundaryEvent.getId());;
  BPMNShape parentGraphicInfo = BpmnModelUtil.getBpmnShape(model,boundaryEvent.getAttachedToRef().getId());
  dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getBounds().getX() + graphicInfo.getBounds().getWidth() - parentGraphicInfo.getBounds().getX());
  dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getBounds().getY() - parentGraphicInfo.getBounds().getY());
  dockersArrayNode.add(dockNode);
  flowElementNode.put("dockers", dockersArrayNode);
  
  if (boundaryEvent.isCancelActivity() == false) {
    propertiesNode.put(PROPERTY_CANCEL_ACTIVITY, PROPERTY_VALUE_NO);
  }
  
  addEventProperties(boundaryEvent, propertiesNode);
}
 
Example 6
Source File: WorkflowAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
private void getWorkflowConfigNode(ObjectNode workflowConfigNode, ZNRecord record) {
  for (Map.Entry<String, String> entry : record.getSimpleFields().entrySet()) {
    if (!entry.getKey().equals(WorkflowConfig.WorkflowConfigProperty.Dag)) {
      workflowConfigNode.put(entry.getKey(), JsonNodeFactory.instance.textNode(entry.getValue()));
    }
  }
}
 
Example 7
Source File: JsonResponseUtil.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static ObjectNode buildResponseJSON(Object obj) {
  ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
  rootNode.put("Result", "OK");
  JsonNode node = MAPPER.convertValue(obj, JsonNode.class);
  rootNode.put("Record", node);
  return rootNode;
}
 
Example 8
Source File: AggregateRewriter.java    From Cubert with Apache License 2.0 5 votes vote down vote up
private ArrayList<ObjectNode> rewriteMeasureJoins(ObjectNode programNode,
                                                  ObjectNode cubeOperatorNode,
                                                  String combinedRelationName,
                                                  List<ObjectNode> measureJoins,
                                                  ObjectNode factNode)
{
    ArrayList<ObjectNode> newMeasureJoins = new ArrayList<ObjectNode>();
    String[] newInputs;

    int inputIndex = 0;
    for (ObjectNode measureJoin : measureJoins)
    {
        ObjectNode newJoin = (ObjectNode) (measureJoin);
        String replacedInput = null;
        newInputs = JsonUtils.asArray(measureJoin.get("input"));
        int replacedInputIndex =
                lineage.getDescendantInputIndex(newInputs, measureJoin, factNode);
        replacedInput = newInputs[replacedInputIndex];
        newInputs[replacedInputIndex] = combinedRelationName;

        System.out.println(String.format("Replaced join-input %s with %s",
                                         replacedInput,
                                         combinedRelationName));
        newJoin.put("input", JsonUtils.createArrayNode(newInputs));
        if (newJoin.get("leftBlock").equals(replacedInput))
            newJoin.put("leftBlock", combinedRelationName);
        else
            newJoin.put("rightBlock", combinedRelationName);

        newMeasureJoins.add(newJoin);
    }

    return newMeasureJoins;
}
 
Example 9
Source File: IndexerResource.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
/**
 * Get a single index configuration (as stored in zookeeper).
 */
@GET
@Path("{name}/config")
@Produces("application/json")
public Response getConfig(@PathParam("name") String name) throws IndexerNotFoundException, IOException {
    IndexerDefinition index = getModel().getIndexer(name);

    ObjectMapper m = new ObjectMapper();
    ObjectNode json = m.createObjectNode();
    json.put("occVersion", index.getOccVersion());
    json.put("config", new String(index.getConfiguration(), Charsets.UTF_8));

    return Response.ok(m.writeValueAsString(json), new MediaType("application", "json")).build();
}
 
Example 10
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testHashJoin2() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 2 }, { 2 }, { 5 }, { 10 } };
    Object[][] rows2 = { { 1 }, { 7 }, { 9 } };
    Object[][] expected = {};

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] { "a" });
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] { "a" });

    TupleOperator operator = new HashJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("leftJoinKeys", "a");
    node.put("rightJoinKeys", "a");
    node.put("leftBlock", "block1");

    BlockProperties props =
            new BlockProperties(null,
                                new BlockSchema("INT block1___a, INT block2___a"),
                                (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] { "block1.a", "block2.a" });
}
 
Example 11
Source File: GenreTO.java    From big-data-lite with MIT License 5 votes vote down vote up
public ObjectNode getGenreJson() {
    objectNode = new ObjectNode(factory);

    objectNode.put(JsonConstant.ID, this.getId());
    objectNode.put(JsonConstant.NAME, this.getName());

    return objectNode;
}
 
Example 12
Source File: MetadataResource.java    From Eagle with Apache License 2.0 5 votes vote down vote up
private void addTo( ObjectNode resourceNode, String uriPrefix, AbstractResourceMethod srm, String path ){
	if(resourceNode.get( uriPrefix ) == null){
		ObjectNode inner = JsonNodeFactory.instance.objectNode();
		inner.put("path", path);
		inner.put("methods", JsonNodeFactory.instance.arrayNode());
		resourceNode.put( uriPrefix, inner );
	}

	((ArrayNode) resourceNode.get( uriPrefix ).get("methods")).add( srm.getHttpMethod() );
}
 
Example 13
Source File: PropertyStoreAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Sample HTTP URLs:
 *  http://<HOST>/clusters/{clusterId}/propertyStore/<PATH>
 * It refers to the /PROPERTYSTORE/<PATH> in Helix metadata store
 * @param clusterId The cluster Id
 * @param path path parameter is like "abc/abc/abc" in the URL
 * @return If the payload is ZNRecord format, return ZnRecord json response;
 *         Otherwise, return json object {<PATH>: raw string}
 */
@GET
@Path("{path: .+}")
public Response getPropertyByPath(@PathParam("clusterId") String clusterId,
    @PathParam("path") String path) {
  path = "/" + path;
  if (!ZkValidationUtil.isPathValid(path)) {
    LOG.info("The propertyStore path {} is invalid for cluster {}", path, clusterId);
    return badRequest(
        "Invalid path string. Valid path strings use slash as the directory separator and names the location of ZNode");
  }
  final String recordPath = PropertyPathBuilder.propertyStore(clusterId) + path;
  BaseDataAccessor<byte[]> propertyStoreDataAccessor = getByteArrayDataAccessor();
  if (propertyStoreDataAccessor.exists(recordPath, AccessOption.PERSISTENT)) {
    byte[] bytes = propertyStoreDataAccessor.get(recordPath, null, AccessOption.PERSISTENT);
    ZNRecord znRecord = (ZNRecord) ZN_RECORD_SERIALIZER.deserialize(bytes);
    // The ZNRecordSerializer returns null when exception occurs in deserialization method
    if (znRecord == null) {
      ObjectNode jsonNode = OBJECT_MAPPER.createObjectNode();
      jsonNode.put(CONTENT_KEY, new String(bytes));
      return JSONRepresentation(jsonNode);
    }
    return JSONRepresentation(znRecord);
  } else {
    throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
        .entity(String.format("The property store path %s doesn't exist", recordPath)).build());
  }
}
 
Example 14
Source File: BpmnJsonConverterUtil.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public static ObjectNode createChildShape(String id, String type, double lowerRightX, double lowerRightY, double upperLeftX, double upperLeftY) {
  ObjectNode shapeNode = objectMapper.createObjectNode();
  shapeNode.put(EDITOR_BOUNDS, createBoundsNode(lowerRightX, lowerRightY, upperLeftX, upperLeftY));
  shapeNode.put(EDITOR_SHAPE_ID, id);
  ArrayNode shapesArrayNode = objectMapper.createArrayNode();
  shapeNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
  ObjectNode stencilNode = objectMapper.createObjectNode();
  stencilNode.put(EDITOR_STENCIL_ID, type);
  shapeNode.put(EDITOR_STENCIL, stencilNode);
  return shapeNode;
}
 
Example 15
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testMergeJoin3() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 0 }, { 2 }, { 2 }, { 5 }, { 10 } };
    Object[][] rows2 = { { 1 }, { 2 }, { 2 }, { 7 }, { 9 } };
    Object[][] expected = { { 2, 2 }, { 2, 2 }, { 2, 2 }, { 2, 2 } };

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] { "a" });
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] { "a" });

    TupleOperator operator = new MergeJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("leftCubeColumns", "a");
    node.put("rightCubeColumns", "a");
    node.put("leftBlock", "block1");

    BlockProperties props =
            new BlockProperties(null,
                                new BlockSchema("INT block1___a, INT block2___a"),
                                (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] { "block1.a", "block2.a" });
}
 
Example 16
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Override
public void exitInputCommand(@NotNull InputCommandContext ctx)
{
    ObjectNode inputNode = objMapper.createObjectNode();
    addLine(ctx, inputNode);

    inputNode.put("name", ctx.ID().get(0).getText());

    if (ctx.format != null)
        inputNode.put("type", ctx.format.getText().toUpperCase());
    else
        inputNode.put("type", ctx.classname.getText());

    ObjectNode paramsNode = objMapper.createObjectNode();
    if (ctx.params() != null)
    {

        for (int i = 0; i < ctx.params().keyval().size(); i++)
        {
            List<TerminalNode> kv = ctx.params().keyval(i).STRING();
            paramsNode.put(CommonUtils.stripQuotes(kv.get(0).getText()),
                           CommonUtils.stripQuotes(kv.get(1).getText()));
        }
    }
    inputNode.put("params", paramsNode);

    ArrayNode inputPathArray = createInputPathsNode(ctx.inputPaths());
    inputNode.put("path", inputPathArray);

    this.mapCommandsNode.put("input", inputNode);

}
 
Example 17
Source File: BaseBpmnJsonConverter.java    From fixflow with Apache License 2.0 4 votes vote down vote up
protected void setPropertyValue(String name, String value, ObjectNode propertiesNode) {
  if (StringUtils.isNotEmpty(value)) {
  	propertiesNode.put(name, value);
  }
}
 
Example 18
Source File: TestOperators.java    From Cubert with Apache License 2.0 4 votes vote down vote up
@Test
// testing multiple join keys
public void testMergeJoinMultipleJoinKeys() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 =
            { { 0, 1 }, { 2, 1 }, { 2, 2 }, { 5, 1 }, { 10, 1 }, { 100, 1 } };
    Object[][] rows2 =
            { { 1, 1 }, { 2, 0 }, { 2, 1 }, { 5, 1 }, { 100, 2 }, { 100, 3 } };
    Object[][] expected = { { 2, 1, 2, 1 }, { 5, 1, 5, 1 } };

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] { "a", "b" });
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] { "c", "a" });

    TupleOperator operator = new MergeJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    ArrayNode lkeys = mapper.createArrayNode();
    lkeys.add("a");
    lkeys.add("b");
    node.put("leftCubeColumns", lkeys);
    ArrayNode rkeys = mapper.createArrayNode();
    rkeys.add("c");
    rkeys.add("a");
    node.put("rightCubeColumns", rkeys);
    node.put("leftBlock", "block1");

    BlockProperties props =
            new BlockProperties(null,
                                new BlockSchema("INT block1___a, INT block1___b, INT block2___c, INT block2___a"),
                                (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] { "block1.a", "block2.a" });
}
 
Example 19
Source File: AggregateRewriter.java    From Cubert with Apache License 2.0 4 votes vote down vote up
public void injectRewrite(ObjectNode programNode,
                          ObjectNode jobNode,
                          JsonNode phaseNode,
                          ObjectNode cubeOperatorNode,
                          String mvName,
                          String mvPath) throws AggregateRewriteException,
        IOException
{
    this.programNode = programNode;
    this.cubeJobNode = jobNode;
    this.cubePhaseNode = phaseNode;
    this.cubeOperatorNode = cubeOperatorNode;
    this.mvName = mvName;
    this.mvPath = mvPath;

    try
    {
        this.lineage.buildLineage(programNode);
    }
    catch (LineageException e)
    {
        throw new AggregateRewriteException(e.toString());
    }

    readSummaryMetaData();

    String[] measures = getMeasureColumns(cubeOperatorNode);
    String[] dimensions = getDimensionColumns(cubeOperatorNode);

    System.out.println("Measure columns = " + Arrays.toString(measures)
            + " Dimensions=" + Arrays.toString(dimensions));
    traceFactLoads(measures);
    traceFactBlockgens();
    calculateIncrementalFactLoadDates();
    rewriteFactBlockgenPaths();
    // Perform any pre-blockgen xforms needed on the fact.
    transformFactPreBlockgen(programNode, bgInfo);
    createMVBlockgen(dimensions, measures);
    insertPreCubeCombine((String[]) (ArrayUtils.addAll(dimensions, measures)));
    incrementalizeFactLoads();
    insertMVRefreshDateJobHook();
    rewritePreCubeMeasureJoins();
    programNode.put("summaryRewrite", "true");
}
 
Example 20
Source File: ShuffleRewriter.java    From Cubert with Apache License 2.0 4 votes vote down vote up
private void copyLine(ObjectNode from, ObjectNode to, String prefix)
{
    if (from.has("line"))
        to.put("line", prefix + getText(from, "line"));
}