Changeset 17685 in main


Ignore:
Timestamp:
12/30/18 18:35:40 (5 months ago)
Author:
GarthBraithwaite_STG
Message:

java, db - reimplemented complete IP xml but controlled via property. Fixed VA suppressed typo. Removed a id="top" from some xslt. Added distinct XMLLib.selectNodes.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/db/src/main/scripts/mysql/data-value_attribute.sql

    r15262 r17685  
    66
    77insert into VALUE_ATTRIBUTE (NAME, TITLE, CODE, DESCRIPTION, DEFINITION, SORT_ORDER, ACTIVE_FLAG, MODIFIED_DATE) values(
    8         'Supressed', 'Supressed', '**', 
     8        'Suppressed', 'Suppressed', '**', 
    99        'Value suppressed due to small numbers.',
    1010        'The estimate has been suppressed because 1) The relative standard error is greater than 50% or when the relative standard error can not be determined.  Consider aggregating years to decrease the relative standard error and improve the reliability of the estimate.  2) the observed number of events is very small and not appropriate for publication, or 3) it could be used to calculate the number in a cell that has been suppressed.',
     
    1212);
    1313insert into VALUE_ATTRIBUTE (NAME, TITLE, CODE, DESCRIPTION, DEFINITION, SORT_ORDER, ACTIVE_FLAG, MODIFIED_DATE) values(
    14         'SurveySupressed', 'Survey Supressed', '**', 
     14        'SurveySuppressed', 'Survey Suppressed', '**', 
    1515        ' Value suppressed due to small sample size (<50).',
    1616        'The estimate has been suppressed because number of responses was less than 50.',
  • trunk/db/src/main/scripts/mysql/tab_c-misc_update_v3.sql

    r17632 r17685  
    3737  VALUE_TYPE_NAME                 varchar  (100),
    3838  XML_ELEMENT_NAME                varchar  (100),                       /* IF USED SHOULD BE REQUIRED */
     39  REQUIRED_FLAG                   varchar    (1),
    3940  /* */
    4041  SORT_ORDER                      int,
  • trunk/ibisph-admin/src/main/webapp/WEB-INF/config/spring/indicator.xml

    r17645 r17685  
    7171                <property name="dateFormat"                  ref="commonDateFormat"/>
    7272                <property name="stringCleaner"               ref="commonMSWordStringCleaner"/>
     73                <property name="includeDependentXML"         value="true"/>
    7374        </bean>
    7475
  • trunk/ibisph-view/src/main/webapp/css/_general.css

    r17645 r17685  
    340340        font-size:                      0.85rem;
    341341}
     342.Note h3
     343{
     344        margin-top:                     2px;
     345}
    342346
    343347
  • trunk/ibisph-view/src/main/webapp/xslt/html/publication/index/chronological/Page.xslt

    r16335 r17685  
    3535                </style>
    3636
    37                 <a id="top"/>
    3837                This page contains a chronological index of the Office of Public Health Assessment publications.
    3938                The year links allow you to directly jump to that section of the index which lists those
  • trunk/ibisph-view/src/main/webapp/xslt/html/publication/index/topical/Page.xslt

    r16335 r17685  
    2727                ibis:doc="Main page content template. Builds a table listing the pubs by topic."
    2828        >
    29                 <a id="top"></a>
    3029                This page contains a topical index of the Office of Public Health Assessment publications.
    3130                The drop down list box will enable you to directly jump to that section of the index which
  • trunk/ibisph-view/src/main/webapp/xslt/html/query/module/result/Page.xslt

    r17632 r17685  
    9292                <xsl:param name="configuration" select="$queryModule/CONFIGURATIONS/CONFIGURATION[NAME=/QUERY_MODULE/REQUEST/CONFIGURATION_NAME]"/>
    9393
    94                 <a id="top"></a>
    9594                <xsl:call-template name="UserSelections.criteria">
    9695                        <xsl:with-param name="queryModule"   select="$queryModule"/>
     
    141140                <br/><br/>
    142141
    143                 <a href="#top" class="Top">Top</a>
     142                <a href="#" class="Top">Top</a>
    144143                <br/><br/>
    145144        </xsl:template>
  • trunk/ibisph-view/src/main/webapp/xslt/json/Kendo.xslt

    r17632 r17685  
    132132                                ,"Label":        { type: "string" }
    133133                                ,"Note":         { type: "string" }
    134                                 ,"ValueAttribute":    { type: "string" }
     134                                ,"ValueAttributeName":    { type: "string" }
    135135                <xsl:for-each select="$recordAncillaryValueFields/RECORD_ANCILLARY_VALUE_FIELD">
    136136                                ,"<xsl:value-of select="NAME"/>":          { type: "number" }
     
    199199                <xsl:param name="recordAncillaryValueFields" ibis:doc="ancillary values struct."/>
    200200                <xsl:param name="measure" ibis:doc="measure info - NOT the measure value."/>
    201                 <xsl:param name="footerValues"/>
    202 
    203                 <xsl:param name="showFooterRow"   select="0 != count($footerValues)"/>
     201                <xsl:param name="footerValues"  ibis:doc="total values - typically from query result."/>
     202                <xsl:param name="showFooterRow" select="(0 != count($footerValues)) and (0 != string-length($footerValues[0]))"/>
     203
    204204                <xsl:param name="showNoteColumn"  select="false()"/>
    205205                <xsl:param name="showLabelColumn" select="false()"/>
     
    209209                <xsl:param name="categoryDimensionField" select="$recordDimensionFields/RECORD_DIMENSION_FIELD[USAGE='category']"/>
    210210                <xsl:param name="constantDimensionField" select="$recordDimensionFields/RECORD_DIMENSION_FIELD[USAGE='constant']"/>
    211 <!-- GARTH: TODO:
    212                 <xsl:param name="baseExportFilename" select="'ibisph-query-result-data'"/>
    213 -->
    214                
     211
    215212<xsl:text>{</xsl:text>
    216213    dataSource: <xsl:value-of select="$kendoDataSourceJavascriptVariableName"/>
     
    293290                </xsl:for-each>
    294291
     292                <xsl:if test="$showLabelColumn">
     293                ,{
     294                        field: "Label"
     295                        ,title: "<xsl:value-of select="$Kendo.labelColumnTitle"/>"
     296                        ,attributes: {"class": "Notes"}
     297                }<xsl:text/>
     298                </xsl:if>
     299
     300                <xsl:if test="$showValueAttributeColumn">
     301                ,{
     302                        field: "ValueAttributeName"
     303                        ,title: "<xsl:value-of select="$Kendo.valueAttributeColumnTitle"/>"
     304                        ,attributes: {"class": "Notes"}
     305                }<xsl:text/>
     306                </xsl:if>
     307
    295308                <xsl:if test="$showNoteColumn">
    296309                ,{
     
    301314                </xsl:if>
    302315
    303                 <xsl:if test="$showLabelColumn">
    304                 ,{
    305                         field: "Label"
    306                         ,title: "<xsl:value-of select="$Kendo.labelColumnTitle"/>"
    307                         ,attributes: {"class": "Notes"}
    308                 }<xsl:text/>
    309                 </xsl:if>
    310 
    311                 <xsl:if test="$showValueAttributeColumn">
    312                 ,{
    313                         field: "ValueAttribute"
    314                         ,title: "<xsl:value-of select="$Kendo.valueAttributeColumnTitle"/>"
    315                         ,attributes: {"class": "Notes"}
    316                 }<xsl:text/>
    317                 </xsl:if>
    318 
    319316                <!-- hidden category sort order
    320317                ,{field: "<xsl:value-of select="$categoryDimensionField/NAME"/>", title: "Default Order", hidden: false, groupable: false}
    321318                -->
    322319        ]
    323 <!-- GARTH: TODO:
    324         saveAsExcel applies only when using
    325         , excel: { fileName: "<xsl:value-of select="$baseExportFilename"/>.xlsx" }
    326         -->
    327320}
    328321        </xsl:template>
     
    350343                <xsl:param name="includeNumerator"     select="false()"/>
    351344                <xsl:param name="includeDenominator"   select="false()"/>
    352 <!-- GARTH: TODO:
    353                 <xsl:param name="baseExportFilename" select="'ibisph-query-result-chart'"/>
    354 -->
     345
    355346                <!--
    356347                        Did have code to dynamically craft - too complex and error prone.
  • trunk/ibisph-view/src/main/webapp/xslt/xml/Interactive.xslt

    r17508 r17685  
    207207
    208208                <xsl:variable name="dimensionUsagesCount" select="count(distinct-values($dimensionUsages/DIMENSION_USAGE/USAGE))"/>
    209                        
     209
    210210                <!-- might as well filter out records that don't have the same number of dims. -->
    211211                <xsl:for-each select="$datasetRecords/RECORD[count(DIMENSIONS/DIMENSION) = $dimensionUsagesCount]">
  • trunk/ibisph/src/main/java/org/ibisph/databean/DimensionsDataBeanToXMLService.java

    r15716 r17685  
    2222
    2323/**
     24 *
     25 * GARTH TODO: Delete if using referenced XML and not embedded.
     26 *
     27 *
     28 *
    2429 * Helper service that creates an INDICATOR DATASET XML document from an
    2530 * indicator dataset data bean (and associated data beans).
  • trunk/ibisph/src/main/java/org/ibisph/indicatorprofile/service/DatasetDataBeanToXML.java

    r17255 r17685  
    1111import org.ibisph.databean.DataBean;
    1212import org.ibisph.databean.DataBeanToXMLService;
     13import org.ibisph.indicatorprofile.databean.AncillaryValue;
    1314import org.ibisph.indicatorprofile.databean.AncillaryValueToDataset;
     15import org.ibisph.indicatorprofile.databean.DataSource;
    1416import org.ibisph.indicatorprofile.databean.DataSourceToDataset;
    1517import org.ibisph.indicatorprofile.databean.Dataset;
    1618import org.ibisph.indicatorprofile.databean.DatasetRecord;
    1719import org.ibisph.indicatorprofile.databean.DatasetRecordAncillaryValue;
     20import org.ibisph.indicatorprofile.databean.Dimension;
     21import org.ibisph.indicatorprofile.databean.DimensionToDataset;
     22import org.ibisph.indicatorprofile.databean.DimensionValue;
    1823import org.ibisph.indicatorprofile.databean.Indicator;
     24import org.ibisph.indicatorprofile.databean.Measure;
     25import org.ibisph.indicatorprofile.databean.ValueAttribute;
     26import org.ibisph.indicatorprofile.databean.ValueType;
    1927import org.ibisph.util.StrLib;
    2028import org.ibisph.util.XMLLib;
     
    2937  protected String dimensionNameSeparator = "---";
    3038
     39  protected boolean includeDependentXML = false;
     40
     41
     42  public void setIncludeDependentXML(boolean includeDependentXML) {
     43    this.includeDependentXML = includeDependentXML;
     44  } //-------------------------- End of Method ------------------------------
     45 
    3146  public Node getDatasetsNode(String indicatorName) throws Exception {
    3247    ArrayList<DataBean> datasetCollection = getIndicatorDatasets(indicatorName);
     
    100115    XMLLib.addNode(document, getRecordsNode(dataset.getMeasureName(), recordsCollection, ancillaryValueToDatasetCollection));
    101116    XMLLib.addNode(document, getSavedQueriesNode(datasetName));
     117
     118    if(this.includeDependentXML) {
     119      Measure measure = new Measure();
     120      this.dataBeanDAOService.load(measure, "NAME", dataset.getMeasureName());
     121      XMLLib.addNode(document, newNode("MEASURE", measure));
     122      XMLLib.addNode(document, getDatasetAncillaryValuesNode(ancillaryValueToDatasetCollection));
     123      XMLLib.addNode(document, getValueTypesNode(measure, ancillaryValueToDatasetCollection));
     124      XMLLib.addNode(document, getValueAttributesNode(recordsCollection));
     125      XMLLib.addNode(document, getDatasetDimensionsNode(datasetName, recordsCollection));
     126      XMLLib.addNode(document, getDataSourcesNode(datasetName));
     127    }
     128
    102129    return(document);
    103130  } //-------------------------- End of Method ------------------------------
    104 
    105131
    106132
     
    128154    return(dataSourceNamesNode);
    129155  } //-------------------------- End of Method ------------------------------
    130 
    131156
    132157
     
    377402  } //-------------------------- End of Method ------------------------------
    378403
     404///////////////////////////
     405
     406
     407  /**
     408   * Creates DATA_SOURCES container and child elements based on the supplied
     409   * dataset. 
     410   * @param dataset DataBean to be converted to XML
     411   * @return XML DATA_SOURCES element for the supplied dataset DataBean.
     412   */
     413  public Node getDataSourcesNode(String datasetName) throws Exception {
     414    Node dataSourcesNode = XMLLib.newNode("DATA_SOURCES");
     415    HashSet<String> dataSourceNameHashSet = new HashSet<String>();
     416
     417    ArrayList<DataBean> datasetDataSourceCollection = new ArrayList<DataBean>();
     418    DataSourceToDataset dataSourceToDataset = new DataSourceToDataset();
     419    dataSourceToDataset.setFieldValue("DATASET_NAME", datasetName);
     420    this.dataBeanDAOService.load(datasetDataSourceCollection, dataSourceToDataset);
     421    for(DataBean dataBean : datasetDataSourceCollection) {
     422      dataSourceToDataset = (DataSourceToDataset)dataBean;
     423      String dataSourceName = dataSourceToDataset.getDataSourceName();
     424      if(StrLib.isSomething(dataSourceName) && !dataSourceNameHashSet.contains(dataSourceName)) {
     425        DataSource dataSource = new DataSource();
     426        this.dataBeanDAOService.load(dataSource, "NAME", dataSourceName);
     427        XMLLib.addNode(dataSourcesNode, this.newNode("DATA_SOURCE", dataSource));
     428        dataSourceNameHashSet.add(dataSourceName);
     429      }
     430    }
     431    return(dataSourcesNode);
     432  } //-------------------------- End of Method ------------------------------
     433
     434
     435  /**
     436   * Creates DATASET's DIMENSIONs child DIMENSION/VALUES based on actual usage. 
     437   * @param dataset DataBean to be used for getting dimension XML.
     438   * @return XML DIMENSIONS element for the supplied dataset Databean.
     439   */
     440  public Node getDatasetDimensionsNode(
     441    String datasetName,
     442    ArrayList<DataBean> recordsCollection
     443  ) throws Exception {
     444    Node containerNode = XMLLib.newNode("DIMENSIONS");
     445
     446    ArrayList<DataBean> dimensionToDatasetCollection = new ArrayList<DataBean>();
     447    DimensionToDataset dimensionToDataset = new DimensionToDataset();
     448    dimensionToDataset.setFieldValue("DATASET_NAME", datasetName);
     449    this.dataBeanDAOService.load(dimensionToDatasetCollection, dimensionToDataset);
     450
     451    for(int i=0; i<dimensionToDatasetCollection.size(); i++) {
     452      dimensionToDataset  = (DimensionToDataset)dimensionToDatasetCollection.get(i);
     453      Dimension dimension = new Dimension();
     454      dimension.setFieldValue("NAME", dimensionToDataset.getDimensionName());
     455      if(0 < this.dataBeanDAOService.load(dimension)) {
     456
     457        Node dimensionNode = this.newNode("DIMENSION", dimension);
     458 
     459        ArrayList<DataBean> dimensionValueCollection = new ArrayList<DataBean>();
     460        DimensionValue dimensionValue = new DimensionValue();
     461        dimensionValue.setFieldValue("DIMENSION_NAME", dimension.getName());
     462        this.dataBeanDAOService.load(dimensionValueCollection, dimensionValue);
     463        Node dimensionValuesNode = XMLLib.newNode("VALUES");
     464        XMLLib.addNode(dimensionNode, dimensionValuesNode);
     465 
     466        // loop for all dimension values.  Add the element if it is used.
     467        DatasetRecord datasetRecord;
     468        for(int j=0; j<dimensionValueCollection.size(); j++) {
     469          dimensionValue = (DimensionValue)dimensionValueCollection.get(j);
     470          boolean dimensionValueUsed = false;
     471          for(int k=0; k<recordsCollection.size(); k++) {
     472            datasetRecord = (DatasetRecord)recordsCollection.get(k);
     473            dimensionValueUsed =
     474                (dimension.getName().equals(datasetRecord.getDimension1Name())
     475                    && dimensionValue.getValue().equals(datasetRecord.getDimension1Value()))
     476                ||
     477                (dimension.getName().equals(datasetRecord.getDimension2Name())
     478                    && dimensionValue.getValue().equals(datasetRecord.getDimension2Value()))
     479                ||
     480                (dimension.getName().equals(datasetRecord.getPeriodDimensionName())
     481                    && dimensionValue.getValue().equals(datasetRecord.getPeriodDimensionValue()))
     482            ;
     483            if(dimensionValueUsed) break;
     484          }
     485          if(dimensionValueUsed) XMLLib.addNode(dimensionValuesNode, this.newNode("VALUE", dimensionValue));
     486        }
     487        XMLLib.addNode(containerNode, dimensionNode);
     488      }
     489    }
     490
     491    return(containerNode);
     492  } //-------------------------- End of Method ------------------------------
     493
     494
     495  /**
     496   * Creates VALUE_TYPES container and child elements based on the measure and
     497   * ancillary values.
     498   * @return XML VALUE_TYPES element.
     499   */
     500  public Node getValueTypesNode(
     501    Measure measure,
     502    ArrayList<DataBean> ancillaryValueToDatasetCollection
     503  ) throws Exception {
     504    Node valueTypesNode = XMLLib.newNode("VALUE_TYPES");
     505    HashSet<String> valueTypeNameHashSet = new HashSet<String>();
     506
     507    ValueType valueType = getValueType(measure.getValueTypeName());
     508    XMLLib.addNode(valueTypesNode, newNode("VALUE_TYPE", valueType));
     509    valueTypeNameHashSet.add(valueType.getName());
     510
     511    for(DataBean dataBean : ancillaryValueToDatasetCollection) {
     512      AncillaryValueToDataset ancillaryValueToDataset = (AncillaryValueToDataset)dataBean;
     513      AncillaryValue ancillaryValue = new AncillaryValue();
     514      ancillaryValue.setFieldValue("NAME", ancillaryValueToDataset.getAncillaryValueName());
     515      if(0 < this.dataBeanDAOService.load(ancillaryValue)) {
     516        String valueTypeName = ancillaryValue.getValueTypeName();
     517        if(StrLib.isSomething(valueTypeName) && !valueTypeNameHashSet.contains(valueTypeName)) {
     518          valueType = getValueType(valueTypeName);
     519          XMLLib.addNode(valueTypesNode, newNode("VALUE_TYPE", valueType));
     520          valueTypeNameHashSet.add(valueType.getName());
     521        }
     522      }
     523    }
     524    return(valueTypesNode);
     525  } //-------------------------- End of Method ------------------------------
     526
     527  public ValueType getValueType(String name) throws Exception {
     528    ValueType valueType = new ValueType();
     529    valueType.setFieldValue("NAME", name);
     530    this.dataBeanDAOService.load(valueType);
     531    return(valueType);
     532  } //-------------------------- End of Method ------------------------------
     533
     534
     535  /**
     536   * Creates VALUE_ATTRIBUTES container and child elements.
     537   * @return XML VALUE_ATTRIBUTES element.
     538   */
     539  public Node getValueAttributesNode(ArrayList<DataBean> recordsCollection) throws Exception {
     540    Node valueAttributesNode = XMLLib.newNode("VALUE_ATTRIBUTES");
     541    HashSet<String> processedValueAttributeSet = new HashSet<String>();
     542    for(DataBean recordDataBean : recordsCollection) {
     543      DatasetRecord datasetRecord = (DatasetRecord)recordDataBean;
     544      String valueAttributeName = datasetRecord.getValueAttributeName();
     545      if(StrLib.isSomething(valueAttributeName) && !processedValueAttributeSet.contains(valueAttributeName)) {
     546        processedValueAttributeSet.add(valueAttributeName);
     547        ValueAttribute valueAttribute = new ValueAttribute();
     548        valueAttribute.setFieldValue("NAME", valueAttributeName);
     549        if(0 < this.dataBeanDAOService.load(valueAttribute)) {
     550          XMLLib.addNode(valueAttributesNode, newNode("VALUE_ATTRIBUTE", valueAttribute));
     551        }
     552      }
     553    }
     554    return(valueAttributesNode);
     555  } //-------------------------- End of Method ------------------------------
     556
     557
     558  /**
     559   * Creates ANCILLARY_VALUES container and child elements based on the supplied
     560   * ancillary value collection.
     561   * @param ancillaryValueToDatasetCollection to be converted to XML
     562   * @return XML ANCILLARY_VALUES element for the supplied collection.
     563   */
     564  public Node getDatasetAncillaryValuesNode(
     565    ArrayList<DataBean> ancillaryValueToDatasetCollection
     566  ) throws Exception {
     567    Node ancillaryValuesNode = XMLLib.newNode("ANCILLARY_VALUES");
     568    for(DataBean dataBean : ancillaryValueToDatasetCollection) {
     569      AncillaryValueToDataset ancillaryValueToDataset = (AncillaryValueToDataset)dataBean;
     570      AncillaryValue ancillaryValue = new AncillaryValue();
     571      ancillaryValue.setFieldValue("NAME", ancillaryValueToDataset.getAncillaryValueName());
     572      if(0 < this.dataBeanDAOService.load(ancillaryValue)) {
     573        Node ancillaryValueNode = newNode("ANCILLARY_VALUE", ancillaryValue);
     574        XMLLib.addNode(ancillaryValuesNode, ancillaryValueNode);
     575      }
     576    }
     577    return(ancillaryValuesNode);
     578  } //-------------------------- End of Method ------------------------------
     579
    379580} //============================ END OF CLASS =================================
  • trunk/ibisph/src/main/java/org/ibisph/indicatorprofile/service/IndicatorDataBeanToXML.java

    r16389 r17685  
    33import java.util.ArrayList;
    44import java.util.Collection;
     5import java.util.HashSet;
     6import java.util.List;
    57
    68import org.dom4j.Node;
     
    1012import org.ibisph.indicatorprofile.databean.*;
    1113import org.ibisph.indicatorprofile.service.DatasetDataBeanToXML;
     14import org.ibisph.util.StrLib;
    1215import org.ibisph.util.XMLLib;
    1316
     
    2326  protected Collection<Relation> relationDataBeanCollection  = null;
    2427
     28  protected boolean includeDependentXML = false;
     29
     30
     31  public void setIncludeDependentXML(boolean includeDependentXML) {
     32    this.includeDependentXML = includeDependentXML;
     33  } //-------------------------- End of Method ------------------------------
    2534
    2635  /**
     
    6372    addDataBeanToNode(document, indicator);
    6473
    65     XMLLib.addNode(document, this.datasetDataBeanToXMLService.getDatasetsNode(indicator));
     74    ArrayList<DataBean> datasetCollection = this.datasetDataBeanToXMLService.getIndicatorDatasets(indicator.getName());
     75    XMLLib.addNode(document, this.datasetDataBeanToXMLService.getDatasetsNode(datasetCollection));
    6676    XMLLib.addNode(document, getTopicsNode(indicator));
    6777    XMLLib.addNode(document, getInitiativesNode(indicator));
     
    6979    XMLLib.addNode(document, getIndicatorViewsNode(indicator));
    7080    XMLLib.addNode(document, getLinksNode(indicator));
    71    
     81
     82    if(this.includeDependentXML) {
     83      XMLLib.addNode(document, getMeasuresNode(document));
     84      XMLLib.addNode(document, getValueTypesNode(document));
     85      XMLLib.addNode(document, getValueAttributesNode(document));
     86      XMLLib.addNode(document, getDataSourcesNode(document));
     87      XMLLib.addNode(document, getDatasetDimensionsNode(document));
     88      XMLLib.addNode(document, getOrgUnitNode(indicator.getOrgUnitName()));
     89    }
     90
    7291    return(document);
     92  } //-------------------------- End of Method ------------------------------
     93
     94
     95  /**
     96   * Creates TOPICS container and child elements based on the supplied
     97   * indicator.
     98   * @param indicator DataBean to be converted to XML
     99   * @return XML TOPICS element for the supplied indicator DataBean.
     100   */
     101  public Node getTopicsNode(Indicator indicator) throws Exception {
     102    Node topicsNode = XMLLib.newNode("TOPICS");
     103
     104    ArrayList<DataBean> topicIndicatorCollection = new ArrayList<DataBean>();
     105    IndicatorToTopic topicIndicator = new IndicatorToTopic();
     106    topicIndicator.setFieldValue("INDICATOR_NAME", indicator.getName());
     107    this.dataBeanDAOService.load(topicIndicatorCollection, topicIndicator);
     108
     109    for(int i=0; i<topicIndicatorCollection.size(); i++) {
     110      topicIndicator = (IndicatorToTopic)topicIndicatorCollection.get(i);
     111      Topic topic = new Topic();
     112      topic.setFieldValue("NAME",        topicIndicator.getTopicName());
     113      topic.setFieldValue("ACTIVE_FLAG", this.dataBeanFlagValue);
     114      if(this.dataBeanDAOService.load(topic) > 0) {
     115        Node topicNode = newNode("TOPIC", topic);
     116        XMLLib.addNode(topicsNode, topicNode);
     117      }
     118    }
     119    return(topicsNode);
    73120  } //-------------------------- End of Method ------------------------------
    74121
     
    139186
    140187  /**
    141    * Creates TOPICS container and child elements based on the supplied
    142    * indicator.
    143    * @param indicator DataBean to be converted to XML
    144    * @return XML TOPICS element for the supplied indicator DataBean.
    145    */
    146   public Node getTopicsNode(Indicator indicator) throws Exception {
    147     Node topicsNode = XMLLib.newNode("TOPICS");
    148 
    149     ArrayList<DataBean> topicIndicatorCollection = new ArrayList<DataBean>();
    150     IndicatorToTopic topicIndicator = new IndicatorToTopic();
    151     topicIndicator.setFieldValue("INDICATOR_NAME", indicator.getName());
    152     this.dataBeanDAOService.load(topicIndicatorCollection, topicIndicator);
    153 
    154     for(int i=0; i<topicIndicatorCollection.size(); i++) {
    155       topicIndicator = (IndicatorToTopic)topicIndicatorCollection.get(i);
    156       Topic topic = new Topic();
    157       topic.setFieldValue("NAME",        topicIndicator.getTopicName());
    158       topic.setFieldValue("ACTIVE_FLAG", this.dataBeanFlagValue);
    159       if(this.dataBeanDAOService.load(topic) > 0) {
    160         Node topicNode = newNode("TOPIC", topic);
    161         XMLLib.addNode(topicsNode, topicNode);
    162       }
    163     }
    164     return(topicsNode);
    165   } //-------------------------- End of Method ------------------------------
    166 
    167 
    168   /**
    169188   * Creates RELATIONS container and child elements based on the supplied
    170189   * indicator.
     
    291310  } //-------------------------- End of Method ------------------------------
    292311
     312
     313
     314
     315  /////////////////////////////////////////////////
     316  public Node getMeasuresNode(Node containerNode) throws Exception {
     317    List<Node> measureNameNodes = XMLLib.getNodes(containerNode, "//MEASURE_NAME", "text()", true);
     318
     319    Node measuresNode = XMLLib.newNode("MEASURES");
     320    for(Node measureNameNode : measureNameNodes) {
     321      Measure measure = new Measure();
     322      this.dataBeanDAOService.load(measure, "NAME", XMLLib.getText(measureNameNode));
     323      XMLLib.addNode(measuresNode, this.newNode("MEASURE", measure));
     324    }
     325    return(measuresNode);
     326  } //-------------------------- End of Method ------------------------------
     327
     328
     329  public Node getValueTypesNode(Node containerNode) throws Exception {
     330    List<Node> valueTypeNamesNode = XMLLib.getNodes(containerNode, "//VALUE_TYPE_NAME", "text()", true);
     331
     332    Node valueTypesNode = XMLLib.newNode("VALUE_TYPES");
     333    for(Node valueTypeNameNode : valueTypeNamesNode) {
     334      ValueType valueType = new ValueType();
     335      this.dataBeanDAOService.load(valueType, "NAME", XMLLib.getText(valueTypeNameNode));
     336      XMLLib.addNode(valueTypesNode, this.newNode("VALUE_TYPE", valueType));
     337    }
     338    return(valueTypesNode);
     339  } //-------------------------- End of Method ------------------------------
     340
     341
     342  public Node getValueAttributesNode(Node containerNode) throws Exception {
     343    List<Node> valueAttributeNamesNode = XMLLib.getNodes(containerNode, "//VALUE_ATTRIBUTE_NAME", "text()", true);
     344
     345    Node valueAttributesNode = XMLLib.newNode("VALUE_ATTRIBUTES");
     346    for(Node valueAttributeNameNode : valueAttributeNamesNode) {
     347      ValueAttribute valueAttribute = new ValueAttribute();
     348      this.dataBeanDAOService.load(valueAttribute, "NAME", XMLLib.getText(valueAttributeNameNode));
     349      XMLLib.addNode(valueAttributesNode, this.newNode("VALUE_ATTRIBUTE", valueAttribute));
     350    }
     351    return(valueAttributesNode);
     352  } //-------------------------- End of Method ------------------------------
     353
     354
     355  public Node getDataSourcesNode(Node containerNode) throws Exception {
     356    List<Node> dataSourceNamesNode = XMLLib.getNodes(containerNode, "//DATA_SOURCE_USAGE/NAME", "text()", true);
     357
     358    Node dataSourcesNode = XMLLib.newNode("DATA_SOURCES");
     359    for(Node dataSourceNameNode : dataSourceNamesNode) {
     360      DataSource dataSource = new DataSource();
     361      this.dataBeanDAOService.load(dataSource, "NAME", XMLLib.getText(dataSourceNameNode));
     362      XMLLib.addNode(dataSourcesNode, this.newNode("DATA_SOURCE", dataSource));
     363    }
     364    return(dataSourcesNode);
     365  } //-------------------------- End of Method ------------------------------
     366
     367
     368  /**
     369   * Creates DATASET's DIMENSIONs child DIMENSION/VALUES based on actual usage. 
     370   * @param dataset DataBean to be used for getting dimension XML.
     371   * @return XML DIMENSIONS element for the supplied dataset Databean.
     372   */
     373  public Node getDatasetDimensionsNode(Node containerNode) throws Exception {
     374    List<Node> dimensionNamesNode = XMLLib.getNodes(containerNode, "//DIMENSION/NAME", "text()", true);
     375
     376    Node dimensionsNode = XMLLib.newNode("DIMENSIONS");
     377    for(Node dimensionNameNode : dimensionNamesNode) {
     378      Dimension dimension = new Dimension();
     379      this.dataBeanDAOService.load(dimension, "NAME", XMLLib.getText(dimensionNameNode));
     380      Node dimensionNode = this.newNode("DIMENSION", dimension);
     381
     382      ArrayList<DataBean> dimensionValueCollection = new ArrayList<DataBean>();
     383      DimensionValue dimensionValue = new DimensionValue();
     384      dimensionValue.setFieldValue("DIMENSION_NAME", dimension.getName());
     385      dimensionValue.setFieldValue("ACTIVE_FLAG", this.dataBeanFlagValue);
     386      this.dataBeanDAOService.load(dimensionValueCollection, dimensionValue);
     387 
     388      // loop for all dimension values.  Add the element if it is used.
     389      Node dimensionValuesNode = XMLLib.newNode("VALUES");
     390      for(int j=0; j<dimensionValueCollection.size(); j++) {
     391        dimensionValue = (DimensionValue)dimensionValueCollection.get(j);
     392        XMLLib.addNode(dimensionValuesNode, this.newNode("VALUE", dimensionValue));
     393      }
     394      XMLLib.addNode(dimensionNode, dimensionValuesNode);
     395      XMLLib.addNode(dimensionsNode, dimensionNode);
     396    }
     397
     398    return(dimensionsNode);
     399  } //-------------------------- End of Method ------------------------------
     400
     401 
     402  public Node getOrgUnitNode(String orgUnitName) throws Exception {
     403    OrgUnit orgUnit = new OrgUnit();
     404    this.dataBeanDAOService.load(orgUnit, "NAME", orgUnitName);
     405    Node orgUnitNode = this.newNode("ORG_UNIT", orgUnit);
     406    return(orgUnitNode);
     407  } //-------------------------- End of Method ------------------------------
     408
     409
     410
     411
     412  //////////////// SAVED FOR NOW
     413
     414  public String[] getMeasureNames(ArrayList<DataBean> datasetCollection) throws Exception {
     415    HashSet<String> measureNames = new HashSet<String>();
     416    for(DataBean dataBean : datasetCollection) {
     417      Dataset dataset = (Dataset)dataBean;
     418      measureNames.add(dataset.getMeasureName());
     419    }
     420    return((String[])measureNames.toArray());
     421  } //-------------------------- End of Method ------------------------------
     422
     423  public ArrayList<DataBean> getMeasures(String[] measureNames) throws Exception {
     424    Measure measure = new Measure();
     425    ArrayList<DataBean> measureCollection = new ArrayList<DataBean>();
     426    for(String measureName : measureNames) {
     427      this.dataBeanDAOService.load(measure, "NAME", measureName);
     428      measureCollection.add(measure);
     429    }
     430    return(measureCollection);
     431  } //-------------------------- End of Method ------------------------------
     432
     433  public Node getMeasuresNode(ArrayList<DataBean> measureCollection) throws Exception {
     434    Node measuresNode = XMLLib.newNode("MEASURES");
     435    for(DataBean dataBean : measureCollection) {
     436      this.addDataBeanToNode(measuresNode, dataBean);
     437    }
     438    return(measuresNode);
     439  } //-------------------------- End of Method ------------------------------
     440
     441
     442
     443  public String[] getValueTypeNames(ArrayList<DataBean> measureCollection) throws Exception {
     444    HashSet<String> valueTypeNames = new HashSet<String>();
     445    for(DataBean dataBean : measureCollection) {
     446      Measure measure = (Measure)dataBean;
     447      valueTypeNames.add(measure.getValueTypeName());
     448    }
     449    return((String[])valueTypeNames.toArray());
     450  } //-------------------------- End of Method ------------------------------
     451
     452  public Node getValueTypesNode(String[] valueTypeNames) throws Exception {
     453    Node valueTypesNode = XMLLib.newNode("VALUE_TYPES");
     454    for(String valueTypeName : valueTypeNames) {
     455      ValueType valueType = new ValueType();
     456      this.dataBeanDAOService.load(valueType, "NAME", valueTypeName);
     457      this.addDataBeanToNode(valueTypesNode, valueType);
     458    }
     459    return(valueTypesNode);
     460  } //-------------------------- End of Method ------------------------------
     461
     462
     463
     464  /**
     465   * Creates DATA_SOURCES container and child elements based on the supplied
     466   * dataset.
     467   * @param dataset DataBean to be converted to XML
     468   * @return XML DATA_SOURCES element for the supplied dataset DataBean.
     469   */
     470  public Node getDataSourcesNode(String datasetName) throws Exception {
     471    Node dataSourcesNode = XMLLib.newNode("DATA_SOURCES");
     472
     473    ArrayList<DataBean> datasetDataSourceCollection = new ArrayList<DataBean>();
     474    DataSourceToDataset datasetDataSource = new DataSourceToDataset();
     475    datasetDataSource.setFieldValue("DATASET_NAME", datasetName);
     476    this.dataBeanDAOService.load(datasetDataSourceCollection, datasetDataSource);
     477    for(DataBean dataBean : datasetDataSourceCollection) {
     478      datasetDataSource = (DataSourceToDataset)dataBean;
     479
     480      Node dataSourceNode = XMLLib.newNode("DATA_SOURCE");
     481      XMLLib.addNode(dataSourceNode, XMLLib.newNode("NAME",  datasetDataSource.getDataSourceName()));
     482      XMLLib.addNode(dataSourceNode, XMLLib.newNode("USAGE", datasetDataSource.getDataSourceUsage()));
     483      XMLLib.addNode(dataSourcesNode, dataSourceNode);
     484    }
     485    return(dataSourcesNode);
     486  } //-------------------------- End of Method ------------------------------
     487
     488
     489  /**
     490   * Creates DATASET's DIMENSIONs child DIMENSION/VALUES based on actual usage. 
     491   * @param dataset DataBean to be used for getting dimension XML.
     492   * @return XML DIMENSIONS element for the supplied dataset Databean.
     493   */
     494  public Node getDatasetDimensionsNode(
     495    String datasetName,
     496    ArrayList<DataBean> recordsCollection
     497  ) throws Exception {
     498    Node containerNode = XMLLib.newNode("DIMENSIONS");
     499
     500    ArrayList<DataBean> dimensionToDatasetCollection = new ArrayList<DataBean>();
     501    DimensionToDataset dimensionToDataset = new DimensionToDataset();
     502    dimensionToDataset.setFieldValue("DATASET_NAME", datasetName);
     503    this.dataBeanDAOService.load(dimensionToDatasetCollection, dimensionToDataset);
     504
     505    for(int i=0; i<dimensionToDatasetCollection.size(); i++) {
     506      dimensionToDataset  = (DimensionToDataset)dimensionToDatasetCollection.get(i);
     507      Dimension dimension = new Dimension();
     508      dimension.setFieldValue("NAME", dimensionToDataset.getDimensionName());
     509      if(0 < this.dataBeanDAOService.load(dimension)) {
     510
     511        Node dimensionNode = this.newNode("DIMENSION", dimension);
     512 
     513        ArrayList<DataBean> dimensionValueCollection = new ArrayList<DataBean>();
     514        DimensionValue dimensionValue = new DimensionValue();
     515        dimensionValue.setFieldValue("DIMENSION_NAME", dimension.getName());
     516        this.dataBeanDAOService.load(dimensionValueCollection, dimensionValue);
     517        Node dimensionValuesNode = XMLLib.newNode("VALUES");
     518        XMLLib.addNode(dimensionNode, dimensionValuesNode);
     519 
     520        // loop for all dimension values.  Add the element if it is used.
     521        DatasetRecord datasetRecord;
     522        for(int j=0; j<dimensionValueCollection.size(); j++) {
     523          dimensionValue = (DimensionValue)dimensionValueCollection.get(j);
     524          boolean dimensionValueUsed = false;
     525          for(int k=0; k<recordsCollection.size(); k++) {
     526            datasetRecord = (DatasetRecord)recordsCollection.get(k);
     527            dimensionValueUsed =
     528                (dimension.getName().equals(datasetRecord.getDimension1Name())
     529                    && dimensionValue.getValue().equals(datasetRecord.getDimension1Value()))
     530                ||
     531                (dimension.getName().equals(datasetRecord.getDimension2Name())
     532                    && dimensionValue.getValue().equals(datasetRecord.getDimension2Value()))
     533                ||
     534                (dimension.getName().equals(datasetRecord.getPeriodDimensionName())
     535                    && dimensionValue.getValue().equals(datasetRecord.getPeriodDimensionValue()))
     536            ;
     537            if(dimensionValueUsed) break;
     538          }
     539          if(dimensionValueUsed) XMLLib.addNode(dimensionValuesNode, this.newNode("VALUE", dimensionValue));
     540        }
     541        XMLLib.addNode(containerNode, dimensionNode);
     542      }
     543    }
     544
     545    return(containerNode);
     546  } //-------------------------- End of Method ------------------------------
     547
     548
     549  /**
     550   * Creates VALUE_TYPES container and child elements based on the measure and
     551   * ancillary values.
     552   * @return XML VALUE_TYPES element.
     553   */
     554  public Node getValueTypesNode(
     555    Measure measure,
     556    ArrayList<DataBean> ancillaryValueToDatasetCollection
     557  ) throws Exception {
     558    Node valueTypesNode = XMLLib.newNode("VALUE_TYPES");
     559    HashSet<String> valueTypeNameHashSet = new HashSet<String>();
     560
     561    ValueType valueType = getValueType(measure.getValueTypeName());
     562    XMLLib.addNode(valueTypesNode, newNode("VALUE_TYPE", valueType));
     563    valueTypeNameHashSet.add(valueType.getName());
     564
     565    for(DataBean dataBean : ancillaryValueToDatasetCollection) {
     566      AncillaryValueToDataset ancillaryValueToDataset = (AncillaryValueToDataset)dataBean;
     567      AncillaryValue ancillaryValue = new AncillaryValue();
     568      ancillaryValue.setFieldValue("NAME", ancillaryValueToDataset.getAncillaryValueName());
     569      if(0 < this.dataBeanDAOService.load(ancillaryValue)) {
     570        String valueTypeName = ancillaryValue.getValueTypeName();
     571        if(StrLib.isSomething(valueTypeName) && !valueTypeNameHashSet.contains(valueTypeName)) {
     572          valueType = getValueType(valueTypeName);
     573          XMLLib.addNode(valueTypesNode, newNode("VALUE_TYPE", valueType));
     574          valueTypeNameHashSet.add(valueType.getName());
     575        }
     576      }
     577    }
     578    return(valueTypesNode);
     579  } //-------------------------- End of Method ------------------------------
     580
     581  public ValueType getValueType(String name) throws Exception {
     582    ValueType valueType = new ValueType();
     583    valueType.setFieldValue("NAME", name);
     584    this.dataBeanDAOService.load(valueType);
     585    return(valueType);
     586  } //-------------------------- End of Method ------------------------------
     587
     588
     589  /**
     590   * Creates VALUE_ATTRIBUTES container and child elements.
     591   * @return XML VALUE_ATTRIBUTES element.
     592   */
     593  public Node getValueAttributesNode() throws Exception {
     594    ArrayList<DataBean> collection = new ArrayList<DataBean>();
     595    ValueAttribute valueAttribute = new ValueAttribute();
     596    valueAttribute.setFieldValue("ACTIVE_FLAG", this.dataBeanFlagValue);
     597    this.dataBeanDAOService.load(collection, valueAttribute);
     598    Node ancillaryValuesNode = this.newNode("VALUE_ATTRIBUTES", "VALUE_ATTRIBUTE", collection);
     599    return(ancillaryValuesNode);
     600  } //-------------------------- End of Method ------------------------------
     601
     602
     603  /**
     604   * Creates ANCILLARY_VALUES container and child elements based on the supplied
     605   * ancillary value collection.
     606   * @param ancillaryValueToDatasetCollection to be converted to XML
     607   * @return XML ANCILLARY_VALUES element for the supplied collection.
     608   */
     609  public Node getDatasetAncillaryValuesNode() throws Exception {
     610    ArrayList<DataBean> collection = new ArrayList<DataBean>();
     611    AncillaryValue ancillaryValue = new AncillaryValue();
     612    this.dataBeanDAOService.load(collection, ancillaryValue);
     613    Node ancillaryValuesNode = this.newNode("ANCILLARY_VALUES", "ANCILLARY_VALUE", collection);
     614    return(ancillaryValuesNode);
     615  } //-------------------------- End of Method ------------------------------
     616
    293617} //============================ END OF CLASS =================================
    294618
  • trunk/ibisph/src/main/java/org/ibisph/util/XMLLib.java

    r17155 r17685  
    2121import org.dom4j.io.DOMWriter;
    2222import org.dom4j.io.DocumentSource;
    23 
     23import org.dom4j.XPath;
     24import org.dom4j.xpath.DefaultXPath;
    2425
    2526/**
     
    148149    return(element);
    149150  } //------------------------------ End of Method ---------------------------
     151
     152
     153  public static XPath newXPath(String xPathExpression) {
     154    return( new DefaultXPath(xPathExpression) );
     155  } //-------------------------- End of Method ------------------------------
    150156
    151157
     
    228234   * @return List of nodes that matches the XPath expression.
    229235   */
    230 
    231236  public static List<Node> getNodes(Node node, String xPathExpression) {
    232237    if(xPathExpression.startsWith("/") && !(node instanceof Document)) {
     
    236241    List<Node> nodes = node.selectNodes(xPathExpression);
    237242    if((nodes.size() < 1) && (node instanceof Document)) return(((Document)node).getRootElement().selectNodes(xPathExpression));
     243    return(nodes);
     244    /*
     245    Object xPathEvaluationObject = evaluateXPath(node, xPathExpression);
     246    if(xPathEvaluationObject instanceof List) {
     247      return((List<Node>)xPathEvaluationObject);
     248    }
     249    else if(xPathEvaluationObject instanceof Node) {
     250      List<Node> nodes = new ArrayList<Node>();
     251      nodes.add((Node)xPathEvaluationObject);
     252      return(nodes);
     253    }
     254    return(null);
     255    */
     256  } //-------------------------- End of Method ------------------------------
     257
     258
     259  /**
     260   * Simple helper that provides a localized way to get unique nodes via an X
     261   * Path expression.
     262   *
     263   * @param node Document/element/node to retrieve nodes from.
     264   * @param xPathExpression Text that contains an XPath expression to be used to
     265   *   select/specify the desired nodes.
     266   * @return Unique list of nodes that matches the XPath expression.
     267   */
     268  public static List<Node> getNodes(Node node, String xPathExpression, String sortOrderXPathExpression, boolean distinct) {
     269//    XPath sortOrderXPath = XMLLib.newXPath(sortOrderXPathExpression);
     270    List<Node> nodes = node.selectNodes(xPathExpression, sortOrderXPathExpression, distinct);
     271    if((nodes.size() < 1) && (node instanceof Document)) return(((Document)node).getRootElement().selectNodes(xPathExpression, sortOrderXPathExpression, distinct));
    238272    return(nodes);
    239273    /*
Note: See TracChangeset for help on using the changeset viewer.