def move_resource(self, key, source, destination): try: source | should | be_instance_of(Node) except ShouldNotSatisfied: raise ContractError( 'Node instance expected for Source, instead %s passed' % type(source)) try: destination | should | be_instance_of(Node) except ShouldNotSatisfied: raise ContractError( 'Node instance expected for Destination, instead %s passed' % type(destination)) try: resource = source.output_area.pop(key) resource | should | be_instance_of(Resource) except KeyError: raise KeyError( 'Resource with key %s not found in source node output area' % key) except ShouldNotSatisfied: source.output_area[key] = resource #put it back in the source raise ContractError( 'Resource instance expected, instead %s passed' % type(resource)) else: destination.input_area[key] = resource
def move_loan_to_account(self, loan_key, account): ''' moves the approved loan to the account ''' try: loan = self.decorated.output_area[loan_key] loan |should| be_instance_of(Loan) except KeyError: raise KeyError("Loan with key %s not found in Analyst's output area" % loan_key) except ShouldNotSatisfied: raise ContractError('Loan instance expected, instead %s passed' % type(loan)) try: Node.move_resource(loan_key, self.decorated, account.decorated) except ShouldNotSatisfied: raise ContractError('Bank Account instance expected, instead %s passed' % type(account)) account.register_credit(loan.loan_request.value)
def __init__(self, source, destination): Decorable.__init__(self) try: source | should | be_instance_of(Node) except: raise ContractError( 'Source: Node instance expected, instead %s passed' % type(source)) self.source = source try: destination | should | be_instance_of(Node) except: raise ContractError( 'Destination: Node instance expected, instead %s passed' % type(destination)) self.destination = destination
def insert_node(self, key, node): try: #organization should be passed as a node too, check what could happen node | should | be_instance_of(Node) except: raise ContractError('Node instance expected, instead %s passed' % type(node)) self.nodes[key] = node
def insert_movement(self, key, movement): try: #process should be passed as a movement too, check what could happen movement | should | be_instance_of(Movement) except: raise ContractError( 'Movement instance expected, instead %s passed' % type(movement)) self.movements[key] = movement
def decorate(self, decorator): ''' Inserts decorator reference and logs datetime activation ''' try: decorator | should | be_instance_of(Decorator) except ShouldNotSatisfied: raise ContractError( 'Decorator instance expected, instead %s passed' % type(decorator)) else: self.decorators[decorator.__doc__] = decorator #decorator reference, datetime ativation, datetime deactivation self.decoration_history.append([decorator, datetime.now(), None])
def receive_resource(self, key, resource): try: resource |should| be_instance_of(Resource) except: raise ContractError('Resource instance expected, instead %s passed' % type(resource)) self.input_area[key] = resource