/**
   * Parses the allocation scenario test.
   *
   * @throws Exception the exception
   */
  @Test(
      enabled = true,
      groups = {"demand", "database", "couchdb"})
  public void parseAllocationScenarioTest() throws Exception {

    AllocationScenario allocationScenario =
        allocationScenarioDao.findAllocationScenarioById(WifKeys.TEST_ALLOCATION_SCENARIO_ID);
    WifProject project = wifProjectDao.findProjectById(allocationScenario.getProjectId());
    SuitabilityScenario suitabilityScenario =
        suitabilityScenarioDao.findSuitabilityScenarioById(
            allocationScenario.getSuitabilityScenarioId());
    Assert.assertNotNull(suitabilityScenario);
    DemandConfig demandConfig = demandConfigDao.findDemandConfigById(project.getDemandConfigId());
    Assert.assertNotNull(demandConfig);

    DemandScenario demandScenario =
        demandScenarioDao.findDemandScenarioById(allocationScenario.getDemandScenarioId());
    Assert.assertNotNull(demandScenario);

    // Parsing components
    project = projectParser.parse(project);
    suitabilityScenario = suitabilityParser.parseSuitabilityScenario(suitabilityScenario, project);
    demandConfig = demandSetupParser.parse(demandConfig, project);
    demandScenario = demandScenarioParser.parse(demandScenario, demandConfig, project);
    demandScenario = demandScenarioParser.parseAreaRequirements(demandScenario);
    allocationScenario.setDemandScenario(demandScenario);
    allocationScenario = allocationParser.parse(allocationScenario, project);
    // Checking mapping

    String AllocationConfigsId = project.getAllocationConfigsId();

    LOGGER.info("getting the AllocationConfig with ID={}", AllocationConfigsId);
    AllocationConfigs allocationConfig =
        AllocationConfigsDao.findAllocationConfigsById(AllocationConfigsId);

    Assert.assertNotNull(allocationScenario.getLandUseOrderMap());
    Assert.assertNotNull(allocationConfig.getAllocationColumnsMap());
    // Checking allocationLU associations
    AllocationLU resLU = project.getExistingLandUseByLabel("Low Density Res.");
    Assert.assertNotNull(resLU.getAllocationFeatureFieldName());
    Assert.assertNotEquals(resLU.getAreaRequirements().size(), 0);
  }
Exemplo n.º 2
0
  public AllocationSimpleAnalysisReport getAllocationSimpleAnalysisReport(
      final AllocationScenario allocationScenario)
      throws WifInvalidInputException, WifInvalidConfigException, ParsingException {
    LOGGER.info("getAllocationSimpleAnalysisReport for: {}", allocationScenario.getLabel());
    final AllocationSimpleAnalysisReport allocationSimpleAnalysisReport =
        new AllocationSimpleAnalysisReport();

    // final WifProject project = allocationScenario.getWifProject();

    final String projectId = allocationScenario.getProjectId();
    final WifProject project = projectService.getProject(projectId);

    final String AllocationConfigsId = project.getAllocationConfigsId();

    final AllocationConfigs allocationConfig =
        AllocationConfigsDao.findAllocationConfigsById(AllocationConfigsId);

    allocationSimpleAnalysisReport.setReportType(allocationScenario.getDocType());
    allocationSimpleAnalysisReport.setLabel(project.getName());
    allocationSimpleAnalysisReport.setScenarioLabel(allocationScenario.getDocType());
    allocationSimpleAnalysisReport.setProjectId(allocationScenario.getProjectId());

    final Set<AllocationSimpleItemReport> setallocationSimpleItemReport =
        new HashSet<AllocationSimpleItemReport>();

    // Getting land use information
    // LOGGER.info("Getting land use information: {}");
    final DemandConfig demandConfig = demandConfigService.getDemandConfig(projectId);
    // LOGGER.info("Associated manualdemandConfigId: {}",
    // manualdemandConfig.getId());
    final TreeSet<Projection> projections = new TreeSet<Projection>(new YearComparator());
    projections.addAll(demandConfig.getProjections());
    final Projection current = projections.first();
    LOGGER.debug("current year projection: {}", current.getLabel());
    // setting up taking into account current projection year is not a
    // projection by itself,per se,
    // NavigableSet<Projection> projectedSet = projections.tailSet(
    // projections.first(), false);
    final Set<AllocationLU> allocationLandUses = project.getAllocationLandUses();
    for (final AllocationLU allocationLU : allocationLandUses) {
      if (allocationLU.getLabel() == null) {
        LOGGER.warn("Not performing analysis for null label for LU: {}", allocationLU.getId());
        continue;
      }
      for (final Projection projection : projections) {
        LOGGER.debug("getAreaByLU for: {}, id {}", allocationLU.getLabel(), allocationLU.getId());
        final String allocationFFName =
            allocationConfig.getAllocationColumnsMap().get(projection.getLabel());

        final Double areaByLU =
            geodataFinder.getAreaByLUNew(
                project.getSuitabilityConfig().getUnifiedAreaZone(),
                project.getAreaLabel(),
                allocationFFName,
                WifKeys.FUTURELU_PREFIX + allocationLU.getFeatureFieldName());

        final AllocationSimpleItemReport allocationSimpleItemReport =
            new AllocationSimpleItemReport();
        allocationSimpleItemReport.setLanduseName(allocationLU.getLabel());
        if (areaByLU == null) {
          allocationSimpleItemReport.setSumofArea(0.0);
        } else {
          allocationSimpleItemReport.setSumofArea(areaByLU);
        }

        allocationSimpleItemReport.setYear(projection.getYear());

        setallocationSimpleItemReport.add(allocationSimpleItemReport);
      }
    }
    allocationSimpleAnalysisReport.setAllocationSimpleItemReport(setallocationSimpleItemReport);
    LOGGER.info(
        "Finished allocationAnalysisReport for: {}", allocationSimpleAnalysisReport.getProjectId());
    return allocationSimpleAnalysisReport;
  }