Java Code Examples for org.bson.Document#getDate()

The following examples show how to use org.bson.Document#getDate() . 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: Snapshot.java    From QVisual with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 2
Source File: TodoItem.java    From stitch-android-sdk with Apache License 2.0 5 votes vote down vote up
/** Constructs a todo item from a MongoDB document. */
TodoItem(final Document todoItemDoc) {
  this.id = todoItemDoc.getObjectId(ID_KEY);
  this.task = todoItemDoc.getString(TASK_KEY);
  this.checked = todoItemDoc.getBoolean(CHECKED_KEY);
  if (todoItemDoc.containsKey(DONE_DATE_KEY)) {
    this.doneDate = todoItemDoc.getDate(DONE_DATE_KEY);
  }
}
 
Example 3
Source File: Reference.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a document to a reference.
 * 
 * @param document
 * 
 * @return a reference.
 */
@SuppressWarnings("unchecked")
public static Reference parseDocument(Document document) {
	Reference r = new Reference(document.getObjectId("_id"),
			document.getObjectId("repository"),
			document.getString("name"),
			document.getString("path"),
			ReferenceType.valueOf(document.getString("type")),
			document.getDate("last_commit_date"),
			document.get("commits", List.class));

	return r;
}
 
Example 4
Source File: Commit.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a document to a commit.
 * 
 * @param document
 * 
 * @return a commit.
 */
@SuppressWarnings("unchecked")
public static Commit parseDocument(Document document) {
	Commit commit = new Commit(document.getObjectId("_id"), document.getString("hash"),
			Developer.parseDocument(document.get("author", Document.class)),
			Developer.parseDocument(document.get("committer", Document.class)), document.getString("message"),
			Change.parseDocuments(document.get("changes", List.class)), document.get("parents", List.class),
			document.getDate("author_date"), document.getDate("committer_date"),
			document.getBoolean("merge", false), document.getObjectId("repository"));
	return commit;
}
 
Example 5
Source File: CmdIdxAccessStats.java    From mongodb-slow-operations-profiler with GNU Affero General Public License v3.0 5 votes vote down vote up
private TableDto getIndexStats(MongoCollection<Document> collection, String dbsLabel){
    final TableDto result = new TableDto();
    final MongoIterable<Document> stats = collection
            .aggregate(Arrays.asList(
                    new Document("$indexStats", new Document()),
                    new Document("$sort", new Document("accesses.ops", 1))
            ));
    final HashMap<String, Document> indexesProperties = getIndexesProperties(collection);

    for(Document doc : stats){
        LOG.info("doc: {}", JSON.serialize(doc));
        final ArrayList<Object> row = new ArrayList<Object>();
        row.add(dbsLabel);
        row.add(doc.getString("host"));
        row.add(collection.getNamespace().getDatabaseName());
        row.add(collection.getNamespace().getCollectionName());
        final String indexName = doc.getString("name");
        row.add(indexName);
        row.add(((Document)doc.get("key")).toJson());
        row.add(Boolean.toString(isTTL(indexesProperties, indexName)));
        final Object accesses = doc.get("accesses");
        if(accesses instanceof Document){
            final Document accDoc = (Document) accesses;
            row.add(accDoc.getLong("ops"));
            final Date date = accDoc.getDate("since");
            final LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
            row.add(localDateTime.format(DATE_TIME_FORMATTER));
        }else{
            row.add(0L);
            row.add("");
        }

        result.addRow(row);

    }

    return result;
}
 
Example 6
Source File: MongoCompensableLogger.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TransactionArchive reconstructTransactionArchive(Document document) throws Exception {
	XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory();

	boolean propagated = document.getBoolean("propagated");
	String propagatedBy = document.getString("propagated_by");
	boolean compensable = document.getBoolean("compensable");
	boolean coordinator = document.getBoolean("coordinator");
	int compensableStatus = document.getInteger("status");
	// boolean error = document.getBoolean("error");
	Integer recoveredTimes = document.getInteger("recovered_times");
	Date recoveredAt = document.getDate("recovered_at");

	TransactionArchive archive = new TransactionArchive();

	String global = document.getString(CONSTANTS_FD_GLOBAL);
	byte[] globalByteArray = ByteUtils.stringToByteArray(global);
	TransactionXid globalXid = compensableXidFactory.createGlobalXid(globalByteArray);
	archive.setXid(globalXid);

	String textVariables = document.getString("variables");
	byte[] variablesByteArray = null;
	if (StringUtils.isNotBlank(textVariables) && StringUtils.equals(textVariables, "null") == false) {
		variablesByteArray = ByteUtils.stringToByteArray(textVariables);
	}

	if (variablesByteArray == null || variablesByteArray.length == 0) {
		archive.setVariables(new HashMap<String, Serializable>());
	} else {
		Map<String, Serializable> variables = //
				(Map<String, Serializable>) SerializeUtils.deserializeObject(variablesByteArray);
		archive.setVariables(variables);
	}

	archive.setRecoveredAt(recoveredAt == null ? 0 : recoveredAt.getTime());
	archive.setRecoveredTimes(recoveredTimes == null ? 0 : recoveredTimes);

	archive.setCompensable(compensable);
	archive.setCoordinator(coordinator);
	archive.setCompensableStatus(compensableStatus);
	archive.setPropagated(propagated);
	archive.setPropagatedBy(propagatedBy);

	archive.getRemoteResources().addAll(this.constructParticipantList(document));
	archive.getCompensableResourceList().addAll(this.constructCompensableList(document));

	return archive;
}