com.fasterxml.jackson.databind.node.LongNode Java Examples

The following examples show how to use com.fasterxml.jackson.databind.node.LongNode. 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: DistributedNetworkConfigStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Activate
public void activate() {
    KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
            .register(KryoNamespaces.API)
            .register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
                      JsonNodeFactory.class, LinkedHashMap.class,
                      TextNode.class, BooleanNode.class,
                      LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
                      NullNode.class);

    configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
            .withSerializer(Serializer.using(kryoBuilder.build()))
            .withName("onos-network-configs")
            .withRelaxedReadConsistency()
            .build();
    configs.addListener(listener);
    log.info("Started");
}
 
Example #2
Source File: ObjectToJsonNode.java    From yosegi with Apache License 2.0 6 votes vote down vote up
/**
 * Judge Java objects and create JsonNode.
 */
public static JsonNode get( final Object obj ) throws IOException {
  if ( obj instanceof PrimitiveObject ) {
    return PrimitiveObjectToJsonNode.get( (PrimitiveObject)obj );
  } else if ( obj instanceof String ) {
    return new TextNode( (String)obj );
  } else if ( obj instanceof Boolean ) {
    return BooleanNode.valueOf( (Boolean)obj );
  } else if ( obj instanceof Short ) {
    return IntNode.valueOf( ( (Short)obj ).intValue() );
  } else if ( obj instanceof Integer ) {
    return IntNode.valueOf( (Integer)obj );
  } else if ( obj instanceof Long ) {
    return new LongNode( (Long)obj );
  } else if ( obj instanceof Float ) {
    return new DoubleNode( ( (Float)obj ).doubleValue() );
  } else if ( obj instanceof Double ) {
    return new DoubleNode( (Double)obj );
  } else if ( obj instanceof byte[] ) {
    return new BinaryNode( (byte[])obj );
  } else if ( obj == null ) {
    return NullNode.getInstance();
  } else {
    return new TextNode( obj.toString() );
  }
}
 
Example #3
Source File: IntegerSampler.java    From log-synth with Apache License 2.0 6 votes vote down vote up
@Override
public JsonNode sample() {
    synchronized (this) {
        if (dist == null) {
            int r = power >= 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
            if (power >= 0) {
                for (int i = 0; i <= power; i++) {
                    r = Math.min(r, min + base.nextInt(max - min));
                }
            } else {
                int n = -power;
                for (int i = 0; i <= n; i++) {
                    r = Math.max(r, min + base.nextInt(max - min));
                }
            }
            if (format == null) {
                return new IntNode(r);
            } else {
                return new TextNode(String.format(format, r));
            }
        } else {
            return new LongNode(dist.sample());
        }
    }
}
 
Example #4
Source File: BurstyEvents.java    From log-synth with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
    private boolean addTimeFields(ObjectNode x) {
        Event e = null;
        while (e != Event.ACTION) {
            e = step();
//            System.out.printf("%8s/%-9s %11s %s %8.2f %8.2f %8.2f %8.2f\n",
//                    Util.isDaytime(Util.timeOfDay(now), sunriseTime, sunsetTime) ? "day" : "night",
//                    isActive ? "active" : "inactive",
//                    e, df.format((long) now),
//                    (nextQuery - now) / TimeUnit.HOURS.toMillis(1),
//                    (nextTransition - now) / TimeUnit.HOURS.toMillis(1),
//                    24 * Util.fractionalPart((sunriseTime - Util.timeOfDay(now)) / TimeUnit.HOURS.toMillis(24)),
//                    24 * Util.fractionalPart((sunsetTime - Util.timeOfDay(now)) / TimeUnit.HOURS.toMillis(24))
//            );
            if (e == Event.END) {
                return false;
            }
        }
        x.set("time", new TextNode(df.format((long) now)));
        x.set("timestamp_ms", new LongNode((long) now));
        x.set("timestamp_s", new LongNode((long) (now / 1000)));
        return true;
    }
 
Example #5
Source File: DivideOperator.java    From jslt with Apache License 2.0 6 votes vote down vote up
public JsonNode perform(JsonNode v1, JsonNode v2) {
  if (v1.isNull() || v2.isNull())
    return NullNode.instance;

  // we only support the numeric operation and nothing else
  v1 = NodeUtils.number(v1, true, location);
  v2 = NodeUtils.number(v2, true, location);

  if (v1.isIntegralNumber() && v2.isIntegralNumber()) {
    long l1 = v1.longValue();
    long l2 = v2.longValue();
    if (l1 % l2 == 0)
      return new LongNode(l1 / l2);
    else
      return new DoubleNode((double) l1 / (double) l2);
  } else
    return new DoubleNode(perform(v1.doubleValue(), v2.doubleValue()));
}
 
Example #6
Source File: TsdbResult.java    From splicer with Apache License 2.0 6 votes vote down vote up
@Override
public Points deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
	TreeNode n = jp.getCodec().readTree(jp);
	Map<String, Object> points = new HashMap<>();
	Iterator<String> namesIter = n.fieldNames();
	while(namesIter.hasNext()) {
		String field = namesIter.next();
		TreeNode child = n.get(field);

		Object o;
		if (child instanceof DoubleNode || child instanceof FloatNode) {
			o = ((NumericNode) child).doubleValue();
		} else if (child instanceof IntNode || child instanceof LongNode) {
			o = ((NumericNode) child).longValue();
		} else {
			throw new MergeException("Unsupported Type, " + child.getClass());
		}

		points.put(field, o);
	}
	return new Points(points);
}
 
Example #7
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 6 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode array = arguments[0];
  if (array.isNull())
    return NullNode.instance;
  else if (!array.isArray())
    throw new JsltException("sum(): argument must be array, was " + array);

  double sum = 0.0;
  boolean integral = true;
  for (int ix = 0; ix < array.size(); ix++) {
    JsonNode value = array.get(ix);
    if (!value.isNumber())
      throw new JsltException("sum(): array must contain numbers, found " + value);
    integral &= value.isIntegralNumber();

    sum += value.doubleValue();
  }
  if (integral)
    return new LongNode((long) sum);
  else
    return new DoubleNode(sum);
}
 
Example #8
Source File: Datapoint.java    From bce-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Add datapoint of double type value.
 *
 * @param time datapoint's timestamp
 * @param value datapoint's value
 * @return Datapoint
 */
public Datapoint addDoubleValue(long time, double value) {
    initialValues();
    checkType(TsdbConstants.TYPE_DOUBLE);

    values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new DoubleNode(value)));
    return this;
}
 
Example #9
Source File: UiExtensionManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Activate
public void activate() {
    Serializer serializer = Serializer.using(KryoNamespaces.API,
                 ObjectNode.class, ArrayNode.class,
                 JsonNodeFactory.class, LinkedHashMap.class,
                 TextNode.class, BooleanNode.class,
                 LongNode.class, DoubleNode.class, ShortNode.class,
                 IntNode.class, NullNode.class, UiSessionToken.class);

    prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder()
            .withName(ONOS_USER_PREFERENCES)
            .withSerializer(serializer)
            .withRelaxedReadConsistency()
            .build();
    prefsConsistentMap.addListener(prefsListener);
    prefs = prefsConsistentMap.asJavaMap();

    tokensConsistentMap = storageService.<UiSessionToken, String>consistentMapBuilder()
            .withName(ONOS_SESSION_TOKENS)
            .withSerializer(serializer)
            .withRelaxedReadConsistency()
            .build();
    tokens = tokensConsistentMap.asJavaMap();

    register(core);

    log.info("Started");
}
 
Example #10
Source File: Datapoint.java    From bce-sdk-java with Apache License 2.0 5 votes vote down vote up
public Datapoint addBytesValue(long time, byte[] value) {
    initialValues();
    if (values != null && !values.isEmpty() && (type == null || !type.equals(TsdbConstants.TYPE_BYTES))) {
        throw new IllegalStateException("There is already another type in datapoint, "
                + "could not add byte array type again");
    }
    type = TsdbConstants.TYPE_BYTES;
    values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new BinaryNode(value)));
    return this;
}
 
Example #11
Source File: Datapoint.java    From bce-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Add datapoint of String type value.
 *
 * @param time datapoint's timestamp
 * @param value datapoint's value
 * @return Datapoint
 */
public Datapoint addStringValue(long time, String value) {
    initialValues();
    checkType(TsdbConstants.TYPE_STRING);

    values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new TextNode(value)));
    return this;
}
 
Example #12
Source File: JsonNodeToPrimitiveObject.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Converts JsonNode to PrimitiveObject.
 */
public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException {
  if ( jsonNode instanceof TextNode ) {
    return new StringObj( ( (TextNode)jsonNode ).textValue() );
  } else if ( jsonNode instanceof BooleanNode ) {
    return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() );
  } else if ( jsonNode instanceof IntNode ) {
    return new IntegerObj( ( (IntNode)jsonNode ).intValue() );
  } else if ( jsonNode instanceof LongNode ) {
    return new LongObj( ( (LongNode)jsonNode ).longValue() );
  } else if ( jsonNode instanceof DoubleNode ) {
    return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() );
  } else if ( jsonNode instanceof BigIntegerNode ) {
    return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() );
  } else if ( jsonNode instanceof DecimalNode ) {
    return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() );
  } else if ( jsonNode instanceof BinaryNode ) {
    return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() );
  } else if ( jsonNode instanceof POJONode ) {
    return new BytesObj( ( (POJONode)jsonNode ).binaryValue() );
  } else if ( jsonNode instanceof NullNode ) {
    return NullObj.getInstance();
  } else if ( jsonNode instanceof MissingNode ) {
    return NullObj.getInstance();
  } else {
    return new StringObj( jsonNode.toString() );
  }
}
 
Example #13
Source File: Datapoint.java    From bce-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Add datapoint of long type value.
 *
 * @param time datapoint's timestamp
 * @param value datapoint's value
 * @return Datapoint
 */
public Datapoint addLongValue(long time, long value) {
    initialValues();
    checkType(TsdbConstants.TYPE_LONG);

    values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new LongNode(value)));
    return this;
}
 
Example #14
Source File: MessageFormatsTest.java    From template-compiler with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateTime() {
  String actual;
  CLDR cldr = CLDR.get("en");
  MessageFormats formats = new MessageFormats(cldr);
  formats.setTimeZone("America/New_York");
  String message = "{0 datetime date:long time:medium}";
  long epoch = 1582129775000L;

  actual = formats.formatter().format(message, args().add(new LongNode(epoch)));
  assertEquals(actual, "February 19, 2020 at 11:29:35 AM");
}
 
Example #15
Source File: MessageFormatsTest.java    From template-compiler with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterval() {
  String actual;
  CLDR cldr = CLDR.get("en");
  MessageFormats formats = new MessageFormats(cldr);
  formats.setTimeZone("America/New_York");
  String message = "{0;1 datetime-interval}";
  long epoch = 1582129775000L;

  long extra = 86400000 + 3600000;
  MessageArgs args = args().add(new LongNode(epoch)).add(new LongNode(epoch + extra));
  actual = formats.formatter().format(message, args);
  assertEquals(actual, "Feb 19 – 20, 2020");
}
 
Example #16
Source File: JsonExampleDeserializer.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
private Example createExample(JsonNode node) {
    if (node instanceof ObjectNode) {
        ObjectExample obj = new ObjectExample();
        ObjectNode on = (ObjectNode) node;
        for (Iterator<Entry<String, JsonNode>> x = on.fields(); x.hasNext(); ) {
            Entry<String, JsonNode> i = x.next();
            String key = i.getKey();
            JsonNode value = i.getValue();
            obj.put(key, createExample(value));
        }
        return obj;
    } else if (node instanceof ArrayNode) {
        ArrayExample arr = new ArrayExample();
        ArrayNode an = (ArrayNode) node;
        for (JsonNode childNode : an) {
            arr.add(createExample(childNode));
        }
        return arr;
    } else if (node instanceof DoubleNode) {
        return new DoubleExample(node.doubleValue());
    } else if (node instanceof IntNode || node instanceof ShortNode) {
        return new IntegerExample(node.intValue());
    } else if (node instanceof FloatNode) {
        return new FloatExample(node.floatValue());
    } else if (node instanceof BigIntegerNode) {
        return new BigIntegerExample(node.bigIntegerValue());
    } else if (node instanceof DecimalNode) {
        return new DecimalExample(node.decimalValue());
    } else if (node instanceof LongNode) {
        return new LongExample(node.longValue());
    } else if (node instanceof BooleanNode) {
        return new BooleanExample(node.booleanValue());
    } else {
        return new StringExample(node.asText());
    }
}
 
Example #17
Source File: Serializer.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Long> deserialize(JsonNode json) {
    if (json instanceof LongNode) {
        return Optional.of(json.asLong());
    } else if (json instanceof IntNode) {
        return Optional.of(Long.valueOf(json.asInt()));
    } else {
        return Optional.empty();
    }
}
 
Example #18
Source File: MultiDateDeserializer.java    From nimble-orm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
	JsonNode node = jp.getCodec().readTree(jp);

	// 针对时间戳做优化
	if(node instanceof LongNode || node instanceof IntNode) {
		long timestamp = node.asLong();
		if(timestamp < 4200000000L) { // 小于42亿认为是秒
			return new Date(timestamp * 1000L);
		} else {
			return new Date(timestamp);
		}
	}

	String date = node.asText();
	if(date == null) {
		return null;
	}
	date = date.trim();
	if(date.isEmpty()) {
		return null;
	}
	
	try {
		return NimbleOrmDateUtils.parseThrowException(date);
	} catch (ParseException e) {
		throw new JsonParseException(jp,
		    "Unparseable date: \"" + date + "\". Supported formats: " 
		    + NimbleOrmDateUtils.DATE_FORMAT_REGEXPS.values());
	}
}
 
Example #19
Source File: CouchDbICureRepositorySupport.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
private <P> PaginatedList<T> pagedQueryView(String viewName, P startKey, P endKey, PaginationOffset<P> pagination, boolean descending, Function<P, ValueNode> startToNode) {
	int limit = pagination.getLimit() != null ? pagination.getLimit() : DEFAULT_LIMIT;
	int page = pagination.getPage() != null ? pagination.getPage() : 0;
	String startDocId = pagination.getStartDocumentId();

	ViewQuery viewQuery = createQuery(viewName)
			.startKey(startKey)
			.includeDocs(true)
			.startDocId(startDocId)
			.limit(limit)
			.descending(descending);

	if (endKey != null) {
		viewQuery = viewQuery.endKey(endKey);
	}

	PageRequest.Builder builder = new PageRequest.Builder().pageSize(limit).page(page);

	if (startKey !=null || startDocId != null) {
		builder.nextKey(new PageRequest.KeyIdPair(pagination.getStartKey() == null ? null : startToNode.apply(pagination.getStartKey()), startDocId)).page(Math.max(page,1));
	}

	PageRequest pr = builder.build();
	Page<T> ts = db.queryForPage(viewQuery, pr, type);

	Object sk = ts.getTotalSize() > ts.getPageSize() && ts.getNextPageRequest() != null ? ts.getNextPageRequest().getStartKey() : null;
	return new PaginatedList<>(
			ts.getPageSize(),
			ts.getTotalSize(),
			ts.getRows(),
			sk != null ?
					new PaginatedDocumentKeyIdPair((sk instanceof  NullNode) ? null : (sk instanceof LongNode) ? Collections.singletonList(""+((LongNode) sk).longValue()) : Collections.singletonList(((TextNode) sk).textValue()), ts.getNextPageRequest().getStartKeyDocId())
					: null
	);
}
 
Example #20
Source File: NumericOperator.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode perform(JsonNode v1, JsonNode v2) {
  if (v1.isNull() || v2.isNull())
    return NullNode.instance;

  v1 = NodeUtils.number(v1, true, location);
  v2 = NodeUtils.number(v2, true, location);

  if (v1.isIntegralNumber() && v2.isIntegralNumber())
    return new LongNode(perform(v1.longValue(), v2.longValue()));
  else
    return new DoubleNode(perform(v1.doubleValue(), v2.doubleValue()));
}
 
Example #21
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode dividend = arguments[0];
  if (dividend.isNull())
    return NullNode.instance;
  else if (!dividend.isNumber())
    throw new JsltException("mod(): dividend cannot be a non-number: " + dividend);

  JsonNode divisor = arguments[1];
  if (divisor.isNull())
    return NullNode.instance;
  else if (!divisor.isNumber())
    throw new JsltException("mod(): divisor cannot be a non-number: " + divisor);

  if (!dividend.isIntegralNumber() || !divisor.isIntegralNumber()) {
    throw new JsltException("mod(): operands must be integral types");
  } else {
    long D = dividend.longValue();
    long d = divisor.longValue();
    if (d == 0)
      throw new JsltException("mod(): cannot divide by zero");

    long r = D % d;
    if (r < 0) {
      if (d > 0)
        r += d;
      else
        r -= d;
    }

    return new LongNode(r);
  }
}
 
Example #22
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode number = arguments[0];
  if (number.isNull())
    return NullNode.instance;
  else if (!number.isNumber())
    throw new JsltException("ceiling() cannot round a non-number: " + number);

  return new LongNode((long) Math.ceil(number.doubleValue()));
}
 
Example #23
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode number = arguments[0];
  if (number.isNull())
    return NullNode.instance;
  else if (!number.isNumber())
    throw new JsltException("floor() cannot round a non-number: " + number);

  return new LongNode((long) Math.floor(number.doubleValue()));
}
 
Example #24
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode number = arguments[0];
  if (number.isNull())
    return NullNode.instance;
  else if (!number.isNumber())
    throw new JsltException("round() cannot round a non-number: " + number);

  return new LongNode(Math.round(number.doubleValue()));
}
 
Example #25
Source File: TemplateUtils.java    From qconfig with MIT License 5 votes vote down vote up
public static Optional<String> processTimeStrToLong(JsonNode data, ObjectNode detail) {
    try {
        Map<String, String> nameTypeMapping = Maps.newHashMap();
        Map<String, ObjectNode> nameDetailMapping = Maps.newHashMap();
        getMapping(detail, nameTypeMapping, nameDetailMapping);
        Iterator<JsonNode> elements = data.elements();
        boolean edit = false;
        while (elements.hasNext()) {
            JsonNode row = elements.next();
            Iterator<Map.Entry<String, JsonNode>> fields = row.get(Constants.COLUMNS).fields();
            while (fields.hasNext()) {
                Map.Entry<String, JsonNode> field = fields.next();
                String type = nameTypeMapping.get(field.getKey());
                JsonNode value = field.getValue();
                String valueStr = value.asText();

                if (!Strings.isNullOrEmpty(valueStr) && (isTimeType(type) || isDateType(type))) {
                    edit = true;
                    if (isTimeType(type)) {
                        field.setValue(new LongNode(parseDataTime(TemplateContants.TIME_FORMATTER, valueStr)));
                    } else if (isDateType(type)) {
                        field.setValue(new LongNode(parseDataTime(TemplateContants.DATE_FORMATTER, valueStr)));
                    }
                }
            }
        }

        if (edit) {
            return Optional.of(mapper.writeValueAsString(data));
        } else {
            return Optional.empty();
        }
    } catch (Exception e) {
        throw new IllegalStateException("解析模版与文件时失败");
    }
}
 
Example #26
Source File: PrimitiveObjectToJsonNode.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Convert PrimitiveObject to JsonNode.
 */
public static JsonNode get( final PrimitiveObject obj ) throws IOException {
  if ( obj == null ) {
    return NullNode.getInstance();
  }
  switch ( obj.getPrimitiveType() ) {
    case BOOLEAN:
      return BooleanNode.valueOf( obj.getBoolean() );
    case BYTE:
      return IntNode.valueOf( obj.getInt() );
    case SHORT:
      return IntNode.valueOf( obj.getInt() );
    case INTEGER:
      return IntNode.valueOf( obj.getInt() );
    case LONG:
      return new LongNode( obj.getLong() );
    case FLOAT:
      return new DoubleNode( obj.getDouble() );
    case DOUBLE:
      return new DoubleNode( obj.getDouble() );
    case STRING:
      return new TextNode( obj.getString() );
    case BYTES:
      return new BinaryNode( obj.getBytes() );
    default:
      return NullNode.getInstance();
  }
}
 
Example #27
Source File: DistributedWorkplaceStore.java    From onos with Apache License 2.0 4 votes vote down vote up
@Activate
public void activate() {

    appId = coreService.registerApplication("org.onosproject.workplacestore");
    log.info("appId=" + appId);

    KryoNamespace workplaceNamespace = KryoNamespace.newBuilder()
            .register(KryoNamespaces.API)
            .register(WorkflowData.class)
            .register(Workplace.class)
            .register(DefaultWorkplace.class)
            .register(WorkflowContext.class)
            .register(DefaultWorkflowContext.class)
            .register(SystemWorkflowContext.class)
            .register(WorkflowState.class)
            .register(ProgramCounter.class)
            .register(DataModelTree.class)
            .register(JsonDataModelTree.class)
            .register(List.class)
            .register(ArrayList.class)
            .register(JsonNode.class)
            .register(ObjectNode.class)
            .register(TextNode.class)
            .register(LinkedHashMap.class)
            .register(ArrayNode.class)
            .register(BaseJsonNode.class)
            .register(BigIntegerNode.class)
            .register(BinaryNode.class)
            .register(BooleanNode.class)
            .register(ContainerNode.class)
            .register(DecimalNode.class)
            .register(DoubleNode.class)
            .register(FloatNode.class)
            .register(IntNode.class)
            .register(JsonNodeType.class)
            .register(LongNode.class)
            .register(MissingNode.class)
            .register(NullNode.class)
            .register(NumericNode.class)
            .register(POJONode.class)
            .register(ShortNode.class)
            .register(ValueNode.class)
            .register(JsonNodeCreator.class)
            .register(JsonNodeFactory.class)
            .build();

    localWorkplaceMap.clear();
    workplaceMap = storageService.<String, WorkflowData>consistentMapBuilder()
            .withSerializer(Serializer.using(workplaceNamespace))
            .withName("workplace-map")
            .withApplicationId(appId)
            .build();
    workplaceMap.addListener(workplaceMapEventListener);

    localContextMap.clear();
    contextMap = storageService.<String, WorkflowData>consistentMapBuilder()
            .withSerializer(Serializer.using(workplaceNamespace))
            .withName("workflow-context-map")
            .withApplicationId(appId)
            .build();
    contextMap.addListener(contextMapEventListener);

    workplaceMapEventListener.syncLocal();
    contextMapEventListener.syncLocal();
    log.info("Started");
}
 
Example #28
Source File: JsonConverter.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public JsonNode toJson(Object object) throws IOException {
	if (object instanceof SBase) {
		SBase base = (SBase) object;
		ObjectNode jsonObject = OBJECT_MAPPER.createObjectNode();
		jsonObject.put("__type", base.getSClass().getSimpleName());
		for (SField field : base.getSClass().getAllFields()) {
			jsonObject.set(field.getName(), toJson(base.sGet(field)));
		}
		return jsonObject;
	} else if (object instanceof Collection) {
		Collection<?> collection = (Collection<?>) object;
		ArrayNode jsonArray = OBJECT_MAPPER.createArrayNode();
		for (Object value : collection) {
			jsonArray.add(toJson(value));
		}
		return jsonArray;
	} else if (object instanceof Date) {
		return new LongNode(((Date) object).getTime());
	} else if (object instanceof DataHandler) {
		DataHandler dataHandler = (DataHandler) object;
		InputStream inputStream = dataHandler.getInputStream();
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		IOUtils.copy(inputStream, out);
		return new TextNode(new String(Base64.encodeBase64(out.toByteArray()), Charsets.UTF_8));
	} else if (object instanceof Boolean) {
		return BooleanNode.valueOf((Boolean) object);
	} else if (object instanceof String) {
		return new TextNode((String) object);
	} else if (object instanceof Long) {
		return new LongNode((Long) object);
	} else if (object instanceof UUID) {
		return new TextNode(((UUID) object).toString());
	} else if (object instanceof Integer) {
		return new IntNode((Integer) object);
	} else if (object instanceof Double) {
		return new DoubleNode((Double) object);
	} else if (object instanceof Float) {
		return new FloatNode((Float) object);
	} else if (object instanceof Enum) {
		return new TextNode(object.toString());
	} else if (object == null) {
		return NullNode.getInstance();
	} else if (object instanceof byte[]) {
		byte[] data = (byte[]) object;
		return new TextNode(new String(Base64.encodeBase64(data), Charsets.UTF_8));
	}
	throw new UnsupportedOperationException(object.getClass().getName());
}
 
Example #29
Source File: Fill.java    From bce-sdk-java with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public void setValue(long value) {
    this.value = new LongNode(value);
}
 
Example #30
Source File: CommonPointOfCompromise.java    From log-synth with Apache License 2.0 4 votes vote down vote up
@Override
public JsonNode sample() {
    ArrayNode r = nodeFactory.arrayNode();

    double t = start;
    double averageInterval = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS) / transactionsPerDay.nextDouble();
    Exponential interval = new Exponential(1 / averageInterval, gen);

    Date date = new Date();
    boolean compromised = false;
    while (t < end) {
        ObjectNode transaction = new ObjectNode(nodeFactory);
        t += interval.nextDouble();
        date.setTime((long) t);
        transaction.set("timestamp", new LongNode((long) (t / 1000)));
        transaction.set("date", new TextNode(df.format(date)));
        Integer merchantId = merchant.sample();
        transaction.set("merchant", new IntNode(merchantId));

        if (merchantId == 0 && t >= compromiseStart && t < compromiseEnd) {
            compromised = true;
            transaction.set("compromise", new IntNode(1));
        } else {
            transaction.set("compromise", new IntNode(0));
        }

        if (t > exploitEnd) {
            compromised = false;
        }

        double pFraud;
        if (t >= exploitStart && compromised) {
            pFraud = compromisedFraudRate;
        } else {
            pFraud = uncompromisedFraudRate;
        }

        transaction.set("fraud", new IntNode((gen.nextDouble() < pFraud) ? 1 : 0));

        r.add(transaction);
    }
    return r;
}