List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
From source file:Candidate.NodeCandidate.NodeCandidate.java
@Override public BasicDBObject toDBObject() { BasicDBObject doc = super.toDBObject(); ArrayList<BasicDBObject> alignsObject = new ArrayList<>(); for (Alignment al : aligns) { BasicDBObject alignDoc = new BasicDBObject(); alignDoc.append("uri1", al.getUri()); alignDoc.append("uri2", al.getUriAlign()); alignDoc.append("trustScore", al.getValue()); alignsObject.add(alignDoc);/*from w w w .j av a 2s .com*/ } doc.append("aligns", alignsObject); doc.append("ncId", this.id); doc.append("alreadyValidated", this.alreadyValidated); doc.append("trustScoreDegree", this.trustDegree); return doc; }
From source file:cc.acs.mongofs.gridfs.GridFSInputFile.java
License:Apache License
public DBObject getMetaData() { if (_metadata == null) _metadata = new BasicDBObject(); return _metadata; }
From source file:cfel.service.PortalImportTask.java
License:Open Source License
private void importActivity(JSONObject activity, String portal_image_url) { // System.out.println(activity.toString()); try {/*from ww w. j a v a 2 s .c o m*/ JSONObject member = activity.getJSONObject("member"); if (member.containsKey("id")) { String title = activity.getString("body").replace(activity.getString("image_large_url"), "").trim(); DBObject photo = new BasicDBObject(); photo.put("portal_image_url", portal_image_url); if (mPhotoCollection.count(photo) > 0) { System.err.println(portal_image_url + " already exists"); return; } else { System.out.println("Inserting " + portal_image_url); } String imageSourceUrl = Config.PORTAL_URL.startsWith("http:") ? portal_image_url.replace("https://", "http://") : portal_image_url; BufferedImage[] images = ImageUtil.convertImage(new URL(imageSourceUrl)); if (images == null) { System.err.println(portal_image_url + " corrupted"); return; } saveThumbnailImages(photo, images, "/" + getFileId(portal_image_url) + ".png"); photo.put("uploader_user_id", member.getString("id")); photo.put("title", title); Object exifObj = getExifData(portal_image_url); Date date = null; if (exifObj instanceof JSONObject) { JSONObject exif = (JSONObject) exifObj; if (exif.containsKey("date")) { try { date = FORMAT_DATE_ISO.parse(exif.getString("date")); } catch (ParseException e) { e.printStackTrace(); } } if (exif.containsKey("location")) { photo.put("exif_location", exif.getJSONArray("location")); } } if (date == null && activity.containsKey("created_at")) { try { date = FORMAT_DATE.parse(activity.getString("created_at")); } catch (ParseException e) { e.printStackTrace(); } } if (date != null) { photo.put("exif_date", date); } mPhotoCollection.insert(photo); // System.out.println(photo); // System.out.println(); } } catch (JSONException | MalformedURLException e) { e.printStackTrace(); } }
From source file:ch.agent.crnickl.mongodb.MongoDatabaseMethods.java
License:Apache License
/** * Return a com.mongodb.DbObject representing an operation object for an * operator and list of arguments. See {@link #mongoObject(Object...)} for * restrictions on the list of arguments. * // w w w .j a v a 2s .c o m * @param op * the operator * @param arg * the list of arguments * @return an operation * @throws IllegalArgumentException */ protected com.mongodb.DBObject operation(Operator op, Object... arg) { com.mongodb.DBObject operation = new BasicDBObject(); addOperation(operation, op, arg); return operation; }
From source file:ch.agent.crnickl.mongodb.MongoDB.java
License:Apache License
private DBCollection createCollection(DB db, String name, String... keys) throws T2DBException { DBCollection coll = db.getCollection(name); if (keys.length > 0) { DBObject index = new BasicDBObject(); DBObject options = new BasicDBObject(); for (String key : keys) { index.put(key, 1);//from www . j a v a 2s . c om } options.put("unique", 1); coll.ensureIndex(index, options); } return coll; }
From source file:ch.agent.crnickl.mongodb.MongoDB.java
License:Apache License
private void createIndex(DBCollection coll, String... keys) throws T2DBException { if (keys.length > 0) { DBObject index = new BasicDBObject(); for (String key : keys) index.put(key, 1);//from w w w. j a v a 2 s . co m coll.ensureIndex(index); } }
From source file:ch.agent.crnickl.mongodb.WriteMethodsForChroniclesAndSeries.java
License:Apache License
private DBObjectId insert(Chronicle chronicle) throws T2DBException { com.mongodb.BasicDBObject bo = new BasicDBObject(); Surrogate s = chronicle.getSurrogate(); if (!s.inConstruction()) bo.put(MongoDatabase.FLD_ID, getId(chronicle)); // use case: re-creating bo.put(MongoDatabase.FLD_CHRON_NAME, chronicle.getName(false)); bo.put(MongoDatabase.FLD_CHRON_DESC, chronicle.getDescription(false)); bo.put(MongoDatabase.FLD_CHRON_PARENT, getIdOrZero(chronicle.getCollection())); bo.put(MongoDatabase.FLD_CHRON_SCHEMA, getIdOrZero(chronicle.getSchema(false))); getMongoDB(s).getChronicles().insert(bo); ObjectId ox = getObjectId(bo);//from ww w.ja v a 2s .co m return new MongoDBObjectId(ox); }
From source file:ch.agent.crnickl.mongodb.WriteMethodsForChroniclesAndSeries.java
License:Apache License
private <T> DBObjectId insert(Series<T> series) throws T2DBException { com.mongodb.BasicDBObject bo = new BasicDBObject(); Surrogate s = series.getSurrogate(); if (!s.inConstruction()) bo.put(MongoDatabase.FLD_ID, getId(series)); // use case: re-creating bo.put(MongoDatabase.FLD_SER_CHRON, getIdOrZero(series.getChronicle())); bo.put(MongoDatabase.FLD_SER_NUM, series.getNumber()); bo.put(MongoDatabase.FLD_SER_FIRST, 1); bo.put(MongoDatabase.FLD_SER_LAST, 0); bo.put(MongoDatabase.FLD_SER_VALUES, new HashMap<String, DBObjectId>()); getMongoDB(s).getSeries().insert(bo); ObjectId ox = getObjectId(bo);// ww w. j a v a 2s .c o m return new MongoDBObjectId(ox); }
From source file:ch.agent.crnickl.mongodb.WriteMethodsForProperty.java
License:Apache License
/** * Packs a property into a BSON object.//from w ww . j a v a2s .c o m * * @param prop a Property * @return a BasicDBObject */ private <T> BasicDBObject pack(Property<T> prop) { com.mongodb.BasicDBObject bo = new BasicDBObject(); if (!prop.getSurrogate().inConstruction()) bo.put(MongoDatabase.FLD_ID, getId(prop)); bo.put(MongoDatabase.FLD_PROP_NAME, prop.getName()); bo.put(MongoDatabase.FLD_PROP_VT, getId(prop.getValueType())); bo.put(MongoDatabase.FLD_PROP_INDEXED, prop.isIndexed()); return bo; }
From source file:ch.agent.crnickl.mongodb.WriteMethodsForSchema.java
License:Apache License
/** * Find a chronicle referencing one of the schemas. * This looks like a "reading" method but is used in the context of schema updating. * /*from ww w . j a v a 2s .c om*/ * @param schema a schema * @return a surrogate or null * @throws T2DBException */ public Surrogate findChronicle(Schema schema) throws T2DBException { Surrogate result = null; try { Database db = schema.getDatabase(); DBObject query = new BasicDBObject(); query.put(MongoDatabase.FLD_CHRON_SCHEMA, getId(schema)); DBObject obj = getMongoDB(db).getChronicles().findOne(query); if (obj != null) result = makeSurrogate(db, DBObjectType.CHRONICLE, getObjectId((BasicDBObject) obj)); } catch (Exception e) { throw T2DBMsg.exception(e, E.E30117); } return result; }