Search in sources :

Example 26 with Facet

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

the class DatabaseDialectService method getDatabaseDialectsWS.

/**
 * Get a list of the database dialects
 *
 * @return IDatabaseDialectList containing the database dialects
 */
@GET
@Path("/getDatabaseDialects")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public IDatabaseDialectList getDatabaseDialectsWS() {
    IDatabaseDialectList value = new DefaultDatabaseDialectList();
    value.setDialects(super.getDatabaseDialects());
    return value;
}
Also used : DefaultDatabaseDialectList(org.pentaho.ui.database.event.DefaultDatabaseDialectList) IDatabaseDialectList(org.pentaho.ui.database.event.IDatabaseDialectList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 27 with Facet

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

the class UserRoleDaoResource method assignAllUsersToRole.

/**
 * Associates all user to a particular role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param roleName   (role name)
 * @return
 */
@PUT
@Path("/assignAllUsersToRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllUsersToRole(@QueryParam("tenant") String tenantPath, @QueryParam("roleName") String roleName) {
    IUserRoleDao roleDao = getUserRoleDao();
    Set<String> assignedUserNames = new HashSet<String>();
    for (IPentahoUser pentahoUser : roleDao.getUsers(getTenant(tenantPath))) {
        assignedUserNames.add(pentahoUser.getUsername());
    }
    roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
    if (assignedUserNames.contains(getSession().getName())) {
        updateRolesForCurrentSession();
    }
    return Response.ok().build();
}
Also used : IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Example 28 with Facet

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

the class FileResource method doIsParameterizable.

/**
 * Determines whether a selected file supports parameters or not
 *
 * @param pathId Colon separated path for the repository file.
 *
 * @return ("true" or "false")
 * @throws FileNotFoundException
 */
@GET
@Path("{pathId : .+}/parameterizable")
@Produces(MediaType.TEXT_PLAIN)
@Facet(name = "Unsupported")
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully get the file or directory."), @ResponseCode(code = 404, condition = "Failed to find the file or resource.") })
public // have to accept anything for browsers to work
String doIsParameterizable(@PathParam("pathId") String pathId) throws FileNotFoundException {
    boolean hasParameterUi = false;
    RepositoryFile repositoryFile = getRepository().getFile(fileService.idToPath(pathId));
    if (repositoryFile != null) {
        try {
            hasParameterUi = hasParameterUi(repositoryFile);
        } catch (NoSuchBeanDefinitionException e) {
        // Do nothing.
        }
    }
    boolean hasParameters = false;
    if (hasParameterUi) {
        try {
            IContentGenerator parameterContentGenerator = getContentGenerator(repositoryFile);
            if (parameterContentGenerator != null) {
                ByteArrayOutputStream outputStream = getByteArrayOutputStream();
                parameterContentGenerator.setOutputHandler(new SimpleOutputHandler(outputStream, false));
                parameterContentGenerator.setMessagesList(new ArrayList<String>());
                Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
                SimpleParameterProvider parameterProvider = getSimpleParameterProvider();
                parameterProvider.setParameter("path", encode(repositoryFile.getPath()));
                parameterProvider.setParameter("renderMode", "PARAMETER");
                parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
                parameterContentGenerator.setParameterProviders(parameterProviders);
                parameterContentGenerator.setSession(getSession());
                parameterContentGenerator.createContent();
                if (outputStream.size() > 0) {
                    Document document = parseText(outputStream.toString());
                    // exclude all parameters that are of type "system", xactions set system params that have to be ignored.
                    @SuppressWarnings("rawtypes") List nodes = document.selectNodes("parameters/parameter");
                    for (int i = 0; i < nodes.size() && !hasParameters; i++) {
                        Element elem = (Element) nodes.get(i);
                        if (elem.attributeValue("name").equalsIgnoreCase("output-target") && elem.attributeValue("is-mandatory").equalsIgnoreCase("true")) {
                            hasParameters = true;
                            continue;
                        }
                        Element attrib = (Element) elem.selectSingleNode("attribute[@namespace='http://reporting.pentaho" + ".org/namespaces/engine/parameter-attributes/core' and @name='role']");
                        if (attrib == null || !"system".equals(attrib.attributeValue("value"))) {
                            hasParameters = true;
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error(getMessagesInstance().getString("FileResource.PARAM_FAILURE", e.getMessage()), e);
        }
    }
    return Boolean.toString(hasParameters);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) DocumentException(org.dom4j.DocumentException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) Facet(org.codehaus.enunciate.Facet)

Example 29 with Facet

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

the class PluginResource method readFile.

/**
 * Retrieve the file from the selected plugin. This file is a static file (i.e javascript, html, css etc)
 *
 * @param pluginId (Plugin ID of the selected Plugin)
 * @param path (Path of the file being retrieved. This is a colon separated path to the plugin file. This
 *        is usually a static file like a javascript, image or html
 * @return
 * @throws IOException
 */
@GET
@Path("/files/{path : .+}")
@Produces(WILDCARD)
@Facet(name = "Unsupported")
public Response readFile(@PathParam("pluginId") String pluginId, @PathParam("path") String path) throws IOException {
    List<String> pluginRestPerspectives = pluginManager.getPluginRESTPerspectivesForId(pluginId);
    // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    boolean useCache = "true".equals(pluginManager.getPluginSetting(pluginId, "settings/cache", "false"));
    // $NON-NLS-1$
    String maxAge = (String) pluginManager.getPluginSetting(pluginId, "settings/max-age", null);
    // /scheduler)
    if (!pluginRestPerspectives.contains(path) && maxAge != null && !"0".equals(maxAge)) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$
        httpServletResponse.setHeader("Cache-Control", "max-age=" + maxAge);
    }
    if (!pluginManager.getRegisteredPlugins().contains(pluginId)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!pluginManager.isPublic(pluginId, path)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    InputStream isTmp;
    try {
        isTmp = getCacheBackedStream(pluginId, path, useCache);
    } catch (FileNotFoundException e) {
        return Response.status(Status.NOT_FOUND).build();
    } catch (IllegalArgumentException e) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final InputStream is = isTmp;
    StreamingOutput streamingOutput = new StreamingOutput() {

        public void write(OutputStream output) throws IOException {
            try {
                IOUtils.copy(is, output);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    };
    MediaType mediaType = MediaType.WILDCARD_TYPE;
    String mimeType = MimeHelper.getMimeTypeFromFileName(path);
    if (mimeType != null) {
        try {
            mediaType = MediaType.valueOf(mimeType);
        } catch (IllegalArgumentException iae) {
            // $NON-NLS-1$
            logger.warn(MessageFormat.format("PluginFileResource.UNDETERMINED_MIME_TYPE", path));
        }
    }
    return Response.ok(streamingOutput, mediaType).build();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) MediaType(javax.ws.rs.core.MediaType) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 30 with Facet

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

the class RepositoryPublishResource method writeFileWithEncodedNameWithOptions.

@POST
@Path("/fileWithOptions")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces(MediaType.TEXT_PLAIN)
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully publish the file."), @ResponseCode(code = 403, condition = "Failure to publish the file due to permissions."), @ResponseCode(code = 422, condition = "Failure to publish the file due to failed validation."), @ResponseCode(code = 500, condition = "Failure to publish the file due to a server error.") })
@Facet(name = "Unsupported")
public Response writeFileWithEncodedNameWithOptions(@FormDataParam("properties") String properties, @FormDataParam("importPath") String pathId, @FormDataParam("fileUpload") InputStream fileContents, @FormDataParam("fileUpload") FormDataContentDisposition fileInfo) {
    try (ByteArrayInputStream bios = new ByteArrayInputStream(properties.getBytes())) {
        Optional<Properties> fileProperties = Optional.of(new Properties());
        fileProperties.get().loadFromXML(bios);
        return writeFile(pathId, fileContents, fileInfo, fileProperties);
    } catch (IOException e) {
        logger.error(e);
        return buildServerErrorResponse(PlatformImportException.PUBLISH_GENERAL_ERROR);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) 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