Search in sources :

Example 6 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserSettingsResource method setUserSetting.

/**
 * Save the value of a particular setting for the current user
 *
 * @param setting  (Setting name)
 * @param settingValue   (Value of the setting)
 *
 * @return
 */
@POST
@Path("{setting : .+}")
@Facet(name = "Unsupported")
public Response setUserSetting(@PathParam("setting") String setting, String settingValue) {
    IUserSettingService settingsService = getUserSettingService();
    // preventing stored XSS(PPP-3464)
    settingValue = EscapeUtils.escapeJsonOrRaw(settingValue);
    settingsService.setUserSetting(setting, settingValue);
    return Response.ok(settingValue).build();
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Facet(org.codehaus.enunciate.Facet)

Example 7 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserSettingsResource method getUserSettings.

/**
 * Retrieve the global settings and the user settings for the current user
 *
 * @return list of settings for the platform
 */
@GET
@Path("/list")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public ArrayList<Setting> getUserSettings() {
    try {
        IUserSettingService settingsService = getUserSettingService();
        List<IUserSetting> userSettings = settingsService.getUserSettings();
        ArrayList<Setting> settings = new ArrayList<Setting>();
        for (IUserSetting userSetting : userSettings) {
            settings.add(new Setting(userSetting.getSettingName(), userSetting.getSettingValue()));
        }
        return settings;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) ArrayList(java.util.ArrayList) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 8 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class RepositoryImportResource method doPostImport.

/**
 * Attempts to import all files from the zip archive or single file. A log file is produced at the end of import.
 *
 * <p><b>Example Request:</b><br />
 *    POST pentaho/api/repo/files/import
 *    <br /><b>POST data:</b>
 *    <pre function="syntax.xml">
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="importDir"
 *
 *      /public
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="fileUpload"; filename="test.csv"
 *      Content-Type: application/vnd.ms-excel
 *
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="overwriteFile"
 *
 *      true
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="overwriteAclPermissions"
 *
 *      true
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="applyAclPermissions"
 *
 *      true
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="retainOwnership"
 *
 *      true
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="charSet"
 *
 *      UTF-8
 *      ------WebKitFormBoundaryB9hzsGp4wR5SGAZD
 *      Content-Disposition: form-data; name="logLevel"
 *
 *      INFO
 *      ------WebKitFormBoundaryd1z6iZhXyx12RYxV
 *      Content-Disposition: form-data; name="fileNameOverride"
 *
 *      fileNameOverriden.csv
 *      ------WebKitFormBoundaryd1z6iZhXyx12RYxV--
 *    </pre>
 * </p>
 *
 * @param importDir               JCR Directory to which the zip structure or single file will be uploaded to.
 * @param fileUpload              Input stream for the file.
 * @param overwriteFile           The flag indicates ability to overwrite existing file.
 * @param overwriteAclPermissions The flag indicates ability to overwrite Acl permissions.
 * @param applyAclPermissions     The flag indicates ability to apply Acl permissions.
 * @param retainOwnership         The flag indicates ability to retain ownership.
 * @param charSet                 The charset for imported file.
 * @param logLevel                The level of logging.
 * @param fileNameOverride        If present and the content represents a single file, this parameter contains the filename to use
 *                                when storing the file in the repository. If not present, the fileInfo.getFileName will be used.
 *                                Note that the later cannot reliably handle foreign character sets.
 *
 * @return A jax-rs Response object with the appropriate header and body.
 *
 * <p><b>Example Response:</b></p>
 * <pre function="syntax.xml">
 *   &lt;html&gt;
 *   &lt;head&gt;
 *   &lt;title&gt;Repository Import Log&lt;/title&gt;
 *   &lt;/head&gt;
 *   &lt;body bgcolor="#FFFFFF" topmargin="6" leftmargin="6" style="font-family: arial,sans-serif; font-size: x-small"&gt;
 *   &lt;hr size="1" noshade&gt;
 *   Log session start time Thu Feb 26 11:04:19 BRT 2015&lt;br&gt;
 *   &lt;br&gt;
 *   &lt;table cellspacing="0" cellpadding="4" border="1" bordercolor="#224466" width="100%"&gt;
 *   &lt;tr style="background: #336699; color: #FFFFFF; text-align: left"&gt;
 *   &lt;th&gt;Import File&lt;/th&gt;
 *   &lt;th&gt;Level&lt;/th&gt;
 *   &lt;th&gt;Message&lt;/th&gt;
 *   &lt;/tr&gt;
 *   &lt;td title="importFile"&gt;/public&lt;/td&gt;
 *   &lt;td title="Level"&gt;INFO&lt;/td&gt;
 *   &lt;td title="Message"&gt;Start Import Job&lt;/td&gt;
 *   &lt;/tr&gt;
 *   &lt;td title="importFile"&gt;/public/fileNameOverriden.csv&lt;/td&gt;
 *   &lt;td title="Level"&gt;INFO&lt;/td&gt;
 *   &lt;td title="Message"&gt;Start File Import&lt;/td&gt;
 *   &lt;/tr&gt;
 *   &lt;td title="importFile"&gt;/public/fileNameOverriden.csv&lt;/td&gt;
 *   &lt;td title="Level"&gt;&lt;font color="#993300"&gt;&lt;strong&gt;WARN&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
 *   &lt;td title="Message"&gt;fileNameOverriden.csv&lt;/td&gt;
 *   &lt;/tr&gt;
 *   &lt;td title="importFile"&gt;/public&lt;/td&gt;
 *   &lt;td title="Level"&gt;INFO&lt;/td&gt;
 *   &lt;td title="Message"&gt;End Import Job&lt;/td&gt;
 *   &lt;/tr&gt;
 *   &lt;/table&gt;
 *   &lt;br&gt;
 *   &lt;/body&gt;&lt;/html&gt;
 * </pre>
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
@Facet(name = "Unsupported")
public Response doPostImport(@FormDataParam("importDir") String importDir, @FormDataParam("fileUpload") InputStream fileUpload, @FormDataParam("overwriteFile") String overwriteFile, @FormDataParam("overwriteAclPermissions") String overwriteAclPermissions, @FormDataParam("applyAclPermissions") String applyAclPermission, @FormDataParam("retainOwnership") String retainOwnership, @FormDataParam("charSet") String charSet, @FormDataParam("logLevel") String logLevel, @FormDataParam("fileUpload") FormDataContentDisposition fileInfo, @FormDataParam("fileNameOverride") String fileNameOverride) {
    IRepositoryImportLogger importLogger = null;
    ByteArrayOutputStream importLoggerStream = new ByteArrayOutputStream();
    boolean logJobStarted = false;
    if (StringUtils.isBlank(charSet)) {
        charSet = DEFAULT_CHAR_SET;
    }
    try {
        validateAccess(importDir);
        boolean overwriteFileFlag = ("false".equals(overwriteFile) ? false : true);
        boolean overwriteAclSettingsFlag = ("true".equals(overwriteAclPermissions) ? true : false);
        boolean applyAclSettingsFlag = ("true".equals(applyAclPermission) ? true : false);
        boolean retainOwnershipFlag = ("true".equals(retainOwnership) ? true : false);
        // If logLevel is null then we will default to ERROR
        if (logLevel == null || logLevel.length() <= 0) {
            logLevel = "ERROR";
        }
        // Non-admins cannot process a manifest
        FileService fileService = new FileService();
        if (!fileService.doCanAdminister()) {
            applyAclSettingsFlag = false;
            retainOwnershipFlag = true;
        }
        Level level = Level.toLevel(logLevel);
        ImportSession.getSession().setAclProperties(applyAclSettingsFlag, retainOwnershipFlag, overwriteAclSettingsFlag);
        // The fileNameOverride was added because the formDataContentDispositionfile object cannot reliable
        // contain non US-ASCII characters.  See RFC283 section 2.3 for details
        String fileName = fileNameOverride != null ? fileNameOverride : fileInfo.getFileName();
        RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
        bundleBuilder.input(fileUpload);
        bundleBuilder.charSet(charSet);
        bundleBuilder.path(importDir);
        bundleBuilder.overwriteFile(overwriteFileFlag);
        bundleBuilder.applyAclSettings(applyAclSettingsFlag);
        bundleBuilder.overwriteAclSettings(overwriteAclSettingsFlag);
        bundleBuilder.retainOwnership(retainOwnershipFlag);
        bundleBuilder.name(fileName);
        IPlatformImportBundle bundle = bundleBuilder.build();
        IPlatformMimeResolver mimeResolver = PentahoSystem.get(IPlatformMimeResolver.class);
        String mimeTypeFromFile = mimeResolver.resolveMimeForFileName(fileName);
        if (mimeTypeFromFile == null) {
            return Response.ok("INVALID_MIME_TYPE", MediaType.TEXT_HTML).build();
        }
        bundleBuilder.mime(mimeTypeFromFile);
        IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
        importLogger = importer.getRepositoryImportLogger();
        final String mimeType = bundle.getMimeType() != null ? bundle.getMimeType() : mimeResolver.resolveMimeForBundle(bundle);
        if (mimeType == null) {
            return Response.ok("INVALID_MIME_TYPE", MediaType.TEXT_HTML).build();
        }
        logJobStarted = true;
        importLogger.startJob(importLoggerStream, importDir, level);
        importer.importFile(bundle);
        // Flush the Mondrian cache to show imported data-sources.
        IMondrianCatalogService mondrianCatalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
        mondrianCatalogService.reInit(PentahoSessionHolder.getSession());
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    } catch (Exception e) {
        return Response.serverError().entity(e.toString()).build();
    } finally {
        ImportSession.clearSession();
        if (logJobStarted == true) {
            importLogger.endJob();
        }
    }
    String responseBody;
    try {
        responseBody = importLoggerStream.toString(charSet);
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Encoding of response body is failed. (charSet=" + charSet + ")", e);
        responseBody = importLoggerStream.toString();
    }
    return Response.ok(responseBody, MediaType.TEXT_HTML).build();
}
Also used : FileService(org.pentaho.platform.web.http.api.resources.services.FileService) IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) Level(org.apache.log4j.Level) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Facet(org.codehaus.enunciate.Facet)

Example 9 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class ThemeResource method getSystemThemes.

/**
 * List the current supported themes in the platform
 *
 * @return list of themes
 */
@GET
@Path("/list")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public List<Theme> getSystemThemes() {
    ArrayList<Theme> themes = new ArrayList<Theme>();
    IThemeManager themeManager = PentahoSystem.get(IThemeManager.class);
    List<String> ids = themeManager.getSystemThemeIds();
    for (String id : ids) {
        org.pentaho.platform.api.ui.Theme theme = themeManager.getSystemTheme(id);
        if (theme.isHidden() == false) {
            themes.add(new Theme(id, theme.getName()));
        }
    }
    return themes;
}
Also used : ArrayList(java.util.ArrayList) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 10 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserConsoleResource method getAdminContent.

/**
 * Returns the list of admin related settings
 *
 * @return list of settings
 */
@GET
@Path("/getAdminContent")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public List<Setting> getAdminContent() {
    ArrayList<Setting> settings = new ArrayList<Setting>();
    try {
        IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, UserConsoleService.getPentahoSession());
        List<String> pluginIds = pluginManager.getRegisteredPlugins();
        nextPlugin: for (String pluginId : pluginIds) {
            String adminContentInfo = (String) pluginManager.getPluginSetting(pluginId, "admin-content-info", null);
            String exceptionMessage = (String) pluginManager.getPluginSetting(pluginId, "exception-message", null);
            if (adminContentInfo != null) {
                StringTokenizer nameValuePairs = new StringTokenizer(adminContentInfo, ";");
                while (nameValuePairs.hasMoreTokens()) {
                    String currentToken = nameValuePairs.nextToken().trim();
                    if (currentToken.startsWith("conditional-logic-validator=")) {
                        String validatorName = currentToken.substring("conditional-logic-validator=".length());
                        Class<?> validatorClass = pluginManager.getClassLoader(pluginId).loadClass(validatorName);
                        IAdminContentConditionalLogic validator = (IAdminContentConditionalLogic) validatorClass.newInstance();
                        int status = validator.validate();
                        if (status == IAdminContentConditionalLogic.DISPLAY_ADMIN_CONTENT) {
                            settings.add(new Setting("admin-content-info", adminContentInfo));
                        }
                        if (status == IAdminContentConditionalLogic.DISPLAY_EXCEPTION_MESSAGE && exceptionMessage != null) {
                            settings.add(new Setting("exception-message", exceptionMessage));
                        }
                        if (status == IAdminContentConditionalLogic.AVOID_ADMIN_CONTENT) {
                            continue nextPlugin;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return settings;
}
Also used : StringTokenizer(java.util.StringTokenizer) IAdminContentConditionalLogic(org.pentaho.platform.plugin.services.pluginmgr.IAdminContentConditionalLogic) ArrayList(java.util.ArrayList) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

Facet (org.codehaus.enunciate.Facet)48 Path (javax.ws.rs.Path)43 Produces (javax.ws.rs.Produces)33 GET (javax.ws.rs.GET)29 ArrayList (java.util.ArrayList)12 Consumes (javax.ws.rs.Consumes)12 POST (javax.ws.rs.POST)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 PUT (javax.ws.rs.PUT)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)6 Response (javax.ws.rs.core.Response)5 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)5 HashSet (java.util.HashSet)4 StringTokenizer (java.util.StringTokenizer)4 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)4 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)4 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3