@Nullable @Override public String apply(ObjectId input) { return input.toHexString(); } }
@Override public void serialize(ObjectId value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(value.toHexString()); } }
@Override public String getStreamId() { return ((ObjectId) fields.get(FIELD_STREAM_ID)).toHexString(); }
@Override public String getId() { // Performance - toHexString is expensive so we cache it. final String s = hexId.get(); if (s == null && id != null) { final String hexString = getObjectId().toHexString(); hexId.compareAndSet(null, hexString); return hexString; } return s; }
@Override public Map<String, Object> asMap() { return ImmutableMap.<String, Object>builder() .put("id", ((ObjectId) fields.get("_id")).toHexString()) .put(FIELD_TITLE, fields.get(FIELD_TITLE)) .put(FIELD_QUERY, fields.get(FIELD_QUERY)) .put(FIELD_CREATED_AT, Tools.getISO8601String((DateTime) fields.get(FIELD_CREATED_AT))) .put(FIELD_CREATOR_USER_ID, fields.get(FIELD_CREATOR_USER_ID)) .build(); }
private boolean isDeletable(ObjectId id) { return streamService.loadAllWithIndexSet(id.toHexString()).isEmpty(); } }
protected Set<Output> loadOutputsForRawStream(DBObject stream) { @SuppressWarnings("unchecked") List<ObjectId> outputIds = (List<ObjectId>) stream.get(StreamImpl.FIELD_OUTPUTS); Set<Output> result = new HashSet<>(); if (outputIds != null) for (ObjectId outputId : outputIds) try { result.add(outputService.load(outputId.toHexString())); } catch (NotFoundException e) { LOG.warn("Non-existing output <{}> referenced from stream <{}>!", outputId.toHexString(), stream.get("_id")); } return result; }
@Override public Map<String, Long> streamRuleCountByStream() { final ImmutableMap.Builder<String, Long> streamRules = ImmutableMap.builder(); try(DBCursor streamIds = collection(StreamImpl.class).find(new BasicDBObject(), new BasicDBObject("_id", 1))) { for (DBObject keys : streamIds) { final ObjectId streamId = (ObjectId) keys.get("_id"); streamRules.put(streamId.toHexString(), streamRuleCount(streamId)); } } return streamRules.build(); }
public static CollectorActions create(String sidecar_id, DateTime created, List<CollectorAction> action) { return create( new org.bson.types.ObjectId().toHexString(), sidecar_id, created, action); } }
public static Configuration create(String collectorId, String name, String color, String template) { return create(new org.bson.types.ObjectId().toHexString(), collectorId, name, color, template); }
public static ConfigurationVariable create(String name, String description, String content) { return create(new org.bson.types.ObjectId().toHexString(), name, description, content); }
@Override public void addOutputs(ObjectId streamId, Collection<ObjectId> outputIds) { final BasicDBList outputs = new BasicDBList(); outputs.addAll(outputIds); collection(StreamImpl.class).update( new BasicDBObject("_id", streamId), new BasicDBObject("$addToSet", new BasicDBObject(StreamImpl.FIELD_OUTPUTS, new BasicDBObject("$each", outputs))) ); clusterEventBus.post(StreamsChangedEvent.create(streamId.toHexString())); }
@Override public AlarmCallbackHistory error(AlarmCallbackConfiguration alarmCallbackConfiguration, Alert alert, AlertCondition alertCondition, String error) { return AlarmCallbackHistoryImpl.create(new ObjectId().toHexString(), alarmCallbackConfiguration, alert, alertCondition, AlarmCallbackError.create(error)); }
@Override public AlarmCallbackHistory success(AlarmCallbackConfiguration alarmCallbackConfiguration, Alert alert, AlertCondition alertCondition) { return AlarmCallbackHistoryImpl.create(new ObjectId().toHexString(), alarmCallbackConfiguration, alert, alertCondition, AlarmCallbackSuccess.create()); }
public static Sidecar create(@JsonProperty(FIELD_NODE_ID) String nodeId, @JsonProperty(FIELD_NODE_NAME) String nodeName, @JsonProperty(FIELD_NODE_DETAILS) NodeDetails nodeDetails, @JsonProperty(FIELD_SIDECAR_VERSION) String sidecarVersion) { return builder() .id(new org.bson.types.ObjectId().toHexString()) .nodeId(nodeId) .nodeName(nodeName) .nodeDetails(nodeDetails) .sidecarVersion(sidecarVersion) .lastSeen(DateTime.now(DateTimeZone.UTC)) .build(); }
@Override public AlarmCallbackConfiguration create(String streamId, CreateAlarmCallbackRequest request, String userId) { return AlarmCallbackConfigurationImpl.create(new ObjectId().toHexString(), streamId, request.type(), request.title(), request.configuration(), new Date(), userId); }
@Override public Output create(CreateOutputRequest request, String userId) throws ValidationException { return create(OutputImpl.create(new ObjectId().toHexString(), request.title(), request.type(), userId, request.configuration(), Tools.nowUTC().toDate(), request.contentPack())); }
public Optional<IndexFieldTypesDTO> upsert(IndexFieldTypesDTO dto) { final WriteResult<IndexFieldTypesDTO, ObjectId> update = db.update( DBQuery.and( DBQuery.is(IndexFieldTypesDTO.FIELD_INDEX_NAME, dto.indexName()), DBQuery.is(IndexFieldTypesDTO.FIELD_INDEX_SET_ID, dto.indexSetId()) ), dto, true, false ); final Object upsertedId = update.getUpsertedId(); if (upsertedId instanceof ObjectId) { return get(((ObjectId) upsertedId).toHexString()); } else if (upsertedId instanceof String) { return get((String) upsertedId); } return Optional.empty(); }
public static AlertImpl fromCheckResult(AlertCondition.CheckResult checkResult) { return create(new org.bson.types.ObjectId().toHexString(), checkResult.getTriggeredCondition().getStream().getId(), checkResult.getTriggeredCondition().getId(), checkResult.getTriggeredAt(), null, checkResult.getResultDescription(), ImmutableMap.copyOf(checkResult.getTriggeredCondition().getParameters()), true); }
public Stream load(ObjectId id) throws NotFoundException { final DBObject o = get(StreamImpl.class, id); if (o == null) { throw new NotFoundException("Stream <" + id + "> not found!"); } final List<StreamRule> streamRules = streamRuleService.loadForStreamId(id.toHexString()); final Set<Output> outputs = loadOutputsForRawStream(o); @SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap(); return new StreamImpl((ObjectId) o.get("_id"), fields, streamRules, outputs, getIndexSet(o)); }