Example usage for com.mongodb BasicDBObjectBuilder get

List of usage examples for com.mongodb BasicDBObjectBuilder get

Introduction

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

Prototype

public DBObject get() 

Source Link

Document

Gets the top level document.

Usage

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public List<Relation> relationsTo(String toId, Set<String> categories, int skip, int maxItems) {
    List<Relation> ret = new LinkedList<>();

    QueryBuilder queryBuilder = QueryBuilder.start("t").is(toId);
    if (categories != null && categories.size() > 0) {
        queryBuilder.and("c").in(categories);
    }// w w  w.  j a va2s.  co  m
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("f", 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 fromId = (String) dbObject.get("f");
            double weight = (Double) dbObject.get("w");
            Relation r = new Relation(fromId, toId, weight);
            ret.add(r);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    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 {//from www .ja v  a 2s  . c om
        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 {//  ww  w. j  a  v a 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();
            }/*from   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);// www  . 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 ww w  . jav 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

@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);// w ww.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

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());
    }//  w w w .  j a va2s  .c  o  m
    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());
    }//from   w  ww  .  j av  a2  s.c  om
    return builder.get();
}