Search in sources :

Example 6 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswFromTemp.

@Test
public void testPublishDswFromTemp() throws Exception {
    InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(mockInputStream).when(dataSourceWizardService).toInputStreamWrapper(mockDomain, mockXmiParser);
    doReturn(mockMetadataBundle).when(dataSourceWizardService).createMetadataDswBundle(mockDomain, mockInputStream, overwrite, aclDto);
    doReturn(mockMondrianBundle).when(dataSourceWizardService).createMondrianDswBundle(mockDomain, aclDto);
    doReturn(mockIPlatformImporter).when(dataSourceWizardService).getIPlatformImporter();
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doReturn(metadataFile).when(dataSourceWizardService).createInputStreamFromFile(anyString());
    MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
    fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
    String list = "{\"xmiFileName\":\"" + XMI_TEMP_FILE_NAME + "\"}";
    String response = dataSourceWizardService.publishDswFromTemp(DOMAIN_ID, fileList, overwrite, checkConnection, aclDto);
    assertEquals(DOMAIN_ID + DataSourceWizardService.METADATA_EXT, response);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) XmiParser(org.pentaho.metadata.util.XmiParser) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 7 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.

the class DataSourceWizardService method publishDsw.

public String publishDsw(String domainId, InputStream metadataFile, List<InputStream> localizeFiles, List<String> localizeFileNames, boolean overwrite, boolean checkConnection, RepositoryFileAclDto acl) throws PentahoAccessControlException, IllegalArgumentException, DswPublishValidationException, Exception {
    if (!hasManageAccessCheck()) {
        throw new PentahoAccessControlException();
    }
    if (!endsWith(domainId, METADATA_EXT)) {
        // if doesn't end in case-sensitive '.xmi' there will be trouble later on
        final String errorMsg = "domainId must end in " + METADATA_EXT;
        throw new IllegalArgumentException(errorMsg);
    }
    if (localizeFiles == null ? (localizeFileNames != null) : (localizeFiles.size() != localizeFileNames.size())) {
        throw new IllegalArgumentException("localizeFiles and localizeFileNames must have equal size");
    }
    if (metadataFile == null) {
        throw new IllegalArgumentException("metadataFile is null");
    }
    if (!overwrite) {
        final List<String> overwritten = getOverwrittenDomains(domainId);
        if (!overwritten.isEmpty()) {
            final String domainIds = StringUtils.join(overwritten, ",");
            throw new DswPublishValidationException(DswPublishValidationException.Type.OVERWRITE_CONFLICT, domainIds);
        }
    }
    XmiParser xmiParser = createXmiParser();
    Domain domain = null;
    try {
        domain = xmiParser.parseXmi(metadataFile);
    } catch (Exception e) {
        throw new DswPublishValidationException(DswPublishValidationException.Type.INVALID_XMI, e.getMessage());
    }
    domain.setId(domainId);
    if (checkConnection) {
        final String connectionId = getMondrianDatasourceWrapper(domain);
        // Left second check with non-escaped name for backward compatibility
        if (datasourceMgmtSvc.getDatasourceByName(sanitizer.escape(connectionId)) == null && datasourceMgmtSvc.getDatasourceByName(connectionId) == null) {
            final String msg = "connection not found: '" + connectionId + "'";
            throw new DswPublishValidationException(Type.MISSING_CONNECTION, msg);
        }
    }
    // build bundles
    IPlatformImportBundle mondrianBundle = createMondrianDswBundle(domain, acl);
    InputStream metadataIn = toInputStreamWrapper(domain, xmiParser);
    IPlatformImportBundle metadataBundle = createMetadataDswBundle(domain, metadataIn, overwrite, acl);
    // add localization bundles
    if (localizeFiles != null) {
        for (int i = 0; i < localizeFiles.size(); i++) {
            IPlatformImportBundle localizationBundle = MetadataService.createNewRepositoryFileImportBundle(localizeFiles.get(i), localizeFileNames.get(i), domainId);
            metadataBundle.getChildBundles().add(localizationBundle);
            logger.info("created language file");
        }
    }
    // do import
    IPlatformImporter importer = getIPlatformImporter();
    importer.importFile(metadataBundle);
    logger.debug("imported metadata xmi");
    importer.importFile(mondrianBundle);
    logger.debug("imported mondrian schema");
    // trigger refreshes
    IPentahoSession session = getSession();
    PentahoSystem.publish(session, METADATA_PUBLISHER);
    PentahoSystem.publish(session, MONDRIAN_PUBLISHER);
    logger.info("publishDsw: Published DSW with domainId='" + domainId + "'.");
    return domainId;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IOException(java.io.IOException) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) XmiParser(org.pentaho.metadata.util.XmiParser) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Domain(org.pentaho.metadata.model.Domain)

Example 8 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.

the class MetadataService method isContainsModel.

public boolean isContainsModel(String tempFileName) throws Exception {
    XmiParser xmiParser = new XmiParser();
    byte[] is = IOUtils.toByteArray(createInputStreamFromFile(internalGetUploadDir() + File.separatorChar + tempFileName));
    Domain domain = xmiParser.parseXmi(new java.io.ByteArrayInputStream(is));
    return isContainsModel(domain);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Example 9 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testSetXmiParser.

@Test
public void testSetXmiParser() throws Exception {
    domainRepositorySpy.setXmiParser(null);
    domainRepositorySpy.setXmiParser(new XmiParser());
}
Also used : XmiParser(org.pentaho.metadata.util.XmiParser) Test(org.junit.Test)

Example 10 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method loadDomain.

/**
 * Loads a "real" Pentaho Metadata Domain
 *
 * @param domainId
 * @param domainFile
 * @return
 * @throws Exception
 */
private static Domain loadDomain(final String domainId, final String domainFile) throws Exception {
    final InputStream in = PentahoMetadataDomainRepositoryTest.class.getResourceAsStream(domainFile);
    final XmiParser parser = new XmiParser();
    final Domain domain = parser.parseXmi(in);
    domain.setId(domainId);
    IOUtils.closeQuietly(in);
    return domain;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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