/** * 解析 * @param group * @param parser * @return */ @Override public Object parse(IGroup group, JsonRuleParser parser) { // rules BasicDBList operates = new BasicDBList(); for (JsonRule jsonRule : group.getRules()) { operates.add(parser.parse(jsonRule)); } // AND or OR BasicDBObject andOrObj = new BasicDBObject(); andOrObj.append(EnumCondition.AND.equals(group.getCondition()) ? "$and" : "$or", operates); // Not if (group.getNot() != null && group.getNot()) { BasicDBList list = new BasicDBList(); list.add(andOrObj); return new BasicDBObject("$nor", list); } return andOrObj; }
public void generateFile(String filename) { DB db = MongoHelper.mongoMerchantDB(); DBCollection col = db.getCollection(COLLECTION_SYNONYMS); DBCursor cursor = col.find(); try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)))) { while (cursor.hasNext()) { DBObject doc = cursor.next(); String word = doc.get(FIELD_KEY_WORLD) != null ? doc.get(FIELD_KEY_WORLD).toString() : null; String synonyms = doc.get(FIELD_KEY_WORLD) != null ? StringUtils.join((BasicDBList) doc.get(FIELD_KEY_SYNONYMS), ",") : null; if (word != null && synonyms != null) { out.println(createLine(word, synonyms)); } } } catch (IOException e) { throw new RuntimeException("IOException: Current db cursor with id: " + cursor.curr().get("_id"), e); } }
public static BasicDBList toDBList(MultiNameValues multiNameValues) { String[] names = multiNameValues.getNames(); BasicDBList basicDBList = new BasicDBList(); for (int i = 0; i < multiNameValues.count(); i++) { Object[] values = multiNameValues.values(i); BasicBSONObject bsonObject = new BasicBSONObject(values.length); for (int j = 0; j < names.length; j++) { bsonObject.append(names[j], values[j]); } basicDBList.add(bsonObject); } return basicDBList; }
private void parserDBObject(BasicDBObject ob,String akey, String aop,Object aval){ boolean isok=false; if (!(ob.keySet().isEmpty())) { for (String field : ob.keySet()) { if (akey.equals(field)){ Object val = ob.get(field); if (val instanceof BasicDBObject) { ((BasicDBObject) val).put(aop, aval); ob.put(field, (BasicDBObject) val); isok=true; break; } else if (val instanceof BasicDBList) { // newobj.put(field, ((BasicDBList)val).copy()); } } } } if (isok==false) { BasicDBObject xo = new BasicDBObject(); xo.put(aop, aval); ob.put(akey,xo); } }
/** * Create a Mongo DB Object baed on the content of this group * * @param id The Mongo Object id to assign to this DB Object. If null, a new Object id will be * created * @return - The Mongo DB Object based on the content of this group */ public BasicDBObject getDBObject(boolean includeId) { BasicDBObject group = new BasicDBObject(); if (includeId) { group.append(DB_ID, new ObjectId(id)); } group.append(JSON_KEY_GROUP_NAME, name); BasicDBList membersArray = new BasicDBList(); for (int i = 0; i < members.length; i++) { membersArray.add(members[i]); } group.append(JSON_KEY_MEMBERS_LIST, membersArray); return group; }
@Override public void setQuery(DBObject query, BasicDBList orList) { // if (null == orList) { // query.put(this.name, value.getValue()); // } else { // orList.add(new BasicDBObject(this.name, value.getValue())); // } if (this.name.equals("_id")) { if (null == orList) { query.put(this.name, new ObjectId(value.getValue().toString())); } else { orList.add(new BasicDBObject(this.name, new ObjectId(value.getValue().toString()))); } } else { if (null == orList) { query.put(this.name, value.getValue()); } else { orList.add(new BasicDBObject(this.name, value.getValue())); } } }
@Override public BasicDBObject mongoSerialise() { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); dbObject.put("y", getY()); dbObject.put("t", ID); BasicDBList tmpNpcArray = new BasicDBList(); for (NonPlayerCharacter npc : npcs) { tmpNpcArray.add(npc.getObjectId()); } dbObject.put("n", tmpNpcArray); return dbObject; }
@Override public BasicDBObject mongoSerialise() { BasicDBList registers = new BasicDBList(); for (Integer index : this.registers.keySet()) { JSONObject register = new JSONObject(); register.put("index", index); register.put("name", getRegister(index).getName()); register.put("value", (int) getRegister(index).getValue()); registers.add(register); } BasicDBObject obj = new BasicDBObject(); obj.put("registers", registers); return obj; }
void cryptFields(DBObject dbObject, Node node, Function<Object, Object> crypt) { if (node.type == Node.Type.MAP) { Node mapChildren = node.children.get(0); for (Map.Entry<String, Object> entry : ((BasicDBObject) dbObject).entrySet()) { cryptFields((DBObject) entry.getValue(), mapChildren, crypt); } return; } for (Node childNode : node.children) { Object value = dbObject.get(childNode.fieldName); if (value == null) continue; if (!childNode.children.isEmpty()) { if (value instanceof BasicDBList) { for (Object o : (BasicDBList) value) cryptFields((DBObject) o, childNode, crypt); } else { cryptFields((BasicDBObject) value, childNode, crypt); } return; } dbObject.put(childNode.fieldName, crypt.apply(value)); } }
public DBObject toDBObject() { DBObject out = new BasicDBObject(); if (name != null && type != null && typeInvite != null) { out.put(FIELD_NAME, this.name); out.put(FIELD_TYPE, this.type); out.put(FIELD_TYPE_INVITE, this.typeInvite); } if (this.choices != null) { BasicDBList dbList = new BasicDBList(); for (String choice : this.choices) { dbList.add(choice); } out.put(FIELD_CHOICES, dbList); } if (this.label != null) { out.put(FIELD_LABEL, this.label); } return out; }
public DBObject toDBObject() { DBObject object = new BasicDBObject(); if (xType != null && type != null && attributes != null) { object.put(FIELD_XTYPE, xType); object.put(FIELD_TYPE, type); object.put(FIELD_ICON, icon); object.put(FIELD_ATTR, attributes.toDBObject()); } if (terminals != null) { BasicDBList dbList = new BasicDBList(); for (Terminal t : terminals) { dbList.add(t.toDBObject()); } object.put(FIELD_TERMINALS, dbList); } return object; }
public DBObject memoryToDBObject() { DBObject dbObj = this.toDBObject(); BasicDBList dbList = new BasicDBList(); if (fields != null) { for (Field field : fields) { dbList.add(field.toDBObject()); } } if (tickTuple != null) { dbList.add(tickTuple.toDBObject()); } dbObj.put(FIELD_FIELDS, dbList); dbObj.put(FIELD_SINGLETON, singleton); dbObj.put(FIELD_DESCRIPTION, description); dbObj.put(FIELD_LANGUAGE, language); if (versionCode > 0) { dbObj.put(FIELD_VERSION_CODE, versionCode); } return dbObj; }
public Terminal(DBObject o) { if (o != null && o.get(FIELD_NAME) != null) { name = o.get(FIELD_NAME).toString(); } if (o != null && o.get(FIELD_N_MAX_WIRES) != null) { nMaxWires = ((Integer) o.get(FIELD_N_MAX_WIRES)); } if (o != null && o.get(FIELD_DIRECTIONS) != null) { BasicDBList dbList = ((BasicDBList) o.get(FIELD_DIRECTIONS)); direction = new ArrayList<Integer>(); for (Object d : dbList) { direction.add((new Double(d.toString())).intValue()); } } if (o != null) { position = new OffsetPosition((DBObject) o.get(FIELD_POSITION)); } if (o != null) { ddConfig = new DdConfig((DBObject) o.get(FIELD_DD_CONFIG)); } }
public DBObject toDBObject() { DBObject object = new BasicDBObject(); if (name != null) object.put(FIELD_NAME, name); if (nMaxWires != null) object.put(FIELD_N_MAX_WIRES, nMaxWires); if (position != null) { object.put(FIELD_POSITION, position.toDBObject()); } if (ddConfig != null) { object.put(FIELD_DD_CONFIG, ddConfig.toDBObject()); } if (direction != null) { BasicDBList dbList = new BasicDBList(); for (Integer d : direction) { dbList.add(d); } object.put(FIELD_DIRECTIONS, dbList); } return object; }
public static ModulesContainer getModules(User user, boolean includeExternalSharing, Integer page) throws SinfonierException { ModulesContainer modules; BasicDBList notDeletedAndAuthor = new BasicDBList(); notDeletedAndAuthor.add(new BasicDBObject(FIELD_STATUS, new BasicDBObject("$ne", STATUS_DELETED))); notDeletedAndAuthor.add(new BasicDBObject(FIELD_AUTHOR_ID, user.getId())); DBObject sortByName = new BasicDBObject(FIELD_NAME, 1); if (user.isAdminUser() && includeExternalSharing) { modules = find(page); } else if (includeExternalSharing) { BasicDBList list = new BasicDBList(); list.add(new BasicDBObject(FIELD_STATUS, new BasicDBObject("$in", new ArrayList(Arrays.asList(STATUS_PUBLISHED,STATUS_PREDEFINED))))); list.add(new BasicDBObject("$and", notDeletedAndAuthor)); modules = find(new BasicDBObject("$or", list), sortByName, page); } else { modules = find(new BasicDBObject("$and", notDeletedAndAuthor), sortByName, page); } return modules; }
public DBObject toDBObject() { DBObject object = new BasicDBObject(); if (type != null) { object.put(FIELD_TYPE, type); BasicDBList dbList = new BasicDBList(); for (String s : allowedTypes) { dbList.add(s); } object.put(FIELD_ALLOWED, dbList); } return object; }
@Override public DBObject toDBObject() { DBObject object = new BasicDBObject(); if (type == null || value == null) { return object; } object.put(FIELD_TYPE, type); object.put(FIELD_VALUE, value); BasicDBList rangeDbList = new BasicDBList(); rangeDbList.add(0, getMinRange()); rangeDbList.add(1, getMaxRange()); object.put(FIELD_RANGE, rangeDbList); return object; }
public ValueList(DBObject o) { if (o != null && o.keySet().size() == 1) { type = TYPE_LIST; value = new ArrayList<String>(); Set<String> keys = o.keySet(); for (String key : keys) { this.key = key; BasicDBList values = ((BasicDBList) o.get(key)); for (Object v : values) { value.add(v.toString()); } } } }
public DBObject toDBObject() { DBObject object = new BasicDBObject(); BasicDBList positionDbList = new BasicDBList(); if (xType != null && position != null) { object.put(FIELD_XTYPE, xType); for (Integer pos : position) { positionDbList.add(pos); } object.put(FIELD_POSITION, positionDbList); } return object; }
private DBObject saveWords(final Pattern pattern) { final BasicDBList list = new BasicDBList(); for (int i = 0; i < pattern.getWords().size(); i++) { final WordToken w = pattern.getWords(i); final BasicDBObject o = new BasicDBObject() .append("text", w.getCoveredText()) .append("pos", w.getPartOfSpeech()); if (w.getLemmas() != null && w.getLemmas().size() >= 1) { o.put("lemma", w.getLemmas(0).getLemmaForm()); } list.add(o); } return list; }
private Map<String, String> dbObjectToMap(BasicDBObject dbObject) { Map<String, String> result = new HashMap<String, String>(); for (String key : dbObject.keySet()) { Object value = dbObject.get(key); if (value == null) { result.put(key, null); } else if (value.getClass() == BasicDBObject.class) { Map<String, String> sub = dbObjectToMap((BasicDBObject) value); for (Map.Entry<String, String> entry : sub.entrySet()) { result.put(key + "." + entry.getKey(), entry.getValue()); } } else if (value.getClass() == BasicDBList.class) { result.put(key, dbArrayToString((BasicDBList) value)); } else { result.put(key, value.toString()); } } return result; }
public static DBObject serialize(TransformedWaveletDelta transformedWaveletDelta) { BasicDBObject mongoTransformedWaveletDelta = new BasicDBObject(); mongoTransformedWaveletDelta.append(FIELD_AUTHOR, serialize(transformedWaveletDelta.getAuthor())); mongoTransformedWaveletDelta.append(FIELD_RESULTINGVERSION, serialize(transformedWaveletDelta.getResultingVersion())); mongoTransformedWaveletDelta.append(FIELD_APPLICATIONTIMESTAMP, transformedWaveletDelta.getApplicationTimestamp()); mongoTransformedWaveletDelta.append(FIELD_APPLIEDATVERSION, transformedWaveletDelta.getAppliedAtVersion()); BasicDBList mongoWaveletOperations = new BasicDBList(); for (WaveletOperation op : transformedWaveletDelta) { mongoWaveletOperations.add(serialize(op)); } mongoTransformedWaveletDelta.append(FIELD_OPS, mongoWaveletOperations); return mongoTransformedWaveletDelta; }
/** * Convert the given runnable BasicDBList object to JsonArray. * * @param object BasicDBList * @return JsonArray */ public JsonArray getAsJsonArray(DBObject object) { if (!(object instanceof BasicDBList)) { throw new IllegalArgumentException("Expected BasicDBList as argument type!"); } BasicDBList list = (BasicDBList)object; JsonArray jsonArray = new JsonArray(); for (int i = 0; i < list.size(); i++) { Object dbObject = list.get(i); if (dbObject instanceof BasicDBList) { jsonArray.add(getAsJsonArray((BasicDBList) dbObject)); } else if (dbObject instanceof BasicDBObject) { // it's an object jsonArray.add(getAsJsonObject((BasicDBObject) dbObject)); } else { // it's a primitive type number or string jsonArray.add(getAsJsonPrimitive(dbObject)); jsonArray.add(getAsJsonPrimitive(dbObject)); } } return jsonArray; }
/** * Convert the given runnable BasicDBObject to JsonObject. * * @param object BasicDBObject * @return JsonObject */ public JsonObject getAsJsonObject(DBObject object) { if (!(object instanceof BasicDBObject)) { throw new IllegalArgumentException("Expected BasicDBObject as argument type!"); } BasicDBObject dbObject = (BasicDBObject)object; Set<String> keys = dbObject.keySet(); Iterator<String> iterator = keys.iterator(); JsonObject jsonObject = new JsonObject(); while (iterator.hasNext()) { String key = iterator.next(); Object innerObject = dbObject.get(key); if (innerObject instanceof BasicDBList) { jsonObject.add(key, getAsJsonArray((BasicDBList)innerObject)); } else if (innerObject instanceof BasicDBObject) { jsonObject.add(key, getAsJsonObject((BasicDBObject)innerObject)); } else { jsonObject.add(key, getAsJsonPrimitive(innerObject)); } } return jsonObject; }
private JSONObject dbObjectToJSONObject(DBObject dbObj) { JSONObject result = new JSONObject(); for (String key : dbObj.keySet()) { if (!key.startsWith("_")) { Object value = dbObj.get(key); if (value instanceof BasicDBList) { value = dbListToJSONArray((BasicDBList) value); } else if (value instanceof DBObject) { value = dbObjectToJSONObject((DBObject) value); } result.addProperty(key, value); } else if (key.equals("_id")) { ObjectId oid = (ObjectId) dbObj.get(key); result.addProperty(key, oid.toString()); } } return result; }
private static PCJIndexDetails.Builder getPCJIndexDetails(final BasicDBObject basicObj) { final BasicDBObject pcjIndexDBO = (BasicDBObject) basicObj.get(PCJ_DETAILS_KEY); final PCJIndexDetails.Builder pcjBuilder = PCJIndexDetails.builder(); if (!pcjIndexDBO.getBoolean(PCJ_ENABLED_KEY)) { pcjBuilder.setEnabled(false); } else { pcjBuilder.setEnabled(true);//no fluo details to set since mongo has no fluo support final BasicDBList pcjs = (BasicDBList) pcjIndexDBO.get(PCJ_PCJS_KEY); if (pcjs != null) { for (int ii = 0; ii < pcjs.size(); ii++) { final BasicDBObject pcj = (BasicDBObject) pcjs.get(ii); pcjBuilder.addPCJDetails(toPCJDetails(pcj)); } } } return pcjBuilder; }
/** * Deserializes a MongoDB {@link DBObject} to a {@link DocumentVisibility}. * @param mongoObj the {@link DBObject} to be deserialized. * @return the {@link DocumentVisibility} object. * @throws MalformedDocumentVisibilityException */ public static DocumentVisibility toDocumentVisibility(final DBObject mongoObj) throws MalformedDocumentVisibilityException { try { final BasicDBObject basicObj = (BasicDBObject) mongoObj; final Object documentVisibilityObject = basicObj.get(DOCUMENT_VISIBILITY_KEY); Object[] documentVisibilityArray = null; if (documentVisibilityObject instanceof Object[]) { documentVisibilityArray = (Object[]) documentVisibilityObject; } else if (documentVisibilityObject instanceof BasicDBList) { documentVisibilityArray = DocumentVisibilityUtil.convertBasicDBListToObjectArray((BasicDBList) documentVisibilityObject); } final String documentVisibilityString = DocumentVisibilityUtil.multidimensionalArrayToBooleanString(documentVisibilityArray); final DocumentVisibility dv = documentVisibilityString == null ? MongoDbRdfConstants.EMPTY_DV : new DocumentVisibility(documentVisibilityString); return dv; } catch(final Exception e) { throw new MalformedDocumentVisibilityException("Failed to make Document Visibility from Mongo Object, it is malformed.", e); } }
@Test public void testGetAllZips() throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); when(response.getWriter()).thenReturn(pw); when(request.getPathInfo()).thenReturn("/zips"); when(request.getRequestDispatcher("")).thenReturn(rd); new MongoCrudServlet().doGet(request, response); String result = sw.getBuffer().toString().trim(); System.out.println("Json Result As String is : " + result.length() + " characters long"); assertTrue("somehow got a very small JSON resposne: " + result, result.length() > 20); System.out.println("first few lines of Json Result:\n" + result.substring(0, 400)); BasicDBList json = (BasicDBList) JSON.parse(result); assertEquals(String.format("Size of input array %d must match size of parsed array %d", zipDocuments.size(), json.size()), zipDocuments.size(), json.size()); System.out.println("Input array and output array are both + " + zipDocuments.size()); assertTrue(true); }
/** * Create String array from database list. * * @param o * The database list object * @return String array */ public String[] toStringArray(Object o) { if( o == null) return emptyStringArray; else if( o instanceof String[]) return (String[])o; else if( o instanceof String) return new String[]{(String)o}; else if( o instanceof BasicDBList) return (((BasicDBList) o).toArray(new String[((BasicDBList) o).size()])); else if( o instanceof PreservationDimension[]) return Arrays.asList(o).toArray(new String[((PreservationDimension[]) o).length]); // return (((PreservationDimension[]) o).toArray(new String[((PreservationDimension[]) o).length])); else{ throw new FfmaTechnicalRuntimeException("The type cannot be converted to String Array: " + o.getClass()); } }
public String getYagoTypeLabel(String uri){ DBCursor cursor = db.getCollection("entities_yago").find(new BasicDBObject().append("uri", uri)); if(cursor.size() > 0){ DBObject tmp = cursor.next(); BasicDBList labels = (BasicDBList)tmp.get("labels"); if(labels != null){ DBObject tmp2 = (DBObject)labels.get(0); return tmp2.get("label").toString(); } } return null; }
@GET @Path("/recent-builds/{product}") public DBObject getRecentBuildStatsForProduct(@BeanParam final Coordinates coordinates, @QueryParam("limit") final Integer limit) { final BasicDBList returns = new BasicDBList(); final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("reportStats"); final BasicDBObject example = coordinates.getQueryObject(Field.PRODUCT); final DBCursor cursor = collection.find(example).sort(Coordinates.getFeatureSortingObject()); if (limit != null) { cursor.limit(limit); } try { while (cursor.hasNext()) { final DBObject doc = cursor.next(); returns.add(doc); } } finally { cursor.close(); } return returns; }
/** * go through find all the backgrounds elements and nest them in their scenarios (simplifies application logic downstream) */ protected void packBackgroundsInToScenarios(final DBObject feature) { final List<DBObject> packedScenarios = new ArrayList<DBObject>(); // go through all the backgrounds /scenarios final BasicDBList elements = (BasicDBList) feature.get("elements"); if (elements != null) { for (int i = 0; i < elements.size(); i++) { final DBObject element = (DBObject) elements.get(i); if (element.get("type").equals("background")) { // if its a background ((DBObject) elements.get(i + 1)).put("background", element); // push it in to the next element. } else { // assume this is a scenario/other top level element and push it to the packed array. packedScenarios.add(element); } } elements.clear(); elements.addAll(packedScenarios); } }
@Test public void testDrugCount() throws UnknownHostException, MongoException { MongoQueryRunner qr = new MongoQueryRunner(); String result = qr.drugCount("localhost", "dbname", "fda_enforcement", "Baxter Healthcare Corporation"); DBObject record = (DBObject) JSON.parse(result); assertTrue(record.containsField("count")); assertEquals(2, record.get("count")); assertTrue(record.containsField("results")); assertEquals(2, ((BasicDBList)record.get("results")).size()); assertEquals("Baxter Healthcare Corporation", record.get("manufacturer").toString()); BasicDBList results = (BasicDBList)record.get("results"); assertEquals(2, results.size()); DBObject drug1 = (DBObject)results.get(0); assertEquals("DIANEAL LOW CALCIUM WITH DEXTROSE", drug1.get("drug_name")); assertEquals(1, drug1.get("count")); assertEquals("Nationwide", ((BasicDBList)drug1.get("recall_area")).get(0).toString()); DBObject drug2 = (DBObject)results.get(1); assertEquals("DEXTROSE", drug2.get("drug_name")); assertEquals(2, drug2.get("count")); assertEquals("Nationwide", ((BasicDBList)drug2.get("recall_area")).get(0).toString()); }
@GET @Produces("application/json") @Path("/featureTagIndex/{product}/{major}.{minor}.{servicePack}/{build}") public BasicDBList getFeatureTagIndexForReport(@BeanParam final Coordinates coordinates, @QueryParam("searchText") final String searchText, @QueryParam("viewPassed") final Integer viewPassed, @QueryParam("viewFailed") final Integer viewFailed, @QueryParam("viewUndefined") final Integer viewUndefined, @QueryParam("viewSkipped") final Integer viewSkipped, @QueryParam("start") final String start) { final DB db = this.client.getDB("bdd"); final DBCollection featuresCollection = db.getCollection("features"); final BasicDBObject query = QueryBuilder.getInstance().buildFilterQuery(coordinates, searchText, viewPassed, viewFailed, viewUndefined, viewSkipped, start); query.append("$and", QueryBuilder.getInstance().buildHasTagsQuery()); final DBCursor results = featuresCollection.find(query, new BasicDBObject("tags", 1).append("elements.tags", 1).append("name", 1).append("calculatedStatus", 1) .append("id", 1).append("elements.steps", 1).append("elements.name", 1).append("elements.id", 1)); return getTagList(results); }
@GET @Path("/{product}/{major}.{minor}.{servicePack}/{build}") public DBObject getPresencesForBuild(@BeanParam final Coordinates coordinates) { try { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("presence"); final BasicDBObject query = coordinates.getQueryObject(Field.PRODUCT, Field.VERSION, Field.BUILD); final BasicDBList presencesForBuild = new BasicDBList(); final DBCursor cursor = collection.find(query); while (cursor.hasNext()) { presencesForBuild.add(cursor.next()); } return presencesForBuild; } catch (final Throwable th) { th.printStackTrace(); return null; } }
@Test public void restrictingResultSize() { final BasicDBObject dbObj = new BasicDBObject(); when(this.cursor.hasNext()).thenAnswer(new Answer<Boolean>() { private int count = Search.SEARCH_LIMIT + 10; @Override public Boolean answer(final InvocationOnMock invocation) throws Throwable { if (this.count < 0) { return false; } else { this.count--; return true; } } }); when(this.cursor.next()).thenReturn(dbObj); final BasicDBList searchResults = this.search.getSearchResults(this.coordinates, "hello"); assertThat(searchResults.size(), is(Search.SEARCH_LIMIT)); }
/** * Test that an empty list of filters and a simple search string result in a database query with * a sort condition, and then a sort. * */ @Test public void testRetrieveAllAssetsWithSearch(final @Mocked DBCollection collection, final @Mocked DBCursor cursor) { BasicDBList list = new BasicDBList(); list.add(new BasicDBObject("$text", new BasicDBObject("$search", "foo"))); final BasicDBObject searchObject = new BasicDBObject("$and", list); final BasicDBObject sortObject = new BasicDBObject("score", new BasicDBObject("$meta", "textScore")); new Expectations() { { collection.find(searchObject, sortObject); cursor.sort(sortObject); } }; createTestBean().retrieveAllAssets(Collections.<AssetFilter> emptySet(), "foo", null, null); }
private BasicDBObject buildIfNullBasedProjection(MongoDocument parent, MongoDocument child) throws TranslatorException { BasicDBObject columns = new BasicDBObject(); Table table = parent.getTable(); for (Column c:table.getColumns()) { if (parent.isMerged() || parent.isEmbeddable()) { columns.append(parent.getQualifiedName(false)+"."+c.getName(), 1); //$NON-NLS-1$ } else { columns.append(c.getName(), 1); } } BasicDBList exprs = new BasicDBList(); exprs.add("$"+child.getQualifiedName(false)); //$NON-NLS-1$ BasicDBList list = new BasicDBList(); list.add(new BasicDBObject()); exprs.add(list); BasicDBObject ifnull = new BasicDBObject("$ifNull", exprs); //$NON-NLS-1$ this.aliasName = "__NN_"+child.getTable().getName();//$NON-NLS-1$ columns.append(this.aliasName, ifnull); child.setAlias(this.aliasName); child.getMergeKey().setAlias(this.aliasName); return columns; }
public void saveSNE(final String dbName,final String collection,final SeimpTrainingRow newRow){ //Updates the tweet with SNE's and possible comments. final BasicDBList bdbList = new BasicDBList(); if(newRow.getAnnotationList()!=null) { for (final Annotation ann:newRow.getAnnotationList()) { final BasicDBObject bdbo = new BasicDBObject(); bdbo.put("comments",ann.getComments()); bdbo.put("annotator",ann.getAnnotator()); bdbo.put("sneList",ann.getSneList()); bdbList.add(bdbo); } } final BasicDBObject dbo=new BasicDBObject(); dbo.append("$set", new BasicDBObject().append("annotationList",bdbList)); MongoDbManager.getCollection(dbName, collection).update(new BasicDBObject().append("_id",newRow.get_id()),dbo); }