org.bson.BsonArray Java Examples

The following examples show how to use org.bson.BsonArray. 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: ChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
private Set<ChronoEdge> getInChronoEdgeSet(final BsonArray labels, final int branchFactor) {
	HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>();
	BsonDocument filter = new BsonDocument();
	BsonDocument inner = new BsonDocument();
	filter.put(Tokens.IN_VERTEX, new BsonString(this.toString()));
	if (labels != null && labels.size() != 0) {
		inner.put(Tokens.FC.$in.toString(), labels);
		filter.put(Tokens.LABEL, inner);
	}

	Iterator<BsonDocument> it = null;
	if (branchFactor == Integer.MAX_VALUE)
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator();
	else
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator();

	while (it.hasNext()) {
		BsonDocument d = it.next();
		edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph));
	}
	return edgeSet;
}
 
Example #2
Source File: CaptureUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
public BsonDocument putChildQuantityList(BsonDocument base, List<QuantityElement> childQuantityList) {
	BsonArray quantityArray = new BsonArray();
	for (QuantityElement quantityElement : childQuantityList) {
		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("childQuantityList", quantityArray);
	return base;
}
 
Example #3
Source File: AvroJsonSchemafulRecordConverter.java    From kafka-connect-mongodb with Apache License 2.0 6 votes vote down vote up
private BsonValue handleArrayField(List list, Field field) {
    logger.trace("handling complex type 'array' of types '{}'",
       field.schema().valueSchema().type());
    if(list==null) {
        logger.trace("no array -> adding null");
        return BsonNull.VALUE;
    }
    BsonArray array = new BsonArray();
    Schema.Type st = field.schema().valueSchema().type();
    for(Object element : list) {
        if(st.isPrimitive()) {
            array.add(getConverter(field.schema().valueSchema()).toBson(element,field.schema()));
        } else if(st == Schema.Type.ARRAY) {
            Field elementField = new Field("first", 0, field.schema().valueSchema());
            array.add(handleArrayField((List)element,elementField));
        } else {
            array.add(toBsonDoc(field.schema().valueSchema(), element));
        }
    }
    return array;
}
 
Example #4
Source File: ChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
private Stream<ChronoVertex> getInChronoVertexStream(final BsonArray labels, final int branchFactor,
		final boolean setParallel) {
	HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>();
	BsonDocument filter = new BsonDocument();
	BsonDocument inner = new BsonDocument();
	filter.put(Tokens.IN_VERTEX, new BsonString(this.toString()));
	if (labels != null && labels.size() != 0) {
		inner.put(Tokens.FC.$in.toString(), labels);
		filter.put(Tokens.LABEL, inner);
	}

	Iterator<BsonDocument> it = null;
	if (branchFactor == Integer.MAX_VALUE)
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator();
	else
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator();
	while (it.hasNext()) {
		BsonDocument d = it.next();
		vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[0], this.graph));
	}
	if (setParallel)
		return vertexSet.parallelStream();
	else
		return vertexSet.stream();
}
 
Example #5
Source File: ChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
private Iterable<ChronoVertex> getInChronoVertices(BsonArray labels, final int branchFactor) {
	HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>();
	BsonDocument filter = new BsonDocument();
	BsonDocument inner = new BsonDocument();
	filter.put(Tokens.IN_VERTEX, new BsonString(this.toString()));
	if (labels != null && labels.size() != 0) {
		inner.put(Tokens.FC.$in.toString(), labels);
		filter.put(Tokens.LABEL, inner);
	}

	Iterator<BsonDocument> it = null;
	if (branchFactor == Integer.MAX_VALUE)
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator();
	else
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator();
	while (it.hasNext()) {
		BsonDocument d = it.next();
		vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[0], this.graph));
	}
	return vertexSet;
}
 
Example #6
Source File: UpdateDescription.java    From stitch-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: CachedChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
public Set<CachedEdgeEvent> getEdgeEventSet(final Direction direction, final BsonArray labels, final Long left,
		final AC tt, final int branchFactor) {

	HashSet<Long> labelIdxSet = null;
	if (labels != null) {
		labelIdxSet = convertToLabelIdxSet(labels);
	}

	if (direction.equals(Direction.OUT)) {
		return this.getOutEdgeEventSet(labelIdxSet, left, tt, branchFactor);
	} else if (direction.equals(Direction.IN))
		return this.getInEdgeEventSet(labelIdxSet, left, tt, branchFactor);
	else {
		Set<CachedEdgeEvent> ret = this.getOutEdgeEventSet(labelIdxSet, left, tt, branchFactor);
		ret.addAll(this.getInEdgeEventSet(labelIdxSet, left, tt, branchFactor));
		return ret;
	}
}
 
Example #8
Source File: EnforcedThingFlattener.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private Stream<Document> singleton(final JsonPointer key, final JsonValue jsonValue) {
    final Optional<JsonValue> fixedJsonValue = indexLengthRestrictionEnforcer.enforce(key, jsonValue);
    if (fixedJsonValue.isPresent()) {
        final BsonValue bsonValue = JsonToBson.convert(fixedJsonValue.get());
        final EffectedSubjects subjects = computeEffectedSubjectIds(key);
        final BsonArray grants = toBsonArray(subjects.getGranted());
        final BsonArray revokes = toBsonArray(subjects.getRevoked());
        final Document document = assembleDocument(key, bsonValue, grants, revokes);
        return replaceFeatureIdByWildcard(key)
                .map(replacedKey -> Stream.of(document, assembleDocument(replacedKey, bsonValue, grants, revokes)))
                .orElse(Stream.of(document));
    } else {
        // Impossible to restrict length of this key-value pair; do not index it.
        return Stream.empty();
    }
}
 
Example #9
Source File: VertexEvent.java    From epcis with Apache License 2.0 6 votes vote down vote up
public Stream<VertexEvent> getVertexEventStream(final Direction direction, final BsonArray labels,
		TemporalType typeOfVertexEvent, final AC tt, final AC s, final AC e, final AC ss, final AC se, final AC es,
		final AC ee, final Position pos, final boolean setParallel) {

	if (typeOfVertexEvent == null)
		typeOfVertexEvent = this.temporalType;

	final Stream<ChronoEdge> edgeStream = vertex.getChronoEdgeStream(direction, labels, Integer.MAX_VALUE,
			setParallel);

	// T -> T
	return edgeStream.map(edge -> {
		Long t = edge.getTimestamp(timestamp, tt);
		return edge.pickTimestamp(t);
	}).filter(edge -> edge != null).map(edgeEvent -> edgeEvent.getVertexEvent(direction.opposite()));
}
 
Example #10
Source File: GridFSTest.java    From mongo-java-driver-rx with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    gridFSBucket = GridFSBuckets.create(database);
    filesCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.files"))
            .withDocumentClass(BsonDocument.class);
    chunksCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.chunks"))
            .withDocumentClass(BsonDocument.class);

    List<BsonDocument> filesDocuments = processFiles(data.getArray("files", new BsonArray()), new ArrayList<BsonDocument>());
    if (!filesDocuments.isEmpty()) {
        filesCollection.insertMany(filesDocuments).timeout(30, SECONDS).first().toBlocking().first();
    }

    List<BsonDocument> chunksDocuments = processChunks(data.getArray("chunks", new BsonArray()), new ArrayList<BsonDocument>());
    if (!chunksDocuments.isEmpty()) {
        chunksCollection.insertMany(chunksDocuments).timeout(30, SECONDS).first().toBlocking().first();
    }
}
 
Example #11
Source File: GridFSTest.java    From mongo-java-driver-rx with Apache License 2.0 6 votes vote down vote up
private List<BsonDocument> processFiles(final BsonArray bsonArray, final List<BsonDocument> documents) {
    for (BsonValue rawDocument : bsonArray.getValues()) {
        if (rawDocument.isDocument()) {
            BsonDocument document = rawDocument.asDocument();
            if (document.get("length").isInt32()) {
                document.put("length", new BsonInt64(document.getInt32("length").getValue()));
            }
            if (document.containsKey("metadata") && document.getDocument("metadata").isEmpty()) {
                document.remove("metadata");
            }
            if (document.containsKey("aliases") && document.getArray("aliases").getValues().size() == 0) {
                document.remove("aliases");
            }
            if (document.containsKey("contentType") && document.getString("contentType").getValue().length() == 0) {
                document.remove("contentType");
            }
            documents.add(document);
        }
    }
    return documents;
}
 
Example #12
Source File: GridFSTest.java    From mongo-java-driver-reactivestreams with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    gridFSBucket = GridFSBuckets.create(database);
    filesCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.files"))
            .withDocumentClass(BsonDocument.class);
    chunksCollection = initializeCollection(new MongoNamespace(getDefaultDatabaseName(), "fs.chunks"))
            .withDocumentClass(BsonDocument.class);

    List<BsonDocument> filesDocuments = processFiles(data.getArray("files", new BsonArray()), new ArrayList<BsonDocument>());
    if (!filesDocuments.isEmpty()) {
        ObservableSubscriber<Success> filesInsertSubscriber = new ObservableSubscriber<Success>();
        filesCollection.insertMany(filesDocuments).subscribe(filesInsertSubscriber);
        filesInsertSubscriber.await(30, SECONDS);
    }

    List<BsonDocument> chunksDocuments = processChunks(data.getArray("chunks", new BsonArray()), new ArrayList<BsonDocument>());
    if (!chunksDocuments.isEmpty()) {
        ObservableSubscriber<Success> chunksInsertSubscriber = new ObservableSubscriber<Success>();
        chunksCollection.insertMany(chunksDocuments).subscribe(chunksInsertSubscriber);
        chunksInsertSubscriber.await(30, SECONDS);
    }
}
 
Example #13
Source File: TransactionEventWriteConverter.java    From epcis with Apache License 2.0 6 votes vote down vote up
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
		String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {

	ChronoGraph pg = Configuration.persistentGraph;

	if (epcList != null && !epcList.isEmpty()) {
		epcList.stream().forEach(object -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
					destinationList);
			pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
		});
	}

	if (epcQuantities != null && !epcQuantities.isEmpty()) {
		epcQuantities.stream().forEach(classElem -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
					sourceList, destinationList);
			pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
					"data", dataID);
		});
	}
}
 
Example #14
Source File: ObjectEventWriteConverter.java    From epcis with Apache License 2.0 6 votes vote down vote up
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
		String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {

	ChronoGraph pg = Configuration.persistentGraph;

	if (epcList != null && !epcList.isEmpty()) {
		epcList.stream().forEach(object -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
					destinationList);
			pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
		});
	}

	if (epcQuantities != null && !epcQuantities.isEmpty()) {
		epcQuantities.stream().forEach(classElem -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
					sourceList, destinationList);
			pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
					"data", dataID);
		});
	}
	return;
}
 
Example #15
Source File: CachedChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
public Iterable<CachedChronoVertex> getChronoVertices(final Direction direction, final BsonArray labels,
		final int branchFactor) {

	HashSet<Long> labelIdxSet = null;
	if (labels != null) {
		labelIdxSet = convertToLabelIdxSet(labels);
	}

	if (direction.equals(Direction.OUT)) {
		return this.getOutChronoVertices(labelIdxSet, branchFactor);
	} else if (direction.equals(Direction.IN))
		return this.getInChronoVertices(labelIdxSet, branchFactor);
	else {
		return new MultiIterable<CachedChronoVertex>(
				Arrays.asList(this.getOutChronoVertices(labelIdxSet, branchFactor),
						this.getInChronoVertices(labelIdxSet, branchFactor)));
	}
}
 
Example #16
Source File: CaptureUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
public BsonDocument putOutputQuantityList(BsonDocument base, List<QuantityElement> outputQuantityList) {
	BsonArray quantityArray = new BsonArray();
	for (QuantityElement quantityElement : outputQuantityList) {
		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("outputQuantityList", quantityArray);
	return base;
}
 
Example #17
Source File: ChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
/**
 * Return out-going edges (Internal Method)
 * 
 * @param labels
 * @return
 */
private Iterable<ChronoEdge> getOutChronoEdges(final BsonArray labels, final int branchFactor) {
	HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>();
	BsonDocument filter = new BsonDocument();
	BsonDocument inner = new BsonDocument();
	filter.put(Tokens.OUT_VERTEX, new BsonString(this.toString()));
	if (labels != null && labels.size() != 0) {
		inner.put(Tokens.FC.$in.toString(), labels);
		filter.put(Tokens.LABEL, inner);
	}

	Iterator<BsonDocument> it = null;
	if (branchFactor == Integer.MAX_VALUE)
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator();
	else
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator();

	while (it.hasNext()) {
		BsonDocument d = it.next();
		edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph));
	}
	return edgeSet;
}
 
Example #18
Source File: CaptureUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
public BsonDocument putInputQuantityList(BsonDocument base, List<QuantityElement> inputQuantityList) {
	BsonArray quantityArray = new BsonArray();
	for (QuantityElement quantityElement : inputQuantityList) {
		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("inputQuantityList", quantityArray);
	return base;
}
 
Example #19
Source File: CaptureUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
public BsonDocument putOutputQuantityList(BsonDocument base, List<QuantityElement> outputQuantityList) {
	BsonArray quantityArray = new BsonArray();
	for (QuantityElement quantityElement : outputQuantityList) {
		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("outputQuantityList", quantityArray);
	return base;
}
 
Example #20
Source File: VertexEvent.java    From epcis with Apache License 2.0 6 votes vote down vote up
public Iterable<VertexEvent> getVertexEvents(final Direction direction, final BsonArray labels,
		TemporalType typeOfVertexEvent, final AC tt, final AC s, final AC e, final AC ss, final AC se, final AC es,
		final AC ee, Position pos) {

	if (typeOfVertexEvent == null)
		typeOfVertexEvent = this.temporalType;

	Set<ChronoEdge> edgeSet = vertex.getChronoEdgeSet(direction, labels, Integer.MAX_VALUE);

	// T -> T
	return edgeSet.parallelStream().map(edge -> {
		Long t = edge.getTimestamp(timestamp, tt);
		return edge.pickTimestamp(t);
	}).filter(edge -> edge != null).map(edgeEvent -> edgeEvent.getVertexEvent(direction.opposite()))
			.collect(Collectors.toSet());
}
 
Example #21
Source File: MongoQueryUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
public static BsonDocument getBsonGeoPoint(String pointString) {
	try {
		BsonDocument pointDoc = new BsonDocument();
		pointDoc.put("type", new BsonString("Point"));

		String[] pointArr = pointString.split(",");
		if (pointArr.length != 2)
			return null;
		BsonArray arr = new BsonArray();
		arr.add(new BsonDouble(Double.parseDouble(pointArr[0])));
		arr.add(new BsonDouble(Double.parseDouble(pointArr[1])));
		pointDoc.put("coordinates", arr);
		return pointDoc;
	} catch (NumberFormatException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #23
Source File: ChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
private Set<ChronoEdge> getOutChronoEdgeSet(final BsonArray labels, final int branchFactor) {
	HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>();
	BsonDocument filter = new BsonDocument();
	BsonDocument inner = new BsonDocument();
	filter.put(Tokens.OUT_VERTEX, new BsonString(this.toString()));
	if (labels != null && labels.size() != 0) {
		inner.put(Tokens.FC.$in.toString(), labels);
		filter.put(Tokens.LABEL, inner);
	}

	Iterator<BsonDocument> it = null;
	if (branchFactor == Integer.MAX_VALUE)
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator();
	else
		it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator();

	while (it.hasNext()) {
		BsonDocument d = it.next();
		edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph));
	}
	return edgeSet;
}
 
Example #24
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
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 #25
Source File: CaptureUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
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 #26
Source File: ChronoGraph.java    From epcis with Apache License 2.0 6 votes vote down vote up
/**
 * Geospatial query
 * 
 * @param key    should be indexed by 2dsphere
 *               db.vertices.createIndex({"urn:oliot:ubv:mda:gps" : "2dsphere"})
 * @param lon
 * @param lat
 * @param radius in metres db.vertices.find({ "urn:oliot:ubv:mda:gps" : { $near
 *               : { $geometry: { type: "Point", coordinates: [ -1.1673,52.93]},
 *               $maxDistance: 50000}}})
 * 
 * @return
 */
public HashSet<ChronoVertex> getChronoVertexSet(String key, double lon, double lat, double radius) {
	HashSet<ChronoVertex> ret = new HashSet<ChronoVertex>();

	BsonArray coordinates = new BsonArray();
	coordinates.add(new BsonDouble(lon));
	coordinates.add(new BsonDouble(lat));
	BsonDocument geometry = new BsonDocument();
	geometry.put("type", new BsonString("Point"));
	geometry.put("coordinates", coordinates);
	BsonDocument near = new BsonDocument();
	near.put("$geometry", geometry);
	near.put("$maxDistance", new BsonDouble(radius));
	BsonDocument geoquery = new BsonDocument();
	geoquery.put("$near", near);
	BsonDocument queryDoc = new BsonDocument();
	queryDoc.put(key, geoquery);

	MongoCursor<BsonDocument> cursor = vertices.find(queryDoc).projection(Tokens.PRJ_ONLY_ID).iterator();

	while (cursor.hasNext()) {
		BsonDocument v = cursor.next();
		ret.add(new ChronoVertex(v.getString(Tokens.ID).getValue(), this));
	}
	return ret;
}
 
Example #27
Source File: CachedChronoVertex.java    From epcis with Apache License 2.0 6 votes vote down vote up
public Set<CachedChronoEdge> getChronoEdgeSet(final Direction direction, final BsonArray labels,
		final int branchFactor) {

	HashSet<Long> labelIdxSet = null;
	if (labels != null) {
		labelIdxSet = convertToLabelIdxSet(labels);
	}

	if (direction.equals(Direction.OUT)) {
		return this.getOutChronoEdgeSet(labelIdxSet, branchFactor);
	} else if (direction.equals(Direction.IN))
		return this.getInChronoEdgeSet(labelIdxSet, branchFactor);
	else {
		Set<CachedChronoEdge> ret = this.getOutChronoEdgeSet(labelIdxSet, branchFactor);
		ret.addAll(this.getInChronoEdgeSet(labelIdxSet, branchFactor));
		return ret;
	}
}
 
Example #28
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static BsonArray getBizTransactionObjectList(List<BusinessTransactionType> bizList) {
	BsonArray bizTranList = new BsonArray();
	for (int i = 0; i < bizList.size(); i++) {
		BusinessTransactionType bizTranType = bizList.get(i);
		if (bizTranType.getType() != null && bizTranType.getValue() != null) {
			BsonDocument dbObj = new BsonDocument();
			dbObj.put(bizTranType.getType(), new BsonString(
					bizTranType.getValue().replaceAll("\n", "").replaceAll("\t", "").replaceAll("\\s", "")));
			bizTranList.add(dbObj);
		}
	}
	return bizTranList;
}
 
Example #29
Source File: ResultDecoders.java    From stitch-android-sdk with Apache License 2.0 5 votes vote down vote up
public RemoteInsertManyResult decode(
    final BsonReader reader,
    final DecoderContext decoderContext
) {
  final BsonDocument document = (new BsonDocumentCodec()).decode(reader, decoderContext);
  keyPresent(Fields.INSERTED_IDS_FIELD, document);
  final BsonArray arr = document.getArray(Fields.INSERTED_IDS_FIELD);
  final Map<Long, BsonValue> insertedIds = new HashMap<>();
  for (int i = 0; i < arr.size(); i++) {
    insertedIds.put((long) i, arr.get(i));
  }

  return new RemoteInsertManyResult(insertedIds);
}
 
Example #30
Source File: TransformationQueryEmulationCode.java    From epcis with Apache License 2.0 5 votes vote down vote up
public ExternalTraversalEngine oute(final BsonArray labels, final TemporalType typeOfVertexEvent, final AC tt,
		final AC s, final AC e, final AC ss, final AC se, final AC es, final AC ee, final Position pos) {
	Map intermediate = (Map) stream.map(ve -> {
		EPCTime et = (EPCTime) ve;
		Set<EPCTime> outSet = new HashSet<EPCTime>();
		try {
			outSet = getNextOutSet(et);
		} catch (IOException | ParserConfigurationException | SAXException | ParseException e1) {
			e1.printStackTrace();
		}
		return new AbstractMap.SimpleImmutableEntry(et, outSet);
	}).collect(Collectors.toMap(entry -> ((Entry) entry).getKey(), entry -> ((Entry) entry).getValue()));
	updateTransformationPath(intermediate);
	stream = getStream(intermediate, isParallel);
	// Step Update
	final Class[] args = new Class[10];
	args[0] = BsonArray.class;
	args[1] = TemporalType.class;
	args[2] = AC.class;
	args[3] = AC.class;
	args[4] = AC.class;
	args[5] = AC.class;
	args[6] = AC.class;
	args[7] = AC.class;
	args[8] = AC.class;
	args[9] = Position.class;
	final Step step = new Step(this.getClass().getName(), "oute", args, labels, typeOfVertexEvent, tt, s, e, ss, se,
			es, ee, pos);
	stepList.add(step);
	elementClass = VertexEvent.class;
	return null;
}