Changeset 19680 in main


Ignore:
Timestamp:
12/31/19 13:02:06 (3 months ago)
Author:
GarthBraithwaite_STG
Message:

java - Changed dim1or2 processing for the EditIndicatorViewRecordsController?.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ibisph/src/main/java/org/ibisph/indicatorprofile/springmvc/databean/EditIndicatorViewRecordsController.java

    r19676 r19680  
    463463      String datasetName = datasetToIndicatorView.getDatasetName();
    464464
    465       int dimension1Found = 0;
    466       int dimension2Found = 0;
    467       int periodDimensionFound = 0;
    468       HashSet<String> dimension1or2Names = new HashSet<String>();
     465      String dimension1Name = null;
     466      String dimension2Name = null;
     467      String periodDimensionName = null;
     468      HashSet<String> dimension1or2NameSet = new HashSet<String>();
    469469
    470470      // loop all of that dataset's dimension usages. 
     
    475475
    476476        if(null != indicatorViewDimensionUsage) {
    477           if(dimensionName.equals(categoryDimensionName) && DimensionToIndicatorView.CATEGORY_USAGE.equals(indicatorViewDimensionUsage)) {
    478             if(dimensionToDataset.isDimension1()) {
    479               datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    480               dimension1Found++;
    481             }
    482             else if(dimensionToDataset.isPeriod()) {
    483               datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    484               periodDimensionFound++;
    485             }
    486             else if(dimensionToDataset.isDimension1or2()) {
    487               dimension1or2Names.add(dimensionName);
    488             }
    489             else if(dimensionToDataset.isDimension2()) {
    490               datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    491               dimension2Found++;
    492             }
     477          if(  (dimensionName.equals(categoryDimensionName) && DimensionToIndicatorView.CATEGORY_USAGE.equals(indicatorViewDimensionUsage))
     478            || (dimensionName.equals(seriesDimensionName)   && DimensionToIndicatorView.SERIES_USAGE.equals(indicatorViewDimensionUsage))
     479            || (dimensionName.equals(constantDimensionName) && DimensionToIndicatorView.CONSTANT_USAGE.equals(indicatorViewDimensionUsage))
     480          ) {
     481            if(     dimensionToDataset.isDimension1() && !StrLib.isSomething(dimension1Name)) dimension1Name  = dimensionName;
     482            else if(dimensionToDataset.isDimension2() && !StrLib.isSomething(dimension2Name)) dimension2Name  = dimensionName;
     483            else if(dimensionToDataset.isPeriod()     && !StrLib.isSomething(periodDimensionName)) periodDimensionName = dimensionName;
     484            else if(dimensionToDataset.isDimension1() || dimensionToDataset.isDimension2()) dimension1or2NameSet.add(dimensionName);
     485
     486            // did have code to set the dims and return when matched. Looping
     487            // all the dataset's dimensionToDataset is quick and then all the
     488            // testing code can be put after where the dim1or2 processing can
     489            // be done at the same time.
    493490          }
    494  
    495           else if(dimensionName.equals(seriesDimensionName) && DimensionToIndicatorView.SERIES_USAGE.equals(indicatorViewDimensionUsage)) {
    496             if(dimensionToDataset.isDimension2()) {
    497               datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    498               dimension2Found++;
    499             }
    500             else if(dimensionToDataset.isDimension1or2()) {
    501               dimension1or2Names.add(dimensionName);
    502             }
    503             else if(dimensionToDataset.isDimension1()) {
    504               datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    505               dimension1Found++;
    506             }
    507             else if(dimensionToDataset.isPeriod()) {
    508               datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    509               periodDimensionFound++;
    510             }
     491        }
     492      } // dataset's dimensionToDataset loop
     493
     494      // if the period dim found then try and process
     495      if(StrLib.isSomething(periodDimensionName)) {
     496
     497        // if dim1or2s then check to see where fits.
     498        if(0 < dimension1or2NameSet.size()) {
     499          String[] dimension1or2Names = dimension1or2NameSet.toArray(new String[0]);
     500          if( (2 == dimension1or2NameSet.size()) && !StrLib.isSomething(dimension1Name) && !StrLib.isSomething(dimension2Name)) {
     501            dimension1Name = dimension1or2Names[0];
     502            dimension2Name = dimension1or2Names[1];
    511503          }
    512          
    513           else if(dimensionName.equals(constantDimensionName) && DimensionToIndicatorView.CONSTANT_USAGE.equals(indicatorViewDimensionUsage)) {
    514             if(dimensionToDataset.isPeriod()) {
    515               datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    516               periodDimensionFound++;
    517             }
    518             else if(dimensionToDataset.isDimension1()) {
    519               datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    520               dimension1Found++;
    521             }
    522             else if(dimensionToDataset.isDimension2()) {
    523               datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    524               dimension2Found++;
    525             }
    526             else if(dimensionToDataset.isDimension1or2()) {
    527               dimension1or2Names.add(dimensionName);
    528             }
     504          else if((1 == dimension1or2NameSet.size()) && !StrLib.isSomething(dimension1Name))
     505            dimension1Name = dimension1or2Names[0];
     506          else if((1 == dimension1or2NameSet.size()) && !StrLib.isSomething(dimension2Name))
     507            dimension2Name = dimension1or2Names[0];
     508
     509          // if here then there was a problem with things matching - throw
     510          else {
     511            throw new Exception("Could not determine the dimension 1or2 usage(s) combinations for this view.  These data will need to be edited using the Dataset Record Edit interface.  Dim1or2 Count: "
     512              + dimension1or2NameSet.size()
     513              + ", category: " + categoryDimensionName
     514              + ", series: " + seriesDimensionName
     515              + ", constant: " + constantDimensionName
     516              + ", period: " + periodDimensionName
     517              + ", dimension1: " + dimension1Name
     518              + ", dimension2: " + dimension2Name
     519            );
    529520          }
    530 
    531           // return the first record that matches everything.
    532           if((!testDimension2Name && (0 == dimension2Found) && (1 == dimension1Found) && (1 == periodDimensionFound))
    533             ||(testDimension2Name && (1 == dimension2Found) && (1 == dimension1Found) && (1 == periodDimensionFound))
    534           ) {
    535             datasetRecord.setFieldValue("DATASET_NAME", datasetName);
    536             return(datasetRecord);
    537           }
    538         }
    539       }
    540 
    541       // if here then need to check dim1or2s before throwing error.  Log some
    542       // warnings if there are abnormal counts.
    543       if(1 < dimension1Found) logger.warn(".getBaseDatasetRecord - [" + dimension1Found + "] dimension 1s found for dataset name: " + datasetName);
    544       if(1 < dimension2Found) logger.warn(".getBaseDatasetRecord - [" + dimension2Found + "] dimension 2s found for dataset name: " + datasetName);
    545       if(1 < periodDimensionFound) logger.warn(".getBaseDatasetRecord - [" + periodDimensionFound + "] period dimensions found for dataset name: " + datasetName);
    546 
    547       // now that all possible dim 1, 2, period have been explicitly tested in
    548       // the main loop if multiple dim1or2s try and fit those values into the
    549       // record.  Rules could get crazy but simple works IF the data are
    550       // consistently or initially edited via the view record edit interface.
    551 
    552       // Loop all dim1or2 namaes.
    553       if((0 < dimension1or2Names.size()) && (1 == periodDimensionFound)) {
    554         for(String dimension1or2Name : dimension1or2Names) {
    555 
    556           // if the name doesn't match the record's dim1 or dim2 from main loop
    557           // then put the value into the first available dimension.
    558           if(!dimension1or2Name.equals(datasetRecord.getDimension1Name())
    559             && !dimension1or2Name.equals(datasetRecord.getDimension2Name())
    560           ) {
    561             if(!StrLib.isSomething(datasetRecord.getDimension1Name()))
    562               datasetRecord.setFieldValue("DIMENSION_1_NAME", dimension1or2Name);
    563             else if(!StrLib.isSomething(datasetRecord.getDimension2Name()) && testDimension2Name)
    564               datasetRecord.setFieldValue("DIMENSION_2_NAME", dimension1or2Name);
    565           }
    566 
    567           // return if the record matches everything.  Period must alreay exist.
    568           if(StrLib.isSomething(datasetRecord.getDimension1Name())
    569             &&
    570             ((!testDimension2Name && !StrLib.isSomething(datasetRecord.getDimension2Name()))
    571               ||
    572               (testDimension2Name && StrLib.isSomething(datasetRecord.getDimension2Name()))
    573             )
    574           ) {
    575             datasetRecord.setFieldValue("DATASET_NAME", datasetName);
    576             return(datasetRecord);
    577           }
    578        }
    579       }
    580 
     521        } // end of dim1or2 processing
     522
     523        // if dimensions all exist/matches everything then set the databean and return.
     524        if( StrLib.isSomething(dimension1Name) &&
     525          ((!testDimension2Name && !StrLib.isSomething(dimension2Name))
     526            ||
     527           (testDimension2Name && StrLib.isSomething(dimension2Name))
     528          )
     529        ) {
     530          datasetRecord.setFieldValue("DIMENSION_1_NAME", dimension1Name);
     531          datasetRecord.setFieldValue("DIMENSION_2_NAME", dimension2Name);
     532          datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", periodDimensionName);
     533          datasetRecord.setFieldValue("DATASET_NAME", datasetName);
     534          return(datasetRecord);
     535        }
     536      }
    581537    } // loop all the datasets
    582538
Note: See TracChangeset for help on using the changeset viewer.