Java Code Examples for org.bson.Document#getBoolean()
The following examples show how to use
org.bson.Document#getBoolean() .
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: MongoIndex.java From presto with Apache License 2.0 | 6 votes |
public static List<MongoIndex> parse(ListIndexesIterable<Document> indexes) { ImmutableList.Builder<MongoIndex> builder = ImmutableList.builder(); for (Document index : indexes) { // TODO: v, ns, sparse fields Document key = (Document) index.get("key"); String name = index.getString("name"); boolean unique = index.getBoolean("unique", false); if (key.containsKey("_fts")) { // Full Text Search continue; } builder.add(new MongoIndex(name, parseKey(key), unique)); } return builder.build(); }
Example 2
Source File: MongoTogglzRepository.java From edison-microservice with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected FeatureState decode(final Document document) { final String name = document.getString(NAME); final Boolean enabled = document.getBoolean(ENABLED); final String strategy = document.getString(STRATEGY); final Map<String, String> parameters = document.get(PARAMETERS, Map.class); final FeatureState featureState = new FeatureState(resolveEnumValue(name)); featureState.setEnabled(enabled); featureState.setStrategyId(strategy); for (final Map.Entry<String, String> parameter : parameters.entrySet()) { featureState.setParameter(parameter.getKey(), parameter.getValue()); } return featureState; }
Example 3
Source File: Snapshot.java From QVisual with Apache License 2.0 | 6 votes |
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 4
Source File: TestMongoClient.java From jframe with Apache License 2.0 | 6 votes |
public void testDatabase() { ListDatabasesIterable<Document> list = mongoClient.listDatabases(); MongoCursor<Document> iterD = list.iterator(); while (iterD.hasNext()) { Document doc = iterD.next(); System.out.println(doc); if (!doc.getBoolean("empty", true)) { System.out.println(mongoClient.getDatabase(doc .getString("name"))); } } // MongoIterable<String> mongo = mongoClient.listDatabaseNames(); // MongoCursor<String> iter = mongo.iterator(); // while (iter.hasNext()) { // System.out.println(iter.next()); // } }
Example 5
Source File: TestMongoClientService.java From jframe with Apache License 2.0 | 6 votes |
public void testDatabase() { MongoClient mongoClient = mongo.getClient("mongo1"); ListDatabasesIterable<Document> list = mongoClient.listDatabases(); MongoCursor<Document> iterD = list.iterator(); while (iterD.hasNext()) { Document doc = iterD.next(); System.out.println(doc); if (!doc.getBoolean("empty", true)) { System.out.println(mongoClient.getDatabase(doc .getString("name"))); } } // MongoIterable<String> mongo = mongoClient.listDatabaseNames(); // MongoCursor<String> iter = mongo.iterator(); // while (iter.hasNext()) { // System.out.println(iter.next()); // } }
Example 6
Source File: MongoSession.java From presto with Apache License 2.0 | 5 votes |
private MongoColumnHandle buildColumnHandle(Document columnMeta) { String name = columnMeta.getString(FIELDS_NAME_KEY); String typeString = columnMeta.getString(FIELDS_TYPE_KEY); boolean hidden = columnMeta.getBoolean(FIELDS_HIDDEN_KEY, false); Type type = typeManager.fromSqlType(typeString); return new MongoColumnHandle(name, type, hidden); }
Example 7
Source File: TodoItem.java From stitch-examples with Apache License 2.0 | 5 votes |
public TodoItem(final Document document) { _id = document.getObjectId("_id"); _text = document.getString("text"); if (document.containsKey("checked")) { _checked = document.getBoolean("checked"); } else { _checked = false; } }
Example 8
Source File: TodoItem.java From stitch-android-sdk with Apache License 2.0 | 5 votes |
/** 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 9
Source File: CoreUserApiKeyAuthProviderClient.java From stitch-android-sdk with Apache License 2.0 | 5 votes |
/** * Decodes a BSON value from the given reader into an instance of the type parameter {@code T}. * * @param reader the BSON reader * @param decoderContext the decoder context * @return an instance of the type parameter {@code T}. */ @Override public UserApiKey decode(final BsonReader reader, final DecoderContext decoderContext) { final Document document = (new DocumentCodec()).decode(reader, decoderContext); keyPresent(ApiKeyFields.ID, document); keyPresent(ApiKeyFields.NAME, document); keyPresent(ApiKeyFields.DISABLED, document); return new UserApiKey( document.getString(ApiKeyFields.ID), document.getString(ApiKeyFields.KEY), document.getString(ApiKeyFields.NAME), document.getBoolean(ApiKeyFields.DISABLED) ); }
Example 10
Source File: BluePrint.java From Much-Assembly-Required with GNU General Public License v3.0 | 5 votes |
public BluePrint(Document document) { requiredItems = (Map<Integer, Integer>) document.get("required_items"); completed = document.getBoolean("completed"); try { targetObject = Class.forName(document.getString("target")).asSubclass(GameObject.class); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
Example 11
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
private void createTransactionsGlobalTxKeyIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> transactions = database.getCollection(CONSTANTS_TB_TRANSACTIONS); ListIndexesIterable<Document> transactionIndexList = transactions.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> transactionCursor = null; try { transactionCursor = transactionIndexList.iterator(); while (transactionIndexExists == false && transactionCursor.hasNext()) { Document document = transactionCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(transactionCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); transactions.createIndex(index, new IndexOptions().unique(true)); } }
Example 12
Source File: MongoCompensableLock.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
private void createLocksIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> locks = database.getCollection(CONSTANTS_TB_LOCKS); ListIndexesIterable<Document> lockIndexList = locks.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> lockCursor = null; try { lockCursor = lockIndexList.iterator(); while (transactionIndexExists == false && lockCursor.hasNext()) { Document document = lockCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(lockCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); locks.createIndex(index, new IndexOptions().unique(true)); } }
Example 13
Source File: RestSemanticController.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public boolean deleteDescriptor(String uri, String descriptor, String contType) { boolean isSuccess = false; try { OneM2mResponse resMessage = null; if(uri == null || uri.equals("") || descriptor == null || descriptor.equals("") || contType == null || contType.equals("") ) { return false; } String semanticEngineUri = this.semanticRestURL + "delete"; RestSemanticCI param = new RestSemanticCI(); param.setParamUri(uri); param.setParamDescriptor(descriptor); param.setParamContentType(contType); JSONConvertor<RestSemanticCI> cvtRcr = (JSONConvertor<RestSemanticCI>) ConvertorFactory.getJSONConvertor(RestSemanticCI.class, null); String jsonParam = cvtRcr.marshal(param); OneM2mRequest reqMessage = new OneM2mRequest(); reqMessage.setContent(jsonParam.getBytes()); reqMessage.setTo(extractToFromFullUri(semanticEngineUri)); reqMessage.setOperation(OPERATION.CREATE); reqMessage.setContentType(CONTENT_TYPE.JSON); resMessage = HttpClient.getInstance().sendRequest(semanticEngineUri, reqMessage); byte[] body = resMessage.getContent(); String resJson = new String(resMessage.getContent()); Document resDoc = Document.parse(resJson); isSuccess = resDoc.getBoolean("ret"); } catch (Exception e) { log.error("deleteDescriptor", e); } return isSuccess; }
Example 14
Source File: RestSemanticController.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public boolean deleteDescriptor(String uri, String descriptor, String contType) { boolean isSuccess = false; try { OneM2mResponse resMessage = null; if(uri == null || uri.equals("") || descriptor == null || descriptor.equals("") || contType == null || contType.equals("") ) { return false; } String semanticEngineUri = this.semanticRestURL + "delete"; RestSemanticCI param = new RestSemanticCI(); param.setParamUri(uri); param.setParamDescriptor(descriptor); param.setParamContentType(contType); JSONConvertor<RestSemanticCI> cvtRcr = (JSONConvertor<RestSemanticCI>) ConvertorFactory.getJSONConvertor(RestSemanticCI.class, null); String jsonParam = cvtRcr.marshal(param); OneM2mRequest reqMessage = new OneM2mRequest(); reqMessage.setContent(jsonParam.getBytes()); reqMessage.setTo(extractToFromFullUri(semanticEngineUri)); reqMessage.setOperation(OPERATION.CREATE); reqMessage.setContentType(CONTENT_TYPE.JSON); resMessage = HttpClient.getInstance().sendRequest(semanticEngineUri, reqMessage); byte[] body = resMessage.getContent(); String resJson = new String(resMessage.getContent()); Document resDoc = Document.parse(resJson); isSuccess = resDoc.getBoolean("ret"); } catch (Exception e) { log.error("deleteDescriptor", e); } return isSuccess; }
Example 15
Source File: RestSemanticController.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public boolean addDescriptor(String uri, String descriptor, String contType) { boolean isSuccess = false; try { OneM2mResponse resMessage = null; if(uri == null || uri.equals("") || descriptor == null || descriptor.equals("") || contType == null || contType.equals("") ) { return false; } String semanticEngineUri = this.semanticRestURL + "add"; RestSemanticCI param = new RestSemanticCI(); param.setParamUri(uri); param.setParamDescriptor(descriptor); param.setParamContentType(contType); JSONConvertor<RestSemanticCI> cvtRcr = (JSONConvertor<RestSemanticCI>) ConvertorFactory.getJSONConvertor(RestSemanticCI.class, null); String jsonParam = cvtRcr.marshal(param); OneM2mRequest reqMessage = new OneM2mRequest(); reqMessage.setContent(jsonParam.getBytes()); reqMessage.setTo(extractToFromFullUri(semanticEngineUri)); reqMessage.setOperation(OPERATION.CREATE); reqMessage.setContentType(CONTENT_TYPE.JSON); resMessage = HttpClient.getInstance().sendRequest(semanticEngineUri, reqMessage); byte[] body = resMessage.getContent(); String resJson = new String(resMessage.getContent()); Document resDoc = Document.parse(resJson); isSuccess = resDoc.getBoolean("ret"); } catch (Exception e) { log.error("addDescriptor", e); } return isSuccess; }
Example 16
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
private List<CompensableArchive> constructCompensableList(Document document) throws Exception { XidFactory transactionXidFactory = this.beanFactory.getTransactionXidFactory(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); List<CompensableArchive> resourceList = new ArrayList<CompensableArchive>(); Document compensables = document.get("compensables", Document.class); for (Iterator<String> itr = compensables.keySet().iterator(); itr.hasNext();) { String key = itr.next(); Document element = compensables.get(key, Document.class); CompensableArchive service = new CompensableArchive(); String gxid = element.getString(CONSTANTS_FD_GLOBAL); String bxid = element.getString(CONSTANTS_FD_BRANCH); boolean coordinatorFlag = element.getBoolean("coordinator"); boolean tried = element.getBoolean("tried"); boolean confirmed = element.getBoolean("confirmed"); boolean cancelled = element.getBoolean("cancelled"); String serviceId = element.getString("serviceId"); boolean simplified = element.getBoolean("simplified"); String confirmableKey = element.getString("confirmable_key"); String cancellableKey = element.getString("cancellable_key"); String argsValue = element.getString("args"); String clazzName = element.getString("interface"); String methodDesc = element.getString("method"); String transactionKey = element.getString("transaction_key"); String compensableKey = element.getString("compensable_key"); String transactionXid = element.getString("transaction_xid"); String compensableXid = element.getString("compensable_xid"); CompensableInvocationImpl invocation = new CompensableInvocationImpl(); invocation.setIdentifier(serviceId); invocation.setSimplified(simplified); Class<?> clazz = cl.loadClass(clazzName); Method method = SerializeUtils.deserializeMethod(clazz, methodDesc); invocation.setMethod(method); byte[] argsByteArray = ByteUtils.stringToByteArray(argsValue); Object[] args = (Object[]) SerializeUtils.deserializeObject(argsByteArray); invocation.setArgs(args); invocation.setConfirmableKey(confirmableKey); invocation.setCancellableKey(cancellableKey); service.setCompensable(invocation); service.setConfirmed(confirmed); service.setCancelled(cancelled); service.setTried(tried); service.setCoordinator(coordinatorFlag); service.setTransactionResourceKey(transactionKey); service.setCompensableResourceKey(compensableKey); String[] transactionArray = transactionXid.split("\\s*\\-\\s*"); if (transactionArray.length == 3) { String transactionGlobalId = transactionArray[1]; String transactionBranchId = transactionArray[2]; TransactionXid transactionGlobalXid = transactionXidFactory .createGlobalXid(ByteUtils.stringToByteArray(transactionGlobalId)); if (StringUtils.isNotBlank(transactionBranchId)) { TransactionXid transactionBranchXid = transactionXidFactory.createBranchXid(transactionGlobalXid, ByteUtils.stringToByteArray(transactionBranchId)); service.setTransactionXid(transactionBranchXid); } else { service.setTransactionXid(transactionGlobalXid); } } String[] compensableArray = compensableXid.split("\\s*\\-\\s*"); if (compensableArray.length == 3) { String compensableGlobalId = compensableArray[1]; String compensableBranchId = compensableArray[2]; TransactionXid compensableGlobalXid = transactionXidFactory .createGlobalXid(ByteUtils.stringToByteArray(compensableGlobalId)); if (StringUtils.isNotBlank(compensableBranchId)) { TransactionXid compensableBranchXid = transactionXidFactory.createBranchXid(compensableGlobalXid, ByteUtils.stringToByteArray(compensableBranchId)); service.setCompensableXid(compensableBranchXid); } else { service.setCompensableXid(compensableGlobalXid); } } byte[] globalTransactionId = ByteUtils.stringToByteArray(gxid); byte[] branchQualifier = ByteUtils.stringToByteArray(bxid); TransactionXid globalId = transactionXidFactory.createGlobalXid(globalTransactionId); TransactionXid branchId = transactionXidFactory.createBranchXid(globalId, branchQualifier); service.setIdentifier(branchId); resourceList.add(service); } return resourceList; }
Example 17
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
private List<XAResourceArchive> constructParticipantList(Document document) { XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory(); List<XAResourceArchive> resourceList = new ArrayList<XAResourceArchive>(); Document participants = document.get("participants", Document.class); for (Iterator<String> itr = participants.keySet().iterator(); itr.hasNext();) { String key = itr.next(); Document element = participants.get(key, Document.class); XAResourceArchive participant = new XAResourceArchive(); String gxid = element.getString(CONSTANTS_FD_GLOBAL); String bxid = element.getString(CONSTANTS_FD_BRANCH); String descriptorType = element.getString("type"); String identifier = element.getString("resource"); int vote = element.getInteger("vote"); boolean committed = element.getBoolean("committed"); boolean rolledback = element.getBoolean("rolledback"); boolean readonly = element.getBoolean("readonly"); boolean completed = element.getBoolean("completed"); boolean heuristic = element.getBoolean("heuristic"); byte[] globalTransactionId = ByteUtils.stringToByteArray(gxid); byte[] branchQualifier = ByteUtils.stringToByteArray(bxid); TransactionXid globalId = compensableXidFactory.createGlobalXid(globalTransactionId); TransactionXid branchId = compensableXidFactory.createBranchXid(globalId, branchQualifier); participant.setXid(branchId); XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer(); XAResourceDescriptor descriptor = resourceDeserializer.deserialize(identifier); if (descriptor != null // && descriptor.getClass().getName().equals(descriptorType) == false) { throw new IllegalStateException(); } participant.setVote(vote); participant.setCommitted(committed); participant.setRolledback(rolledback); participant.setReadonly(readonly); participant.setCompleted(completed); participant.setHeuristic(heuristic); participant.setDescriptor(descriptor); resourceList.add(participant); } return resourceList; }
Example 18
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
@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; }
Example 19
Source File: RestSemanticController.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public boolean addDescriptor(String uri, String descriptor, String contType) { boolean isSuccess = false; try { OneM2mResponse resMessage = null; if(uri == null || uri.equals("") || descriptor == null || descriptor.equals("") || contType == null || contType.equals("") ) { return false; } String semanticEngineUri = this.semanticRestURL + "add"; RestSemanticCI param = new RestSemanticCI(); param.setParamUri(uri); param.setParamDescriptor(descriptor); param.setParamContentType(contType); JSONConvertor<RestSemanticCI> cvtRcr = (JSONConvertor<RestSemanticCI>) ConvertorFactory.getJSONConvertor(RestSemanticCI.class, null); String jsonParam = cvtRcr.marshal(param); OneM2mRequest reqMessage = new OneM2mRequest(); reqMessage.setContent(jsonParam.getBytes()); reqMessage.setTo(extractToFromFullUri(semanticEngineUri)); reqMessage.setOperation(OPERATION.CREATE); reqMessage.setContentType(CONTENT_TYPE.JSON); resMessage = HttpClient.getInstance().sendRequest(semanticEngineUri, reqMessage); byte[] body = resMessage.getContent(); String resJson = new String(resMessage.getContent()); Document resDoc = Document.parse(resJson); isSuccess = resDoc.getBoolean("ret"); } catch (Exception e) { log.error("addDescriptor", e); } return isSuccess; }
Example 20
Source File: ConnectionValidator.java From mongo-kafka with Apache License 2.0 | 4 votes |
/** * Checks the roles info document for matching actions and removes them from the provided list * * <p>See: https://docs.mongodb.com/manual/reference/command/rolesInfo See: * https://docs.mongodb.com/manual/reference/resource-document/ */ private static List<String> removeUserActions( final Document rolesInfo, final String authDatabase, final String databaseName, final String collectionName, final List<String> userActions) { List<Document> privileges = rolesInfo.getList("inheritedPrivileges", Document.class, emptyList()); if (privileges.isEmpty() || userActions.isEmpty()) { return userActions; } List<String> unsupportedUserActions = new ArrayList<>(userActions); for (final Document privilege : privileges) { Document resource = privilege.get("resource", new Document()); if (resource.containsKey("cluster") && resource.getBoolean("cluster")) { unsupportedUserActions.removeAll(privilege.getList("actions", String.class, emptyList())); } else if (resource.containsKey("db") && resource.containsKey("collection")) { String database = resource.getString("db"); String collection = resource.getString("collection"); boolean resourceMatches = false; boolean collectionMatches = collection.isEmpty() || collection.equals(collectionName); if (database.isEmpty() && collectionMatches) { resourceMatches = true; } else if (database.equals(authDatabase) && collection.isEmpty()) { resourceMatches = true; } else if (database.equals(databaseName) && collectionMatches) { resourceMatches = true; } if (resourceMatches) { unsupportedUserActions.removeAll(privilege.getList("actions", String.class, emptyList())); } } if (unsupportedUserActions.isEmpty()) { break; } } return unsupportedUserActions; }