List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:org.pentaho.mongo.MongoUtils.java
License:Open Source License
protected static void setupAllTags(BasicDBList members, List<String> allTags) { HashSet<String> tempTags = new HashSet<String>(); if (members != null && members.size() > 0) { for (int i = 0; i < members.size(); i++) { Object m = members.get(i); if (m != null) { DBObject tags = (DBObject) ((DBObject) m).get("tags"); //$NON-NLS-1$ if (tags == null) { continue; }//www . j a va 2 s . c o m for (String tagName : tags.keySet()) { String tagVal = tags.get(tagName).toString(); String combined = quote(tagName) + " : " + quote(tagVal); //$NON-NLS-1$ tempTags.add(combined); } } } } for (String s : tempTags) { allTags.add(s); } }
From source file:org.pentaho.mongo.MongoUtils.java
License:Open Source License
protected static void checkForReplicaSetMembersThatSatisfyTagSets(List<DBObject> tagSets, List<DBObject> satisfy, BasicDBList members) { if (members != null && members.size() > 0) { for (int i = 0; i < members.size(); i++) { Object m = members.get(i); if (m != null) { DBObject tags = (DBObject) ((DBObject) m).get("tags"); //$NON-NLS-1$ if (tags == null) { continue; }/*from w w w .j a v a2 s. c om*/ for (int j = 0; j < tagSets.size(); j++) { boolean match = true; DBObject toMatch = tagSets.get(j); for (String tagName : toMatch.keySet()) { String tagValue = toMatch.get(tagName).toString(); // does replica set member m's tags contain this tag? Object matchVal = tags.get(tagName); if (matchVal == null) { match = false; // doesn't match this particular tag set // no need to check any other keys in toMatch break; } if (!matchVal.toString().equals(tagValue)) { // rep set member m's tags has this tag, but it's value does not // match match = false; // no need to check any other keys in toMatch break; } } if (match) { // all tag/values present and match - add this member (only if its // not already there) if (!satisfy.contains(m)) { satisfy.add((DBObject) m); } } } } } } }
From source file:org.pentaho.mongo.wrapper.NoAuthMongoClientWrapper.java
License:Open Source License
protected List<String> setupAllTags(BasicDBList members) { HashSet<String> tempTags = new HashSet<String>(); if (members != null && members.size() > 0) { for (Object member : members) { if (member != null) { DBObject tags = (DBObject) ((DBObject) member).get("tags"); //$NON-NLS-1$ if (tags == null) { continue; }//from ww w.ja v a 2s .c o m for (String tagName : tags.keySet()) { String tagVal = tags.get(tagName).toString(); String combined = quote(tagName) + " : " + quote(tagVal); //$NON-NLS-1$ tempTags.add(combined); } } } } return new ArrayList<String>(tempTags); }
From source file:org.pentaho.mongo.wrapper.NoAuthMongoClientWrapper.java
License:Open Source License
protected List<DBObject> checkForReplicaSetMembersThatSatisfyTagSets(List<DBObject> tagSets, BasicDBList members) {/* w w w. j av a2s .c om*/ List<DBObject> satisfy = new ArrayList<DBObject>(); if (members != null && members.size() > 0) { for (Object m : members) { if (m != null) { DBObject tags = (DBObject) ((DBObject) m).get("tags"); //$NON-NLS-1$ if (tags == null) { continue; } for (DBObject toMatch : tagSets) { boolean match = true; for (String tagName : toMatch.keySet()) { String tagValue = toMatch.get(tagName).toString(); // does replica set member m's tags contain this tag? Object matchVal = tags.get(tagName); if (matchVal == null) { match = false; // doesn't match this particular tag set // no need to check any other keys in toMatch break; } if (!matchVal.toString().equals(tagValue)) { // rep set member m's tags has this tag, but it's value does not // match match = false; // no need to check any other keys in toMatch break; } } if (match) { // all tag/values present and match - add this member (only if its // not already there) if (!satisfy.contains(m)) { satisfy.add((DBObject) m); } } } } } } return satisfy; }
From source file:org.restheart.hal.metadata.singletons.OidsAsStringsTransformer.java
License:Open Source License
private void _transform(DBObject data) { data.keySet().stream().forEach(key -> { Object value = data.get(key); if (value instanceof DBObject) { _transform((DBObject) value); } else if (value instanceof ObjectId) { data.put(key, ((ObjectId) value).toString()); }/*from w w w. j a v a 2s . co m*/ }); }
From source file:org.restheart.hal.metadata.singletons.RequestPropsInjecterTransformer.java
License:Open Source License
/** * * @param exchange// w w w. java 2 s . c om * @param context * @param contentToTransform * @param args properties to add */ @Override public void tranform(final HttpServerExchange exchange, final RequestContext context, DBObject contentToTransform, final DBObject args) { BasicDBObject injected = new BasicDBObject(); if (args instanceof BasicDBObject) { HashMap<String, Object> properties = getPropsValues(exchange, context); String firstKey = args.keySet().iterator().next(); Object _toinject = args.get(firstKey); if (_toinject instanceof BasicDBList) { BasicDBList toinject = (BasicDBList) _toinject; toinject.forEach(_el -> { if (_el instanceof String) { String el = (String) _el; Object value = properties.get(el); if (value != null) { injected.put(el, value); } else { context.addWarning("property in the args list does not have a value: " + _el); } } else { context.addWarning("property in the args list is not a string: " + _el); } }); contentToTransform.put(firstKey, injected); } else { context.addWarning( "transformer wrong definition: args must be an object with a array containing the names of the properties to inject. got " + JsonUtils.serialize(args)); } } else if (args instanceof BasicDBList) { HashMap<String, Object> properties = getPropsValues(exchange, context); BasicDBList toinject = (BasicDBList) args; toinject.forEach(_el -> { if (_el instanceof String) { String el = (String) _el; Object value = properties.get(el); if (value != null) { injected.put(el, value); } else { context.addWarning("property in the args list does not have a value: " + _el); } } else { context.addWarning("property in the args list is not a string: " + _el); } }); contentToTransform.putAll((BSONObject) injected); } else { context.addWarning( "transformer wrong definition: args must be an object with a array containing the names of the properties to inject. got " + JsonUtils.serialize(args)); } }
From source file:org.restheart.hal.metadata.singletons.RequetPropsInjecterTransformer.java
License:Open Source License
/** * * @param exchange// w w w . java2 s . c o m * @param context * @param contentToTransform * @param args properties to add */ @Override public void tranform(final HttpServerExchange exchange, final RequestContext context, DBObject contentToTransform, final DBObject args) { BasicDBObject injected = new BasicDBObject(); if (args instanceof BasicDBObject) { HashMap<String, String> properties = getPropsValues(exchange, context); String firstKey = args.keySet().iterator().next(); Object _toinject = args.get(firstKey); if (_toinject instanceof BasicDBList) { BasicDBList toinject = (BasicDBList) _toinject; toinject.forEach(_el -> { if (_el instanceof String) { String el = (String) _el; String value = properties.get(el); injected.put(el, value); } else { context.addWarning("property in the args list is not a string: " + _el); } }); contentToTransform.put(firstKey, injected); } else { context.addWarning( "transformer wrong definition: args must be an object with a array containing the names of the properties to inject. got " + JsonUtils.serialize(args)); } } else if (args instanceof BasicDBList) { HashMap<String, String> properties = getPropsValues(exchange, context); BasicDBList toinject = (BasicDBList) args; toinject.forEach(_el -> { if (_el instanceof String) { String el = (String) _el; String value = properties.get(el); injected.put(el, value); } else { context.addWarning("property in the args list is not a string: " + _el); } }); contentToTransform.putAll((BSONObject) injected); } else { context.addWarning( "transformer wrong definition: args must be an object with a array containing the names of the properties to inject. got " + JsonUtils.serialize(args)); } }
From source file:org.restheart.hal.metadata.singletons.ValidOidsStringsAsOidsTransformer.java
License:Open Source License
private void _transform(DBObject data, Set<String> propertiesNames) { data.keySet().stream().forEach(key -> { Object value = data.get(key); if (shouldTransform(key, propertiesNames)) { if (value instanceof String && ObjectId.isValid((String) value)) { data.put(key, new ObjectId((String) value)); }//from ww w . j a v a2 s. c o m } if (value instanceof DBObject) { _transform((DBObject) value, propertiesNames); } }); }
From source file:org.restheart.handlers.document.DocumentRepresentationFactory.java
License:Open Source License
/** * * @param href/* w ww . ja va 2s. c o m*/ * @param exchange * @param context * @param data * @return * @throws IllegalQueryParamenterException */ public Representation getRepresentation(String href, HttpServerExchange exchange, RequestContext context, DBObject data) throws IllegalQueryParamenterException { Representation rep; Object id = data.get("_id"); String _docIdType = null; rep = new Representation(URLUtils.getReferenceLink(context, URLUtils.getParentPath(href), id)); rep.addProperty("_type", context.getType().name()); // document properties data.keySet().stream().forEach((key) -> rep.addProperty(key, data.get(key))); // document links TreeMap<String, String> links; links = getRelationshipsLinks(rep, context, data); if (links != null) { links.keySet().stream().forEach((k) -> { rep.addLink(new Link(k, links.get(k))); }); } // link templates and curies String requestPath = URLUtils.removeTrailingSlashes(exchange.getRequestPath()); if (isBinaryFile(data)) { if (_docIdType == null) { rep.addLink(new Link("rh:data", String.format("%s/%s", href, RequestContext.BINARY_CONTENT))); } else { rep.addLink(new Link("rh:data", String.format("%s/%s?%s", href, RequestContext.BINARY_CONTENT, _docIdType))); } if (context.isParentAccessible()) { rep.addLink(new Link("rh:bucket", URLUtils.getParentPath(requestPath))); } } else { if (context.isParentAccessible()) { rep.addLink(new Link("rh:coll", URLUtils.getParentPath(requestPath))); } } rep.addLink(new Link("rh", "curies", Configuration.RESTHEART_ONLINE_DOC_URL + "/#api-doc-{rel}", false), true); return rep; }
From source file:org.restheart.handlers.schema.JsonSchemaTransformer.java
License:Open Source License
public static void escapeSchema(DBObject schema) { DBObject escaped = (DBObject) JsonUtils.escapeKeys(schema, false); List<String> keys = Lists.newArrayList(schema.keySet().iterator()); keys.stream().forEach(f -> schema.removeField(f)); schema.putAll(escaped);//from ww w.ja v a2 s . c om }