Package it.eng.spagobi.tools.dataset.common.datastore

Examples of it.eng.spagobi.tools.dataset.common.datastore.IDataStore


   
    dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( profile ));
    dataSet.setParamsMap(parametersFilled);   
    try {
      dataSet.loadData(start, limit, GeneralUtilities.getDatasetMaxResults());
      IDataStore dataStore = dataSet.getDataStore();
      DatasetMetadataParser dsp = new DatasetMetadataParser();
      dsMetadata = dsp.metadataToXML(dataStore);
    }
    catch (Exception e) {
      logger.error("Error while executing dataset for test purpose",e);
View Full Code Here


      if(dataSet.getTransformerId()!=null){
        dataSet.loadData();
      }else{
        dataSet.loadData(start, limit, GeneralUtilities.getDatasetMaxResults());
      }   
      IDataStore dataStore = dataSet.getDataStore();
      JSONDataWriter dataSetWriter = new JSONDataWriter();
      dataSetJSON = (JSONObject) dataSetWriter.write(dataStore);
    }
    catch (Exception e) {
      logger.error("Error while executing dataset for test purpose",e);
View Full Code Here

    String dataSetLabel;
    String user;
    String callback;
 
    IDataSet dataSet;
    IDataStore dataStore;
    JSONObject dataSetJSON;
   
   
    logger.debug("IN");
    Monitor monitor =MonitorFactory.start("SpagoBI_Console.ExecuteDataSetAction.service");
View Full Code Here

    String mimeType;
    String responseType;
    JSONArray jsonArray;
   
    IDataSet dataSet;
    IDataStore dataStore;
    JSONObject dataSetJSON;
   
    String fileExtension;
    String fileName;
    boolean writeBackResponseInline;
   
    logger.debug("IN");
   
    try {
      super.service(request,response);
     
      Assert.assertNotNull(getConsoleEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
      Assert.assertNotNull(getConsoleEngineInstance().getDataSetServiceProxy(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of DatasetServiceProxy class");
     

      dataSetLabel = getAttributeAsString( DATASET_LABEL );
      logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");     
      Assert.assertTrue(!StringUtilities.isEmpty( dataSetLabel ), "Parameter [" + DATASET_LABEL + "] cannot be null or empty");
       
      mimeType = getAttributeAsString( MIME_TYPE );
      logger.debug("Parameter [" + MIME_TYPE + "] is equal to [" + mimeType + "]");
      if(mimeType == null) {
        logger.warn("Parameter [" + MIME_TYPE + "] has not been valorized");
        mimeType = DEFAULT_MIME_TYPE;
        logger.debug("Parameter [" + MIME_TYPE + "] has been set equal to [" + mimeType + "]");
      }
     
      responseType = getAttributeAsString( RESPONSE_TYPE );
      logger.debug("Parameter [" + RESPONSE_TYPE + "] is equal to [" + responseType + "]");
      if(!RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType) && !RESPONSE_TYPE_ATTACHMENT.equalsIgnoreCase(responseType)) {
        logger.warn("Value [" + responseType + "] is not a valid for parameter [" + RESPONSE_TYPE + "]");
        responseType = RESPONSE_TYPE_ATTACHMENT;
        logger.debug("Parameter [" + RESPONSE_TYPE + "] has been set equal to [" + responseType + "]");
      }
       
      String test = getAttributeAsString(META);
      logger.debug("Parameter [" + META + "] is equal to [" + test + "]");
     
      jsonArray = this.getAttributeAsJSONArray(META);
      logger.debug("Parameter [" + META + "] is equal to [" + jsonArray.toString(4) + "]");
   
      dataSet = null;
      try {
        dataSet = getConsoleEngineInstance().getDataSetServiceProxy().getDataSetByLabel( dataSetLabel );
      } catch(Throwable t) {
        throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
       
     
      Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
      Map params = getConsoleEngineInstance().getAnalyticalDrivers();
      dataSet.setParamsMap(params);
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
      dataSet.loadData();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
     
     
      // dataStore decoration ....
      Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
      if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer((int)dataStore.getRecordsCount()));
     
      if(jsonArray != null && jsonArray.length() > 0) {
        int fieldNo = dataStore.getMetaData().getFieldCount();
        for(int i = 0; i < fieldNo; i++) {
          dataStore.getMetaData().getFieldMeta(i).setProperty("visible", Boolean.FALSE);
        }
       
        List actionColumns = new ArrayList();
       
        for(int i = 0; i < jsonArray.length(); i++) {
          String fieldName = jsonArray.getJSONObject(i).optString("name", null);
          String fieldHeader = jsonArray.getJSONObject(i).optString("header", null);
          Boolean isActionColumn = jsonArray.getJSONObject(i).optBoolean("actionColumn", Boolean.FALSE);
         
          if(isActionColumn.booleanValue() == false) {
            if(StringUtilities.isEmpty(fieldName)) {
              logger.warn("no name for column: " + jsonArray.getJSONObject(i).toString(4));
              continue;
            }
            int fieldIndex = dataStore.getMetaData().getFieldIndex(fieldName);
            if(fieldIndex < 0){
              logger.warn("dataStore does not conatin a column named [" + fieldIndex + "]");
              continue;
            }
            if(jsonArray.getJSONObject(i).optBoolean("hidden", true) == false) {
              dataStore.getMetaData().getFieldMeta(fieldIndex).setProperty("visible", Boolean.TRUE);
              dataStore.getMetaData().getFieldMeta(fieldIndex).setAlias(fieldHeader);
            }
          } else {
            String actionConfig = jsonArray.getJSONObject(i).optString("actionConfig");
            logger.debug("Parameter [actionConfig] is equal to [" + actionConfig + "]");
            Assert.assertNotNull(actionConfig, "Parameter [actionConfig]connot be undefined if parameter [actionColumn] is true");
            JSONObject actionConfigJson = new JSONObject(actionConfig);
            actionColumns.add( actionConfigJson );
          }
        }
       
        dataStore.getMetaData().setProperty("actionColumns", actionColumns);
      }
     
     
     
      params = new HashMap();
View Full Code Here

    JSONArray fieldsMetaDataJSON;   
    JSONObject fieldMetaDataJSON;
    IRecord record;
    JSONObject recordJSON;
    int recNo;
    IDataStore dataStore;
       
    JSONArray recordsJSON;
    int resultNumber;
    Object propertyRawValue;
   
    Assert.assertNotNull(o, "Object to be serialized connot be null");
    if( !(o instanceof IDataStore) ) {
      throw new SerializationException("DataStoreJSONSerializer is unable to serialize object of type: " + o.getClass().getName());
    }
   
   
   
    try {
      dataStore = (IDataStore)o;
      result = new JSONObject();
     
      metadata = new JSONObject();
       
      metadata.put("totalProperty", TOTAL_PROPERTY);
      metadata.put("root", ROOT);
      metadata.put("id", "id");
      result.put("metaData", metadata);
     
      propertyRawValue = dataStore.getMetaData().getProperty("resultNumber");
     
     
      recordsJSON = new JSONArray();
      result.put(ROOT, recordsJSON);
   
      // field's meta
      fieldsMetaDataJSON = new JSONArray();
      //fieldsMetaDataJSON.put("recNo");
      for(int i = 0; i < dataStore.getMetaData().getFieldCount(); i++) {
        IFieldMetaData fieldMetaData = dataStore.getMetaData().getFieldMeta(i);
       
        Object visibleProp = fieldMetaData.getProperty("visible");
        if(visibleProp != null
            && (visibleProp instanceof Boolean)
            && ((Boolean)visibleProp).booleanValue() == false) {
          continue;
        }
       
        fieldMetaDataJSON = new JSONObject();
        fieldMetaDataJSON.put("header", fieldMetaData.getName());
        fieldMetaDataJSON.put("name", "column-" + (i+1));           
        fieldMetaDataJSON.put("dataIndex", "column-" + (i+1));
       
        fieldsMetaDataJSON.put(fieldMetaDataJSON);   
      }
      metadata.put("fields", fieldsMetaDataJSON);
     
      // records
      recNo = 0;
      Iterator records = dataStore.iterator();
      while(records.hasNext()) {
        record = (IRecord)records.next();
        recordJSON = new JSONObject();
        recordJSON.put("id", ++recNo);
       
View Full Code Here

    } catch (Throwable e) {
      e.printStackTrace();
      fail();
    }
   
    IDataStore dataStore = datsSet.getDataStore();
   
    assertNotNull(dataStore);
    assertTrue(dataStore.getRecordsCount() > 0);
  }
View Full Code Here

    String user;
    String callback;
    String rowId;
 
    IDataSet dataSet;
    IDataStore dataStore;
    JSONObject dataSetJSON;
   
   
    logger.debug("IN");
    Monitor monitor =MonitorFactory.start("SpagoBI_Console.GetErrorListAction.service")
   
    try {
      super.service(request,response);
      ConsoleEngineInstance consoleEngineInstance = getConsoleEngineInstance();
   
      dataSetLabel = getAttributeAsString( DATASET_LABEL );
      logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");     
      Assert.assertTrue(!StringUtilities.isEmpty( dataSetLabel ), "Parameter [" + DATASET_LABEL + "] cannot be null or empty");
     
      callback = getAttributeAsString( CALLBACK );
      logger.debug("Parameter [" + CALLBACK + "] is equals to [" + callback + "]");
     
      rowId = getAttributeAsString( ID );
      logger.debug("Parameter [" + ID + "] is equals to [" + rowId + "]");
      Assert.assertNotNull(rowId, "Input parameters [" + ID + "] cannot be null");
     
      dataSet = null;
      try {
        dataSet = getDataSet(dataSetLabel);
      } catch(Throwable t) {
        throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
        /*
      Map params = new HashMap();
      params.put("id", rowId);
      dataSet.setParamsMap(params);
      */
      Map params = consoleEngineInstance.getAnalyticalDrivers();
      params.put("id", rowId);
      dataSet.setParamsMap(params);
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
      Monitor monitorLD =MonitorFactory.start("SpagoBI_Console.GetErrorListAction.service.LoadData")
     
      dataSet.loadData();
      monitorLD.stop();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
         
      dataStore.getMetaData().setProperty("detailProperty", ERRORS_DETAIL_COLUMN);
      //int fieldIndex = dataStore.getMetaData().getFieldIndex(ERRORS_DETAIL_COLUMN);
      //dataStore.getMetaData().getFieldMeta(fieldIndex).setProperty("detail", true);
     
     
     
      dataSetJSON = null;
     
      try {
        JSONDataWriter writer = new JSONDataWriter();
       
        Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
        if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer((int)dataStore.getRecordsCount()));
       
        dataSetJSON = (JSONObject)writer.write(dataStore);
      } catch (Throwable e) {
        throw new SpagoBIServiceException("Impossible to serialize datastore", e);
      }
View Full Code Here

    String dataSetLabel;
    String user;
    String callback;
 
    IDataSet dataSet;
    IDataStore dataStore;
   
    logger.debug("IN");
    Monitor monitor =MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service")
   
    try {
      super.service(request,response);
      ConsoleEngineInstance consoleEngineInstance = getConsoleEngineInstance();
     
      dataSetLabel = getAttributeAsString( DATASET_LABEL );
      logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");     
      Assert.assertTrue(!StringUtilities.isEmpty( dataSetLabel ), "Parameter [" + DATASET_LABEL + "] cannot be null or empty");
     
      callback = getAttributeAsString( CALLBACK );
      logger.debug("Parameter [" + CALLBACK + "] is equals to [" + callback + "]");
     
      dataSet = null;
      try {
        dataSet = getDataSet(dataSetLabel);
      } catch(Throwable t) {
        throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
      Map params = consoleEngineInstance.getAnalyticalDrivers();
      dataSet.setParamsMap(params);
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
      //dataSet.setParamsMap(getEnv());
      //gets the max number of rows for the table
      String strRowLimit = ConsoleEngineConfig.getInstance().getProperty("CONSOLE-TABLE-ROWS-LIMIT");
      int rowLimit = (strRowLimit == null)? 0 : Integer.parseInt(strRowLimit);
      Monitor monitorLD =MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service.LoadData");
      if (rowLimit > 0){
        dataSet.loadData(-1, -1, rowLimit);
      }else{
        dataSet.loadData();
      }
      monitorLD.stop();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
     
      JSONObject results = new JSONObject();
      try {
        JSONDataWriter writer = new JSONDataWriter();
       
        Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
        if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer((int)dataStore.getRecordsCount()));
        /*
        //gets the max number of rows for the table
        String strRowLimit = ConsoleEngineConfig.getInstance().getProperty("CONSOLE-TABLE-ROWS-LIMIT");
        int rowLimit = (strRowLimit == null)? 0 : Integer.parseInt(strRowLimit);
       
View Full Code Here

    String user;
    String callback;
    String rowId;
   
    IDataSet dataSet;
    IDataStore dataStore;
    JSONObject dataSetJSON;
   
   
    logger.debug("IN");
    Monitor monitor =MonitorFactory.start("SpagoBI_Console.GetWarningListAction.service")
   
    try {
      super.service(request,response);
      ConsoleEngineInstance consoleEngineInstance = getConsoleEngineInstance();
   
      dataSetLabel = getAttributeAsString( DATASET_LABEL );
      logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");     
      Assert.assertTrue(!StringUtilities.isEmpty( dataSetLabel ), "Parameter [" + DATASET_LABEL + "] cannot be null or empty");
     
      callback = getAttributeAsString( CALLBACK );
      logger.debug("Parameter [" + CALLBACK + "] is equals to [" + callback + "]");
     
      rowId = getAttributeAsString( ID );
      logger.debug("Parameter [" + ID + "] is equals to [" + rowId + "]");
      Assert.assertNotNull(rowId, "Input parameters [" + ID + "] cannot be null");
     
      dataSet = null;
      try {
        dataSet = getDataSet(dataSetLabel);
      } catch(Throwable t) {
        throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
        /*
      Map params = new HashMap();
      params.put("id", rowId);
      dataSet.setParamsMap(params);
      */
      Map params = consoleEngineInstance.getAnalyticalDrivers();
      params.put("id", rowId);
      dataSet.setParamsMap(params);
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
      Monitor monitorLD =MonitorFactory.start("SpagoBI_Console.GetWarningListAction.service.LoadData")
      dataSet.loadData();
      monitorLD.stop();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
         
      dataStore.getMetaData().setProperty("detailProperty", ERRORS_DETAIL_COLUMN);
      //int fieldIndex = dataStore.getMetaData().getFieldIndex(ERRORS_DETAIL_COLUMN);
      //dataStore.getMetaData().getFieldMeta(fieldIndex).setProperty("detail", true);
     
     
     
      dataSetJSON = null;
     
      try {
        JSONDataWriter writer = new JSONDataWriter();
       
        Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
        if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer((int)dataStore.getRecordsCount()));
       
       
        dataSetJSON = (JSONObject)writer.write(dataStore);
      } catch (Throwable e) {
        throw new SpagoBIServiceException("Impossible to serialize datastore", e);
View Full Code Here

   * @param targetMap the target map
   * @param datamart the datamart
   */
  private void decorateMap(SVGDocument masterMap, SVGDocument targetMap, DataMart datamart) {

    IDataStore dataStore = datamart.getDataStore();
    IDataStoreMetaData dataStoreMeta = dataStore.getMetaData();
    List measureFieldsMeta = dataStoreMeta.findFieldMeta("ROLE", "MEASURE");
    String[] kpiNames = new String[measureFieldsMeta.size()];
    for(int i = 0; i < kpiNames.length; i++) {
      IFieldMetaData filedMeta = (IFieldMetaData)measureFieldsMeta.get(i);
      kpiNames[i] = filedMeta.getName();
    }





    //int selectedKpiIndex = dataStoreMeta.getFieldIndex( getSelectedMeasureName() );
    String selectedKpiName = getSelectedMeasureName(); //kpiNames[selectedKpiIndex];
    Assert.assertTrue(selectedKpiName != null, "default_kpi attribute cannot be null. Please add it to MEASURES tag in your template file");
    Measure measure  = getMeasure( selectedKpiName );
    Number lb_value = null;
    Number ub_value = null;
    String lb_color = null;
    String ub_color = null;
    String null_values_color = null;
    String[] trasholdCalculationPercParams = null;
    Integer num_group = null;
    Integer trasholdCalculationUniformParams = null;
    String colorRangeCalculationGradParams = null;
    String[] col_kpi_array = null;
    Number[] trash_kpi_array = null;
    Number[] kpi_ordered_values = null;




    dataStore.sortRecords( dataStoreMeta.getFieldIndex(selectedKpiName) );
    List orderedKpiValuesSet = dataStore.getFieldValues( dataStoreMeta.getFieldIndex(selectedKpiName) );
    //Set orderedKpiValuesSet = datamart.getOrderedKpiValuesSet( selectedKpiName );
    kpi_ordered_values = (Number[])orderedKpiValuesSet.toArray(new Number[0]);



    if( measure.getTresholdLb() == null
        || measure.getTresholdLb().trim().equalsIgnoreCase("")
        || measure.getTresholdLb().equalsIgnoreCase("none") ) {
      lb_value = null;
    } else {
      lb_value = Double.parseDouble( measure.getTresholdLb() );
    }

    if( measure.getTresholdUb() == null
        || measure.getTresholdUb().trim().equalsIgnoreCase("")
        || measure.getTresholdUb().equalsIgnoreCase("none") ) {
      ub_value = null;
    } else {
      ub_value = Double.parseDouble( measure.getTresholdUb() );
    }

    lb_color = measure.getColurOutboundCol();
    ub_color = measure.getColurOutboundCol();
    null_values_color = measure.getColurNullCol();


    String numGroupAttr = measure.getTresholdCalculatorParameters().getProperty("GROUPS_NUMBER");
    if( numGroupAttr != null ) {
      num_group = Integer.parseInt( numGroupAttr );
      trasholdCalculationUniformParams = num_group;
    }

    colorRangeCalculationGradParams = measure.getColurCalculatorParameters().getProperty("BASE_COLOR");




    //////////////////////////////////////////////////////////////////////////
    // SetTrashHolds
    ///////////////
    if(lb_value == null) {
      lb_value = kpi_ordered_values[0];
    }
    if(ub_value == null) {
      ub_value = kpi_ordered_values[kpi_ordered_values.length-1];
    }

    if(lb_value.doubleValue() > ub_value.doubleValue()) {
      Number t = lb_value;
      ub_value = lb_value;
      lb_value = t;
    }

    if(ub_value.doubleValue() < kpi_ordered_values[0].doubleValue() || lb_value.doubleValue() >  kpi_ordered_values[kpi_ordered_values.length-1].doubleValue()) {
      lb_value = kpi_ordered_values[0];
      ub_value = kpi_ordered_values[kpi_ordered_values.length-1];
    }



    if( measure.getTresholdCalculatorType().equalsIgnoreCase("quantile") ) {     

      trash_kpi_array = new Number[num_group + 1];

      int diff_value_num = 0
      int start_index = -1
      if(kpi_ordered_values[0].doubleValue() >= lb_value.doubleValue() && kpi_ordered_values[kpi_ordered_values.length-1].doubleValue() <= ub_value.doubleValue()) {
        diff_value_num = kpi_ordered_values.length;
        start_index = 0;
      } else {
        for(int j = 0; j < kpi_ordered_values.length; j++) {           
          if(kpi_ordered_values[j].doubleValue() >= lb_value.doubleValue() && kpi_ordered_values[j].doubleValue() <= ub_value.doubleValue()) {
            start_index = (start_index == -1?j:start_index);
            diff_value_num++;
          }
        }
      }


      if(diff_value_num < num_group) num_group = diff_value_num;
      int blockSize = (int)Math.floor( diff_value_num / num_group );

      trash_kpi_array[0] = lb_value;
      for(int j = 1; j < num_group; j++){
        trash_kpi_array[j] = kpi_ordered_values[start_index + (j*blockSize)];
      }
      trash_kpi_array[num_group] = ub_value;

    } else if ( measure.getTresholdCalculatorType().equalsIgnoreCase("perc") ) {
      double range = ub_value.doubleValue() - lb_value.doubleValue();

      trasholdCalculationPercParams = getTresholdsArray(measure.getColumnId());
      trash_kpi_array = new Number[trasholdCalculationPercParams.length + 1];

      trash_kpi_array[0] = lb_value;
      for(int j = 0; j < trasholdCalculationPercParams.length; j++) {
        double groupSize = (range / 100.0) * Double.parseDouble(trasholdCalculationPercParams[j]);
        trash_kpi_array[j+1] = trash_kpi_array[j].doubleValue() + groupSize;
      }
      trash_kpi_array[ trash_kpi_array.length - 1] = ub_value;
      num_group = trash_kpi_array.length - 1;
    } else if ( measure.getTresholdCalculatorType().equalsIgnoreCase("uniform") ) {
      trash_kpi_array = new Number[ trasholdCalculationUniformParams.intValue() + 1 ];
      double perc = 100 / (trasholdCalculationUniformParams.doubleValue());
      trasholdCalculationPercParams = new String[trasholdCalculationUniformParams.intValue() + 1];
      for(int j = 0; j < trasholdCalculationPercParams.length; j++) {
        trasholdCalculationPercParams[j] = "" + perc;
      }

      double range = ub_value.doubleValue() - lb_value.doubleValue();
      trash_kpi_array[0] = lb_value;

      for(int j = 0; j < trash_kpi_array.length-2; j++) {
        double groupSize = (range / 100.0) * Double.parseDouble(trasholdCalculationPercParams[j]);
        trash_kpi_array[j+1] = trash_kpi_array[j].doubleValue() + groupSize;
      }
      trash_kpi_array[ trash_kpi_array.length-1 ] = ub_value;
      num_group = trasholdCalculationPercParams.length - 1;     
    } else if ( measure.getTresholdCalculatorType().equalsIgnoreCase("static") ) {
      String[] trasholdsArray = getTresholdsArray( selectedKpiName );
      trash_kpi_array = new Number[trasholdsArray.length];
      for(int j = 0; j < trasholdsArray.length; j++) {
        trash_kpi_array[j] = new Double( trasholdsArray[j] );
      }
    } else {
      //setQuantileTrasholds(kpi_names[i]);
    }

    if(num_group == null) { // static case, num_group is calculated from bounds
      num_group = new Integer(trash_kpi_array.length-1);
    }

    if(measure.getColurCalculatorType().equalsIgnoreCase("static"))  {
      col_kpi_array = getColoursArray( selectedKpiName );
    } else if(measure.getColurCalculatorType().equalsIgnoreCase("gradient") || measure.getColurCalculatorType().equalsIgnoreCase("grad"))  {
      col_kpi_array = getGradientColourRange(colorRangeCalculationGradParams, num_group)
    } else {
      col_kpi_array = getGradientColourRange(colorRangeCalculationGradParams, num_group)
    }
    logger.debug( Arrays.toString( col_kpi_array ) );



    Element targetLayer = targetMap.getElementById(datamart.getTargetFeatureName());

    NodeList nodeList = targetLayer.getChildNodes();
    for(int i = 0; i < nodeList.getLength(); i++){
      Node childNode = (Node)nodeList.item(i);
      if(childNode instanceof Element) {
        SVGElement child = (SVGElement)childNode;

        String childId = child.getId();
        String column_id = childId.replaceAll(datamart.getTargetFeatureName() + "_", "");

        IRecord record = dataStore.getRecordByID( column_id );


        //Map attributes = (Map)datamart.getAttributeseById(column_id);


        String targetColor = null;
        Number kpyValue = null;
        if(record != null) {
          IField field = record.getFieldAt( dataStoreMeta.getFieldIndex(selectedKpiName) )
          String kpyValueAttr = "" + field.getValue();
          //String kpyValueAttr = (String)attributes.get( selectedKpiName ); 
          if(kpyValueAttr == null) {
            targetColor = null_values_color;
          } else {
            kpyValue = Double.parseDouble(kpyValueAttr);

            if(kpyValue.doubleValue() < lb_value.doubleValue()) {
              targetColor = lb_color;
            } else if(kpyValue.doubleValue() > ub_value.doubleValue()) {
              targetColor = ub_color;
            } else if(kpyValue.doubleValue() == ub_value.doubleValue()) {
              targetColor = col_kpi_array[trash_kpi_array.length-2];
            } else  {
              for (int j = 0; j < trash_kpi_array.length-1; j++) {
                if (kpyValue.doubleValue() >= trash_kpi_array[j].doubleValue() && kpyValue.doubleValue() <  trash_kpi_array[j+1].doubleValue()) {
                  targetColor = col_kpi_array[j];
                  break;
                }
              }
            }
          }
        }

        if(targetColor != null) {
          if(child.getNodeName().equals("path")
              || child.getNodeName().equals("polygon")
              || child.getNodeName().equals("ellipse")
              || child.getNodeName().equals("circle")
              || child.getNodeName().equals("rect")
          ) {

            child.setAttribute("fill", targetColor );
          } else if(child.getNodeName().equals("line")
              || child.getNodeName().equals("polyline")
          ) {
            child.setAttribute("stroke", targetColor );
          }

          String opacity = measure.getColurCalculatorParameters().getProperty("opacity");
          if(opacity != null) {
            child.setAttribute("opacity", opacity );
          }


        }

      }
    }

    // add label
    //Map values = datamart.getValues();
    //Iterator it = values.keySet().iterator();
    Iterator it = dataStore.iterator();
    while(it.hasNext()) {
      IRecord record = (IRecord)it.next();
      IField field = null;

      field = record.getFieldAt( dataStoreMeta.getIdFieldIndex() );
View Full Code Here

TOP

Related Classes of it.eng.spagobi.tools.dataset.common.datastore.IDataStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.