List of usage examples for org.apache.commons.lang StringUtils containsOnly
public static boolean containsOnly(String str, String validChars)
Checks if the String contains only certain characters.
From source file:org.apache.kylin.rest.controller.CubeController.java
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" }) @ResponseBody/*from w ww . j ava 2 s . c o m*/ public CubeInstance cloneCube(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) { String newCubeName = cubeRequest.getCubeName(); String projectName = cubeRequest.getProject(); CubeInstance cube = cubeService.getCubeManager().getCube(cubeName); if (cube == null) { throw new BadRequestException("Cannot find cube " + cubeName); } if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) { throw new BadRequestException("Broken cube can't be cloned"); } if (!StringUtils.containsOnly(newCubeName, VALID_CUBENAME)) { logger.info("Invalid Cube name {}, only letters, numbers and underline supported.", newCubeName); throw new BadRequestException("Invalid Cube name, only letters, numbers and underline supported."); } ProjectInstance project = cubeService.getProjectManager().getProject(projectName); if (project == null) { throw new BadRequestException("Project " + projectName + " doesn't exist"); } CubeDesc cubeDesc = cube.getDescriptor(); CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc); newCubeDesc.setName(newCubeName); CubeInstance newCube; try { newCube = cubeService.createCubeAndDesc(project, newCubeDesc); //reload to avoid shallow clone cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName); } catch (IOException e) { throw new InternalErrorException("Failed to clone cube ", e); } return newCube; }
From source file:org.apache.kylin.rest.controller.CubeController.java
/** * save cubeDesc/*from www . j a v a 2 s.c o m*/ * * @return Table metadata array * @throws IOException */ @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" }) @ResponseBody public CubeRequest saveCubeDesc(@RequestBody CubeRequest cubeRequest) { CubeDesc desc = deserializeCubeDesc(cubeRequest); if (desc == null) { cubeRequest.setMessage("CubeDesc is null."); return cubeRequest; } String name = desc.getName(); if (StringUtils.isEmpty(name)) { logger.info("Cube name should not be empty."); throw new BadRequestException("Cube name should not be empty."); } if (!StringUtils.containsOnly(name, VALID_CUBENAME)) { logger.info("Invalid Cube name {}, only letters, numbers and underline supported.", name); throw new BadRequestException("Invalid Cube name, only letters, numbers and underline supported."); } try { desc.setUuid(UUID.randomUUID().toString()); String projectName = (null == cubeRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME : cubeRequest.getProject(); ProjectInstance project = cubeService.getProjectManager().getProject(projectName); if (project == null) { throw new BadRequestException("Project " + projectName + " doesn't exist"); } cubeService.createCubeAndDesc(project, desc); } catch (Exception e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException(e.getLocalizedMessage(), e); } cubeRequest.setUuid(desc.getUuid()); cubeRequest.setSuccessful(true); return cubeRequest; }
From source file:org.apache.kylin.rest.controller.ModelController.java
/** * * create model/*from w ww. ja v a 2s .co m*/ * @throws java.io.IOException */ @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" }) @ResponseBody public ModelRequest saveModelDesc(@RequestBody ModelRequest modelRequest) { //Update Model DataModelDesc modelDesc = deserializeDataModelDesc(modelRequest); if (modelDesc == null || StringUtils.isEmpty(modelDesc.getName())) { return modelRequest; } if (StringUtils.isEmpty(modelDesc.getName())) { logger.info("Model name should not be empty."); throw new BadRequestException("Model name should not be empty."); } if (!StringUtils.containsOnly(modelDesc.getName(), VALID_MODELNAME)) { logger.info("Invalid Model name {}, only letters, numbers and underline supported.", modelDesc.getName()); throw new BadRequestException("Invalid Model name, only letters, numbers and underline supported."); } try { modelDesc.setUuid(UUID.randomUUID().toString()); String projectName = (null == modelRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME : modelRequest.getProject(); modelService.createModelDesc(projectName, modelDesc); } catch (IOException e) { // TODO Auto-generated catch block logger.error("Failed to deal with the request:" + e.getLocalizedMessage(), e); throw new InternalErrorException("Failed to deal with the request: " + e.getLocalizedMessage()); } modelRequest.setUuid(modelDesc.getUuid()); modelRequest.setSuccessful(true); return modelRequest; }
From source file:org.apache.kylin.rest.controller.ModelController.java
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" }) @ResponseBody/*from w w w.j av a 2s . c o m*/ public ModelRequest cloneModel(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) { String project = modelRequest.getProject(); MetadataManager metaManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName); String newModelName = modelRequest.getModelName(); if (StringUtils.isEmpty(project)) { logger.info("Project name should not be empty."); throw new BadRequestException("Project name should not be empty."); } if (modelDesc == null || StringUtils.isEmpty(modelName)) { logger.info("Model does not exist."); throw new BadRequestException("Model does not exist."); } if (StringUtils.isEmpty(newModelName)) { logger.info("New model name is empty."); throw new BadRequestException("New model name is empty."); } if (!StringUtils.containsOnly(newModelName, VALID_MODELNAME)) { logger.info("Invalid Model name {}, only letters, numbers and underline supported.", newModelName); throw new BadRequestException("Invalid Model name, only letters, numbers and underline supported."); } DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc); newModelDesc.setName(newModelName); try { newModelDesc = modelService.createModelDesc(project, newModelDesc); //reload avoid shallow metaManager.reloadDataModelDescAt(DataModelDesc.concatResourcePath(newModelName)); } catch (IOException e) { throw new InternalErrorException("failed to clone DataModelDesc", e); } modelRequest.setUuid(newModelDesc.getUuid()); modelRequest.setSuccessful(true); return modelRequest; }
From source file:org.apache.kylin.rest.controller.ProjectController.java
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" }) @ResponseBody// w ww . j av a 2 s. co m public ProjectInstance saveProject(@RequestBody ProjectRequest projectRequest) { ProjectInstance projectDesc = deserializeProjectDesc(projectRequest); if (StringUtils.isEmpty(projectDesc.getName())) { throw new InternalErrorException("A project name must be given to create a project"); } if (!StringUtils.containsOnly(projectDesc.getName(), VALID_PROJECTNAME)) { logger.info("Invalid Project name {}, only letters, numbers and underline supported.", projectDesc.getName()); throw new BadRequestException("Invalid Project name, only letters, numbers and underline supported."); } ProjectInstance createdProj = null; try { createdProj = projectService.createProject(projectDesc); } catch (Exception e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException(e.getLocalizedMessage()); } return createdProj; }
From source file:org.apache.kylin.rest.controller2.CubeControllerV2.java
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/vnd.apache.kylin-v2+json" }) @ResponseBody// w ww .j a v a 2 s . c o m public EnvelopeResponse cloneCubeV2(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) throws IOException { Message msg = MsgPicker.getMsg(); String newCubeName = cubeRequest.getCubeName(); String project = cubeRequest.getProject(); CubeInstance cube = cubeService.getCubeManager().getCube(cubeName); if (cube == null) { throw new BadRequestException(String.format(msg.getCUBE_NOT_FOUND(), cubeName)); } if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) { throw new BadRequestException(String.format(msg.getCLONE_BROKEN_CUBE(), cubeName)); } if (!StringUtils.containsOnly(newCubeName, VALID_CUBENAME)) { logger.info("Invalid Cube name {}, only letters, numbers and underline supported.", newCubeName); throw new BadRequestException(String.format(msg.getINVALID_CUBE_NAME(), cubeName)); } CubeDesc cubeDesc = cube.getDescriptor(); CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc); newCubeDesc.setName(newCubeName); CubeInstance newCube; newCube = cubeService.createCubeAndDesc(newCubeName, project, newCubeDesc); //reload to avoid shallow clone cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName); return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, newCube, ""); }
From source file:org.apache.kylin.rest.controller2.ModelControllerV2.java
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/vnd.apache.kylin-v2+json" }) @ResponseBody// w w w .j a v a2 s. c o m public EnvelopeResponse cloneModelV2(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) throws IOException { Message msg = MsgPicker.getMsg(); String project = modelRequest.getProject(); MetadataManager metaManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName); String newModelName = modelRequest.getModelName(); if (StringUtils.isEmpty(project)) { logger.info("Project name should not be empty."); throw new BadRequestException(msg.getEMPTY_PROJECT_NAME()); } if (modelDesc == null || StringUtils.isEmpty(modelName)) { throw new BadRequestException(msg.getEMPTY_MODEL_NAME()); } if (StringUtils.isEmpty(newModelName)) { logger.info("New model name is empty."); throw new BadRequestException(msg.getEMPTY_NEW_MODEL_NAME()); } if (!StringUtils.containsOnly(newModelName, VALID_MODELNAME)) { logger.info("Invalid Model name {}, only letters, numbers and underline supported.", newModelName); throw new BadRequestException(String.format(msg.getINVALID_MODEL_NAME(), newModelName)); } DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc); newModelDesc.setName(newModelName); newModelDesc = modelService.createModelDesc(project, newModelDesc); //reload avoid shallow metaManager.reloadDataModelDescAt(DataModelDesc.concatResourcePath(newModelName)); String descData = JsonUtil.writeValueAsIndentString(newModelDesc); GeneralResponse data = new GeneralResponse(); data.setProperty("uuid", newModelDesc.getUuid()); data.setProperty("modelDescData", descData); return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, ""); }
From source file:org.apache.kylin.rest.controller2.ProjectControllerV2.java
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/vnd.apache.kylin-v2+json" }) @ResponseBody/*from w w w . j av a 2s. co m*/ public EnvelopeResponse saveProjectV2(@RequestBody ProjectRequest projectRequest) throws IOException { Message msg = MsgPicker.getMsg(); ProjectInstance projectDesc = deserializeProjectDescV2(projectRequest); if (StringUtils.isEmpty(projectDesc.getName())) { throw new BadRequestException(msg.getEMPTY_PROJECT_NAME()); } if (!StringUtils.containsOnly(projectDesc.getName(), VALID_PROJECTNAME)) { logger.info("Invalid Project name {}, only letters, numbers and underline supported.", projectDesc.getName()); throw new BadRequestException(String.format(msg.getINVALID_PROJECT_NAME(), projectDesc.getName())); } ProjectInstance createdProj = null; createdProj = projectService.createProject(projectDesc); return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, createdProj, ""); }
From source file:org.apache.kylin.rest.service.CubeService.java
public void validateCubeDesc(CubeDesc desc, boolean isDraft) { Message msg = MsgPicker.getMsg();/*w ww.jav a 2 s. c o m*/ if (desc == null) { throw new BadRequestException(msg.getINVALID_CUBE_DEFINITION()); } String cubeName = desc.getName(); if (StringUtils.isEmpty(cubeName)) { logger.info("Cube name should not be empty."); throw new BadRequestException(msg.getEMPTY_CUBE_NAME()); } if (!StringUtils.containsOnly(cubeName, VALID_CUBENAME)) { logger.info("Invalid Cube name {}, only letters, numbers and underline supported.", cubeName); throw new BadRequestException(String.format(msg.getINVALID_CUBE_NAME(), cubeName)); } if (!isDraft) { DataModelDesc modelDesc = modelService.getMetadataManager().getDataModelDesc(desc.getModelName()); if (modelDesc == null) { throw new BadRequestException(String.format(msg.getMODEL_NOT_FOUND(), desc.getModelName())); } if (modelDesc.isDraft()) { logger.info("Cannot use draft model."); throw new BadRequestException(String.format(msg.getUSE_DRAFT_MODEL(), desc.getModelName())); } } }
From source file:org.apache.kylin.rest.service.ModelService.java
public void validateModelDesc(DataModelDesc modelDesc) { Message msg = MsgPicker.getMsg();//w w w .ja v a 2s .co m if (modelDesc == null) { throw new BadRequestException(msg.getINVALID_MODEL_DEFINITION()); } String modelName = modelDesc.getName(); if (StringUtils.isEmpty(modelName)) { logger.info("Model name should not be empty."); throw new BadRequestException(msg.getEMPTY_MODEL_NAME()); } if (!StringUtils.containsOnly(modelName, VALID_MODELNAME)) { logger.info("Invalid Model name {}, only letters, numbers and underline supported.", modelDesc.getName()); throw new BadRequestException(String.format(msg.getINVALID_MODEL_NAME(), modelName)); } }