List of usage examples for com.mongodb BasicDBObject putAll
@SuppressWarnings("unchecked") @Override public void putAll(final Map m)
From source file:fr.gouv.vitam.cases.ElasticSearchAccess.java
License:Open Source License
private static final BasicDBObject getFiltered(final BSONObject bson) { BasicDBObject maip = new BasicDBObject(); maip.putAll(bson); maip.removeField(VitamLinks.DAip2DAip.field1to2); // Keep it maip.removeField(VitamLinks.DAip2DAip.field2to1); //maip.removeField(VitamLinks.Domain2DAip.field2to1); //maip.removeField(VitamLinks.DAip2Dua.field1to2); //maip.removeField(VitamLinks.DAip2PAip.field1to2); // maip.removeField(ParserIngest.REFID); // DOMDEPTH already ok but duplicate it @SuppressWarnings("unchecked") final HashMap<String, Integer> map = (HashMap<String, Integer>) maip.get(DAip.DAIPDEPTHS); //final List<String> list = new ArrayList<>(map.keySet()); maip.append(DAip.DAIPPARENTS, map.keySet());// was list); return maip;// ww w . j a va 2 s . c o m }
From source file:fr.gouv.vitam.cases.PAip.java
License:Open Source License
@Override protected boolean updated(final CassandraAccess dbvitam) { final PAip vt = (PAip) dbvitam.paips.collection.findOne(getId()); BasicDBObject update = null;/*from w ww. ja va 2s . c om*/ if (vt != null) { final List<DBObject> list = new ArrayList<>(); BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.DAip2PAip, false); if (upd != null) { list.add(upd); } 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.cbes.ResultCached.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w .ja v a 2s . c o m protected boolean updated(final CouchbaseAccess dbvitam) { final ResultCached vt = (ResultCached) dbvitam.findOne(VitamCollections.Crequests, getId()); if (vt != null) { final List<DBObject> list = new ArrayList<DBObject>(); final List<String> slist = (List<String>) vt.get(CURRENTDAIP); if (slist != null) { final Set<String> newset = new HashSet<String>(currentDaip); newset.removeAll(currentDaip); if (!newset.isEmpty()) { list.add(new BasicDBObject(CURRENTDAIP, new BasicDBObject("$each", newset))); } } if (!list.isEmpty()) { final BasicDBObject upd = new BasicDBObject(); for (final DBObject dbObject : list) { upd.putAll(dbObject); } upd.append(MINLEVEL, minLevel); upd.append(MAXLEVEL, maxLevel); upd.append(NBSUBNODES, nbSubNodes); final BasicDBObject update = new BasicDBObject("$addToSet", upd); // XXX FIXME cannot make an update //dbvitam.requests.collection.update(new BasicDBObject(ID, this.get(ID)), update); } } return false; }
From source file:fr.gouv.vitam.mdbes.CopyOfResultMongodb.java
License:Open Source License
@SuppressWarnings("unchecked") protected boolean updated(final MongoDbAccess dbvitam) { if (getId() == null) { return false; }/*from w ww. j a v a2 s .c o m*/ final CopyOfResultMongodb vt = (CopyOfResultMongodb) 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.DAip.java
License:Open Source License
@Override protected boolean updated(final MongoDbAccess dbvitam) { final DAip vt = (DAip) dbvitam.daips.collection.findOne(getString(ID)); BasicDBObject update = null;// w ww .ja v a 2s . co m if (vt != null) { LOGGER.debug("UpdateLinks: {}\n\t{}", this, vt); final List<DBObject> list = new ArrayList<>(); final List<DBObject> listset = new ArrayList<>(); /* * Only parent link, not child link * BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.DAip2DAip, true); * if (upd != null) { * list.add(upd); * } */ BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.DAip2DAip, false); if (upd != null) { list.add(upd); } upd = dbvitam.updateLinks(this, vt, VitamLinks.Domain2DAip, false); if (upd != null) { list.add(upd); } upd = dbvitam.updateLink(this, vt, VitamLinks.DAip2PAip, true); if (upd != null) { listset.add(upd); } upd = dbvitam.updateLink(this, vt, VitamLinks.DAip2Dua, true); if (upd != null) { listset.add(upd); } // DAIPDEPTHS @SuppressWarnings("unchecked") final HashMap<String, Integer> vtDom = (HashMap<String, Integer>) vt.removeField(DAIPDEPTHS); @SuppressWarnings("unchecked") HashMap<String, Integer> domainelevels = (HashMap<String, Integer>) get(DAIPDEPTHS); if (domainelevels == null) { domainelevels = new HashMap<String, Integer>(); } final BasicDBObject vtDomaineLevels = new BasicDBObject(); if (vtDom != null) { // remove all not in current but in vt as already updated, for the others compare vt with current for (final String dom : vtDom.keySet()) { final Integer pastval = vtDom.get(dom); final Integer newval = domainelevels.get(dom); if (newval != null) { if (pastval > newval) { vtDomaineLevels.append(dom, newval); // to be remotely updated } else { vtDomaineLevels.append(dom, pastval); // to be remotely updated domainelevels.put(dom, pastval); // update only locally } } else { vtDomaineLevels.append(dom, pastval); // to be remotely updated domainelevels.put(dom, pastval); // update only locally } } // now add into remote update from current, but only non existing in vt (already done) for (final String dom : domainelevels.keySet()) { // remove by default final Integer srcobj = vtDom.get(dom); final Integer obj = domainelevels.get(dom); if (srcobj == null) { vtDomaineLevels.append(dom, obj); // will be updated remotely } } // Update locally append(DAIPDEPTHS, domainelevels); } if (!vtDomaineLevels.isEmpty()) { upd = new BasicDBObject(DAIPDEPTHS, vtDomaineLevels); listset.add(upd); } try { update = new BasicDBObject(); if (!list.isEmpty()) { upd = new BasicDBObject(); for (final DBObject dbObject : list) { upd.putAll(dbObject); } update = update.append("$addToSet", upd); } if (!listset.isEmpty()) { upd = new BasicDBObject(); for (final DBObject dbObject : listset) { upd.putAll(dbObject); } update = update.append("$set", upd); } update = update.append("$inc", new BasicDBObject(NBCHILD, nb)); nb = 0; dbvitam.daips.collection.update(new BasicDBObject(ID, this.get(ID)), update); } catch (final MongoException e) { LOGGER.error("Exception for " + update, e); throw e; } list.clear(); listset.clear(); return true; } else { // dbvitam.updateLinks(this, null, VitamLinks.DAip2DAip, true); dbvitam.updateLinks(this, null, VitamLinks.DAip2DAip, false); dbvitam.updateLinks(this, null, VitamLinks.Domain2DAip, false); append(NBCHILD, nb); nb = 0; } return false; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
private final ResultInterface getRequest1LevelMaipFromMD(final TypeRequest request, final ResultInterface previous, final boolean useStart) throws InvalidExecOperationException, InstantiationException, IllegalAccessException { BasicDBObject query = null; if (request.requestModel == null) { throw new InvalidExecOperationException( "Expression is not valid for Daip Level 1 with MD only since no MD request is available"); }/* ww w . j ava2 s . c o m*/ if (useStart) { query = getInClauseForField(DAip.ID, previous.getCurrentDaip()); } else { if (previous.getMinLevel() == 1) { query = getInClauseForField(MongoDbAccess.VitamLinks.Domain2DAip.field2to1, previous.getCurrentDaip()); } else { query = getInClauseForField(MongoDbAccess.VitamLinks.DAip2DAip.field2to1, previous.getCurrentDaip()); } } final String srequest = request.requestModel.toString(); final BasicDBObject condition = (BasicDBObject) JSON.parse(srequest); query.putAll((BSONObject) condition); final ResultInterface subresult = MongoDbAccess.createOneResult(); if (simulate) { LOGGER.info("Req1LevelMD: {}", query); return createFalseResult(previous, 1); } LOGGER.debug("Req1LevelMD: {}", query); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req1LevelMD: {}", query); } final DBCursor cursor = mdAccess.find(mdAccess.daips, query, ID_NBCHILD); long tempCount = 0; while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); if (useStart) { if (previous.getCurrentDaip().contains(mid)) { subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(Domain.NBCHILD); } } else { subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(Domain.NBCHILD); } } cursor.close(); subresult.setNbSubNodes(tempCount); // filter on Ancestor if (!useStart && !previous.checkAncestor(mdAccess, subresult)) { LOGGER.error("No ancestor for " + query + "\n" + previous.getCurrentDaip() + " not in " + subresult.getCurrentDaip()); return null; } // Not updateMinMax since result is not "valid" path but node UUID and not needed subresult.setMinLevel(previous.getMinLevel() + 1); subresult.setMaxLevel(previous.getMaxLevel() + 1); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("MetaAip2: {}", subresult); } return subresult; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
private final ResultInterface getRequestNegativeRelativeDepthFromMD(final TypeRequest request, final ResultInterface previous, final boolean useStart) throws InvalidExecOperationException, InstantiationException, IllegalAccessException { BasicDBObject query = null; if (request.requestModel == null) { throw new InvalidExecOperationException("Expression is not valid for Daip Level " + request.relativedepth + " with MD only since no MD request is available"); }/* ww w . j a va2 s .c o m*/ if (useStart) { throw new InvalidExecOperationException("Cannot make a negative path when starting up"); } if (simulate) { LOGGER.info("Req-xLevelMD"); return createFalseResult(previous, 1); } int distance = -request.relativedepth; Set<String> subset = new HashSet<String>(); for (String prev : previous.getCurrentDaip()) { DAip dprev = DAip.findOne(mdAccess, prev); Map<String, Integer> parents = dprev.getDomDepth(); for (Entry<String, Integer> elt : parents.entrySet()) { if (elt.getValue() == distance) { subset.add(elt.getKey()); } } } // Use ID and not graph dependencies query = getInClauseForField(DAip.ID, subset); final String srequest = request.requestModel.toString(); final BasicDBObject condition = (BasicDBObject) JSON.parse(srequest); query.putAll((BSONObject) condition); final ResultInterface subresult = MongoDbAccess.createOneResult(); LOGGER.debug("Req-xLevelMD: {}", query); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req-xLevelMD: {}", query); } final DBCursor cursor = mdAccess.find(mdAccess.daips, query, ID_NBCHILD); long tempCount = 0; subresult.setMinLevel(previous.getMaxLevel()); subresult.setMaxLevel(0); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); subresult.getCurrentDaip().add(mid); maip.load(mdAccess); tempCount += maip.getLong(DAip.NBCHILD); // Not updateMinMax since result is not "valid" path but node UUID and not needed int max = maip.getMaxDepth(); if (subresult.getMaxLevel() < max) { subresult.setMaxLevel(max); } if (subresult.getMinLevel() > max) { subresult.setMinLevel(max); } } cursor.close(); subresult.setNbSubNodes(tempCount); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("MetaAip2: {}", subresult); } return subresult; }
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;//from w w w .ja va2s. co m 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); } 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.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;/* w ww . j av a 2s .com*/ if (vt != null) { final List<DBObject> list = new ArrayList<>(); BasicDBObject upd = dbvitam.updateLinks(this, vt, VitamLinks.DAip2PAip, false); if (upd != null) { list.add(upd); } 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 av a 2s . c o m * @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; }