Java Code Examples for org.pentaho.metadata.model.concept.types.LocalizedString

The following examples show how to use org.pentaho.metadata.model.concept.types.LocalizedString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected void exportLocalizedPropertiesRecursively( Properties props, IConcept parent, String locale ) {
  for ( String propName : parent.getChildProperties().keySet() ) {
    if ( parent.getChildProperty( propName ) instanceof LocalizedString ) {
      // externalize string
      String key = stringizeTokens( parent.getUniqueId() ) + ".[" + escapeKey( propName ) + "]";
      LocalizedString lstr = (LocalizedString) parent.getChildProperty( propName );
      String value = lstr.getLocalizedString( locale );
      if ( value == null ) {
        value = "";
      }
      props.setProperty( key, value );
    }
  }
  if ( parent.getChildren() != null ) {
    for ( IConcept child : parent.getChildren() ) {
      exportLocalizedPropertiesRecursively( props, child, locale );
    }
  } else {
    if ( logger.isDebugEnabled() ) {
      logger.debug( "concept " + stringizeTokens( parent.getUniqueId() ) + " does not have children" );
    }
  }
}
 
Example 2
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean copyTable(Shell shell, LogicalModel logicalModel, String tableName) {

    LogicalTable originalTable = findLogicalTable(tableName);
    if (originalTable!=null) {
      // Copy
      //
      LogicalTable logicalTable = new LogicalTable();
      logicalTable.setId(UUID.randomUUID().toString());
      logicalTable.setName(new LocalizedString(locale, ConceptUtil.getName(originalTable, locale)+" (Copy)"));
      logicalTable.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(originalTable, locale)+" (Copy)"));
      logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, originalTable.getProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME));
      logicalTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), originalTable.getProperty(DefaultPropertyID.TABLE_TYPE.getId()));
      for (LogicalColumn column : originalTable.getLogicalColumns()) {
        logicalTable.getLogicalColumns().add((LogicalColumn) column.clone());
      }

      DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
      if (dialog.open()!=null) {
        logicalModel.addLogicalTable(logicalTable);
        return true;
      }
    }
    return false;
  }
 
Example 3
/**
 * @param value
 * @param type
 * @return
 */
public Object getValue( final Object value, final Class type, final DataAttributeContext context ) {
  if ( value == null ) {
    return null;
  }

  if ( value instanceof LocalizedString == false ) {
    return null;
  }

  if ( type == null || Object.class.equals( type ) || LocalizedString.class.equals( type ) ) {
    if ( value instanceof LocalizedStringWrapper ) {
      return value;
    }
    return new LocalizedStringWrapper( (LocalizedString) value );
  }

  if ( String.class.equals( type ) == false ) {
    return null;
  }

  final LocalizedString settings = (LocalizedString) value;
  final Locale locale = context.getLocale();
  final String localeAsText = locale.toString();
  final Object o = settings.getLocalizedString( localeAsText );
  if ( o == null ) {
    logger.warn( "Unable to translate localized-string property for locale [" + locale + "]. "
      + "The localization does not contain a translation for this locale and does not provide a fallback." );
  }
  return o;
}
 
Example 4
@Override
public boolean equals( final Object object ) {
  if ( object == null ) {
    return false;
  }
  if ( object instanceof LocalizedString == false ) {
    return false;
  }
  return backend.equals( object );
}
 
Example 5
private LogicalTable createBusinessTable( SqlPhysicalTable physicalTable, String locale ) {

    // Create a business table with a new ID and localized name
    //
    LogicalTable businessTable = new LogicalTable( null, physicalTable );

    // Try to set the name of the business table to something nice (beautify)
    //
    String tableName = PhysicalTableImporter.beautifyName( physicalTable.getTargetTable() );
    businessTable.setName( new LocalizedString( locale, tableName ) );

    businessTable.setId( Util.proposeSqlBasedLogicalTableId( locale, businessTable, physicalTable ) );

    // Add columns to this by copying the physical columns to the business
    // columns...
    //
    for ( IPhysicalColumn physicalColumn : physicalTable.getPhysicalColumns() ) {

      LogicalColumn businessColumn = new LogicalColumn();
      businessColumn.setPhysicalColumn( physicalColumn );
      businessColumn.setLogicalTable( businessTable );

      // We're done, add the business column.
      //
      // Propose a new ID
      businessColumn.setId( Util.proposeSqlBasedLogicalColumnId( locale, businessTable,
          (SqlPhysicalColumn) physicalColumn ) );
      businessTable.addLogicalColumn( businessColumn );
    }

    return businessTable;
  }
 
Example 6
public String getName( String locale ) {
  LocalizedString locName = getName();
  if ( locName == null ) {
    return getId();
  }
  String name = locName.getLocalizedString( locale );
  if ( name == null || name.trim().length() == 0 ) {
    return getId();
  }
  return name;
}
 
Example 7
public String getDescription( String locale ) {
  LocalizedString locDesc = getDescription();
  if ( locDesc == null ) {
    return getId();
  }
  String name = locDesc.getLocalizedString( locale );
  if ( name == null || name.trim().length() == 0 ) {
    return getId();
  }
  return name;
}
 
Example 8
public SqlPhysicalTable() {
  super();
  setTargetTableType( TargetTableType.TABLE );
  // physical table has the following default properties:
  setName( new LocalizedString() );
  setDescription( new LocalizedString() );
}
 
Example 9
public SqlPhysicalColumn() {
  super();
  setTargetColumnType( TargetColumnType.COLUMN_NAME );
  // physical column has the following default properties:
  setName( new LocalizedString() );
  setDescription( new LocalizedString() );
}
 
Example 10
public PropertyTypeRegistry() {
  // load these from a spring config file?
  addPropertyType( String.class );
  addPropertyType( LocalizedString.class );
  addPropertyType( DataType.class );
  addPropertyType( TargetTableType.class );
  addPropertyType( TargetColumnType.class );
  addPropertyType( AggregationType.class );

  // this is for agg lists,
  // we will need another way to express lists
  addPropertyType( List.class );

  addPropertyType( Alignment.class );
  addPropertyType( Color.class );
  addPropertyType( ColumnWidth.class );
  addPropertyType( FieldType.class );
  addPropertyType( Font.class );
  addPropertyType( TableType.class );
  addPropertyType( RowLevelSecurity.class );
  addPropertyType( Security.class );
  addPropertyType( Double.class );
  addPropertyType( Boolean.class );
  addPropertyType( Date.class );

  // note that URL is not GWT compatible, we'll need to figure out what to do with this
  // once we move towards a fully supported thin client metadata editor
  addPropertyType( URL.class );

}
 
Example 11
@Test
public void testImportExportOfMultibyteChars() throws Exception {
  // 日本語

  XmiParser parser = new XmiParser();
  Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/simple_model.xmi" ) );
  Category category = new Category( domain.getLogicalModels().get( 0 ) );
  category.setId( "TEST_WITH_日本語_CHARS" );
  LocalizedString str = new LocalizedString( "en_US", "日本語" );
  category.setName( str );
  domain.getLogicalModels().get( 0 ).addCategory( category );

  LocalizationUtil util = new LocalizationUtil();
  Properties props = util.exportLocalizedProperties( domain, "en_US" );

  Assert.assertEquals( props.getProperty( "[LogicalModel-BV_MODEL_1].[Category-TEST_WITH_日本語_CHARS].[name]" ),
      "日本語" );

  props.setProperty( "[LogicalModel-BV_MODEL_1].[name]", "日本語" );
  props
      .setProperty( "[LogicalModel-BV_MODEL_1].[Category-TEST_WITH_日本語_CHARS].[name]", "2nd Version 日本語" );

  Assert.assertEquals( "en_US", domain.getLocales().get( 0 ).getCode() );

  util.importLocalizedProperties( domain, props, "jp" );

  Assert.assertEquals( "en_US", domain.getLocales().get( 0 ).getCode() );
  Assert.assertEquals( "jp", domain.getLocales().get( 1 ).getCode() );

  Assert.assertEquals( domain.getLogicalModels().get( 0 ).getName( "jp" ), "日本語" );
  Assert.assertEquals( domain.getLogicalModels().get( 0 ).getCategories().get( 1 ).getName( "jp" ),
      "2nd Version 日本語" );
}
 
Example 12
@Test
public void testDescriptions() throws Exception {
  LogicalModel businessModel = getTestModel( TargetTableType.TABLE, "table", "schema" );
  @SuppressWarnings( "unchecked" )
  List<OlapCube> cubes = (List<OlapCube>) businessModel.getProperty( LogicalModel.PROPERTY_OLAP_CUBES );
  OlapMeasure measure = cubes.get( 0 ).getOlapMeasures().get( 0 );
  measure.getLogicalColumn().setDescription( new LocalizedString( "en_US", "it's a measure" ) );
  OlapHierarchyLevel level =
      cubes.get( 0 ).getOlapDimensionUsages().get( 0 ).getOlapDimension().getHierarchies().get( 0 )
          .getHierarchyLevels().get( 0 );
  OlapAnnotation description = new OlapAnnotation();
  description.setName( "description.en_US" );
  description.setValue( "description with > in there" );
  level.getAnnotations().add( description );

  MondrianModelExporter exporter = new MondrianModelExporter( businessModel, "en_US" );
  final String schema = exporter.createMondrianModelXML();

  TestHelper.assertEqualsIgnoreWhitespaces(
      "<Schema name=\"model\">\n"
          + "  <Dimension name=\"Dim1\">\n"
          + "    <Hierarchy name=\"Hier1\" hasAll=\"false\">\n"
          + "      <Table name=\"table\" schema=\"schema\"/>\n"
          + "      <Level name=\"Lvl1\" uniqueMembers=\"false\" column=\"pc1\" type=\"Numeric\">\n"
          + "        <Annotations>\n"
          + "          <Annotation name=\"description.en_US\">description with &gt; in there</Annotation>\n"
          + "        </Annotations>\n"
          + "      </Level>\n"
          + "    </Hierarchy>\n"
          + "  </Dimension>\n"
          + "  <Cube name=\"Cube1\">\n"
          + "    <Table name=\"table\" schema=\"schema\"/>\n"
          + "    <DimensionUsage name=\"Dim1\" source=\"Dim1\" foreignKey=\"pc2\"/>\n"
          + "    <Measure name=\"bc1\" column=\"pc1\" aggregator=\"sum\" description=\"it&#39;s a measure\"/>\n"
          + "  </Cube>\n" + "</Schema>", schema );
}
 
Example 13
Source Project: pentaho-kettle   Source File: MetadataGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private String extractId(Concept item) {
  LocalizedString localizedName = item.getName();
  Set<String> locales = localizedName.getLocales();
  if (locales.isEmpty()) return "";
  // Just grab the first locale we come across
  // This should normally only one for the star modeler
  //
  String locale = locales.iterator().next();

  String id = localizedName.getLocalizedString(locale);
  id = id.toUpperCase().replace(" ", "_");

  return id;
}
 
Example 14
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 15
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean newTable(Shell shell, LogicalModel logicalModel) {
  LogicalTable logicalTable = new LogicalTable(logicalModel, null);
  logicalTable.setId(UUID.randomUUID().toString());
  logicalTable.setName(new LocalizedString(locale, "New table"));
  logicalTable.setDescription(new LocalizedString(locale, "New table description"));

  DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
  if (dialog.open()!=null) {
    logicalModel.addLogicalTable(logicalTable);
    return true;
  }
  return false;
}
 
Example 16
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void ok() {

    if (Utils.isEmpty(wModelName.getText())) {
      MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
      box.setText(BaseMessages.getString(PKG, "StarModelDialog.ErrorModelHasNoName.Title"));
      box.setMessage(BaseMessages.getString(PKG, "StarModelDialog.ErrorModelHasNoName.Message"));
      box.open();
      return;
    }

    logicalModel.setName(new LocalizedString(locale, wModelName.getText()));
    logicalModel.setDescription(new LocalizedString(locale, wModelDescription.getText()));

    factTable.setName(new LocalizedString(locale, wFactTableName.getText()));
    factTable.setDescription(new LocalizedString(locale, wFactTableDescription.getText()));
    factTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, wPhysicalFactName.getText());

    String factName = ConceptUtil.getName(factTable, locale);
    System.out.println("Fact name = "+factName+" has "+factTable.getLogicalColumns().size()+" columns");

    // Add the relationships informational
    //
    getRelationshipsFromFact();
    logicalModel.getLogicalRelationships().clear();
    logicalModel.getLogicalRelationships().addAll(logicalRelationships);

    // System.out.println("Fact name = "+factName+" has "+factTable.getLogicalColumns().size()+" columns");

    // If the fact table is not yet in the table list, add it.
    // If it is, replace it.
    //
    int factIndex = ConceptUtil.indexOfFactTable(logicalModel);
    if (factIndex<0) {
      logicalModel.getLogicalTables().add(factTable);
    }

    System.out.println("Fact name = "+factName+" has "+factTable.getLogicalColumns().size()+" columns");

    dispose();
  }
 
Example 17
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void getFactColumns() {
  factTable.getLogicalColumns().clear();
  int nr = wFactAttributes.nrNonEmpty();
  for (int i=0;i<nr;i++) {
    TableItem item = wFactAttributes.getNonEmpty(i);
    LogicalColumn logicalColumn = new LogicalColumn();

    int col=1;
    logicalColumn.setId(UUID.randomUUID().toString());
    logicalColumn.setName(new LocalizedString(locale, item.getText(col++)));
    logicalColumn.setDescription(new LocalizedString(locale, item.getText(col++)));
    String fieldTypeString = item.getText(col++);
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, AttributeType.getAttributeType(fieldTypeString).name());
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, item.getText(col++));
    logicalColumn.setDataType(ConceptUtil.getDataType(item.getText(col++)));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_PRECISION, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_DB, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, item.getText(col++));

    logicalColumn.setLogicalTable(factTable);
    factTable.getLogicalColumns().add(logicalColumn);
  }
}
 
Example 18
Source Project: pentaho-kettle   Source File: ModelerHelper.java    License: Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 19
Source Project: pentaho-kettle   Source File: StarModelerPerspective.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new shared dimension in the domain
 *
 * @param domain the domain to create the new model in
 */
private boolean newSharedDimension(Shell shell, StarDomain starDomain) {
  LogicalTable dimensionTable = new LogicalTable();
  dimensionTable.setName(new LocalizedString(defaultLocale, "Shared dimension"));

  DimensionTableDialog dialog = new DimensionTableDialog(shell, dimensionTable, defaultLocale);
  if (dialog.open()!=null) {
    starDomain.getSharedDimensions().add(dimensionTable);
    starDomain.setChanged(true);
    return true;
  }
  return false;
}
 
Example 20
Source Project: pentaho-kettle   Source File: StarModelerPerspective.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new model in the domain
 *
 * @param domain the domain to create the new model in
 */
private boolean newModel(Shell shell, StarDomain starDomain) {
  LogicalModel model = new LogicalModel();
  model.setName(new LocalizedString(defaultLocale, "Model"));

  StarModelDialog dialog = new StarModelDialog(shell, model, defaultLocale);
  if (dialog.open()!=null) {
    starDomain.getDomain().getLogicalModels().add(model);
    starDomain.setChanged(true);
    return true;
  }
  return false;
}
 
Example 21
Source Project: pentaho-kettle   Source File: DimensionTableDialog.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 22
Source Project: pentaho-kettle   Source File: ModelMetaStoreUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Inflate a logical model from a metastore element.
 *
 * @param metaStore The metastore to read from
 * @param element The element to read from
 * @return The Logical Model
 * @throws MetaStoreException in case something goes wrong
 */
public static LogicalModel buildLogicalModel(IMetaStore metaStore, IMetaStoreElement element) throws MetaStoreException {
  try {
    LogicalModel model = new LogicalModel();

    model.setName(new LocalizedString(defaultLocale, element.getName()));
    model.setDescription(new LocalizedString(defaultLocale, getChildString(element, Attribute.ID_MODEL_DESCRIPTION.id)));



    return model;
  } catch(Exception e) {
    throw new MetaStoreException("Unable to inflate logical model from metastore element", e);
  }
}
 
Example 23
Source Project: pentaho-kettle   Source File: ConceptUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDescription() throws Exception {
  final Concept concept = mock( Concept.class );
  final LocalizedString localizedString = mock( LocalizedString.class );
  final String result = "result";
  when( localizedString.getLocalizedString( eq( locale ) ) ).thenReturn( result );
  when( concept.getProperty( anyString() ) ).thenReturn( localizedString );

  final String description = ConceptUtil.getDescription( concept, locale );

  verify( localizedString, times( 1 ) ).getLocalizedString( eq( locale ) );
  assertEquals( result, description );
}
 
Example 24
Source Project: pentaho-kettle   Source File: ConceptUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetName() throws Exception {
  final Concept concept = mock( Concept.class );
  final LocalizedString localizedString = mock( LocalizedString.class );
  final String result = "result";
  when( localizedString.getLocalizedString( eq( locale ) ) ).thenReturn( result );
  when( concept.getProperty( anyString() ) ).thenReturn( localizedString );

  final String name = ConceptUtil.getName( concept, locale );

  verify( localizedString, times( 1 ) ).getLocalizedString( eq( locale ) );
  assertEquals( result, name );
}
 
Example 25
Source Project: pentaho-kettle   Source File: ConceptUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 );
}
 
Example 26
public LocalizedStringWrapper( final LocalizedString backend ) {
  this.backend = backend;
}
 
Example 27
public void testDataSchemaCompiler() throws Exception {

    final PmdDataFactory pmdDataFactory = new PmdDataFactory();
    pmdDataFactory.setConnectionProvider( new PmdConnectionProvider() );
    pmdDataFactory.setXmiFile( "src/test/resources/metadata/metadata.xmi" );
    pmdDataFactory.setDomainId( "steel-wheels" );
    pmdDataFactory.initialize( new DesignTimeDataFactoryContext() );

    try {
      pmdDataFactory.setQuery( "default", QUERY, null, null );
      final CloseableTableModel tableModel =
        (CloseableTableModel) pmdDataFactory.queryData( "default", new ParameterDataRow() );
      try {
        final DefaultDataSchemaDefinition def = new DefaultDataSchemaDefinition();
        final DataSchemaCompiler compiler = new DataSchemaCompiler( def, new DefaultDataAttributeContext() );
        final DataSchema dataSchema = compiler.compile( tableModel );
        final String[] names = dataSchema.getNames();
        assertEquals( 4, names.length );
        assertEquals( "BC_EMPLOYEES_FIRSTNAME", names[ 0 ] );
        assertEquals( "BC_EMPLOYEES_LASTNAME", names[ 1 ] );
        assertEquals( "BC_EMPLOYEES_EMPLOYEENUMBER", names[ 2 ] );
        assertEquals( "BC_EMPLOYEES_EMAIL", names[ 3 ] );

        final DataAttributes attributes = dataSchema.getAttributes( names[ 2 ] );
        // assert that formatting-label is not a default mapper
        final ConceptQueryMapper mapper = attributes.getMetaAttributeMapper( MetaAttributeNames.Formatting.NAMESPACE,
          MetaAttributeNames.Formatting.LABEL );
        if ( mapper instanceof DefaultConceptQueryMapper ) {
          fail( "Formatting::label should be a LocalizedString instead of a default-mapper" );
        }

        final Object value = attributes.getMetaAttribute( MetaAttributeNames.Formatting.NAMESPACE,
          MetaAttributeNames.Formatting.LABEL, null, new DefaultDataAttributeContext() );
        if ( value instanceof LocalizedString == false ) {
          fail( "Formatting::label should be a LocalizedString" );
        }

        final Object label = attributes.getMetaAttribute( MetaAttributeNames.Formatting.NAMESPACE,
          MetaAttributeNames.Formatting.LABEL, String.class, new DefaultDataAttributeContext( Locale.US ) );
        if ( label instanceof String == false ) {
          fail( "Formatting::label should be a String" );
        }

        final Object elementAlignment = attributes.getMetaAttribute( MetaAttributeNames.Style.NAMESPACE,
          MetaAttributeNames.Style.HORIZONTAL_ALIGNMENT, null, new DefaultDataAttributeContext( Locale.US ) );
        if ( "right".equals( elementAlignment ) == false ) {
          fail( "Style::horizontal-alignment should be a String of value 'right'" );
        }

        final DataAttributes attributes2 = dataSchema.getAttributes( names[ 0 ] );
        final Object elementAlignment2 = attributes2.getMetaAttribute( MetaAttributeNames.Style.NAMESPACE,
          MetaAttributeNames.Style.HORIZONTAL_ALIGNMENT, null, new DefaultDataAttributeContext( Locale.US ) );
        if ( "left".equals( elementAlignment2 ) == false ) {
          fail( "Style::horizontal-alignment should be a String of value 'right'" );
        }

      } finally {
        tableModel.close();
      }
    } finally {

      pmdDataFactory.close();
    }
  }
 
Example 28
public static SqlPhysicalTable importTableDefinition( Database database, String schemaName, String tableName,
    String locale, ImportStrategy importStrategy ) throws KettleException {

  String id = ( Util.getPhysicalTableIdPrefix() + Util.toId( tableName ) ).toUpperCase();

  SqlPhysicalTable physicalTable = new SqlPhysicalTable();
  physicalTable.setId( id );
  physicalTable.setTargetSchema( schemaName );
  List<IPhysicalColumn> fields = physicalTable.getPhysicalColumns();
  physicalTable.setTargetTable( tableName );

  // id, schemaName, tableName,
  // database.getDatabaseMeta(), fields);

  // Also set a localized description...
  String niceName = beautifyName( tableName );
  physicalTable.setName( new LocalizedString( locale, niceName ) );

  DatabaseMeta dbMeta = database.getDatabaseMeta();
  String schemaTableCombination =
      dbMeta.getSchemaTableCombination( dbMeta.quoteField( schemaName ), dbMeta.quoteField( tableName ) );
  RowMetaInterface row = database.getTableFields( schemaTableCombination );

  if ( row != null && row.size() > 0 ) {
    for ( int i = 0; i < row.size(); i++ ) {
      ValueMetaInterface v = row.getValueMeta( i );
      if ( importStrategy.shouldInclude( v ) ) {
        IPhysicalColumn physicalColumn = importPhysicalColumnDefinition( v, physicalTable, locale, importStrategy );
        fields.add( physicalColumn );
      }
    }
  }
  String upper = tableName.toUpperCase();

  if ( upper.startsWith( "D_" ) || upper.startsWith( "DIM" ) || upper.endsWith( "DIM" ) ) {
    physicalTable.setTableType( TableType.DIMENSION ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  if ( upper.startsWith( "F_" ) || upper.startsWith( "FACT" ) || upper.endsWith( "FACT" ) ) {
    physicalTable.setTableType( TableType.FACT ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }

  return physicalTable;
}
 
Example 29
private static IPhysicalColumn importPhysicalColumnDefinition( ValueMetaInterface v, SqlPhysicalTable physicalTable,
                                                               String locale,
                                                               final ImportStrategy importStrategy ) {
   // The name of the column in the database
  //
  String columnName = v.getName();

  // The field type?
  //
  FieldType fieldType = FieldType.guessFieldType( v.getName() );

  // Create a physical column.
  //
  SqlPhysicalColumn physicalColumn = new SqlPhysicalColumn( physicalTable );
  physicalColumn.setId( v.getName() );
  physicalColumn.setTargetColumn( columnName );
  physicalColumn.setFieldType( fieldType );
  physicalColumn.setAggregationType( AggregationType.NONE );

  // Set the localized name...
  //
  String niceName = beautifyName( importStrategy.displayName( v ) );
  physicalColumn.setName( new LocalizedString( locale, niceName ) );

  // Set the parent concept to the base concept...
  // physicalColumn.getConcept().setParentInterface(schemaMeta.findConcept(
  // Settings.getConceptNameBase()));

  // The data type...
  DataType dataType = getDataType( v );
  physicalColumn.setDataType( dataType );

  if ( null != v.getConversionMask() ) {
    physicalColumn.setProperty( "source_mask", v.getConversionMask() );
  }

  if ( null != v.getDecimalSymbol() ) {
    physicalColumn.setProperty( "source_decimalSymbol", v.getDecimalSymbol() );
  }

  if ( null != v.getGroupingSymbol() ) {
    physicalColumn.setProperty( "source_groupingSymbol", v.getGroupingSymbol() );
  }

  if ( null != v.getCurrencySymbol() ) {
    physicalColumn.setProperty( "source_currencySymbol", v.getCurrencySymbol() );
  }

  return physicalColumn;
}
 
Example 30
public LogicalModel() {
  super();
  // logical model has the following default properties:
  setName( new LocalizedString() );
  setDescription( new LocalizedString() );
}