use of org.codehaus.enunciate.jaxrs.StatusCodes in project pentaho-platform by pentaho.
the class Log4jResource method updateLogLevel.
@PUT
@Path("/update")
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully update log level."), @ResponseCode(code = 304, condition = "Log level is not modified.") })
@Produces({ MediaType.TEXT_PLAIN })
public Response updateLogLevel(@FormParam("level") String targetLevel, @FormParam("category") String category) throws Exception {
LOGGER.setLevel(Level.INFO);
if (StringUtils.isBlank(targetLevel) && StringUtils.isBlank(category)) {
return Response.notModified("No parameter provided, log level not modified.").build();
}
Logger root = LogManager.getRootLogger();
if (StringUtils.isNotBlank(targetLevel)) {
LOGGER.info("Request to set log level: " + targetLevel);
if (StringUtils.isNotBlank(category)) {
LOGGER.info("Request to set log level for package: " + category);
Logger catLog = LogManager.exists(category);
if (catLog != null) {
catLog.setLevel(Level.toLevel(targetLevel, root.getLevel()));
return Response.ok("Setting log level for: '" + catLog.getName() + "' to be: " + catLog.getLevel()).build();
}
return Response.notModified("Category: '" + Encode.forHtml(category) + "' not found, log level not modified.").build();
}
root.setLevel(Level.toLevel(targetLevel, root.getLevel()));
LOGGER.info("Root logger level set to: " + root.getLevel());
Enumeration e = LogManager.getCurrentLoggers();
while (e.hasMoreElements()) {
Logger logger = (Logger) e.nextElement();
logger.setLevel(Level.toLevel(targetLevel, root.getLevel()));
}
}
return Response.ok("Log level updated.").build();
}
use of org.codehaus.enunciate.jaxrs.StatusCodes 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="uploadAnalysis"; filename="SampleData2.mondrian.xml"
* Content-Type: text/xml
*
* <?xml version="1.0"?>
* <Schema name="SampleData2">
* <!-- Shared dimensions -->
*
* <Dimension name="Region">
* <Hierarchy hasAll="true" allMemberName="All Regions">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Region" column="REGION" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
* <Dimension name="Department">
* <Hierarchy hasAll="true" allMemberName="All Departments">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Department" column="DEPARTMENT" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
*
* <Dimension name="Positions">
* <Hierarchy hasAll="true" allMemberName="All Positions">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Positions" column="POSITIONTITLE" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
*
* <Cube name="Quadrant Analysis">
* <Table name="QUADRANT_ACTUALS"/>
* <DimensionUsage name="Region" source="Region"/>
* <DimensionUsage name="Department" source="Department" />
* <DimensionUsage name="Positions" source="Positions" />
* <Measure name="Actual" column="ACTUAL" aggregator="sum" formatString="#,###.00"/>
* <Measure name="Budget" column="BUDGET" aggregator="sum" formatString="#,###.00"/>
* <Measure name="Variance" column="VARIANCE" aggregator="sum" formatString="#,###.00"/>
* <!-- <CalculatedMember name="Variance Percent" dimension="Measures" formula="([Measures].[Variance]/[Measures].[Budget])*100" /> -->
* </Cube>
*
* </Schema>
*
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="parameters"
*
* DataSource=SampleData2;overwrite=true
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="schemaFileInfo"
*
* test.xml
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="catalogName"
*
* Catalog Name
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="xmlaEnabledFlag"
*
* 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());
}
}
use of org.codehaus.enunciate.jaxrs.StatusCodes in project data-access by pentaho.
the class JDBCDatasourceResource method getConnectionIDs.
/**
* Get a list of JDBC datasource IDs.
*
* <p><b>Example Request:</b><br />
* GET pentaho/plugin/data-access/api/datasource/jdbc/connection
* </p>
*
* @return A list of JDBC datasource IDs.
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* {
* "Item": [
* {
* "@type": "xs:string",
* "$": "AgileBI"
* },
* {
* "@type": "xs:string",
* "$": "Audit"
* },
* {
* "@type": "xs:string",
* "$": "SampleData"
* },
* {
* "@type": "xs:string",
* "$": "TestDataSourceResource"
* },
* {
* "@type": "xs:string",
* "$": "baseball connection"
* },
* {
* "@type": "xs:string",
* "$": "baseball connection"
* },
* {
* "@type": "xs:string",
* "$": "live_logging_info"
* },
* {
* "@type": "xs:string",
* "$": "pentaho_operations_mart"
* }
* ]
* }
* </pre>
*/
@GET
@Path("/")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully retrieved the list of JDBC datasource IDs"), @ResponseCode(code = 500, condition = "Internal error retrieving JDBC datasource IDs") })
public JaxbList<String> getConnectionIDs() {
List<String> connStrList = new ArrayList<String>();
try {
List<IDatabaseConnection> conns = service.getConnections();
for (IDatabaseConnection conn : conns) {
conn.setPassword(null);
connStrList.add(conn.getName());
}
} catch (ConnectionServiceException e) {
logger.error("Error " + e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
JaxbList<String> connections = new JaxbList<String>(connStrList);
return connections;
}
use of org.codehaus.enunciate.jaxrs.StatusCodes in project pentaho-metaverse by pentaho.
the class MetaverseService method download.
/**
* Download a zip file of all known lineage related artifacts created between (inclusive) two dates.
*
* <p><b>Example Request:</b><br />
* GET pentaho-di/osgi/cxf/lineage/api/download/all/20150101/20151231
* </p>
*
* @param startingDate a date string in the format YYYYMMDD
* @param endingDate a date string in the format YYYYMMDD
*
* @return A zip file containing lineage artifacts
*/
@GET
@Path("/download/all/{startingDate}/{endingDate}")
@Produces({ "application/zip" })
@StatusCodes({ @ResponseCode(code = OK, condition = "Successfully created and returned the zip file."), @ResponseCode(code = BAD_REQUEST, condition = "Bad request, invalid starting and/or ending date provided."), @ResponseCode(code = SERVER_ERROR, condition = "Server Error.") })
public Response download(@PathParam("startingDate") final String startingDate, @PathParam("endingDate") String endingDate) {
if (lineageCollector == null) {
return Response.serverError().entity(Messages.getString("ERROR.LineageCollector.IsNull")).build();
}
String filename = "pentaho-lineage";
if (startingDate != null) {
filename += "_" + startingDate;
}
if (endingDate != null) {
filename += "-" + endingDate;
}
filename += ".zip";
try {
final List<String> artifacts = lineageCollector.listArtifacts(startingDate, endingDate);
StreamingOutput stream = new LineageStreamingOutput(artifacts, lineageCollector);
return Response.ok(stream).header("Content-Type", "application/zip").header("Content-Disposition", "inline; filename=" + filename).build();
} catch (IllegalArgumentException e) {
// illegal date format, return an error to the caller
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid date string provided. All dates must be valid and conform to this format " + DATE_FORMAT).build());
}
}
use of org.codehaus.enunciate.jaxrs.StatusCodes in project pentaho-metaverse by pentaho.
the class MetaverseService method downloadFile.
/**
* Download a zip file of all known lineage related artifacts for a specified file
* created between two dates (inclusive)
*
* <p><b>Example Request:</b><br />
* POST pentaho-di/osgi/cxf/lineage/api/download/file/20150101/20151231
* <br /><b>POST data:</b>
* <pre function="syntax.xml">
* { "path": "/home/suzy/test.ktr" }
* </pre>
* </p>
*
* @param request {@link LineageRequest} containing the path to the file of interest
* @param startingDate a date string in the format YYYYMMDD
* @param endingDate a date string in the format YYYYMMDD
*
* @return A zip file containing lineage artifacts
*/
@POST
@Path("/download/file/{startingDate}/{endingDate}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({ "application/zip" })
@StatusCodes({ @ResponseCode(code = OK, condition = "Successfully created and returned the zip file."), @ResponseCode(code = BAD_REQUEST, condition = "Bad request, invalid starting and/or ending date provided."), @ResponseCode(code = SERVER_ERROR, condition = "Server Error.") })
public Response downloadFile(LineageRequest request, @PathParam("startingDate") String startingDate, @PathParam("endingDate") String endingDate) {
if (lineageCollector == null) {
return Response.serverError().entity(Messages.getString("ERROR.LineageCollector.IsNull")).build();
}
if (request == null || request.getPath() == null) {
return Response.serverError().entity(Messages.getString("ERROR.NoPathFound")).build();
}
try {
final List<String> artifacts = lineageCollector.listArtifactsForFile(request.getPath(), startingDate, endingDate);
File f = new File(request.getPath());
String filename = f.getName() + "_lineage";
if (startingDate != null) {
filename += "_" + startingDate;
}
if (endingDate != null) {
filename += "-" + endingDate;
}
filename += ".zip";
StreamingOutput stream = new LineageStreamingOutput(artifacts, lineageCollector);
return Response.ok(stream).header("Content-Type", "application/zip").header("Content-Disposition", "inline; filename=" + filename).build();
} catch (IllegalArgumentException e) {
// illegal date format, return an error to the caller
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid date string provided. All dates must be valid and conform to this format " + DATE_FORMAT).build());
}
}
Aggregations