Search in sources :

Example 11 with StatusCodes

use of org.codehaus.enunciate.jaxrs.StatusCodes in project pentaho-kettle by pentaho.

the class RevisionResource method doGetVersions.

/**
 * Retrieves the version history of a selected repository file
 *
 * <p>
 * <b>Example Request:</b><br>
 * GET /pur-repository-plugin/api/revision/path:to:file/revisions
 * </p>
 *
 * @param pathId
 *          (colon separated path for the repository file)
 *
 *          <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @return file revisions objects <code> purObjectRevisions </code>
 *
 *         <pre function="syntax.xml">
 * &lt;purObjectRevisions&gt;
 * &lt;revision&gt;
 * &lt;versionId&gt;1.0&lt;/versionId&gt;
 * &lt;creationDate&gt;2014-07-22T14:42:46.029-04:00&lt;/creationDate&gt;
 * &lt;login&gt;admin&lt;/login&gt;
 * &lt;comment&gt;JMeter test&lt;/comment&gt;
 * &lt;/revision&gt;
 * &lt;/purObjectRevisions&gt;
 * </pre>
 */
@GET
@Path("{pathId : .+}/revisions")
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully returns list of revisions"), @ResponseCode(code = 500, condition = "Something failed when attempting to retrieve revisions"), @ResponseCode(code = 404, condition = "Invalid path") })
@Produces({ APPLICATION_XML, APPLICATION_JSON })
public Response doGetVersions(@PathParam("pathId") String pathId) {
    Serializable fileId = null;
    List<ObjectRevision> originalRevisions = null;
    RepositoryFile repositoryFile = repository.getFile(FileUtils.idToPath(pathId));
    if (repositoryFile != null) {
        fileId = repositoryFile.getId();
    }
    if (fileId != null) {
        try {
            originalRevisions = revisionService.getRevisions(new StringObjectId(fileId.toString()));
        } catch (KettleException e) {
            return Response.serverError().build();
        }
        List<PurObjectRevision> revisions = new ArrayList();
        for (ObjectRevision revision : originalRevisions) {
            revisions.add((PurObjectRevision) revision);
        }
        GenericEntity<List<PurObjectRevision>> genericRevisionsEntity = new GenericEntity<List<PurObjectRevision>>(revisions) {
        };
        return Response.ok(genericRevisionsEntity).build();
    } else {
        return Response.serverError().build();
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) PurObjectRevision(org.pentaho.di.repository.pur.PurObjectRevision) KettleException(org.pentaho.di.core.exception.KettleException) Serializable(java.io.Serializable) GenericEntity(javax.ws.rs.core.GenericEntity) PurObjectRevision(org.pentaho.di.repository.pur.PurObjectRevision) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List) StringObjectId(org.pentaho.di.repository.StringObjectId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Example 12 with StatusCodes

use of org.codehaus.enunciate.jaxrs.StatusCodes 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 13 with StatusCodes

use of org.codehaus.enunciate.jaxrs.StatusCodes 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)

Example 14 with StatusCodes

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

the class RepositoryPublishResource method writeFileWithEncodedName.

/**
 * Publishes the file to the provided path in the repository. The file will be overwritten if {@code overwriteFile}
 * is {@code true}.
 *
 * This method should be used instead of
 * {@linkplain #writeFile(String, InputStream, Boolean, FormDataContentDisposition)}. Contrary to
 * {@linkplain FileResource} convention, it expects {@code pathId} <b>not</b> to be separated by colons, but to be
 * simply encoded with {@linkplain java.net.URLEncoder}. Also it expects {@code pathId} to be a well-formatted
 * Unix-style path with no slash at the end.
 *
 * Examples of correct {@code pathId}:
 * <ul>
 *   <li><tt>%2Fpublic%2Fmyfile.txt</tt></li>
 *   <li><tt>%2Fpublic%2Fmyfile</tt></li>
 *   <li><tt>%2Fpublic%2Fmyfile</tt></li>
 *   <li><tt>%2Fpublic%2Fmyfile%22quoted%22</tt></li>
 * </ul>
 *
 * @param pathId        slash-separated path for the repository file
 * @param fileContents  input stream containing the data
 * @param overwriteFile flag to determine whether to overwrite the existing file in the repository or not
 * @param fileInfo      file information (Currently not being used).
 *
 * @return A jax-rs Response object with the appropriate status code, header, and body.
 */
@POST
@Path("/file")
@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 writeFileWithEncodedName(@FormDataParam("importPath") String pathId, @FormDataParam("fileUpload") InputStream fileContents, @FormDataParam("overwriteFile") Boolean overwriteFile, @FormDataParam("fileUpload") FormDataContentDisposition fileInfo) {
    Optional<Properties> fileProperties = Optional.of(new Properties());
    fileProperties.get().setProperty("overwriteFile", String.valueOf(overwriteFile));
    return writeFile(pathId, fileContents, fileInfo, fileProperties);
}
Also used : 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)

Example 15 with StatusCodes

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

the class RepositoryResource method doExecuteDefault.

/**
 * Takes a pathId to a file and generates a URI that represents the URL to call to generate content from that file.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/api/repos/public:steel%20wheels:Invoice%20(report).prpt/default
 * </p>
 *
 * @param pathId @param pathId
 *
 * @return URI that represents a forwarding URL to execute to generate content from the file {pathId}.
 *
 * <p><b>Example Response:</b></p>
 *  <pre function="syntax.xml">
 *    This response does not contain data.
 *  </pre>
 */
@GET
@Path("{pathId : .+}/default")
@Produces({ WILDCARD })
@StatusCodes({ @ResponseCode(code = 303, condition = "Successfully get the resource."), @ResponseCode(code = 404, condition = "Failed to find the resource.") })
public Response doExecuteDefault(@PathParam("pathId") String pathId) throws FileNotFoundException, MalformedURLException, URISyntaxException {
    String perspective = null;
    StringBuffer buffer = null;
    String url = null;
    String path = FileResource.idToPath(pathId);
    String extension = path.substring(path.lastIndexOf('.') + 1);
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession());
    IContentInfo info = pluginManager.getContentTypeInfo(extension);
    for (IPluginOperation operation : info.getOperations()) {
        if (operation.getId().equalsIgnoreCase("RUN")) {
            // $NON-NLS-1$
            perspective = operation.getPerspective();
            break;
        }
    }
    if (perspective == null) {
        perspective = GENERATED_CONTENT_PERSPECTIVE;
    }
    buffer = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    url = // $NON-NLS-1$
    buffer.substring(0, buffer.lastIndexOf("/") + 1) + perspective + ((queryString != null && queryString.length() > 0) ? "?" + httpServletRequest.getQueryString() : "");
    return Response.seeOther((new URL(url)).toURI()).build();
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) IPluginOperation(org.pentaho.platform.api.engine.IPluginOperation) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) URL(java.net.URL) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Aggregations

Path (javax.ws.rs.Path)17 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)17 Produces (javax.ws.rs.Produces)15 Consumes (javax.ws.rs.Consumes)8 GET (javax.ws.rs.GET)8 ArrayList (java.util.ArrayList)5 POST (javax.ws.rs.POST)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 PUT (javax.ws.rs.PUT)4 Facet (org.codehaus.enunciate.Facet)4 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 List (java.util.List)2 Properties (java.util.Properties)2 BadRequestException (javax.ws.rs.BadRequestException)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2