List of usage examples for com.mongodb BasicDBObject getString
public String getString(final String key)
From source file:tango.dataStructure.Field.java
License:Open Source License
public Field(BasicDBObject dbField, Experiment xp) { this.xp = xp; this.id = (ObjectId) dbField.get("_id"); this.name = dbField.getString("name"); this.mc = xp.getConnector(); inputImages = new InputFieldImages(this); this.verbose = false; this.nbCPUs = Core.getMaxCPUs(); thumbnails = new ImageIcon[xp.getNBFiles()]; }
From source file:tango.gui.DataManager.java
License:Open Source License
private void extractData() { HashMap<MultiKey, TreeSet<String>> newC2CKeys = new HashMap<MultiKey, TreeSet<String>>(); TreeSet<String> NucKeysToAdd = new TreeSet<String>(); DBCursor cur = mc.getXPNuclei(xp.getName()); cur.sort(new BasicDBObject("field_id", 1).append("idx", 1)); int nbNuc = cur.count(); IJ.log("extract data nb nuc:" + nbNuc); objectMes = new HashMap<Integer, TreeMap<MultiKey3D, String>>(ojectKeys.size()); nbObjects = new TreeMap<MultiKey2D, int[]>(); nucTags = new TreeMap<MultiKey2D, Integer>(); nucIds = new TreeMap<MultiKey2D, String>(); for (int i : ojectKeys.keySet()) { if (i < 0) { continue; }/* w ww . j a v a 2 s . co m*/ objectMes.put(i, new TreeMap<MultiKey3D, String>()); } if (!ojectKeys.containsKey(0)) { objectMes.put(0, new TreeMap<MultiKey3D, String>()); ojectKeys.put(0, new TreeSet<String>()); } o2oMes = new HashMap<MultiKey, TreeMap<MultiKey4D, String>>(); for (MultiKey dk : c2cKeys.keySet()) { o2oMes.put(dk, new TreeMap<MultiKey4D, String>()); newC2CKeys.put(dk, new TreeSet<String>()); } while (cur.hasNext()) { BasicDBObject nuc = (BasicDBObject) cur.next(); if (nuc.getInt("tag", 0) < 0) { continue; // exclude negative tags } ObjectId nucId = (ObjectId) nuc.get("_id"); int nucIdx = nuc.getInt("idx"); String fieldName = mc.getField((ObjectId) nuc.get("field_id")).getString("name"); int[] nbPart = new int[channelNames.length]; //mesure objects for (int i = 0; i < channelNames.length; i++) { TreeMap<MultiKey3D, String> omes = objectMes.get(i); TreeSet<String> keys = ojectKeys.get(i); DBCursor cursor = mc.getObjectsCursor(nucId, i); cursor.sort(new BasicDBObject("idx", 1)); nbPart[i] = cursor.count(); if (keys != null && !keys.isEmpty()) { while (cursor.hasNext()) { BasicDBObject o = (BasicDBObject) cursor.next(); //IJ.log("o="+o); //IJ.log("omes="+omes); //IJ.log("f="+fieldName+" "+nucIdx+" "+o.getInt("idx")+" "+keys); for (String k : keys) { //IJ.log("k="+k+" "+o.getString(k)); if (o.getString(k) != null) { omes.put(new MultiKey3D(fieldName, nucIdx, o.getInt("idx"), k), o.get(k).toString()); } } } } cursor.close(); } String s = ""; for (int i : nbPart) { s += i + ";"; } //IJ.log("nb objects:" + s); MultiKey2D k2D = new MultiKey2D(fieldName, nucIdx, "nbParts"); nbObjects.put(k2D, nbPart); nucTags.put(k2D, nuc.getInt("tag", 0)); nucIds.put(k2D, nuc.getString("_id")); //C2C TreeMap<MultiKey3D, String> nucMes = objectMes.get(0); for (MultiKey dk : c2cKeys.keySet()) { if (dk.getKey(0) < 0) { continue; } int size = (dk.getKey(0) != dk.getKey(1)) ? nbPart[dk.getKey(0)] * nbPart[dk.getKey(1)] : nbPart[dk.getKey(0)] * (nbPart[dk.getKey(0)] - 1) / 2; BasicDBObject mes = mc.getMeasurementStructure(nucId, dk.getKeys(), true); //IJ.log("get mes:" + dk + " mes"); TreeMap<MultiKey4D, String> o2oMesDk = o2oMes.get(dk); TreeSet<String> keys = c2cKeys.get(dk); TreeSet<String> newKeys = newC2CKeys.get(dk); for (String k : keys) { Object o = mes.get(k); if (o instanceof BasicDBList) { BasicDBList list = ((BasicDBList) o); if (list.size() == size) { int count = 0; if (dk.getKey(0) != dk.getKey(1)) { for (int p1 = 1; p1 <= nbPart[dk.getKey(0)]; p1++) { for (int p2 = 1; p2 <= nbPart[dk.getKey(1)]; p2++) { o2oMesDk.put(new MultiKey4D(fieldName, nucIdx, p1, p2, k), list.get(count).toString()); count++; } } } else { for (int p1 = 1; p1 < nbPart[dk.getKey(0)]; p1++) { for (int p2 = p1 + 1; p2 <= nbPart[dk.getKey(1)]; p2++) { o2oMesDk.put(new MultiKey4D(fieldName, nucIdx, p1, p2, k), list.get(count).toString()); count++; } } } newKeys.add(k); } } else if (o instanceof Number || o instanceof String) { String newKey = channelNames[dk.getKey(0)] + "." + channelNames[dk.getKey(1)] + "." + k; nucMes.put(new MultiKey3D(fieldName, nucIdx, 1, newKey), o.toString()); NucKeysToAdd.add(newKey); } } } } cur.close(); this.ojectKeys.get(0).addAll(NucKeysToAdd); this.c2cKeys = newC2CKeys; }
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 .jav a 2 s. c o m } return null; }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public ArrayList<String> getUsers() { DBCursor cur = adminUser.find();/* w w w .j a v a2 s . c om*/ ArrayList<String> res = new ArrayList(cur.size()); while (cur.hasNext()) { BasicDBObject u = (BasicDBObject) cur.next(); String name = u.getString("name"); if (Utils.isValid(name, false)) { res.add(name); } } cur.close(); Collections.sort(res); return res; }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized BasicDBObject setUser(String username, boolean create) { //IJ.log("set user:"+username+ " create?"+create); if ("".equals(username)) { username = null;/*from w w w . j a v a2s. c om*/ } if (username == null) { this.username = null; this.userId = null; settings = null; nucleusSettings = null; channelSettings = null; return null; } try { this.username = username; BasicDBObject user = (BasicDBObject) adminUser.findOne(new BasicDBObject("name", username)); if (user == null) { if (!create) { return null; } String settingsDB = prefix + "_" + username + "_settings"; List<String> names = m.getDatabaseNames(); while (names.contains(settingsDB)) { settingsDB = settingsDB + "0"; } adminUser.save(new BasicDBObject("name", username).append("settingsDB", settingsDB)); user = (BasicDBObject) adminUser.findOne(new BasicDBObject("name", username)); adminProject.createIndex(new BasicDBObject("user_id", 1).append("name", 1)); adminUser.createIndex(new BasicDBObject("name", 1)); help.createIndex(new BasicDBObject("container", 1).append("element", 1)); } userId = (ObjectId) user.get("_id"); //IJ.log("settings DB:"+user.getString("settingsDB")); settings = m.getDB(user.getString("settingsDB")); if (settings == null) { IJ.log("settings null"); } if (!settings.collectionExists("nucleus")) { settings.createCollection("nucleus", new BasicDBObject()); } //IJ.log("collection nucleus created!");} if (!settings.collectionExists("channel")) { settings.createCollection("channel", new BasicDBObject()); } //IJ.log("collection channel created!");} nucleusSettings = settings.getCollection("nucleus"); channelSettings = settings.getCollection("channel"); return user; } catch (Exception e) { exceptionPrinter.print(e, "Connection: ", Core.GUIMode); return null; } }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public ArrayList<String> getProjects() { //db names: prefixe + _ + username + _ + xp element DBCursor cur = adminProject.find(new BasicDBObject("user_id", this.userId)); ArrayList<String> res = new ArrayList<String>(cur.size()); while (cur.hasNext()) { BasicDBObject f = (BasicDBObject) cur.next(); res.add(f.getString("name")); }/* w ww .j ava 2s . co m*/ cur.close(); Collections.sort(res); return res; }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
private String getProjectDBName(String name) { BasicDBObject projectDB = (BasicDBObject) adminProject .findOne(new BasicDBObject("user_id", userId).append("name", name)); if (projectDB == null) { return null; } else {/*from w w w . ja v a 2 s . co m*/ return projectDB.getString("dbname"); } }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized void saveExperiment(BasicDBObject xp) { String name = xp.getString("name"); experiment.update(new BasicDBObject("name", name), xp, true, false); }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized void saveNucSettings(BasicDBObject type) { String name = type.getString("name"); this.nucleusSettings.update(new BasicDBObject("name", name), type, true, false); }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized void saveStructureProcessingChain(BasicDBObject type) { String name = type.getString("name"); this.channelSettings.update(new BasicDBObject("name", name), type, true, false); }