use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException in project data-access by pentaho.
the class DataSourceWizardServiceTest method testErrorRemovingMondrianDoesNotStopXMIRemoval.
@Test
public void testErrorRemovingMondrianDoesNotStopXMIRemoval() throws Exception {
Domain mockDomain = mock(Domain.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
LogicalModel mockLogicalModel = mock(LogicalModel.class);
String mockObject = "not null";
String dswId = "dswId";
doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
doThrow(new MondrianCatalogServiceException("who cares")).when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
doNothing().when(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
dataSourceWizardService.removeDSW("dswId");
verify(dataSourceWizardService, times(1)).removeDSW("dswId");
verify(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException in project data-access by pentaho.
the class DataSourceWizardService method removeDSW.
public void removeDSW(String dswId) throws PentahoAccessControlException {
try {
ensureDataAccessPermissionCheck();
} catch (ConnectionServiceException e) {
throw new PentahoAccessControlException();
}
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
try {
mondrianCatalogService.removeCatalog(catalogRef, getSession());
} catch (MondrianCatalogServiceException e) {
logger.warn("Failed to remove mondrian catalog", e);
}
}
try {
dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
} catch (DatasourceServiceException ex) {
logger.warn("Failed to remove logical model", ex);
}
metadataDomainRepository.removeDomain(dswId);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException 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.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException in project pentaho-platform by pentaho.
the class MondrianImportHandlerTest method testConvertExceptionToStatus.
public void testConvertExceptionToStatus(int importStatus, Reason reason) {
MondrianCatalogServiceException exception = new MondrianCatalogServiceException("msg", reason);
when(bundle.getProperty(eq(MondrianImportHandler.DOMAIN_ID))).thenReturn(MondrianImportHandler.DOMAIN_ID);
doThrow(exception).when(mondrianImporter).addCatalog(any(InputStream.class), any(MondrianCatalog.class), anyBoolean(), any(IPentahoSession.class));
try {
testImportFileBase();
} catch (PlatformImportException e) {
assertEquals(importStatus, e.getErrorStatus());
} catch (Exception e) {
fail("According current implementation, should not happen.");
}
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException in project data-access by pentaho.
the class DSWDatasourceServiceImpl method deleteLogicalModel.
public boolean deleteLogicalModel(String domainId, String modelName) throws DatasourceServiceException {
if (!hasDataAccessPermission()) {
// $NON-NLS-1$
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
return false;
}
String catalogRef = null;
String targetTable = null;
try {
// first load the model
Domain domain = getMetadataDomainRepository().getDomain(domainId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
LogicalModel logicalModelRep = model.getLogicalModel(ModelerPerspective.REPORTING);
// CSV related data is bounded to reporting model so need to perform some additional clean up here
if (logicalModelRep != null) {
String modelState = (String) logicalModelRep.getProperty(LM_PROP_DATASOURCE_MODEL);
// TODO: use the edit story's stored info to do this
if ("CSV".equals(logicalModelRep.getProperty(LM_PROP_DATASOURCE_TYPE)) || "true".equalsIgnoreCase((String) logicalModelRep.getProperty(LogicalModel.PROPERTY_TARGET_TABLE_STAGED))) {
targetTable = ((SqlPhysicalTable) domain.getPhysicalModels().get(0).getPhysicalTables().get(0)).getTargetTable();
DatasourceDTO datasource = null;
if (modelState != null) {
datasource = deSerializeModelState(modelState);
}
if (datasource != null) {
CsvTransformGenerator csvTransformGenerator = new CsvTransformGenerator(datasource.getCsvModelInfo(), AgileHelper.getDatabaseMeta());
try {
csvTransformGenerator.dropTable(targetTable);
} catch (CsvTransformGeneratorException e) {
// table might not be there, it's OK that is what we were trying to do anyway
logger.warn(Messages.getErrorString("DatasourceServiceImpl.ERROR_0019_UNABLE_TO_DROP_TABLE", targetTable, domainId, e.getLocalizedMessage()), // $NON-NLS-1$
e);
}
String fileName = datasource.getCsvModelInfo().getFileInfo().getFilename();
FileUtils fileService = new FileUtils();
if (fileName != null) {
fileService.deleteFile(fileName);
}
}
}
}
// if associated mondrian file, delete
if (logicalModel.getProperty(LM_PROP_MONDRIAN_CATALOG_REF) != null) {
// remove Mondrian schema
IMondrianCatalogService service = PentahoSystem.get(IMondrianCatalogService.class, null);
catalogRef = (String) logicalModel.getProperty(LM_PROP_MONDRIAN_CATALOG_REF);
// check if the model is not already removed
if (service.getCatalog(catalogRef, PentahoSessionHolder.getSession()) != null) {
service.removeCatalog(catalogRef, PentahoSessionHolder.getSession());
}
}
getMetadataDomainRepository().removeModel(domainId, logicalModel.getId());
if (logicalModelRep != null && !logicalModelRep.getId().equals(logicalModel.getId())) {
getMetadataDomainRepository().removeModel(domainId, logicalModelRep.getId());
}
// get updated domain
domain = getMetadataDomainRepository().getDomain(domainId);
if (domain == null) {
// already deleted
return true;
}
if (domain.getLogicalModels() == null || domain.getLogicalModels().isEmpty()) {
getMetadataDomainRepository().removeDomain(domainId);
}
} catch (MondrianCatalogServiceException me) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0020_UNABLE_TO_DELETE_CATALOG", catalogRef, domainId, me.getLocalizedMessage()), // $NON-NLS-1$
me);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0020_UNABLE_TO_DELETE_CATALOG", catalogRef, domainId, me.getLocalizedMessage()), // $NON-NLS-1$
me);
} catch (DomainStorageException dse) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0017_UNABLE_TO_STORE_DOMAIN", domainId, dse.getLocalizedMessage()), // $NON-NLS-1$
dse);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0016_UNABLE_TO_STORE_DOMAIN", domainId, dse.getLocalizedMessage()), // $NON-NLS-1$
dse);
} catch (DomainIdNullException dne) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0019_DOMAIN_IS_NULL", dne.getLocalizedMessage()), // $NON-NLS-1$
dne);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0019_DOMAIN_IS_NULL", dne.getLocalizedMessage()), // $NON-NLS-1$
dne);
}
return true;
}
Aggregations