List of usage examples for com.mongodb BasicDBList keySet
@Override
public Set<String> keySet()
From source file:com.flyingdonut.implementation.helpers.MongoDbConsumerAssociationStore.java
License:Apache License
private void mongoEnsureIndexAddAll(DBObject indexDoc, BasicDBList queryKeys) { for (String k : queryKeys.keySet()) { BasicDBObject value = (BasicDBObject) queryKeys.get(k); if (k.startsWith("$")) { mongoEnsureIndexAddAll(indexDoc, (BasicDBList) queryKeys.get(k)); } else {// w w w .j a v a 2 s . c om for (String kk : value.keySet()) { indexDoc.put(kk, 1); } } } }
From source file:org.hibernate.ogm.datastore.mongodb.utils.MongoDBTestHelper.java
License:LGPL
private static boolean isDBObjectAndContentEqual(Object left, Object right) { if (left instanceof BasicDBList) { if (!(right instanceof BasicDBList)) { return false; }/*from w w w .j av a2 s . c om*/ // we don't care about the order here for now BasicDBList leftAsList = (BasicDBList) left; BasicDBList rightAsList = (BasicDBList) right; // check that the fields names are the same Set<String> leftFields = new HashSet<String>(leftAsList.keySet()); Set<String> rightFields = new HashSet<String>(rightAsList.keySet()); if (!leftFields.equals(rightFields)) { return false; } // check that all left field values are in right for (String field : leftFields) { // fall back to native equals via the contains. It is out of our current tests if (!rightAsList.contains(leftAsList.get(field))) { return false; } } } else if (left instanceof DBObject) { if (!(right instanceof DBObject)) { return false; } DBObject leftAsDBObject = (DBObject) left; DBObject rightAsDBObject = (DBObject) right; // check that the fields names are the same Set<String> leftFields = new HashSet<String>(leftAsDBObject.keySet()); Set<String> rightFields = new HashSet<String>(rightAsDBObject.keySet()); if (!leftFields.equals(rightFields)) { return false; } // check that all left fields are in right and equal for (String field : leftFields) { boolean matches = isDBObjectAndContentEqual(leftAsDBObject.get(field), rightAsDBObject.get(field)); if (!matches) { return false; } } } else { return left == right || (left != null && left.equals(right)); } return true; }
From source file:org.restheart.handlers.metadata.ResponseTranformerMetadataHandler.java
License:Open Source License
@Override void enforceDbRepresentationTransformLogic(HttpServerExchange exchange, RequestContext context) throws InvalidMetadataException { List<RepresentationTransformer> dbRts = RepresentationTransformer.getFromJson(context.getDbProps()); RequestContext.TYPE requestType = context.getType(); // DB or COLLECTION for (RepresentationTransformer rt : dbRts) { if (rt.getPhase() == RepresentationTransformer.PHASE.RESPONSE) { Transformer t = (Transformer) NamedSingletonsFactory.getInstance().get("transformers", rt.getName());// ww w . j a v a 2 s . c o m if (t == null) { throw new IllegalArgumentException( "cannot find singleton " + rt.getName() + " in singleton group transformers"); } if (rt.getScope() == RepresentationTransformer.SCOPE.THIS && requestType == RequestContext.TYPE.DB) { t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.COLLECTION) { BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); // evaluate the script on children collection BasicDBList colls = (BasicDBList) _embedded.get("rh:coll"); if (colls != null) { for (String k : colls.keySet()) { DBObject coll = (DBObject) colls.get(k); t.tranform(exchange, context, coll, rt.getArgs()); } } } } } }
From source file:org.restheart.handlers.metadata.ResponseTranformerMetadataHandler.java
License:Open Source License
@Override void enforceCollRepresentationTransformLogic(HttpServerExchange exchange, RequestContext context) throws InvalidMetadataException { List<RepresentationTransformer> dbRts = RepresentationTransformer.getFromJson(context.getCollectionProps()); RequestContext.TYPE requestType = context.getType(); // DOCUMENT or COLLECTION for (RepresentationTransformer rt : dbRts) { if (rt.getPhase() == RepresentationTransformer.PHASE.RESPONSE) { Transformer t;//from w w w. ja va 2 s. co m try { t = (Transformer) NamedSingletonsFactory.getInstance().get("transformers", rt.getName()); } catch (IllegalArgumentException ex) { context.addWarning("error applying transformer: " + ex.getMessage()); return; } if (t == null) { throw new IllegalArgumentException( "cannot find singleton " + rt.getName() + " in singleton group transformers"); } if (rt.getScope() == RepresentationTransformer.SCOPE.THIS && requestType == RequestContext.TYPE.COLLECTION) { // evaluate the script on collection t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.COLLECTION) { BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); // execute the logic on children documents BasicDBList docs = (BasicDBList) _embedded.get("rh:doc"); if (docs != null) { for (String k : docs.keySet()) { DBObject doc = (DBObject) docs.get(k); t.tranform(exchange, context, doc, rt.getArgs()); } } // execute the logic on children files BasicDBList files = (BasicDBList) _embedded.get("rh:file"); if (files != null) { for (String k : files.keySet()) { DBObject file = (DBObject) files.get(k); t.tranform(exchange, context, file, rt.getArgs()); } } } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.DOCUMENT) { t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } } } }
From source file:org.restheart.handlers.schema.JsonSchemaTransformer.java
License:Open Source License
@Override public void tranform(HttpServerExchange exchange, RequestContext context, final DBObject contentToTransform, DBObject args) {//from www . j a v a 2s. c om if (context.getType() == RequestContext.TYPE.SCHEMA) { if (context.getMethod() == RequestContext.METHOD.GET) { unescapeSchema(context.getResponseContent()); } else if (context.getMethod() == RequestContext.METHOD.PUT || context.getMethod() == RequestContext.METHOD.PATCH) { // generate id as specs mandates SchemaStoreURL uri = new SchemaStoreURL(context.getDBName(), context.getDocumentId()); context.getContent().put("id", uri.toString()); // escape all $ prefixed keys escapeSchema(contentToTransform); // add (overwrite) $schema field contentToTransform.put("_$schema", "http://json-schema.org/draft-04/schema#"); } } else if (context.getType() == RequestContext.TYPE.SCHEMA_STORE) { if (context.getMethod() == RequestContext.METHOD.POST) { // generate id as specs mandates Object schemaId; if (context.getContent().get("_id") == null) { schemaId = new ObjectId(); context.getContent().put("id", schemaId); } else { schemaId = context.getContent().get("_id"); } SchemaStoreURL uri = new SchemaStoreURL(context.getDBName(), schemaId); context.getContent().put("id", uri.toString()); // escape all $ prefixed keys escapeSchema(contentToTransform); // add (overwrite) $schema field contentToTransform.put("_$schema", "http://json-schema.org/draft-04/schema#"); } else if (context.getMethod() == RequestContext.METHOD.GET) { // apply transformation on embedded schemas BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); if (_embedded != null) { // execute the logic on children documents BasicDBList docs = (BasicDBList) _embedded.get("rh:schema"); if (docs != null) { docs.keySet().stream().map((k) -> (DBObject) docs.get(k)).forEach((doc) -> { unescapeSchema(doc); }); } } } } }
From source file:tango.dataStructure.Selection.java
License:Open Source License
public void init() { if (!this.containsField("nuclei")) { nuclei = new BasicDBObject(); this.append("nuclei", nuclei); } else {// ww w. j av a 2 s .c o m Object o = this.get("nuclei"); if (o instanceof BasicDBList) { IJ.log("Warning: Selection: " + this.getName() + " bad structure: level 1"); nuclei = new BasicDBObject(); this.append("nuclei", nuclei); BasicDBList l = (BasicDBList) o; boolean warn2 = false; for (String s : l.keySet()) { Object n = l.get(s); if (n instanceof BasicDBObject) nuclei.append(s, (BasicDBObject) n); else if (n instanceof BasicDBList) { nuclei.append(s, toBDO((BasicDBList) n)); if (!warn2) { IJ.log("Warning: Selection: " + this.getName() + "nucleus: " + s + " bad structure: level 2"); warn2 = true; } } } } else if (o instanceof BasicDBObject) { nuclei = (BasicDBObject) o; } else { nuclei = new BasicDBObject(); this.append("nuclei", nuclei); } } }
From source file:tango.dataStructure.Selection.java
License:Open Source License
static BasicDBObject toBDO(BasicDBList list) { BasicDBObject res = new BasicDBObject(); for (String s : list.keySet()) res.append(s, list.get(s));/*from w ww . jav a2 s . c om*/ return res; }