list2 = AdvancedQueryPojo.listFromApi(sQueryJson, new TypeToken<List<AdvancedQueryPojo>>(){});
////////////////////////////////////////////////
System.out.println("APL=" + new Gson().toJson(list2));
//API: BasicDBList (like feeds in the full system)
BasicDBList dbl = new BasicDBList();
BasicDBObject db01 = new BasicDBObject("index", 1);
BasicDBObject db02 = new BasicDBObject("index", 2);
BasicDBObject db03 = new BasicDBObject("index", 3);
dbl.addAll(Arrays.asList(db01, db02, db03));
ResponsePojo rp2 = new ResponsePojo(null, dbl, (BasePojoApiMap<BasicDBList>)null);
System.out.println("DBO=" + rp2.toApi());
//API: test the V0 DocumentPojo, which has a few differences (including a static version for raw modification)
BasicDBObject docApiDbo = (BasicDBObject) DbManager.getDocument().getMetadata().findOne();
// (remove a few things to tidy up display)
docApiDbo.remove("entities");
docApiDbo.remove("associations");
docApiDbo.remove("metadata");
// (remove things as a test)
// docApiDbo.remove("sourceKey");
// docApiDbo.remove("source");
// docApiDbo.remove("mediaType");
// (sourceKey in <key>#<community> format)
// docApiDbo.put("sourceKey", docApiDbo.getString("sourceKey")+"#doc_api_test");
// (display results of API mappings)
DocumentPojo docApi = DocumentPojo.fromDb(docApiDbo, DocumentPojo.class);
ResponsePojo rp3 = new ResponsePojo(null, docApi, new DocumentPojoApiMap());
System.out.println("TIME_DOC_API1_CREATED="+docApi.getCreated());
System.out.println("DOC_API1=" + rp3.toApi());
DocumentPojoApiMap.mapToApi(docApiDbo);
System.out.println("DOC_API2=" + BaseApiPojo.getDefaultBuilder().setPrettyPrinting().create().toJson(docApiDbo));
DocumentPojo docFromApi = ApiManager.mapFromApi(ApiManager.mapToApi(docApi, null), DocumentPojo.class, null);
System.out.println("TIME_DOC_API1_CREATED_INV="+docFromApi.getCreated());
/////////////////////////////////////////////////////////////////////////////
// DB testing:
System.out.println("Open Community DB collection");
//OLD:
//CollectionManager cm = new CollectionManager();
//DBCollection communityDb = cm.getCommunities();
//NEW:
DBCollection communityDb = DbManager.getSocial().getCommunity();
//DB: read/write community object
////////////////////////////////////////////////
//CANONICAL EXAMPLE:
CommunityPojo cp = CommunityPojo.fromDb(communityDb.findOne(), CommunityPojo.class);
System.out.println("CP1=" + cp.toDb()); // (converts DBObject to string ie BSON->JSON - should have { $oid } and { $date } objectid/date formats)
////////////////////////////////////////////////
System.out.println("CP2=" + new Gson().toJson(cp)); // (will have complex object id format and string dates)
//DB: read/write list of community objects
////////////////////////////////////////////////
//CANONICAL EXAMPLE:
List<CommunityPojo> cpl = CommunityPojo.listFromDb(communityDb.find().limit(3), CommunityPojo.listType());
System.out.println("CPL1=" + CommunityPojo.listToDb(cpl, CommunityPojo.listType()));
////////////////////////////////////////////////
System.out.println("CPL2=" + BaseDbPojo.getDefaultBuilder().create().toJson(cpl)); // (will have complex object id format and string dates)
//Expect to see another delay here with the old method, new method should roll on...
System.out.println("Open Document DB collection");
//OLD:
//CollectionManager cm2 = new CollectionManager();
//DBCollection documentDb = cm2.getFeeds();
//NEW:
DBCollection documentDb = DbManager.getDocument().getMetadata();
//DB: Read/write feed with metadata
BasicDBObject query = new BasicDBObject("metadata", new BasicDBObject("$exists", true)); // (complex query so can't represent using pojos)
query.put("entities", new BasicDBObject("$size", 3));
////////////////////////////////////////////////
//CANONICAL EXAMPLE:
DocumentPojo doc = DocumentPojo.fromDb(documentDb.findOne(query), DocumentPojo.class);
System.out.println("DOC1="+doc.toDb());
BasicDBList dblTest = (BasicDBList) doc.toDb().get("entities");
BasicDBObject dboTest = (BasicDBObject) dblTest.get(0);
if (!dboTest.get("doccount").getClass().toString().equals("class java.lang.Long")) {
throw new RuntimeException(dboTest.get("doccount").getClass().toString() + " SHOULD BE LONG");
}
////////////////////////////////////////////////
System.out.println("DOC2="+new Gson().toJson(doc));