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