List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:com.fliker.Modal.GuidancePreview.java
public HashMap getGuidanceQuizData(String guidanceid) { // TODO Auto-generated method stub ArrayList guidancequizlist = new ArrayList(); MongoConnection mongocon = new MongoConnection(); HashMap quizlistmap = new HashMap(); DBCursor resultcursor = mongocon.getDBObject("guidanceid", guidanceid, "GuidanceContent"); if (resultcursor.hasNext()) { DBObject dbj = resultcursor.next(); BasicDBList quizlist = (BasicDBList) dbj.get("quizids"); for (int k = 0; k < quizlist.size(); k++) { HashMap quizmap = new HashMap(); DBCursor quizlinkcursor = mongocon.getDBObject("quizid", (String) quizlist.get(k), "GuidanceQuizLink"); while (quizlinkcursor.hasNext()) { DBObject quizdbj = quizlinkcursor.next(); quizmap.put("quizid", quizdbj.get("quizid")); DBCursor quizdatcursor = mongocon.getDBObject("quizid", (String) quizdbj.get("quizid"), "GuidanceContentQuiz"); if (quizdatcursor.hasNext()) { DBObject quizdatdbj = quizdatcursor.next(); quizmap.put("quizname", quizdbj.get("quizname")); quizmap.put("quizdescription", quizdbj.get("quizdescription")); quizmap.put("quizdatetime", quizdbj.get("quizdatetime")); }// ww w. j a va 2 s . co m quizmap.put("shareduserids", (BasicDBList) quizdbj.get("shareduserids")); /*ArrayList feedbacklist = new ArrayList(); BasicDBList feedbcklist = (BasicDBList)quizdbj.get("guidancefeedbackid"); for(int x=0;x<feedbcklist.size();x++){ DBCursor feedbackcursor = mongocon.getDBObject("feedbackid", (String)feedbcklist.get(x), "GuidanceFeedback"); while(feedbackcursor.hasNext()){ DBObject feedbackdbj = feedbackcursor.next(); feedbacklist.add(feedbackdbj.get("feedback")); } } quizmap.put("feedback", feedbacklist); ArrayList remarklist = new ArrayList(); BasicDBList remrklst = (BasicDBList)quizdbj.get("guidanceremarkid"); for(int h=0;h<remrklst.size();h++){ DBCursor remarkcursor = mongocon.getDBObject("remarkid", (String)remrklst.get(h), "GuidanceRemarks"); while(remarkcursor.hasNext()){ DBObject remarkdbj = remarkcursor.next(); remarklist.add((BasicDBList)remarkdbj.get("remarks")); } } quizmap.put("remarks", remarklist);*/ } quizlistmap.put((String) quizlist.get(k), quizmap); } } return quizlistmap; }
From source file:com.fliker.Modal.GuidancePreview.java
public ArrayList getAllSpecifications(String guidanceid, String userid) { // TODO Auto-generated method stub MongoConnection mongocon = new MongoConnection(); DBCursor resultcursor = mongocon.getDBObject("guidanceid", guidanceid, "GuidanceContent"); ArrayList specificlist = new ArrayList(); if (resultcursor.hasNext()) { DBObject dbj = resultcursor.next(); BasicDBList specificationlist = (BasicDBList) dbj.get("specification"); for (int j = 0; j < specificationlist.size(); j++) { HashMap specificatiomap = new HashMap(); DBCursor specificcursor = mongocon.getDBObject("specificationid", (String) specificationlist.get(j), "GuidanceSpecificationData"); while (specificcursor.hasNext()) { DBObject specificdbj = specificcursor.next(); specificatiomap.put("specificationid", (String) specificdbj.get("specificationid")); specificatiomap.put("specificationname", (String) specificdbj.get("specificationname")); specificatiomap.put("specificationdetails", (String) specificdbj.get("specificationdetails")); specificatiomap.put("specificationpercentage", "5"); }//w w w . j a v a 2 s . c om specificlist.add(specificatiomap); } } return specificlist; }
From source file:com.flyingdonut.implementation.helpers.MongoDbConsumerAssociationStore.java
License:Apache License
private void mongoEnsureIndexAddAll(DBObject indexDoc, BasicDBList queryKeys) { for (String k : queryKeys.keySet()) { BasicDBObject value = (BasicDBObject) queryKeys.get(k); if (k.startsWith("$")) { mongoEnsureIndexAddAll(indexDoc, (BasicDBList) queryKeys.get(k)); } else {//from w w w.j a va2 s.co m for (String kk : value.keySet()) { indexDoc.put(kk, 1); } } } }
From source file:com.fpt.xml.hth.db.lib.converter.MovieTheaterSessionConverter.java
/** * To convert from BasicDBObject object to MovieDBTheaterSessionDTO object * * @param object/*from w w w . j av a2 s. c om*/ * @return MovieDBTheaterSessionDTO */ //TODO: remove public MovieTheaterSessionDTO convertBasicObjectToModel(BasicDBObject object) { MovieTheaterSessionDTO dto = new MovieTheaterSessionDTO(); ObjectId id = object.getObjectId("_id"); BasicDBObject basicMovie = (BasicDBObject) object.get("movie"); BasicDBList basicLstSession = (BasicDBList) object.get("theaters"); //convert basicMovie object movie MovieDB movie = movieConverter.convertBasicObjectToModel(basicMovie); //convert basicLstSession to theaters List<TheaterSessionDTO> theaters = new ArrayList<TheaterSessionDTO>(); if (basicLstSession != null && !basicLstSession.isEmpty()) { for (int i = 0; i < basicLstSession.size(); i++) { BasicDBObject basic = (BasicDBObject) basicLstSession.get(i); TheaterSessionDTO theaterSessionDTO = tsConverter.convertBasicObjectToModel(basic); theaters.add(theaterSessionDTO); } } //set value for object MovieTheaterSessionDTO dto.setId(id); dto.setMovie(movie); dto.setTheaters(theaters); return dto; }
From source file:com.fpt.xml.hth.db.lib.converter.TheaterSessionConverter.java
/** * To convert from BasicDBObject object to TheaterDBSessionDTO object * * @param object/* ww w.j a v a 2s . c o m*/ * @return TheaterDBSessionDTO */ public TheaterSessionDTO convertBasicObjectToModel(BasicDBObject object) { String cinemaName = object.getString("cinemaName"); String id = object.getString("id"); BasicDBObject basicTheater = (BasicDBObject) object.get("theater"); BasicDBList basicSessions = (BasicDBList) object.get("sessions"); // convert basicTheater to theater TheaterDB theater = conveter.convertBasicObjectToModel(basicTheater); // convert basicSessions to session List<String> sessions = new ArrayList<String>(); for (int i = 0; i < basicSessions.size(); i++) { String session = basicSessions.get(i).toString(); sessions.add(session); } TheaterSessionDTO theaterSessionDTO = new TheaterSessionDTO(); theaterSessionDTO.setId(id); theaterSessionDTO.setCinemaName(cinemaName); theaterSessionDTO.setLstSession(sessions); theaterSessionDTO.setTheater(theater); return theaterSessionDTO; }
From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java
License:Open Source License
private Object toExactArray(BasicDBList value) { if (value.size() < 1) throw new IllegalStateException( "Illegal BSON array size: " + value.size() + ", size must be at lest 1"); Class<?> type = getClassFor((String) value.get(0)); return toExtractArray(value, type); }
From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) private Map toMap(Class<?> type, BasicDBList value) { try {//from www .j a v a2 s. co m Map map; if (!type.isInterface()) { map = (Map) repository.getConstructor(type).newInstance(); } else { map = (Map) repository.getConstructor(getClassFor((String) value.get(0))).newInstance(); } for (int i = 1; i < value.size(); i += 2) { Object key = fromDBObject(value.get(i)); Object val = fromDBObject(value.get(i + 1)); map.put(key, val); } return map; } catch (InvocationTargetException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } catch (InstantiationException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } catch (IllegalAccessException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } }
From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java
License:Open Source License
private Object toArray(Class<?> type, BasicDBList value) { int length = value.size() - 1; Object array = Array.newInstance(type.getComponentType(), length); for (int i = 1; i < length + 1; i++) { Object v = fromDBObject(value.get(i)); if (SpaceDocument.class.isAssignableFrom(type.getComponentType())) v = MongoDocumentObjectConverter.instance().toDocumentIfNeeded(v, SpaceDocumentSupport.CONVERT); if (type(type.getComponentType()) == TYPE_SHORT) v = ((Integer) v).shortValue(); Array.set(array, i - 1, v); }//www. ja va2 s. co m return array; }
From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) private Collection toCollection(Class<?> type, BasicDBList value) { try {//www . j a v a2 s. c om Collection collection; if (!type.isInterface()) { collection = (Collection) repository.getConstructor(type).newInstance(); } else { collection = (Collection) repository.getConstructor(getClassFor((String) value.get(0))) .newInstance(); } for (int i = 1; i < value.size(); i++) collection.add(fromDBObject(value.get(i))); return collection; } catch (InvocationTargetException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } catch (InstantiationException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } catch (IllegalAccessException e) { throw new SpaceMongoException("Could not find default constructor for type: " + type.getName(), e); } }
From source file:com.gigaspaces.persistency.metadata.SpaceDocumentMapperImpl.java
License:Open Source License
private Object toExactArray(BasicDBList value) { if (value.size() < 1) throw new IllegalStateException( "Illegal BSON array size: " + value.size() + ", size must be at lest 1"); Class<?> type = getClassFor((String) value.get(0)); if (type.isArray()) { return toArray(type, value); } else if (Collection.class.isAssignableFrom(type)) { return toCollection(type, value); } else if (Map.class.isAssignableFrom(type)) { return toMap(type, value); }/* w w w. ja v a 2 s . c o m*/ throw new SpaceMongoException("invalid Array/Collection/Map type: " + type.getName()); }