// 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;
}
fieldMetaDataJSON = new JSONObject();
fieldMetaDataJSON.put("header", "Values");
fieldMetaDataJSON.put("name", "Values" );
fieldMetaDataJSON.put("dataIndex", "Values");
Class clazz = fieldMetaData.getType();
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");
}
} else if( String.class.isAssignableFrom(clazz) ) {
logger.debug("Column [" + (i+1) + "] type is equal to [" + "STRING" + "]");
fieldMetaDataJSON.put("type", "string");
} 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 H:i:s");
} 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");
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");
}
}
fieldsMetaDataJSON.put(fieldMetaDataJSON);
}
fieldsMetaDataJSON.put("recCk");
metadata.put("fields", fieldsMetaDataJSON);
// records
recNo = 0;
Iterator records = dataStore.iterator();
while(records.hasNext()) {
record = (IRecord)records.next();
recordJSON = new JSONObject();
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 && !field.getValue().equals("")) {
if(Date.class.isAssignableFrom(fieldMetaData.getType())) {
fieldValue = DATE_FORMATTER.format( field.getValue() );
} else {
fieldValue = field.getValue().toString();
}
}