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();
}
}
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);
}
}
}
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);
}
}
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;
}
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;
}
Aggregations