Java Code Examples for org.bson.BsonDocument#isEmpty()

The following examples show how to use org.bson.BsonDocument#isEmpty() . 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: RdbmsHandler.java    From kafka-connect-mongodb with Apache License 2.0 6 votes vote down vote up
protected static BsonDocument generateFilterDoc(BsonDocument keyDoc, BsonDocument valueDoc, OperationType opType) {
    if (keyDoc.keySet().isEmpty()) {
        if (opType.equals(OperationType.CREATE) || opType.equals(OperationType.READ)) {
            //create: no PK info in keyDoc -> generate ObjectId
            return new BsonDocument(DBCollection.ID_FIELD_NAME,new BsonObjectId());
        }
        //update or delete: no PK info in keyDoc -> take everything in 'before' field
        try {
            BsonDocument filter = valueDoc.getDocument(JSON_DOC_BEFORE_FIELD);
            if (filter.isEmpty())
                throw new BsonInvalidOperationException("value doc before field is empty");
            return filter;
        } catch(BsonInvalidOperationException exc) {
            throw new DataException("error: value doc 'before' field is empty or has invalid type" +
                    " for update/delete operation which seems severely wrong -> defensive actions taken!",exc);
        }
    }
    //build filter document composed of all PK columns
    BsonDocument pk = new BsonDocument();
    for (String f : keyDoc.keySet()) {
        pk.put(f,keyDoc.get(f));
    }
    return new BsonDocument(DBCollection.ID_FIELD_NAME,pk);
}
 
Example 2
Source File: MongoDbHandler.java    From kafka-connect-mongodb with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<WriteModel<BsonDocument>> handle(SinkDocument doc) {

    BsonDocument keyDoc = doc.getKeyDoc().orElseThrow(
            () -> new DataException("error: key document must not be missing for CDC mode")
    );

    BsonDocument valueDoc = doc.getValueDoc()
                                .orElseGet(BsonDocument::new);

    if(keyDoc.containsKey(JSON_ID_FIELD_PATH)
            && valueDoc.isEmpty()) {
        logger.debug("skipping debezium tombstone event for kafka topic compaction");
        return Optional.empty();
    }

    logger.debug("key: "+keyDoc.toString());
    logger.debug("value: "+valueDoc.toString());

    return Optional.ofNullable(getCdcOperation(valueDoc).perform(doc));
}
 
Example 3
Source File: GridFSTest.java    From mongo-java-driver-rx with Apache License 2.0 6 votes vote down vote up
private void actionGridFS(final BsonDocument action, final BsonDocument assertion) throws Throwable {
    if (action.isEmpty()) {
        return;
    }

    String operation = action.getString("operation").getValue();
    if (operation.equals("delete")) {
        doDelete(action.getDocument("arguments"), assertion);
    } else if (operation.equals("download")) {
        doDownload(action.getDocument("arguments"), assertion);
    } else if (operation.equals("download_by_name")) {
        doDownloadByName(action.getDocument("arguments"), assertion);
    } else if (operation.equals("upload")) {
        doUpload(action.getDocument("arguments"), assertion);
    } else {
        throw new IllegalArgumentException("Unknown operation: " + operation);
    }
}
 
Example 4
Source File: GridFSTest.java    From mongo-java-driver-reactivestreams with Apache License 2.0 6 votes vote down vote up
private void actionGridFS(final BsonDocument action, final BsonDocument assertion) throws Throwable {
    if (action.isEmpty()) {
        return;
    }

    String operation = action.getString("operation").getValue();
    if (operation.equals("delete")) {
        doDelete(action.getDocument("arguments"), assertion);
    } else if (operation.equals("download")) {
        doDownload(action.getDocument("arguments"), assertion);
    } else if (operation.equals("download_by_name")) {
        doDownloadByName(action.getDocument("arguments"), assertion);
    } else if (operation.equals("upload")) {
        doUpload(action.getDocument("arguments"), assertion);
    } else {
        throw new IllegalArgumentException("Unknown operation: " + operation);
    }
}
 
Example 5
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
static BsonDocument getBaseExtensionObject(EPCISEventExtensionType baseExtensionType) {
	BsonDocument baseExtension = new BsonDocument();
	/*
	 * May be deprecated if (baseExtensionType.getAny() != null &&
	 * baseExtensionType.getAny().isEmpty() == false) { List<Object> objList =
	 * baseExtensionType.getAny(); BsonDocument map2Save = getAnyMap(objList); if
	 * (map2Save.isEmpty() == false) baseExtension.put("any", map2Save); }
	 */
	if (baseExtensionType.getOtherAttributes() != null
			&& baseExtensionType.getOtherAttributes().isEmpty() == false) {
		Map<QName, String> map = baseExtensionType.getOtherAttributes();
		BsonDocument map2Save = getOtherAttributesMap(map);
		if (map2Save.isEmpty() == false)
			baseExtension.put("otherAttributes", map2Save);
	}
	return baseExtension;
}
 
Example 6
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
static BsonDocument getBaseExtensionObject(EPCISEventExtensionType baseExtensionType) {
	BsonDocument baseExtension = new BsonDocument();
	/*
	 * May be deprecated if (baseExtensionType.getAny() != null &&
	 * baseExtensionType.getAny().isEmpty() == false) { List<Object> objList =
	 * baseExtensionType.getAny(); BsonDocument map2Save = getAnyMap(objList); if
	 * (map2Save.isEmpty() == false) baseExtension.put("any", map2Save); }
	 */
	if (baseExtensionType.getOtherAttributes() != null
			&& baseExtensionType.getOtherAttributes().isEmpty() == false) {
		Map<QName, String> map = baseExtensionType.getOtherAttributes();
		BsonDocument map2Save = getOtherAttributesMap(map);
		if (map2Save.isEmpty() == false)
			baseExtension.put("otherAttributes", map2Save);
	}
	return baseExtension;
}
 
Example 7
Source File: RdbmsHandler.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
static BsonDocument generateFilterDoc(
    final BsonDocument keyDoc, final BsonDocument valueDoc, final OperationType opType) {
  if (keyDoc.keySet().isEmpty()) {
    if (opType.equals(OperationType.CREATE) || opType.equals(OperationType.READ)) {
      // create: no PK info in keyDoc -> generate ObjectId
      return new BsonDocument(ID_FIELD, new BsonObjectId());
    }
    // update or delete: no PK info in keyDoc -> take everything in 'before' field
    try {
      BsonDocument filter = valueDoc.getDocument(JSON_DOC_BEFORE_FIELD);
      if (filter.isEmpty()) {
        throw new BsonInvalidOperationException("value doc before field is empty");
      }
      return filter;
    } catch (BsonInvalidOperationException exc) {
      throw new DataException(
          "Error: value doc 'before' field is empty or has invalid type"
              + " for update/delete operation which seems severely wrong -> defensive actions taken!",
          exc);
    }
  }
  // build filter document composed of all PK columns
  BsonDocument pk = new BsonDocument();
  for (String f : keyDoc.keySet()) {
    pk.put(f, keyDoc.get(f));
  }
  return new BsonDocument(ID_FIELD, pk);
}
 
Example 8
Source File: RdbmsHandler.java    From kafka-connect-mongodb with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<WriteModel<BsonDocument>> handle(SinkDocument doc) {

    BsonDocument keyDoc = doc.getKeyDoc().orElseGet(BsonDocument::new);

    BsonDocument valueDoc = doc.getValueDoc().orElseGet(BsonDocument::new);

    if (valueDoc.isEmpty())  {
        logger.debug("skipping debezium tombstone event for kafka topic compaction");
        return Optional.empty();
    }

    return Optional.ofNullable(getCdcOperation(valueDoc)
                        .perform(new SinkDocument(keyDoc,valueDoc)));
}
 
Example 9
Source File: MongoWriterUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static BsonDocument getErrorDeclaration(ErrorDeclarationType edt) {
	BsonDocument errorBson = new BsonDocument();
	long declarationTime = edt.getDeclarationTime().toGregorianCalendar().getTimeInMillis();
	errorBson.put("declarationTime", new BsonDateTime(declarationTime));
	// (Optional) reason
	if (edt.getReason() != null) {
		errorBson.put("reason", new BsonString(edt.getReason()));
	}
	// (Optional) correctiveEventIDs
	if (edt.getCorrectiveEventIDs() != null) {
		CorrectiveEventIDsType cIDs = edt.getCorrectiveEventIDs();
		List<String> cIDStringList = cIDs.getCorrectiveEventID();
		BsonArray correctiveIDBsonArray = new BsonArray();
		for (String cIDString : cIDStringList) {
			correctiveIDBsonArray.add(new BsonString(cIDString));
		}
		if (correctiveIDBsonArray.size() != 0) {
			errorBson.put("correctiveEventIDs", correctiveIDBsonArray);
		}
	}
	if (edt.getAny() != null) {
		BsonDocument map2Save = getAnyMap(edt.getAny());
		if (map2Save != null && map2Save.isEmpty() == false) {
			errorBson.put("any", map2Save);
		}
	}

	return errorBson;
}
 
Example 10
Source File: QuantityEventWriteConverter.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument convert(QuantityEventType quantityEventType, Integer gcpLength) {

		BsonDocument dbo = new BsonDocument();

		dbo.put("eventType", new BsonString("QuantityEvent"));
		// Event Time
		if (quantityEventType.getEventTime() != null)
			dbo.put("eventTime",
					new BsonDateTime(quantityEventType.getEventTime().toGregorianCalendar().getTimeInMillis()));
		// Event Time zone
		if (quantityEventType.getEventTimeZoneOffset() != null)
			dbo.put("eventTimeZoneOffset", new BsonString(quantityEventType.getEventTimeZoneOffset()));
		// Record Time : according to M5
		GregorianCalendar recordTime = new GregorianCalendar();
		long recordTimeMilis = recordTime.getTimeInMillis();
		dbo.put("recordTime", new BsonDateTime(recordTimeMilis));
		// EPC Class
		if (quantityEventType.getEpcClass() != null)
			dbo.put("epcClass",
					new BsonString(MongoWriterUtil.getClassEPC(quantityEventType.getEpcClass(), gcpLength)));
		dbo.put("quantity", new BsonInt64(quantityEventType.getQuantity()));
		// Business Step
		if (quantityEventType.getBizStep() != null)
			dbo.put("bizStep", new BsonString(quantityEventType.getBizStep()));
		// Disposition
		if (quantityEventType.getDisposition() != null)
			dbo.put("disposition", new BsonString(quantityEventType.getDisposition()));
		// Read Point
		if (quantityEventType.getReadPoint() != null) {
			ReadPointType readPointType = quantityEventType.getReadPoint();
			BsonDocument readPoint = getReadPointObject(readPointType, gcpLength);
			dbo.put("readPoint", readPoint);
		}
		// BizLocation
		if (quantityEventType.getBizLocation() != null) {
			BusinessLocationType bizLocationType = quantityEventType.getBizLocation();
			BsonDocument bizLocation = getBizLocationObject(bizLocationType, gcpLength);
			dbo.put("bizLocation", bizLocation);
		}

		// Vendor Extension
		if (quantityEventType.getAny() != null) {
			List<Object> objList = quantityEventType.getAny();
			BsonDocument map2Save = getAnyMap(objList);
			if (map2Save != null && map2Save.isEmpty() == false)
				dbo.put("any", map2Save);

		}

		// BizTransaction
		if (quantityEventType.getBizTransactionList() != null) {
			BusinessTransactionListType bizListType = quantityEventType.getBizTransactionList();
			List<BusinessTransactionType> bizList = bizListType.getBizTransaction();
			BsonArray bizTranList = getBizTransactionObjectList(bizList);
			dbo.put("bizTransactionList", bizTranList);
		}
		// Extension
		if (quantityEventType.getExtension() != null) {
			QuantityEventExtensionType oee = quantityEventType.getExtension();
			BsonDocument extension = getQuantityEventExtensionObject(oee);
			dbo.put("extension", extension);
		}

		// Event ID
		if (quantityEventType.getBaseExtension() != null) {
			if (quantityEventType.getBaseExtension().getEventID() != null) {
				dbo.put("eventID", new BsonString(quantityEventType.getBaseExtension().getEventID()));
			}
		}

		// Error Declaration
		// If declared, it notes that the event is erroneous
		if (quantityEventType.getBaseExtension() != null) {
			EPCISEventExtensionType eeet = quantityEventType.getBaseExtension();
			ErrorDeclarationType edt = eeet.getErrorDeclaration();
			if (edt != null) {
				if (edt.getDeclarationTime() != null) {
					dbo.put("errorDeclaration", MongoWriterUtil.getErrorDeclaration(edt));
				}
			}
		}

		// Build Graph
		capture(quantityEventType, gcpLength);

		return dbo;
	}
 
Example 11
Source File: ObjectEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument objectEvent = super.asBsonDocument();
	// Required Fields
	objectEvent = util.putEventType(objectEvent, "ObjectEvent");
	objectEvent = util.putAction(objectEvent, action);

	// Optional Fields
	if (this.epcList != null && this.epcList.size() != 0) {
		objectEvent = util.putEPCList(objectEvent, epcList);
	}
	if (this.bizStep != null) {
		objectEvent = util.putBizStep(objectEvent, bizStep);
	}
	if (this.disposition != null) {
		objectEvent = util.putDisposition(objectEvent, disposition);
	}
	if (this.readPoint != null) {
		objectEvent = util.putReadPoint(objectEvent, readPoint);
	}
	if (this.bizLocation != null) {
		objectEvent = util.putBizLocation(objectEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		objectEvent = util.putBizTransactionList(objectEvent, bizTransactionList);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		objectEvent = util.putExtensions(objectEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.quantityList != null && this.quantityList.isEmpty() == false) {
		extension = util.putQuantityList(extension, quantityList);
	}
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		extension = util.putILMD(extension, namespaces, ilmds);
	}
	if (extension.isEmpty() == false)
		objectEvent.put("extension", extension);

	return objectEvent;
}
 
Example 12
Source File: TransformationEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument transformationEvent = super.asBsonDocument();
	transformationEvent = util.putEventType(transformationEvent, "TransformationEvent");
	// Optional Fields
	if (this.inputEPCList != null && this.inputEPCList.size() != 0) {
		transformationEvent = util.putInputEPCList(transformationEvent, inputEPCList);
	}
	if (this.inputQuantityList != null && this.inputQuantityList.isEmpty() == false) {
		transformationEvent = util.putInputQuantityList(transformationEvent, inputQuantityList);
	}
	if (this.outputEPCList != null && this.outputEPCList.size() != 0) {
		transformationEvent = util.putOutputEPCList(transformationEvent, outputEPCList);
	}
	if (this.outputQuantityList != null && this.outputQuantityList.isEmpty() == false) {
		transformationEvent = util.putOutputQuantityList(transformationEvent, outputQuantityList);
	}

	if (this.transformationID != null) {
		transformationEvent = util.putTransformationID(transformationEvent, transformationID);
	}

	if (this.bizStep != null) {
		transformationEvent = util.putBizStep(transformationEvent, bizStep);
	}
	if (this.disposition != null) {
		transformationEvent = util.putDisposition(transformationEvent, disposition);
	}
	if (this.readPoint != null) {
		transformationEvent = util.putReadPoint(transformationEvent, readPoint);
	}
	if (this.bizLocation != null) {
		transformationEvent = util.putBizLocation(transformationEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		transformationEvent = util.putBizTransactionList(transformationEvent, bizTransactionList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		transformationEvent = util.putILMD(transformationEvent, namespaces, ilmds);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		transformationEvent = util.putExtensions(transformationEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (extension.isEmpty() == false)
		transformationEvent.put("extension", extension);

	return transformationEvent;
}
 
Example 13
Source File: ObjectEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument objectEvent = super.asBsonDocument();
	// Required Fields
	objectEvent = util.putEventType(objectEvent, "ObjectEvent");
	objectEvent = util.putAction(objectEvent, action);

	// Optional Fields
	if (this.epcList != null && this.epcList.size() != 0) {
		objectEvent = util.putEPCList(objectEvent, epcList);
	}
	if (this.bizStep != null) {
		objectEvent = util.putBizStep(objectEvent, bizStep);
	}
	if (this.disposition != null) {
		objectEvent = util.putDisposition(objectEvent, disposition);
	}
	if (this.readPoint != null) {
		objectEvent = util.putReadPoint(objectEvent, readPoint);
	}
	if (this.bizLocation != null) {
		objectEvent = util.putBizLocation(objectEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		objectEvent = util.putBizTransactionList(objectEvent, bizTransactionList);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		objectEvent = util.putExtensions(objectEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.quantityList != null && this.quantityList.isEmpty() == false) {
		extension = util.putQuantityList(extension, quantityList);
	}
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		extension = util.putILMD(extension, namespaces, ilmds);
	}
	if (extension.isEmpty() == false)
		objectEvent.put("extension", extension);

	return objectEvent;
}
 
Example 14
Source File: TransformationEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument transformationEvent = super.asBsonDocument();
	transformationEvent = util.putEventType(transformationEvent, "TransformationEvent");

	// Optional Fields
	if (this.inputEPCList != null && this.inputEPCList.size() != 0) {
		transformationEvent = util.putInputEPCList(transformationEvent, inputEPCList);
	}
	if (this.inputQuantityList != null && this.inputQuantityList.isEmpty() == false) {
		transformationEvent = util.putInputQuantityList(transformationEvent, inputQuantityList);
	}
	if (this.outputEPCList != null && this.outputEPCList.size() != 0) {
		transformationEvent = util.putOutputEPCList(transformationEvent, outputEPCList);
	}
	if (this.outputQuantityList != null && this.outputQuantityList.isEmpty() == false) {
		transformationEvent = util.putOutputQuantityList(transformationEvent, outputQuantityList);
	}

	if (this.transformationID != null) {
		transformationEvent = util.putTransformationID(transformationEvent, transformationID);
	}

	if (this.bizStep != null) {
		transformationEvent = util.putBizStep(transformationEvent, bizStep);
	}
	if (this.disposition != null) {
		transformationEvent = util.putDisposition(transformationEvent, disposition);
	}
	if (this.readPoint != null) {
		transformationEvent = util.putReadPoint(transformationEvent, readPoint);
	}
	if (this.bizLocation != null) {
		transformationEvent = util.putBizLocation(transformationEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		transformationEvent = util.putBizTransactionList(transformationEvent, bizTransactionList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		transformationEvent = util.putILMD(transformationEvent, namespaces, ilmds);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		transformationEvent = util.putExtensions(transformationEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (extension.isEmpty() == false)
		transformationEvent.put("extension", extension);

	return transformationEvent;
}
 
Example 15
Source File: TransactionEventWriteConverter.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument convert(TransactionEventType transactionEventType, Integer gcpLength) {

		BsonDocument dbo = new BsonDocument();

		dbo.put("eventType", new BsonString("TransactionEvent"));
		// Event Time
		if (transactionEventType.getEventTime() != null)
			dbo.put("eventTime",
					new BsonDateTime(transactionEventType.getEventTime().toGregorianCalendar().getTimeInMillis()));
		// Event Time Zone
		if (transactionEventType.getEventTimeZoneOffset() != null)
			dbo.put("eventTimeZoneOffset", new BsonString(transactionEventType.getEventTimeZoneOffset()));
		// Record Time : according to M5
		GregorianCalendar recordTime = new GregorianCalendar();
		long recordTimeMilis = recordTime.getTimeInMillis();
		dbo.put("recordTime", new BsonDateTime(recordTimeMilis));
		// Parent ID
		if (transactionEventType.getParentID() != null)
			dbo.put("parentID",
					new BsonString(MongoWriterUtil.getInstanceEPC(transactionEventType.getParentID(), gcpLength)));
		// EPC List
		if (transactionEventType.getEpcList() != null) {
			EPCListType epcs = transactionEventType.getEpcList();
			List<EPC> epcList = epcs.getEpc();
			BsonArray epcDBList = new BsonArray();
			for (int i = 0; i < epcList.size(); i++) {
				BsonDocument epcDB = new BsonDocument();
				epcDB.put("epc", new BsonString(MongoWriterUtil.getInstanceEPC(epcList.get(i).getValue(), gcpLength)));
				epcDBList.add(epcDB);
			}
			dbo.put("epcList", epcDBList);
		}
		// Action
		if (transactionEventType.getAction() != null)
			dbo.put("action", new BsonString(transactionEventType.getAction().name()));
		// BizStep
		if (transactionEventType.getBizStep() != null)
			dbo.put("bizStep", new BsonString(transactionEventType.getBizStep()));
		// Disposition
		if (transactionEventType.getDisposition() != null)
			dbo.put("disposition", new BsonString(transactionEventType.getDisposition()));
		if (transactionEventType.getReadPoint() != null) {
			ReadPointType readPointType = transactionEventType.getReadPoint();
			BsonDocument readPoint = getReadPointObject(readPointType, gcpLength);
			dbo.put("readPoint", readPoint);
		}
		if (transactionEventType.getBizLocation() != null) {
			BusinessLocationType bizLocationType = transactionEventType.getBizLocation();
			BsonDocument bizLocation = getBizLocationObject(bizLocationType, gcpLength);
			dbo.put("bizLocation", bizLocation);
		}

		if (transactionEventType.getBizTransactionList() != null) {
			BusinessTransactionListType bizListType = transactionEventType.getBizTransactionList();
			List<BusinessTransactionType> bizList = bizListType.getBizTransaction();

			BsonArray bizTranList = getBizTransactionObjectList(bizList);
			dbo.put("bizTransactionList", bizTranList);
		}

		// Vendor Extension
		if (transactionEventType.getAny() != null) {
			List<Object> objList = transactionEventType.getAny();
			BsonDocument map2Save = getAnyMap(objList);
			if (map2Save != null && map2Save.isEmpty() == false)
				dbo.put("any", map2Save);

		}

		// Extension
		if (transactionEventType.getExtension() != null) {
			TransactionEventExtensionType oee = transactionEventType.getExtension();
			BsonDocument extension = getTransactionEventExtensionObject(oee, gcpLength);
			dbo.put("extension", extension);
		}

		// Event ID
		if (transactionEventType.getBaseExtension() != null) {
			if (transactionEventType.getBaseExtension().getEventID() != null) {
				dbo.put("eventID", new BsonString(transactionEventType.getBaseExtension().getEventID()));
			}
		}

		// Error Declaration
		// If declared, it notes that the event is erroneous
		if (transactionEventType.getBaseExtension() != null) {
			EPCISEventExtensionType eeet = transactionEventType.getBaseExtension();
			ErrorDeclarationType edt = eeet.getErrorDeclaration();
			if (edt != null) {
				if (edt.getDeclarationTime() != null) {
					dbo.put("errorDeclaration", MongoWriterUtil.getErrorDeclaration(edt));
				}
			}
		}

		return dbo;
	}
 
Example 16
Source File: AggregationEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument aggregationEvent = super.asBsonDocument();
	aggregationEvent.put("eventType", new BsonString("AggregationEvent"));
	// Required Fields
	aggregationEvent = util.putAction(aggregationEvent, action);

	// Optional Fields
	if (this.parentID != null) {
		aggregationEvent = util.putParentID(aggregationEvent, parentID);
	}
	if (this.childEPCs != null && this.childEPCs.size() != 0) {
		aggregationEvent = util.putChildEPCs(aggregationEvent, childEPCs);
	}
	if (this.bizStep != null) {
		aggregationEvent = util.putBizStep(aggregationEvent, bizStep);
	}
	if (this.disposition != null) {
		aggregationEvent = util.putDisposition(aggregationEvent, disposition);
	}
	if (this.readPoint != null) {
		aggregationEvent = util.putReadPoint(aggregationEvent, readPoint);
	}
	if (this.bizLocation != null) {
		aggregationEvent = util.putBizLocation(aggregationEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		aggregationEvent = util.putBizTransactionList(aggregationEvent, bizTransactionList);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		aggregationEvent = util.putExtensions(aggregationEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.childQuantityList != null && this.childQuantityList.isEmpty() == false) {
		extension = util.putChildQuantityList(extension, childQuantityList);
	}
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (extension.isEmpty() == false)
		aggregationEvent.put("extension", extension);

	return aggregationEvent;
}
 
Example 17
Source File: ObjectEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument objectEvent = super.asBsonDocument();
	// Required Fields
	objectEvent = util.putEventType(objectEvent, "ObjectEvent");
	objectEvent = util.putAction(objectEvent, action);

	// Optional Fields
	if (this.epcList != null && this.epcList.size() != 0) {
		objectEvent = util.putEPCList(objectEvent, epcList);
	}
	if (this.bizStep != null) {
		objectEvent = util.putBizStep(objectEvent, bizStep);
	}
	if (this.disposition != null) {
		objectEvent = util.putDisposition(objectEvent, disposition);
	}
	if (this.readPoint != null) {
		objectEvent = util.putReadPoint(objectEvent, readPoint);
	}
	if (this.bizLocation != null) {
		objectEvent = util.putBizLocation(objectEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		objectEvent = util.putBizTransactionList(objectEvent, bizTransactionList);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		objectEvent = util.putExtensions(objectEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.quantityList != null && this.quantityList.isEmpty() == false) {
		extension = util.putQuantityList(extension, quantityList);
	}
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		extension = util.putILMD(extension, namespaces, ilmds);
	}
	if (extension.isEmpty() == false)
		objectEvent.put("extension", extension);

	return objectEvent;
}
 
Example 18
Source File: TransformationEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument transformationEvent = super.asBsonDocument();
	transformationEvent = util.putEventType(transformationEvent, "TransformationEvent");
	// Optional Fields
	if (this.inputEPCList != null && this.inputEPCList.size() != 0) {
		transformationEvent = util.putInputEPCList(transformationEvent, inputEPCList);
	}
	if (this.inputQuantityList != null && this.inputQuantityList.isEmpty() == false) {
		transformationEvent = util.putInputQuantityList(transformationEvent, inputQuantityList);
	}
	if (this.outputEPCList != null && this.outputEPCList.size() != 0) {
		transformationEvent = util.putOutputEPCList(transformationEvent, outputEPCList);
	}
	if (this.outputQuantityList != null && this.outputQuantityList.isEmpty() == false) {
		transformationEvent = util.putOutputQuantityList(transformationEvent, outputQuantityList);
	}

	if (this.transformationID != null) {
		transformationEvent = util.putTransformationID(transformationEvent, transformationID);
	}

	if (this.bizStep != null) {
		transformationEvent = util.putBizStep(transformationEvent, bizStep);
	}
	if (this.disposition != null) {
		transformationEvent = util.putDisposition(transformationEvent, disposition);
	}
	if (this.readPoint != null) {
		transformationEvent = util.putReadPoint(transformationEvent, readPoint);
	}
	if (this.bizLocation != null) {
		transformationEvent = util.putBizLocation(transformationEvent, bizLocation);
	}
	if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) {
		transformationEvent = util.putBizTransactionList(transformationEvent, bizTransactionList);
	}
	if (this.ilmds != null && this.ilmds.isEmpty() == false) {
		transformationEvent = util.putILMD(transformationEvent, namespaces, ilmds);
	}
	if (this.extensions != null && this.extensions.isEmpty() == false) {
		transformationEvent = util.putExtensions(transformationEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (extension.isEmpty() == false)
		transformationEvent.put("extension", extension);

	return transformationEvent;
}
 
Example 19
Source File: QuantityEventWriteConverter.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument convert(QuantityEventType quantityEventType, Integer gcpLength) {

		BsonDocument dbo = new BsonDocument();

		dbo.put("eventType", new BsonString("QuantityEvent"));
		// Event Time
		if (quantityEventType.getEventTime() != null)
			dbo.put("eventTime",
					new BsonDateTime(quantityEventType.getEventTime().toGregorianCalendar().getTimeInMillis()));
		// Event Time zone
		if (quantityEventType.getEventTimeZoneOffset() != null)
			dbo.put("eventTimeZoneOffset", new BsonString(quantityEventType.getEventTimeZoneOffset()));
		// Record Time : according to M5
		GregorianCalendar recordTime = new GregorianCalendar();
		long recordTimeMilis = recordTime.getTimeInMillis();
		dbo.put("recordTime", new BsonDateTime(recordTimeMilis));
		// EPC Class
		if (quantityEventType.getEpcClass() != null)
			dbo.put("epcClass",
					new BsonString(MongoWriterUtil.getClassEPC(quantityEventType.getEpcClass(), gcpLength)));
		dbo.put("quantity", new BsonInt64(quantityEventType.getQuantity()));
		// Business Step
		if (quantityEventType.getBizStep() != null)
			dbo.put("bizStep", new BsonString(quantityEventType.getBizStep()));
		// Disposition
		if (quantityEventType.getDisposition() != null)
			dbo.put("disposition", new BsonString(quantityEventType.getDisposition()));
		// Read Point
		if (quantityEventType.getReadPoint() != null) {
			ReadPointType readPointType = quantityEventType.getReadPoint();
			BsonDocument readPoint = getReadPointObject(readPointType, gcpLength);
			dbo.put("readPoint", readPoint);
		}
		// BizLocation
		if (quantityEventType.getBizLocation() != null) {
			BusinessLocationType bizLocationType = quantityEventType.getBizLocation();
			BsonDocument bizLocation = getBizLocationObject(bizLocationType, gcpLength);
			dbo.put("bizLocation", bizLocation);
		}

		// Vendor Extension
		if (quantityEventType.getAny() != null) {
			List<Object> objList = quantityEventType.getAny();
			BsonDocument map2Save = getAnyMap(objList);
			if (map2Save != null && map2Save.isEmpty() == false)
				dbo.put("any", map2Save);

		}

		// BizTransaction
		if (quantityEventType.getBizTransactionList() != null) {
			BusinessTransactionListType bizListType = quantityEventType.getBizTransactionList();
			List<BusinessTransactionType> bizList = bizListType.getBizTransaction();
			BsonArray bizTranList = getBizTransactionObjectList(bizList);
			dbo.put("bizTransactionList", bizTranList);
		}
		// Extension
		if (quantityEventType.getExtension() != null) {
			QuantityEventExtensionType oee = quantityEventType.getExtension();
			BsonDocument extension = getQuantityEventExtensionObject(oee);
			dbo.put("extension", extension);
		}

		// Event ID
		if (quantityEventType.getBaseExtension() != null) {
			if (quantityEventType.getBaseExtension().getEventID() != null) {
				dbo.put("eventID", new BsonString(quantityEventType.getBaseExtension().getEventID()));
			}
		}

		// Error Declaration
		// If declared, it notes that the event is erroneous
		if (quantityEventType.getBaseExtension() != null) {
			EPCISEventExtensionType eeet = quantityEventType.getBaseExtension();
			ErrorDeclarationType edt = eeet.getErrorDeclaration();
			if (edt != null) {
				if (edt.getDeclarationTime() != null) {
					dbo.put("errorDeclaration", MongoWriterUtil.getErrorDeclaration(edt));
				}
			}
		}

		return dbo;
	}
 
Example 20
Source File: TransactionEvent.java    From epcis with Apache License 2.0 4 votes vote down vote up
public BsonDocument asBsonDocument() {
	CaptureUtil util = new CaptureUtil();

	BsonDocument transactionEvent = super.asBsonDocument();

	// Required Fields
	transactionEvent = util.putEventType(transactionEvent, "TransactionEvent");
	transactionEvent = util.putAction(transactionEvent, action);
	transactionEvent = util.putBizTransactionList(transactionEvent, bizTransactionList);

	// Optional Fields
	if (this.parentID != null) {
		transactionEvent = util.putParentID(transactionEvent, parentID);
	}
	if (this.epcList != null && this.epcList.size() != 0) {
		transactionEvent = util.putEPCList(transactionEvent, epcList);
	}
	if (this.bizStep != null) {
		transactionEvent = util.putBizStep(transactionEvent, bizStep);
	}
	if (this.disposition != null) {
		transactionEvent = util.putDisposition(transactionEvent, disposition);
	}
	if (this.readPoint != null) {
		transactionEvent = util.putReadPoint(transactionEvent, readPoint);
	}
	if (this.bizLocation != null) {
		transactionEvent = util.putBizLocation(transactionEvent, bizLocation);
	}

	if (this.extensions != null && this.extensions.isEmpty() == false) {
		transactionEvent = util.putExtensions(transactionEvent, namespaces, extensions);
	}

	BsonDocument extension = new BsonDocument();
	if (this.quantityList != null && this.quantityList.isEmpty() == false) {
		extension = util.putQuantityList(extension, quantityList);
	}
	if (this.sourceList != null && this.sourceList.isEmpty() == false) {
		extension = util.putSourceList(extension, sourceList);
	}
	if (this.destinationList != null && this.destinationList.isEmpty() == false) {
		extension = util.putDestinationList(extension, destinationList);
	}
	if (extension.isEmpty() == false)
		transactionEvent.put("extension", extension);

	return transactionEvent;
}