List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchIndexer.java
License:Open Source License
public void indexEvent(org.alfresco.events.types.NodeEvent event) throws IOException { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); String nodeId = event.getNodeId(); String changeTxnId = event.getTxnId(); Long timestampMS = event.getTimestamp(); String username = event.getUsername(); String site = event.getSiteId(); List<String> paths = event.getPaths(); String nodeType = event.getNodeType(); if (site == null) { site = ""; }/*from w w w . j a v a2 s . c o m*/ String networkId = event.getNetworkId(); if (networkId == null) { networkId = ""; } org.alfresco.repo.Client client = event.getClient(); String clientId = (client != null ? client.getClientId() : null); if (clientId == null) { clientId = ""; } String path = null; if (paths != null && paths.size() > 0) { path = paths.get(0); } builder.add("t", event.getType()).add("u", username).add("ct", changeTxnId).add("ti", timestampMS) .add("tim", timestampMS).add("n", nodeId).add("s", site).add("ne", networkId).add("c", clientId) .add("nt", nodeType); if (path != null) { builder.add("p", path); } String id = event.getId(); String json = builder.get().toString(); IndexResponse response = elasticSearchClient.index(indexName, id, IndexType.event, json, true); logger.debug("Indexed event " + id + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.apache.airavata.userprofile.core.UserProfileDao.java
License:Apache License
/** * The following operation replaces the document with item equal to * the given user id. The newly replaced document will only * contain the the _id field and the fields in the replacement document. * @param userProfile/* www . jav a2 s. c om*/ * @throws org.apache.airavata.registry.cpi.UserProfileException */ public boolean updateUserProfile(UserProfile userProfile) throws UserProfileException { try { DBObject query = BasicDBObjectBuilder.start().add(USER_ID, userProfile.getUserId()).get(); WriteResult result = collection.update(query, (DBObject) JSON.parse(modelConversionHelper.serializeObject(userProfile))); logger.debug("No of updated results " + result.getN()); return true; } catch (JsonProcessingException e) { throw new UserProfileException(e); } }
From source file:org.apache.airavata.userprofile.core.UserProfileDao.java
License:Apache License
public boolean deleteUserProfile(String userId) throws UserProfileException { DBObject query = BasicDBObjectBuilder.start().add(USER_ID, userId).get(); WriteResult result = collection.remove(query); logger.debug("No of removed user profiles " + result.getN()); return true;// w w w . jav a 2 s.c o m }
From source file:org.apache.camel.component.mongodb.MongoDbTailTrackingManager.java
License:Apache License
public synchronized void persistToStore() { if (!config.persistent || lastVal == null) { return;// w ww . j av a 2 s. c om } if (LOG.isDebugEnabled()) { LOG.debug("Persisting lastVal={} to store, collection: {}", lastVal, config.collection); } DBObject updateObj = BasicDBObjectBuilder.start().add("$set", new BasicDBObject(config.field, lastVal)) .get(); dbCol.update(trackingObj, updateObj, false, false, WriteConcern.SAFE); trackingObj = dbCol.findOne(); }
From source file:org.apache.karaf.jaas.modules.mongo.internal.DefaultUserDetailService.java
License:Apache License
@Override public UserInfo getUserInfo(String username) throws Exception { DB db = getDB();/*from w ww.j a v a2s. c om*/ DBCollection users = db.getCollection(configuration.getUserCollectionName()); // populate user DBObject userQuery = new BasicDBObject("username", username); BasicDBObjectBuilder userProjectionBuilder = BasicDBObjectBuilder.start().add("_id", 0).add("username", 1) .add("passwordHash", 1); // also add all custom user fields for (String prop : configuration.getAdditionalAttributes()) { userProjectionBuilder.add(prop, 1); } DBObject user = users.findOne(userQuery, userProjectionBuilder.get()); // if nothing comes back just return empty handed if (user == null) { return null; } UserInfo userInfo = new UserInfo().withName((String) user.get("username")) .withPassword((String) user.get("passwordHash")); for (String prop : configuration.getAdditionalAttributes()) { // only add if property is actually present in the database if (user.containsField(prop)) { Object val = user.get(prop); userInfo.addProperty(prop, val != null ? val.toString() : ""); } } // populate group DBCollection groups = db.getCollection(configuration.getGroupCollectionName()); DBObject groupQuery = new BasicDBObject("members", username); DBCursor gc = groups.find(groupQuery, BasicDBObjectBuilder.start().append("_id", 0).append("name", 1).get()); while (gc.hasNext()) { DBObject group = gc.next(); userInfo.addGroup((String) group.get("name")); } gc.close(); return userInfo; }
From source file:org.apache.rya.export.mongo.parent.ParentMetadataRepositoryAdapter.java
License:Apache License
/** * Serializes the {@link MergeParentMetadata} into a mongoDB object. * @param metadata - The {@link MergeParentMetadata} to serialize. * @return The MongoDB object// ww w.j a va 2 s .co m */ public DBObject serialize(final MergeParentMetadata metadata) { final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start() .add(RYANAME_KEY, metadata.getRyaInstanceName()).add(TIMESTAMP_KEY, metadata.getTimestamp()) .add(FILTER_TIMESTAMP_KEY, metadata.getFilterTimestamp()) .add(PARENT_TIME_OFFSET_KEY, metadata.getParentTimeOffset()); return builder.get(); }
From source file:org.apache.rya.indexing.mongodb.temporal.TemporalMongoDBStorageStrategy.java
License:Apache License
public DBObject getTimeValue(final String timeData) { final Matcher match = TemporalInstantRfc3339.PATTERN.matcher(timeData); final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); if (match.find()) { final TemporalInterval date = TemporalInstantRfc3339.parseInterval(timeData); builder.add(INTERVAL_START, date.getHasBeginning().getAsDateTime().toDate()); builder.add(INTERVAL_END, date.getHasEnd().getAsDateTime().toDate()); } else {//from w w w .jav a 2 s .c o m builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate()); } return builder.get(); }
From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java
License:Apache License
/** * Checks if the field intersects the set. * @param field the field to check.//from w ww . j av a2 s.c om * @param set the set to check. * @return the $setIntersection expression {@link BasicDBObject}. */ public static BasicDBObject setIntersection(final String field, final Object[] set) { final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); return (BasicDBObject) setIntersection(builder, field, set).get(); }
From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java
License:Apache License
/** * Checks if the expression is a subset of the set. * @param expression the expression to see if it's in the set. * @param set the set to check against.// ww w .ja v a 2 s . co m * @return the $setIsSubset expression {@link BasicDBObject}. */ public static BasicDBObject setIsSubset(final DBObject expression, final Object[] set) { final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); return (BasicDBObject) setIsSubset(builder, expression, set).get(); }
From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java
License:Apache License
/** * Checks if the field is a subset of the set and is safe if the field is * null./*from w w w. j ava 2 s . c om*/ * @param field the field to see if it's in the set. * @param set the set to check against. * @return the $setIsSubset expression {@link BasicDBObject}. */ public static BasicDBObject setIsSubsetNullSafe(final String field, final Object[] set) { final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); return (BasicDBObject) setIsSubsetNullSafe(builder, field, set).get(); }