Search in sources :

Example 16 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException 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);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 17 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class AnalysisResource method putSchema.

/**
 * Import Analysis Schema.
 *
 * <p><b>Example Request:</b><br />
 *    PUT pentaho/plugin/data-access/api/datasource/analysis/catalog/SampleSchema
 * <br /><b>PUT data:</b>
 *  <pre function="syntax.xml">
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY
 *      Content-Disposition: form-data; name=&quot;uploadAnalysis&quot;; filename=&quot;SampleData2.mondrian.xml&quot;
 *      Content-Type: text/xml
 *
 *      &lt;?xml version=&quot;1.0&quot;?&gt;
 *      &lt;Schema name=&quot;SampleData2&quot;&gt;
 *      &lt;!-- Shared dimensions --&gt;
 *
 *      &lt;Dimension name=&quot;Region&quot;&gt;
 *      &lt;Hierarchy hasAll=&quot;true&quot; allMemberName=&quot;All Regions&quot;&gt;
 *      &lt;Table name=&quot;QUADRANT_ACTUALS&quot;/&gt;
 *      &lt;Level name=&quot;Region&quot; column=&quot;REGION&quot; uniqueMembers=&quot;true&quot;/&gt;
 *      &lt;/Hierarchy&gt;
 *      &lt;/Dimension&gt;
 *      &lt;Dimension name=&quot;Department&quot;&gt;
 *      &lt;Hierarchy hasAll=&quot;true&quot; allMemberName=&quot;All Departments&quot;&gt;
 *      &lt;Table name=&quot;QUADRANT_ACTUALS&quot;/&gt;
 *      &lt;Level name=&quot;Department&quot; column=&quot;DEPARTMENT&quot; uniqueMembers=&quot;true&quot;/&gt;
 *      &lt;/Hierarchy&gt;
 *      &lt;/Dimension&gt;
 *
 *      &lt;Dimension name=&quot;Positions&quot;&gt;
 *      &lt;Hierarchy hasAll=&quot;true&quot; allMemberName=&quot;All Positions&quot;&gt;
 *      &lt;Table name=&quot;QUADRANT_ACTUALS&quot;/&gt;
 *      &lt;Level name=&quot;Positions&quot; column=&quot;POSITIONTITLE&quot; uniqueMembers=&quot;true&quot;/&gt;
 *      &lt;/Hierarchy&gt;
 *      &lt;/Dimension&gt;
 *
 *      &lt;Cube name=&quot;Quadrant Analysis&quot;&gt;
 *      &lt;Table name=&quot;QUADRANT_ACTUALS&quot;/&gt;
 *      &lt;DimensionUsage name=&quot;Region&quot; source=&quot;Region&quot;/&gt;
 *      &lt;DimensionUsage name=&quot;Department&quot; source=&quot;Department&quot; /&gt;
 *      &lt;DimensionUsage name=&quot;Positions&quot; source=&quot;Positions&quot; /&gt;
 *      &lt;Measure name=&quot;Actual&quot; column=&quot;ACTUAL&quot; aggregator=&quot;sum&quot; formatString=&quot;#,###.00&quot;/&gt;
 *      &lt;Measure name=&quot;Budget&quot; column=&quot;BUDGET&quot; aggregator=&quot;sum&quot; formatString=&quot;#,###.00&quot;/&gt;
 *      &lt;Measure name=&quot;Variance&quot; column=&quot;VARIANCE&quot; aggregator=&quot;sum&quot; formatString=&quot;#,###.00&quot;/&gt;
 *      &lt;!--    &lt;CalculatedMember name=&quot;Variance Percent&quot; dimension=&quot;Measures&quot; formula=&quot;([Measures].[Variance]/[Measures].[Budget])*100&quot; /&gt; --&gt;
 *      &lt;/Cube&gt;
 *
 *      &lt;/Schema&gt;
 *
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY
 *      Content-Disposition: form-data; name=&quot;parameters&quot;
 *
 *      DataSource=SampleData2;overwrite=true
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY
 *      Content-Disposition: form-data; name=&quot;schemaFileInfo&quot;
 *
 *      test.xml
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY
 *      Content-Disposition: form-data; name=&quot;catalogName&quot;
 *
 *      Catalog Name
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY
 *      Content-Disposition: form-data; name=&quot;xmlaEnabledFlag&quot;
 *
 *      true
 *      ------WebKitFormBoundaryNLNb246RTFIn1elY--
 *  </pre>
 * </p>
 *
 * @param catalog         (optional) The catalog name.
 * @param uploadAnalysis  A Mondrian schema XML file.
 * @param schemaFileInfo  User selected name for the file.
 * @param origCatalogName (optional) The original catalog name.
 * @param datasourceName  (optional) The datasource  name.
 * @param overwrite       Flag for overwriting existing version of the file.
 * @param xmlaEnabledFlag Is XMLA enabled or not.
 * @param parameters      Import parameters.
 * @param acl             acl information for the data source. This parameter is optional.
 *
 * @return Response containing the success of the method.
 *
 * <p><b>Example Response:</b></p>
 * <pre function="syntax.xml">
 *   200
 * </pre>
 */
@PUT
@Path("/catalog/{catalogId : .+}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@StatusCodes({ @ResponseCode(code = 409, condition = "Content already exists (use overwrite flag to force)"), @ResponseCode(code = 401, condition = "Import failed because publish is prohibited"), @ResponseCode(code = 500, condition = "Unspecified general error has occurred"), @ResponseCode(code = 412, condition = "Analysis datasource import failed.  Error code or message included in response entity"), @ResponseCode(code = 403, condition = "Access Control Forbidden"), @ResponseCode(code = 201, condition = "Indicates successful import") })
public Response putSchema(// Optional
@PathParam(CATALOG_ID) String catalog, @FormDataParam(UPLOAD_ANALYSIS) InputStream uploadAnalysis, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(ORIG_CATALOG_NAME) String origCatalogName, // Optional
@FormDataParam(DATASOURCE_NAME) String datasourceName, @FormDataParam(OVERWRITE_IN_REPOS) Boolean overwrite, @FormDataParam(XMLA_ENABLED_FLAG) Boolean xmlaEnabledFlag, @FormDataParam(PARAMETERS) String parameters, @FormDataParam(DATASOURCE_ACL) RepositoryFileAclDto acl) throws PentahoAccessControlException {
    try {
        service.putMondrianSchema(uploadAnalysis, schemaFileInfo, catalog, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, acl);
        Response response = Response.status(Response.Status.CREATED).build();
        logger.debug("putMondrianSchema Response " + response);
        return response;
    } catch (PentahoAccessControlException pac) {
        int statusCode = PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL;
        logger.error("Error putMondrianSchema " + pac.getMessage() + " status = " + statusCode);
        throw new ResourceUtil.AccessControlException(pac.getMessage());
    } catch (PlatformImportException pe) {
        if (pe.getErrorStatus() == PlatformImportException.PUBLISH_PROHIBITED_SYMBOLS_ERROR) {
            throw new ResourceUtil.PublishProhibitedException(pe.getMessage());
        } else {
            String msg = pe.getMessage();
            logger.error("Error import analysis: " + msg + " status = " + pe.getErrorStatus());
            Throwable throwable = pe.getCause();
            if (throwable != null) {
                msg = throwable.getMessage();
                logger.error("Root cause: " + msg);
            }
            int status = pe.getErrorStatus();
            if (status == 8) {
                throw new ResourceUtil.ContentAlreadyExistsException(msg);
            } else {
                throw new ResourceUtil.ImportFailedException(msg);
            }
        }
    } catch (Exception e) {
        int statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
        logger.error("Error putMondrianSchema " + e.getMessage() + " status = " + statusCode);
        throw new ResourceUtil.UnspecifiedErrorException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) PUT(javax.ws.rs.PUT)

Example 18 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class AnalysisResource method importMondrianSchema.

public Response importMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream uploadAnalysis, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(CATALOG_ID) 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 {
        boolean overWriteInRepository = "True".equalsIgnoreCase(overwrite);
        boolean xmlaEnabled = "True".equalsIgnoreCase(xmlaEnabledFlag);
        service.putMondrianSchema(uploadAnalysis, 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 = buildOkResponse(String.valueOf(statusCode));
    logger.debug("putMondrianSchema Response " + response);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 19 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataDatasourceService method storeDomain.

/**
 * @param metadataFile
 *          Input stream for the metadata.xmi
 * @param domainId
 *          Unique identifier for the metadata datasource
 *
 * @return Response containing the success of the method
 *
 * @throws PentahoAccessControlException
 *           Thrown when validation of access fails
 */
@PUT
@Path("/storeDomain")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response storeDomain(InputStream metadataFile, @QueryParam("domainId") String domainId) throws PentahoAccessControlException {
    try {
        DatasourceService.validateAccess();
        PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
        metadataImporter.storeDomain(metadataFile, domainId, true);
        return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    } catch (Exception e) {
        return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
    }
}
Also used : PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Facet(org.codehaus.enunciate.Facet)

Example 20 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataDatasourceService method uploadServletImportMetadataDatasource.

/**
 * @param localizeBundleEntries
 * @param domainId
 *          Unique identifier for the metadata datasource
 * @param metadataFile
 *          Input stream for the metadata.xmi
 *
 * @return Response containing the success of the method
 *
 * @throws PentahoAccessControlException
 *           Thrown when validation of access fails
 */
@PUT
@Path("/uploadServletImport")
@Consumes({ TEXT_PLAIN })
@Produces("text/plain")
@Deprecated
@Facet(name = "Unsupported")
public Response uploadServletImportMetadataDatasource(String localizeBundleEntries, @QueryParam("domainId") String domainId, @QueryParam("metadataFile") String metadataFile) throws PentahoAccessControlException {
    try {
        DatasourceService.validateAccess();
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    }
    IMetadataDomainRepository metadataDomainRepository = PentahoSystem.get(IMetadataDomainRepository.class, PentahoSessionHolder.getSession());
    PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
    CsvUtils csvUtils = new CsvUtils();
    boolean validPropertyFiles = true;
    StringBuffer invalidFiles = new StringBuffer();
    try {
        String TMP_FILE_PATH = File.separatorChar + "system" + File.separatorChar + "tmp" + File.separatorChar;
        String sysTmpDir = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);
        FileInputStream metadataInputStream = new FileInputStream(sysTmpDir + File.separatorChar + metadataFile);
        metadataImporter.storeDomain(metadataInputStream, domainId, true);
        metadataDomainRepository.getDomain(domainId);
        StringTokenizer bundleEntriesParam = new StringTokenizer(localizeBundleEntries, ";");
        while (bundleEntriesParam.hasMoreTokens()) {
            String localizationBundleElement = bundleEntriesParam.nextToken();
            StringTokenizer localizationBundle = new StringTokenizer(localizationBundleElement, "=");
            String localizationFileName = localizationBundle.nextToken();
            String localizationFile = localizationBundle.nextToken();
            if (localizationFileName.endsWith(".properties")) {
                String encoding = csvUtils.getEncoding(localizationFile);
                if (ENCODINGS.contains(encoding)) {
                    for (final Pattern propertyBundlePattern : patterns) {
                        final Matcher propertyBundleMatcher = propertyBundlePattern.matcher(localizationFileName);
                        if (propertyBundleMatcher.matches()) {
                            FileInputStream bundleFileInputStream = new FileInputStream(sysTmpDir + File.separatorChar + localizationFile);
                            metadataImporter.addLocalizationFile(domainId, propertyBundleMatcher.group(2), bundleFileInputStream, true);
                            break;
                        }
                    }
                } else {
                    validPropertyFiles = false;
                    invalidFiles.append(localizationFileName);
                }
            } else {
                validPropertyFiles = false;
                invalidFiles.append(localizationFileName);
            }
        }
        if (!validPropertyFiles) {
            return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_002_PROPERTY_FILES_ERROR") + invalidFiles.toString()).build();
        }
        return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
    } catch (Exception e) {
        metadataImporter.removeDomain(domainId);
        return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileInputStream(java.io.FileInputStream) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) CsvUtils(org.pentaho.platform.dataaccess.datasource.wizard.csv.CsvUtils) StringTokenizer(java.util.StringTokenizer) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Facet(org.codehaus.enunciate.Facet)

Aggregations

PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)48 Test (org.junit.Test)28 InputStream (java.io.InputStream)13 Response (javax.ws.rs.core.Response)13 FileNotFoundException (java.io.FileNotFoundException)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)6 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)6 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)6 DataAccessException (org.springframework.dao.DataAccessException)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 Domain (org.pentaho.metadata.model.Domain)5 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)5 FileInputStream (java.io.FileInputStream)4 Consumes (javax.ws.rs.Consumes)4 Facet (org.codehaus.enunciate.Facet)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)4 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)3