public String execute() throws Exception {
    if (id == null || id == ALL) {
      indicators = new ArrayList<Indicator>(indicatorService.getAllIndicators());
    } else {
      IndicatorGroup indicatorGroup = indicatorService.getIndicatorGroup(id);

      if (indicatorGroup != null) {
        indicators = new ArrayList<Indicator>(indicatorGroup.getMembers());
      } else {
        indicators = new ArrayList<Indicator>();
      }
    }

    // To Filter the indicators that are assigned to any survey
    /*
    if( surveyflag != null && surveyflag.equalsIgnoreCase( "yes" ) )
    {
        List<Indicator> surveyIndicators = new ArrayList<Indicator>( surveyService.getAllSurveyIndicators() );

        indicators.retainAll( surveyIndicators );
    }
    System.out.println( "id = "+id + " indicator size = "+ indicators.size() );
    */

    // filter all the indicators which have not any survey
    if (surveyExist != null && surveyExist.equalsIgnoreCase("yes")) {
      System.out.println("surveyExist" + surveyExist);
      Iterator<Indicator> allIndicatorIterator = indicators.iterator();
      while (allIndicatorIterator.hasNext()) {
        Indicator indicator = allIndicatorIterator.next();
        Collection<Survey> surveyList = surveyService.getSurveysByIndicator(indicator);
        // surveyList = surveyService.getSurveysByIndicator( indicator );

        if (surveyList == null || surveyList.size() <= 0) {
          allIndicatorIterator.remove();
        }
      }
    }

    System.out.println("id = " + id + " indicator final size = " + indicators.size());

    Collections.sort(indicators, indicatorComparator);

    // displayPropertyHandler.handle( indicators );

    return SUCCESS;
  }
Ejemplo n.º 2
0
  @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);
  }