use of org.pentaho.metadata.repository.DomainAlreadyExistsException 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);
}
}
use of org.pentaho.metadata.repository.DomainAlreadyExistsException 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.DomainAlreadyExistsException in project pentaho-platform by pentaho.
the class MockSessionAwareMetadataDomainRepository method removeModel.
@Override
public void removeModel(String domainId, String modelId) throws DomainIdNullException, DomainStorageException {
// $NON-NLS-1$
incrementInvocationCount("removeModel");
// don't actually do anything
Domain domain = getDomain(domainId);
removeDomain(domainId);
try {
storeDomain(domain, true);
} catch (DomainAlreadyExistsException ex) {
throw new IllegalStateException(ex);
}
}
use of org.pentaho.metadata.repository.DomainAlreadyExistsException 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.DomainAlreadyExistsException in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testStoreDomain.
public void testStoreDomain() throws Exception {
// $NON-NLS-1$
final String ID = "1";
MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
repo.storeDomain(getTestDomain(ID), false);
// No cache values when storing a domain
assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Cache one domain
repo.getDomain(ID);
// Storing a domain under a different session should wipe out all cached domains with the same id
// $NON-NLS-1$ //$NON-NLS-2$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
try {
repo.storeDomain(getTestDomain(ID), false);
// $NON-NLS-1$
fail("Should have thrown a " + DomainAlreadyExistsException.class.getSimpleName());
} catch (DomainAlreadyExistsException ex) {
// expected
}
repo.storeDomain(getTestDomain(ID), true);
// Storing a domain under a different session should wipe out all cached domains with the same id
assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
assertEquals(1, repo.getDomainIds().size());
repo.getDomain(ID);
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Storing a domain should only wipe out the cached domains with the same id
// $NON-NLS-1$
repo.storeDomain(getTestDomain("2"), false);
assertEquals(2, repo.getDomainIds().size());
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Aggregations