List of usage examples for com.mongodb BasicDBObjectBuilder get
public DBObject get()
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Exports a test run with encrypted password properties by test and run * name./*ww w . j a v a 2 s . com*/ * * @param testName * (String, mandatory) test name * @param runName * (String, mandatory) run name * * @return (DBObject) or exception * * @throws ObjectNotFoundException * @throws CipherException * * @since 2.1.2 */ public DBObject exportTestRun(String testName, String runName) throws ObjectNotFoundException, CipherException { ArgumentCheck.checkMandatoryString(testName, "testName"); ArgumentCheck.checkMandatoryString(runName, "runName"); // get object IDs ObjectId testObjId = getTestId(testName); ObjectId runObjId = getTestRunId(testObjId, runName); if (null == testObjId) { throw new ObjectNotFoundException(testName + "." + runName); } // get test definition DBObject queryObj = QueryBuilder.start(FIELD_ID).is(testObjId).get(); BasicDBObjectBuilder fieldsObjBuilder = BasicDBObjectBuilder.start(FIELD_NAME, 1).add(FIELD_VERSION, true) .add(FIELD_RELEASE, true).add(FIELD_SCHEMA, true); DBObject fieldsObj = fieldsObjBuilder.get(); DBObject testObj = tests.findOne(queryObj, fieldsObj); if (testObj == null) { throw new ObjectNotFoundException(testName + "." + runName); } // get values from test String release = (String) testObj.get(FIELD_RELEASE); Object tmp = testObj.get(FIELD_SCHEMA); Integer schema = null == tmp ? 0 : Integer.valueOf(tmp.toString()); tmp = testObj.get(FIELD_VERSION); Integer version = null == tmp ? 0 : Integer.valueOf(tmp.toString()); // get properties Set<String> maskedProps = getMaskedProperyNames(testName); Map<String, DBObject> mapProps = getTestRunPropertiesMap(testObjId, runObjId, testName, runName); // encrypt passwords for (final String propName : maskedProps) { DBObject propDbObj = mapProps.get(propName); if (null != propDbObj) { // encrypt propDbObj = encryptPropertyValue(propDbObj, propName); mapProps.put(propName, propDbObj); } } // prepare return object DBObject exportObj = new BasicDBObject(); exportObj.put(FIELD_TEST, testName); exportObj.put(FIELD_RUN, runName); exportObj.put(FIELD_RELEASE, release); exportObj.put(FIELD_SCHEMA, schema); exportObj.put(FIELD_VERSION, version); // Turn into a map and add BasicDBList propsList = MongoTestDAO.getPropertyList(mapProps); exportObj.put(FIELD_PROPERTIES, propsList); return exportObj; }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
/** * {@inheritDoc}//from w ww .j a va 2 s .co m */ @Override public void createNewUser(UserData data) { BasicDBObjectBuilder insertObjBuilder = BasicDBObjectBuilder.start() .add(FIELD_RANDOMIZER, data.getRandomizer()).add(FIELD_USERNAME, data.getUsername()) .add(FIELD_PASSWORD, data.getPassword()) .add(FIELD_CREATION_STATE, data.getCreationState().toString()) .add(FIELD_FIRST_NAME, data.getFirstName()).add(FIELD_LAST_NAME, data.getLastName()) .add(FIELD_EMAIL, data.getEmail()).add(FIELD_DOMAIN, data.getDomain()) .add(FIELD_GROUPS, data.getGroups()); DBObject insertObj = insertObjBuilder.get(); try { collection.insert(insertObj); } catch (DuplicateKeyException e) { // We just rethrow as per the API throw e; } }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public long countUsers(String domain, DataCreationState creationState) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start(); if (domain != null) { queryObjBuilder.add(FIELD_DOMAIN, domain); }//from w ww.j av a 2 s.co m if (creationState != null) { queryObjBuilder.add(FIELD_CREATION_STATE, creationState.toString()); } DBObject queryObj = queryObjBuilder.get(); return collection.count(queryObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public long deleteUsers(DataCreationState creationState) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start(); if (creationState != null) { queryObjBuilder.add(FIELD_CREATION_STATE, creationState.toString()); }/*from w w w . j av a 2 s . c o m*/ DBObject queryObj = queryObjBuilder.get(); WriteResult result = collection.remove(queryObj); return result.getN(); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
private Range getRandomizerRange(List<String> domains) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start().add(FIELD_CREATION_STATE, DataCreationState.Created.toString()); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }/*from w ww.j ava2 s. c o m*/ DBObject queryObj = queryObjBuilder.get(); DBObject fieldsObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, Boolean.TRUE).get(); DBObject sortObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, -1).get(); // Find max DBObject resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int maxRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); // Find min sortObj.put(FIELD_RANDOMIZER, +1); resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int minRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); return new Range(minRandomizer, maxRandomizer); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public UserData getRandomUserFromDomains(List<String> domains) { Range range = getRandomizerRange(domains); int upper = range.getMax(); int lower = range.getMin(); int random = lower + (int) (Math.random() * (double) (upper - lower)); BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start() .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()).push(FIELD_RANDOMIZER) .add("$gte", random).pop(); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }//from w ww. ja va2 s . c om DBObject queryObj = queryObjBuilder.get(); DBObject userDataObj = collection.findOne(queryObj); return fromDBObject(userDataObj); }
From source file:org.alfresco.cacheserver.dao.mongo.MongoWebSocketDAO.java
License:Open Source License
protected DBCollection getCappedCollection(DB db, String collectionName, Integer maxCollectionSize, Integer maxDocuments, WriteConcern writeConcern) { if (!db.collectionExists(collectionName)) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.add("capped", true); if (maxCollectionSize != null) { builder.add("size", maxCollectionSize); }/* w w w . java 2s.c om*/ if (maxDocuments != null) { builder.add("max", maxDocuments); } DBObject options = builder.get(); db.createCollection(collectionName, options); } DBCollection collection = db.getCollection(collectionName); collection.setWriteConcern(writeConcern); return collection; }
From source file:org.alfresco.cacheserver.dao.mongo.MongoWebSocketDAO.java
License:Open Source License
private DBObject fromRegistration(Registration registration) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("u", registration.getUsername()).add("i", registration.getIpAddress()); return builder.get(); }
From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java
License:Open Source License
@Override public void updateNode(NodeInfo nodeInfo) { String cacheServerId = serverIdentity.getId(); String nodeId = nodeInfo.getNode().getNodeId(); // String versionLabel = nodeInfo.getNode().getVersionLabel(); Long nodeInternalId = nodeInfo.getNode().getNodeInternalId(); Long nodeVersion = nodeInfo.getNode().getNodeVersion(); MimeType mimeType = nodeInfo.getMimeType(); Long size = nodeInfo.getSize(); String nodePath = nodeInfo.getNode().getNodePath(); String contentPath = nodeInfo.getContentPath(); boolean isPrimary = nodeInfo.isPrimary(); QueryBuilder queryBuilder = QueryBuilder.start("e").is(cacheServerId).and("n").is(nodeId); if (nodeVersion != null) { queryBuilder.and("v").is(nodeVersion); }//from ww w . j a v a2 s. c o m if (nodeInternalId != null) { queryBuilder.and("ni").is(nodeInternalId); } DBObject query = queryBuilder.get(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("$set", BasicDBObjectBuilder.start("m", mimeType.getMimetype()).add("s", size).add("ni", nodeInternalId) .add("c", contentPath).add("p", nodePath).add("pri", isPrimary).get()); DBObject update = builder.get(); WriteResult result = contentData.update(query, update, true, false); checkResult(result); }
From source file:org.alfresco.contentstore.dao.mongo.MongoNodeUsageDAO.java
License:Open Source License
private DBObject fromNodeUsageInfo(NodeUsage nodeUsage) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("e", serverIdentity.getId()) .add("n", nodeUsage.getNodeId()).add("v", nodeUsage.getNodeVersion()) .add("t", nodeUsage.getTimestamp()).add("u", nodeUsage.getUsername()); return builder.get(); }