use of org.pentaho.metadata.util.XmiParser 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.util.XmiParser in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method testLoadLocaleStrings.
@Test
public void testLoadLocaleStrings() throws Exception {
// Add a domain with no external locale information
domainRepositorySpy.setXmiParser(new XmiParser());
final Domain steelWheels = loadDomain(STEEL_WHEELS, "./steel-wheels.xmi");
domainRepositorySpy.storeDomain(steelWheels, true);
final int initialLocaleSize = steelWheels.getLocaleCodes().length;
assertEquals(initialLocaleSize, steelWheels.getLocales().size());
domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
assertEquals(initialLocaleSize, steelWheels.getLocaleCodes().length);
assertEquals(initialLocaleSize, steelWheels.getLocales().size());
final Properties newLocale = new Properties();
newLocale.put("[LogicalModel-BV_HUMAN_RESOURCES].[description]", "New Description in Italian");
domainRepositorySpy.addLocalizationFile(STEEL_WHEELS, "it_IT", newLocale);
domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
final int newLocaleSize = initialLocaleSize + 1;
assertEquals(newLocaleSize, steelWheels.getLocales().size());
domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
assertEquals(newLocaleSize, steelWheels.getLocaleCodes().length);
assertEquals(newLocaleSize, steelWheels.getLocales().size());
}
use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryConcurrencyTest method mockXmiParser.
private XmiParser mockXmiParser() throws Exception {
XmiParser parser = mock(XmiParser.class);
when(parser.generateXmi(any(Domain.class))).thenReturn("");
when(parser.parseXmi(any(InputStream.class))).thenAnswer(new Answer<Domain>() {
@Override
public Domain answer(InvocationOnMock invocation) throws Throwable {
return new Domain();
}
});
return parser;
}
use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method testInitialization.
@Test
public void testInitialization() {
try {
createDomainRepository(null);
fail("An exception should be thrown");
} catch (Exception success) {
// ignored
}
try {
createDomainRepository(null, null, null, null);
fail("An exception should be thrown");
} catch (Exception success) {
// ignored
}
final RepositoryUtils repositoryUtils = new RepositoryUtils(repository);
final XmiParser xmiParser = new XmiParser();
final LocalizationUtil localizationUtil = new LocalizationUtil();
final PentahoMetadataDomainRepository repo = createDomainRepository(repository, repositoryUtils, xmiParser, localizationUtil);
assertEquals(repository, repo.getRepository());
assertEquals(repositoryUtils, repo.getRepositoryUtils());
assertEquals(xmiParser, repo.getXmiParser());
assertEquals(localizationUtil, repo.getLocalizationUtil());
}
use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.
the class SolutionFolderIT method loadDomain.
private static final Domain loadDomain(final String domainId, final String domainFile) throws Exception {
final InputStream in = SolutionFolderIT.class.getResourceAsStream(domainFile);
final XmiParser parser = new XmiParser();
final Domain domain = parser.parseXmi(in);
domain.setId(domainId);
IOUtils.closeQuietly(in);
return domain;
}
Aggregations