use of org.pentaho.metadata.model.concept.types.Alignment 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;
}
Aggregations