Search in sources :

Example 6 with DomainStorageException

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

the class MondrianImportHandler method importFile.

/**
 * **************************************** Main entry point from the Spring Interface
 *
 * @param IPlatformImportBundle
 * @throws IOException
 * @throws DomainStorageException
 * @throws DomainAlreadyExistsException
 * @throws DomainIdNullException
 * @throws PlatformImportException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    boolean overwriteInRepossitory = bundle.overwriteInRepository();
    boolean xmla = "false".equalsIgnoreCase(findParameterPropertyValue(bundle, ENABLE_XMLA)) ? false : true;
    final String domainId = (String) bundle.getProperty(DOMAIN_ID);
    if (domainId == null) {
        throw new PlatformImportException("Bundle missing required domain-id property");
    }
    try {
        InputStream is = bundle.getInputStream();
        MondrianCatalog catalog = this.createCatalogObject(domainId, xmla, bundle);
        IPentahoSession session = PentahoSessionHolder.getSession();
        if (mondrianRepositoryImporter instanceof IAclAwareMondrianCatalogService) {
            RepositoryFileAcl acl = bundle.isApplyAclSettings() ? bundle.getAcl() : null;
            IAclAwareMondrianCatalogService aware = (IAclAwareMondrianCatalogService) mondrianRepositoryImporter;
            aware.addCatalog(is, catalog, overwriteInRepossitory, acl, session);
        } else {
            mondrianRepositoryImporter.addCatalog(is, catalog, overwriteInRepossitory, session);
        }
    } catch (MondrianCatalogServiceException mse) {
        int statusCode = convertExceptionToStatus(mse);
        throw new PlatformImportException(mse.getMessage(), statusCode);
    } catch (Exception e) {
        throw new PlatformImportException(e.getMessage(), PlatformImportException.PUBLISH_GENERAL_ERROR);
    }
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) IAclAwareMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IAclAwareMondrianCatalogService) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IOException(java.io.IOException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) SAXException(org.xml.sax.SAXException)

Example 7 with DomainStorageException

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

the class PentahoMetadataDomainRepository method addLocalizationFile.

/**
 * Adds a set of properties as a locale properties file for the specified Domain ID
 *
 * @param domainId   the domain ID for which this properties file will be added
 * @param locale     the locale for which this properties file will be added
 * @param properties the properties to be added
 */
public void addLocalizationFile(final String domainId, final String locale, final Properties properties) throws DomainStorageException {
    // This is safe since ByteArray streams don't have to be closed
    if (null != properties) {
        try {
            final OutputStream out = new ByteArrayOutputStream();
            properties.store(out, null);
            addLocalizationFile(domainId, locale, new ByteArrayInputStream(out.toString().getBytes()), true);
        } catch (IOException e) {
            throw new DomainStorageException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0008_ERROR_IN_REPOSITORY", e.getLocalizedMessage()), e);
        }
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 8 with DomainStorageException

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

the class PentahoMetadataDomainRepository method storeDomain.

@Override
public void storeDomain(InputStream inputStream, String domainId, boolean overwrite, RepositoryFileAcl acl) throws DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("storeDomain(inputStream, %s, %s, %s)", domainId, overwrite, acl));
    }
    if (null == inputStream) {
        throw new IllegalArgumentException();
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new DomainIdNullException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL"));
    }
    // Check to see if the domain already exists
    RepositoryFile domainFile = getMetadataRepositoryFile(domainId);
    if (domainFile == null && domainId.endsWith(XMI_EXTENSION)) {
        domainFile = getMetadataRepositoryFile(domainId.substring(0, domainId.length() - XMI_EXTENSION.length()));
    }
    if (!overwrite && domainFile != null) {
        final String errorString = messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0002_DOMAIN_ALREADY_EXISTS", domainId);
        logger.error(errorString);
        throw new DomainAlreadyExistsException(errorString);
    }
    // Check if this is valid xml
    InputStream inputStream2;
    String xmi;
    try {
        // try to see if the xmi can be parsed (ie, check if it's valid xmi)
        // first, convert our input stream to a string
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, DEFAULT_ENCODING));
        try {
            while ((xmi = reader.readLine()) != null) {
                stringBuilder.append(xmi);
            }
        } finally {
            inputStream.close();
        }
        if (!isDomainIdXmiEqualsOrNotPresent(domainId, getDomainIdFromXmi(stringBuilder))) {
            domainId = replaceDomainId(stringBuilder, domainId);
        }
        xmi = stringBuilder.toString();
        // now, try to see if the xmi can be parsed (ie, check if it's valid xmi)
        byte[] xmiBytes = xmi.getBytes(DEFAULT_ENCODING);
        inputStream2 = new java.io.ByteArrayInputStream(xmiBytes);
        xmiParser.parseXmi(inputStream2);
        // xmi is valid. Create a new inputstream for the actual import action.
        inputStream2.reset();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        // throw new
        // DomainStorageException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0010_ERROR_PARSING_XMI"),
        // ex);
        java.io.ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ex.printStackTrace(new java.io.PrintStream(byteArrayOutputStream));
        throw new DomainStorageException(byteArrayOutputStream.toString(), ex);
    }
    final SimpleRepositoryFileData data = new SimpleRepositoryFileData(inputStream2, DEFAULT_ENCODING, DOMAIN_MIME_TYPE);
    final RepositoryFile newDomainFile;
    if (domainFile == null) {
        newDomainFile = createUniqueFile(domainId, null, data);
    } else {
        newDomainFile = repository.updateFile(domainFile, data, null);
    }
    // This invalidates any caching
    flushDomains();
    getAclHelper().setAclFor(newDomainFile, acl);
}
Also used : InputStreamReader(java.io.InputStreamReader) 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) BufferedReader(java.io.BufferedReader) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 9 with DomainStorageException

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

the class PentahoMetadataDomainRepository method addLocalizationFile.

@Override
public void addLocalizationFile(final String domainId, final String locale, final InputStream inputStream, final boolean overwrite) throws DomainStorageException {
    if (logger.isDebugEnabled()) {
        logger.debug("addLocalizationFile(" + domainId + ", " + locale + ", inputStream)");
    }
    if (null != inputStream) {
        if (StringUtils.isEmpty(domainId) || StringUtils.isEmpty(locale)) {
            throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
        }
        lock.writeLock().lock();
        try {
            // Check for duplicates
            final RepositoryFile localeFile = metadataMapping.getLocaleFile(domainId, locale);
            if (!overwrite && localeFile != null) {
                throw new DomainStorageException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0009_LOCALE_ALREADY_EXISTS", domainId, locale), null);
            }
            final SimpleRepositoryFileData data = new SimpleRepositoryFileData(inputStream, DEFAULT_ENCODING, LOCALE_MIME_TYPE);
            if (localeFile == null) {
                final RepositoryFile newLocaleFile = createUniqueFile(domainId, locale, data);
                metadataMapping.addLocale(domainId, locale, newLocaleFile);
            } else {
                repository.updateFile(localeFile, data, null);
            }
            // This invalidates any cached information
            flushDomains();
        } finally {
            lock.writeLock().unlock();
        }
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 10 with DomainStorageException

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

the class SolutionFolderIT method testMultiLocaleFileDiscovery.

/**
 * Tests MetadataDomainRepository.getLocalePropertyFilenames() when one xmi file and several property file exists in
 * the metadata folder.
 * Update: Get locales with use Domain.getLocaleCodes()
 */
@Test
public void testMultiLocaleFileDiscovery() {
    try {
        Domain steelWheels = loadDomain(STEEL_WHEELS, "./" + LEGACY_XMI_FILENAME);
        // get count of current locales
        final int previousLocaleSize = steelWheels.getLocaleCodes().length;
        // add new locales
        steelWheels.addLocale(new LocaleType("EN_US", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
        steelWheels.addLocale(new LocaleType("EN_GB", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
        steelWheels.addLocale(new LocaleType("NO_BOK", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
        // get the list of codes to import
        String[] localizationFiles = steelWheels.getLocaleCodes();
        // test the localization filenames for correctness
        ArrayList<String> solutionFileNames = new ArrayList<String>();
        for (String solutionFile : localizationFiles) {
            solutionFileNames.add(solutionFile);
        }
        assertNotNull(localizationFiles);
        assertEquals(previousLocaleSize + 3, localizationFiles.length);
        assertTrue(solutionFileNames.contains("EN_US"));
        assertTrue(solutionFileNames.contains("EN_GB"));
        assertTrue(solutionFileNames.contains("NO_BOK"));
    } catch (IOException ioe) {
        fail(ioe.getMessage());
    } catch (DomainStorageException dse) {
        fail(dse.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) ArrayList(java.util.ArrayList) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) IOException(java.io.IOException) Domain(org.pentaho.metadata.model.Domain) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) IOException(java.io.IOException) Test(org.junit.Test)

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