Search in sources :

Example 6 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testFindLogicalTables.

@Test
public void testFindLogicalTables() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final TableType dimension = TableType.DIMENSION;
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(dimension);
    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(dimension);
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    final List<LogicalTable> logicalTables = ConceptUtil.findLogicalTables(logicalModel, dimension);
    assertEquals(2, logicalTables.size());
    assertEquals(logicalTable1, logicalTables.get(0));
    assertEquals(logicalTable3, logicalTables.get(1));
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) TableType(org.pentaho.metadata.model.concept.types.TableType) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 7 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testIndexOfFactTable.

@Test
public void testIndexOfFactTable() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    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(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    final int indexOfFactTable = ConceptUtil.indexOfFactTable(logicalModel);
    assertEquals(1, indexOfFactTable);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 8 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testFindDimensionWithName.

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

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

Example 9 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project pentaho-platform by pentaho.

the class MetadataImportHandler method StripDswFromStream.

InputStream StripDswFromStream(InputStream inputStream) throws Exception {
    // Check if this is valid xml
    InputStream inputStream2 = null;
    String xmi = null;
    XmiParser xmiParser = new XmiParser();
    try {
        byte[] is = IOUtils.toByteArray(inputStream);
        xmi = new String(is, "UTF-8");
        // now, try to see if the xmi can be parsed (ie, check if it's valid xmi)
        Domain domain = xmiParser.parseXmi(new java.io.ByteArrayInputStream(is));
        boolean changed = false;
        Iterator<LogicalModel> iterator = domain.getLogicalModels().iterator();
        while (iterator.hasNext()) {
            LogicalModel logicalModel = iterator.next();
            // $NON-NLS-1$
            Object property = logicalModel.getProperty(DSW_SOURCE_PROPERTY);
            if (property != null) {
                // definition we only want to import the metadata portion.
                if (logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_DIMS) != null) {
                    // This logical model is an Olap model that needs to be removed from metadata
                    iterator.remove();
                } else {
                    // Remove properties that make this a DSW
                    logicalModel.removeChildProperty(DSW_SOURCE_PROPERTY);
                    logicalModel.removeChildProperty(AGILE_BI_VERSION_PROPERTY);
                    logicalModel.removeChildProperty(WIZARD_GENERATED_PROPERTY);
                }
                changed = true;
            }
        }
        if (changed) {
            // The model was modified, regenerate the xml
            xmi = xmiParser.generateXmi(domain);
        }
        // xmi is valid. Create a new inputstream for the actual import action.
        inputStream2 = new java.io.ByteArrayInputStream(xmi.getBytes("UTF-8"));
    } catch (Exception e) {
        throw new PlatformImportException(e.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, e);
    }
    return inputStream2;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) LogicalModel(org.pentaho.metadata.model.LogicalModel) ByteArrayInputStream(java.io.ByteArrayInputStream) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Example 10 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method removeModel.

/**
 * remove a model from a domain which is stored either on a disk or memory.
 *
 * @param domainId
 * @param modelId
 */
@Override
public void removeModel(final String domainId, final String modelId) throws DomainIdNullException, DomainStorageException {
    if (logger.isDebugEnabled()) {
        logger.debug("removeModel(" + domainId + ", " + modelId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    if (StringUtils.isEmpty(modelId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0006_MODEL_ID_INVALID"));
    }
    // Get the domain and remove the model
    final Domain domain = getDomain(domainId);
    if (null != domain) {
        boolean found = false;
        final Iterator<LogicalModel> iter = domain.getLogicalModels().iterator();
        while (iter.hasNext()) {
            LogicalModel model = iter.next();
            if (modelId.equals(model.getId())) {
                iter.remove();
                found = true;
                break;
            }
        }
        // Update the domain if we change it
        if (found) {
            try {
                storeDomain(domain, true);
                flushDomains();
            } catch (DomainAlreadyExistsException ignored) {
            // This can't happen since we have setup overwrite to true
            }
        }
    }
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Domain(org.pentaho.metadata.model.Domain)

Aggregations

LogicalModel (org.pentaho.metadata.model.LogicalModel)53 Domain (org.pentaho.metadata.model.Domain)29 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)14 Test (org.junit.Test)13 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)11 ArrayList (java.util.ArrayList)10 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)9 Category (org.pentaho.metadata.model.Category)8 Matchers.anyString (org.mockito.Matchers.anyString)7 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)6 IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)5 IOException (java.io.IOException)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4