Code Duplication    Length = 42-43 lines in 2 locations

src/main/java/unicon/matthews/xapi/service/DefaultXapiToCaliperConversionService.java 2 locations

@@ 491-533 (lines=43) @@
488
              
489
              List<XApiObject> parents = xapiContextActivities.getParent();
490
              SubOrganizationOf subOrganizationOf = null;
491
              if (parents != null && parents.size() == 1) {
492
                XApiObject parent = parents.get(0);
493
                String parentId = parent.getId();
494
                String parentType = "http://purl.imsglobal.org/caliper/v1/lis/CourseOffering";
495
                String parentName = null;
496
                String parentDescription = null;
497
                XApiObjectDefinition parentXapiObjectDefinition = parent.getDefinition();
498
                if (parentXapiObjectDefinition != null) {
499
                  
500
                  if (StringUtils.isNoneBlank(parentXapiObjectDefinition.getType())) {
501
                    parentType = parentXapiObjectDefinition.getType();
502
                  }
503
                  
504
                  Map<String,String> names = parentXapiObjectDefinition.getName();
505
                  if (names != null) {
506
                    if (names.size() == 1) {
507
                      parentName = CollectionUtils.get(names, 0).getValue();
508
                    }
509
                    else {
510
                      // default to en?
511
                      parentName = names.get("en");
512
                    }
513
                  }
514
515
                  Map<String,String> descriptions = parentXapiObjectDefinition.getDescription();
516
                  if (descriptions != null) {
517
                    if (descriptions.size() == 1) {
518
                      parentDescription = CollectionUtils.get(descriptions, 0).getValue();
519
                    }
520
                    else {
521
                      // default to en?
522
                      parentDescription = descriptions.get("en");
523
                    }
524
                  }
525
526
                  subOrganizationOf 
527
                    = new SubOrganizationOf.Builder()
528
                      .withId(parentId)
529
                      .withContext(Context.CONTEXT.getValue())
530
                      .withType(parentType)
531
                      .withName(parentName)
532
                      .withDescription(parentDescription)
533
                      .build();
534
                }
535
              }
536
              
@@ 548-589 (lines=42) @@
545
                  .withSubOrganizationOf(subOrganizationOf)
546
                  .build();
547
            }
548
            else if (xapiContextActivities.getParent() != null) {
549
              XApiObject parent = xapiContextActivities.getParent().get(0);
550
              String name = null;
551
              String description = null;
552
              XApiObjectDefinition xapiObjectDefinition = parent.getDefinition();
553
              if (xapiObjectDefinition != null) {
554
                if (StringUtils.isBlank(type) && StringUtils.isNoneBlank(xapiObjectDefinition.getType())) {
555
                  type = xapiObjectDefinition.getType();
556
                }
557
                
558
                Map<String,String> names = xapiObjectDefinition.getName();
559
                if (names != null) {
560
                  if (names.size() == 1) {
561
                    name = CollectionUtils.get(names, 0).getValue();
562
                  }
563
                  else {
564
                    // default to en?
565
                    name = names.get("en");
566
                  }
567
                }
568
569
                Map<String,String> descriptions = xapiObjectDefinition.getDescription();
570
                if (descriptions != null) {
571
                  if (descriptions.size() == 1) {
572
                    description = CollectionUtils.get(descriptions, 0).getValue();
573
                  }
574
                  else {
575
                    // default to en?
576
                    description = descriptions.get("en");
577
                  }
578
                }
579
              }
580
581
              caliperGroup 
582
                = new Group.Builder()
583
                  .withId(parent.getId())
584
                  .withContext(Context.CONTEXT.getValue())
585
                  .withType(type)
586
                  .withName(name)
587
                  .withDescription(description)
588
                  .withExtensions(contextExtensions)
589
                  .build();
590
            }
591
          }
592
        }