List of usage examples for com.mongodb DBObject containsField
boolean containsField(String s);
From source file:com.epam.ta.reportportal.database.LaunchesDurationDocumentHandler.java
License:Open Source License
@Override public void processDocument(DBObject dbObject) throws MongoException, DataAccessException { ChartObject chartObject = new ChartObject(); Map<String, String> values = new HashMap<>(); chartObject.setId(dbObject.get(ID).toString()); if (dbObject.containsField(START_TIME) && dbObject.containsField(END_TIME)) { Long startTime = ((Date) dbObject.get(START_TIME)).getTime(); Long endTime = ((Date) dbObject.get(END_TIME)).getTime(); long duration = endTime - startTime; values.put(START_TIME, String.valueOf(startTime)); values.put(END_TIME, String.valueOf(endTime)); values.put(DURATION, String.valueOf(duration)); }//from w w w . j a va2 s . c om if (dbObject.containsField(NAME)) { chartObject.setName(dbObject.get(NAME).toString()); } if (dbObject.containsField(NUMBER)) { chartObject.setNumber(dbObject.get(NUMBER).toString()); } if (dbObject.containsField(STATUS)) { values.put(STATUS, dbObject.get(STATUS).toString()); } chartObject.setValues(values); result.add(chartObject); }
From source file:com.epam.ta.reportportal.database.UniqueBugDocumentHandler.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void processDocument(DBObject dbObject) throws MongoException, DataAccessException { if (dbObject.containsField(ISSUE) && ((DBObject) dbObject.get(ISSUE)).containsField(EXTERNAL_SYSTEM_ISSUES)) { List<DBObject> innerDbObjects = (List<DBObject>) ((DBObject) dbObject.get(ISSUE)) .get(EXTERNAL_SYSTEM_ISSUES); for (DBObject innerDbObject : innerDbObjects) { ChartObject axisObject = new ChartObject(); Map<String, String> objectValues = new HashMap<>(); String ticketId;//from ww w. j a va 2 s .c om if (dbObject.containsField(LAUNCH_REF)) { objectValues.put(LAUNCH_REF, dbObject.get(LAUNCH_REF).toString()); axisObject.setValues(objectValues); } if (dbObject.containsField(ID)) { /* ID of test-item containing external system issue */ axisObject.setId(dbObject.get(ID).toString()); } if (innerDbObject.containsField(SUBMIT_DATE)) { axisObject.setStartTime(innerDbObject.get(SUBMIT_DATE).toString()); } if (innerDbObject.containsField(SUBMITTER)) { axisObject.setName(innerDbObject.get(SUBMITTER).toString()); } if (innerDbObject.containsField(TICKET_ID)) { ticketId = innerDbObject.get(TICKET_ID).toString(); if (result.containsKey(ticketId)) { List<ChartObject> items = result.get(ticketId); items.add(axisObject); } else result.put(ticketId, Lists.newArrayList(axisObject)); } } } }
From source file:com.epam.ta.reportportal.triggers.DeleteLogsListener.java
License:Open Source License
@Override public void onBeforeDelete(BeforeDeleteEvent<Log> event) { List<String> ids = new ArrayList<>(); for (DBObject dbObject : mongoTemplate.getCollection(event.getCollectionName()).find(queryMapper .getMappedObject(event.getDBObject(), mongoMappingContext.getPersistentEntity(Log.class)))) { if (dbObject.containsField("binary_content")) { @SuppressWarnings("unchecked") Map<String, Object> binaries = (Map<String, Object>) dbObject.get("binary_content"); if (binaries.containsKey("id")) { ids.add(binaries.get("id").toString()); }//w w w. j a va 2s . co m if (binaries.containsKey("thumbnail_id")) { ids.add(binaries.get("thumbnail_id").toString()); } } } dataStorage.delete(ids); }
From source file:com.eywa.impl.app.controllers.central.Activity.java
License:Open Source License
public Object getData(final String key) { final DBObject data = getData(); if (null != data && data.containsField(key)) { return data.get(key); }/* w ww . java 2 s . co m*/ return null; }
From source file:com.eywa.impl.app.mongo.entities.items.session.cart.ItemSessionDataCart.java
License:Open Source License
public static void setItems(final DBObject item, final List<DBObject> value) { MongoUtils.put(item, ITEMS, value);/*from w ww . j ava2 s . c om*/ setItemsCount(item, getItems(item).size()); double total_qty = 0; double total_price = 0; final List<String> seller_id = new LinkedList<>(); final DBObject seller_price = new BasicDBObject(); String currency = DEF_CURRENCY; for (final DBObject cart_item : value) { final double price = ItemSessionDataCartItem.getPrice(cart_item); final double qty = ItemSessionDataCartItem.getQty(cart_item); final String seller = ItemSessionDataCartItem.getSellerId(cart_item); currency = ItemSessionDataCartItem.getCurrencyCode(cart_item); total_qty += qty; total_price += price * qty; if (!seller_id.contains(seller)) { seller_id.add(seller); } if (!seller_price.containsField(seller)) { seller_price.put(seller, 0.0); } seller_price.put(seller, MongoUtils.getDouble(seller_price, seller) + price * qty); } setItemsPrice(item, total_price); setItemsQty(item, total_qty); setSellerId(item, seller_id); setSellerPrice(item, seller_price); setCurrencyCode(item, currency); }
From source file:com.gatf.executor.dataprovider.MongoDBTestDataSource.java
License:Apache License
public List<Map<String, String>> provide(GatfTestDataProvider provider, AcceptanceTestContext context) { List<Map<String, String>> result = new ArrayList<Map<String, String>>(); Assert.assertNotNull("provider cannot be null", provider); Assert.assertTrue("provider cannot be null", provider.getArgs() != null && provider.getArgs().length > 0); Assert.assertNotNull("mongodb-collection cannot be empty", provider.getArgs()[0]); Assert.assertNotNull("queryString cannot be empty", provider.getQueryStr()); Assert.assertNotNull("variableNames cannot be empty", provider.getSourceProperties()); Assert.assertNotNull("propertyNames cannot be empty", provider.getProviderProperties()); String dbName = args[2].trim(); String collName = provider.getArgs()[0].trim(); String queryString = provider.getQueryStr().trim(); String variableNames = provider.getProviderProperties(); String propertyNames = provider.getSourceProperties(); Assert.assertNotNull("mongodb-collection cannot be empty", collName.isEmpty()); Assert.assertFalse("queryString cannot be empty", queryString.isEmpty()); List<String> variableNamesArr = new ArrayList<String>(); for (String varName : variableNames.split(",")) { if (!varName.trim().isEmpty()) { variableNamesArr.add(varName); }//from w w w . j ava 2 s. c o m } Assert.assertTrue("need to define at-least a single variable name", !variableNames.isEmpty() && variableNames.split(",").length > 0 && variableNamesArr.size() > 0); List<String> propertyNamesArr = new ArrayList<String>(); for (String varName : propertyNames.split(",")) { if (!varName.trim().isEmpty()) { propertyNamesArr.add(varName); } } Assert.assertTrue("need to define at-least a single property name", !propertyNames.isEmpty() && propertyNames.split(",").length > 0 && propertyNamesArr.size() > 0); Assert.assertTrue("property name and variable name sizes don't match", propertyNamesArr.size() == variableNamesArr.size()); StringBuilder build = new StringBuilder(); build.append("Provider configuration [\n"); build.append(String.format("dataSource name is %s\n", getDataSourceName())); build.append(String.format("mongodb-collection is %s\n", collName)); build.append(String.format("queryString is %s\n", queryString)); build.append(String.format("propertyNames is %s\n", propertyNames)); build.append(String.format("variableNames is %s]", variableNames)); logger.info(build.toString()); Resource res = null; try { res = getResource(); MongoClient mongoClient = (MongoClient) res.object; DB db = null; try { db = mongoClient.getDB(dbName); DBCollection coll = db.getCollection(collName); Assert.assertNotNull(String.format("Mongodb collection %s not found", collName), coll); DBObject queryObject = null; try { queryObject = (DBObject) JSON.parse(queryString); } catch (Exception e) { Assert.assertNotNull("queryString passed is invalid"); } DBCursor cursor = null; try { cursor = coll.find(queryObject); while (cursor.hasNext()) { DBObject object = cursor.next(); Map<String, String> row = new HashMap<String, String>(); for (int i = 0; i < variableNamesArr.size(); i++) { Assert.assertTrue( String.format("Could not find %s field in the result document returned", propertyNamesArr.get(i)), object.containsField(propertyNamesArr.get(i))); row.put(variableNamesArr.get(i), object.get(propertyNamesArr.get(i)).toString()); } result.add(row); } } catch (Exception e) { throw new AssertionError(e); } finally { if (cursor != null) cursor.close(); } } catch (Exception e) { throw new AssertionError( String.format("Fetching Test Data failed while executing query %s with the error %s", queryString, ExceptionUtils.getStackTrace(e))); } finally { if (mongoClient != null) mongoClient.close(); } } catch (Exception e) { throw new AssertionError( String.format("Fetching Test Data failed while executing query %s with the error %s", queryString, ExceptionUtils.getStackTrace(e))); } finally { if (res != null) releaseToPool(res); } return result; }
From source file:com.gigaspaces.persistency.datasource.MongoQueryFactory.java
License:Open Source License
@SuppressWarnings("static-access") private static void replaceIdProperty(BasicDBObjectBuilder qResult, SpaceTypeDescriptor typeDescriptor) { DBObject q = qResult.get(); if (q.containsField(typeDescriptor.getIdPropertyName())) { Object value = q.get(typeDescriptor.getIdPropertyName()); q.removeField(typeDescriptor.getIdPropertyName()); q.put(Constants.ID_PROPERTY, value); qResult.start(q.toMap());/*from w w w .ja v a2 s . com*/ } }
From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java
License:Open Source License
@SuppressWarnings("unchecked") private Object toExactObject(Object value) { DBObject bson = (DBObject) value; if (bson.containsField(Constants.TYPE) && bson.containsField(Constants.VALUE)) { String t = (String) bson.get(Constants.TYPE); if (Constants.CUSTOM_BINARY.equals(t)) { Object result = deserializeObject(bson); return result; } else {// w ww . j av a 2s.c om try { @SuppressWarnings("rawtypes") Class type = Class.forName(t); if (type.isEnum()) return Enum.valueOf(type, (String) bson.get(Constants.VALUE)); else return fromSpecialType((DBObject) value); } catch (ClassNotFoundException e) { } } } return toDocument(bson); }
From source file:com.gigaspaces.persistency.metadata.SpaceDocumentMapperImpl.java
License:Open Source License
@SuppressWarnings("unchecked") private Object toExactObject(Object value) { DBObject bson = (DBObject) value; if (bson.containsField(TYPE) && bson.containsField(VALUE)) { try {// w w w. j a v a 2 s .c om @SuppressWarnings("rawtypes") Class type = Class.forName((String) bson.get(TYPE)); if (type.isEnum()) return Enum.valueOf(type, (String) bson.get(VALUE)); else return fromSpetialType((DBObject) value); } catch (ClassNotFoundException e) { } } return toDocument(bson); }
From source file:com.github.dbourdette.otto.source.config.TransformConfig.java
License:Apache License
public static TransformConfig fromDBObject(DBObject dbObject) { TransformConfig config = new TransformConfig(); if (dbObject == null || !dbObject.containsField("operations")) { return config; }/* w ww .j a va 2 s. com*/ List<DBObject> operations = (List<DBObject>) dbObject.get("operations"); for (DBObject object : operations) { String parameter = (String) object.get("name"); String parameterOperations = (String) object.get("operations"); config.forParam(parameter).add(parameterOperations); } return config; }