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">
* <purObjectRevisions>
* <revision>
* <versionId>1.0</versionId>
* <creationDate>2014-07-22T14:42:46.029-04:00</creationDate>
* <login>admin</login>
* <comment>JMeter test</comment>
* </revision>
* </purObjectRevisions>
* </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();
}
}
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);
}
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);
}
}
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);
}
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();
}
Aggregations