use of org.pentaho.metadata.model.Domain in project pentaho-kettle by pentaho.
the class JobGeneratorTest method setUp.
@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);
}
use of org.pentaho.metadata.model.Domain in project pentaho-kettle by pentaho.
the class MetadataGenerator method generatePhysicalMetadataModel.
public Domain generatePhysicalMetadataModel() throws KettleException {
// First do some checking and lookups...
//
String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
if (Utils.isEmpty(targetDatabaseName)) {
throw new KettleException("Please specify a target database!");
}
DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
if (targetDatabaseMeta == null) {
throw new KettleException("Target database with name '" + targetDatabaseName + "' can't be found!");
}
// Now start creation of a new domain with physical underpinning.
//
Domain domain = new Domain();
// Copy the domain information...
//
domain.setId(createId("DOMAIN", null, domain));
domain.setName(logicalDomain.getName());
domain.setDescription(logicalDomain.getDescription());
//
for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
// Copy model information...
//
LogicalModel model = new LogicalModel();
model.setId(createId("MODEL", domain, model));
model.setName(logicalModel.getName());
model.setDescription(logicalModel.getDescription());
// Create a physical model...
//
SqlPhysicalModel sqlModel = new SqlPhysicalModel();
sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
model.setPhysicalModel(sqlModel);
for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
LogicalTable table = new LogicalTable();
table.setId(createId("LOGICAL_TABLE", logicalModel, logicalTable));
table.setName(logicalTable.getName());
table.setDescription(logicalTable.getDescription());
String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
table.setPhysicalTable(sqlTable);
// Copy name & description from physical level...
//
sqlTable.setId(createId("PHYSICAL_TABLE", logicalModel, logicalTable));
sqlTable.setName(logicalTable.getName());
sqlTable.setDescription(logicalTable.getDescription());
sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
sqlTable.setTargetTable(targetTable);
}
}
return domain;
}
use of org.pentaho.metadata.model.Domain 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.Domain in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepository method getDomain.
/**
* retrieve a domain from the repo. This does lazy loading of the repo, so it calls reloadDomains() if not already
* loaded.
*
* @param domainId domain to get from the repository
* @return domain object
*/
@Override
public Domain getDomain(final String domainId) {
if (logger.isDebugEnabled()) {
logger.debug("getDomain(" + domainId + ")");
}
if (StringUtils.isEmpty(domainId)) {
throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
}
Domain domain = null;
try {
// Load the domain file
final RepositoryFile file = getMetadataRepositoryFile(domainId);
if (file != null) {
if (hasAccessFor(file)) {
SimpleRepositoryFileData data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
if (data != null) {
InputStream is = data.getStream();
try {
domain = xmiParser.parseXmi(is);
} finally {
IOUtils.closeQuietly(is);
}
domain.setId(domainId);
logger.debug("loaded domain");
// Load any I18N bundles
loadLocaleStrings(domainId, domain);
logger.debug("loaded I18N bundles");
} else {
throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "data not found"));
}
} else {
throw new PentahoAccessControlException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "access denied"));
}
}
} catch (Exception e) {
if (!(e instanceof UnifiedRepositoryException || e instanceof PentahoAccessControlException)) {
throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, e.getLocalizedMessage()), e);
}
}
// Return
return domain;
}
use of org.pentaho.metadata.model.Domain 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