def __init__(self, epc, item_class=None, dbname='EPCIS_DB'): self.epc = epc self.created = datetime.datetime.utcnow() #self.item_class=item_class if isinstance(item_class, physicalGood_class): self.class_attributes = item_class.__dict__ #save the record into the database db, dbname = mdb.setConnectionPymongo(dbname, not_enc=True) #check if the record already exists find = db['PhysicalGood'].find_one({'_id': epc}) if find == None: # if not found document = {} for key in list(self.__dict__.keys()): #unpack if a dictionary if isinstance(self.__dict__[key], dict): for key_child in list(self.__dict__[key].keys()): document[key_child] = self.__dict__[key][key_child] elif key == 'epc': #set epc as _id document['_id'] = self.__dict__['epc'] else: document[key] = self.__dict__[key] document['traceability'] = [] result = db['PhysicalGood'].insert_one(document)
def DELETEtransformationEvent(physicalGoodDict_input, physicalGoodDict_output, epcClass=None, xformID=None, quantity_in=1, quantity_in_udm=None, quantity_out=1, quantity_out_udm=None, nodeDict=None, disposition=None, bizStep=None, bizTransactionList=None, extensions={}, dbname="EPCIS_DB"): results = {} document = defineTranformationEvent( physicalGoodDict_input=physicalGoodDict_input, physicalGoodDict_output=physicalGoodDict_output, epcClass=epcClass, xformID=xformID, quantity_in=quantity_in, quantity_in_udm=quantity_in_udm, quantity_out=quantity_out, quantity_out_udm=quantity_out_udm, nodeDict=nodeDict, disposition=disposition, bizStep=bizStep, bizTransactionList=bizTransactionList, extensions=extensions) document['action'] = "DELETE" #insert record db, dbname = mdb.setConnectionPymongo(dbname, not_enc=True) results['insert'] = db['TransformationEvent'].insert_one(document) # update the traceability results['track'] = db['PhysicalGood'].update_one( {'_id': document['inputEpc']}, {'$push': { 'traceability': document }}) results['track'] = db['PhysicalGood'].update_one( {'_id': document['outputEpc']}, {'$push': { 'traceability': document }}) return results
def DELETEobjectEvent(physicalGoodDict, nodeDict, quantity, quantity_udm, disposition=None, bizTransactionList=None, bizStep=None, sourceDestList=None, ilmd=None, extensions={}, dbname="EPCIS_DB"): results = {} document = defineObjectEvent(physicalGoodDict=physicalGoodDict, nodeDict=nodeDict, quantity=quantity, quantity_udm=quantity_udm, disposition=disposition, bizTransactionList=bizTransactionList, bizStep=bizStep, sourceDestList=sourceDestList, ilmd=ilmd, extensions=extensions) document['action'] = "DELETE" #insert record db, dbname = mdb.setConnectionPymongo(dbname, not_enc=True) results['insert'] = db['ObjectEvent'].insert_one(document) #update the inventory function results['inventory'] = deleteInventory(document, nodeDict, quantity, quantity_udm, db) # update the traceability results['track'] = db['PhysicalGood'].update_one( {'_id': document['epc']}, {'$push': { 'traceability': document }}) return results
def DELETEtransactionEvent(physicalGoodDict, nodeDict, bizTransactionList, DestnodeDict, quantity, quantity_udm, bizStep=None, parentID=None, disposition=None, extensions={}, dbname="EPCIS_DB"): results = {} document = defineTransactionEvent(physicalGoodDict=physicalGoodDict, nodeDict=nodeDict, bizTransactionList=bizTransactionList, DestnodeDict=DestnodeDict, quantity=quantity, quantity_udm=quantity_udm, bizStep=bizStep, parentID=parentID, disposition=disposition, extensions=extensions) document['action'] = "DELETE" #insert record db, dbname = mdb.setConnectionPymongo(dbname, not_enc=True) results['insert'] = db['TransactionEvent'].insert_one(document) # update the traceability results['track'] = db['PhysicalGood'].update_one( {'_id': document['epc']}, {'$push': { 'traceability': document }}) return results
def OBSERVEaggregationEvent(physicalGoodDict_parent, physicalGoodDict_child, nodeDict=None, disposition=None, bizTransactionList=None, bizStep=None, sourceDestList=None, extensions={}, dbname="EPCIS_DB"): results = {} document = defineAggregationEvent(physicalGoodDict_parent, physicalGoodDict_child, nodeDict=nodeDict, disposition=disposition, bizTransactionList=bizTransactionList, bizStep=bizStep, sourceDestList=sourceDestList, extensions=extensions) document['action'] = "OBSERVE" #insert record db, dbname = mdb.setConnectionPymongo(dbname, not_enc=True) results['insert'] = db['AggregationEvent'].insert_one(document) # update the traceability results['track'] = db['PhysicalGood'].update_one( {'_id': document['parent_epc']}, {'$push': { 'traceability': document }}) results['track'] = db['PhysicalGood'].update_one( {'_id': document['child_epc']}, {'$push': { 'traceability': document }}) return results