// Index testing:
////////////////////////////////////////////////
//CANONICAL EXAMPLE:
DocumentPojoIndexMap docMap = new DocumentPojoIndexMap();
System.out.println("DOC_INDEX=" + IndexManager.mapToIndex(doc, docMap));
////////////////////////////////////////////////
// Check use of enums in Entity pojo works
EntityPojo testEnt = new EntityPojo();
testEnt.setDimension(EntityPojo.Dimension.Where);
System.out.println("ENT1=" + new GsonBuilder().setPrettyPrinting().create().toJson(testEnt));
System.out.println("DIM=" + testEnt.getDimension());
BasicDBObject testEntDb = new BasicDBObject("dimension", "Who");
testEnt = new Gson().fromJson(testEntDb.toString(), EntityPojo.class);
System.out.println("ENT2=" + new GsonBuilder().setPrettyPrinting().create().toJson(testEnt));
try {
testEntDb = new BasicDBObject("dimension", "what");
testEnt = BaseDbPojo.getDefaultBuilder().create().fromJson(testEntDb.toString(), EntityPojo.class);
System.out.println("***FAIL=" + BaseDbPojo.getDefaultBuilder().setPrettyPrinting().create().toJson(testEnt));
}
catch (Exception e) {
System.out.println("ENT3: Correctly failed with illegal dimension type");
}
////////////////////////////////////////////////
// Metadata transformations based on type:
String metadataObjStr = "{ 'test__long': 3, 'test_long': '3', 'error__long': { 'field1': 'no'}, "+
"'test_arrayObj': [ { 'field1': 'test' } ], 'test_nestedArrayObj': [ [ { 'field1': 'test' } ] ], "+
"'test_array': [ 'val' ], 'test_nestedArray': [ [ 'val' ] ], "+
"'test_obj': { 'field1': 'string' }, 'test_nestedObj': { 'field1': 'string', 'field2': { 'field3': 'string' }},"+
"'test_null1': {}, test_null2: null"+
"}";
BasicDBObject metadataObj = (BasicDBObject) com.mongodb.util.JSON.parse(metadataObjStr);
doc.addToMetadata("TestMeta", metadataObj);
System.out.println("DOC_META=" + docMap.extendBuilder(BaseApiPojo.getDefaultBuilder()).setPrettyPrinting().create().toJson(doc));
// Changes to new ElasticSearch construct (particularly for bulk add)
ElasticSearchManager indexManager = IndexManager.createIndex("test", null, false, null, null, ImmutableSettings.settingsBuilder());
BulkResponse result = null;
// All docs
result = indexManager.bulkAddDocuments(IndexManager.mapListToIndex(docset, new TypeToken<Set<DocumentPojo>>(){},
new DocumentPojoIndexMap()), "_id", null, true);
if (result.hasFailures()) {
System.out.print("****** FAILED: ");
System.out.println(result.buildFailureMessage());
}