Search in sources :

Example 1 with FieldType

use of org.pentaho.metadata.model.concept.types.FieldType in project data-access by pentaho.

the class MetadataServiceUtil method createColumn.

/**
 * Creates a lightweight, serializable Column object from a logical model column
 *
 * @param m
 * @param c
 * @return
 */
private Column createColumn(LogicalModel m, LogicalColumn c, org.pentaho.metadata.model.Category category) {
    Column col = new Column();
    col.setName(c.getName(getLocale()));
    col.setId(c.getId());
    if (c.getFieldType() != null) {
        col.setFieldType(c.getFieldType().name());
    } else {
        // $NON-NLS-1$
        col.setFieldType("UNKNOWN");
    }
    col.setType(c.getDataType().getName().toUpperCase());
    col.setCategory(category.getId());
    // set the aggregation fields for the column
    List<AggregationType> possibleAggs = c.getAggregationList();
    List<String> aggTypes = new ArrayList<String>();
    if (possibleAggs != null) {
        for (AggregationType agg : possibleAggs) {
            aggTypes.add(agg.name());
        }
    }
    // There might be a default agg, but no agg list. If so, add it to the list.
    AggregationType defaultAggType = AggregationType.NONE;
    if (c.getAggregationType() != null) {
        defaultAggType = c.getAggregationType();
    }
    if (!aggTypes.contains(defaultAggType)) {
        aggTypes.add(defaultAggType.name());
    }
    col.setAggTypes(aggTypes);
    col.setDefaultAggType(defaultAggType.name());
    col.setSelectedAggType(defaultAggType.name());
    // set the alignment
    DataType dataType = c.getDataType();
    FieldType fieldType = c.getFieldType();
    // $NON-NLS-1$
    Object obj = c.getProperty("alignment");
    if (obj instanceof Alignment) {
        if (obj == Alignment.LEFT) {
            col.setHorizontalAlignment(Alignment.LEFT.toString());
        } else if (obj == Alignment.RIGHT) {
            col.setHorizontalAlignment(Alignment.RIGHT.toString());
        } else if (obj == Alignment.CENTERED) {
            col.setHorizontalAlignment(Alignment.CENTERED.toString());
        }
    } else if (fieldType == FieldType.FACT) {
        col.setHorizontalAlignment(Alignment.RIGHT.toString());
    } else if (fieldType == FieldType.OTHER && dataType == DataType.NUMERIC) {
        col.setHorizontalAlignment(Alignment.RIGHT.toString());
    } else {
        col.setHorizontalAlignment(Alignment.LEFT.toString());
    }
    // set the format mask
    // $NON-NLS-1$
    obj = c.getProperty("mask");
    if (obj != null) {
        col.setFormatMask((String) obj);
    }
    return col;
}
Also used : Alignment(org.pentaho.metadata.model.concept.types.Alignment) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) IPhysicalColumn(org.pentaho.metadata.model.IPhysicalColumn) Column(org.pentaho.platform.dataaccess.metadata.model.impl.Column) ArrayList(java.util.ArrayList) DataType(org.pentaho.metadata.model.concept.types.DataType) JSONObject(org.json.JSONObject) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) FieldType(org.pentaho.metadata.model.concept.types.FieldType)

Aggregations

ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1 IPhysicalColumn (org.pentaho.metadata.model.IPhysicalColumn)1 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)1 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)1 Alignment (org.pentaho.metadata.model.concept.types.Alignment)1 DataType (org.pentaho.metadata.model.concept.types.DataType)1 FieldType (org.pentaho.metadata.model.concept.types.FieldType)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1 Column (org.pentaho.platform.dataaccess.metadata.model.impl.Column)1