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

The following examples show how to use org.pentaho.metadata.model.concept.types.LocalizedString. 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
Source File: LocalizationUtil.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 File: StarModelDialog.java    From pentaho-kettle with 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
Source File: StarModelerPerspective.java    From pentaho-kettle with 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 #4
Source File: MondrianModelExporterTest.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 #5
Source File: MetadataGenerator.java    From pentaho-kettle with 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 #6
Source File: StarModelDialog.java    From pentaho-kettle with 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 #7
Source File: LocalizedStringConceptMapper.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @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 #8
Source File: StarModelDialog.java    From pentaho-kettle with 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 #9
Source File: LocalizationUtilIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 #10
Source File: PropertyTypeRegistry.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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
Source File: StarModelDialog.java    From pentaho-kettle with 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 #12
Source File: SqlPhysicalColumn.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SqlPhysicalColumn() {
  super();
  setTargetColumnType( TargetColumnType.COLUMN_NAME );
  // physical column has the following default properties:
  setName( new LocalizedString() );
  setDescription( new LocalizedString() );
}
 
Example #13
Source File: StarModelDialog.java    From pentaho-kettle with 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 #14
Source File: SqlPhysicalTable.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SqlPhysicalTable() {
  super();
  setTargetTableType( TargetTableType.TABLE );
  // physical table has the following default properties:
  setName( new LocalizedString() );
  setDescription( new LocalizedString() );
}
 
Example #15
Source File: ModelerHelper.java    From pentaho-kettle with 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 #16
Source File: ConceptUtilTest.java    From pentaho-kettle with 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 #17
Source File: StarModelerPerspective.java    From pentaho-kettle with 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 #18
Source File: Concept.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #19
Source File: LocalizedStringWrapper.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean equals( final Object object ) {
  if ( object == null ) {
    return false;
  }
  if ( object instanceof LocalizedString == false ) {
    return false;
  }
  return backend.equals( object );
}
 
Example #20
Source File: ConceptUtilTest.java    From pentaho-kettle with 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 #21
Source File: DimensionTableDialog.java    From pentaho-kettle with 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 File: Concept.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #23
Source File: AutoModeler.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #24
Source File: ModelMetaStoreUtil.java    From pentaho-kettle with 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 #25
Source File: ConceptUtilTest.java    From pentaho-kettle with 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 #26
Source File: DimensionTableDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void ok()
{

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

	logicalTable.setName( new LocalizedString(locale, wTableName.getText()) );
	logicalTable.setDescription( new LocalizedString(locale, wTableDescription.getText()) );
	logicalTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), TableType.DIMENSION);
	logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, wPhysicalName.getText());
   logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_DIMENSION_TYPE, wDimensionType.getText());

   // name, description, field type, physical column name, data type, length, precision,
	// source db, source table, source column, conversion remarks
   //
	logicalTable.getLogicalColumns().clear();
	int nr = wAttributes.nrNonEmpty();
	for (int i=0;i<nr;i++) {
	  TableItem item = wAttributes.getNonEmpty(i);
	  LogicalColumn logicalColumn = new LogicalColumn();
	  logicalColumn.setId(UUID.randomUUID().toString());

	  int col=1;
	  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++));
     String dataTypeString = item.getText(col++);
     logicalColumn.setDataType(Utils.isEmpty(dataTypeString) ? null  : DataType.valueOf(dataTypeString));
     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(logicalTable);
     logicalTable.getLogicalColumns().add(logicalColumn);
	}

	dispose();
}
 
Example #27
Source File: TestHelper.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Domain getBasicDomain() {

    String locale = LocaleHelper.getLocale().toString();

    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName( "SampleData" );
    model.setDatasource( dataSource );
    SqlPhysicalTable table = new SqlPhysicalTable( model );
    table.setId( "PT1" );
    model.getPhysicalTables().add( table );
    table.setTargetTableType( TargetTableType.INLINE_SQL );
    table.setTargetTable( "select * from customers" );

    SqlPhysicalColumn column = new SqlPhysicalColumn( table );
    column.setId( "PC1" );
    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();
    logicalModel.setId( "MODEL" );
    logicalModel.setName( new LocalizedString( locale, "My Model" ) );
    logicalModel.setDescription( new LocalizedString( locale, "A Description of the Model" ) );

    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setId( "LT" );
    logicalTable.setPhysicalTable( table );
    logicalTable.setLogicalModel( logicalModel );

    logicalModel.getLogicalTables().add( logicalTable );

    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId( "LC_CUSTOMERNAME" );
    logicalColumn.setPhysicalColumn( column );
    logicalColumn.setLogicalTable( logicalTable );
    logicalTable.addLogicalColumn( logicalColumn );

    Category mainCategory = new Category( logicalModel );
    mainCategory.setId( "CATEGORY" );
    mainCategory.setName( new LocalizedString( locale, "Category" ) );
    mainCategory.addLogicalColumn( logicalColumn );

    logicalModel.getCategories().add( mainCategory );

    Domain domain = new Domain();
    domain.setId( "DOMAIN" );
    domain.addPhysicalModel( model );
    domain.addLogicalModel( logicalModel );

    return domain;
  }
 
Example #28
Source File: MQLEditorServiceDelegateTest.java    From mql-editor with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test( timeout = 5000 )
public void testConcurrency() throws Exception {
  String domainIdPrefix = "id";
  int repoSize = 100;
  //init repo
  IMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  for ( int i = 0; i < repoSize; i++ ) {
    Domain domain = new Domain();
    LocalizedString name = new LocalizedString();
    name.setString( "US", String.valueOf( i + 1 ) );
    domain.setId( domainIdPrefix + String.valueOf( i + 1 ) );
    domain.setName( name );
    repo.storeDomain( domain, false );
  }

  MQLEditorServiceDelegate service = new MQLEditorServiceDelegate( repo );

  int poolSize = repoSize / 2;
  ExecutorService executorService = Executors.newFixedThreadPool( poolSize );

  List<Future<Boolean>> results = new ArrayList<>();
  for ( int i = 0; i < poolSize; i++ ) {
    results.add( executorService.submit( new Callable<Boolean>() {
      public Boolean call() throws Exception {
        for ( int i = 0; i < repoSize; i++ ) {
          try {
            String id = domainIdPrefix + String.valueOf( i + 1 );
            service.getDomainByName( id );
            service.addThinDomain( id );
          } catch ( Exception e ) {
            return false;
          }
        }
        return true;
      }
    } ) );
  }
  for ( Future<Boolean> result : results ) {
    Assert.assertTrue( result.get() );
  }
  executorService.shutdown();
}
 
Example #29
Source File: StarDomain.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void setDescription(String description) {
  domain.setDescription(new LocalizedString(locale, description));
}
 
Example #30
Source File: StarDomain.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void setName(String name) {
  domain.setName(new LocalizedString(locale, name));
}