Java Code Examples for org.bson.BsonArray#add()
The following examples show how to use
org.bson.BsonArray#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateDescription.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
/** * Converts this update description to its document representation as it would appear in a * MongoDB Change Event. * * @return the update description document as it would appear in a change event */ public BsonDocument toBsonDocument() { final BsonDocument updateDescDoc = new BsonDocument(); updateDescDoc.put( Fields.UPDATED_FIELDS_FIELD, this.getUpdatedFields()); final BsonArray removedFields = new BsonArray(); for (final String field : this.getRemovedFields()) { removedFields.add(new BsonString(field)); } updateDescDoc.put( Fields.REMOVED_FIELDS_FIELD, removedFields); return updateDescDoc; }
Example 2
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getExistsQueryObject(String[] fieldArr, String str, BsonBoolean isExist) { BsonArray conjQueries = new BsonArray(); for (String field : fieldArr) { BsonDocument query = new BsonDocument(); if (str != null) { str = encodeMongoObjectKey(str); query.put(field + "." + str, new BsonDocument("$exists", isExist)); } else { query.put(field, new BsonDocument("$exists", isExist)); } conjQueries.add(query); } if (conjQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); if (isExist.equals(BsonBoolean.TRUE)) queryObject.put("$or", conjQueries); else { queryObject.put("$and", conjQueries); } return queryObject; } else { return null; } }
Example 3
Source File: MongoWriterUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonArray getQuantityObjectList(List<QuantityElementType> qetList, Integer gcpLength) { BsonArray quantityList = new BsonArray(); for (int i = 0; i < qetList.size(); i++) { BsonDocument quantity = new BsonDocument(); QuantityElementType qet = qetList.get(i); if (qet.getEpcClass() != null) quantity.put("epcClass", new BsonString(getClassEPC(qet.getEpcClass().toString(), gcpLength))); if (qet.getQuantity().doubleValue() != 0) { quantity.put("quantity", new BsonDouble(qet.getQuantity().doubleValue())); } if (qet.getUom() != null) quantity.put("uom", new BsonString(qet.getUom().toString())); quantityList.add(quantity); } return quantityList; }
Example 4
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 6 votes |
public BsonDocument putQuantityList(BsonDocument base, List<QuantityElement> quantityList) { BsonArray quantityArray = new BsonArray(); for (QuantityElement quantityElement : quantityList) { BsonDocument bsonQuantityElement = new BsonDocument("epcClass", new BsonString(quantityElement.getEpcClass())); if (quantityElement.getQuantity() != null) { bsonQuantityElement.put("quantity", new BsonDouble(quantityElement.getQuantity())); } if (quantityElement.getUom() != null) { bsonQuantityElement.put("uom", new BsonString(quantityElement.getUom())); } quantityArray.add(bsonQuantityElement); } base.put("quantityList", quantityArray); return base; }
Example 5
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putInputEPCList(BsonDocument base, List<String> inputEPCList) { BsonArray bsonEPCList = new BsonArray(); for (String epc : inputEPCList) { bsonEPCList.add(new BsonDocument("epc", new BsonString(epc))); } base.put("inputEPCList", bsonEPCList); return base; }
Example 6
Source File: TransformationAAExisting.java From epcis with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private JSONArray getTransformationTreeEmulation(String epc, String startTime) { // 여기에 에뮬레이션을 함 // Time processing long startTimeMil = 0; startTimeMil = TimeUtil.getTimeMil(startTime); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); BsonArray transforms = new BsonArray(); transforms.add(new BsonString("transformsTo")); PersistentBreadthFirstSearchExternal tBFS = new PersistentBreadthFirstSearchExternal(); Map pathMap = new HashMap(); pathMap = tBFS.compute(epc, startTimeMil, AC.$gte); // JSONarray contains each path // contains time - vertex mapping JSONArray pathArray = new JSONArray(); Iterator<Set> pathSetIter = pathMap.values().iterator(); while (pathSetIter.hasNext()) { Set pathSet = pathSetIter.next(); Iterator<List> pathIter = pathSet.iterator(); while (pathIter.hasNext()) { List path = pathIter.next(); Iterator<EPCTime> vi = path.iterator(); JSONArray p = new JSONArray(); while (vi.hasNext()) { EPCTime ve = vi.next(); p.put(ve.epc + "-" + ve.time); } pathArray.put(p); } } return pathArray; }
Example 7
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putBizTransactionList(BsonDocument base, Map<String, List<String>> bizTransactionList) { BsonArray bsonBizTransactionList = new BsonArray(); for (String key : bizTransactionList.keySet()) { List<String> list = bizTransactionList.get(key); for (String element : list) { bsonBizTransactionList.add(new BsonDocument(key, new BsonString(element))); } } base.put("bizTransactionList", bsonBizTransactionList); return base; }
Example 8
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonDocument getNearQueryObject(String key, String paramValues) { try { // Prepare Query Values String[] paramValueArr = paramValues.split(","); if (paramValueArr.length < 2) return null; Double lon = Double.parseDouble(paramValueArr[0]); Double lat = Double.parseDouble(paramValueArr[1]); Integer min = null; if (paramValueArr.length > 2) min = Integer.parseInt(paramValueArr[2]); Integer max = null; if (paramValueArr.length > 3) max = Integer.parseInt(paramValueArr[3]); BsonDocument near = new BsonDocument(); BsonDocument geometry = new BsonDocument("type", new BsonString("Point")); BsonArray coordinates = new BsonArray(); coordinates.add(new BsonDouble(lon)); coordinates.add(new BsonDouble(lat)); geometry.put("coordinates", coordinates); near.put("$geometry", geometry); if (min != null) near.put("$minDistance", new BsonInt32(min)); if (max != null) near.put("$maxDistance", new BsonInt32(max)); return new BsonDocument("any." + key, new BsonDocument("$near", near)); } catch (NumberFormatException e) { e.printStackTrace(); return null; } }
Example 9
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putChildren(BsonDocument base, List<String> children) { BsonArray bsonChildren = new BsonArray(); for (String child : children) { bsonChildren.add(new BsonString(child)); } base.put("children", bsonChildren); return base; }
Example 10
Source File: Converter.java From epcis with Apache License 2.0 | 5 votes |
public static BsonArray stringArrayToBsonArray(String[] stringArray) { BsonArray bson = new BsonArray(); for (String string : stringArray) { bson.add(new BsonString(string)); } return bson; }
Example 11
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonDocument getQueryObject(String[] fieldArr, BsonArray paramArray) { BsonArray orQueries = new BsonArray(); for (String field : fieldArr) { Iterator<BsonValue> paramIterator = paramArray.iterator(); BsonArray pureStringParamArray = new BsonArray(); while (paramIterator.hasNext()) { BsonValue param = paramIterator.next(); if (param instanceof BsonRegularExpression) { BsonDocument regexQuery = new BsonDocument(field, new BsonDocument("$regex", param)); orQueries.add(regexQuery); } else { pureStringParamArray.add(param); } } if (pureStringParamArray.size() != 0) { BsonDocument stringInQueries = new BsonDocument(field, new BsonDocument("$in", pureStringParamArray)); orQueries.add(stringInQueries); } } if (orQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); queryObject.put("$or", orQueries); return queryObject; } else { return null; } }
Example 12
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putInputEPCList(BsonDocument base, List<String> inputEPCList) { BsonArray bsonEPCList = new BsonArray(); for (String epc : inputEPCList) { bsonEPCList.add(new BsonDocument("epc", new BsonString(epc))); } base.put("inputEPCList", bsonEPCList); return base; }
Example 13
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putBizTransactionList(BsonDocument base, Map<String, List<String>> bizTransactionList) { BsonArray bsonBizTransactionList = new BsonArray(); for (String key : bizTransactionList.keySet()) { List<String> list = bizTransactionList.get(key); for (String element : list) { bsonBizTransactionList.add(new BsonDocument(key, new BsonString(element))); } } base.put("bizTransactionList", bsonBizTransactionList); return base; }
Example 14
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putOutputEPCList(BsonDocument base, List<String> outputEPCList) { BsonArray bsonEPCList = new BsonArray(); for (String epc : outputEPCList) { bsonEPCList.add(new BsonDocument("epc", new BsonString(epc))); } base.put("outputEPCList", bsonEPCList); return base; }
Example 15
Source File: Converter.java From epcis with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes" }) public static BsonDocument getTraversalDocument(Collection collection, Class elementClass) { BsonArray idArr = new BsonArray(); BsonArray outVArr = new BsonArray(); BsonArray inVArr = new BsonArray(); BsonArray labelArr = new BsonArray(); BsonArray edgeArr = new BsonArray(); Iterator iterator = collection.iterator(); while (iterator.hasNext()) { if (elementClass == ChronoVertex.class) { ChronoVertex cv = (ChronoVertex) iterator.next(); idArr.add(new BsonString(cv.toString())); } else if (elementClass == ChronoEdge.class) { ChronoEdge ce = (ChronoEdge) iterator.next(); idArr.add(new BsonString(ce.toString())); outVArr.add(new BsonString(ce.getOutVertex().toString())); inVArr.add(new BsonString(ce.getInVertex().toString())); labelArr.add(new BsonString(ce.getLabel().toString())); } else if (elementClass == VertexEvent.class) { VertexEvent cve = (VertexEvent) iterator.next(); idArr.add(new BsonString(cve.toString())); } else if (elementClass == EdgeEvent.class) { EdgeEvent cee = (EdgeEvent) iterator.next(); idArr.add(new BsonString(cee.toString())); edgeArr.add(new BsonString(cee.getEdge().toString())); } } if (elementClass == ChronoVertex.class) { return new BsonDocument(Tokens.ID, idArr); } else if (elementClass == ChronoEdge.class) { return new BsonDocument(Tokens.ID, idArr).append(Tokens.OUT_VERTEX, outVArr) .append(Tokens.IN_VERTEX, inVArr).append(Tokens.LABEL, labelArr); } return null; }
Example 16
Source File: Converter.java From epcis with Apache License 2.0 | 5 votes |
public static BsonArray getBsonArrayOfBsonString(String... strings) { BsonArray ret = new BsonArray(); for (String string : strings) { ret.add(new BsonString(string)); } return ret; }
Example 17
Source File: CaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
public BsonDocument putEPCList(BsonDocument base, List<String> epcList) { BsonArray bsonEPCList = new BsonArray(); for (String epc : epcList) { bsonEPCList.add(new BsonDocument("epc", new BsonString(epc))); } base.put("epcList", bsonEPCList); return base; }
Example 18
Source File: AggregationTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() { ChronoGraph g = new ChronoGraph("epcis"); // g.getChronoVertexSet().parallelStream().forEach(v -> System.out.println(v)); BsonArray contains = new BsonArray(); contains.add(new BsonString("contains")); // 각 중요시간 마다 트럭 안에 있는 물건들의 리스트와 무게를 가져옴 Iterator<Long> timeSet = g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001") .getTimestamps(Direction.OUT, contains, 0l, AC.$gt).iterator(); while (timeSet.hasNext()) { Long t = timeSet.next(); System.out.println("at " + new Date(t)); AtomicDouble totalK = new AtomicDouble(); ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); PipeFunction<EdgeEvent, Boolean> retainIfAdd = new PipeFunction<EdgeEvent, Boolean>() { @Override public Boolean compute(EdgeEvent ee) { if (ee.getProperty("action").equals(new BsonString("ADD"))) { return true; } return false; } }; PipeFunction<VertexEvent, Object> listUpFreight = new PipeFunction<VertexEvent, Object>() { @Override public Object compute(VertexEvent ve) { BsonDouble kg = (BsonDouble) ve.getVertex().getProperty("urn:epc:cbv:mda:netWeight"); totalK.addAndGet(kg.doubleValue()); map.put(ve.getVertex().toString(), "1"); return ve; } }; TraversalEngine engine = new TraversalEngine(g, g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001").setTimestamp(t), false, false, VertexEvent.class); engine.outEe(contains, TemporalType.TIMESTAMP, AC.$lte, null, null, null, null, null, null) .filter(retainIfAdd).inVe().sideEffect(listUpFreight).toList(); // g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001").getChronoEdgeSet(Direction.OUT, // contains) // .parallelStream().forEach(e -> { // // System.out.println(e); // // EdgeEvent ee = e.pickFloorTimestamp(t); // if (ee != null && ee.getProperty("action").equals(new BsonString("ADD"))) { // BsonDouble kg = (BsonDouble) // e.getInVertex().getProperty("urn:epc:cbv:mda:netWeight"); // totalK.addAndGet(kg.doubleValue()); // map.put(e.getInVertex().toString(), "1"); // } // }); System.out.println(map.keySet()); System.out.println(totalK); } g.shutdown(); }
Example 19
Source File: TraceabilityQueryService.java From epcis with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public String getTransformation(String traceEPC, String traceTarget, String startTime, String endTime, Long fromTimeMil, Long toTimeMil, String orderDirection) { BsonArray transforms = new BsonArray(); transforms.add(new BsonString("transformsTo")); ChronoGraph g = Configuration.persistentGraph; PersistentBreadthFirstSearch tBFS = new PersistentBreadthFirstSearch(); Map pathMap = new HashMap(); VertexEvent source; if (orderDirection.equals("ASC")) source = g.getChronoVertex(traceEPC).setTimestamp(fromTimeMil); else source = g.getChronoVertex(traceEPC).setTimestamp(toTimeMil); pathMap = tBFS.compute(g, source, "transformsTo", orderDirection); Document doc = createBaseQueryResults(traceEPC, traceTarget, startTime, endTime, orderDirection); Element transformationTrace = doc.createElement("transformationTrace"); Iterator<Set> pathSetIter = pathMap.values().iterator(); while (pathSetIter.hasNext()) { Set pathSet = pathSetIter.next(); Iterator<List> pathIter = pathSet.iterator(); while (pathIter.hasNext()) { List path = pathIter.next(); Iterator<VertexEvent> vi = path.iterator(); Element transformationPath = doc.createElement("transformationPath"); while (vi.hasNext()) { Object ve = vi.next(); if (ve != null) { Element pathElement = doc.createElement("pathElement"); VertexEvent veObj = (VertexEvent) ve; Element eventTime = doc.createElement("eventTime"); Date date = new Date(veObj.getTimestamp()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String dateString = sdf.format(date); eventTime.setTextContent(dateString); Element epc = doc.createElement("epc"); epc.setTextContent(veObj.getVertexID()); pathElement.appendChild(epc); pathElement.appendChild(eventTime); transformationPath.appendChild(pathElement); } } transformationTrace.appendChild(transformationPath); } } Element resultsBody = doc.createElement("resultsBody"); resultsBody.appendChild(transformationTrace); doc.getFirstChild().appendChild(resultsBody); return toString(doc); }
Example 20
Source File: TransformationQueryEmulationTest.java From epcis with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private JSONArray getTransformationTreeEmulation(String epc, String startTime) { // 여기에 에뮬레이션을 함 // Time processing long startTimeMil = 0; startTimeMil = TimeUtil.getTimeMil(startTime); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); BsonArray transforms = new BsonArray(); transforms.add(new BsonString("transformsTo")); PersistentBreadthFirstSearchExternal tBFS = new PersistentBreadthFirstSearchExternal(); Map pathMap = new HashMap(); PersistentBreadthFirstSearchExternal.length = new AtomicInteger(0); pathMap = tBFS.compute(epc, startTimeMil, AC.$gte); // JSONarray contains each path // contains time - vertex mapping JSONArray pathArray = new JSONArray(); Iterator<Set> pathSetIter = pathMap.values().iterator(); while (pathSetIter.hasNext()) { Set pathSet = pathSetIter.next(); Iterator<List> pathIter = pathSet.iterator(); while (pathIter.hasNext()) { List path = pathIter.next(); Iterator<EPCTime> vi = path.iterator(); JSONArray p = new JSONArray(); while (vi.hasNext()) { Object ve = vi.next(); if (ve != null) p.put(ve.toString()); } pathArray.put(p); } } return pathArray; }