Changeset 19676 in main


Ignore:
Timestamp:
12/30/19 22:04:28 (3 months ago)
Author:
GarthBraithwaite_STG
Message:

java - temp commit of view dsr edit controller before reworking again.

File:
1 edited

Legend:

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

    r19508 r19676  
    44import java.util.Collection;
    55import java.util.HashMap;
     6import java.util.HashSet;
    67import java.util.Iterator;
    78import java.util.Map;
     
    441442   * The ds record is setup with all the dim names and dataset name.
    442443   *
     444   * This code has to deal with the dataset having dim1 and dim2 being implemented
     445   * as dim1or2!
     446   *
    443447   * @return exiting dataset record from the db or a stubbed out blank record.
    444448   * @throws Exception
     
    459463      String datasetName = datasetToIndicatorView.getDatasetName();
    460464
    461       boolean dimension1Found = false;
    462       boolean dimension2Found = false;
    463       boolean periodDimensionFound = false;
     465      int dimension1Found = 0;
     466      int dimension2Found = 0;
     467      int periodDimensionFound = 0;
     468      HashSet<String> dimension1or2Names = new HashSet<String>();
    464469
    465470      // loop all of that dataset's dimension usages. 
     
    469474        String indicatorViewDimensionUsage = dimensionToDataset.getViewDimensionUsage();
    470475
    471         if(dimensionName.equals(categoryDimensionName) && DimensionToIndicatorView.CATEGORY_USAGE.equals(indicatorViewDimensionUsage)) {
    472           if(dimensionToDataset.isDimension1()) {
    473             datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    474             dimension1Found = true;
     476        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            }
    475493          }
    476           else if(dimensionToDataset.isDimension2()) {
    477             datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    478             dimension2Found = true;
     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            }
    479511          }
    480           else if(dimensionToDataset.isPeriod()) {
    481             datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    482             periodDimensionFound = true;
     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            }
    483529          }
    484         }
    485 
    486         else if(dimensionName.equals(seriesDimensionName) && DimensionToIndicatorView.SERIES_USAGE.equals(indicatorViewDimensionUsage)) {
    487           if(dimensionToDataset.isDimension1()) {
    488             datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    489             dimension1Found = true;
     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);
    490537          }
    491           else if(dimensionToDataset.isDimension2()) {
    492             datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    493             dimension2Found = true;
     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);
    494565          }
    495           else if(dimensionToDataset.isPeriod()) {
    496             datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    497             periodDimensionFound = true;
     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);
    498577          }
    499         }
    500        
    501         else if(dimensionName.equals(constantDimensionName) && DimensionToIndicatorView.CONSTANT_USAGE.equals(indicatorViewDimensionUsage)) {
    502           if(dimensionToDataset.isDimension1()) {
    503             datasetRecord.setFieldValue("DIMENSION_1_NAME", dimensionName);
    504             dimension1Found = true;
    505           }
    506           else if(dimensionToDataset.isDimension2()) {
    507             datasetRecord.setFieldValue("DIMENSION_2_NAME", dimensionName);
    508             dimension2Found = true;
    509           }
    510           else if(dimensionToDataset.isPeriod()) {
    511             datasetRecord.setFieldValue("PERIOD_DIMENSION_NAME", dimensionName);
    512             periodDimensionFound = true;
    513           }
    514         }
    515 
    516         if((!testDimension2Name && !dimension2Found && dimension1Found && periodDimensionFound)
    517           || (testDimension2Name && dimension2Found && dimension1Found && periodDimensionFound)
    518         ) {
    519           datasetRecord.setFieldValue("DATASET_NAME", datasetName);
    520           return(datasetRecord);
    521         }
    522       }
    523     }
    524 
    525     // if here nothing found - this should never happen so throw an error...
    526     throw new Exception("Could not find any dimension combinations view dimension usages.  Category: "
     578       }
     579      }
     580
     581    } // loop all the datasets
     582
     583    // if here nothing found - this can happen in some cases where dim1or2 is
     584    // used for both dim1 and dim2 and dim2 and dim1 - throw an error as it's
     585    // a problem.
     586    throw new Exception("Could not determine the dimension usage combinations for this view.  These data will need to be edited using the Dataset Record Edit interface.  Category: "
    527587      + categoryDimensionName
    528588      + ", Series: " + seriesDimensionName
Note: See TracChangeset for help on using the changeset viewer.