@Ignore
  @Test
  public void testImportAllWithNewOnly() {
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementAModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementBModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementCModified, null);

    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementGroupADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementGroupBDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementGroupCDuplicate, null);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationA);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationB);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationC);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationE);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationF);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationG);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationI);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationJ);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationK);

    dbmsManager.clearSession();

    importObjectService.importAll();

    Collection<DataElement> dataElements = dataElementService.getAllDataElements();

    assertEquals(dataElements.size(), 3);

    assertTrue(dataElements.contains(dataElementA));
    assertTrue(dataElements.contains(dataElementB));
    assertTrue(dataElements.contains(dataElementC));

    Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();

    assertEquals(dataElementGroups.size(), 3);

    assertTrue(dataElementGroups.contains(dataElementGroupA));
    assertTrue(dataElementGroups.contains(dataElementGroupB));
    assertTrue(dataElementGroups.contains(dataElementGroupC));

    for (DataElementGroup dataElementGroup : dataElementGroups) {
      assertEquals(dataElementGroup.getMembers().size(), 3);

      assertTrue(dataElementGroup.getMembers().containsAll(dataElements));
    }

    assertEquals(importObjectService.getImportObjects(DataElement.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(DataElementGroup.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(GroupMemberAssociation.class).size(), 0);
  }
  public String execute() {
    // ---------------------------------------------------------------------
    // Get group members
    // ---------------------------------------------------------------------

    if (id != null) {
      DataElementGroup group = dataElementService.getDataElementGroup(id);

      groupMembers = new ArrayList<DataElement>(group.getMembers());

      Collections.sort(groupMembers, new IdentifiableObjectNameComparator());
    }

    return SUCCESS;
  }
Esempio n. 3
0
  /**
   * Returns meta-data mapping for this analytical object. Includes a identifier to name mapping for
   * dynamic dimensions.
   */
  public Map<String, String> getMetaData() {
    Map<String, String> meta = new HashMap<>();

    for (DataElementGroup group : dataElementGroups) {
      meta.put(group.getGroupSet().getUid(), group.getGroupSet().getName());
    }

    for (OrganisationUnitGroup group : organisationUnitGroups) {
      meta.put(group.getGroupSet().getUid(), group.getGroupSet().getName());
    }

    for (DataElementCategoryDimension category : categoryDimensions) {
      meta.put(category.getDimension().getUid(), category.getDimension().getName());
    }

    return meta;
  }
  @Override
  public String execute() {
    if (dataElementGroupId > 0) {
      DataElementGroup group =
          dataElementService.getDataElementGroup(dataElementGroupId.intValue());

      dataElements = new ArrayList<>(group.getMembers());
    } else {
      dataElements = new ArrayList<>(dataElementService.getAllDataElements());
    }

    Collections.sort(dataElements, new IdentifiableObjectNameComparator());

    for (DataElement dataElement : dataElements) {
      DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();

      Set<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getOptionCombos();

      if (optionCombos.size() > 1) {
        for (DataElementCategoryOptionCombo optionCombo : optionCombos) {
          DataElementOperand operand =
              new DataElementOperand(
                  dataElement.getUid(),
                  optionCombo.getUid(),
                  dataElement.getName() + optionCombo.getName());
          operands.add(operand);
        }
      } else {
        DataElementOperand operand =
            new DataElementOperand(
                dataElement.getUid(),
                optionCombos.iterator().next().getUid(),
                dataElement.getName());
        operands.add(operand);
      }
    }

    return SUCCESS;
  }
Esempio n. 5
0
  @Override
  public void setUpTest() {
    organisationUnit = createOrganisationUnit('A');
    organisationUnitLevel = new OrganisationUnitLevel(1, "Level");

    organisationUnitService.addOrganisationUnit(organisationUnit);
    organisationUnitService.addOrganisationUnitLevel(organisationUnitLevel);

    indicatorGroup = createIndicatorGroup('A');
    indicatorService.addIndicatorGroup(indicatorGroup);

    indicatorType = createIndicatorType('A');
    indicatorService.addIndicatorType(indicatorType);

    indicator = createIndicator('A', indicatorType);
    indicatorService.addIndicator(indicator);

    dataElement = createDataElement('A');
    dataElementService.addDataElement(dataElement);

    dataElementGroup = createDataElementGroup('A');
    dataElementGroup.getMembers().add(dataElement);
    dataElementService.addDataElementGroup(dataElementGroup);

    periodType = periodService.getPeriodTypeByName(MonthlyPeriodType.NAME);
    period = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 2, 1));
    periodService.addPeriod(period);

    mapLegendSet = createLegendSet('A');
    legendService.addLegendSet(mapLegendSet);

    internalMapLayer = new InternalMapLayer();
    internalMapLayer.setRadiusLow(15);
    internalMapLayer.setRadiusHigh(35);
    internalMapLayer.setColorLow(Color.YELLOW);
    internalMapLayer.setColorHigh(Color.RED);
    internalMapLayer.setOpacity(0.5f);
  }
Esempio n. 6
0
  /**
   * Assembles a list of DimensionalObjects based on the concrete objects in this
   * BaseAnalyticalObject. Explodes the dx dimension into the in|de|dc|ds concrete objects and
   * returns them as separate DimensionalObjects.
   *
   * <p>Merges fixed and relative periods into the pe dimension, where the RelativePeriods object is
   * represented by enums (e.g. LAST_MONTH). Merges fixed and user organisation units into the ou
   * dimension, where user organisation units properties are represented by enums (e.g.
   * USER_ORG_UNIT).
   *
   * <p>This method is useful when serializing the AnalyticalObject.
   *
   * @param dimension the dimension identifier.
   * @return a list of DimensionalObjects.
   */
  protected List<DimensionalObject> getDimensionalObjectList(String dimension) {
    List<DimensionalObject> objects = new ArrayList<>();

    List<String> categoryDims = getCategoryDims();

    if (DATA_X_DIM_ID.equals(dimension)) {
      if (!indicators.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(INDICATOR_DIM_ID, DimensionType.INDICATOR, indicators));
      }

      if (!dataElements.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements));
      }

      if (!dataElementOperands.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(
                DATAELEMENT_OPERAND_ID, DimensionType.DATAELEMENT_OPERAND, dataElementOperands));
      }

      if (!dataSets.isEmpty()) {
        objects.add(new BaseDimensionalObject(DATASET_DIM_ID, DimensionType.DATASET, dataSets));
      }
    } else if (PERIOD_DIM_ID.equals(dimension) && (!periods.isEmpty() || hasRelativePeriods())) {
      List<Period> periodList = new ArrayList<>(periods);

      if (hasRelativePeriods()) {
        List<RelativePeriodEnum> list = relatives.getRelativePeriodEnums();

        for (RelativePeriodEnum periodEnum : list) {
          periodList.add(new ConfigurablePeriod(periodEnum.toString()));
        }
      }

      Collections.sort(periodList, new AscendingPeriodComparator());

      objects.add(new BaseDimensionalObject(dimension, DimensionType.PERIOD, periodList));
    } else if (ORGUNIT_DIM_ID.equals(dimension)
        && (!organisationUnits.isEmpty()
            || !transientOrganisationUnits.isEmpty()
            || hasUserOrgUnit())) {
      List<NameableObject> ouList = new ArrayList<>();
      ouList.addAll(organisationUnits);
      ouList.addAll(transientOrganisationUnits);

      if (userOrganisationUnit) {
        ouList.add(new BaseNameableObject(KEY_USER_ORGUNIT, KEY_USER_ORGUNIT, KEY_USER_ORGUNIT));
      }

      if (userOrganisationUnitChildren) {
        ouList.add(
            new BaseNameableObject(
                KEY_USER_ORGUNIT_CHILDREN, KEY_USER_ORGUNIT_CHILDREN, KEY_USER_ORGUNIT_CHILDREN));
      }

      if (userOrganisationUnitGrandChildren) {
        ouList.add(
            new BaseNameableObject(
                KEY_USER_ORGUNIT_GRANDCHILDREN,
                KEY_USER_ORGUNIT_GRANDCHILDREN,
                KEY_USER_ORGUNIT_GRANDCHILDREN));
      }

      if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
        for (Integer level : organisationUnitLevels) {
          String id = KEY_LEVEL + level;

          ouList.add(new BaseNameableObject(id, id, id));
        }
      }

      if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty()) {
        for (OrganisationUnitGroup group : itemOrganisationUnitGroups) {
          String id = KEY_ORGUNIT_GROUP + group.getUid();

          ouList.add(new BaseNameableObject(id, id, id));
        }
      }

      objects.add(new BaseDimensionalObject(dimension, DimensionType.ORGANISATIONUNIT, ouList));
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<BaseNameableObject>()));
    } else if (categoryDims.contains(dimension)) {
      DataElementCategoryDimension categoryDimension =
          categoryDimensions.get(categoryDims.indexOf(dimension));

      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.CATEGORY, categoryDimension.getItems()));
    } else if (DATA_COLLAPSED_DIM_ID.contains(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.DATA_COLLAPSED, new ArrayList<NameableObject>()));
    } else if (STATIC_DIMS.contains(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.STATIC, new ArrayList<NameableObject>()));
    } else {
      // Data element group set

      ListMap<String, NameableObject> deGroupMap = new ListMap<>();

      for (DataElementGroup group : dataElementGroups) {
        if (group.getGroupSet() != null) {
          deGroupMap.putValue(group.getGroupSet().getDimension(), group);
        }
      }

      if (deGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.DATAELEMENT_GROUPSET, deGroupMap.get(dimension)));
      }

      // Organisation unit group set

      ListMap<String, NameableObject> ouGroupMap = new ListMap<>();

      for (OrganisationUnitGroup group : organisationUnitGroups) {
        if (group.getGroupSet() != null) {
          ouGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (ouGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, ouGroupMap.get(dimension)));
      }

      // Category option group set

      ListMap<String, NameableObject> coGroupMap = new ListMap<>();

      for (CategoryOptionGroup group : categoryOptionGroups) {
        if (group.getGroupSet() != null) {
          coGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (coGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.CATEGORYOPTION_GROUPSET, coGroupMap.get(dimension)));
      }

      // Tracked entity attribute

      Map<String, TrackedEntityAttributeDimension> attributes = new HashMap<>();

      for (TrackedEntityAttributeDimension attribute : attributeDimensions) {
        attributes.put(attribute.getUid(), attribute);
      }

      if (attributes.containsKey(dimension)) {
        TrackedEntityAttributeDimension tead = attributes.get(dimension);

        objects.add(
            new BaseDimensionalObject(
                dimension,
                DimensionType.TRACKED_ENTITY_ATTRIBUTE,
                null,
                tead.getDisplayName(),
                tead.getLegendSet(),
                tead.getFilter()));
      }

      // Tracked entity data element

      Map<String, TrackedEntityDataElementDimension> dataElements = new HashMap<>();

      for (TrackedEntityDataElementDimension dataElement : dataElementDimensions) {
        dataElements.put(dataElement.getUid(), dataElement);
      }

      if (dataElements.containsKey(dimension)) {
        TrackedEntityDataElementDimension tedd = dataElements.get(dimension);

        objects.add(
            new BaseDimensionalObject(
                dimension,
                DimensionType.TRACKED_ENTITY_DATAELEMENT,
                null,
                tedd.getDisplayName(),
                tedd.getLegendSet(),
                tedd.getFilter()));
      }
    }

    return objects;
  }
Esempio n. 7
0
  /**
   * Assembles a DimensionalObject based on the persisted properties of this AnalyticalObject.
   * Collapses indicators, data elements, data element operands and data sets into the dx dimension.
   *
   * <p>Collapses fixed and relative periods into the pe dimension. Collapses fixed and user
   * organisation units into the ou dimension.
   *
   * @param dimension the dimension identifier.
   * @param date the date used for generating relative periods.
   * @param user the current user.
   * @param dynamicNames whether to use dynamic or static names.
   * @param format the I18nFormat.
   * @return a DimensionalObject.
   */
  protected DimensionalObject getDimensionalObject(
      String dimension,
      Date date,
      User user,
      boolean dynamicNames,
      List<OrganisationUnit> organisationUnitsAtLevel,
      List<OrganisationUnit> organisationUnitsInGroups,
      I18nFormat format) {
    List<NameableObject> items = new ArrayList<>();

    DimensionType type = null;

    List<String> categoryDims = getCategoryDims();

    if (DATA_X_DIM_ID.equals(dimension)) {
      items.addAll(indicators);
      items.addAll(dataElements);
      items.addAll(dataElementOperands);
      items.addAll(dataSets);

      type = DimensionType.DATA_X;
    } else if (PERIOD_DIM_ID.equals(dimension)) {
      setPeriodNames(periods, dynamicNames, format);

      items.addAll(periods);

      if (hasRelativePeriods()) {
        if (rewindRelativePeriods) {
          items.addAll(relatives.getRewindedRelativePeriods(1, date, format, dynamicNames));
        } else {
          items.addAll(relatives.getRelativePeriods(date, format, dynamicNames));
        }
      }

      type = DimensionType.PERIOD;
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
      items.addAll(organisationUnits);
      items.addAll(transientOrganisationUnits);

      if (userOrganisationUnit && user != null && user.hasOrganisationUnit()) {
        items.add(user.getOrganisationUnit());
      }

      if (userOrganisationUnitChildren && user != null && user.hasOrganisationUnit()) {
        items.addAll(user.getOrganisationUnit().getSortedChildren());
      }

      if (userOrganisationUnitGrandChildren && user != null && user.hasOrganisationUnit()) {
        items.addAll(user.getOrganisationUnit().getSortedGrandChildren());
      }

      if (organisationUnitLevels != null
          && !organisationUnitLevels.isEmpty()
          && organisationUnitsAtLevel != null) {
        items.addAll(organisationUnitsAtLevel); // Must be set externally
      }

      if (itemOrganisationUnitGroups != null
          && !itemOrganisationUnitGroups.isEmpty()
          && organisationUnitsInGroups != null) {
        items.addAll(organisationUnitsInGroups); // Must be set externally
      }

      type = DimensionType.ORGANISATIONUNIT;
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
      items.addAll(transientCategoryOptionCombos);

      type = DimensionType.CATEGORY_OPTION_COMBO;
    } else if (categoryDims.contains(dimension)) {
      DataElementCategoryDimension categoryDimension =
          categoryDimensions.get(categoryDims.indexOf(dimension));

      items.addAll(categoryDimension.getItems());

      type = DimensionType.CATEGORY;
    } else if (STATIC_DIMS.contains(dimension)) {
      type = DimensionType.STATIC;
    } else {
      // Data element group set

      ListMap<String, NameableObject> deGroupMap = new ListMap<>();

      for (DataElementGroup group : dataElementGroups) {
        if (group.getGroupSet() != null) {
          deGroupMap.putValue(group.getGroupSet().getDimension(), group);
        }
      }

      if (deGroupMap.containsKey(dimension)) {
        items.addAll(deGroupMap.get(dimension));

        type = DimensionType.DATAELEMENT_GROUPSET;
      }

      // Organisation unit group set

      ListMap<String, NameableObject> ouGroupMap = new ListMap<>();

      for (OrganisationUnitGroup group : organisationUnitGroups) {
        if (group.getGroupSet() != null) {
          ouGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (ouGroupMap.containsKey(dimension)) {
        items.addAll(ouGroupMap.get(dimension));

        type = DimensionType.ORGANISATIONUNIT_GROUPSET;
      }

      // Category option group set

      ListMap<String, NameableObject> coGroupMap = new ListMap<>();

      for (CategoryOptionGroup group : categoryOptionGroups) {
        if (group.getGroupSet() != null) {
          coGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (coGroupMap.containsKey(dimension)) {
        items.addAll(coGroupMap.get(dimension));

        type = DimensionType.CATEGORYOPTION_GROUPSET;
      }

      // Tracked entity attribute

      Map<String, TrackedEntityAttributeDimension> attributes = new HashMap<>();

      for (TrackedEntityAttributeDimension attribute : attributeDimensions) {
        attributes.put(attribute.getUid(), attribute);
      }

      if (attributes.containsKey(dimension)) {
        TrackedEntityAttributeDimension tead = attributes.get(dimension);

        return new BaseDimensionalObject(
            dimension,
            DimensionType.TRACKED_ENTITY_ATTRIBUTE,
            null,
            tead.getDisplayName(),
            tead.getLegendSet(),
            tead.getFilter());
      }

      // Tracked entity data element

      Map<String, TrackedEntityDataElementDimension> dataElements = new HashMap<>();

      for (TrackedEntityDataElementDimension dataElement : dataElementDimensions) {
        dataElements.put(dataElement.getUid(), dataElement);
      }

      if (dataElements.containsKey(dimension)) {
        TrackedEntityDataElementDimension tedd = dataElements.get(dimension);

        return new BaseDimensionalObject(
            dimension,
            DimensionType.TRACKED_ENTITY_DATAELEMENT,
            null,
            tedd.getDisplayName(),
            tedd.getLegendSet(),
            tedd.getFilter());
      }
    }

    IdentifiableObjectUtils.removeDuplicates(items);

    return new BaseDimensionalObject(dimension, type, items);
  }
  @Override
  public void setUpTest() {
    // ---------------------------------------------------------------------
    // Services
    // ---------------------------------------------------------------------

    dataIntegrityService = (DataIntegrityService) getBean(DataIntegrityService.ID);
    dataElementService = (DataElementService) getBean(DataElementService.ID);
    indicatorService = (IndicatorService) getBean(IndicatorService.ID);
    dataSetService = (DataSetService) getBean(DataSetService.ID);
    organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);
    organisationUnitGroupService =
        (OrganisationUnitGroupService) getBean(OrganisationUnitGroupService.ID);

    // ---------------------------------------------------------------------
    // Objects
    // ---------------------------------------------------------------------

    elementA = createDataElement('A');
    elementB = createDataElement('B');
    elementC = createDataElement('C');

    dataElementService.addDataElement(elementA);
    dataElementService.addDataElement(elementB);
    dataElementService.addDataElement(elementC);

    indicatorTypeA = createIndicatorType('A');

    indicatorService.addIndicatorType(indicatorTypeA);

    indicatorA = createIndicator('A', indicatorTypeA);
    indicatorB = createIndicator('B', indicatorTypeA);
    indicatorC = createIndicator('C', indicatorTypeA);

    indicatorA.setNumerator(" ");
    indicatorB.setNumerator("Numerator");
    indicatorB.setDenominator("Denominator");
    indicatorC.setNumerator("Numerator");
    indicatorC.setDenominator("Denominator");

    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);

    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitB);
    unitD = createOrganisationUnit('D', unitC);
    unitE = createOrganisationUnit('E', unitD);
    unitF = createOrganisationUnit('F');

    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    organisationUnitService.addOrganisationUnit(unitC);
    organisationUnitService.addOrganisationUnit(unitD);
    organisationUnitService.addOrganisationUnit(unitE);
    organisationUnitService.addOrganisationUnit(unitF);

    unitA.setParent(unitC);

    organisationUnitService.updateOrganisationUnit(unitA);

    dataSetA = createDataSet('A', new MonthlyPeriodType());
    dataSetB = createDataSet('B', new QuarterlyPeriodType());

    dataSetA.getDataElements().add(elementA);
    dataSetA.getDataElements().add(elementB);
    elementA.getDataSets().add(dataSetA);
    elementB.getDataSets().add(dataSetA);

    dataSetA.getSources().add(unitA);
    unitA.getDataSets().add(dataSetA);

    dataSetB.getDataElements().add(elementA);
    elementA.getDataSets().add(dataSetB);

    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);

    // ---------------------------------------------------------------------
    // Groups
    // ---------------------------------------------------------------------

    elementGroupA = createDataElementGroup('A');

    elementGroupA.getMembers().add(elementA);
    elementA.getGroups().add(elementGroupA);

    dataElementService.addDataElementGroup(elementGroupA);

    indicatorGroupA = createIndicatorGroup('A');

    indicatorGroupA.getMembers().add(indicatorA);
    indicatorA.getGroups().add(indicatorGroupA);

    indicatorService.addIndicatorGroup(indicatorGroupA);

    unitGroupA = createOrganisationUnitGroup('A');
    unitGroupB = createOrganisationUnitGroup('B');
    unitGroupC = createOrganisationUnitGroup('C');
    unitGroupD = createOrganisationUnitGroup('D');

    unitGroupA.getMembers().add(unitA);
    unitGroupA.getMembers().add(unitB);
    unitGroupA.getMembers().add(unitC);
    unitA.getGroups().add(unitGroupA);
    unitB.getGroups().add(unitGroupA);
    unitC.getGroups().add(unitGroupA);

    unitGroupB.getMembers().add(unitA);
    unitGroupB.getMembers().add(unitB);
    unitGroupB.getMembers().add(unitF);
    unitA.getGroups().add(unitGroupB);
    unitB.getGroups().add(unitGroupB);
    unitF.getGroups().add(unitGroupB);

    unitGroupC.getMembers().add(unitA);
    unitA.getGroups().add(unitGroupC);

    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupC);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupD);

    // ---------------------------------------------------------------------
    // Group sets
    // ---------------------------------------------------------------------

    unitGroupSetA = createOrganisationUnitGroupSet('A');
    unitGroupSetB = createOrganisationUnitGroupSet('B');

    unitGroupSetA.setCompulsory(true);
    unitGroupSetB.setCompulsory(false);

    unitGroupSetA.getOrganisationUnitGroups().add(unitGroupA);
    unitGroupA.setGroupSet(unitGroupSetA);

    unitGroupSetB.getOrganisationUnitGroups().add(unitGroupB);
    unitGroupSetB.getOrganisationUnitGroups().add(unitGroupC);
    unitGroupB.setGroupSet(unitGroupSetB);
    unitGroupC.setGroupSet(unitGroupSetB);

    organisationUnitGroupService.addOrganisationUnitGroupSet(unitGroupSetA);
    organisationUnitGroupService.addOrganisationUnitGroupSet(unitGroupSetB);
  }
  @Ignore
  @Test
  public void testDeleteAndImportAll() {
    dataElementService.addDataElement(dataElementA);

    dataElementGroupA.getMembers().add(dataElementA);

    dataElementService.addDataElementGroup(dataElementGroupA);

    int importObjectIdA =
        importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementBModified, null);
    int importObjectIdB =
        importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementCModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementDModified, null);

    int importObjectIdC =
        importObjectService.addImportObject(
            ImportObjectStatus.NEW, dataElementGroupBDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementGroupCDuplicate, null);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationF);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationG);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationH);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationJ);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationK);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, dataElementGroupAssociationL);

    dbmsManager.clearSession();

    importObjectService.cascadeDeleteImportObject(importObjectIdA);
    importObjectService.cascadeDeleteImportObject(importObjectIdB);
    importObjectService.cascadeDeleteImportObject(importObjectIdC);

    importObjectService.importAll();

    Collection<DataElement> dataElements = dataElementService.getAllDataElements();

    assertEquals(dataElements.size(), 2);

    assertTrue(dataElements.contains(dataElementA));
    assertTrue(dataElements.contains(dataElementDModified));

    Collection<DataElementGroup> dataElementGroups = dataElementService.getAllDataElementGroups();

    assertEquals(dataElementGroups.size(), 2);

    assertTrue(dataElementGroups.contains(dataElementGroupA));
    assertTrue(dataElementGroups.contains(dataElementGroupCDuplicate));

    for (DataElementGroup dataElementGroup : dataElementGroups) {
      assertEquals(dataElementGroup.getMembers().size(), 1);
    }

    assertEquals(importObjectService.getImportObjects(DataElement.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(DataElementGroup.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(GroupMemberAssociation.class).size(), 0);
  }
  @Override
  public void setUpTest() {
    // ---------------------------------------------------------------------
    // Services
    // ---------------------------------------------------------------------

    importObjectService = (ImportObjectService) getBean(ImportObjectService.ID);

    batchHandlerFactory = (BatchHandlerFactory) getBean("batchHandlerFactory");

    dataElementService = (DataElementService) getBean(DataElementService.ID);

    categoryService = (DataElementCategoryService) getBean(DataElementCategoryService.ID);

    periodService = (PeriodService) getBean(PeriodService.ID);

    organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);

    dataValueService = (DataValueService) getBean(DataValueService.ID);

    // ---------------------------------------------------------------------
    // CategoryOption
    // ---------------------------------------------------------------------

    categoryOptionA = new DataElementCategoryOption("CategoryOptionA");
    categoryOptionB = new DataElementCategoryOption("CategoryOptionB");
    categoryOptionC = new DataElementCategoryOption("CategoryOptionC");
    categoryOptionD = new DataElementCategoryOption("CategoryOptionD");

    categoryService.addDataElementCategoryOption(categoryOptionA);
    categoryService.addDataElementCategoryOption(categoryOptionB);
    categoryService.addDataElementCategoryOption(categoryOptionC);
    categoryService.addDataElementCategoryOption(categoryOptionD);

    categoryOptionADuplicate = new DataElementCategoryOption("CategoryOptionA");
    categoryOptionBDuplicate = new DataElementCategoryOption("CategoryOptionB");
    categoryOptionCDuplicate = new DataElementCategoryOption("CategoryOptionC");
    categoryOptionDDuplicate = new DataElementCategoryOption("CategoryOptionD");

    categoryOptionADuplicate.setId('A');
    categoryOptionBDuplicate.setId('B');
    categoryOptionCDuplicate.setId('C');
    categoryOptionDDuplicate.setId('D');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionBDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionCDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionDDuplicate, null);

    // ---------------------------------------------------------------------
    // Category
    // ---------------------------------------------------------------------

    categoryA = new DataElementCategory("CategoryA");
    categoryB = new DataElementCategory("CategoryB");

    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);

    categoryService.addDataElementCategory(categoryA);
    categoryService.addDataElementCategory(categoryB);

    categoryADuplicate = new DataElementCategory("CategoryA");
    categoryBDuplicate = new DataElementCategory("CategoryB");

    categoryADuplicate.setId('A');
    categoryBDuplicate.setId('B');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryBDuplicate, null);

    // ---------------------------------------------------------------------
    // Category - CategoryOption Association
    // ---------------------------------------------------------------------

    categoryCategoryOptionAssociationA = new GroupMemberAssociation('A', 'A', 1);
    categoryCategoryOptionAssociationB = new GroupMemberAssociation('A', 'B', 2);
    categoryCategoryOptionAssociationC = new GroupMemberAssociation('B', 'C', 1);
    categoryCategoryOptionAssociationD = new GroupMemberAssociation('B', 'D', 2);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationA);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationB);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationC);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationD);

    // ---------------------------------------------------------------------
    // CategoryCombo
    // ---------------------------------------------------------------------

    categoryComboA = new DataElementCategoryCombo("CategoryComboA");
    categoryComboB = new DataElementCategoryCombo("CategoryComboB");

    categoryComboA.getCategories().add(categoryA);
    categoryComboA.getCategories().add(categoryB);
    categoryComboB.getCategories().add(categoryA);

    categoryService.addDataElementCategoryCombo(categoryComboA);
    categoryService.addDataElementCategoryCombo(categoryComboB);

    categoryComboADuplicate = new DataElementCategoryCombo("CategoryComboA");
    categoryComboBDuplicate = new DataElementCategoryCombo("CategoryComboB");

    categoryComboADuplicate.setId('A');
    categoryComboBDuplicate.setId('B');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryComboADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryComboBDuplicate, null);

    // ---------------------------------------------------------------------
    // CategoryCombo - Category Association
    // ---------------------------------------------------------------------

    categoryComboCategoryAssociationA = new GroupMemberAssociation('A', 'A', 1);
    categoryComboCategoryAssociationB = new GroupMemberAssociation('A', 'B', 2);
    categoryComboCategoryAssociationC = new GroupMemberAssociation('B', 'A', 1);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationA);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationB);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationC);

    // ---------------------------------------------------------------------
    // CategoryOptionCombo
    // ---------------------------------------------------------------------

    categoryOptionComboA = new DataElementCategoryOptionCombo();
    categoryOptionComboB = new DataElementCategoryOptionCombo();
    categoryOptionComboC = new DataElementCategoryOptionCombo();
    categoryOptionComboD = new DataElementCategoryOptionCombo();

    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryOptionComboB.setCategoryCombo(categoryComboA);
    categoryOptionComboC.setCategoryCombo(categoryComboB);
    categoryOptionComboD.setCategoryCombo(categoryComboB);

    categoryOptionComboA.getCategoryOptions().add(categoryOptionA);
    categoryOptionComboA.getCategoryOptions().add(categoryOptionC);
    categoryOptionComboB.getCategoryOptions().add(categoryOptionB);
    categoryOptionComboB.getCategoryOptions().add(categoryOptionD);
    categoryOptionComboC.getCategoryOptions().add(categoryOptionA);
    categoryOptionComboD.getCategoryOptions().add(categoryOptionB);

    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboB);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboC);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboD);

    categoryOptionComboADuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboBDuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboCDuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboDDuplicate = new DataElementCategoryOptionCombo();

    categoryOptionComboADuplicate.setId('A');
    categoryOptionComboBDuplicate.setId('B');
    categoryOptionComboCDuplicate.setId('C');
    categoryOptionComboDDuplicate.setId('D');

    categoryOptionComboADuplicate.setCategoryCombo(categoryComboADuplicate);
    categoryOptionComboBDuplicate.setCategoryCombo(categoryComboADuplicate);
    categoryOptionComboCDuplicate.setCategoryCombo(categoryComboBDuplicate);
    categoryOptionComboDDuplicate.setCategoryCombo(categoryComboBDuplicate);

    categoryOptionComboADuplicate.getCategoryOptions().add(categoryOptionADuplicate);
    categoryOptionComboADuplicate.getCategoryOptions().add(categoryOptionCDuplicate);
    categoryOptionComboBDuplicate.getCategoryOptions().add(categoryOptionBDuplicate);
    categoryOptionComboBDuplicate.getCategoryOptions().add(categoryOptionDDuplicate);
    categoryOptionComboCDuplicate.getCategoryOptions().add(categoryOptionADuplicate);
    categoryOptionComboDDuplicate.getCategoryOptions().add(categoryOptionBDuplicate);

    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboADuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboBDuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboCDuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboDDuplicate, null);

    // ---------------------------------------------------------------------
    // DataElement
    // ---------------------------------------------------------------------

    dataElementA = createDataElement('A', categoryComboA);
    dataElementB = createDataElement('B', categoryComboA);
    dataElementC = createDataElement('C', categoryComboA);
    dataElementD = createDataElement('D', categoryComboA);

    dataElementAModified = createDataElement('A', categoryComboADuplicate);
    dataElementBModified = createDataElement('B', categoryComboADuplicate);
    dataElementCModified = createDataElement('C', categoryComboADuplicate);
    dataElementDModified = createDataElement('D', categoryComboADuplicate);

    dataElementAModified.setId('A');
    dataElementBModified.setId('B');
    dataElementCModified.setId('C');
    dataElementDModified.setId('D');

    dataElementAModified.setShortName("ShortNameModifiedA");
    dataElementBModified.setShortName("ShortNameModifiedB");
    dataElementCModified.setShortName("ShortNameModifiedC");
    dataElementDModified.setShortName("ShortNameModifiedD");

    // ---------------------------------------------------------------------
    // DataElementGroup
    // ---------------------------------------------------------------------

    dataElementGroupA = createDataElementGroup('A');
    dataElementGroupB = createDataElementGroup('B');
    dataElementGroupC = createDataElementGroup('C');

    dataElementGroupADuplicate = createDataElementGroup('A');
    dataElementGroupBDuplicate = createDataElementGroup('B');
    dataElementGroupCDuplicate = createDataElementGroup('C');

    dataElementGroupADuplicate.setId('A');
    dataElementGroupBDuplicate.setId('B');
    dataElementGroupCDuplicate.setId('C');

    dataElementGroupAssociationA = new GroupMemberAssociation('A', 'A');
    dataElementGroupAssociationB = new GroupMemberAssociation('A', 'B');
    dataElementGroupAssociationC = new GroupMemberAssociation('A', 'C');
    dataElementGroupAssociationD = new GroupMemberAssociation('A', 'D');
    dataElementGroupAssociationE = new GroupMemberAssociation('B', 'A');
    dataElementGroupAssociationF = new GroupMemberAssociation('B', 'B');
    dataElementGroupAssociationG = new GroupMemberAssociation('B', 'C');
    dataElementGroupAssociationH = new GroupMemberAssociation('B', 'D');
    dataElementGroupAssociationI = new GroupMemberAssociation('C', 'A');
    dataElementGroupAssociationJ = new GroupMemberAssociation('C', 'B');
    dataElementGroupAssociationK = new GroupMemberAssociation('C', 'C');
    dataElementGroupAssociationL = new GroupMemberAssociation('C', 'D');

    // ---------------------------------------------------------------------
    // Period
    // ---------------------------------------------------------------------

    periodTypeA = periodService.getPeriodTypeByName(MonthlyPeriodType.NAME);

    periodA = createPeriod(periodTypeA, getDate(1, 0, 2000), getDate(31, 0, 2000));

    periodADuplicate = createPeriod(periodTypeA, getDate(1, 0, 2000), getDate(31, 0, 2000));

    periodADuplicate.setId('A');

    // ---------------------------------------------------------------------
    // OrganisationUnit
    // ---------------------------------------------------------------------

    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    organisationUnitC = createOrganisationUnit('C');

    organisationUnitAModified = createOrganisationUnit('A');
    organisationUnitBModified = createOrganisationUnit('B');
    organisationUnitCModified = createOrganisationUnit('C');

    organisationUnitAModified.setId('A');
    organisationUnitBModified.setId('B');
    organisationUnitCModified.setId('C');

    organisationUnitAModified.setShortName("ShortNameModifiedA");
    organisationUnitBModified.setShortName("ShortNameModifiedB");
    organisationUnitCModified.setShortName("ShortNameModifiedC");

    // ---------------------------------------------------------------------
    // RelationshipAssociation
    // ---------------------------------------------------------------------

    relationshipAssociationA = new GroupMemberAssociation('A', 'B');
    relationshipAssociationB = new GroupMemberAssociation('B', 'C');

    // ---------------------------------------------------------------------
    // DataValue
    // ---------------------------------------------------------------------

    dataValueA =
        createDataValue(dataElementA, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueB =
        createDataValue(dataElementA, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueC =
        createDataValue(dataElementA, periodA, organisationUnitC, "10", categoryOptionComboA);
    dataValueD =
        createDataValue(dataElementB, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueE =
        createDataValue(dataElementB, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueF =
        createDataValue(dataElementB, periodA, organisationUnitC, "10", categoryOptionComboA);
    dataValueG =
        createDataValue(dataElementC, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueH =
        createDataValue(dataElementC, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueI =
        createDataValue(dataElementC, periodA, organisationUnitC, "10", categoryOptionComboA);

    dataValueADuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueBDuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueCDuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueDDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueEDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueFDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueGDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueHDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueIDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
  }
  @Transactional
  public void matchObject(int importObjectId, int existingObjectId) {
    ImportObject importObject = importObjectStore.getImportObject(importObjectId);

    Object object = importObject.getObject();

    // ---------------------------------------------------------------------
    // Updates the name of the import object to the name of the existing
    // object.
    // ---------------------------------------------------------------------

    if (object.getClass().equals(DataElement.class)) {
      DataElement element = (DataElement) object;

      element.setName(dataElementService.getDataElement(existingObjectId).getName());
    } else if (object.getClass().equals(DataElementGroup.class)) {
      DataElementGroup group = (DataElementGroup) object;

      group.setName(dataElementService.getDataElementGroup(existingObjectId).getName());
    } else if (object.getClass().equals(DataElementGroupSet.class)) {
      DataElementGroupSet groupSet = (DataElementGroupSet) object;

      groupSet.setName(dataElementService.getDataElementGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorType.class)) {
      IndicatorType type = (IndicatorType) object;

      type.setName(indicatorService.getIndicatorType(existingObjectId).getName());
    } else if (object.getClass().equals(Indicator.class)) {
      Indicator indicator = (Indicator) object;

      indicator.setName(indicatorService.getIndicator(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorGroup.class)) {
      IndicatorGroup group = (IndicatorGroup) object;

      group.setName(indicatorService.getIndicatorGroup(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorGroupSet.class)) {
      IndicatorGroupSet groupSet = (IndicatorGroupSet) object;

      groupSet.setName(indicatorService.getIndicatorGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(DataDictionary.class)) {
      DataDictionary dictionary = (DataDictionary) object;

      dictionary.setName(dataDictionaryService.getDataDictionary(existingObjectId).getName());
    } else if (object.getClass().equals(DataSet.class)) {
      DataSet dataSet = (DataSet) object;

      dataSet.setName(dataSetService.getDataSet(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnit.class)) {
      OrganisationUnit unit = (OrganisationUnit) object;

      unit.setName(organisationUnitService.getOrganisationUnit(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitGroup.class)) {
      OrganisationUnitGroup group = (OrganisationUnitGroup) object;

      group.setName(
          organisationUnitGroupService.getOrganisationUnitGroup(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitGroupSet.class)) {
      OrganisationUnitGroupSet groupSet = (OrganisationUnitGroupSet) object;

      groupSet.setName(
          organisationUnitGroupService.getOrganisationUnitGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitLevel.class)) {
      OrganisationUnitLevel level = (OrganisationUnitLevel) object;

      level.setName(organisationUnitService.getOrganisationUnitLevel(existingObjectId).getName());
    } else if (object.getClass().equals(ValidationRule.class)) {
      ValidationRule validationRule = (ValidationRule) object;

      validationRule.setName(validationRuleService.getValidationRule(existingObjectId).getName());
    } else if (object.getClass().equals(Report.class)) {
      Report report = (Report) object;

      report.setName(reportService.getReport(existingObjectId).getName());
    } else if (object.getClass().equals(ReportTable.class)) {
      ReportTable reportTable = (ReportTable) object;

      reportTable.setName(reportTableService.getReportTable(existingObjectId).getName());
    } else if (object.getClass().equals(Chart.class)) {
      Chart chart = (Chart) object;

      chart.setName(chartService.getChart(existingObjectId).getName());
    } else if (object.getClass().equals(DataValue.class)) {
      DataValue dataValue = (DataValue) object;

      dataValue =
          updateDataValue(
              dataValue,
              dataValueService.getDataValue(
                  dataValue.getSource(),
                  dataValue.getDataElement(),
                  dataValue.getPeriod(),
                  dataValue.getOptionCombo()));
    }

    // ---------------------------------------------------------------------
    // Sets the status of the import object to match, these objects will
    // later be ignored on import all but is needed for matching of
    // associations.
    // ---------------------------------------------------------------------

    importObject.setStatus(ImportObjectStatus.MATCH);

    importObjectStore.updateImportObject(importObject);
  }
  @Transactional
  public void cascadeDeleteImportObject(int importObjectId) {
    ImportObject importObject = importObjectStore.getImportObject(importObjectId);

    if (importObject != null) {
      if (importObject.getClassName().equals(DataElement.class.getName())) {
        DataElement element = (DataElement) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.DATAELEMENTGROUP, element.getId());
        deleteMemberAssociations(GroupMemberType.DATASET, element.getId());
        deleteMemberAssociations(GroupMemberType.DATADICTIONARY_DATAELEMENT, element.getId());

        deleteIndicatorsContainingDataElement(element.getId());

        importDataValueService.deleteImportDataValuesByDataElement(element.getId());
      } else if (importObject.getClassName().equals(DataElementGroup.class.getName())) {
        DataElementGroup group = (DataElementGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATAELEMENTGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.DATAELEMENTGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(DataElementGroupSet.class.getName())) {
        DataElementGroupSet groupSet = (DataElementGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATAELEMENTGROUPSET, groupSet.getId());
      } else if (importObject.getClassName().equals(IndicatorType.class.getName())) {
        IndicatorType type = (IndicatorType) importObject.getObject();

        deleteIndicatorsWithIndicatorType(type.getId());
      } else if (importObject.getClassName().equals(Indicator.class.getName())) {
        Indicator indicator = (Indicator) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.INDICATORGROUP, indicator.getId());
        deleteMemberAssociations(GroupMemberType.DATADICTIONARY_INDICATOR, indicator.getId());
      } else if (importObject.getClassName().equals(IndicatorGroup.class.getName())) {
        IndicatorGroup group = (IndicatorGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.INDICATORGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.INDICATORGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(IndicatorGroupSet.class.getName())) {
        IndicatorGroupSet groupSet = (IndicatorGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.INDICATORGROUPSET, groupSet.getId());
      } else if (importObject.getClassName().equals(DataDictionary.class.getName())) {
        DataDictionary dictionary = (DataDictionary) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATADICTIONARY_DATAELEMENT, dictionary.getId());
        deleteGroupAssociations(GroupMemberType.DATADICTIONARY_INDICATOR, dictionary.getId());
      } else if (importObject.getClassName().equals(DataSet.class.getName())) {
        DataSet dataSet = (DataSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATASET, dataSet.getId());
        deleteMemberAssociations(GroupMemberType.DATASET_SOURCE, dataSet.getId());

        deleteCompleteDataSetRegistrationsByDataSet(dataSet.getId());
      } else if (importObject.getClassName().equals(OrganisationUnit.class.getName())) {
        OrganisationUnit unit = (OrganisationUnit) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITGROUP, unit.getId());
        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITRELATIONSHIP, unit.getId());
        deleteMemberAssociations(GroupMemberType.DATASET_SOURCE, unit.getId());
        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITRELATIONSHIP, unit.getId());

        deleteCompleteDataSetRegistrationsBySource(unit.getId());

        importDataValueService.deleteImportDataValuesBySource(unit.getId());
      } else if (importObject.getClassName().equals(OrganisationUnitGroup.class.getName())) {
        OrganisationUnitGroup group = (OrganisationUnitGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(OrganisationUnitGroupSet.class.getName())) {
        OrganisationUnitGroupSet groupSet = (OrganisationUnitGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITGROUPSET, groupSet.getId());
      }
    }

    deleteImportObject(importObjectId);
  }