Date recoveredAt = document.getDate("recovered_at");
@Test public void testIsMaster() throws Exception { Document isMaster = db.runCommand(new Document("isMaster", Integer.valueOf(1))); assertThat(isMaster.getBoolean("ismaster")).isTrue(); assertThat(isMaster.getDate("localTime")).isInstanceOf(Date.class); assertThat(isMaster.getInteger("maxBsonObjectSize")).isGreaterThan(1000); assertThat(isMaster.getInteger("maxMessageSizeBytes")).isGreaterThan(isMaster.getInteger("maxBsonObjectSize")); }
private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
public static <T extends Token> TokenDocument<T> from(Document document) { String type = document.getString("type"); assert type != null : "type is null"; TokenDocument<T> tokenDocument; UserInfo userInfoObject = new UserInfo(new JSONObject((Map<String,?>)document.get("userInfo"))); ClientID clientIdObj = new ClientID(document.getString("clientId")); LoginSessionToken loginSession = document.getString("sessionId") != null ? new LoginSessionToken(document.getString("sessionId")) : null; Date created = document.getDate("created"); if (TokenType.ACCESS.name().equals(type)) { long tokenLifetime = (document.getDate("expires").getTime() - created.getTime()) / 1000; BearerAccessToken bearerAccessToken = new BearerAccessToken(document.getString("_id"), tokenLifetime, null); tokenDocument = (TokenDocument<T>) new TokenDocument<BearerAccessToken>(bearerAccessToken, created, clientIdObj, loginSession, userInfoObject); } else if (TokenType.REFRESH.name().equals(type)) { int tokenLifetime = 0; if (document.getDate("expires") != null) { tokenLifetime = (int) (document.getDate("expires").getTime() - created.getTime()) / 1000; } RefreshToken refreshToken = new RefreshToken(document.getString("_id")); tokenDocument = (TokenDocument<T>) new TokenDocument<RefreshToken>(refreshToken, created, clientIdObj, loginSession, userInfoObject, tokenLifetime); } else { throw new IllegalArgumentException("unknow token type " + type); } tokenDocument.refreshTokenRef = document.getString("refreshTokenRef"); return tokenDocument; }
private JobMessage toJobMessage(final Document document) { return jobMessage( Level.valueOf(document.get(JobStructure.MSG_LEVEL.key()).toString()), getMessage(document), toOffsetDateTime(document.getDate(JobStructure.MSG_TS.key())) ); }
private JobMessage toJobMessage(final Document document) { return jobMessage( Level.valueOf(document.get(JobStructure.MSG_LEVEL.key()).toString()), getMessage(document), DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.MSG_TS.key())) ); }
@Override protected final JobInfo decode(final Document document) { return newJobInfo( document.getString(JobStructure.ID.key()), document.getString(JobStructure.JOB_TYPE.key()), DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.STARTED.key())), DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.LAST_UPDATED.key())), ofNullable(DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.STOPPED.key()))), JobStatus.valueOf(document.getString(JobStructure.STATUS.key())), getMessagesFrom(document), clock, document.getString(JobStructure.HOSTNAME.key())); }
@Override protected final JobInfo decode(final Document document) { return newJobInfo( document.getString(JobStructure.ID.key()), document.getString(JobStructure.JOB_TYPE.key()), toOffsetDateTime(document.getDate(JobStructure.STARTED.key())), toOffsetDateTime(document.getDate(JobStructure.LAST_UPDATED.key())), ofNullable(toOffsetDateTime(document.getDate(JobStructure.STOPPED.key()))), JobStatus.valueOf(document.getString(JobStructure.STATUS.key())), getMessagesFrom(document), clock, document.getString(JobStructure.HOSTNAME.key())); }
/** * Retrieves a lock by key * * @param lockKey key * @return LockEntry */ LockEntry findByKey(String lockKey) { Document result = collection.find(new Document().append(LockEntry.KEY_FIELD, lockKey)).first(); if (result != null) { return new LockEntry( result.getString(LockEntry.KEY_FIELD), result.getString(LockEntry.STATUS_FIELD), result.getString(LockEntry.OWNER_FIELD), result.getDate(LockEntry.EXPIRES_AT_FIELD) ); } return null; }
@Override public void updateOrInsertChange(Change change, DeployExecution deployExecution) { MongoCollection<Document> auditCollection = getAuditCollection(change); MutableList<Document> docs = iterableToCollection(auditCollection.find(getChangeFilter(change))); if (docs.size() > 1) { throw new IllegalStateException("Not expecting multiple changes for this key [" + change.getObjectName() + "." + change.getChangeName() + "], but found " + docs); } else if (docs.isEmpty()) { insertNewChange(change, deployExecution); } else { Document previousDoc = docs.get(0); Date timeInserted = previousDoc.getDate(timeInsertedColumn); auditCollection.replaceOne(getChangeFilter(change), createDocFromChange(change, deployExecution, timeInserted)); } }
private ContainerTrace toContainerTrace(Document doc){ ContainerTrace trace = new ContainerTrace(); trace.setNodeId(doc.getString("nodeId")); trace.setQueueSize(doc.getInteger("queueSize")); trace.setCountOfQueueBuffer(doc.getInteger("queueBuffer")); trace.setCountOfLiveThread(doc.getInteger("liveThread")); trace.setCreated(doc.getDate("created")); return trace; } }
@Override public void updateOrInsertChange(Change change, DeployExecution deployExecution) { MongoCollection<Document> auditCollection = getAuditCollection(change); MutableList<Document> docs = iterableToCollection(auditCollection.find(getChangeFilter(change))); if (docs.size() > 1) { throw new IllegalStateException("Not expecting multiple changes for this key [" + change.getObjectName() + "." + change.getChangeName() + "], but found " + docs); } else if (docs.isEmpty()) { insertNewChange(change, deployExecution); } else { Document previousDoc = docs.get(0); Date timeInserted = previousDoc.getDate(timeInsertedColumn); auditCollection.replaceOne(getChangeFilter(change), createDocFromChange(change, deployExecution, timeInserted)); } }
private IndexConfig toIndexConfig(Document doc){ IndexConfig config = new IndexConfig(); config.setId(doc.getString("_id")); config.setModified(doc.getDate("modified")); config.setCreated(doc.getDate("created")); config.setArgsIndexes(doc.getString("argsIndexes")); config.setResultIndexes(doc.getString("resultIndexes")); config.setEventName(doc.getString("eventName")); config.setWildcard(doc.getBoolean("wildcard")); config.setMatched(doc.getBoolean("matched")); config.setWildcardId(doc.getString("wildcardId")); config.setGroup(doc.getString("group")); return config; }
@Override public DeployExecution valueOf(Document doc) { MutableList<Document> attrsList = ListAdapter.adapt(doc.get("attrs", List.class)); MutableList<DeployExecutionAttribute> attrs = attrsList.collect(new Function<Document, DeployExecutionAttribute>() { @Override public DeployExecutionAttribute valueOf(Document object) { return new DeployExecutionAttributeImpl( object.getString(attrNameColName), object.getString(attrValueColName) ); } }); DeployExecutionImpl exec = new DeployExecutionImpl( doc.getString(requesterIdColName), doc.getString(deployExecutionIdColName), doc.getString(dbSchemaColName), doc.getString(toolVersionColName), new Timestamp(doc.getDate(deployTimeColName).getTime()), doc.getBoolean(initCommandColName), doc.getBoolean(rollbackCommandColName), doc.getString(productVersionColName), doc.getString(reasonColName), attrs.toSet().toImmutable() ); exec.setId(doc.getLong(idColName)); return exec; } }).toImmutable();
protected NodeInfo toNodeInfo(Document doc){ NodeInfo nodeInfo = new NodeInfo(); nodeInfo.setName(doc.getString("name")); nodeInfo.setStart(doc.getDate("lastStart")); nodeInfo.setStat(doc.getInteger("stat")); nodeInfo.setGroup(doc.getString("group")); nodeInfo.setHost(doc.getString("host")); nodeInfo.setId(doc.getString("_id")); return nodeInfo; }
public void setMetadataDoc(Document doc) { setId(doc.getString("pid")); setLinked(doc.getBoolean("linked", false)); setLabel(doc.getString("label")); setType(PayloadType.valueOf(doc.getString("payloadType"))); setContentType(doc.getString("contentType")); lastModified = doc.getDate("lastModified"); getBackend().setId(doc.getString("payloadId")); }
public Snapshot(Document dbObject) { this.server = dbObject.getString("server"); this.branch = dbObject.getString("branch"); this.commit = dbObject.getString("commit"); this.testcaseId = dbObject.getString("testcaseId"); this.story = dbObject.getString("story"); this.state = dbObject.getString("state"); this.datetime = dbObject.getDate("datetime"); this.elements = dbObject.getString("elements"); this.url = dbObject.getString("url"); this.device = dbObject.getString("device"); this.osName = dbObject.getString("osName"); this.osVersion = dbObject.getString("osVersion"); this.browserName = dbObject.getString("browserName"); this.browserVersion = dbObject.getString("browserVersion"); this.resolution = dbObject.getString("resolution"); this.retina = dbObject.getBoolean("retina"); }
@Test public void sample_105() throws Exception { final MongoDatabase db = MongoClients .create() .getDatabase("rx"); Observable<Integer> days = db.getCollection("months") .find(Filters.eq("name", APRIL.name())) .projection(Projections.include("days_not_leap")) .first() .map(doc -> doc.getInteger("days_not_leap")); Observable<Instant> carManufactured = db.getCollection("cars") .find(Filters.eq("owner.name", "Smith")) .first() .map(doc -> doc.getDate("manufactured")) .map(Date::toInstant); Observable<BigDecimal> pricePerDay = dailyPrice(LocalDateTime.now()); Observable<Insurance> insurance = Observable .zip(days, carManufactured, pricePerDay, (d, man, price) -> { //Create insurance return new Insurance(); }); }
private MonitorEventInfoModel toMonitorEventInfo(Document doc, NodeInfo nodeInfo){ MonitorEventInfoModel info = new MonitorEventInfoModel(); info.setId(doc.getObjectId("_id").toString()); info.setNodeId(doc.getString("nodeId")); info.setEventCreate(doc.getDate("eventCreated")); info.setException(doc.getString("exception")); info.setListenerClazz(doc.getString("listenerClass")); info.setFromNodeId(doc.getString("fromNodeId")); info.setSuccess(doc.getBoolean("success")); info.setTook(doc.getLong("took")); info.setEventArgs(doc.getString("args")); info.setEventResult(doc.getString("result")); info.setEventId(doc.getString("eventId")); info.setEventName(doc.getString("eventName")); info.setMdcValue(doc.getString("mdcValue")); info.setEventConsumed(doc.getDate("eventConsumed")); if(null != nodeInfo){ info.setNodeName(nodeInfo.getName()); info.setNodeGroup(nodeInfo.getGroup()); info.setNodeHost(nodeInfo.getHost()); } return info; }