List of usage examples for com.mongodb BasicDBObjectBuilder get
public DBObject get()
From source file:org.alfresco.events.serialize.NodeAddedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); return builder.get(); }
From source file:org.alfresco.events.serialize.NodeCheckedOutEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeCheckedOutEvent) { NodeCheckedOutEvent nodeCheckedOutEvent = (NodeCheckedOutEvent) nodeEvent; builder.add(FIELD_CHECKED_OUT_NODE_ID, nodeCheckedOutEvent.getCheckedOutNodeId()); }// w w w.j a v a2 s . co m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeContentPutEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeContentPutEvent) { NodeContentPutEvent nodeCPEvent = (NodeContentPutEvent) nodeEvent; builder.add(FIELD_SIZE, nodeCPEvent.getSize()).add(FIELD_ENCODING, nodeCPEvent.getEncoding()) .add(FIELD_MIME_TYPE, nodeCPEvent.getMimeType()); }/* ww w .ja va2 s .c o m*/ return builder.get(); }
From source file:org.alfresco.events.serialize.NodeMovedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeMovedEvent) { NodeMovedEvent nodeMovedEvent = (NodeMovedEvent) nodeEvent; List<String> toPaths = nodeMovedEvent.getToPaths(); String toPathStr = toPaths.get(0); Path toPath = new Path(toPathStr); String newName = nodeMovedEvent.getNewName(); builder.add(FIELD_TO_PARENT_NODE_IDS, nodeMovedEvent.getToParentNodeIds()) .add(FIELD_PRIMARY_TO_PATH, (toPath != null ? toPath.getArrayPath() : null)) .add(FIELD_NODE_NEW_NAME, newName); }//from w w w. j a va 2s. c o m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeRenamedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeRenamedEvent) { NodeRenamedEvent nodeRenamedEvent = (NodeRenamedEvent) nodeEvent; List<String> toPaths = nodeRenamedEvent.getToPaths(); String toPathStr = toPaths.get(0); Path toPath = new Path(toPathStr); String newName = nodeRenamedEvent.getNewName(); builder.add(FIELD_PRIMARY_TO_PATH, (toPath != null ? toPath.getArrayPath() : null)) .add(FIELD_NODE_NEW_NAME, newName); }//from www.j a va 2 s . c o m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeUpdatedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeUpdatedEvent) { NodeUpdatedEvent nodeUpdatedEvent = (NodeUpdatedEvent) nodeEvent; Set<String> aspectsAdded = nodeUpdatedEvent.getAspectsAdded(); if (aspectsAdded != null) { builder.add("aspectsAdded", aspectsAdded); }/* w w w . ja v a2s . co m*/ Set<String> aspectsRemoved = nodeUpdatedEvent.getAspectsRemoved(); if (aspectsRemoved != null) { builder.add("aspectsRemoved", aspectsRemoved); } Map<String, Property> propsAdded = nodeUpdatedEvent.getPropertiesAdded(); if (propsAdded != null) { List<DBObject> propertiesAdded = new ArrayList<DBObject>(propsAdded.size()); for (Map.Entry<String, Property> entry : propsAdded.entrySet()) { Property prop = entry.getValue(); DBObject propDbObject = propertySerializer.serialize(prop); propertiesAdded.add(propDbObject); } builder.add("propertiesAdded", propertiesAdded); } Map<String, Property> propsChanged = nodeUpdatedEvent.getPropertiesChanged(); if (propsChanged != null) { List<DBObject> propertiesChanged = new ArrayList<DBObject>(propsChanged.size()); for (Map.Entry<String, Property> entry : propsChanged.entrySet()) { Property prop = entry.getValue(); DBObject propDbObject = propertySerializer.serialize(prop); propertiesChanged.add(propDbObject); } builder.add("propertiesChanged", propertiesChanged); } Set<String> propsRemoved = nodeUpdatedEvent.getPropertiesRemoved(); if (propsRemoved != null) { builder.add("propertiesRemoved", propsRemoved); } } return builder.get(); }
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
public DBObject serialize(Property property) { String name = property.getName(); DataType type = property.getDataType(); Object value = property.getValue(); // Use the value as is for the data types: // DataType.Text, DataType.Int, DataType.Long, DataType.Float, DataType.Double, DataType.Boolean if (value != null) { if (type == null || type == DataType.Any) { value = value.toString();/*from w w w . ja va2 s . com*/ } else if (type == DataType.Encrypted) { value = "*****"; } else if (type == DataType.Content) { // don't do anything with content properties (they're handled by contentput events) value = null; // ContentData contentData = (ContentData)value; // String contentUrl = contentData.getContentUrl(); // String encoding = contentData.getEncoding(); // String mimeType = contentData.getMimetype(); // contentData. } else if (type == DataType.Mltext) { MLText mlText = (MLText) value; BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); for (Locale locale : mlText.getLocales()) { String languageTag = locale.toLanguageTag(); String mlValue = mlText.getValue(locale); builder.add(languageTag, mlValue); } value = builder.get(); } else if (type == DataType.Date || type == DataType.Datetime) { Date date = (Date) value; value = ISO8601DateFormat.format(date); } else if (type == DataType.Qname) { QName qname = (QName) value; value = qname.toPrefixString(); } else if (type == DataType.Noderef) { NodeRef nodeRef = (NodeRef) value; value = serializeNodeRef(nodeRef); } else if (type == DataType.Childassocref) { ChildAssociationRef assocRef = (ChildAssociationRef) value; value = serializeChildAssocRef(assocRef); } else if (type == DataType.Assocref) { AssociationRef assocRef = (AssociationRef) value; value = serializeAssocRef(assocRef); } else if (type == DataType.Path) { Path path = (Path) value; value = serializePath(path); } else if (type == DataType.Category) { NodeRef nodeRef = (NodeRef) value; value = serializeNodeRef(nodeRef); } else if (type == DataType.Locale) { Locale locale = (Locale) value; value = locale.toLanguageTag(); } else if (type == DataType.Version) { VersionNumber versionNumber = (VersionNumber) value; value = versionNumber.getParts(); } else if (type == DataType.Period) { Period period = (Period) value; String periodType = period.getPeriodType(); String expression = period.getExpression(); value = BasicDBObjectBuilder.start("periodType", periodType).add("expression", expression).get(); } else { // try converting to a string value = value.toString(); } } DBObject ret = BasicDBObjectBuilder.start("name", name).add("type", (type != null ? type.toString() : null)) .add("value", value).get(); return ret; }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public void addRelation(String fromId, String toId, String category) { QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId); DBObject query = queryBuilder.get(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("f", fromId).add("t", toId).add("c", category) .add("w", 1.0); DBObject insert = builder.get(); WriteResult result = relations.update(query, insert, true, false); checkResult(result, 1);/* w w w . j av a 2 s . c om*/ }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public void increaseWeight(String fromId, String toId, double weight) { QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId); DBObject query = queryBuilder.get(); BasicDBObjectBuilder updateBuilder = BasicDBObjectBuilder.start("$inc", BasicDBObjectBuilder.start("w", weight).get()); DBObject update = updateBuilder.get(); WriteResult result = relations.update(query, update, false, false); checkResult(result, 1);//w w w .j a v a 2 s . co m }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public List<Relation> relationsFrom(String fromId, Set<String> categories, int skip, int maxItems) { List<Relation> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId); if (categories != null && categories.size() > 0) { queryBuilder.and("c").in(categories); }//from w w w . j a v a 2s. c om DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("t", 1).add("w", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems); try { for (DBObject dbObject : cursor) { String toId = (String) dbObject.get("t"); double weight = (Double) dbObject.get("w"); Relation r = new Relation(fromId, toId, weight); ret.add(r); } } finally { if (cursor != null) { cursor.close(); } } return ret; }