Search in sources :

Example 1 with XmiParser

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;
}
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 2 with XmiParser

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());
}
Also used : XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with XmiParser

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Example 4 with XmiParser

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());
}
Also used : RepositoryUtils(org.pentaho.platform.repository2.unified.RepositoryUtils) LocalizationUtil(org.pentaho.metadata.util.LocalizationUtil) XmiParser(org.pentaho.metadata.util.XmiParser) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with XmiParser

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;
}
Also used : InputStream(java.io.InputStream) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Aggregations

XmiParser (org.pentaho.metadata.util.XmiParser)12 Domain (org.pentaho.metadata.model.Domain)10 InputStream (java.io.InputStream)8 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)4 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)4 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)2 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)2 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)2 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)2 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)2 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1