Code Duplication    Length = 41-44 lines in 2 locations

bika/lims/browser/analysisrequest/add2.py 2 locations

@@ 353-396 (lines=44) @@
350
        TODO: This needs to go to bika.lims.api
351
        """
352
353
        def calc_dependants_gen(service, collector=None):
354
            """Generator for recursive resolution of dependant sevices.
355
            """
356
357
            # The UID of the service
358
            service_uid = api.get_uid(service)
359
360
            # maintain an internal dependency mapping
361
            if collector is None:
362
                collector = {}
363
364
            # Stop iteration if we processed this service already
365
            if service_uid in collector:
366
                raise StopIteration
367
368
            # Get the dependant calculations of the service
369
            # (calculations that use the service in their formula).
370
            dep_calcs = service.getBackReferences('CalculationAnalysisService')
371
            for dep_calc in dep_calcs:
372
                # Get the methods linked to this calculation
373
                dep_methods = dep_calc.getBackReferences('MethodCalculation')
374
                for dep_method in dep_methods:
375
                    # Get the services that have this method linked
376
                    dep_services = dep_method.getBackReferences('AnalysisServiceMethod')
377
                    for dep_service in dep_services:
378
379
                        # get the UID of the dependent service
380
                        dep_service_uid = api.get_uid(dep_service)
381
382
                        # skip services with a different calculation, e.g. when
383
                        # the user selected a calculation manually.
384
                        if dep_service.getCalculation() != dep_calc:
385
                            continue
386
387
                        # remember the dependent service
388
                        collector[dep_service_uid] = dep_service
389
390
                        # yield the dependent service
391
                        yield dep_service
392
393
                        # check the dependants of the dependant services
394
                        for ddep_service in calc_dependants_gen(dep_service,
395
                                                                collector=collector):
396
                            yield ddep_service
397
398
        dependants = {}
399
        for dep_service in calc_dependants_gen(service):
@@ 295-335 (lines=41) @@
292
        TODO: This needs to go to bika.lims.api
293
        """
294
295
        def calc_dependencies_gen(service, collector=None):
296
            """Generator for recursive dependency resolution.
297
            """
298
299
            # The UID of the service
300
            service_uid = api.get_uid(service)
301
302
            # maintain an internal dependency mapping
303
            if collector is None:
304
                collector = {}
305
306
            # Stop iteration if we processed this service already
307
            if service_uid in collector:
308
                raise StopIteration
309
310
            # Get the calculation of the service.
311
            # The calculation comes either from an assigned method or the user
312
            # has set a calculation manually (see content/analysisservice.py).
313
            calculation = service.getCalculation()
314
315
            # Stop iteration if there is no calculation
316
            if not calculation:
317
                raise StopIteration
318
319
            # The services used in this calculation.
320
            # These are the actual dependencies of the used formula.
321
            dep_services = calculation.getDependentServices()
322
            for dep_service in dep_services:
323
                # get the UID of the dependent service
324
                dep_service_uid = api.get_uid(dep_service)
325
326
                # remember the dependent service
327
                collector[dep_service_uid] = dep_service
328
329
                # yield the dependent service
330
                yield dep_service
331
332
                # check the dependencies of the dependent services
333
                for ddep_service in calc_dependencies_gen(dep_service,
334
                                                          collector=collector):
335
                    yield ddep_service
336
337
        dependencies = {}
338
        for dep_service in calc_dependencies_gen(service):