List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start(final String key, final Object val)
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchIndexer.java
License:Open Source License
public void reindexNode(NodeUpdatedEvent event) throws IOException { AlfrescoNode node = makeAlfrescoNode(event); long nodeInternalId = node.getNodeInternalId(); String nodeId = node.getNodeId(); long nodeVersion = node.getNodeVersion(); String versionLabel = getVersionLabel(event); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("n", nodeId).add("nid", nodeInternalId) .add("v", nodeVersion).add("l", versionLabel); NodeVersionKey nodeVersionKey = new NodeVersionKey(nodeInternalId, nodeVersion); String changeTxnId = node.getChangeTxnId(); Long txnId = node.getTxnId(); String nodeType = node.getType(); Set<String> aspects = node.getAspects(); Map<String, Serializable> serializedProperties = node.getProperties(); Map<String, Serializable> deserializedProperties = propertySerializer.deserialize(serializedProperties); nodeMetadataSerializer.buildNodeMetadata(builder, nodeVersionKey, changeTxnId, txnId, nodeType, deserializedProperties, aspects); String json = builder.get().toString(); String id = buildIndexId(event); UpdateResponse response = elasticSearchClient.reindex(indexName, id, IndexType.node, json, true); logger.debug("Re-indexed node " + id + ", " + nodeId + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchIndexer.java
License:Open Source License
public void reindexNode(org.alfresco.events.types.NodeUpdatedEvent event) throws IOException { AlfrescoNode node = makeAlfrescoNode(event); String nodeId = node.getNodeId(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("n", nodeId); String changeTxnId = node.getChangeTxnId(); String nodeType = node.getType(); Set<String> aspects = node.getAspects(); Map<String, Serializable> serializedProperties = node.getProperties(); Map<String, Serializable> deserializedProperties = propertySerializer.deserialize(serializedProperties); nodeMetadataSerializer.buildNodeMetadata(builder, nodeId, changeTxnId, nodeType, deserializedProperties, aspects);//from www . j ava 2 s .com String json = builder.get().toString(); String id = buildIndexId(event); UpdateResponse response = elasticSearchClient.reindex(indexName, id, IndexType.node, json, true); logger.debug("Re-indexed node " + id + ", " + nodeId + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchIndexer.java
License:Open Source License
public void indexContent(NodeContentPutEvent event) throws IOException { String nodeId = event.getNodeId(); long nodeVersion = event.getNodeVersion(); long nodeInternalId = event.getNodeInternalId(); String nodeType = event.getNodeType(); String versionLabel = getVersionLabel(event); List<String> paths = event.getPaths(); String path = null;//from w w w.ja va 2 s . c o m if (paths != null && paths.size() > 0) { path = paths.get(0); } try { // GetTextContentResponse response = contentGetter.getContentByNodeId(nodeInternalId); Content content = contentGetter.getContentByNodeId(nodeInternalId); ReadableByteChannel channel = (content != null ? content.getChannel() : null); if (channel != null) { String str = getContent(channel); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("n", nodeId).add("nid", nodeInternalId) .add("t", nodeType).add("p", path) // .add("_n", nodeInternalId) .add("v", nodeVersion).add("l", versionLabel) // .add("c_enc", base64); .add("c", str); String id = buildIndexId(event); String json = builder.get().toString(); UpdateResponse esResponse = elasticSearchClient.reindex(indexName, id, IndexType.content, json, false); logger.debug("Re-indexed content " + nodeId + ", " + builder.get() + "response " + esResponse.getId() + ", " + esResponse.getType() + ", " + esResponse.getIndex() + ", " + esResponse.getVersion()); } else { logger.debug("No content for " + nodeInternalId + "." + nodeVersion); } } catch (Exception e) { throw new ElasticsearchException("", e); } }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchMonitoringIndexer.java
License:Open Source License
public void indexSync(SyncEvent event) { String syncId = event.getSyncId(); String username = event.getUsername(); long timestampMS = event.getTimestamp(); Integer numSyncChanges = event.getNumSyncChanges(); Integer numConflicts = event.getNumConflicts(); long duration = event.getDuration(); boolean isSuccess = event.isSuccess(); String siteId = event.getSiteId(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("syncId", syncId).add("u", username) .add("tim", timestampMS).add("ti", timestampMS).add("duration", duration) .add("isSuccess", isSuccess).add("s", siteId); if (numSyncChanges != null) { builder.add("numSyncChanges", numSyncChanges); }//from www . j a va 2 s .c om if (numConflicts != null) { builder.add("numConflicts", numConflicts); } String id = event.getId(); String json = builder.get().toString(); IndexResponse response = elasticSearchClient.index(indexName, id, IndexType.sync, json, true); logger.debug("Indexed sync start " + id + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchMonitoringIndexer.java
License:Open Source License
public void indexMonitoring(HistogramMonitoringEvent event) { long timestampMS = event.getTimestamp(); String type = event.getType(); Histogram data = event.getData();// w w w .j a va 2 s . c o m BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("mt", type).add("tim", timestampMS) .add("ti", timestampMS).add("max", data.getMax()).add("min", data.getMin()) .add("mean", data.getMean()).add("p50", data.getP50()).add("p75", data.getP75()) .add("p95", data.getP95()).add("p98", data.getP98()).add("p99", data.getP99()) .add("p999", data.getP999()).add("stdev", data.getStddev()); String id = event.getId(); String json = builder.get().toString(); IndexResponse response = elasticSearchClient.index(indexName, id, IndexType.monitoring, json, true); logger.debug("Indexed monitoring " + id + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchMonitoringIndexer.java
License:Open Source License
public void indexMonitoring(TimerMonitoringEvent event) { long timestampMS = event.getTimestamp(); String type = event.getType(); Timer data = event.getData(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("mt", type).add("tim", timestampMS) .add("ti", timestampMS).add("max", data.getMax()).add("min", data.getMin()) .add("mean", data.getMean()).add("p50", data.getP50()).add("p75", data.getP75()) .add("p95", data.getP95()).add("p98", data.getP98()).add("p99", data.getP99()) .add("p999", data.getP999()).add("stdev", data.getStddev()).add("m1_rate", data.getM1_rate()) .add("m5_rate", data.getM5_rate()).add("m15_rate", data.getM15_rate()) .add("mean_rate", data.getMean_rate()); String id = event.getId();/* ww w . j a v a2s .c o m*/ String json = builder.get().toString(); IndexResponse response = elasticSearchClient.index(indexName, id, IndexType.monitoring, json, true); logger.debug("Indexed monitoring " + id + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.alfresco.service.common.elasticsearch.ElasticSearchMonitoringIndexer.java
License:Open Source License
public void indexMonitoring(GaugeMonitoringEvent event) { long timestampMS = event.getTimestamp(); String type = event.getType(); long data = event.getData(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("mt", type).add("tim", timestampMS) .add("ti", timestampMS).add("value", data); String id = event.getId();//from w w w.ja va 2 s . com String json = builder.get().toString(); IndexResponse response = elasticSearchClient.index(indexName, id, IndexType.monitoring, json, true); logger.debug("Indexed monitoring " + id + ", " + builder.get() + "response " + response.getId() + ", " + response.getType() + ", " + response.getIndex() + ", " + response.getVersion()); }
From source file:org.apache.camel.component.gridfs.GridFsConsumer.java
License:Apache License
@Override public void run() { DBCursor c = null;/*from w w w. ja va2s. co m*/ java.util.Date fromDate = null; QueryStrategy s = endpoint.getQueryStrategy(); boolean usesTimestamp = (s != QueryStrategy.FileAttribute); boolean persistsTimestamp = (s == QueryStrategy.PersistentTimestamp || s == QueryStrategy.PersistentTimestampAndFileAttribute); boolean usesAttribute = (s == QueryStrategy.FileAttribute || s == QueryStrategy.TimeStampAndFileAttribute || s == QueryStrategy.PersistentTimestampAndFileAttribute); DBCollection ptsCollection = null; DBObject persistentTimestamp = null; if (persistsTimestamp) { ptsCollection = endpoint.getDB().getCollection(endpoint.getPersistentTSCollection()); // ensure standard indexes as long as collections are small try { if (ptsCollection.count() < 1000) { ptsCollection.createIndex(new BasicDBObject("id", 1)); } } catch (MongoException e) { //TODO: Logging } persistentTimestamp = ptsCollection.findOne(new BasicDBObject("id", endpoint.getPersistentTSObject())); if (persistentTimestamp == null) { persistentTimestamp = new BasicDBObject("id", endpoint.getPersistentTSObject()); fromDate = new java.util.Date(); persistentTimestamp.put("timestamp", fromDate); ptsCollection.save(persistentTimestamp); } fromDate = (java.util.Date) persistentTimestamp.get("timestamp"); } else if (usesTimestamp) { fromDate = new java.util.Date(); } try { Thread.sleep(endpoint.getInitialDelay()); while (isStarted()) { if (c == null || c.getCursorId() == 0) { if (c != null) { c.close(); } String queryString = endpoint.getQuery(); DBObject query; if (queryString == null) { query = new BasicDBObject(); } else { query = (DBObject) JSON.parse(queryString); } if (usesTimestamp) { query.put("uploadDate", new BasicDBObject("$gt", fromDate)); } if (usesAttribute) { query.put(endpoint.getFileAttributeName(), null); } c = endpoint.getFilesCollection().find(query); } boolean dateModified = false; while (c.hasNext() && isStarted()) { GridFSDBFile file = (GridFSDBFile) c.next(); GridFSDBFile forig = file; if (usesAttribute) { file.put(endpoint.getFileAttributeName(), "processing"); DBObject q = BasicDBObjectBuilder.start("_id", file.getId()).append("camel-processed", null) .get(); forig = (GridFSDBFile) endpoint.getFilesCollection().findAndModify(q, null, null, false, file, true, false); } if (forig != null) { file = endpoint.getGridFs().findOne(new BasicDBObject("_id", file.getId())); Exchange exchange = endpoint.createExchange(); exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType()); exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength()); exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate()); exchange.getIn().setBody(file.getInputStream(), InputStream.class); try { getProcessor().process(exchange); //System.out.println("Processing " + file.getFilename()); if (usesAttribute) { forig.put(endpoint.getFileAttributeName(), "done"); endpoint.getFilesCollection().save(forig); } if (usesTimestamp) { if (file.getUploadDate().compareTo(fromDate) > 0) { fromDate = file.getUploadDate(); dateModified = true; } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (persistsTimestamp && dateModified) { persistentTimestamp.put("timestamp", fromDate); ptsCollection.save(persistentTimestamp); } Thread.sleep(endpoint.getDelay()); } } catch (Throwable e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (c != null) { c.close(); } }
From source file:org.apache.karaf.jaas.modules.mongo.internal.DefaultUserDetailService.java
License:Apache License
@Override public UserInfo addUser(UserInfo user) throws Exception { DB db = getDB();// w w w . j a va 2 s . c om DBCollection users = db.getCollection(configuration.getUserCollectionName()); DBCollection roles = db.getCollection(configuration.getGroupCollectionName()); DBObject storedUser = users.findOne(new BasicDBObject().append("username", user.getName())); if (storedUser == null) { users.insert(BasicDBObjectBuilder.start("username", user.getName()) .append("passwordHash", user.getPassword()).get()); } else { // will not do anything here } for (String role : user.getGroups()) { DBObject roleQuery = new BasicDBObject("name", role); // roles are unique by name DBObject roleData = roles.findOne(roleQuery, ROLE_PROJECTION); if (roleData == null) { // add role with user as first member BasicDBList members = new BasicDBList(); members.add(user.getName()); roleData = BasicDBObjectBuilder.start().add("name", role).add("members", members).get(); roles.insert(roleData); } else { // add user to group if not already in the role's member list Object mo = roleData.get("members"); if (mo == null) { // TODO what here? BasicDBObject updateObject = new BasicDBObject().append("$push", new BasicDBObject("members", user.getName())); roles.update(roleQuery, updateObject); } else if (mo != null && mo instanceof List) { // if user is in group already we dont need to do anything List<?> existingMembers = (List<?>) mo; if (!existingMembers.contains(user.getName())) { // push this user to the members list BasicDBObject updateObject = new BasicDBObject().append("$push", new BasicDBObject("members", user.getName())); roles.update(roleQuery, updateObject); } } else { log.warn("The members collection of group [{}] is not a list but of type [{}].", role, mo.getClass().getName()); } } } return user; }
From source file:org.apache.rya.indexing.geotemporal.mongo.GeoTemporalMongoDBStorageStrategy.java
License:Apache License
@Override public DBObject serialize(final RyaStatement ryaStatement) { final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode()); final URI obj = ryaStatement.getObject().getDataType(); if (obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try {//from w w w . j a v a2 s . co m final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { builder.add(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return builder.get(); }