Search in sources :

Example 81 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method removeDomain.

/**
 * remove a domain from disk and memory.
 *
 * @param domainId
 */
@Override
public void removeDomain(final String domainId) {
    if (logger.isDebugEnabled()) {
        logger.debug("removeDomain(" + domainId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    // Get the metadata domain file
    RepositoryFile domainFile;
    Set<RepositoryFile> domainFiles;
    lock.writeLock().lock();
    try {
        domainFiles = metadataMapping.getFiles(domainId);
        domainFile = metadataMapping.getDomainFile(domainId);
        metadataMapping.deleteDomain(domainId);
    } finally {
        lock.writeLock().unlock();
    }
    if (domainFile != null) {
        // it no node exists, nothing would happen
        getAclHelper().removeAclFor(domainFile);
    }
    for (final RepositoryFile file : domainFiles) {
        if (logger.isTraceEnabled()) {
            logger.trace("Deleting repository file " + toString(file));
        }
        repository.deleteFile(file.getId(), true, null);
    }
    // This invalidates any caching
    if (!domainFiles.isEmpty()) {
        flushDomains();
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 82 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method loadLocaleStrings.

protected void loadLocaleStrings(final String domainId, final Domain domain) {
    final Map<String, RepositoryFile> localeFiles = metadataMapping.getLocaleFiles(domainId);
    if (localeFiles != null) {
        for (final String locale : localeFiles.keySet()) {
            final RepositoryFile localeFile = localeFiles.get(locale);
            final Properties properties = loadProperties(localeFile);
            if (logger.isTraceEnabled()) {
                logger.trace("\tLoading properties [" + domain + " : " + locale + "]");
            }
            localizationUtil.importLocalizedProperties(domain, properties, locale);
        }
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Properties(java.util.Properties)

Example 83 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method loadProperties.

protected Properties loadProperties(final RepositoryFile bundle) {
    try {
        Properties properties = null;
        final SimpleRepositoryFileData bundleData = repository.getDataForRead(bundle.getId(), SimpleRepositoryFileData.class);
        if (bundleData != null) {
            properties = new Properties();
            properties.load(bundleData.getStream());
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Could not load properties from repository file: " + bundle.getName());
            }
        }
        return properties;
    } catch (IOException e) {
        throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0008_ERROR_IN_REPOSITORY", e.getLocalizedMessage()), e);
    }
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 84 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method getDomain.

/**
 * retrieve a domain from the repo. This does lazy loading of the repo, so it calls reloadDomains() if not already
 * loaded.
 *
 * @param domainId domain to get from the repository
 * @return domain object
 */
@Override
public Domain getDomain(final String domainId) {
    if (logger.isDebugEnabled()) {
        logger.debug("getDomain(" + domainId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    Domain domain = null;
    try {
        // Load the domain file
        final RepositoryFile file = getMetadataRepositoryFile(domainId);
        if (file != null) {
            if (hasAccessFor(file)) {
                SimpleRepositoryFileData data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
                if (data != null) {
                    InputStream is = data.getStream();
                    try {
                        domain = xmiParser.parseXmi(is);
                    } finally {
                        IOUtils.closeQuietly(is);
                    }
                    domain.setId(domainId);
                    logger.debug("loaded domain");
                    // Load any I18N bundles
                    loadLocaleStrings(domainId, domain);
                    logger.debug("loaded I18N bundles");
                } else {
                    throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "data not found"));
                }
            } else {
                throw new PentahoAccessControlException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "access denied"));
            }
        }
    } catch (Exception e) {
        if (!(e instanceof UnifiedRepositoryException || e instanceof PentahoAccessControlException)) {
            throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, e.getLocalizedMessage()), e);
        }
    }
    // Return
    return domain;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) 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 85 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method getMetadataRepositoryFile.

/**
 * Accesses the metadata mapping (with 1 retry) to find the metadata file for the specified domainId
 */
protected RepositoryFile getMetadataRepositoryFile(final String domainId) {
    lock.readLock().lock();
    RepositoryFile domainFile;
    try {
        domainFile = metadataMapping.getDomainFile(domainId);
    } finally {
        lock.readLock().unlock();
    }
    if (domainFile == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Requested Domain (" + domainId + ") wasn't found in Metadata Mapping. Domain cache will be reloaded");
        }
        lock.writeLock().lock();
        try {
            domainFile = metadataMapping.getDomainFile(domainId);
            if (domainFile == null) {
                reloadDomainsIfNeeded();
                domainFile = metadataMapping.getDomainFile(domainId);
            }
        } finally {
            lock.writeLock().unlock();
        }
    }
    if (domainFile == null && logger.isDebugEnabled()) {
        logger.debug("Even after reloading all domains, the specified Domain wasn't found in the system: " + domainId);
    }
    return domainFile;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32