Пример #1
0
  /**
   * Get all projects created with the given dataset
   *
   * @param datasetName Name of the dataset
   * @return JSON array of {@link org.wso2.carbon.ml.rest.api.model.MLProjectBean} objects
   */
  @GET
  @Path("/analyses")
  @Produces("application/json")
  public Response getAllProjectsWithAnalyses(@QueryParam("datasetName") String datasetName) {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {
      List<MLProject> projects = mlProjectHandler.getAllProjects(tenantId, userName);
      List<MLProjectBean> projectBeans = new ArrayList<MLProjectBean>();
      for (MLProject mlProject : projects) {
        if (!StringUtils.isEmpty(datasetName) && !datasetName.equals(mlProject.getDatasetName())) {
          continue;
        }
        MLProjectBean projectBean = new MLProjectBean();
        long projectId = mlProject.getId();
        projectBean.setId(projectId);
        projectBean.setCreatedTime(mlProject.getCreatedTime());
        projectBean.setDatasetId(mlProject.getDatasetId());
        projectBean.setDatasetName(mlProject.getDatasetName());
        projectBean.setDatasetStatus(mlProject.getDatasetStatus());
        projectBean.setDescription(mlProject.getDescription());
        projectBean.setName(mlProject.getName());

        List<MLAnalysisBean> analysisBeans = new ArrayList<MLAnalysisBean>();
        List<MLAnalysis> analyses =
            mlProjectHandler.getAllAnalysesOfProject(tenantId, userName, projectId);
        for (MLAnalysis mlAnalysis : analyses) {
          MLAnalysisBean analysisBean = new MLAnalysisBean();
          analysisBean.setId(mlAnalysis.getId());
          analysisBean.setName(mlAnalysis.getName());
          analysisBean.setProjectId(mlAnalysis.getProjectId());
          analysisBean.setComments(mlAnalysis.getComments());
          analysisBeans.add(analysisBean);
        }
        projectBean.setAnalyses(analysisBeans);
        projectBeans.add(projectBean);
      }
      return Response.ok(projectBeans).build();
    } catch (MLProjectHandlerException e) {
      String msg =
          MLUtils.getErrorMsg(
              String.format(
                  "Error occurred while retrieving all analyses of tenant [id] %s and [user] %s .",
                  tenantId, userName),
              e);
      logger.error(msg, e);
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
          .entity(new MLErrorBean(e.getMessage()))
          .build();
    }
  }
Пример #2
0
 /**
  * Get all analyses of a project
  *
  * @param projectId Unique id of the project
  * @return A JSON array of {@link org.wso2.carbon.ml.commons.domain.MLAnalysis} objects
  */
 @GET
 @Path("/{projectId}/analyses")
 @Produces("application/json")
 public Response getAllAnalysesOfProject(@PathParam("projectId") long projectId) {
   PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
   int tenantId = carbonContext.getTenantId();
   String userName = carbonContext.getUsername();
   try {
     List<MLAnalysis> analyses =
         mlProjectHandler.getAllAnalysesOfProject(tenantId, userName, projectId);
     return Response.ok(analyses).build();
   } catch (MLProjectHandlerException e) {
     String msg =
         MLUtils.getErrorMsg(
             String.format(
                 "Error occurred while retrieving all analyses of project [id]  %s of tenant [id] %s and [user] %s .",
                 projectId, tenantId, userName),
             e);
     logger.error(msg, e);
     return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
         .entity(new MLErrorBean(e.getMessage()))
         .build();
   }
 }