Search in sources :

Example 1 with DomainStorageException

use of org.pentaho.metadata.repository.DomainStorageException in project pentaho-platform by pentaho.

the class PentahoPlatformImporter method importFile.

/**
 * this is the main method that uses the mime time (from Spring) to determine which handler to invoke.
 */
public void importFile(IPlatformImportBundle file) throws PlatformImportException {
    String mime = file.getMimeType() != null ? file.getMimeType() : mimeResolver.resolveMimeForBundle(file);
    try {
        if (mime == null) {
            log.trace(messages.getString("PentahoPlatformImporter.ERROR_0001_INVALID_MIME_TYPE") + file.getName());
            repositoryImportLogger.error(messages.getString("PentahoPlatformImporter.ERROR_0001_INVALID_MIME_TYPE") + file.getName());
            return;
        }
        IPlatformImportHandler handler = (importHandlers.containsKey(mime) == false) ? defaultHandler : importHandlers.get(mime);
        if (handler == null) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0002_MISSING_IMPORT_HANDLER"), PlatformImportException.PUBLISH_GENERAL_ERROR);
        // replace with default handler?
        }
        try {
            logImportFile(file);
            handler.importFile(file);
        } catch (DomainIdNullException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0004_PUBLISH_TO_SERVER_FAILED"), PlatformImportException.PUBLISH_TO_SERVER_FAILED, e1);
        } catch (DomainAlreadyExistsException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0007_PUBLISH_SCHEMA_EXISTS_ERROR"), PlatformImportException.PUBLISH_SCHEMA_EXISTS_ERROR, e1);
        } catch (DomainStorageException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0004_PUBLISH_TO_SERVER_FAILED"), PlatformImportException.PUBLISH_DATASOURCE_ERROR, e1);
        } catch (IOException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0005_PUBLISH_GENERAL_ERRORR", e1.getLocalizedMessage()), PlatformImportException.PUBLISH_GENERAL_ERROR, e1);
        } catch (PlatformImportException pe) {
            // if already converted - just rethrow
            throw pe;
        } catch (Exception e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0005_PUBLISH_GENERAL_ERRORR", e1.getLocalizedMessage()), PlatformImportException.PUBLISH_GENERAL_ERROR, e1);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // If we are doing a logged import then we do not want to fail on a single file
        // so log the error and keep going.
        RepositoryFileImportBundle bundle = (RepositoryFileImportBundle) file;
        String repositoryFilePath = RepositoryFilenameUtils.concat(bundle.getPath(), bundle.getName());
        if (repositoryImportLogger.hasLogger() && repositoryFilePath != null && repositoryFilePath.length() > 0) {
            repositoryImportLogger.error(e);
        } else {
            if (e instanceof PlatformImportException) {
                throw (PlatformImportException) e;
            } else {
                // shouldn't happen but just in case
                throw new PlatformImportException(e.getMessage());
            }
        }
        if (e.getCause() instanceof UnifiedRepositoryAccessDeniedException) {
            throw new UnifiedRepositoryAccessDeniedException();
        }
    }
}
Also used : UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IOException(java.io.IOException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)

Example 2 with DomainStorageException

use of org.pentaho.metadata.repository.DomainStorageException in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method storeDomain.

/**
 * Store a domain to the repository. The domain should persist between JVM restarts.
 *
 * @param domain    domain object to store
 * @param overwrite if true, overwrite existing domain
 * @throws DomainIdNullException        if domain id is null or empty
 * @throws DomainAlreadyExistsException if a domain with the same Domain ID already exists in the repository and
 *                                      {@code overwrite == false}
 * @throws DomainStorageException       if there is a problem storing the domain
 */
@Override
public void storeDomain(final Domain domain, final boolean overwrite) throws DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    if (logger.isDebugEnabled()) {
        logger.debug("storeDomain(domain(id=" + (domain != null ? domain.getId() : "") + ", " + overwrite + ")");
    }
    if (null == domain || StringUtils.isEmpty(domain.getId())) {
        throw new DomainIdNullException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL"));
    }
    String xmi = "";
    try {
        // NOTE - a ByteArrayInputStream doesn't need to be closed ...
        // ... so this is safe AS LONG AS we use a ByteArrayInputStream
        xmi = xmiParser.generateXmi(domain);
        // final InputStream inputStream = new ByteArrayInputStream( xmi.getBytes( DEFAULT_ENCODING ) );
        final InputStream inputStream = new ByteArrayInputStream(xmi.getBytes("UTF8"));
        storeDomain(inputStream, domain.getId(), overwrite);
    } catch (DomainStorageException dse) {
        throw dse;
    } catch (DomainAlreadyExistsException dae) {
        throw dae;
    } catch (Exception e) {
        final String errorMessage = messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0003_ERROR_STORING_DOMAIN", domain.getId(), e.getLocalizedMessage());
        logger.error(errorMessage, e);
        throw new DomainStorageException(xmi + errorMessage, e);
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Example 3 with DomainStorageException

use of org.pentaho.metadata.repository.DomainStorageException in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testStoreDomain.

@Test
public void testStoreDomain() throws Exception {
    try {
        domainRepositorySpy.storeDomain(null, true);
        fail("Invalid domain should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new MockDomain(null), true);
        fail("Null domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new MockDomain(""), true);
        fail("Empty domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, null, true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, "", true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, "valid", true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(EMPTY_INPUT_STREAM, null, true);
        fail("Invalid domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(EMPTY_INPUT_STREAM, "", true);
        fail("Invalid domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    // Have the XmiParser fail
    try {
        domainRepositorySpy.storeDomain(new MockDomain("exception"), true);
        fail("An unexpected exception should throw a DomainStorageException");
    } catch (DomainStorageException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new ByteArrayInputStream(null), "valid", true);
        fail("Error with byte array input stream should throw exception");
    } catch (Exception success) {
    // ignored
    }
    domainRepositorySpy.removeDomain("steel-wheels_test");
    domainRepositorySpy.removeDomain(STEEL_WHEELS);
    domainRepositorySpy.removeDomain(SAMPLE_DOMAIN_ID);
    final MockDomain sample = new MockDomain(SAMPLE_DOMAIN_ID);
    domainRepositorySpy.storeDomain(sample, false);
    doReturn(true).when(aclNodeHelper).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
    final Domain domain = domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID);
    assertNotNull(domain);
    final List<LogicalModel> logicalModels = domain.getLogicalModels();
    assertNotNull(logicalModels);
    assertEquals(0, logicalModels.size());
    try {
        domainRepositorySpy.storeDomain(sample, false);
        fail("A duplicate domain with overwrite=false should fail");
    } catch (DomainAlreadyExistsException success) {
    // ignored
    }
    sample.addLogicalModel("test");
    domainRepositorySpy.storeDomain(sample, true);
    assertEquals(1, domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID).getLogicalModels().size());
    MockDomain xmiExtensionSample = new MockDomain(SAMPLE_DOMAIN_ID + ".xmi");
    try {
        domainRepositorySpy.storeDomain(xmiExtensionSample, false);
        fail("A duplicate domain with overwrite=false should fail");
    } catch (DomainAlreadyExistsException success) {
    // ignored
    }
    xmiExtensionSample.addLogicalModel("test1");
    xmiExtensionSample.addLogicalModel("test2");
    domainRepositorySpy.storeDomain(xmiExtensionSample, true);
    assertEquals(2, domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID).getLogicalModels().size());
    final RepositoryFile folder = domainRepositorySpy.getMetadataDir();
    assertNotNull(folder);
    assertTrue(folder.isFolder());
    assertEquals(1, repository.getChildren(folder.getId()).size());
    final Domain steelWheelsDomain = loadDomain(STEEL_WHEELS, "./steel-wheels.xmi");
    domainRepositorySpy.storeDomain(steelWheelsDomain, true);
    assertEquals(2, repository.getChildren(folder.getId()).size());
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Domain(org.pentaho.metadata.model.Domain) 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 4 with DomainStorageException

use of org.pentaho.metadata.repository.DomainStorageException in project pentaho-platform by pentaho.

the class SolutionImportHandler method importFile.

@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    RepositoryFileImportBundle importBundle = (RepositoryFileImportBundle) bundle;
    ZipInputStream zipImportStream = new ZipInputStream(bundle.getInputStream());
    SolutionRepositoryImportSource importSource = new SolutionRepositoryImportSource(zipImportStream);
    LocaleFilesProcessor localeFilesProcessor = new LocaleFilesProcessor();
    setOverwriteFile(bundle.overwriteInRepository());
    // importSession.set(ImportSession.getSession());
    IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
    cachedImports = new HashMap<String, RepositoryFileImportBundle.Builder>();
    // Process Manifest Settings
    ExportManifest manifest = getImportSession().getManifest();
    String manifestVersion = null;
    if (manifest != null) {
        manifestVersion = manifest.getManifestInformation().getManifestVersion();
    }
    // Process Metadata
    if (manifest != null) {
        // import the users
        Map<String, List<String>> roleToUserMap = importUsers(manifest.getUserExports());
        // import the roles
        importRoles(manifest.getRoleExports(), roleToUserMap);
        List<ExportManifestMetadata> metadataList = manifest.getMetadataList();
        for (ExportManifestMetadata exportManifestMetadata : metadataList) {
            String domainId = exportManifestMetadata.getDomainId();
            if (domainId != null && !domainId.endsWith(XMI_EXTENSION)) {
                domainId = domainId + XMI_EXTENSION;
            }
            boolean overWriteInRepository = isOverwriteFile();
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF-8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).preserveDsw(bundle.isPreserveDsw()).overwriteFile(overWriteInRepository).mime("text/xmi+xml").withParam("domain-id", domainId);
            cachedImports.put(exportManifestMetadata.getFile(), bundleBuilder);
        }
        // Process Mondrian
        List<ExportManifestMondrian> mondrianList = manifest.getMondrianList();
        for (ExportManifestMondrian exportManifestMondrian : mondrianList) {
            String catName = exportManifestMondrian.getCatalogName();
            Parameters parametersMap = exportManifestMondrian.getParameters();
            StringBuilder parametersStr = new StringBuilder();
            for (String s : parametersMap.keySet()) {
                parametersStr.append(s).append("=").append(parametersMap.get(s)).append(sep);
            }
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF_8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).name(catName).overwriteFile(isOverwriteFile()).mime("application/vnd.pentaho.mondrian+xml").withParam("parameters", parametersStr.toString()).withParam("domain-id", // TODO: this is
            catName);
            // definitely
            // named wrong
            // at the very
            // least.
            // pass as param if not in parameters string
            String xmlaEnabled = "" + exportManifestMondrian.isXmlaEnabled();
            bundleBuilder.withParam("EnableXmla", xmlaEnabled);
            cachedImports.put(exportManifestMondrian.getFile(), bundleBuilder);
            String annotationsFile = exportManifestMondrian.getAnnotationsFile();
            if (annotationsFile != null) {
                RepositoryFileImportBundle.Builder annotationsBundle = new RepositoryFileImportBundle.Builder().path(MondrianCatalogRepositoryHelper.ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catName).name("annotations.xml").charSet("UTF_8").overwriteFile(isOverwriteFile()).mime("text/xml").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).withParam("domain-id", catName);
                cachedImports.put(annotationsFile, annotationsBundle);
            }
        }
    }
    importMetaStore(manifest, bundle.overwriteInRepository());
    for (IRepositoryFileBundle fileBundle : importSource.getFiles()) {
        String fileName = fileBundle.getFile().getName();
        String actualFilePath = fileBundle.getPath();
        if (manifestVersion != null) {
            fileName = ExportFileNameEncoder.decodeZipFileName(fileName);
            actualFilePath = ExportFileNameEncoder.decodeZipFileName(actualFilePath);
        }
        String repositoryFilePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        if (this.cachedImports.containsKey(repositoryFilePath)) {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            RepositoryFileImportBundle.Builder builder = cachedImports.get(repositoryFilePath);
            builder.input(new ByteArrayInputStream(bytes));
            importer.importFile(build(builder));
            continue;
        }
        RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
        InputStream bundleInputStream = null;
        String decodedFilePath = fileBundle.getPath();
        RepositoryFile decodedFile = fileBundle.getFile();
        if (manifestVersion != null) {
            decodedFile = new RepositoryFile.Builder(decodedFile).path(decodedFilePath).name(fileName).title(fileName).build();
            decodedFilePath = ExportFileNameEncoder.decodeZipFileName(fileBundle.getPath());
        }
        if (fileBundle.getFile().isFolder()) {
            bundleBuilder.mime("text/directory");
            bundleBuilder.file(decodedFile);
            fileName = repositoryFilePath;
            repositoryFilePath = importBundle.getPath();
        } else {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            bundleInputStream = new ByteArrayInputStream(bytes);
            // If is locale file store it for later processing.
            if (localeFilesProcessor.isLocaleFile(fileBundle, importBundle.getPath(), bytes)) {
                log.trace("Skipping [" + repositoryFilePath + "], it is a locale property file");
                continue;
            }
            bundleBuilder.input(bundleInputStream);
            bundleBuilder.mime(solutionHelper.getMime(fileName));
            String filePath = (decodedFilePath.equals("/") || decodedFilePath.equals("\\")) ? "" : decodedFilePath;
            repositoryFilePath = RepositoryFilenameUtils.concat(importBundle.getPath(), filePath);
        }
        bundleBuilder.name(fileName);
        bundleBuilder.path(repositoryFilePath);
        String sourcePath;
        if (fileBundle.getFile().isFolder()) {
            sourcePath = fileName;
        } else {
            sourcePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        }
        // may not have rights to such as /home or /public
        if (manifest != null && manifest.getExportManifestEntity(sourcePath) == null && fileBundle.getFile().isFolder()) {
            continue;
        }
        getImportSession().setCurrentManifestKey(sourcePath);
        bundleBuilder.charSet(bundle.getCharset());
        bundleBuilder.overwriteFile(bundle.overwriteInRepository());
        bundleBuilder.applyAclSettings(bundle.isApplyAclSettings());
        bundleBuilder.retainOwnership(bundle.isRetainOwnership());
        bundleBuilder.overwriteAclSettings(bundle.isOverwriteAclSettings());
        bundleBuilder.acl(getImportSession().processAclForFile(sourcePath));
        RepositoryFile file = getFile(importBundle, fileBundle);
        ManifestFile manifestFile = getImportSession().getManifestFile(sourcePath, file != null);
        bundleBuilder.hidden(isFileHidden(file, manifestFile, sourcePath));
        boolean isSchedulable = isSchedulable(file, manifestFile);
        if (isSchedulable) {
            bundleBuilder.schedulable(isSchedulable);
        } else {
            bundleBuilder.schedulable(fileIsScheduleInputSource(manifest, sourcePath));
        }
        IPlatformImportBundle platformImportBundle = build(bundleBuilder);
        importer.importFile(platformImportBundle);
        if (bundleInputStream != null) {
            bundleInputStream.close();
            bundleInputStream = null;
        }
    }
    if (manifest != null) {
        importSchedules(manifest.getScheduleList());
        // Add Hitachi Vantara Connections
        List<org.pentaho.database.model.DatabaseConnection> datasourceList = manifest.getDatasourceList();
        if (datasourceList != null) {
            IDatasourceMgmtService datasourceMgmtSvc = PentahoSystem.get(IDatasourceMgmtService.class);
            for (org.pentaho.database.model.DatabaseConnection databaseConnection : datasourceList) {
                if (databaseConnection.getDatabaseType() == null) {
                    // don't try to import the connection if there is no type it will cause an error
                    // However, if this is the DI Server, and the connection is defined in a ktr, it will import automatically
                    log.warn("Can't import connection " + databaseConnection.getName() + " because it doesn't have a databaseType");
                    continue;
                }
                try {
                    IDatabaseConnection existingDBConnection = datasourceMgmtSvc.getDatasourceByName(databaseConnection.getName());
                    if (existingDBConnection != null && existingDBConnection.getName() != null) {
                        if (isOverwriteFile()) {
                            databaseConnection.setId(existingDBConnection.getId());
                            datasourceMgmtSvc.updateDatasourceByName(databaseConnection.getName(), databaseConnection);
                        }
                    } else {
                        datasourceMgmtSvc.createDatasource(databaseConnection);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // Process locale files.
    localeFilesProcessor.processLocaleFiles(importer);
}
Also used : ExportManifestMetadata(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) List(java.util.List) ArrayList(java.util.ArrayList) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IRepositoryFileBundle(org.pentaho.platform.plugin.services.importexport.ImportSource.IRepositoryFileBundle) Parameters(org.pentaho.platform.plugin.services.importexport.exportManifest.Parameters) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ManifestFile(org.pentaho.platform.plugin.services.importexport.ImportSession.ManifestFile) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 5 with DomainStorageException

use of org.pentaho.metadata.repository.DomainStorageException in project pentaho-platform by pentaho.

the class MetadataImportHandler method processMetadataFile.

/**
 * Processes the file as a metadata file and returns the domain name. It will import the file into the Pentaho
 * Metadata Domain Repository.
 *
 * @param bundle
 * @return
 */
protected String processMetadataFile(final IPlatformImportBundle bundle) throws PlatformImportException {
    final String domainId = (String) bundle.getProperty("domain-id");
    if (domainId == null) {
        throw new PlatformImportException("Bundle missing required domain-id property");
    }
    try {
        log.debug("Importing as metadata - [domain=" + domainId + "]");
        final InputStream inputStream;
        if (bundle.isPreserveDsw()) {
            // storeDomain needs to be able to close the stream
            inputStream = cloneStream(bundle.getInputStream());
        } else {
            inputStream = StripDswFromStream(bundle.getInputStream());
        }
        if (metadataRepositoryImporter instanceof IAclAwarePentahoMetadataDomainRepositoryImporter) {
            IAclAwarePentahoMetadataDomainRepositoryImporter importer = (IAclAwarePentahoMetadataDomainRepositoryImporter) metadataRepositoryImporter;
            importer.storeDomain(inputStream, domainId, bundle.overwriteInRepository(), bundle.isApplyAclSettings() ? bundle.getAcl() : null);
        } else {
            metadataRepositoryImporter.storeDomain(inputStream, domainId, bundle.overwriteInRepository());
        }
        if (metadataRepositoryImporter instanceof IModelAnnotationsAwareMetadataDomainRepositoryImporter) {
            // Store annotations xml with the domain if it exists
            final String annotationsXml = (String) bundle.getProperty(IModelAnnotationsAwareMetadataDomainRepositoryImporter.PROPERTY_NAME_ANNOTATIONS);
            if (StringUtils.isNotBlank(annotationsXml)) {
                // Save annotations
                IModelAnnotationsAwareMetadataDomainRepositoryImporter importer = (IModelAnnotationsAwareMetadataDomainRepositoryImporter) metadataRepositoryImporter;
                importer.storeAnnotationsXml(domainId, annotationsXml);
            }
        }
        return domainId;
    } catch (DomainIdNullException dine) {
        throw new PlatformImportException(dine.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, dine);
    } catch (DomainStorageException dse) {
        throw new PlatformImportException(dse.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, dse);
    } catch (DomainAlreadyExistsException daee) {
        throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0007_PUBLISH_SCHEMA_EXISTS_ERROR"), PlatformImportException.PUBLISH_SCHEMA_EXISTS_ERROR, daee);
    } catch (Exception e) {
        final String errorMessage = messages.getErrorString("MetadataImportHandler.ERROR_0001_IMPORTING_METADATA", domainId, e.getLocalizedMessage());
        log.error(errorMessage, e);
        throw new PlatformImportException(errorMessage, e);
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IModelAnnotationsAwareMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IModelAnnotationsAwareMetadataDomainRepositoryImporter) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IAclAwarePentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IAclAwarePentahoMetadataDomainRepositoryImporter) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException)

Aggregations

DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)12 IOException (java.io.IOException)9 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)8 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)5 Domain (org.pentaho.metadata.model.Domain)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)4 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 LocaleType (org.pentaho.metadata.model.concept.types.LocaleType)2 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)2 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)2 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)2 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)2 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1