Search in sources :

Example 1 with ModelerService

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService in project data-access by pentaho.

the class SerializeMultiTableServiceIT method testSerialize.

@Test
public void testSerialize() throws Exception {
    if (ModelerMessagesHolder.getMessages() == null) {
        ModelerMessagesHolder.setMessages(new SpoonModelerMessages());
    }
    try {
        KettleEnvironment.init();
        Props.init(Props.TYPE_PROPERTIES_EMPTY);
    } catch (Exception e) {
    // may already be initialized by another test
    }
    login("suzy", "", false);
    String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
    String path = solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + // $NON-NLS-1$  //$NON-NLS-2$
    RepositoryFile.SEPARATOR;
    String olapPath = null;
    IApplicationContext appContext = PentahoSystem.getApplicationContext();
    if (appContext != null) {
        path = PentahoSystem.getApplicationContext().getSolutionPath(path);
        olapPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$  //$NON-NLS-2$
        "system" + RepositoryFile.SEPARATOR + "olap" + RepositoryFile.SEPARATOR);
    }
    // $NON-NLS-1$
    File olap1 = new File(olapPath + "datasources.xml");
    // $NON-NLS-1$
    File olap2 = new File(olapPath + "tmp_datasources.xml");
    FileUtils.copyFile(olap1, olap2);
    DatabaseMeta database = getDatabaseMeta();
    MultiTableModelerSource multiTable = new MultiTableModelerSource(database, getSchema(), database.getName(), Arrays.asList("CUSTOMERS", "PRODUCTS", "CUSTOMERNAME", "PRODUCTCODE"));
    Domain domain = multiTable.generateDomain();
    List<OlapDimension> olapDimensions = new ArrayList<OlapDimension>();
    OlapDimension dimension = new OlapDimension();
    // $NON-NLS-1$
    dimension.setName("test");
    dimension.setTimeDimension(false);
    olapDimensions.add(dimension);
    // $NON-NLS-1$
    domain.getLogicalModels().get(0).setProperty("olap_dimensions", olapDimensions);
    ModelerService service = new ModelerService();
    // $NON-NLS-1$
    service.serializeModels(domain, "test_file");
    Assert.assertEquals((String) domain.getLogicalModels().get(0).getProperty("MondrianCatalogRef"), "SampleData");
}
Also used : MultiTableModelerSource(org.pentaho.agilebi.modeler.util.MultiTableModelerSource) SpoonModelerMessages(org.pentaho.agilebi.modeler.util.SpoonModelerMessages) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Domain(org.pentaho.metadata.model.Domain) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) OlapDimension(org.pentaho.metadata.model.olap.OlapDimension) ModelerService(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) Test(org.junit.Test)

Example 2 with ModelerService

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService in project data-access by pentaho.

the class SerializeServiceIT method testSerialize.

@Test
public void testSerialize() throws Exception {
    if (ModelerMessagesHolder.getMessages() == null) {
        ModelerMessagesHolder.setMessages(new SpoonModelerMessages());
    }
    try {
        KettleEnvironment.init();
        Props.init(Props.TYPE_PROPERTIES_EMPTY);
    } catch (Exception e) {
    // may already be initialized by another test
    }
    login("suzy", "", false);
    String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
    String path = solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + // $NON-NLS-1$  //$NON-NLS-2$
    RepositoryFile.SEPARATOR;
    String olapPath = null;
    IApplicationContext appContext = PentahoSystem.getApplicationContext();
    if (appContext != null) {
        path = PentahoSystem.getApplicationContext().getSolutionPath(path);
        olapPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$  //$NON-NLS-2$
        "system" + RepositoryFile.SEPARATOR + "olap" + RepositoryFile.SEPARATOR);
    }
    // $NON-NLS-1$
    File olap1 = new File(olapPath + "datasources.xml");
    // $NON-NLS-1$
    File olap2 = new File(olapPath + "tmp_datasources.xml");
    FileUtils.copyFile(olap1, olap2);
    Domain domain = generateModel();
    ModelerService service = new ModelerService();
    ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper());
    model.setModelName("ORDERS");
    model.setDomain(domain);
    model.getWorkspaceHelper().populateDomain(model);
    // $NON-NLS-1$
    service.serializeModels(domain, "test_file");
    Assert.assertEquals(domain.getLogicalModels().get(1).getProperty("MondrianCatalogRef"), model.getModelName());
}
Also used : GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) SpoonModelerMessages(org.pentaho.agilebi.modeler.util.SpoonModelerMessages) Matchers.anyString(org.mockito.Matchers.anyString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Domain(org.pentaho.metadata.model.Domain) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) ModelerService(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 SpoonModelerMessages (org.pentaho.agilebi.modeler.util.SpoonModelerMessages)2 Domain (org.pentaho.metadata.model.Domain)2 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)2 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)2 DuplicateDatasourceException (org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException)2 NonExistingDatasourceException (org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ModelerService (org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService)2 DataAccessException (org.springframework.dao.DataAccessException)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 ArrayList (java.util.ArrayList)1 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)1 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)1 MultiTableModelerSource (org.pentaho.agilebi.modeler.util.MultiTableModelerSource)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 OlapDimension (org.pentaho.metadata.model.olap.OlapDimension)1