def add_transfer_of_custody(self, data, current_tx, xfer_to, xfer_from, buy_sell_modifiers, sequence=1, purpose=None): THROUGH = CaseFoldingSet(buy_sell_modifiers['through']) FOR = CaseFoldingSet(buy_sell_modifiers['for']) buyers = xfer_to sellers = xfer_from hmo = get_crom_object(data) parent = data['parent_data'] auction_data = parent['auction_of_lot'] cno, lno, date = object_key(auction_data) xfer_label = None purpose_label = f'(for {purpose}) ' if purpose else '' try: object_label = f'“{hmo._label}”' xfer_label = f'Transfer of Custody {purpose_label}of {cno} {lno} ({date}): {object_label}' except AttributeError: object_label = '(object)' xfer_label = f'Transfer of Custody {purpose_label}of {cno} {lno} ({date})' # TODO: pass in the tx to use instead of getting it from `parent` tx_data = parent.get('_prov_entry_data') current_tx = get_crom_object(tx_data) # The custody transfer sequence is specific to a single transaction. Therefore, # the custody transfer URI must not share a prefix with the object URI, otherwise # all such custody transfers are liable to be merged during URI reconciliation as # part of the prev/post sale rewriting. xfer_id = self.helper.prepend_uri_key(hmo.id, f'CustodyTransfer,{sequence}') xfer = model.TransferOfCustody(ident=xfer_id, label=xfer_label) xfer.transferred_custody_of = hmo if purpose in self.custody_xfer_purposes: xfer.general_purpose = self.custody_xfer_purposes[purpose] for seller_data in sellers: seller = get_crom_object(seller_data) mods = self.modifiers(seller_data, 'auth_mod_a') if not THROUGH.intersects(mods): xfer.transferred_custody_from = seller for buyer_data in buyers: buyer = get_crom_object(buyer_data) mods = self.modifiers(buyer_data, 'auth_mod_a') if not THROUGH.intersects(mods): xfer.transferred_custody_to = buyer current_tx.part = xfer
def test_breadth(self): x = model.TransferOfCustody() e = model.Activity() fr = model.Group() to = model.Group() w = model.ManMadeObject() fr.label = "From" to.label = "To" x.transferred_custody_of = w x.transferred_custody_from = fr x.transferred_custody_to = to e.used_specific_object = w e.carried_out_by = to w.current_owner = fr x.specific_purpose = e js = model.factory.toJSON(x) # Okay ... if we're breadth first, then custody_from is a resource # And now it's the first in the list self.assertTrue(isinstance(js['transferred_custody_from'][0], OrderedDict))
def add_transfer_of_custody(self, data, current_tx, xfer_to, xfer_from, sequence=1, purpose=None): buyers = xfer_to sellers = xfer_from hmo = get_crom_object(data) parent = data['parent_data'] auction_data = parent['auction_of_lot'] cno, lno, date = object_key(auction_data) xfer_label = None purpose_label = f'(for {purpose}) ' if purpose else '' try: object_label = f'“{hmo._label}”' xfer_label = f'Transfer of Custody {purpose_label}of {cno} {lno} ({date}): {object_label}' except AttributeError: object_label = '(object)' xfer_label = f'Transfer of Custody {purpose_label}of {cno} {lno} ({date})' # TODO: pass in the tx to use instead of getting it from `parent` tx_data = parent['_prov_entry_data'] current_tx = get_crom_object(tx_data) xfer_id = hmo.id + f'-CustodyTransfer-{sequence}' xfer = model.TransferOfCustody(ident=xfer_id, label=xfer_label) xfer.transferred_custody_of = hmo if purpose in self.custody_xfer_purposes: xfer.general_purpose = self.custody_xfer_purposes[purpose] for seller_data in sellers: seller = get_crom_object(seller_data) xfer.transferred_custody_from = seller for buyer_data in buyers: buyer = get_crom_object(buyer_data) xfer.transferred_custody_to = buyer current_tx.part = xfer
def related_procurement(self, hmo, tx_label_args, current_tx=None, current_ts=None, buyer=None, seller=None, previous=False, ident=None, make_label=None): ''' Returns a new `vocab.ProvenanceEntry` object (and related acquisition) that is temporally related to the supplied procurement and associated data. The new procurement is for the given object, and has the given buyer and seller (both optional). If the `previous` flag is `True`, the new procurement is occurs before `current_tx`, and if the timespan `current_ts` is given, has temporal data to that effect. If `previous` is `False`, this relationship is reversed. The `make_label` argument, if supplied, is used as a function to generate the label for the provenance entry. Its arguments (generated in `handle_prev_post_owner`) are: * helper: the helper object for the current pipeline * sale_type: the sale type passed to `handle_prev_post_owner` (e.g. "Auction") * transaction: the transaction type being handled (e.g. "Sold") * rel: a string describing the relationship between this provenance entry and the object (e.g. "leading to the previous ownership of") * N trailing arguments used that are the contents of the `lot_object_key` tuple passed to `handle_prev_post_owner` ''' def _make_label_default(helper, sale_type, transaction, rel, *args): strs = [str(x) for x in args] return ', '.join(strs) if make_label is None: make_label = _make_label_default tx = vocab.ProvenanceEntry(ident=ident) tx_label = make_label(*tx_label_args) tx._label = tx_label tx.identified_by = model.Name(ident='', content=tx_label) if current_tx: if previous: tx.ends_before_the_start_of = current_tx else: tx.starts_after_the_end_of = current_tx modifier_label = 'Previous' if previous else 'Subsequent' try: pacq = model.Acquisition( ident='', label=f'{modifier_label} Acquisition of: “{hmo._label}”') pxfer = model.TransferOfCustody( ident='', label=f'{modifier_label} Transfer of Custody of: “{hmo._label}”' ) except AttributeError: pacq = model.Acquisition(ident='', label=f'{modifier_label} Acquisition') pxfer = model.TransferOfCustody( ident='', label=f'{modifier_label} Transfer of Custody') pacq.transferred_title_of = hmo pxfer.transferred_custody_of = hmo if buyer: pacq.transferred_title_to = buyer pxfer.transferred_custody_to = buyer if seller: pacq.transferred_title_from = seller pxfer.transferred_custody_from = seller tx.part = pacq tx.part = pxfer if current_ts: if previous: pacq.timespan = timespan_before(current_ts) else: pacq.timespan = timespan_after(current_ts) return tx, pacq