@Test
  public void testObjectExists() {
    indicatorService.addIndicatorGroupSet(groupSetA);

    assertTrue(batchHandler.objectExists(groupSetA));

    assertFalse(batchHandler.objectExists(groupSetB));
  }
  @Test
  public void testInsertObject() {
    int idA = batchHandler.insertObject(groupSetA, true);
    int idB = batchHandler.insertObject(groupSetB, true);
    int idC = batchHandler.insertObject(groupSetC, true);

    assertNotNull(indicatorService.getIndicatorGroupSet(idA));
    assertNotNull(indicatorService.getIndicatorGroupSet(idB));
    assertNotNull(indicatorService.getIndicatorGroupSet(idC));
  }
  @Test
  public void testUpdateObject() {
    int id = batchHandler.insertObject(groupSetA, true);

    groupSetA.setId(id);
    groupSetA.setName("UpdatedName");

    batchHandler.updateObject(groupSetA);

    assertEquals("UpdatedName", indicatorService.getIndicatorGroupSet(id).getName());
  }
  @Test
  public void testAddObject() {
    batchHandler.addObject(groupSetA);
    batchHandler.addObject(groupSetB);
    batchHandler.addObject(groupSetC);

    batchHandler.flush();

    Collection<IndicatorGroupSet> groupSets = indicatorService.getAllIndicatorGroupSets();

    assertTrue(groupSets.contains(groupSetA));
    assertTrue(groupSets.contains(groupSetB));
    assertTrue(groupSets.contains(groupSetC));
  }
  @Test
  public void testGetObjectIdentifier() {
    int referenceId = indicatorService.addIndicatorGroupSet(groupSetA);

    int retrievedId = batchHandler.getObjectIdentifier("IndicatorGroupSetA");

    assertEquals(referenceId, retrievedId);
  }
  @Override
  public void setUpTest() {
    indicatorService = (IndicatorService) getBean(IndicatorService.ID);

    batchHandler = batchHandlerFactory.createBatchHandler(IndicatorGroupSetBatchHandler.class);

    batchHandler.init();

    groupSetA = createIndicatorGroupSet('A');
    groupSetB = createIndicatorGroupSet('B');
    groupSetC = createIndicatorGroupSet('C');
  }
  @Ignore
  @Test
  public void testImportDataValueImportAll() {
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementAModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementBModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, dataElementCModified, null);

    importObjectService.addImportObject(ImportObjectStatus.NEW, periodADuplicate, null);

    importObjectService.addImportObject(ImportObjectStatus.NEW, organisationUnitAModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, organisationUnitBModified, null);
    importObjectService.addImportObject(ImportObjectStatus.NEW, organisationUnitCModified, null);

    BatchHandler<ImportDataValue> batchHandler =
        batchHandlerFactory.createBatchHandler(ImportDataValueBatchHandler.class);

    batchHandler.init();

    batchHandler.addObject(new ImportDataValue(dataValueADuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueBDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueCDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueDDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueEDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueFDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueGDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueHDuplicate, ImportObjectStatus.NEW));
    batchHandler.addObject(new ImportDataValue(dataValueIDuplicate, ImportObjectStatus.NEW));

    batchHandler.flush();

    dbmsManager.clearSession();

    importObjectService.importAll();

    assertEquals(dataElementService.getAllDataElements().size(), 3);

    assertEquals(periodService.getPeriodsByPeriodType(periodTypeA).size(), 1);

    assertEquals(organisationUnitService.getAllOrganisationUnits().size(), 3);

    assertEquals(dataValueService.getAllDataValues().size(), 9);

    assertEquals(importObjectService.getImportObjects(DataElement.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(Period.class).size(), 0);
    assertEquals(importObjectService.getImportObjects(OrganisationUnit.class).size(), 0);
  }
Example #8
0
  @Override
  public void execute() {
    executeSql("update mapview set valuetype=mapvaluetype where valuetype is null");
    executeSql("update mapview set legendtype=maplegendtype where legendtype is null");
    executeSql("update mapview set legendsetid=maplegendsetid where legendsetid is null");

    executeSql("alter table mapview drop column mapvaluetype");
    executeSql("alter table mapview drop column maplegendtype");
    executeSql("alter table mapview drop column maplegendsetid");

    executeSql("alter table mapview drop column bounds");
    executeSql("alter table mapview drop column code");
    executeSql("alter table mapview drop column periodtypeid");

    executeSql("update mapview set layer='thematic1' where layer is null");
    executeSql("update mapview set valuetype='dataElement' where valuetype='dataelement'");
    executeSql("alter table mapview alter column opacity type double precision");

    String sql =
        "select mapviewid, name, userid, longitude, latitude, zoom from mapview where mapviewid not in ("
            + "select mapviewid from mapmapviews)";

    BatchHandler<Map> batchHandler =
        batchHandlerFactory.createBatchHandler(MapBatchHandler.class).init();

    try {
      ResultSet rs = statementManager.getHolder().getStatement().executeQuery(sql);

      while (rs.next()) {
        log.info("Upgrading map view...");

        User user = null;
        int userId = rs.getInt("userid");
        int mapViewId = rs.getInt("mapviewid");

        if (userId != 0) {
          user = new User();
          user.setId(userId);
        }

        String uid = CodeGenerator.generateCode();

        Map map =
            new Map(
                rs.getString("name"),
                user,
                rs.getDouble("longitude"),
                rs.getDouble("latitude"),
                rs.getInt("zoom"));
        map.setUid(uid);

        int mapId = batchHandler.insertObject(map, true);

        statementManager
            .getHolder()
            .executeUpdate(
                "insert into mapmapviews (mapid,mapviewid,sort_order) values("
                    + mapId
                    + ","
                    + mapViewId
                    + ",0);");

        log.info("Upgraded map view: " + map);
      }
    } catch (Exception ex) {
      log.debug("Error", ex);
      return;
    } finally {
      batchHandler.flush();
    }

    executeSql("alter table mapview drop column name");
    executeSql("alter table mapview drop column userid");
    executeSql("alter table mapview drop column longitude");
    executeSql("alter table mapview drop column latitude");
    executeSql("alter table mapview drop column zoom");
  }
 @Override
 public void tearDownTest() {
   batchHandler.flush();
 }