Search in sources :

Example 26 with LogicalColumn

use of org.pentaho.metadata.model.LogicalColumn in project data-access by pentaho.

the class GuiStateModelTest method test.

@Test
public void test() {
    GuiStateModel guiStateModel = new GuiStateModel();
    Assert.assertEquals(0, guiStateModel.getConnections().size());
    Assert.assertEquals(false, guiStateModel.isRelationalValidated());
    IDatabaseConnection connection = new DatabaseConnection();
    connection.setAccessType(DatabaseAccessType.NATIVE);
    // connection.setDriverClass("org.hsqldb.jdbcDriver");
    connection.setName("SampleData");
    connection.setPassword("password");
    // connection.setUrl("jdbc:hsqldb:file:target/test-classes/solution1/system/data/sampledata");
    connection.setUsername("pentaho_user");
    List<IDatabaseConnection> connectionList = new ArrayList<IDatabaseConnection>();
    connectionList.add(connection);
    guiStateModel.setConnections(connectionList);
    guiStateModel.setPreviewLimit("10");
    guiStateModel.validateRelational();
    Assert.assertEquals(true, guiStateModel.isRelationalPreviewValidated());
    // Assert.assertEquals(false, relationalModel.isValidated());
    LogicalColumn logColumn = new LogicalColumn();
    logColumn.setDataType(DataType.NUMERIC);
    List<AggregationType> aggTypeList = new ArrayList<AggregationType>();
    aggTypeList.add(AggregationType.AVERAGE);
    logColumn.setAggregationList(aggTypeList);
    logColumn.setName(new LocalizedString("En", "Column1"));
    BusinessData businessData = new BusinessData();
    List<List<String>> dataSample = new ArrayList<List<String>>();
    List<String> rowData = new ArrayList<String>();
    rowData.add("Data1");
    rowData.add("Data2");
    rowData.add("Data3");
    rowData.add("Data4");
    dataSample.add(rowData);
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalTable.addLogicalColumn(logicalColumn);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString(locale, "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    List<LocaleType> localeTypeList = new ArrayList<LocaleType>();
    localeTypeList.add(new LocaleType("Code", "Locale Description"));
    domain.setLocales(localeTypeList);
    businessData.setData(dataSample);
    businessData.setDomain(domain);
    guiStateModel.setLogicalModels(domain.getLogicalModels());
    guiStateModel.setLocaleCode("en");
    Assert.assertEquals(true, guiStateModel.isRelationalValidated());
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) LogicalModel(org.pentaho.metadata.model.LogicalModel) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 27 with LogicalColumn

use of org.pentaho.metadata.model.LogicalColumn 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)

Example 28 with LogicalColumn

use of org.pentaho.metadata.model.LogicalColumn in project data-access by pentaho.

the class MetadataServiceTest method initialize.

@Before
public void initialize() {
    List<Category> categoryList = new ArrayList();
    Category category = mock(Category.class);
    when(category.getId()).thenReturn(CATEGORY_ID);
    categoryList.add(category);
    LogicalColumn logicalColumn = mock(LogicalColumn.class);
    when(logicalColumn.getId()).thenReturn(COLUMN_ID);
    when(logicalColumn.getDataType()).thenReturn(DataType.STRING);
    when(category.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    logicalModel = mock(LogicalModel.class);
    when(logicalModel.getId()).thenReturn(LOGICAL_MODEL_ID);
    when(logicalModel.getName(anyString())).thenReturn(LOGICAL_MODEL_NAME);
    when(logicalModel.getCategories()).thenReturn(categoryList);
    when(logicalModel.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    when(logicalModel.getProperty(anyString())).thenReturn(null);
    logicalModel2 = mock(LogicalModel.class);
    when(logicalModel2.getId()).thenReturn(LOGICAL_MODEL_2_ID);
    when(logicalModel2.getName(anyString())).thenReturn(LOGICAL_MODEL_2_NAME);
    when(logicalModel2.getProperty(anyString())).thenReturn(null);
    Domain domainOnlyReportingModel = new Domain();
    domainOnlyReportingModel.setId(DOMAIN_ID);
    domainOnlyReportingModel.setLogicalModels(new ArrayList<LogicalModel>() {

        {
            add(logicalModel2);
        }

        {
            add(logicalModel);
        }
    });
    iMetadataDomainRepository = mock(IMetadataDomainRepository.class);
    when(iMetadataDomainRepository.getDomain(DOMAIN_ID)).thenReturn(domainOnlyReportingModel);
    Set<String> domains = new HashSet<String>();
    domains.add(DOMAIN_ID);
    when(iMetadataDomainRepository.getDomainIds()).thenReturn(domains);
    metadataService = mock(MetadataService.class);
    when(metadataService.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    metadataServiceUtil = mock(MetadataServiceUtil.class);
    when(metadataServiceUtil.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    when(metadataServiceUtil.createThinModel(any(LogicalModel.class), anyString())).thenCallRealMethod();
    when(metadataService.getMetadataServiceUtil()).thenReturn(metadataServiceUtil);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalModel(org.pentaho.metadata.model.LogicalModel) Domain(org.pentaho.metadata.model.Domain) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 29 with LogicalColumn

use of org.pentaho.metadata.model.LogicalColumn in project data-access by pentaho.

the class MultitableGuiModel method generateLogicalRelationships.

@Deprecated
public List<LogicalRelationship> generateLogicalRelationships(List<JoinRelationshipModel> joins) {
    String locale = LocalizedString.DEFAULT_LOCALE;
    List<LogicalRelationship> logicalRelationships = new ArrayList<LogicalRelationship>();
    for (JoinRelationshipModel join : joins) {
        LogicalTable fromTable = new LogicalTable();
        fromTable.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getParentTable().getName()));
        LogicalTable toTable = new LogicalTable();
        toTable.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getParentTable().getName()));
        LogicalColumn fromColumn = new LogicalColumn();
        fromColumn.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getName()));
        LogicalColumn toColumn = new LogicalColumn();
        toColumn.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getName()));
        LogicalRelationship logicalRelationship = new LogicalRelationship();
        logicalRelationship.setFromTable(fromTable);
        logicalRelationship.setToTable(toTable);
        logicalRelationship.setFromColumn(fromColumn);
        logicalRelationship.setToColumn(toColumn);
        logicalRelationships.add(logicalRelationship);
    }
    return logicalRelationships;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) ArrayList(java.util.ArrayList) JoinRelationshipModel(org.pentaho.agilebi.modeler.models.JoinRelationshipModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship)

Example 30 with LogicalColumn

use of org.pentaho.metadata.model.LogicalColumn in project data-access by pentaho.

the class DatasourceModel method copyOverMetadata.

/**
 * This is a utility method that looks into an old domain for the same column ids, and then copies over the old
 * metadata into the new.
 *
 * @param oldDomain
 * @param newDomain
 */
public void copyOverMetadata(Domain oldDomain, Domain newDomain) {
    Category category = newDomain.getLogicalModels().get(0).getCategories().get(0);
    LogicalModel oldModel = oldDomain.getLogicalModels().get(0);
    for (LogicalColumn column : category.getLogicalColumns()) {
        LogicalColumn oldColumn = oldModel.findLogicalColumn(column.getId());
        if (oldColumn != null) {
            column.setDataType(oldColumn.getDataType());
            column.setName(oldColumn.getName());
            column.setAggregationList(oldColumn.getAggregationList());
            column.setAggregationType(oldColumn.getAggregationType());
        }
    }
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category)

Aggregations

LogicalColumn (org.pentaho.metadata.model.LogicalColumn)30 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)16 LogicalTable (org.pentaho.metadata.model.LogicalTable)12 ArrayList (java.util.ArrayList)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)9 Domain (org.pentaho.metadata.model.Domain)8 Category (org.pentaho.metadata.model.Category)7 Test (org.junit.Test)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)4 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)4 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)4 Point (org.pentaho.di.core.gui.Point)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 List (java.util.List)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 TableItem (org.eclipse.swt.widgets.TableItem)2