コード例 #1
0
  public Object unwrap(Object o) {

    if (o == null) {
      return null;
    }
    if (!(o instanceof JsonNode)) {
      return o;
    }

    JsonNode e = (JsonNode) o;

    if (e.isValueNode()) {

      if (e.isTextual()) {
        return e.asText();
      } else if (e.isBoolean()) {
        return e.asBoolean();
      } else if (e.isInt()) {
        return e.asInt();
      } else if (e.isLong()) {
        return e.asLong();
      } else if (e.isBigDecimal()) {
        return e.decimalValue();
      } else if (e.isDouble()) {
        return e.doubleValue();
      } else if (e.isFloat()) {
        return e.floatValue();
      } else if (e.isBigDecimal()) {
        return e.decimalValue();
      } else if (e.isNull()) {
        return null;
      }
    }
    return o;
  }
コード例 #2
0
 @Override
 public void configure(Map stormConf, JsonNode paramNode) {
   JsonNode node = paramNode.get("maxDepth");
   if (node != null && node.isInt()) {
     maxDepth = node.intValue();
   } else {
     maxDepth = 0;
     LOG.warn("maxDepth paramater not found");
   }
 }
コード例 #3
0
 @Override
 public Criterion decodeCriterion(ObjectNode json) {
   JsonNode ethTypeNode =
       nullIsIllegal(
           json.get(CriterionCodec.ETH_TYPE), CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE);
   int ethType;
   if (ethTypeNode.isInt()) {
     ethType = ethTypeNode.asInt();
   } else {
     ethType = Integer.decode(ethTypeNode.textValue());
   }
   return Criteria.matchEthType(ethType);
 }
コード例 #4
0
ファイル: JsonRpcServer.java プロジェクト: sdhjob/jsonrpc4j
 /**
  * Parses an ID.
  *
  * @param node
  * @return
  */
 protected Object parseId(JsonNode node) {
   if (node == null || node.isNull()) {
     return null;
   } else if (node.isDouble()) {
     return node.asDouble();
   } else if (node.isFloatingPointNumber()) {
     return node.asDouble();
   } else if (node.isInt()) {
     return node.asInt();
   } else if (node.isIntegralNumber()) {
     return node.asInt();
   } else if (node.isLong()) {
     return node.asLong();
   } else if (node.isTextual()) {
     return node.asText();
   }
   throw new IllegalArgumentException("Unknown id type");
 }
コード例 #5
0
  @Test
  public void testLatestBackref() throws Exception {
    ModelPath a =
        ModelPath.builder("Container.parent.latset_backref.StatusUpdate|Document|Blog.name.value")
            .addPathMember(
                new ModelPathStep(
                    true,
                    newHashSet("StatusUpdate", "Document", "Blog"),
                    "parent",
                    latest_backRef,
                    newHashSet("Container"),
                    null))
            .addPathMember(
                new ModelPathStep(
                    false,
                    newHashSet("StatusUpdate", "Document", "Blog"),
                    null,
                    value,
                    null,
                    Arrays.asList("instanceId")))
            .build();

    Set<Id> permissions = new HashSet<>();
    ViewResponse viewResponse = viewFieldsCollector.getView(permissions);
    ObjectNode view = viewResponse.getViewBody();
    Assert.assertNull(view);

    viewFieldsCollector.add(
        viewDescriptor,
        a,
        new Id[] {new Id(1), new Id(2)},
        new String[] {"Container", "Document"},
        new ViewValue(new long[] {1, 2}, "{\"instanceId\":11}".getBytes()),
        1L);
    viewFieldsCollector.add(
        viewDescriptor,
        a,
        new Id[] {new Id(1), new Id(3)},
        new String[] {"Container", "StatusUpdate"},
        new ViewValue(new long[] {1, 3}, "{\"instanceId\":12}".getBytes()),
        2L);
    viewFieldsCollector.add(
        viewDescriptor,
        a,
        new Id[] {new Id(1), new Id(4)},
        new String[] {"Container", "Document"},
        new ViewValue(new long[] {1, 5}, "{\"instanceId\":13}".getBytes()),
        4L);
    viewFieldsCollector.add(
        viewDescriptor,
        a,
        new Id[] {new Id(1), new Id(5)},
        new String[] {"Container", "Document"},
        new ViewValue(new long[] {1, 4}, "{\"instanceId\":14}".getBytes()),
        3L);
    viewFieldsCollector.done();

    viewResponse = viewFieldsCollector.getView(permissions);
    view = viewResponse.getViewBody();
    Assert.assertNull(view);

    permissions.add(new Id(1L));
    permissions.add(new Id(2L));
    permissions.add(new Id(3L));
    permissions.add(new Id(4L));
    permissions.add(new Id(5L));

    viewResponse = viewFieldsCollector.getView(permissions);
    view = viewResponse.getViewBody();
    System.out.println("view=" + view);
    JsonNode got = view.get("latest_parent");
    Assert.assertTrue(got.isObject());
    JsonNode field = got.get("instanceId");
    Assert.assertTrue(field.isInt());
    Assert.assertEquals(field.asInt(), 13); // added at the highest timestamp
  }
コード例 #6
0
 private int parsePort(JsonNode node) {
   return node.isInt() ? node.asInt() : ServerEnvironment.parsePortValue("config", node.asText());
 }