def getRetest(self): """Returns the retest that comes from this analysis, if any """ back_refs = get_backreferences(self, 'AnalysisRetestOf') if not back_refs: return None if len(back_refs) > 1: logger.warn("Analysis {} with multiple retests".format(self.id)) return api.get_object_by_uid(back_refs[0])
def getRetest(self): """Returns the retest that comes from this analysis, if any """ relationship = "{}RetestOf".format(self.portal_type) back_refs = get_backreferences(self, relationship) if not back_refs: return None if len(back_refs) > 1: logger.warn("Analysis {} with multiple retests".format(self.id)) return api.get_object_by_uid(back_refs[0])
def calc_dependants_gen(service, collector=None): """Generator for recursive resolution of dependant sevices. """ # The UID of the service service_uid = api.get_uid(service) # maintain an internal dependency mapping if collector is None: collector = {} # Stop iteration if we processed this service already if service_uid in collector: raise StopIteration # Get the dependant calculations of the service # (calculations that use the service in their formula). calc_uids = get_backreferences( service, relationship="CalculationDependentServices") for calc_uid in calc_uids: # Get the calculation object calc = api.get_object_by_uid(calc_uid) # Get the Analysis Services which have this calculation assigned dep_service_uids = get_backreferences( calc, relationship='AnalysisServiceCalculation') for dep_service_uid in dep_service_uids: dep_service = api.get_object_by_uid(dep_service_uid) # remember the dependent service collector[dep_service_uid] = dep_service # yield the dependent service yield dep_service # check the dependants of the dependant services for ddep_service in calc_dependants_gen( dep_service, collector=collector): yield ddep_service
def getAnalysis(self): """Return the analysis to which this is linked it may not be linked to an analysis """ analysis = get_backreferences(self, 'AnalysisAttachment', as_brains=True) if not analysis: return None if len(analysis) > 1: logger.warn("Single attachment assigned to more than one Analysis") analysis = api.get_object(analysis[0]) return analysis
def getAnalysis(self): """Return the analysis to which this is linked it may not be linked to an analysis """ analysis = get_backreferences(self, 'AnalysisAttachment', as_brains=True) if not analysis: return None if len(analysis) > 1: logger.warn("Single attachment assigned to more than one Analysis") analysis = api.get_object(analysis[0]) return analysis
def getLinkedAnalyses(self): """Lookup linked Analyses :returns: sorted list of ANs, where the latest AN comes first """ # Fetch the linked Analyses UIDs refs = get_backreferences(self, "AnalysisAttachment") # fetch the objects by UID and handle nonexisting UIDs gracefully ans = map(lambda uid: api.get_object_by_uid(uid, None), refs) # filter out None values (nonexisting UIDs) ans = filter(None, ans) # sort by physical path, so that attachments coming from an AR with a # higher "-Rn" suffix get sorted correctly. # N.B. the created date is the same, hence we can not use it return sorted(ans, key=api.get_path, reverse=True)
def getCalculationDependants(self): """Return a flat list of services who depend on this calculation. This refers only to services who's Calculation UIDReferenceField have the value set to point to this calculation. It has nothing to do with the services referenced in the calculation's Formula. """ deps = [] backrefs = get_backreferences(self, 'AnalysisServiceCalculation') services = map(get_object_by_uid, backrefs) for service in services: calc = service.getCalculation() if calc and calc.UID() != self.UID(): calc.getCalculationDependants(deps) deps.append(service) return deps
def getCalculationDependants(self, deps=None): """Return a flat list of services who depend on this calculation. This refers only to services who's Calculation UIDReferenceField have the value set to point to this calculation. It has nothing to do with the services referenced in the calculation's Formula. """ if deps is None: deps = [] backrefs = get_backreferences(self, 'AnalysisServiceCalculation') services = map(get_object_by_uid, backrefs) for service in services: calc = service.getCalculation() if calc and calc.UID() != self.UID(): calc.getCalculationDependants(deps) deps.append(service) return deps
def getAnalysisRequests(self): backrefs = get_backreferences(self, 'AnalysisRequestSample') ars = map(get_object_by_uid, backrefs) return ars
def getAnalysisRequests(self): backrefs = get_backreferences(self, 'AnalysisRequestSample') ars = map(get_object_by_uid, backrefs) return ars