List of usage examples for com.mongodb BasicDBObject containsField
public boolean containsField(final String field)
From source file:rapture.sheet.mongodb.MongoCellStore.java
License:Open Source License
public List<RaptureSheetCell> findCellsByEpoch(final String sheetName, final int dimension, final long minEpochFilter) { MongoRetryWrapper<List<RaptureSheetCell>> wrapper = new MongoRetryWrapper<List<RaptureSheetCell>>() { public DBCursor makeCursor() { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.put(KEY, sheetName);/*from w w w . j a v a 2 s . co m*/ query.put(DIM, dimension); return collection.find(query); } public List<RaptureSheetCell> action(DBCursor cursor) { List<RaptureSheetCell> ret = new ArrayList<RaptureSheetCell>(); Long maxEpoch = 0L; while (cursor.hasNext()) { BasicDBObject val = (BasicDBObject) cursor.next(); RaptureSheetCell cell = new RaptureSheetCell(); cell.setColumn(val.getInt(COL)); cell.setRow(val.getInt(ROW)); cell.setData(val.getString(VALUE)); boolean shouldAdd; if (val.containsField(EPOCH)) { long currEpoch = val.getLong(EPOCH); shouldAdd = (currEpoch > minEpochFilter); cell.setEpoch(currEpoch); if (maxEpoch < currEpoch) { maxEpoch = currEpoch; } } else { shouldAdd = true; } if (shouldAdd) ret.add(cell); } return ret; } }; return wrapper.doAction(); }
From source file:tango.dataStructure.Selection.java
License:Open Source License
protected void appendToNucleus(ObjectId id, int structure, ArrayList<Integer> selectedObjects) { BasicDBObject nucleus = getNucleus(id, true); System.out.println("appending structure:" + structure + " to nucleus:" + id.toHexString()); if (!nucleus.containsField(structure + "")) { nucleus.append(structure + "", selectedObjects); } else {/*from w w w . j a v a 2s . c o m*/ Object o = nucleus.get(structure + ""); Collection c = (Collection) o; selectedObjects.removeAll(c); c.addAll(selectedObjects); } //setNucleus(id, nucleus); }
From source file:tango.dataStructure.Selection.java
License:Open Source License
protected void removeFromNucleus(ObjectId id, int structure, ArrayList<Integer> selectedObjects) { BasicDBObject nucleus = getNucleus(id, false); if (nucleus == null) return;//from w w w . j a va 2 s . c o m if (nucleus.containsField(structure + "")) { Collection list = (Collection) nucleus.get(structure + ""); list.removeAll(selectedObjects); if (list.isEmpty()) nucleus.remove(structure + ""); } }
From source file:tango.gui.CellManager.java
License:Open Source License
private void sort(String key, ArrayList<Cell> cells) { if (key.equals("idx")) return;/* w w w.ja v a 2 s . co m*/ ij.IJ.log("sort by:" + key); Cell.setAscendingOrger(layout.getAscendingOrder()); boolean notFound = false; HashMap<ObjectId, BasicDBObject> objects = null; if (!key.equals("tag")) objects = Core.getExperiment().getConnector().getNucleiObjects(Core.getExperiment().getId()); for (Cell c : cells) { if (key.equals("tag")) c.setValue(c.getTag().getTag()); else { //HashMap<Integer, BasicDBObject> objects = Core.getExperiment().getConnector().getObjects(c.getId(), 0); //ij.IJ.log("nb of objects:"+objects.size()); //BasicDBObject dbo = objects.get(1); BasicDBObject dbo = objects.get(c.getId()); if (dbo != null) { if (dbo.containsField(key)) c.setValue(dbo.getDouble(key)); else { c.setValue(-1); notFound = true; } } } } if (notFound) ij.IJ.log("Warning measurement: " + key + " not found for one or several nuclei"); Collections.sort(cells); }
From source file:tango.gui.FieldManager.java
License:Open Source License
private File getUsrDir() { BasicDBObject usr = Core.mongoConnector.getUser(); if (usr.containsField("importDir")) { File f = new File(usr.getString("importDir")); if (f.exists()) { return f; }/*from w ww . j a v a 2 s.c om*/ } return null; }
From source file:tango.gui.ObjectManager.java
License:Open Source License
private void sort(String key, Object3DGui[] objectsGui, int structureIdx) { Object3DGui.setAscendingOrger(((ObjectManagerLayout) layout).getAscendingOrder()); HashMap<Integer, BasicDBObject> objects = Core.getExperiment().getConnector().getObjects(currentNucId, structureIdx);/*from www . java 2 s. c o m*/ boolean notFound = false; for (Object3DGui o : objectsGui) { BasicDBObject dbo = objects.get(o.getLabel()); if (dbo != null) { if (dbo.containsField(key)) { o.setValue(dbo.getDouble(key)); } else { o.setValue(-1); notFound = true; } } } if (notFound) { ij.IJ.log("Warning measurement: " + key + " not found for one or several objects"); } Arrays.sort(objectsGui); }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized ImageHandler getInputImage(ObjectId field_id, int idx) { BasicDBObject query = new BasicDBObject("field_id", field_id).append("fileRank", idx); GridFSDBFile f = this.gfsField.findOne(query); if (f != null) { ImageHandler res = createImage(f); if (res != null) { return res; }//from w w w . ja v a 2 s . c o m } // open from directory BasicDBObject field = this.getField(field_id); String error = "could'nt open file:" + idx + " from field:" + field.getString("name") + " please relink files by launching the command \"import files\""; if (field.containsField("files")) { BasicDBList files = (BasicDBList) field.get("files"); if (files.size() > 1) { // separated files if (idx >= files.size()) { IJ.log(error); } else { BasicDBObject fileObj = (BasicDBObject) files.get(idx); File file = new File(fileObj.getString("path")); if (file.exists()) { return ImageOpener.OpenChannel(file, 0, 0, 0); } } } else { BasicDBObject fileObj = (BasicDBObject) files.get(0); File file = new File(fileObj.getString("path")); if (file.exists()) { return ImageOpener.OpenChannel(file, idx, fileObj.getInt("series"), fileObj.getInt("timePoint")); } } } else { IJ.log(error); } return null; }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized byte[] createInputImageThumbnail(ObjectId field_id, int idx) { BasicDBObject query = new BasicDBObject("field_id", field_id).append("fileRank", idx); GridFSDBFile f = this.gfsField.findOne(query); if (f != null) { ImageHandler res = createImage(f); if (res != null) { return res.getThumbNail(Field.tmbSize, Field.tmbSize); }/*from w ww . ja v a2 s.c o m*/ } // open from directory BasicDBObject field = this.getField(field_id); String error = "could'nt open file:" + idx + " from field:" + field.getString("name") + " please relink files by launching the command \"import files\""; if (field.containsField("files")) { BasicDBList files = (BasicDBList) field.get("files"); if (files.size() > 1) { // separated files if (idx >= files.size()) { IJ.log(error); } else { BasicDBObject fileObj = (BasicDBObject) files.get(idx); File file = new File(fileObj.getString("path")); if (file.exists()) { return ImageOpener.openThumbnail(file, 0, 0, 0, Field.tmbSize, Field.tmbSize); } } } else { BasicDBObject fileObj = (BasicDBObject) files.get(0); File file = new File(fileObj.getString("path")); if (file.exists()) { return ImageOpener.openThumbnail(file, idx, fileObj.getInt("series"), fileObj.getInt("timePoint"), Field.tmbSize, Field.tmbSize); } } } else { IJ.log(error); } return null; }
From source file:tango.mongo.MongoUtils.java
License:Open Source License
public static float[] getFloatArray(DBCursor cur, String key) { List<DBObject> list = cur.toArray(); float[] res = new float[list.size()]; boolean field = false; for (int i = 0; i < list.size(); i++) { BasicDBObject o = ((BasicDBObject) list.get(i)); if (o.containsField(key)) { field = true;/*from w w w . j av a2 s .c o m*/ res[i] = (float) o.getDouble(key); } } return field ? res : null; }
From source file:tango.mongo.MongoUtils.java
License:Open Source License
public static float[] getFloatArray(BasicDBList list, String key) { float[] res = new float[list.size()]; boolean field = false; for (int i = 0; i < list.size(); i++) { BasicDBObject o = ((BasicDBObject) list.get(i)); if (o.containsField(key)) { field = true;// w w w . j a va 2s. co m res[i] = (float) o.getDouble(key); } } return field ? res : null; }