Search in sources :

Example 1 with AnalysisService

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);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 2 with AnalysisService

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);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 3 with AnalysisService

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;
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Aggregations

AnalysisService (org.pentaho.platform.dataaccess.datasource.api.AnalysisService)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)2 FileInputStream (java.io.FileInputStream)2 Description (org.hamcrest.Description)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)2 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)2 File (java.io.File)1 ZipFile (java.util.zip.ZipFile)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 Facet (org.codehaus.enunciate.Facet)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)1