List of usage examples for com.mongodb BasicDBObjectBuilder add
public BasicDBObjectBuilder add(final String key, final Object val)
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 www.ja va2 s. c om*/ 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 w ww. ja v a 2s . com 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); }/*from w w w . j a va 2 s . c om*/ 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();/*ww w . j av a 2s .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.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected DBObject buildDeleteProperties(NodeVersionKey nodeVersionKey, Set<String> qnames) { if (qnames == null || qnames.isEmpty()) { throw new IllegalArgumentException(); } else {//ww w .j a v a 2 s.co m BasicDBObjectBuilder updateBuilder = BasicDBObjectBuilder.start(); BasicDBObjectBuilder propertiesBuilder = BasicDBObjectBuilder.start(); for (String propertyName : qnames) { QName propertyQName = serializerRegistry.deserialize(QName.class, propertyName); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); ClassDefinition classDef = propDef.getContainerClass(); QName aspectQName = classDef.getName(); String className = serializerRegistry.serialize(aspectQName).toString(); propertiesBuilder.add(className + "." + propertyName, ""); } updateBuilder.add("$unset", propertiesBuilder.get()); return updateBuilder.get(); } }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected DBObject buildDeleteAspects(NodeVersionKey nodeVersionKey, Set<String> aspects) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); if (aspects == null || aspects.size() == 0) { builder.add("$set", new BasicDBObject(CLASSES, new BasicDBObject())); return builder.get(); } else {//w w w .ja va 2s . c o m BasicDBObjectBuilder aspectsBuilder = BasicDBObjectBuilder.start(); for (String aspect : aspects) { QName aspectQName = serializerRegistry.deserialize(QName.class, aspect); String className = serializerRegistry.serialize(aspectQName).toString(); aspectsBuilder.add(className, ""); } builder.add("$unset", aspectsBuilder.get()); } return builder.get(); }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected DBObject buildPropertiesUpdate(NodeVersionKey nodeVersionKey, Map<String, Serializable> persistableProps) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); for (Map.Entry<String, Serializable> entry : persistableProps.entrySet()) { String propertyName = entry.getKey(); QName propertyQName = serializerRegistry.deserialize(QName.class, propertyName); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); String clazz = "residual"; if (propDef != null) { ClassDefinition classDef = propDef.getContainerClass(); if (classDef != null) { QName classQName = classDef.getName(); clazz = serializerRegistry.serialize(classQName).toString(); }/*ww w.ja v a 2 s . com*/ } Serializable value = entry.getValue(); Object propVal = propertySerializer.serialize(propertyQName, value); builder.add(CLASSES + "." + clazz + "." + propertyName, propVal); } return builder.get(); }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected void buildNodeMetadata(BasicDBObjectBuilder builder, NodeVersionKey nodeVersionKey, String changeTxnId, Long txnId, QName nodeTypeQName, Map<QName, Serializable> props, Set<QName> aspects) { String nodeType = serializerRegistry.serialize(nodeTypeQName).toString(); Map<String, BasicDBObjectBuilder> classBuilders = new HashMap<>(); Set<QName> classesToAdd = new HashSet<>(); if (aspects != null) { classesToAdd.addAll(aspects);//from w w w . j a v a 2s . c om } classesToAdd.add(nodeTypeQName); for (Map.Entry<QName, Serializable> entry : props.entrySet()) { QName propertyQName = entry.getKey(); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); Serializable propertyValue = entry.getValue(); String className = "residual"; if (propDef != null) { ClassDefinition classDef = propDef.getContainerClass(); if (classDef != null) { QName classQName = classDef.getName(); classesToAdd.remove(classQName); className = serializerRegistry.serialize(classQName).toString(); } } String propName = buildPropertyName(propertyQName); Object propValue = propertySerializer.serialize(propertyQName, propertyValue); BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } classBuilder.add(propName, propValue); } for (QName classQName : classesToAdd) { String className = (String) serializerRegistry.serialize(classQName); BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } } BasicDBObjectBuilder setterBuilder = BasicDBObjectBuilder.start(); for (Map.Entry<String, BasicDBObjectBuilder> classBuilderEntry : classBuilders.entrySet()) { setterBuilder.add(classBuilderEntry.getKey(), classBuilderEntry.getValue().get()); } DBObject setter = setterBuilder.get(); builder.add(NODE_TYPE, nodeType).add(CLASSES, setter); }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
@Override public void buildNodeMetadata(BasicDBObjectBuilder builder, NodeVersionKey nodeVersionKey, String changeTxnId, Long txnId, String nodeType, Map<String, Serializable> props, Set<String> aspects) { Map<String, BasicDBObjectBuilder> classBuilders = new HashMap<>(); Set<String> classesToAdd = new HashSet<>(); if (aspects != null) { classesToAdd.addAll(aspects);/*from w ww.j a v a 2s . c o m*/ } classesToAdd.add(nodeType); for (Map.Entry<String, Serializable> entry : props.entrySet()) { String propertyName = entry.getKey(); QName propertyQName = serializerRegistry.deserialize(QName.class, propertyName); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); Serializable propertyValue = entry.getValue(); String className = "residual"; if (propDef != null) { ClassDefinition classDef = propDef.getContainerClass(); if (classDef != null) { QName classQName = classDef.getName(); classesToAdd.remove(classQName); className = serializerRegistry.serialize(classQName).toString(); } } BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } propertySerializer.serialize(propertyQName, propertyValue, classBuilder); } for (String className : classesToAdd) { BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } } BasicDBObjectBuilder setterBuilder = BasicDBObjectBuilder.start(); for (Map.Entry<String, BasicDBObjectBuilder> classBuilderEntry : classBuilders.entrySet()) { setterBuilder.add(classBuilderEntry.getKey(), classBuilderEntry.getValue().get()); } DBObject setter = setterBuilder.get(); builder.add(NODE_TYPE, nodeType).add(CLASSES, setter); }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
@Override public void buildNodeMetadata(BasicDBObjectBuilder builder, String nodeId, String changeTxnId, String nodeType, Map<String, Serializable> props, Set<String> aspects) { Map<String, BasicDBObjectBuilder> classBuilders = new HashMap<>(); Set<String> classesToAdd = new HashSet<>(); if (aspects != null) { classesToAdd.addAll(aspects);/*from w ww . jav a 2s. co m*/ } classesToAdd.add(nodeType); for (Map.Entry<String, Serializable> entry : props.entrySet()) { String propertyName = entry.getKey(); QName propertyQName = serializerRegistry.deserialize(QName.class, propertyName); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); Serializable propertyValue = entry.getValue(); String className = "residual"; if (propDef != null) { ClassDefinition classDef = propDef.getContainerClass(); if (classDef != null) { QName classQName = classDef.getName(); classesToAdd.remove(classQName); className = serializerRegistry.serialize(classQName).toString(); } } BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } propertySerializer.serialize(propertyQName, propertyValue, classBuilder); } for (String className : classesToAdd) { BasicDBObjectBuilder classBuilder = classBuilders.get(className); if (classBuilder == null) { classBuilder = BasicDBObjectBuilder.start(); classBuilders.put(className, classBuilder); } } BasicDBObjectBuilder setterBuilder = BasicDBObjectBuilder.start(); for (Map.Entry<String, BasicDBObjectBuilder> classBuilderEntry : classBuilders.entrySet()) { setterBuilder.add(classBuilderEntry.getKey(), classBuilderEntry.getValue().get()); } DBObject setter = setterBuilder.get(); builder.add(NODE_TYPE, nodeType).add(CLASSES, setter); }