@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));
  }
  @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);
  }
Esempio n. 3
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();
 }