Search in sources :

Example 1 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project pentaho-kettle by pentaho.

the class DimensionTableDialog method addAttribute.

private void addAttribute(String name, String description, String phName, AttributeType attributeType, DataType dataType, int length, int precision, String comment) {
    LogicalColumn column = new LogicalColumn();
    column.setLogicalTable(logicalTable);
    column.setName(new LocalizedString(locale, name));
    column.setDescription(new LocalizedString(locale, description));
    column.setDataType(dataType);
    column.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, attributeType.name());
    column.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, phName);
    if (length >= 0)
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, Integer.toString(length));
    if (precision >= 0)
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_PRECISION, Integer.toString(precision));
    column.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, comment);
    addLogicalColumnToAttributesList(column);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 2 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project pentaho-kettle by pentaho.

the class ModelerHelper method createEmptyModel.

public void createEmptyModel() {
    try {
        StarDomain starDomain = new StarDomain();
        starDomain.getDomain().setName(new LocalizedString(defaultLocale, "Star model domain"));
        starDomain.getDomain().setDescription(new LocalizedString(defaultLocale, "This star model domain contains multiple star models for the same subject domain"));
        StarModelerPerspective.getInstance().createTabForDomain(starDomain);
        SpoonPerspectiveManager.getInstance().activatePerspective(StarModelerPerspective.class);
    } catch (Exception e) {
        new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), "Error", "Error creating visualization", e);
    }
}
Also used : Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 3 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project pentaho-kettle by pentaho.

the class StarModelDialog method addDimensionKeys.

protected void addDimensionKeys() {
    // Import the technical keys from all the dimensions in the fact table...
    // 
    List<LogicalColumn> keyColumns = new ArrayList<LogicalColumn>();
    List<LogicalTable> dimensionTables = ConceptUtil.findLogicalTables(logicalModel, TableType.DIMENSION);
    for (LogicalTable dimensionTable : dimensionTables) {
        // Find the technical or smart key
        // 
        keyColumns.addAll(ConceptUtil.findLogicalColumns(dimensionTable, AttributeType.SMART_TECHNICAL_KEY));
        keyColumns.addAll(ConceptUtil.findLogicalColumns(dimensionTable, AttributeType.TECHNICAL_KEY));
    }
    for (LogicalColumn keyColumn : keyColumns) {
        LogicalColumn column = new LogicalColumn();
        String dimensionName = ConceptUtil.getName(keyColumn.getLogicalTable(), locale);
        column.setName(new LocalizedString(locale, dimensionName + " TK"));
        column.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(keyColumn, locale)));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, dimensionName.toLowerCase().replace(' ', '_') + "_tk");
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, AttributeType.TECHNICAL_KEY.name());
        column.setDataType(keyColumn.getDataType());
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME, dimensionName);
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, ConceptUtil.getString(keyColumn, DefaultIDs.LOGICAL_COLUMN_LENGTH));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, ConceptUtil.getString(keyColumn, DefaultIDs.LOGICAL_COLUMN_LENGTH));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, "Key to dimension '" + dimensionName + "'");
        addLogicalColumnToFactAttributesList(column);
    }
    wFactAttributes.removeEmptyRows();
    wFactAttributes.setRowNums();
    wFactAttributes.optWidth(true);
    getRelationshipsFromFact();
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) ArrayList(java.util.ArrayList) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 4 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testFindDimensionWithName.

@Test
public void testFindDimensionWithName() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final String dn = "dn";
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable1.getProperty(eq(Concept.NAME_PROPERTY))).thenReturn(new LocalizedString(locale, "wrong name"));
    final LogicalTable logicalTable2 = mock(LogicalTable.class);
    when(logicalTable2.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.FACT);
    final LogicalTable logicalTable3 = mock(LogicalTable.class);
    when(logicalTable3.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable3.getProperty(eq(Concept.NAME_PROPERTY))).thenReturn(new LocalizedString(locale, dn));
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    assertNull(ConceptUtil.findDimensionWithName(logicalModel, dn, "other_locale"));
    assertNull(ConceptUtil.findDimensionWithName(logicalModel, "dn2", locale));
    final LogicalTable dimensionWithName = ConceptUtil.findDimensionWithName(logicalModel, dn, locale);
    assertEquals(logicalTable3, dimensionWithName);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Test(org.junit.Test)

Example 5 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project pentaho-platform by pentaho.

the class PMDUIComponent method getLookup.

public Document getLookup() {
    // Create a document that describes the result
    Document doc = DocumentHelper.createDocument();
    // $NON-NLS-1$
    Element root = doc.addElement("metadata");
    if (domainName == null) {
        // we can't do this without a model
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_DOMAIN_SPECIFIED"));
        return doc;
    }
    if (modelId == null) {
        // we can't do this without a view
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_MODEL_SPECIFIED"));
        return doc;
    }
    if (columnId == null) {
        // we can't do this without a view
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_COLUMN_SPECIFIED"));
        return doc;
    }
    Domain domain = getMetadataRepository().getDomain(domainName);
    String locale = LocaleHelper.getClosestLocale(LocaleHelper.getLocale().toString(), domain.getLocaleCodes());
    // This is the business view that was selected.
    LogicalModel model = domain.findLogicalModel(modelId);
    if (model == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_MODEL_LOADING_ERROR", modelId));
        return doc;
    }
    LogicalColumn column = model.findLogicalColumn(columnId);
    if (column == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_COLUMN_NOT_FOUND"));
        return doc;
    }
    // Temporary hack to get the BusinessCategory. When fixed properly, you should be able to interrogate the
    // business column thingie for it's containing BusinessCategory.
    Category view = null;
    for (Category category : model.getCategories()) {
        for (LogicalColumn col : category.getLogicalColumns()) {
            if (col.getId().equals(column.getId())) {
                view = category;
                break;
            }
        }
    }
    if (view == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_VIEW_NOT_FOUND"));
        return doc;
    }
    String mql = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "<mql><domain_type>relational</domain_type><domain_id>" + domainName + "</domain_id><model_id>" + modelId + "</model_id>";
    if (column.getProperty("lookup") == null) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        mql += "<selection><view>" + view.getId() + "</view><column>" + column.getId() + "</column></selection>";
        mql += // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "<orders><order><direction>asc</direction><view_id>" + view.getId() + "</view_id><column_id>" + column.getId() + "</column_id></order></orders>";
    } else {
        // $NON-NLS-1$
        String lookup = (String) column.getProperty("lookup");
        // assume model and view are the same...
        // $NON-NLS-1$
        StringTokenizer tokenizer1 = new StringTokenizer(lookup, ";");
        while (tokenizer1.hasMoreTokens()) {
            // $NON-NLS-1$
            StringTokenizer tokenizer2 = new StringTokenizer(tokenizer1.nextToken(), ".");
            if (tokenizer2.countTokens() == 2) {
                String lookupViewId = tokenizer2.nextToken();
                String lookupColumnId = tokenizer2.nextToken();
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                mql += "<selection><view>" + lookupViewId + "</view><column>" + lookupColumnId + "</column></selection>";
            }
        }
    }
    // $NON-NLS-1$
    mql += "</mql>";
    ArrayList messages = new ArrayList();
    SimpleParameterProvider lookupParameters = new SimpleParameterProvider();
    // $NON-NLS-1$
    lookupParameters.setParameter("mql", mql);
    IRuntimeContext runtime = SolutionHelper.doAction("/system/metadata/PickList.xaction", "lookup-list", lookupParameters, getSession(), messages, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    this);
    IPentahoResultSet results = null;
    if (runtime != null) {
        if (runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
            if (runtime.getOutputNames().contains("data")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                results = runtime.getOutputParameter("data").getValueAsResultSet();
                Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
                boolean hasColumnHeaders = columnHeaders != null;
                Element rowElement;
                // $NON-NLS-1$
                Element dataElement = root.addElement("data");
                if (hasColumnHeaders) {
                    for (int rowNo = 0; rowNo < columnHeaders.length; rowNo++) {
                        // $NON-NLS-1$
                        rowElement = dataElement.addElement("COLUMN-HDR-ROW");
                        for (int columnNo = 0; columnNo < columnHeaders[rowNo].length; columnNo++) {
                            // $NON-NLS-1$
                            Object nameAttr = results.getMetaData().getAttribute(rowNo, columnNo, "name");
                            if ((nameAttr != null) && (nameAttr instanceof LocalizedString)) {
                                LocalizedString str = (LocalizedString) nameAttr;
                                String name = str.getLocalizedString(locale);
                                if (name != null) {
                                    // $NON-NLS-1$
                                    rowElement.addElement("COLUMN-HDR-ITEM").setText(name);
                                } else {
                                    // $NON-NLS-1$
                                    rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
                                }
                            } else {
                                // $NON-NLS-1$
                                rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
                            }
                        }
                    }
                }
                Object[] row = results.next();
                while (row != null) {
                    // $NON-NLS-1$
                    rowElement = dataElement.addElement("DATA-ROW");
                    for (Object element : row) {
                        if (element == null) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            rowElement.addElement("DATA-ITEM").setText("");
                        } else {
                            // $NON-NLS-1$
                            rowElement.addElement("DATA-ITEM").setText(element.toString());
                        }
                    }
                    row = results.next();
                }
            }
        }
    }
    return doc;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Document(org.dom4j.Document) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StringTokenizer(java.util.StringTokenizer) Domain(org.pentaho.metadata.model.Domain) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)25 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)8 Domain (org.pentaho.metadata.model.Domain)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Category (org.pentaho.metadata.model.Category)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 TableItem (org.eclipse.swt.widgets.TableItem)3 Matchers.anyString (org.mockito.Matchers.anyString)3 List (java.util.List)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 Concept (org.pentaho.metadata.model.concept.Concept)2