use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardResourceTest method testRemoveError.
@Test
public void testRemoveError() throws Exception {
Response mockResponse = mock(Response.class);
// Test 1
PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(dataSourceWizardResource.service).removeDSW("dswId");
doReturn(mockResponse).when(dataSourceWizardResource).buildUnauthorizedResponse();
try {
Response response = dataSourceWizardResource.remove("dswId");
fail("should have thrown an exception");
} catch (Exception e) {
// good
}
verify(dataSourceWizardResource, times(1)).remove("dswId");
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardResourceTest method testPublishDswError.
@Test
public void testPublishDswError() throws Exception {
String domainId = "domainId";
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = false;
boolean checkConnection = false;
Response mockResponse = mock(Response.class);
// Test 1
PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(dataSourceWizardResource.service).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
doReturn(mockResponse).when(dataSourceWizardResource).buildUnauthorizedResponse();
Response response = dataSourceWizardResource.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
assertEquals(mockResponse, response);
// Test 2
IllegalArgumentException mockIllegalArgumentException = mock(IllegalArgumentException.class);
doThrow(mockIllegalArgumentException).when(dataSourceWizardResource.service).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
doReturn(mockResponse).when(dataSourceWizardResource).buildBadRequestResponse(anyString());
response = dataSourceWizardResource.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
assertEquals(mockResponse, response);
// Test 3
DataSourceWizardService.DswPublishValidationException mockDataSourceWizardServiceDswPublishValidationException = mock(DataSourceWizardService.DswPublishValidationException.class);
doThrow(mockDataSourceWizardServiceDswPublishValidationException).when(dataSourceWizardResource.service).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
doReturn(mockResponse).when(dataSourceWizardResource).buildConfilictResponse(anyString());
response = dataSourceWizardResource.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
assertEquals(mockResponse, response);
// Test 4
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockException).when(dataSourceWizardResource.service).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
doReturn(mockResponse).when(dataSourceWizardResource).buildServerErrorResponse();
response = dataSourceWizardResource.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
assertEquals(mockResponse, response);
verify(dataSourceWizardResource, times(4)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataResourceTest method doSetMetadataAcl.
@Test
public void doSetMetadataAcl() throws Exception {
String domainId = "domainId";
doReturn(new HashMap<String, InputStream>() {
{
put("test", null);
}
}).when(metadataResource).getDomainFilesData(domainId);
Response response = metadataResource.doSetMetadataAcl(domainId, null);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
//
doThrow(new PentahoAccessControlException()).when(metadataResource.service).setMetadataAcl(domainId, null);
response = metadataResource.doSetMetadataAcl(domainId, null);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
//
doThrow(new FileNotFoundException()).when(metadataResource.service).setMetadataAcl(domainId, null);
response = metadataResource.doSetMetadataAcl(domainId, null);
assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardService method publishDsw.
public String publishDsw(String domainId, InputStream metadataFile, List<InputStream> localizeFiles, List<String> localizeFileNames, boolean overwrite, boolean checkConnection, RepositoryFileAclDto acl) throws PentahoAccessControlException, IllegalArgumentException, DswPublishValidationException, Exception {
if (!hasManageAccessCheck()) {
throw new PentahoAccessControlException();
}
if (!endsWith(domainId, METADATA_EXT)) {
// if doesn't end in case-sensitive '.xmi' there will be trouble later on
final String errorMsg = "domainId must end in " + METADATA_EXT;
throw new IllegalArgumentException(errorMsg);
}
if (localizeFiles == null ? (localizeFileNames != null) : (localizeFiles.size() != localizeFileNames.size())) {
throw new IllegalArgumentException("localizeFiles and localizeFileNames must have equal size");
}
if (metadataFile == null) {
throw new IllegalArgumentException("metadataFile is null");
}
if (!overwrite) {
final List<String> overwritten = getOverwrittenDomains(domainId);
if (!overwritten.isEmpty()) {
final String domainIds = StringUtils.join(overwritten, ",");
throw new DswPublishValidationException(DswPublishValidationException.Type.OVERWRITE_CONFLICT, domainIds);
}
}
XmiParser xmiParser = createXmiParser();
Domain domain = null;
try {
domain = xmiParser.parseXmi(metadataFile);
} catch (Exception e) {
throw new DswPublishValidationException(DswPublishValidationException.Type.INVALID_XMI, e.getMessage());
}
domain.setId(domainId);
if (checkConnection) {
final String connectionId = getMondrianDatasourceWrapper(domain);
// Left second check with non-escaped name for backward compatibility
if (datasourceMgmtSvc.getDatasourceByName(sanitizer.escape(connectionId)) == null && datasourceMgmtSvc.getDatasourceByName(connectionId) == null) {
final String msg = "connection not found: '" + connectionId + "'";
throw new DswPublishValidationException(Type.MISSING_CONNECTION, msg);
}
}
// build bundles
IPlatformImportBundle mondrianBundle = createMondrianDswBundle(domain, acl);
InputStream metadataIn = toInputStreamWrapper(domain, xmiParser);
IPlatformImportBundle metadataBundle = createMetadataDswBundle(domain, metadataIn, overwrite, acl);
// add localization bundles
if (localizeFiles != null) {
for (int i = 0; i < localizeFiles.size(); i++) {
IPlatformImportBundle localizationBundle = MetadataService.createNewRepositoryFileImportBundle(localizeFiles.get(i), localizeFileNames.get(i), domainId);
metadataBundle.getChildBundles().add(localizationBundle);
logger.info("created language file");
}
}
// do import
IPlatformImporter importer = getIPlatformImporter();
importer.importFile(metadataBundle);
logger.debug("imported metadata xmi");
importer.importFile(mondrianBundle);
logger.debug("imported mondrian schema");
// trigger refreshes
IPentahoSession session = getSession();
PentahoSystem.publish(session, METADATA_PUBLISHER);
PentahoSystem.publish(session, MONDRIAN_PUBLISHER);
logger.info("publishDsw: Published DSW with domainId='" + domainId + "'.");
return domainId;
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardService method doGetDSWFilesAsDownload.
public Map<String, InputStream> doGetDSWFilesAsDownload(String dswId) throws PentahoAccessControlException {
if (!canManageACL()) {
throw new PentahoAccessControlException();
}
// First get the metadata files;
Map<String, InputStream> fileData = getMetadataFiles(dswId);
// Then get the corresponding mondrian files
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) {
MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper();
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
fileData.putAll(helper.getModrianSchemaFiles(catalogRef));
parseMondrianSchemaNameWrapper(dswId, fileData);
}
return fileData;
}
Aggregations