Example usage for com.mongodb BasicDBObjectBuilder start

List of usage examples for com.mongodb BasicDBObjectBuilder start

Introduction

In this page you can find the example usage for com.mongodb BasicDBObjectBuilder start.

Prototype

public static BasicDBObjectBuilder start() 

Source Link

Document

Creates a builder intialized with an empty document.

Usage

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 {//from  w w w  .  j a  v a  2 s  . co  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();
            }//  w  ww.  j  a  v  a2  s .  c  o m
        }

        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);/*  w  ww.  ja  va 2s  .  c o  m*/
    }
    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  w  w .  j  a  va  2 s . 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  w  w.  j a v  a 2  s  .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

protected DBObject buildAspectUpdate(String aspect) {
    BasicDBObjectBuilder setterBuilder = BasicDBObjectBuilder.start();
    DBObject setter = setterBuilder.get();

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("$set", setter);
    return builder.get();
}

From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java

License:Open Source License

protected DBObject buildAspectsUpdate(Set<String> aspects) {
    BasicDBObjectBuilder setterBuilder = BasicDBObjectBuilder.start();
    for (String aspect : aspects) {
        setterBuilder.add(CLASSES + "." + aspect, new BasicDBObject());
    }/*from  w  ww. j  a  va 2s  . com*/
    DBObject setter = setterBuilder.get();

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("$set", setter);
    return builder.get();
}

From source file:org.alfresco.serializers.JSON.java

License:Open Source License

public DBObject makeDBObject() {
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        builder.append(entry.getKey(), entry.getValue());
    }//  w  w  w. j a v a 2s .  c o  m
    return builder.get();
}

From source file:org.alfresco.serializers.types.Serializers.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   www.  ja v a  2s.  c om
public Object serialize(Object value) {
    Object ret = null;

    if (value != null) {
        if (value instanceof Map<?, ?>) {
            Map<Serializable, Serializable> map = (Map<Serializable, Serializable>) value;
            // Persist the individual entries
            for (Map.Entry<Serializable, Serializable> entry : map.entrySet()) {
                // Recurse for each value
                Serializable mapKey = entry.getKey();
                Serializable mapValue = entry.getValue();

                Object serializedKey = serialize(mapKey);
                Object serializedValue = serialize(mapValue);

                String key = null;
                if (serializedKey instanceof String) {
                    key = (String) serializedKey;
                } else {
                    key = serializedKey.toString();
                }
                BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
                builder.add(key, serializedValue);
                ret = builder.get();
            }
        } else if (value instanceof Collection<?>) {
            Collection<Serializable> collection = (Collection<Serializable>) value;

            BasicDBList values = new BasicDBList();

            // Persist the individual entries
            for (Serializable collectionValue : collection) {

                Object mValue = serialize(collectionValue);
                values.add(mValue);
            }

            ret = values;
        } else {
            String valueName = value.getClass().getName();
            Serializer serializer = getSerializer(valueName);
            if (serializer != null) {
                ret = serializer.serialize(value);
            } else {
                ret = value;
            }
        }
    }

    return ret;
}

From source file:org.alfresco.service.common.elasticsearch.ElasticSearchIndexer.java

License:Open Source License

public void indexEvent(NodeEvent event) throws IOException {
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();

    long nodeInternalId = event.getNodeInternalId();
    long versionId = 1l;

    String nodeId = event.getNodeId();

    String changeTxnId = event.getTxnId();
    Long txnId = event.getTxnInternalId();
    Long timestampMS = event.getTimestamp();
    String username = event.getUsername();
    List<String> paths = event.getPaths();
    String nodeType = event.getNodeType();

    String path = null;//from  w w  w  .  jav  a  2 s  .  c  om
    if (paths != null && paths.size() > 0) {
        path = paths.get(0);
    }
    String site = event.getSiteId();
    if (site == null) {
        site = "";
    }
    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 = "";
    }

    builder.add("t", event.getType()).add("u", username).add("ct", changeTxnId).add("tx", txnId)
            .add("tim", timestampMS).add("ti", timestampMS).add("nid", nodeInternalId).add("v", versionId)
            .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());
}