def put(self, receiver_gus, *uriargs): """ Request: adminReceiverDesc Response: adminReceiverDesc Errors: InvalidInputFormat, ReceiverGusNotFound, ContextGus Update information about a Receiver, return the instance updated. """ try: # TODO parameter validation - InvalidInputFormat request = validateMessage(self.request.body, requests.adminReceiverDesc) receiver_iface = Receiver() yield receiver_iface.update(receiver_gus, request) # 'contexts' it's a relationship between two tables, and is managed # with a separate method of new() context_iface = Context() yield receiver_iface.receiver_align(receiver_gus, request['contexts']) yield context_iface.full_context_align(receiver_gus, request['contexts']) receiver_description = yield receiver_iface.get_single(receiver_gus) self.set_status(200) self.write(receiver_description) except InvalidInputFormat, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def post(self, *uriargs): """ Request: adminReceiverDesc Response: adminReceiverDesc Errors: InvalidInputFormat, ContextGusNotFound Create a new receiver """ try: request = validateMessage(self.request.body, requests.adminReceiverDesc) receiver_iface = Receiver() new_receiver = yield receiver_iface.new(request) new_receiver_gus = new_receiver['receiver_gus'] # 'contexts' it's a relationship between two tables, and is managed # with a separate method of new() context_iface = Context() yield receiver_iface.receiver_align(new_receiver_gus, request['contexts']) yield context_iface.full_context_align(new_receiver_gus, request['contexts']) new_receiver_desc = yield receiver_iface.get_single(new_receiver_gus) self.set_status(201) # Created self.write(new_receiver_desc) except InvalidInputFormat, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def delete_receiver(self, receiver_gus): store = self.getStore() receiver_iface = Receiver(store) receiver_desc = receiver_iface.get_single(receiver_gus) receivertip_iface = ReceiverTip(store) # Remove Tip possessed by the receiver related_tips = receivertip_iface.get_tips_by_receiver(receiver_gus) for tip in related_tips: receivertip_iface.personal_delete(tip['tip_gus']) # Remind: the comment are kept, and the name do not use a reference # but is stored in the comment entry. context_iface = Context(store) # Just an alignment check that need to be removed contexts_associated = context_iface.get_contexts_by_receiver(receiver_gus) print "context associated by receiver POV:", len(contexts_associated),\ "context associated by receiver-DB field:", len(receiver_desc['contexts']) context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus) receiverconf_iface = ReceiverConfs(store) receivercfg_list = receiverconf_iface.get_confs_by_receiver(receiver_gus) for rcfg in receivercfg_list: receiverconf_iface.delete(rcfg['config_id'], receiver_gus) # Finally delete the receiver receiver_iface.receiver_delete(receiver_gus) self.returnData(receiver_desc) self.returnCode(200) return self.prepareRetVals()
def get_receiver(self, receiver_gus): receiver_iface = Receiver(self.getStore()) receiver_description = receiver_iface.get_single(receiver_gus) self.returnData(receiver_description) self.returnCode(200) return self.prepareRetVals()
def delete(self, receiver_gus, *uriargs): """ Parameter: receiver_gus Request: None Response: None Errors: InvalidInputFormat, ReceiverGusNotFound """ receiver_iface = Receiver() try: # TODO parameter receiver_gus validation - InvalidInputFormat receiver_desc = yield receiver_iface.get_single(receiver_gus) receivertip_iface = ReceiverTip() # Remove Tip possessed by the receiver related_tips = yield receivertip_iface.get_tips_by_receiver(receiver_gus) for tip in related_tips: yield receivertip_iface.personal_delete(tip['tip_gus']) # Remind: the comment are kept, and the name is not referenced but stored # in the comment entry. context_iface = Context() # TODO make an app log contexts_associated = yield context_iface.get_contexts_by_receiver(receiver_gus) print "context associated by receiver POV:", len(contexts_associated),\ "context associated by receiver-DB field:", len(receiver_desc['contexts']) yield context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus) receiverconf_iface = ReceiverConfs() # Delete all the receiver configuration associated TODO - App log an number of RCFGs receivercfg_list = yield receiverconf_iface.get_confs_by_receiver(receiver_gus) for rcfg in receivercfg_list: yield receiverconf_iface.delete(rcfg['config_id'], receiver_gus) # Finally delete the receiver yield receiver_iface.receiver_delete(receiver_gus) self.set_status(200) except ReceiverGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def update_receiver(self, receiver_gus, request): store = self.getStore() receiver_iface = Receiver(store) receiver_iface.update(receiver_gus, request) # 'contexts' it's a relationship between two tables, and is managed # with a separate method of update() context_iface = Context(store) receiver_iface.receiver_align(receiver_gus, request['contexts']) context_iface.full_context_align(receiver_gus, request['contexts']) receiver_description = receiver_iface.get_single(receiver_gus) self.returnData(receiver_description) self.returnCode(200) return self.prepareRetVals()
def create_receiver(self, request): store = self.getStore() receiver_iface = Receiver(store) new_receiver = receiver_iface.new(request) new_receiver_gus = new_receiver['receiver_gus'] # 'contexts' it's a relationship between two tables, and is managed # with a separate method of new() context_iface = Context(store) receiver_iface.receiver_align(new_receiver_gus, request['contexts']) context_iface.full_context_align(new_receiver_gus, request['contexts']) new_receiver_desc = receiver_iface.get_single(new_receiver_gus) self.returnData(new_receiver_desc) self.returnCode(201) return self.prepareRetVals()
def get(self, receiver_gus, *uriargs): """ Parameters: receiver_gus Response: adminReceiverDesc Errors: InvalidInputFormat, ReceiverGusNotFound Get an existent Receiver instance. """ try: # TODO parameter validation - InvalidInputFormat receiver_iface = Receiver() receiver_description = yield receiver_iface.get_single(receiver_gus) self.set_status(200) self.write(receiver_description) except ReceiverGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def get_receiver_list_by_wb(self, receipt): store = self.getStore() requested_t = WhistleblowerTip(store) tip_description = requested_t.get_single(receipt) receiver_iface = Receiver(store) itip_iface = InternalTip(store) # inforet = itip_iface.get_receivers_by_itip(tip_description['internaltip_id']) # the wb, instead get the list of active receiver, is getting the list of receiver # configured in the context: receivers_selected = itip_iface.get_single(tip_description['internaltip_id'])['receivers'] inforet = [] for receiver_gus in receivers_selected: inforet.append(receiver_iface.get_single(receiver_gus)) self.returnData(inforet) self.returnCode(200) return self.prepareRetVals()
def tip_creation(self): store = self.getStore() internaltip_iface = InternalTip(store) receiver_iface = Receiver(store) internal_tip_list = internaltip_iface.get_itips_by_maker(u'new', False) if len(internal_tip_list): print "TipSched: found %d new Tip" % len(internal_tip_list) for internaltip_desc in internal_tip_list: for receiver_gus in internaltip_desc['receivers']: try: receiver_desc = receiver_iface.get_single(receiver_gus) except ReceiverGusNotFound: # Log error, a receiver has been removed before get the Tip continue # check if the Receiver Tier is the first if int(receiver_desc['receiver_level']) != 1: continue receivertip_obj = ReceiverTip(store) receivertip_desc = receivertip_obj.new(internaltip_desc, receiver_desc) print "Created rTip", receivertip_desc['tip_gus'], "for", receiver_desc['name'], \ "in", internaltip_desc['context_gus'] internaltip_iface.flip_mark(internaltip_desc['internaltip_id'], internaltip_iface._marker[1]) # Escalation is not working at the moment, may be well engineered the function # before, permitting various layer of receivers. # # loops over the InternalTip and checks the escalation threshold # It may require the creation of second-step Tips escalated_itip_list = internaltip_iface.get_itips_by_maker(internaltip_iface._marker[1], True) if len(escalated_itip_list): print "TipSched: %d Tip are escalated" % len(escalated_itip_list) for eitip in escalated_itip_list: eitip_id = int(eitip['internaltip_id']) # This event has to be notified as system Comment Comment(store).new(eitip_id, u"Escalation threshold has been reached", u'system') for receiver_gus in eitip['receivers']: try: receiver_desc = receiver_iface.get_single(receiver_gus) except ReceiverGusNotFound: # Log error, a receiver has been removed before get the Tip continue # check if the Receiver Tier is the second if int(receiver_desc['receiver_level']) != 2: continue receivertip_obj = ReceiverTip(store) receivertip_desc = receivertip_obj.new(eitip, receiver_desc) print "Created 2nd tir rTip", receivertip_desc['tip_gus'], "for", receiver_desc['name'], \ "in", eitip['context_gus'] internaltip_iface.flip_mark(eitip_id, internaltip_iface._marker[2])
def operation(self): """ Goal of this function is to check all the InternalTip and create the Tips for the receiver needing. Create the ReceiverTip only, because WhistleBlowerTip is created when submission is finalized, along with the receipt exchange. Only the Receiver marked as first tier receiver has a Tip now, the receiver marked as tier 2 (if configured in the context) had their Tip only when the escalation_threshold has reached the requested value. """ internaltip_iface = InternalTip() receivertip_iface = ReceiverTip() receiver_iface = Receiver() internal_tip_list = yield internaltip_iface.get_itips_by_maker(u'new', False) # TODO for each itip # TODO get file status if len(internal_tip_list): log.debug("TipSched: found %d new Tip" % len(internal_tip_list) ) for internaltip_desc in internal_tip_list: for receiver_gus in internaltip_desc['receivers']: receiver_desc = yield receiver_iface.get_single(receiver_gus) # check if the Receiver Tier is the first if int(receiver_desc['receiver_level']) != 1: continue receivertip_desc = yield receivertip_iface.new(internaltip_desc, receiver_desc) print "Created rTip", receivertip_desc['tip_gus'], "for", receiver_desc['name'] try: # switch the InternalTip.mark for the tier supplied yield internaltip_iface.flip_mark(internaltip_desc['internaltip_id'], internaltip_iface._marker[1]) except: # ErrorTheWorldWillEndSoon("Goodbye and thanks for all the fish") print "Internal error" raise # Escalation is not working at the moment, may be well engineered the function # before, permitting various layer of receivers. # # loops over the InternalTip and checks the escalation threshold # It may require the creation of second-step Tips escalated_itip_list = yield internaltip_iface.get_itips_by_maker(internaltip_iface._marker[1], True) if len(escalated_itip_list): log.debug("TipSched: %d Tip are escalated" % len(escalated_itip_list) ) # This event has to be notified as system Comment comment_iface = Comment() for itip in escalated_itip_list: itip_id = int(itip['internaltip_id']) yield comment_iface.add_comment(itip_id, u"Escalation threshold has been reached", u'system') # XXX missing part new yield internaltip_iface.flip_mark(itip_id, internaltip_iface._marker[2]) log.debug("TipSched: escalated %d ReceiverTip for the iTip %d" % (receivertip_created, itip_id))