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

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


          } else if(fieldType ==  Boolean.class) {
            value = new Boolean(columnValue);
          } else {
            throw new RuntimeException("Impossible to resolve field type [" + fieldType + "]");
          }
          IField field = new Field(value);
          record.appendField(field);
        }
          dataStore.appendRecord(record);
      }
      
View Full Code Here


            fieldMeta.setName(token);
            fieldMeta.setType(String.class);
            dataStoreMeta.addFiedMeta(fieldMeta);
          } else {
            if (token != null) {
              IField field = new Field(token);
              record.appendField(field);
            }
          }
        }
       
View Full Code Here

            fieldMeta.setName( columnName );
            fieldMeta.setType( columnType );
            dataStoreMeta.addFiedMeta(fieldMeta);
          }
           
            IField field = new Field(columnValue);
          record.appendField(field);
          }
         
          dataStore.appendRecord(record);
      }
View Full Code Here

          for(int i = 0; i < dataStoreMeta.getFieldCount(); i++) {
            IFieldMetaData fieldMetaData = dataStoreMeta.getFieldMeta(i);
            try {
              Object value = rowSB.getAttribute( dataStoreMeta.getFieldName(i) );
              logger.debug("Column [" + fieldMetaData.getName() + "] of type [" + (value!=null? value.getClass(): "undef") + "] is equal to [" + value + "]");         
              IField field = new Field( value );
              if(value != null) {
                dataStoreMeta.getFieldMeta(i).setType( value.getClass() );
              }
              record.appendField( field );
            } catch(Throwable t ) {
View Full Code Here

      while (it.hasNext()){
      IRecord record =(IRecord) it.next()
      DataStoreMetaData dataStoreMeta = (DataStoreMetaData)record.getDataStore().getMetaData();
      List fields = record.getFields();
      for(int j = 0; j < fields.size(); j++) {   
        IField field = (IField)fields.get(j);
        String fieldName = dataStoreMeta.getFieldName(j);
        String fieldValue = "" + field.getValue();
       
        //checks if the field is a row, a column or a value specified into configuration and manages them
        if (fieldName.equalsIgnoreCase(pivotRow)){
          if (rowValue.equals("")) rowValue = fieldValue;
          if (!(rowValue.trim()).equalsIgnoreCase(fieldValue.trim())){
            rowValue = fieldValue;
            newRecords.add(newRecord);
            newRecord = new Record();
          }
          if (newRecord.getFieldAt(dataStoreMeta.getFieldIndex(fieldName) ) == null)
            newRecord.appendField(field);
        }
        else if (fieldName.equalsIgnoreCase(pivotColumn)){
          newFName = fieldValue;
          IField fv = record.getFieldAt(dataStoreMeta.getFieldIndex(pivotValue));
          if (fv == null){
            logger.error("Pivot value column '"+ pivotValue +"' not found into dataset. Pivot not applicated!");
            return null;
          }
          SourceBeanAttribute newFObject =(SourceBeanAttribute) fv.getValue();
          newFValue = newFObject.getValue().toString();
         
          FieldMetadata fieldMeta = new FieldMetadata();
          fieldMeta.setName(newFName);
          fieldMeta.setType(newFValue.getClass());
          dataStoreMeta.addFiedMeta(fieldMeta);
          IField newf = new Field(newFValue);
          newRecord.appendField(newf);
        }
        else if (fieldName.equalsIgnoreCase(pivotValue)){
          //skip field
        }
View Full Code Here

      int cont = 0;
      Iterator iterator = dataStore.iterator();
      while (iterator.hasNext()) {
        IRecord record = (IRecord) iterator.next();
 
        IField pivotField = record.getFieldAt(pivotFieldIndex);
        IField valueField = record.getFieldAt(valueFieldIndex);
        IField groupField = record.getFieldAt(groupFieldIndex);
        
        if (precGroupField == null)
          precGroupField = groupField.getValue().toString();
       
        if (precPivotField == null)
          precPivotField = pivotField.getValue().toString();
       
        if (precGroupField.equalsIgnoreCase(groupField.getValue().toString())){
          if (precPivotField.equalsIgnoreCase(pivotField.getValue().toString())){
            pivotField.setValue(pivotField.getValue().toString()+String.valueOf(cont));
            cont++;
          }
          else{
            cont = 0;
            precPivotField = pivotField.getValue().toString();
            pivotField.setValue(pivotField.getValue().toString()+String.valueOf(cont))
            cont++;
          }
        }
        else{
          cont = 0;
          precGroupField = groupField.getValue().toString();
          precPivotField = pivotField.getValue().toString();
          pivotField.setValue(pivotField.getValue().toString()+String.valueOf(cont));
          cont++;
        }
      }
    }

   
    Iterator pivotedFieldNamesIterator = dataStore.getFieldDistinctValues(pivotFieldIndex).iterator();   
    while ( pivotedFieldNamesIterator.hasNext() ) {
      pivotedFieldNames.add( pivotedFieldNamesIterator.next() );
    }
   
    Iterator it = dataStore.iterator();
    while (it.hasNext()) {
      IRecord record = (IRecord) it.next();

      IField pivotField = record.getFieldAt(pivotFieldIndex);
      IField valueField = record.getFieldAt(valueFieldIndex);
      IField groupField = record.getFieldAt(groupFieldIndex);

      if(selectedGroupValue == null || !selectedGroupValue.toString().equals( groupField.getValue().toString() )) {
        selectedGroupValue = groupField.getValue();
        if(newRecord != null) {
          newRecord.getFields().remove(pivotFieldIndex);
          newRecord.getFields().remove(valueFieldIndex-1);
          newRecords.add( newRecord );
        }
View Full Code Here

    public static transient Logger logger = Logger.getLogger(JSONDataWriter.class);
 
  public Object write(IDataStore dataStore) throws RuntimeException {
    JSONObject  result = null;
    JSONObject metadata;
    IField field;
    JSONArray fieldsMetaDataJSON;   
    JSONObject fieldMetaDataJSON;
    IRecord record;
    JSONObject recordJSON;
    int recNo;
   
   
    JSONArray recordsJSON;
    int resultNumber;
    Object propertyRawValue;
    String detailProperty;
   
    Assert.assertNotNull(dataStore, "Object to be serialized connot be null");
   
    try {
      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");
      detailProperty = (String)dataStore.getMetaData().getProperty("detailProperty");
      if(propertyRawValue==null){
        propertyRawValue = new Integer(1);
      }
      Assert.assertNotNull(propertyRawValue, "DataStore property [resultNumber] cannot be null");
      Assert.assertTrue(propertyRawValue instanceof Integer, "DataStore property [resultNumber] must be of type [Integer]");
      resultNumber = ((Integer)propertyRawValue).intValue();
      Assert.assertTrue(resultNumber >= 0, "DataStore property [resultNumber] cannot be equal to [" + resultNumber + "]. It must be greater or equal to zero")
      result.put(TOTAL_PROPERTY, resultNumber);
     
      recordsJSON = new JSONArray();
      result.put(ROOT, recordsJSON);
   
      // field's meta
      fieldsMetaDataJSON = new JSONArray();
      fieldsMetaDataJSON.put("recNo"); // counting column
      for(int i = 0; i < dataStore.getMetaData().getFieldCount(); i++) {
        IFieldMetaData fieldMetaData = dataStore.getMetaData().getFieldMeta(i);
       
        propertyRawValue = fieldMetaData.getProperty("visible");
        if(propertyRawValue != null
            && (propertyRawValue instanceof Boolean)
            && ((Boolean)propertyRawValue).booleanValue() == false) {
          continue;
        }
       
        String fieldName = "column_" + (i+1);
        String fieldHeader = fieldMetaData.getAlias() != null? fieldMetaData.getAlias(): fieldMetaData.getName();
       
        fieldMetaDataJSON = new JSONObject();
        fieldMetaDataJSON.put("name", fieldName);           
        fieldMetaDataJSON.put("dataIndex", fieldName);
        fieldMetaDataJSON.put("header", fieldHeader);
       
       
        Class clazz = fieldMetaData.getType();
        if (clazz == null) {
          logger.debug("Metadata class is null; considering String as default");
          clazz = String.class;
        } else {
          logger.debug("Column [" + (i+1) + "] class is equal to [" + clazz.getName() + "]");
        }
        if( Number.class.isAssignableFrom(clazz) ) {
          //BigInteger, Integer, Long, Short, Byte
          if(Integer.class.isAssignableFrom(clazz)
               || BigInteger.class.isAssignableFrom(clazz)
             || Long.class.isAssignableFrom(clazz)
             || Short.class.isAssignableFrom(clazz)
             || Byte.class.isAssignableFrom(clazz)) {
            logger.debug("Column [" + (i+1) + "] type is equal to [" + "INTEGER" + "]");
            fieldMetaDataJSON.put("type", "int");
          } else {
            logger.debug("Column [" + (i+1) + "] type is equal to [" + "FLOAT" + "]");
            fieldMetaDataJSON.put("type", "float");
          }
         
          String format = (String) fieldMetaData.getProperty("format");
          if ( format != null ) {
            fieldMetaDataJSON.put("format", format);
          }
         
        } else if( String.class.isAssignableFrom(clazz) ) {
          logger.debug("Column [" + (i+1) + "] type is equal to [" + "STRING" + "]");
          fieldMetaDataJSON.put("type", "string");
        } else if( Timestamp.class.isAssignableFrom(clazz) ) {
          logger.debug("Column [" + (i+1) + "] type is equal to [" + "TIMESTAMP" + "]");
          fieldMetaDataJSON.put("type", "date");
          fieldMetaDataJSON.put("subtype", "timestamp");
          fieldMetaDataJSON.put("dateFormat", "d/m/Y H:i:s");
        } else if( Date.class.isAssignableFrom(clazz) ) {
          logger.debug("Column [" + (i+1) + "] type is equal to [" + "DATE" + "]");
          fieldMetaDataJSON.put("type", "date");
          fieldMetaDataJSON.put("dateFormat", "d/m/Y");
        } else if( Boolean.class.isAssignableFrom(clazz) ) {
          logger.debug("Column [" + (i+1) + "] type is equal to [" + "BOOLEAN" + "]");
          fieldMetaDataJSON.put("type", "boolean");
        } else {
          logger.warn("Column [" + (i+1) + "] type is equal to [" + "???" + "]");
          fieldMetaDataJSON.put("type", "string");
        }
       
        Boolean calculated = (Boolean)fieldMetaData.getProperty("calculated");
        calculated = calculated == null? Boolean.FALSE: calculated;
        if(calculated.booleanValue() == true) {
          DataSetVariable variable =  (DataSetVariable)fieldMetaData.getProperty("variable");
          if(variable.getType().equalsIgnoreCase(DataSetVariable.HTML)) {
            fieldMetaDataJSON.put("type", "auto");
            fieldMetaDataJSON.remove("type");
            fieldMetaDataJSON.put("subtype", "html");
          }
         
        }
       
        if(detailProperty != null && fieldHeader.equalsIgnoreCase(detailProperty)) {
          metadata.put("detailProperty", fieldName);
          fieldMetaDataJSON.put("hidden", true);
        }
       
        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);
       
        for(int i = 0; i < dataStore.getMetaData().getFieldCount(); i++) {
          IFieldMetaData fieldMetaData = dataStore.getMetaData().getFieldMeta(i);
         
          propertyRawValue = fieldMetaData.getProperty("visible");
          if(propertyRawValue != null
              && (propertyRawValue instanceof Boolean)
              && ((Boolean)propertyRawValue).booleanValue() == false) {
            continue;
          }
          String key = fieldMetaData.getAlias() != null ? fieldMetaData.getAlias() : fieldMetaData.getName();
          field = record.getFieldAt( dataStore.getMetaData().getFieldIndex( key ) );
         
         
         
          String fieldValue = "";
          if(field.getValue() != null) {
            if(Timestamp.class.isAssignableFrom(fieldMetaData.getType())) {
              fieldValue =  TIMESTAMP_FORMATTER.formatfield.getValue() );
            } else if (Date.class.isAssignableFrom(fieldMetaData.getType())) {
              fieldValue =  DATE_FORMATTER.formatfield.getValue() );
            } else {
              fieldValue =  field.getValue().toString();
            }
          }
         
         
          recordJSON.put("column_" + (i+1), fieldValue);
View Full Code Here

 
 
  public Object serialize(Object o, Locale locale) throws SerializationException {
    JSONObject  result = null;
    JSONObject metadata;
    IField field;
    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);
       
        for(int i = 0; i < metadata.getJSONArray("fields").length(); i++) {
          field = record.getFieldAt(i);
          recordJSON.put("column-" + (i+1), field.getValue().toString());
        }
       
        recordsJSON.put(recordJSON);
      }
     
View Full Code Here


        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() );
      String id = (String)field.getValue();
      //String id = (String)it.next();



      //Map kpiValueMap = (Map)values.get(id);

      String centroideId = "centroidi_" + datamart.getTargetFeatureName() + "_"  + id;
      Element centroide = targetMap.getElementById( centroideId );
      if( centroide != null ) {
        List fields = record.getFields();
        int line = 0;
        Element labelGroup = null;
        if(fields.size()>0) labelGroup = masterMap.createElement("g");
        boolean isFirst = true;
        for(int i = 0; i < fields.size(); i++) {
          if(i == dataStoreMeta.getIdFieldIndex()) continue;

          field = (IField)fields.get(i);
          String fieldName = dataStoreMeta.getFieldName(i);
          //String tmpKpiName = (String)kpiValueIterator.next();


          Measure kpi  = getMeasure( fieldName );
          String kpiValue = "" + field.getValue();
          labelGroup.setAttribute("transform", "translate(" + centroide.getAttribute("cx") + "," + centroide.getAttribute("cy")+ ") scale(40)");
          labelGroup.setAttribute("display", "inherit");

          Element label = masterMap.createElement("text");
          label.setAttribute("x", "0");
View Full Code Here

        List fields = record.getFields();
        for(int j = 0; j < fields.size(); j++) {
          if(j == dataStore.getMetaData().getIdFieldIndex() ) {
            continue;
          }
          IField field = (IField)fields.get(j);
          child.setAttribute("attrib:" + dataStore.getMetaData().getFieldName(j), "" + field.getValue());
        }
        child.setAttribute("attrib:nome", child.getAttribute("id"));

      }
    }
View Full Code Here

TOP

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

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.