use of org.pentaho.platform.dataaccess.datasource.api.AnalysisService in project data-access by pentaho.
the class DatasourceResourceIT method testImportZipFile.
private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
File f = new File(filePath);
when(schemaFileInfo.getFileName()).thenReturn(f.getName());
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
if (annotated) {
mockery.checking(new Expectations() {
{
exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return true;
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
} else {
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName);
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
}
AnalysisService service = new AnalysisService();
FileInputStream in = new FileInputStream(filePath);
try {
service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.pentaho.platform.dataaccess.datasource.api.AnalysisService in project data-access by pentaho.
the class DatasourceResourceIT method testImportFile.
private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
}
public void describeTo(Description description) {
description.appendText("bundle with mondrian schema");
}
})));
}
});
AnalysisService service = new AnalysisService();
FileInputStream in = new FileInputStream(filePath);
try {
service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.pentaho.platform.dataaccess.datasource.api.AnalysisService in project data-access by pentaho.
the class AnalysisDatasourceService method putMondrianSchema.
/**
* This is used by PUC to use a Jersey put to import a Mondrian Schema XML into PUR
*
* @param dataInputStream
* @param schemaFileInfo
* @param catalogName
* @param datasourceName
* @param overwrite
* @param xmlaEnabledFlag
* @param parameters
* @param acl acl information for the data source. This parameter is optional.
* @return this method returns a response of "3" for success, 8 if exists, etc.
* @throws PentahoAccessControlException
*/
@PUT
@Path("/putSchema")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response putMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream dataInputStream, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(CATALOG_NAME) String catalogName, // Optional
@FormDataParam(ORIG_CATALOG_NAME) String origCatalogName, // Optional
@FormDataParam(DATASOURCE_NAME) String datasourceName, @FormDataParam(OVERWRITE_IN_REPOS) String overwrite, @FormDataParam(XMLA_ENABLED_FLAG) String xmlaEnabledFlag, @FormDataParam(PARAMETERS) String parameters, @FormDataParam(DATASOURCE_ACL) RepositoryFileAclDto acl) throws PentahoAccessControlException {
Response response = null;
int statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
try {
AnalysisService service = new AnalysisService();
boolean overWriteInRepository = "True".equalsIgnoreCase(overwrite) ? true : false;
boolean xmlaEnabled = "True".equalsIgnoreCase(xmlaEnabledFlag) ? true : false;
service.putMondrianSchema(dataInputStream, schemaFileInfo, catalogName, origCatalogName, datasourceName, overWriteInRepository, xmlaEnabled, parameters, acl);
statusCode = SUCCESS;
} catch (PentahoAccessControlException pac) {
logger.error(pac.getMessage());
statusCode = PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL;
} catch (PlatformImportException pe) {
statusCode = pe.getErrorStatus();
logger.error("Error putMondrianSchema " + pe.getMessage() + " status = " + statusCode);
} catch (Exception e) {
logger.error("Error putMondrianSchema " + e.getMessage());
statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
}
response = Response.ok().status(statusCode).type(MediaType.TEXT_PLAIN).build();
logger.debug("putMondrianSchema Response " + response);
return response;
}
Aggregations