private String lookForAttachedRef(String boundaryEventId, JsonNode childShapesNode) {
    String attachedRefId = null;

    if (childShapesNode != null) {

      for (JsonNode childNode : childShapesNode) {
        ArrayNode outgoingNode = (ArrayNode) childNode.get("outgoing");
        if (outgoingNode != null && outgoingNode.size() > 0) {
          for (JsonNode outgoingChildNode : outgoingNode) {
            JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID);
            if (resourceNode != null && boundaryEventId.equals(resourceNode.asText())) {
              attachedRefId = childNode.get(EDITOR_SHAPE_ID).asText();
              break;
            }
          }

          if (attachedRefId != null) {
            break;
          }
        }

        attachedRefId = lookForAttachedRef(boundaryEventId, childNode.get(EDITOR_CHILD_SHAPES));

        if (attachedRefId != null) {
          break;
        }
      }
    }

    return attachedRefId;
  }
Esempio n. 2
0
  ObjectNode createNamespaceNode(ArrayNode container) {
    ObjectNode ns = container.objectNode();
    ns.put(Constants.EJS_NS_KEYWORD, ns.objectNode());
    container.add(ns);

    return ns;
  }
Esempio n. 3
0
 private ArrayNode createSerializedTimestamp(int[] vector, ObjectMapper mapper) {
   ArrayNode ret = mapper.createArrayNode();
   for (int val : vector) {
     ret.add(val);
   }
   return ret;
 }
  @Test
  public void testSortOperator()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    System.out.println("Testing SORT operator");

    Object[][] rows1 = {{0, 10, 0}, {2, 5, 2}, {2, 8, 5}, {5, 9, 6}, {10, 11, 1}, {100, 6, 10}};
    Block block = new ArrayBlock(Arrays.asList(rows1), new String[] {"a", "b", "c"}, 1);

    TupleOperator operator = new SortOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("unsorted", block);

    ObjectMapper mapper = new ObjectMapper();

    ObjectNode json = mapper.createObjectNode();
    json.put("input", "unsorted");
    ArrayNode anode = mapper.createArrayNode();
    anode.add("b");
    anode.add("c");
    json.put("sortBy", anode);

    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT a, INT b, INT c"), (BlockProperties) null);
    operator.setInput(input, json, props);

    Block output = new TupleOperatorBlock(operator, props);

    System.out.println("output is " + output);
    ArrayBlock.assertData(
        output,
        new Object[][] {{2, 5, 2}, {100, 6, 10}, {2, 8, 5}, {5, 9, 6}, {0, 10, 0}, {10, 11, 1}},
        new String[] {"a", "b", "c"});
  }
  public static String getSerializedJSON(List<SearchResult> searchResults) {
    ArrayNode resultArray = JsonNodeFactory.instance.arrayNode();
    for (SearchResult result : searchResults) {
      ObjectNode resultNode = JsonNodeFactory.instance.objectNode();
      resultNode.put("metric", result.getMetricName());

      String unit = result.getUnit();
      if (unit != null) {
        // Preaggreated metrics do not have units. Do not want to return null units in query
        // results.
        resultNode.put("unit", unit);
      }

      // get enum values and add if applicable
      List<String> enumValues = result.getEnumValues();
      if (enumValues != null) {
        // sort for consistent result ordering
        Collections.sort(enumValues);
        ArrayNode enumValuesArray = JsonNodeFactory.instance.arrayNode();
        for (String val : enumValues) {
          enumValuesArray.add(val);
        }
        resultNode.put("enum_values", enumValuesArray);
      }

      resultArray.add(resultNode);
    }
    return resultArray.toString();
  }
Esempio n. 6
0
  public String createChallangeNAClaims(String req, String claimDefs, int size) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode claimDefNodes = (ArrayNode) mapper.readTree(claimDefs);

    req = req.replaceAll("\"", "");
    byte[] reqElemBytes = Base64.decode(req);

    Element reqElem = null;
    ArrayList<IdentityClaimDefinition> icds = new ArrayList<IdentityClaimDefinition>();

    for (int i = 0; i < size; i++) {
      String onVal = claimDefNodes.get(i).getTextValue();

      ObjectNode claimDefOn = (ObjectNode) mapper.readTree(onVal);
      IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn);
      icds.add(idClaimDef);

      if (reqElem == null) {
        Pairing pairing = idClaimDef.getParams().getPairing();
        reqElem = pairing.getG1().newElement();
        reqElem.setFromBytes(reqElemBytes);
        //				System.out.println(reqElem);
      }
    }

    Pairing pairing = icds.get(0).getParams().getPairing();
    Field gt = pairing.getGT();
    Element sessionKey = gt.newRandomElement().getImmutable();
    Element sessionKeyOrig = sessionKey.getImmutable();
    // System.out.println("Key: " + sessionKey);

    JsonNode rootNode = mapper.createObjectNode();
    ObjectNode on = (ObjectNode) rootNode;
    Encrypt encrypt = new Encrypt();

    for (int i = 0; i < size; i++) {
      IdentityClaimDefinition claimDef = icds.get(i);

      Element share = null;
      if (i < (size - 1)) {
        share = gt.newRandomElement().getImmutable();
        sessionKey = sessionKey.sub(share).getImmutable();
      } else {
        // Last one should be the remaining part of session key
        share = sessionKey;
      }

      encrypt.init(claimDef.getParams());
      // System.out.println("Part : " + i + " : " + share);
      AECipherTextBlock ct = encrypt.doEncrypt(share, reqElem);

      on.put(claimDef.getName(), ct.serializeJSON());
    }

    //		System.out.println(sessionKeyOrig);
    String sk = new String(Base64.encode(sessionKeyOrig.toBytes()));
    sk = sk.replaceAll(" ", "");
    on.put("SessionKey", sk);
    return on.toString();
  }
Esempio n. 7
0
  @Security.Authenticated(SecuriteAPI.class)
  public static Result labelsUtilisateurs() {
    if (Securite.utilisateur().getRole() != Utilisateur.Role.ADMIN) {
      return unauthorized();
    }

    ObjectNode json =
        JsonUtils.genererReponseJson(JsonUtils.JsonStatut.OK, "Récupération des labels effectuée");

    UtilisateurService.LabelsResult labelsResult = UtilisateurService.getLabels();
    ArrayNode auth = new ArrayNode(JsonNodeFactory.instance);
    for (String s : labelsResult.types_auth) {
      auth.add(s);
    }

    ArrayNode roles = new ArrayNode(JsonNodeFactory.instance);
    for (String s : labelsResult.roles) {
      roles.add(s);
    }

    json.put("services", auth);
    json.put("roles", roles);

    // attendu: msg.statut, msg.services, msg.roles
    return ok(json);
  }
Esempio n. 8
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String thisUsersId = req.getParameter("userId");
    if ("true".equals(req.getParameter("pingAlive"))) {
      updateLastAliveTime(thisUsersId);
    } else {
      ObjectMapper mapper = new ObjectMapper();

      ArrayNode usersArray = mapper.createArrayNode();

      for (Map.Entry<String, User> userEntry : users.entrySet()) {
        if (!thisUsersId.equals(userEntry.getKey())) {
          User user = userEntry.getValue();
          Date now = new Date();
          if ((now.getTime() - user.getLastAliveTime().getTime()) / 1000 <= 10) {
            ObjectNode userJson = mapper.createObjectNode();
            userJson.put("user_id", userEntry.getKey());
            userJson.put("user_name", user.getName());
            usersArray.add(userJson);
          }
        }
      }

      ObjectNode usersJson = mapper.createObjectNode();
      usersJson.put("opponents", usersArray);

      resp.setContentType("application/json; charset=UTF-8");
      mapper.writeValue(resp.getWriter(), usersJson);
    }
  }
  private void addJsonParameters(
      String propertyName, List<IOParameter> parameterList, ObjectNode propertiesNode) {
    ObjectNode parametersNode = objectMapper.createObjectNode();
    ArrayNode itemsNode = objectMapper.createArrayNode();
    for (IOParameter parameter : parameterList) {
      ObjectNode parameterItemNode = objectMapper.createObjectNode();
      if (StringUtils.isNotEmpty(parameter.getSource())) {
        parameterItemNode.put(PROPERTY_IOPARAMETER_SOURCE, parameter.getSource());
      } else {
        parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE);
      }
      if (StringUtils.isNotEmpty(parameter.getTarget())) {
        parameterItemNode.put(PROPERTY_IOPARAMETER_TARGET, parameter.getTarget());
      } else {
        parameterItemNode.putNull(PROPERTY_IOPARAMETER_TARGET);
      }
      if (StringUtils.isNotEmpty(parameter.getSourceExpression())) {
        parameterItemNode.put(
            PROPERTY_IOPARAMETER_SOURCE_EXPRESSION, parameter.getSourceExpression());
      } else {
        parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE_EXPRESSION);
      }

      itemsNode.add(parameterItemNode);
    }

    parametersNode.put("totalCount", itemsNode.size());
    parametersNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
    propertiesNode.put(propertyName, parametersNode);
  }
  @Test
  public void testGroupByWithSum1()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{0}, {2}, {2}, {5}, {10}, {100}};
    Block block = new ArrayBlock(Arrays.asList(rows1), new String[] {"a"}, 1);

    TupleOperator operator = new GroupByOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("first", block);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode json = mapper.createObjectNode();
    json.put("input", "first");
    ArrayNode anode = mapper.createArrayNode();
    anode.add("a");
    json.put("groupBy", anode);
    anode = mapper.createArrayNode();
    ObjectNode onode = mapper.createObjectNode();
    onode.put("type", "SUM");
    onode.put("input", "a");
    onode.put("output", "sum");
    anode.add(onode);
    json.put("aggregates", anode);

    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT a, INT sum"), (BlockProperties) null);
    operator.setInput(input, json, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(
        output,
        new Object[][] {{0, 0}, {2, 4}, {5, 5}, {10, 10}, {100, 100}},
        new String[] {"a", "sum"});
  }
Esempio n. 11
0
  private static Object getValue(Object value, final boolean includeType) {

    Object returnValue = value;

    // if the includeType is set to true then show the data types of the properties
    if (includeType) {

      // type will be one of: map, list, string, long, int, double, float.
      // in the event of a complex object it will call a toString and store as a
      // string
      String type = determineType(value);

      ObjectNode valueAndType = jsonNodeFactory.objectNode();
      valueAndType.put(GraphSONTokens.TYPE, type);

      if (type.equals(GraphSONTokens.TYPE_LIST)) {

        // values of lists must be accumulated as ObjectNode objects under the value key.
        // will return as a ArrayNode. called recursively to traverse the entire
        // object graph of each item in the array.
        ArrayNode list = (ArrayNode) value;

        // there is a set of values that must be accumulated as an array under a key
        ArrayNode valueArray = valueAndType.putArray(GraphSONTokens.VALUE);
        for (int ix = 0; ix < list.size(); ix++) {
          // the value of each item in the array is a node object from an ArrayNode...must
          // get the value of it.
          addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType));
        }

      } else if (type.equals(GraphSONTokens.TYPE_MAP)) {

        // maps are converted to a ObjectNode.  called recursively to traverse
        // the entire object graph within the map.
        ObjectNode convertedMap = jsonNodeFactory.objectNode();
        ObjectNode jsonObject = (ObjectNode) value;
        Iterator keyIterator = jsonObject.getFieldNames();
        while (keyIterator.hasNext()) {
          Object key = keyIterator.next();

          // no need to getValue() here as this is already a ObjectNode and should have type info
          convertedMap.put(key.toString(), jsonObject.get(key.toString()));
        }

        valueAndType.put(GraphSONTokens.VALUE, convertedMap);
      } else {

        // this must be a primitive value or a complex object.  if a complex
        // object it will be handled by a call to toString and stored as a
        // string value
        putObject(valueAndType, GraphSONTokens.VALUE, value);
      }

      // this goes back as a JSONObject with data type and value
      returnValue = valueAndType;
    }

    return returnValue;
  }
 /**
  * @deprecated since 0.6.0 use {@link #fetch(String)} (with slightly different, but better
  *     semantics)
  */
 @Deprecated
 @Override
 public JsonNode applicationTree() {
   ArrayNode apps = mapper().createArrayNode();
   for (Application application : mgmt().getApplications())
     apps.add(recursiveTreeFromEntity(application));
   return apps;
 }
Esempio n. 13
0
  /**
   * Handles the given {@link ArrayNode} and writes the responses to the given {@link OutputStream}.
   *
   * @param node the {@link JsonNode}
   * @param ops the {@link OutputStream}
   * @throws JsonGenerationException
   * @throws JsonMappingException
   * @throws IOException
   */
  private void handleArray(ArrayNode node, OutputStream ops)
      throws JsonGenerationException, JsonMappingException, IOException {

    // loop through each array element
    for (int i = 0; i < node.size(); i++) {
      handleNode(node.get(i), ops);
    }
  }
 private ArrayNode childEntitiesRecursiveAsArray(Entity entity) {
   ArrayNode node = mapper().createArrayNode();
   for (Entity e : entity.getChildren()) {
     if (Entitlements.isEntitled(
         mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
       node.add(recursiveTreeFromEntity(e));
     }
   }
   return node;
 }
 private ArrayNode entitiesIdAsArray(Iterable<? extends Entity> entities) {
   ArrayNode node = mapper().createArrayNode();
   for (Entity entity : entities) {
     if (Entitlements.isEntitled(
         mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
       node.add(entity.getId());
     }
   }
   return node;
 }
Esempio n. 16
0
  public static ObjectNode entityListToJson(List<Entity> entityList) throws LeanException {
    ObjectNode json = getObjectMapper().createObjectNode();
    ArrayNode array = getObjectMapper().createArrayNode();

    for (Entity entity : entityList) {
      array.add(entityToJson(entity));
    }
    json.put("result", array);
    return json;
  }
Esempio n. 17
0
  /**
   * Generates the JSON code for the raw log entry collection.
   *
   * @param model the model data to output
   * @param locale the locale indicating the language in which localizable data should be shown
   * @return a string containing the JSON code for the raw log entry collection
   * @throws MonitorInterfaceException
   *     <ul>
   *       <li>the model data is invalid
   *       <li>an error occurred while converting the raw log entry collection to JSON
   *     </ul>
   */
  @SuppressWarnings("unchecked")
  @Override
  protected JsonNode getResponseData(Map<String, ?> model, Locale locale)
      throws MonitorInterfaceException {

    if (model.containsKey("rawLogsCollection") && model.containsKey("addQueryId")) {

      if (model.containsKey("getExport")
          && model.containsKey("Slaname")
          && model.containsKey("Jobname")
          && model.containsKey("Queryname")) {
        final Set<RawLogEntry> logsCollection = (Set<RawLogEntry>) model.get("rawLogsCollection");
        final Boolean addQueryId = (Boolean) model.get("addQueryId");
        final Boolean getExport = (Boolean) model.get("getExport");
        final Boolean isSummary = (Boolean) model.get("isSummary");
        final String slaName = (String) model.get("Slaname");
        final String jobName = (String) model.get("Jobname");
        final String queryName = (String) model.get("Queryname");
        final ObjectMapper mapper = this.getObjectMapper();
        final ArrayNode rowsCollection = mapper.createArrayNode();
        List<RawLogEntry> sortLogs = new ArrayList<RawLogEntry>(logsCollection);
        Collections.sort(sortLogs, new MyLogComparable());

        for (RawLogEntry logEntry : sortLogs) {
          rowsCollection.add(
              RawLogSerializer.serialize(
                  logEntry,
                  addQueryId,
                  getExport,
                  slaName,
                  jobName,
                  queryName,
                  locale,
                  mapper,
                  isSummary,
                  null));
        }
        return rowsCollection;
      } else {
        final Set<RawLogEntry> logsCollection = (Set<RawLogEntry>) model.get("rawLogsCollection");
        final Boolean addQueryId = (Boolean) model.get("addQueryId");
        final Boolean isSummary = (Boolean) model.get("isSummary");
        final Long noPagingCount = (Long) model.get("noPagingCount");
        final ObjectMapper mapper = this.getObjectMapper();
        this.getRootObjectNode().put("noPagingCount", noPagingCount);
        final ArrayNode rowsCollection = mapper.createArrayNode();
        for (RawLogEntry logEntry : logsCollection) {
          rowsCollection.add(
              RawLogSerializer.serialize(logEntry, addQueryId, locale, mapper, isSummary));
        }
        return rowsCollection;
      }
    }
    throw new MonitorInterfaceException("An internal error occurred", "internal.error");
  }
 /**
  * Extracts a list of {@link PropertyValue} objects from a JSON array.
  *
  * @param node ObjectNode containing the list of objects.
  * @param key Key pointing to the node where the list is stored.
  */
 static List<PropertyValue> getGUIModelPropertyValueList(JsonNode node, String key) {
   if (node.has(key)) {
     final ArrayNode a = (ArrayNode) node.get(key);
     final List<PropertyValue> l = new ArrayList<PropertyValue>(a.size());
     for (int i = 0; i < a.size(); i++) {
       l.add(new PropertyValue((JsonNode) a.get(i)));
     }
     return l;
   }
   return new ArrayList<PropertyValue>(0);
 }
 /**
  * Extracts a list of {@link Skin} objects from a JSON array.
  *
  * @param node ObjectNode containing the list of objects.
  * @param key Key pointing to the node where the list is stored.
  */
 static List<Skin> getGUIModelSkinList(JsonNode node, String key) {
   if (node.has(key)) {
     final ArrayNode a = (ArrayNode) node.get(key);
     final List<Skin> l = new ArrayList<Skin>(a.size());
     for (int i = 0; i < a.size(); i++) {
       l.add(new Skin((JsonNode) a.get(i)));
     }
     return l;
   }
   return new ArrayList<Skin>(0);
 }
 /**
  * Extracts a list of {@link Currentcontrol} objects from a JSON array.
  *
  * @param node ObjectNode containing the list of objects.
  * @param key Key pointing to the node where the list is stored.
  */
 static List<Currentcontrol> getGUIModelCurrentcontrolList(JsonNode node, String key) {
   if (node.has(key)) {
     final ArrayNode a = (ArrayNode) node.get(key);
     final List<Currentcontrol> l = new ArrayList<Currentcontrol>(a.size());
     for (int i = 0; i < a.size(); i++) {
       l.add(new Currentcontrol((JsonNode) a.get(i)));
     }
     return l;
   }
   return new ArrayList<Currentcontrol>(0);
 }
Esempio n. 21
0
  public static String getSubredditId(String mSubreddit) {
    String subreddit_id = null;
    JsonNode subredditInfo =
        RestJsonClient.connect(Constants.REDDIT_BASE_URL + "/r/" + mSubreddit + "/.json?count=1");

    if (subredditInfo != null) {
      ArrayNode children = (ArrayNode) subredditInfo.path("data").path("children");
      subreddit_id = children.get(0).get("data").get("subreddit_id").getTextValue();
    }
    return subreddit_id;
  }
 /**
  * Extracts a list of {@link ItemModel.BaseDetails} objects from a JSON array.
  *
  * @param obj ObjectNode containing the list of objects
  * @param key Key pointing to the node where the list is stored
  */
 static ArrayList<ItemModel.BaseDetails> getItemModelBaseDetailsList(
     ObjectNode node, String key) {
   if (node.has(key)) {
     final ArrayNode a = (ArrayNode) node.get(key);
     final ArrayList<ItemModel.BaseDetails> l = new ArrayList<ItemModel.BaseDetails>(a.size());
     for (int i = 0; i < a.size(); i++) {
       l.add(new ItemModel.BaseDetails((ObjectNode) a.get(i)));
     }
     return l;
   }
   return new ArrayList<ItemModel.BaseDetails>(0);
 }
Esempio n. 23
0
 public String toJson(ObjectMapper mapper) {
   ObjectNode rootNode = mapper.createObjectNode();
   ArrayNode keysNode = rootNode.putArray("keys");
   for (Object key : keys) {
     keysNode.addPOJO(key);
   }
   try {
     return mapper.writeValueAsString(rootNode);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/class")
  public String getClasses() {
    ArrayNode noClasses = JsonNodeFactory.instance.arrayNode();

    for (Clazz clazz : LomBusinessFacade.getInstance().getAllClasses()) {
      noClasses.add(clazz.getJson());
    }

    return noClasses.toString();
  }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/attribute")
  public String getAttributes() {
    ArrayNode noAttributes = JsonNodeFactory.instance.arrayNode();

    for (Attribute attribute : LomBusinessFacade.getInstance().getAllAttributes()) {
      noAttributes.add(attribute.getJson());
    }

    return noAttributes.toString();
  }
  public void testAcceptRejectGet() {
    TestHttpApiClient client =
        newHttpApiClient(UA_EMPTY, ServerTeam.jcsTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET);
    client.get(
        PUB_API + "/suggest/recommend",
        new Object[][] {
          {"touser", ServerTeam.CG_ID},
          {"suggestedusers", String.valueOf(ServerTeam.WP_ID)}
        });
    client =
        newHttpApiClient(UA_EMPTY, ServerTeam.grxTicket(), TestApp.APP1_ID, TestApp.APP1_SECRET);
    client.get(
        PUB_API + "/psuggest/create",
        new Object[][] {
          {"to", ServerTeam.CG_ID},
          {
            "suggested",
            StringHelper.join(
                new long[] {ServerTeam.WP_ID, ServerTeam.GRX_ID, ServerTeam.JCS_ID}, ",")
          }
        });

    client =
        newHttpApiClient(UA_EMPTY, ServerTeam.cgTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET);
    client.get(
        PUB_API + "/psuggest/accept",
        new Object[][] {
          {"suggested", ServerTeam.GRX_ID},
          {
            "circles",
            StringHelper.join(new int[] {Circle.CIRCLE_DEFAULT, Circle.CIRCLE_FAMILY}, ",")
          }
        });
    client.get(PUB_API + "/psuggest/reject", new Object[][] {{"suggested", ServerTeam.WP_ID}});

    AbstractHttpClient.Response resp =
        client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.ACCEPTED}});
    ArrayNode arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 1);
    assertTrue(
        JsonCompare.compare(
                arrNode.get(0).get("suggested"),
                JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.GRX_ID), false)))
            .isEquals());
    resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.REJECTED}});
    arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 1);
    assertTrue(
        JsonCompare.compare(
                arrNode.get(0).get("suggested"),
                JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false)))
            .isEquals());
  }
  protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) {
    BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
    ArrayNode dockersArrayNode = objectMapper.createArrayNode();
    ObjectNode dockNode = objectMapper.createObjectNode();
    GraphicInfo graphicInfo = model.getGraphicInfo(boundaryEvent.getId());
    GraphicInfo parentGraphicInfo = model.getGraphicInfo(boundaryEvent.getAttachedToRef().getId());
    dockNode.put(EDITOR_BOUNDS_X, graphicInfo.x + graphicInfo.width - parentGraphicInfo.x);
    dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.y - parentGraphicInfo.y);
    dockersArrayNode.add(dockNode);
    flowElementNode.put("dockers", dockersArrayNode);

    addEventProperties(boundaryEvent, propertiesNode);
  }
Esempio n. 28
0
  @Override
  ObjectNode toJson() {
    final ObjectNode obj = mapper.createObjectNode();
    final ArrayNode bool = obj.putArray(BooleanPropertyParser.BOOLEAN_PROPERTY);

    for (final QueryClause clause : clauses) {
      final ObjectNode e = bool.addObject();
      e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
      e.putAll(clause.getQuery().toJson());
    }

    return obj;
  }
 private ArrayNode entitiesIdAndNameAsArray(Collection<? extends Entity> entities) {
   ArrayNode node = mapper().createArrayNode();
   for (Entity entity : entities) {
     if (Entitlements.isEntitled(
         mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
       ObjectNode holder = mapper().createObjectNode();
       holder.put("id", entity.getId());
       holder.put("name", entity.getDisplayName());
       node.add(holder);
     }
   }
   return node;
 }
Esempio n. 30
0
  public static void main(String args[]) {

    JacksonTester tester = new JacksonTester();

    try {
      ObjectMapper mapper = new ObjectMapper();

      JsonNode rootNode = mapper.createObjectNode();
      JsonNode marksNode = mapper.createArrayNode();

      ((ArrayNode) marksNode).add(100);
      ((ArrayNode) marksNode).add(90);
      ((ArrayNode) marksNode).add(85);

      ((ObjectNode) rootNode).put("name", "Mahesh Kumar");
      ((ObjectNode) rootNode).put("age", 21);
      ((ObjectNode) rootNode).put("verified", false);
      ((ObjectNode) rootNode).put("marks", marksNode);

      mapper.writeValue(new File("student.json"), rootNode);

      rootNode = mapper.readTree(new File("student.json"));

      JsonNode nameNode = rootNode.path("name");
      System.out.println("Name: " + nameNode.getTextValue());

      JsonNode ageNode = rootNode.path("age");
      System.out.println("Age: " + ageNode.getIntValue());

      JsonNode verifiedNode = rootNode.path("verified");
      System.out.println("Verified: " + (verifiedNode.getBooleanValue() ? "Yes" : "No"));

      JsonNode marksNode1 = rootNode.path("marks");
      Iterator<JsonNode> iterator = marksNode1.getElements();
      System.out.print("Marks: [ ");

      while (iterator.hasNext()) {
        JsonNode marks = iterator.next();
        System.out.print(marks.getIntValue() + " ");
      }

      System.out.println("]");
    } catch (JsonParseException e) {
      e.printStackTrace();
    } catch (JsonMappingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }