List of usage examples for com.mongodb BasicDBObject append
@Override public BasicDBObject append(final String key, final Object val)
From source file:fr.gouv.vitam.mdbes.DAip.java
License:Open Source License
/** * //from ww w . j av a 2 s . co m * @param dbvitam * @param model * @return True if inserted in ES */ public boolean addEsIndex(final MongoDbAccess dbvitam, final String model) { BasicDBObject maip = (BasicDBObject) copy(); if (!maip.containsField(NBCHILD)) { maip.append(NBCHILD, nb); } return ElasticSearchAccess.addEsIndex(dbvitam, model, maip); }
From source file:fr.gouv.vitam.mdbes.Domain.java
License:Open Source License
@Override protected boolean updated(final MongoDbAccess dbvitam) { final Domain vt = (Domain) dbvitam.domains.collection.findOne(getId()); BasicDBObject update = null; LOGGER.debug("Previous Domain exists ? " + (vt != null)); if (vt != null) { final List<DBObject> list = new ArrayList<>(); BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.Domain2DAip, true); if (upd != null) { list.add(upd);//w w w.ja v a 2s . c o m } try { update = new BasicDBObject(); if (!list.isEmpty()) { upd = new BasicDBObject(); for (final DBObject dbObject : list) { upd.putAll(dbObject); } update = update.append("$addToSet", upd); } update = update.append("$inc", new BasicDBObject(NBCHILD, nb)); nb = 0; dbvitam.domains.collection.update(new BasicDBObject(ID, this.get(ID)), update); } catch (final MongoException e) { LOGGER.error("Exception for {}", update, e); throw e; } list.clear(); return true; } else { dbvitam.updateLinks(this, null, VitamLinks.Domain2DAip, true); append(NBCHILD, nb); nb = 0; } return false; }
From source file:fr.gouv.vitam.mdbes.MainSimpleRequest.java
License:Open Source License
protected static void oneShot(MongoDbAccess dbvitam) throws InvalidParseOperationException, InvalidExecOperationException, InstantiationException, IllegalAccessException { // Requesting String comdtree = request.toString(); BasicDBObject query = (BasicDBObject) JSON.parse(comdtree); if (ids != null) { BasicDBObject id = (BasicDBObject) JSON.parse(ids); DateTime date = new DateTime(-123456789012345L); query = new BasicDBObject("OldDate", date.toDate()); System.out.println("Date: " + date + " upd: " + query + " => " + date.getYear()); dbvitam.daips.collection.update(id, query); final DBCursor cursor = dbvitam.daips.collection.find(id); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); maip.load(dbvitam);//from ww w. j ava 2 s . c om System.out.println(maip); } cursor.close(); System.out.println("===="); date = date.plusYears(10); id.append("OldDate", new BasicDBObject("$lt", date.toDate())); System.out.println("Date: " + date + " find: " + id + " => " + date.getYear()); final DBCursor cursor2 = dbvitam.daips.collection.find(id); while (cursor2.hasNext()) { final DAip maip = (DAip) cursor2.next(); Date madate = maip.getDate("OldDate"); System.out.println("Madate: " + madate); System.out.println("Madate: " + madate.getTime()); System.out.println("Madate: " + new DateTime(madate)); maip.load(dbvitam); System.out.println(maip); } cursor2.close(); } else { final DBCursor cursor = dbvitam.find(dbvitam.daips, query, ID_NBCHILD); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); maip.load(dbvitam); System.out.println(maip); } cursor.close(); } }
From source file:fr.gouv.vitam.mdbes.PAip.java
License:Open Source License
@Override protected boolean updated(final MongoDbAccess dbvitam) { final PAip vt = (PAip) dbvitam.paips.collection.findOne(getId()); BasicDBObject update = null; if (vt != null) { final List<DBObject> list = new ArrayList<>(); BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.DAip2PAip, false); if (upd != null) { list.add(upd);//w w w . j a v a2 s . com } upd = dbvitam.updateLink(this, vt, VitamLinks.PAip2Dua, true); if (upd != null) { list.add(upd); } if (!list.isEmpty()) { try { update = new BasicDBObject(); if (!list.isEmpty()) { upd = new BasicDBObject(); for (final DBObject dbObject : list) { upd.putAll(dbObject); } update = update.append("$addToSet", upd); } dbvitam.paips.collection.update(new BasicDBObject(ID, this.get(ID)), update); } catch (final MongoException e) { LOGGER.error("Exception for " + update, e); throw e; } list.clear(); } return true; } else { dbvitam.updateLinks(this, null, VitamLinks.DAip2PAip, false); } return false; }
From source file:fr.gouv.vitam.mdbes.ParserIngest.java
License:Open Source License
/** * * @param typeField/*from w ww . j a v a 2 s . c om*/ * @param rank * @param lstart * @param cpt * @return the equivalent BSon object for the current Field * @throws InvalidExecOperationException */ private BasicDBObject getDbObject(final TypeField typeField, final long rank, final long lstart, final AtomicLong cpt) throws InvalidExecOperationException { final BasicDBObject subobj = new BasicDBObject(); String val = null; switch (typeField.type) { case constant: setValue(subobj, typeField, typeField.prefix); break; case constantArray: subobj.put(typeField.name, typeField.listeValeurs); break; case random: switch (typeField.ftype) { case date: final long curdate = System.currentTimeMillis(); final Date date = new Date(curdate - rnd.nextInt()); final DateTime dateTime = new DateTime(date); if (typeField.saveName != null) { context.savedNames.put(typeField.saveName, dateTime.toString()); } subobj.put(typeField.name, date); break; case nombre: final Long lnval = rnd.nextLong(); if (typeField.saveName != null) { context.savedNames.put(typeField.saveName, lnval.toString()); } subobj.put(typeField.name, lnval); break; case nombrevirgule: final Double dnval = rnd.nextDouble(); if (typeField.saveName != null) { context.savedNames.put(typeField.saveName, dnval.toString()); } subobj.put(typeField.name, dnval); break; case chaine: default: val = randomString(32); val = getValue(typeField, val); subobj.put(typeField.name, val); break; } break; case save: val = getValue(typeField, ""); setValue(subobj, typeField, val); break; case liste: final int rlist = rnd.nextInt(typeField.listeValeurs.length); val = typeField.listeValeurs[rlist]; val = getValue(typeField, val); setValue(subobj, typeField, val); break; case listeorder: long i = rank - lstart; if (i >= typeField.listeValeurs.length) { i = typeField.listeValeurs.length - 1; } val = typeField.listeValeurs[(int) i]; val = getValue(typeField, val); setValue(subobj, typeField, val); break; case serie: AtomicLong newcpt = cpt; long j = newcpt.get(); if (typeField.idcpt != null) { newcpt = context.cpts.get(typeField.idcpt); // System.out.println("CPT replaced by: "+typeField.idcpt); if (newcpt == null) { newcpt = cpt; LOGGER.error("wrong cpt name: " + typeField.idcpt); } else { j = newcpt.getAndIncrement(); // System.out.println("increment: "+j+" for "+typeField.name); } } if (typeField.modulo > 0) { j = j % typeField.modulo; } val = (typeField.prefix != null ? typeField.prefix : "") + j; val = getValue(typeField, val); setValue(subobj, typeField, val); break; case subfield: final BasicDBObject subobjs = new BasicDBObject(); for (final TypeField field : typeField.subfields) { final BasicDBObject obj = getDbObject(field, rank, lstart, cpt); if (obj != null) { subobjs.putAll((BSONObject) obj); } else { return null; } } subobj.put(typeField.name, subobjs); break; case interval: final int newval = rnd.nextInt(typeField.low, typeField.high + 1); val = getValue(typeField, "" + newval); setValue(subobj, typeField, val); break; case select: final BasicDBObject request = new BasicDBObject(); for (final TypeField field : typeField.subfields) { final String name = field.name; final String arg = getValue(field, ""); request.append(name, arg); } if (simulate) { LOGGER.error("NotAsking: " + request); return null; } final DAip maip = (DAip) MongoDbAccess.VitamCollections.Cdaip.getCollection().findOne(request, new BasicDBObject(typeField.name, 1)); if (maip != null) { // System.out.println("Select: "+typeField.name+":"+ maip.get(typeField.name)); val = getValue(typeField, (String) maip.get(typeField.name)); setValue(subobj, typeField, val); } else { // LOGGER.error("NotFound: "+request); return null; } break; default: throw new InvalidExecOperationException("Incorrect type: " + typeField.type); } return subobj; }
From source file:fr.gouv.vitam.mdbes.ResultMongodb.java
License:Open Source License
@SuppressWarnings("unchecked") protected boolean updated(final MongoDbAccess dbvitam) { if (getId() == null) { return false; }/* w w w. j a v a2 s . c o m*/ final ResultMongodb vt = (ResultMongodb) dbvitam.requests.collection.findOne(getId()); if (vt != null) { final List<DBObject> list = new ArrayList<DBObject>(); final Object obj = vt.obj.get(CURRENTDAIP); final Set<String> vtset = new HashSet<String>(); if (obj instanceof BasicDBList) { for (Object string : (BasicDBList) obj) { vtset.add((String) string); } } else { vtset.addAll((Set<String>) obj); } if (!vtset.isEmpty()) { final Set<String> newset = new HashSet<String>(currentDaip); newset.removeAll(vtset); if (!newset.isEmpty()) { list.add(new BasicDBObject(CURRENTDAIP, new BasicDBObject("$each", newset))); } } if (!list.isEmpty()) { final BasicDBObject updset = new BasicDBObject(); for (final DBObject dbObject : list) { updset.putAll(dbObject); } final BasicDBObject upd = new BasicDBObject(); upd.append(MINLEVEL, minLevel); upd.append(MAXLEVEL, maxLevel); upd.append(NBSUBNODES, nbSubNodes); upd.append(TTL, ttl); final BasicDBObject update = new BasicDBObject("$addToSet", updset).append("$set", upd); dbvitam.requests.collection.update(new BasicDBObject(ID, this.obj.get(ID)), update); } if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("UPDATE: " + this); } } else if (obj.containsField(ID)) { // not in DB but got already an ID => Save it if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("SAVE: " + this); } this.forceSave(dbvitam.requests); return true; } return false; }
From source file:fr.gouv.vitam.mdbes.ResultMongodbBak.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww .j a v a2 s .co m*/ protected boolean updated(final MongoDbAccess dbvitam) { final ResultMongodbBak vt = (ResultMongodbBak) dbvitam.requests.collection.findOne(getId()); if (vt != null) { final List<DBObject> list = new ArrayList<DBObject>(); final Object obj = vt.get(CURRENTDAIP); final Set<String> vtset = new HashSet<String>(); if (obj instanceof BasicDBList) { for (Object string : (BasicDBList) obj) { vtset.add((String) string); } } else { vtset.addAll((Set<String>) obj); } if (!vtset.isEmpty()) { final Set<String> newset = new HashSet<String>(currentDaip); newset.removeAll(vtset); if (!newset.isEmpty()) { list.add(new BasicDBObject(CURRENTDAIP, new BasicDBObject("$each", newset))); } } if (!list.isEmpty()) { final BasicDBObject updset = new BasicDBObject(); for (final DBObject dbObject : list) { updset.putAll(dbObject); } final BasicDBObject upd = new BasicDBObject(); upd.append(MINLEVEL, minLevel); upd.append(MAXLEVEL, maxLevel); upd.append(NBSUBNODES, nbSubNodes); upd.append(TTL, ttl); final BasicDBObject update = new BasicDBObject("$addToSet", updset).append("$set", upd); dbvitam.requests.collection.update(new BasicDBObject(ID, this.get(ID)), update); } if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("UPDATE: " + this); } } else if (containsField(ID)) { // not in DB but got already an ID => Save it if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("SAVE: " + this); } this.forceSave(dbvitam.requests); return true; } return false; }
From source file:framework.mod.user.client.model.classes.Client.java
public BasicDBObject Client_to_DB() { BasicDBObject dbObjectClient = new BasicDBObject(); dbObjectClient.append("age", this.getAge()); dbObjectClient.append("avataring", this.getAvataring()); dbObjectClient.append("birth_date", this.getBorn_date().toString()); dbObjectClient.append("dni", this.getDni()); dbObjectClient.append("email", this.getEmail()); dbObjectClient.append("movile", this.getMovile()); dbObjectClient.append("name", this.getName()); dbObjectClient.append("lastname", this.getLastname()); dbObjectClient.append("password", this.getPassword()); dbObjectClient.append("state", this.getState()); dbObjectClient.append("user", this.getUser()); dbObjectClient.append("antiqueness", this.getAntiqueness()); dbObjectClient.append("amount", Double.parseDouble(Float.toString(this.getShop_acount()))); dbObjectClient.append("type", this.getClient_type()); dbObjectClient.append("premium", this.isPremium()); dbObjectClient.append("register_date", this.getRegister_date().toString()); return dbObjectClient; }
From source file:framework.mod.user.client.model.DAO.DAO_DB_Client.java
public static void update_Client() { //Prepara para insertar un nuevo campo BasicDBObject updateAtribute = new BasicDBObject(); updateAtribute.append("$set", singletonClient.ephemeralClient.Client_to_DB()); //look for register with primariKey BasicDBObject searchById = new BasicDBObject(); searchById.append("dni", singletonClient.dniClt); //update/*from ww w.ja v a2s .c om*/ singletonGen.collection.updateMulti(searchById, updateAtribute); }
From source file:framework.module.users.client.model.DAO.DAO_BD_client.java
/** * UPDATE USER/*www .jav a2s.c om*/ * @param c1 */ public static void update_BD(Client c1) { //Prepara para insertar un nuevo campo BasicDBObject update = new BasicDBObject(); update.append("$set", c1.Client_to_BD()); //Busca el/los registro/s con el nombre indicado BasicDBObject searchById = new BasicDBObject(); searchById.append("DNI", c1.getDNI()); //Realiza la actualizacin collection.updateMulti(searchById, update); }