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));
}
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);
}
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);
}
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;
}
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
}
}
}
}
Aggregations