本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext.getUsername方法的具体用法?Java PrivilegedCarbonContext.getUsername怎么用?Java PrivilegedCarbonContext.getUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.context.PrivilegedCarbonContext
的用法示例。
在下文中一共展示了PrivilegedCarbonContext.getUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObservationList
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* get the observation list fraction of an analysis.
*/
@GET
@Path("/{analysisId}/observationList")
@Produces("application/json")
@Consumes("application/json")
public Response getObservationList(@PathParam("analysisId") long analysisId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
String observations = mlAnalysisHandler.getObservations(analysisId);
return Response.ok(observations).build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving observations for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例2: getResponseVariable
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the response variable of an analysis.
* @param analysisId Unique id of the analysis
* @return Response variable name
*/
@GET
@Path("/{analysisId}/responseVariables")
@Produces("application/json")
@Consumes("application/json")
public Response getResponseVariable(@PathParam("analysisId") long analysisId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
String responseVariable = mlAnalysisHandler.getResponseVariable(analysisId);
return Response.ok(responseVariable).build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving response variable for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例3: getAlgorithmType
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the algorithm type of an analysis.
* @param analysisId Unique id of the analysis
* @return Algorithm type
*/
@GET
@Path("/{analysisId}/algorithmType")
@Produces("application/json")
@Consumes("application/json")
public Response getAlgorithmType(@PathParam("analysisId") long analysisId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
String responseVariable = mlAnalysisHandler.getAlgorithmType(analysisId);
return Response.ok(responseVariable).build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving algorithm type for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例4: getDataset
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the dataset of a given dataset ID.
*
* @param datasetId ID of the dataset
* @return JSON of {@link org.wso2.carbon.ml.commons.domain.MLDataset} object
*/
@GET
@Path("/{datasetId}")
@Produces("application/json")
public Response getDataset(@PathParam("datasetId") long datasetId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
MLDataset dataset = datasetProcessor.getDataset(tenantId, userName, datasetId);
if (dataset == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(dataset).build();
} catch (MLDataProcessingException e) {
String msg = MLUtils.getErrorMsg(String.format(
"Error occurred while retrieving the dataset with the [id] %s of tenant [id] %s and [user] %s .",
datasetId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例5: getProductVariable
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* get the product variable of an analysis.
*/
@GET
@Path("/{analysisId}/productVariable")
@Produces("application/json")
@Consumes("application/json")
public Response getProductVariable(@PathParam("analysisId") long analysisId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
String productVariable = mlAnalysisHandler.getProductVariable(analysisId);
return Response.ok(productVariable).build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving product variable for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例6: getModelSummary
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the model summary
* @param modelId Unique id of the model
* @return JSON of {@link org.wso2.carbon.ml.commons.domain.ModelSummary} object
*/
@GET
@Path("/{modelId}/summary")
@Produces("application/json")
@Consumes("application/json")
public Response getModelSummary(@PathParam("modelId") long modelId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
ModelSummary modelSummary = mlModelHandler.getModelSummary(modelId);
return Response.ok(modelSummary).build();
} catch (MLModelHandlerException e) {
String msg = MLUtils.getErrorMsg(String.format(
"Error occurred while retrieving summary of the model [id] %s of tenant [id] %s and [user] %s .",
modelId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例7: getModel
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the model data
*
* @param modelName Name of the model
* @return JSON of {@link MLModelData} object
*/
@GET
@Path("/{modelName}")
@Produces("application/json")
public Response getModel(@PathParam("modelName") String modelName) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
MLModelData model = mlModelHandler.getModel(tenantId, userName, modelName);
if (model == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(model).build();
} catch (MLModelHandlerException e) {
String msg = MLUtils.getErrorMsg(String.format(
"Error occurred while retrieving a model [name] %s of tenant [id] %s and [user] %s .", modelName,
tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例8: addCustomizedFeatures
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Adding customized features of an analysis.
* @param analysisId Unique id of the analysis
* @param customizedFeatures {@link List} of {@link MLCustomizedFeature} objects
*/
@POST
@Path("/{analysisId}/features")
@Produces("application/json")
@Consumes("application/json")
public Response addCustomizedFeatures(@PathParam("analysisId") long analysisId,
List<MLCustomizedFeature> customizedFeatures) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
mlAnalysisHandler.addCustomizedFeatures(analysisId, customizedFeatures, tenantId, userName);
return Response.ok().build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while adding customized features for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例9: getRecommendations
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the model data
* @param modelName Name of the model
* @return JSON of {@link org.wso2.carbon.ml.commons.domain.MLModelData} object
*/
@GET
@Path("/{modelId}/getRecommendations/{userId}/{noOfProducts}")
@Produces("application/json")
public Response getRecommendations(@PathParam("modelId") long modelId,
@PathParam("userId") int userId,
@PathParam("noOfProducts") int noOfProducts) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
List<?> recommendations =
mlModelHandler.getProductRecommendations(tenantId, userName, modelId, userId, noOfProducts);
return Response.ok(recommendations).build();
} catch (MLModelHandlerException e) {
String msg = MLUtils.getErrorMsg(String.format("Error occurred while getting recommendations from model [id] %s of tenant [id] %s and [user] %s.",
modelId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例10: getHyperParameters
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get hyper-parameter of an analysis.
* @param analysisId Unique id of the analysis
* @param algorithmName Algorithm name
* @return JSON array of {@link org.wso2.carbon.ml.commons.domain.MLHyperParameter} objects
*/
@GET
@Path("/{analysisId}/hyperParameters")
@Produces("application/json")
@Consumes("application/json")
public Response getHyperParameters(@PathParam("analysisId") long analysisId,
@QueryParam("algorithmName") String algorithmName) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
List<MLHyperParameter> hyperParameters = mlAnalysisHandler.getHyperParameters(analysisId, algorithmName);
return Response.ok(hyperParameters).build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving hyper parameters of algorithm [name] %s for the analysis [id] %s of tenant [id] %s and [user] %s .",
algorithmName, analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例11: getProductRecommendations
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get a list of recommended products for a given user using the given model.
* @param modelId id of the recommendation model to be used.
* @param userId id of the user.
* @param noOfProducts number of recommendations required.
* @return an array of product recommendations.
*/
@GET
@Path("/{modelId}/product-recommendations")
@Produces("application/json")
public Response getProductRecommendations(@PathParam("modelId") long modelId,
@QueryParam("user-id") int userId,
@QueryParam("no-of-products") int noOfProducts) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
List<?> recommendations =
mlModelHandler.getProductRecommendations(tenantId, userName, modelId, userId, noOfProducts);
return Response.ok(recommendations).build();
} catch (MLModelHandlerException e) {
String msg = MLUtils.getErrorMsg(String.format("Error occurred while getting recommendations from model [id] %s of tenant [id] %s and [user] %s.",
modelId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例12: getAllVersionsets
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get all versions of a dataset.
*
* @param datasetId ID of the dataset
* @return JSON array of {@link org.wso2.carbon.ml.commons.domain.MLDatasetVersion} objects
*/
@GET
@Path("/{datasetId}/versions")
@Produces("application/json")
public Response getAllVersionsets(@PathParam("datasetId") long datasetId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
List<MLDatasetVersion> versionsets = datasetProcessor.getAllDatasetVersions(tenantId, userName, datasetId);
return Response.ok(versionsets).build();
} catch (MLDataProcessingException e) {
String msg = MLUtils
.getErrorMsg(
String.format(
"Error occurred while retrieving all versions of a dataset with the [id] %s of tenant [id] %s and [user] %s .",
datasetId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例13: logout
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Logout.
*/
@POST
@Path("/logout")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response logout() {
HttpSession session = httpServletRequest.getSession();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = carbonContext.getUsername();
String tenantDomain = carbonContext.getTenantDomain();
int tenantId = carbonContext.getTenantId();
if (session != null) {
session.invalidate();
}
auditLog.info(String.format(
"User [name] %s of tenant [id] %s [domain] %s is logged-out from WSO2 Machine Learner. "
+ "Granted session id is %s", username, tenantId, tenantDomain, session == null ? null
: session.getId()));
return Response.status(Response.Status.OK).entity("User logged out: " + carbonContext.getUsername()).build();
}
示例14: addCustomizedFeatures
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Adding customized features of an analysis.
* @param analysisId Unique id of the analysis
* @param customizedFeatures {@link java.util.List} of {@link org.wso2.carbon.ml.commons.domain.MLCustomizedFeature} objects
*/
@POST
@Path("/{analysisId}/features")
@Produces("application/json")
@Consumes("application/json")
public Response addCustomizedFeatures(@PathParam("analysisId") long analysisId,
List<MLCustomizedFeature> customizedFeatures) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
mlAnalysisHandler.addCustomizedFeatures(analysisId, customizedFeatures, tenantId, userName);
return Response.ok().build();
} catch (MLAnalysisHandlerException e) {
String msg = MLUtils
.getErrorMsg(String.format(
"Error occurred while adding customized features for the analysis [id] %s of tenant [id] %s and [user] %s .",
analysisId, tenantId, userName), e);
logger.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}
示例15: deleteModel
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Delete a model
*
* @param modelId Unique id of the model
*/
@DELETE
@Path("/{modelId}")
@Produces("application/json")
public Response deleteModel(@PathParam("modelId") long modelId) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = carbonContext.getTenantId();
String userName = carbonContext.getUsername();
try {
mlModelHandler.deleteModel(tenantId, userName, modelId);
auditLog.info(String.format("User [name] %s of tenant [id] %s deleted a model [id] %s ", userName,
tenantId, modelId));
return Response.ok().build();
} catch (MLModelHandlerException e) {
String msg = MLUtils.getErrorMsg(String.format(
"Error occurred while deleting a model [id] %s of tenant [id] %s and [user] %s .", modelId,
tenantId, userName), e);
logger.error(msg, e);
auditLog.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
.build();
}
}