org.pentaho.metadata.model.Domain Java Examples
The following examples show how to use
org.pentaho.metadata.model.Domain.
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: JobGeneratorTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { final StarDomain starDomain = mock( StarDomain.class ); final Domain domain = mock( Domain.class ); when( domain.getProperty( eq( DefaultIDs.DOMAIN_TARGET_DATABASE ) ) ).thenReturn( "test_domain_target_db" ); when( starDomain.getDomain() ).thenReturn( domain ); final Repository repository = mock( Repository.class ); final RepositoryDirectoryInterface targetDirectory = mock( RepositoryDirectoryInterface.class ); final DatabaseMeta meta = Mockito.mock( DatabaseMeta.class ); Mockito.when( meta.getName() ).thenReturn( "test_domain_target_db" ); final LinkedList<DatabaseMeta> databases = new LinkedList<DatabaseMeta>() { { add( meta ); } }; final String locale = Locale.US.toString(); jobGenerator = new JobGenerator( starDomain, repository, targetDirectory, databases, locale ); }
Example #2
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOlapCalculatedMembers() throws Exception { XmiParser parser = new XmiParser(); Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/example_olap.xmi" ) ); List<OlapCalculatedMember> members = new ArrayList<OlapCalculatedMember>(); members.add( new OlapCalculatedMember( "Constant One", "Measures", "1", "Currency", false ) ); members.add( new OlapCalculatedMember( "Constant Two", "Measures", "2", "Currency", true ) ); List<OlapCube> cubes = (List<OlapCube>) domain.getLogicalModels().get( 0 ).getProperty( "olap_cubes" ); OlapCube cube = cubes.get( 0 ); cube.setOlapCalculatedMembers( members ); String xmi = parser.generateXmi( domain ); ByteArrayInputStream is = new ByteArrayInputStream( xmi.getBytes() ); Domain domain2 = parser.parseXmi( is ); SerializationService serializer = new SerializationService(); String xml1 = serializeWithOrderedHashmaps( domain ); String xml2 = serializeWithOrderedHashmaps( domain2 ); assertEquals( xml1, xml2 ); }
Example #3
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testMissingDescriptionRef() throws Exception { XmiParser parser = new XmiParser(); Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/missing_ref.xmi" ) ); String xmi = parser.generateXmi( domain ); ByteArrayInputStream is = new ByteArrayInputStream( xmi.getBytes() ); Domain domain2 = parser.parseXmi( is ); ByteArrayInputStream is2 = new ByteArrayInputStream( parser.generateXmi( domain2 ).getBytes() ); Domain domain3 = parser.parseXmi( is2 ); String xml1 = serializeWithOrderedHashmaps( domain2 ); String xml2 = serializeWithOrderedHashmaps( domain3 ); // note: this does not verify security objects at this time assertEquals( xml1, xml2 ); }
Example #4
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testXmiGenerator() throws Exception { // String str = new XmiParser().generateXmi(new Domain()); // System.out.println(str); Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/steelwheels.xmi" ) ); String xmi = parser.generateXmi( domain ); ByteArrayInputStream is = new ByteArrayInputStream( xmi.getBytes( "UTF-8" ) ); Domain domain2 = parser.parseXmi( is ); String xml1 = serializeWithOrderedHashmaps( domain ); String xml2 = serializeWithOrderedHashmaps( domain2 ); // note: this does not verify security objects at this time assertEquals( xml1, xml2 ); }
Example #5
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testWriteAndParseLevelFormatter() throws Exception { Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/example_olap.xmi" ) ); LogicalModel analysisModel = domain.getLogicalModels().get( 0 ); @SuppressWarnings( "unchecked" ) List<OlapDimension> dims = (List<OlapDimension>) analysisModel.getProperty( LogicalModel.PROPERTY_OLAP_DIMS ); OlapHierarchyLevel firstLevel = dims.get( 0 ).getHierarchies().get( 0 ).getHierarchyLevels().get( 0 ); firstLevel.setFormatter( "InlineMemberFormatter" ); String xmi = parser.generateXmi( domain ); assertTrue( xmi.contains( "<CWM:TaggedValue tag=\"HIERARCHY_LEVEL_FORMATTER\" value=\"InlineMemberFormatter\"" ) ); domain = parser.parseXmi( new ByteArrayInputStream( xmi.getBytes() ) ); analysisModel = domain.getLogicalModels().get( 0 ); @SuppressWarnings( "unchecked" ) List<OlapDimension> parsedDims = (List<OlapDimension>) analysisModel.getProperty( LogicalModel.PROPERTY_OLAP_DIMS ); firstLevel = parsedDims.get( 0 ).getHierarchies().get( 0 ).getHierarchyLevels().get( 0 ); assertEquals( "InlineMemberFormatter", firstLevel.getFormatter() ); }
Example #6
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testAnalyzeImport() throws Exception { // this test exercises all known places where localized strings are located XmiParser parser = new XmiParser(); Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/simple_model.xmi" ) ); LocalizationUtil util = new LocalizationUtil(); Properties props = util.exportLocalizedProperties( domain, "en_US" ); List<String> messages = util.analyzeImport( domain, props, "en_US" ); Assert.assertEquals( 0, messages.size() ); props.remove( "[Base].[comments]" ); props.setProperty( "[Test].[Property]", "Test Value" ); messages = util.analyzeImport( domain, props, "en_US" ); Assert.assertEquals( 2, messages.size() ); Assert.assertEquals( messages.get( 0 ), "Key [Base].[comments] is missing from imported bundle" ); Assert.assertEquals( messages.get( 1 ), "Imported key [Test].[Property] is not referenced in domain" ); }
Example #7
Source File: XmiParser.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public String generateXmi( Domain domain ) { if ( domain == null ) { logger.error( Messages.getErrorString( "XmiParser.ERROR_0001_DOMAIN_NULL" ) ); //$NON-NLS-1$ return null; } try { StringWriter stringWriter = new StringWriter(); StreamResult result = new StreamResult(); result.setWriter( stringWriter ); TransformerFactory factory = TransformerFactory.newInstance(); Document doc = toXmiDocument( domain ); if ( doc != null ) { factory.newTransformer().transform( new DOMSource( doc ), result ); return stringWriter.getBuffer().toString(); } } catch ( Exception e ) { logger.error( Messages.getErrorString( "XmiParser.ERROR_0002_TO_XML_FAILED" ), e ); //$NON-NLS-1$ } return null; }
Example #8
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
/** * Tests the import of localization properties exported from a model that was published from aAgile BI to a BI Server. **/ @Test public void testImportPropertiesIntoAgileBiPublishedModel() throws Exception { // this test exercises all known places where localized strings are located XmiParser parser = new XmiParser(); Domain domain = null; domain = parser.parseXmi( getClass().getResourceAsStream( "/agileBiGenerated.xmi" ) ); LocalizationUtil util = new LocalizationUtil(); // Load the properties from the exported properties file Properties exportedPropertyFileProps = new Properties(); exportedPropertyFileProps.load( getClass().getResourceAsStream( "/agileBiGenerated_en_US.properties" ) ); // import the properties into the domain List<String> messages = util.analyzeImport( domain, exportedPropertyFileProps, "en_US" ); if ( messages.isEmpty() ) { Assert.assertTrue( messages.isEmpty() ); } else { for ( String message : messages ) { System.out.println( message ); } Assert.fail( "The analysis of the export failed." ); } }
Example #9
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
/** * Tests the import of localization properties exported from a model that was published from aAgile BI to a BI Server. **/ @Test public void testImportPropertiesExportedFromPME() throws Exception { // this test exercises all known places where localized strings are located XmiParser parser = new XmiParser(); Domain domain = null; domain = parser.parseXmi( getClass().getResourceAsStream( "/exportedFromPME.xmi" ) ); LocalizationUtil util = new LocalizationUtil(); // Load the properties from the exported properties file Properties exportedPropertyFileProps = new Properties(); exportedPropertyFileProps.load( getClass().getResourceAsStream( "/exportedFromPME_en_US.properties" ) ); // import the properties into the domain List<String> messages = util.analyzeImport( domain, exportedPropertyFileProps, "en_US" ); if ( messages.isEmpty() ) { Assert.assertTrue( messages.isEmpty() ); } else { for ( String message : messages ) { System.out.println( message ); } Assert.fail( "The analysis of the export failed." ); } }
Example #10
Source File: FileBasedMetadataDomainRepository.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public Domain getDomain( String id ) { // for now, lazy load all the domains at once. We could be smarter, // loading the files as requested. if ( domains.size() == 0 ) { reloadDomains(); } Domain domain = domains.get( id ); if ( domain == null ) { // try to reference the metadata file implicitly, for backward compatibility domain = domains.get( id + "/metadata.xmi" ); } if ( domain != null ) { SecurityHelper helper = new SecurityHelper(); Domain clone = helper.createSecureDomain( this, domain ); return clone; } else { logger.error( Messages.getErrorString( "FileBasedMetadataDomainRepository.ERROR_0006_DOMAIN_NOT_FOUND", id ) ); //$NON-NLS-1$ return null; } }
Example #11
Source File: InMemoryMetadataDomainRepository.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public synchronized void storeDomain( Domain domain, boolean overwrite ) throws DomainIdNullException, DomainAlreadyExistsException, DomainStorageException { // stores a domain to system/metadata/DOMAIN_ID.domain.xml // ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class, session); // repo.addSolutionFile(baseUrl, path, fileName, data, overwrite) if ( domain.getId() == null ) { // todo: replace with exception throw new DomainIdNullException( Messages.getErrorString( "IMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL" ) ); //$NON-NLS-1$ } if ( !overwrite && domains != null && domains.get( domain.getId() ) != null ) { throw new DomainAlreadyExistsException( Messages.getErrorString( "IMetadataDomainRepository.ERROR_0002_DOMAIN_OBJECT_EXISTS", domain.getId() ) ); //$NON-NLS-1$ } // adds the domain to the domains list if ( domains == null ) { domains = new HashMap<String, Domain>(); } domains.put( domain.getId(), domain ); }
Example #12
Source File: QueryXmlHelper.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public Query fromXML( IMetadataDomainRepository repo, Document doc ) throws PentahoMetadataException { // get the domain id String domainId = getElementText( doc, "domain_id" ); //$NON-NLS-1$ Domain domain = repo.getDomain( domainId ); if ( domain == null ) { if ( domainId != null && !domainId.contains( ".xmi" ) ) { domain = repo.getDomain( domainId + ".xmi" ); } if ( domain != null ) { logger.warn( String.format( "Metadata model [%1$s] was requested, but the model doesn't exist. " + "Substituting [%1$s.xmi] instead as a legacy fallback. " + "Please change your reports to reference %1$s.xmi instead", domainId ) ); } } if ( domain == null ) { // need to throw an error logger.error( String.format( "Metadata model [%1$s] doesn't exist. " + "Please check the existence of the model", domainId ) ); throw new PentahoMetadataException( Messages.getErrorString( "QueryXmlHelper.ERROR_0009_DOMAIN_INSTANCE_NULL", domainId ) ); //$NON-NLS-1$ } return fromXML( doc, domain ); }
Example #13
Source File: StarModelerPerspective.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public boolean open(Node transNode, String fname, boolean importfile) { try { String xml = KettleVFS.getTextFileContent(fname, Const.XML_ENCODING); Domain domain = new SerializationService().deserializeDomain(xml); StarDomain starDomain = new StarDomain(); starDomain.setDomain(domain); starDomain.setFilename(fname); createTabForDomain(starDomain); PropsUI.getInstance().addLastFile(LastUsedFile.FILE_TYPE_SCHEMA, fname, null, false, null); Spoon.getInstance().addMenuLast(); return true; } catch(Exception e) { new ErrorDialog(Spoon.getInstance().getShell(), "Error", "There was an error opening model from file '"+fname+"'", e); } return false; }
Example #14
Source File: PentahoMetaDataTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public IMetadataDomainRepository getMetadataDomainRepository( final String domainId, final ResourceManager resourceManager, final ResourceKey contextKey, final String xmiFile ) throws ReportDataFactoryException { try { final InputStream stream = createStream( resourceManager, contextKey, xmiFile ); try { final InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository(); final XmiParser parser = new XmiParser(); final Domain domain = parser.parseXmi( stream ); // add a couple of agg types to the quantity ordered physical column final IPhysicalTable table = ( (SqlPhysicalModel) domain.getPhysicalModels().get( 0 ) ).getPhysicalTables().get( 7 ); final IPhysicalColumn col = table.getPhysicalColumns().get( 3 ); final List<AggregationType> list = new ArrayList<AggregationType>(); list.add( AggregationType.SUM ); list.add( AggregationType.AVERAGE ); col.setAggregationList( list ); domain.setId( domainId ); repo.storeDomain( domain, true ); return repo; } finally { stream.close(); } } catch ( final Exception e ) { throw new ReportDataFactoryException( "The Specified XMI File is invalid: " + xmiFile, e ); } }
Example #15
Source File: InMemoryMetadataDomainRepository.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
public synchronized void removeModel( String domainId, String modelId ) throws DomainIdNullException, DomainStorageException { // get a raw domain vs. the cloned secure domain Domain domain = domains.get( domainId ); if ( domain == null ) { throw new DomainIdNullException( Messages.getErrorString( "IMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL" ) ); //$NON-NLS-1$ } // remove the model Iterator<LogicalModel> iter = domain.getLogicalModels().iterator(); while ( iter.hasNext() ) { LogicalModel model = iter.next(); if ( modelId.equals( model.getId() ) ) { iter.remove(); break; } } if ( domain.getLogicalModels().size() == 0 ) { // remove the domain all together removeDomain( domainId ); } else { // store the modified domain try { storeDomain( domain, true ); } catch ( DomainAlreadyExistsException e ) { logger.error( "this should not happen", e ); } } }
Example #16
Source File: FileBasedMetadataDomainRepository.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
public void removeModel( String domainId, String modelId ) throws DomainIdNullException, DomainStorageException { synchronized ( domains ) { // get a raw domain vs. the cloned secure domain Domain domain = domains.get( domainId ); if ( domain == null ) { throw new DomainIdNullException( Messages .getErrorString( "IMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL" ) ); //$NON-NLS-1$ } // remove the model Iterator<LogicalModel> iter = domain.getLogicalModels().iterator(); while ( iter.hasNext() ) { LogicalModel model = iter.next(); if ( modelId.equals( model.getId() ) ) { iter.remove(); break; } } if ( domain.getLogicalModels().size() == 0 ) { // remove the domain all together removeDomain( domainId ); } else { // store the modified domain try { storeDomain( domain, true ); } catch ( DomainAlreadyExistsException e ) { // this should not happen logger.error( Messages.getErrorString( "FileBasedMetadataDomainRepository.ERROR_0007_DOMAIN_ALREADY_EXISTS", domain.getId() ), e ); //$NON-NLS-1$ } } } }
Example #17
Source File: InMemoryMetadataDomainRepository.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
public Domain getDomain( String id ) { if ( domains == null ) { return null; } Domain domain = domains.get( id ); if ( domain != null ) { SecurityHelper helper = new SecurityHelper(); Domain clone = helper.createSecureDomain( this, domain ); return clone; } else { logger.error( "domain not found : " + id ); return null; } }
Example #18
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test @Ignore // ids aren't changed on the fly see http://jira.pentaho.com/browse/BISERVER-13338 public void incorrectIdsAreReplacedOnTheFly() throws Exception { final String modelName = "BV_HUMAN_RESOURCES"; final String tableName = "BT_EMPLOYEES_EMPLOYEES"; final String columnName = "BC_EMPLOYEES_EMPLOYEENUMBER"; final String categoryName = "BC_OFFICES_"; Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/steelwheels.xmi" ) ); LogicalModel model = domain.findLogicalModel( modelName ); assertNotNull( model ); Category category = model.findCategory( categoryName ); assertNotNull( category ); LogicalTable table = model.findLogicalTable( tableName ); assertValidId( table ); LogicalColumn column = table.findLogicalColumn( columnName ); assertValidId( column ); setInvalidId( " (Cat_Id)", category, table, column ); String spoiltXmi = parser.generateXmi( domain ); domain = parser.parseXmi( new ByteArrayInputStream( spoiltXmi.getBytes() ) ); model = domain.findLogicalModel( modelName ); assertNotNull( model ); category = findConceptStartingWith( categoryName, model.getCategories() ); assertValidId( category ); table = findConceptStartingWith( tableName, model.getLogicalTables() ); assertValidId( table ); column = findConceptStartingWith( columnName, table.getLogicalColumns() ); assertValidId( column ); }
Example #19
Source File: XmiParserIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void collisionAfterCorrectionAreResolved() throws Exception { Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/steelwheels.xmi" ) ); LogicalTable table = domain.getLogicalModels().get( 0 ).getLogicalTables().get( 0 ); assertTrue( table.getLogicalColumns().size() >= 2 ); LogicalColumn col1 = table.getLogicalColumns().get( 0 ); col1.setId( "column[x]" ); LogicalColumn col2 = table.getLogicalColumns().get( 1 ); col2.setId( "column{x}" ); assertFalse( "Columns have different raw ids", col1.getId().equals( col2.getId() ) ); assertEquals( "Columns have equal validated ids", validateId( col1.getId() ), validateId( col2.getId() ) ); String xmi = parser.generateXmi( domain ); domain = parser.parseXmi( new ByteArrayInputStream( xmi.getBytes() ) ); List<LogicalColumn> columns = domain.getLogicalModels().get( 0 ).getLogicalTables().get( 0 ).getLogicalColumns(); col1 = columns.get( 0 ); col2 = columns.get( 1 ); assertTrue( col1.getId(), col1.getId().startsWith( "column" ) ); assertTrue( col2.getId(), col2.getId().startsWith( "column" ) ); assertFalse( "Columns have different corrected ids", col1.getId().equals( col2.getId() ) ); }
Example #20
Source File: ThinQueryIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testQueryConversion() throws Exception { Domain domain = TestHelper.getBasicDomain(); LogicalModel model = domain.findLogicalModel( "MODEL" ); Query query = new Query( domain, model ); Category category = model.findCategory( "CATEGORY" ); LogicalColumn column = category.findLogicalColumn( "LC_CUSTOMERNAME" ); query.getSelections().add( new Selection( category, column, null ) ); query.getConstraints().add( new Constraint( CombinationType.AND, "[CATEGORY.LC_CUSTOMERNAME] = \"bob\"" ) ); query.getOrders().add( new Order( new Selection( category, column, null ), Order.Type.ASC ) ); MQLQueryImpl impl = null; try { impl = ThinModelConverter.convertToLegacy( query, null ); } catch ( Exception e ) { e.printStackTrace(); Assert.fail(); } Assert.assertNotNull( impl ); TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + " LT.customername AS COL0\n" + "FROM \n" + " (select * from customers) LT\n" + "WHERE \n" + " (\n" + " (\n" + " LT.customername = 'bob'\n" + " )\n" + " )\n" + "ORDER BY \n" + " COL0\n", impl.getQuery().getQuery() ); query.setLimit( 10 ); impl = ThinModelConverter.convertToLegacy( query, null ); Assert.assertEquals( 10, impl.getLimit() ); }
Example #21
Source File: StarModelerPerspective.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private LogicalModel findLogicalTable(Domain domain, String locale, String modelName) { for (LogicalModel logicalModel : domain.getLogicalModels()) { String name = ConceptUtil.getName(logicalModel, locale); if (name!=null && name.equalsIgnoreCase(modelName)) return logicalModel; } return null; }
Example #22
Source File: StarModelerPerspective.java From pentaho-kettle with Apache License 2.0 | 5 votes |
protected void generatePhysicalModelButton(StarDomain starDomain) { try { List<DatabaseMeta> sharedDatabases = SharedDatabaseUtil.loadSharedDatabases(); MetadataGenerator generator = new MetadataGenerator(starDomain.getDomain(), sharedDatabases); Domain physicalMetadataModel = generator.generatePhysicalMetadataModel(); System.out.println("Generated physical model: "+physicalMetadataModel.getName(defaultLocale)); } catch(Exception e) { new ErrorDialog(Spoon.getInstance().getShell(), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingPhysicalModel.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingPhysicalModel.Message"), e); } }
Example #23
Source File: InlineEtlModelGeneratorIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testQueryExecution() throws Exception { List<String> users = new ArrayList<String>(); users.add( "suzy" ); List<String> roles = new ArrayList<String>(); roles.add( "Authenticated" ); int defaultAcls = 31; InlineEtlModelGenerator gen = new InlineEtlModelGenerator( "testmodel", csvFilesPath, "example.csv", true, ",", "\"", true, users, roles, defaultAcls, "joe" ); Domain domain = gen.generate(); LogicalModel model = domain.getLogicalModels().get( 0 ); Category category = model.getCategories().get( 0 ); Query query = new Query( domain, model ); query.getSelections().add( new Selection( category, category.getLogicalColumns().get( 0 ), null ) ); InlineEtlQueryExecutor executor = new InlineEtlQueryExecutor(); IPentahoResultSet resultset = executor.executeQuery( query, csvFilesPath, null ); Assert.assertEquals( 5, resultset.getRowCount() ); Assert.assertEquals( 1, resultset.getColumnCount() ); Assert.assertEquals( "bc_0_Data1", resultset.getMetaData().getColumnHeaders()[0][0] ); Assert.assertEquals( 1.0, resultset.getValueAt( 0, 0 ) ); Assert.assertEquals( 2.0, resultset.getValueAt( 1, 0 ) ); Assert.assertEquals( 3.0, resultset.getValueAt( 2, 0 ) ); Assert.assertEquals( 4.0, resultset.getValueAt( 3, 0 ) ); Assert.assertEquals( 5.0, resultset.getValueAt( 4, 0 ) ); }
Example #24
Source File: SqlOpenFormulaIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testMqlDateParams() throws Exception { Domain steelWheelsDomain = new XmiParser().parseXmi( getClass().getResourceAsStream( "/steel-wheels.xmi" ) ); String mql = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<mql>" + "<domain_id>Steel-Wheels</domain_id>" + "<model_id>BV_ORDERS</model_id>" + "<options>" + "<disable_distinct>false</disable_distinct>" + "</options>" + "<parameters>" + "<parameter defaultValue=\"2004-01-01\" name=\"date\" type=\"STRING\"/>" + "</parameters>" + "<selections>" + "<selection>" + "<view>BC_CUSTOMER_W_TER_</view>" + "<column>BC_CUSTOMER_W_TER_CUSTOMERNUMBER</column>" + "<aggregation>NONE</aggregation>" + "</selection>" + "<selection>" + "<view>CAT_ORDERS</view>" + "<column>BC_ORDERS_ORDERDATE</column>" + "<aggregation>NONE</aggregation>" + "</selection>" + "</selections>" + "<constraints>" + "<constraint>" + "<operator/>" + "<condition>[CAT_ORDERS.BC_ORDERS_ORDERDATE] " + ">DATEVALUE([param:date])</condition>" + "</constraint>" + "</constraints>" + "<orders/>" + "</mql>"; QueryXmlHelper helper = new QueryXmlHelper(); InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository(); steelWheelsDomain.setId( "Steel-Wheels" ); repo.storeDomain( steelWheelsDomain, false ); Query query = helper.fromXML( repo, mql ); DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ SqlGenerator generator = new SqlGenerator(); MappedQuery mappedQuery = generator.generateSql( query, "en_US", repo, databaseMeta ); TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + " BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER AS COL0\n" + " ,BT_ORDERS_ORDERS.ORDERDATE AS COL1\n" + "FROM \n" + " CUSTOMER_W_TER BT_CUSTOMER_W_TER_CUSTOMER_W01\n" + " ,ORDERS BT_ORDERS_ORDERS\n" + "WHERE \n" + " ( BT_ORDERS_ORDERS.CUSTOMERNUMBER = BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER )\n" + " AND \n" + " (\n" + " (\n" + " BT_ORDERS_ORDERS.ORDERDATE > TO_DATE('2004-01-01','YYYY-MM-DD')\n" + " )\n" + " )\n", mappedQuery.getQuery() ); }
Example #25
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #26
Source File: QueryXmlHelperTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testFromXML() throws Exception { Domain domain = TestHelper.getBasicDomain(); LogicalModel model = TestHelper.buildDefaultModel(); domain.addLogicalModel( model ); model.setId( "MODEL2" ); Query query = new Query( domain, model ); String xml = helper.toXML( query ); try { query = helper.fromXML( metadataDomainRepository, xml ); fail(); } catch ( PentahoMetadataException e ) { // expected } }
Example #27
Source File: QueryXmlHelperTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void init() throws Exception { helper = new QueryXmlHelper(); Domain domain = TestHelper.getBasicDomain(); LogicalModel model = TestHelper.buildDefaultModel(); domain.addLogicalModel( model ); model.setId( "MODEL1" ); query = new Query( domain, model ); LogicalColumn column = new LogicalColumn(); column.setId( "LC_Test_Column1" ); LogicalColumn column2 = new LogicalColumn(); column2.setId( "LC_Test_Column2" ); Category category = new Category(); category.getLogicalColumns().add( column ); query.getLogicalModel().getCategories().add( category ); LogicalTable lt = new LogicalTable(); lt.getLogicalColumns().add( column ); lt.getLogicalColumns().add( column2 ); query.getLogicalModel().getLogicalTables().add( lt ); documentBuilderFactory = DocumentBuilderFactory.newInstance(); db = documentBuilderFactory.newDocumentBuilder(); doc = db.newDocument(); metadataDomainRepository = new InMemoryMetadataDomainRepository(); metadataDomainRepository.storeDomain( domain, true ); }
Example #28
Source File: LocalizationUtilIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testImportedLocaleIntoDomainWithSameLocale() throws Exception { // this test exercises all known places where localized strings are located String locale = "en_US"; XmiParser parser = new XmiParser(); Domain domain = null; domain = parser.parseXmi( getClass().getResourceAsStream( "/modelWith_EN_US.xmi" ) ); LocalizationUtil util = new LocalizationUtil(); // Load the properties from the exported properties file Properties exportedPropertyFileProps = new Properties(); exportedPropertyFileProps.load( getClass().getResourceAsStream( "/modelWith_EN_US_en_US.properties" ) ); // import the properties into the domain util.importLocalizedProperties( domain, exportedPropertyFileProps, locale ); // Out imported localization will have the string "en_US" before each non empty string. // take the printing of all the properties out before checking in Properties en_US_FromDomain = util.exportLocalizedProperties( domain, locale ); for ( Entry<Object, Object> entry : en_US_FromDomain.entrySet() ) { System.out.println( entry.getKey().toString() + " => " + entry.getValue().toString() ); } assertEquals( "en_US Num children at home", en_US_FromDomain .get( "[IPhysicalModel-foodmart].[PT_CUSTOMER].[num_children_at_home].[name]" ) ); }
Example #29
Source File: InlineEtlModelGeneratorIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testQueryExecutionWithAggregationsAndConstraints() throws Exception { List<String> users = new ArrayList<String>(); users.add( "suzy" ); List<String> roles = new ArrayList<String>(); roles.add( "Authenticated" ); int defaultAcls = 31; InlineEtlModelGenerator gen = new InlineEtlModelGenerator( "testmodel", csvFilesPath, "example.csv", true, ",", "\"", true, users, roles, defaultAcls, "joe" ); Domain domain = gen.generate(); LogicalModel model = domain.getLogicalModels().get( 0 ); Category category = model.getCategories().get( 0 ); category.getLogicalColumns().get( 1 ).setDataType( DataType.NUMERIC ); category.getLogicalColumns().get( 1 ).setAggregationType( AggregationType.SUM ); Query query = new Query( domain, model ); query.getSelections().add( new Selection( category, category.getLogicalColumns().get( 3 ), null ) ); query.getSelections().add( new Selection( category, category.getLogicalColumns().get( 1 ), null ) ); query.getConstraints().add( new Constraint( CombinationType.AND, "[bc_testmodel.bc_1_Data2] > 4.0" ) ); query.getOrders().add( new Order( new Selection( category, category.getLogicalColumns().get( 3 ), null ), Order.Type.DESC ) ); InlineEtlQueryExecutor executor = new InlineEtlQueryExecutor(); IPentahoResultSet resultset = executor.executeQuery( query, csvFilesPath, null ); Assert.assertEquals( 2, resultset.getRowCount() ); Assert.assertEquals( 2, resultset.getColumnCount() ); Assert.assertEquals( "bc_3_Data4", resultset.getMetaData().getColumnHeaders()[0][0] ); Assert.assertEquals( "bc_1_Data2", resultset.getMetaData().getColumnHeaders()[0][1] ); Assert.assertEquals( "String Value", resultset.getValueAt( 0, 0 ) ); Assert.assertEquals( "Bigger String Value", resultset.getValueAt( 1, 0 ) ); Assert.assertEquals( 19.5, resultset.getValueAt( 0, 1 ) ); Assert.assertEquals( 5.7, resultset.getValueAt( 1, 1 ) ); }
Example #30
Source File: SQLModelGeneratorIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSQLModelGenerator() { SerializationService service = new SerializationService(); String xml = service.serializeDomain( domain ); Domain domain2 = service.deserializeDomain( xml ); assertEquals( 1, domain2.getPhysicalModels().size() ); }