Rick Cheng
2 years ago
committed by
GitHub
13 changed files with 766 additions and 3 deletions
@ -0,0 +1,169 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.api.controller; |
||||
|
||||
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_PARAMETER_ERROR; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROJECT_PARAMETER_ERROR; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_PARAMETER_ERROR; |
||||
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_PARAMETER_ERROR; |
||||
|
||||
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||
import org.apache.dolphinscheduler.api.service.ProjectParameterService; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.constants.Constants; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.PutMapping; |
||||
import org.springframework.web.bind.annotation.RequestAttribute; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseStatus; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
import io.swagger.v3.oas.annotations.Parameter; |
||||
import io.swagger.v3.oas.annotations.Parameters; |
||||
import io.swagger.v3.oas.annotations.media.Schema; |
||||
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
||||
@Tag(name = "PROJECT_PARAMETER_TAG") |
||||
@RestController |
||||
@RequestMapping("projects/{projectCode}/project-parameter") |
||||
@Slf4j |
||||
public class ProjectParameterController extends BaseController { |
||||
|
||||
@Autowired |
||||
private ProjectParameterService projectParameterService; |
||||
|
||||
@Operation(summary = "createProjectParameter", description = "CREATE_PROJECT_PARAMETER_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "projectParameterName", description = "PROJECT_PARAMETER_NAME", schema = @Schema(implementation = String.class)), |
||||
@Parameter(name = "projectParameterValue", description = "PROJECT_PARAMETER_VALUE", schema = @Schema(implementation = String.class)) |
||||
}) |
||||
@PostMapping() |
||||
@ResponseStatus(HttpStatus.CREATED) |
||||
@ApiException(CREATE_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result createProjectParameter(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@RequestParam("projectParameterName") String projectParameterName, |
||||
@RequestParam(value = "projectParameterValue") String projectParameterValue) { |
||||
return projectParameterService.createProjectParameter(loginUser, projectCode, projectParameterName, |
||||
projectParameterValue); |
||||
} |
||||
|
||||
@Operation(summary = "updateProjectParameter", description = "UPDATE_PROJECT_PARAMETER_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "code", description = "PROJECT_PARAMETER_CODE", schema = @Schema(implementation = long.class, example = "123456")), |
||||
@Parameter(name = "projectParameterName", description = "PROJECT_PARAMETER_NAME", schema = @Schema(implementation = String.class)), |
||||
@Parameter(name = "projectParameterValue", description = "PROJECT_PARAMETER_VALUE", schema = @Schema(implementation = String.class)), |
||||
}) |
||||
@PutMapping(value = "/{code}") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(UPDATE_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result updateProjectParameter(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@PathVariable("code") Long code, |
||||
@RequestParam("projectParameterName") String projectParameterName, |
||||
@RequestParam(value = "projectParameterValue") String projectParameterValue) { |
||||
return projectParameterService.updateProjectParameter(loginUser, projectCode, code, projectParameterName, |
||||
projectParameterValue); |
||||
} |
||||
|
||||
@Operation(summary = "deleteProjectParametersByCode", description = "DELETE_PROJECT_PARAMETER_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "code", description = "PROJECT_PARAMETER_CODE", required = true, schema = @Schema(implementation = String.class)) |
||||
}) |
||||
@PostMapping(value = "/delete") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(DELETE_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result deleteProjectParametersByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@RequestParam("code") long code) { |
||||
|
||||
return projectParameterService.deleteProjectParametersByCode(loginUser, projectCode, code); |
||||
} |
||||
|
||||
@Operation(summary = "batchDeleteProjectParametersByCodes", description = "DELETE_PROJECT_PARAMETER_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "codes", description = "PROJECT_PARAMETER_CODE", required = true, schema = @Schema(implementation = String.class)) |
||||
}) |
||||
@PostMapping(value = "/batch-delete") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(DELETE_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result batchDeleteProjectParametersByCodes(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@RequestParam("codes") String codes) { |
||||
|
||||
return projectParameterService.batchDeleteProjectParametersByCodes(loginUser, projectCode, codes); |
||||
} |
||||
|
||||
@Operation(summary = "queryProjectParameterListPaging", description = "QUERY_PROJECT_PARAMETER_LIST_PAGING_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "searchVal", description = "SEARCH_VAL", required = false, schema = @Schema(implementation = String.class)), |
||||
@Parameter(name = "pageNo", description = "PAGE_NO", required = true, schema = @Schema(implementation = int.class, example = "1")), |
||||
@Parameter(name = "pageSize", description = "PAGE_SIZE", required = true, schema = @Schema(implementation = int.class, example = "10")) |
||||
}) |
||||
@GetMapping() |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(QUERY_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result queryProjectParameterListPaging( |
||||
@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||
@RequestParam("pageNo") Integer pageNo, |
||||
@RequestParam("pageSize") Integer pageSize) { |
||||
|
||||
Result result = checkPageParams(pageNo, pageSize); |
||||
if (!result.checkResult()) { |
||||
log.warn("Pagination parameters check failed, pageNo:{}, pageSize:{}", pageNo, pageSize); |
||||
return result; |
||||
} |
||||
searchVal = ParameterUtils.handleEscapes(searchVal); |
||||
return projectParameterService.queryProjectParameterListPaging(loginUser, projectCode, pageSize, pageNo, |
||||
searchVal); |
||||
} |
||||
|
||||
@Operation(summary = "queryProjectParameterByCode", description = "QUERY_PROJECT_PARAMETER_NOTES") |
||||
@Parameters({ |
||||
@Parameter(name = "code", description = "PROJECT_PARAMETER_CODE", schema = @Schema(implementation = long.class, example = "123456")) |
||||
}) |
||||
@GetMapping(value = "/{code}") |
||||
@ResponseStatus(HttpStatus.OK) |
||||
@ApiException(QUERY_PROJECT_PARAMETER_ERROR) |
||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||
public Result queryProjectParameterByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||
@PathVariable("code") long code) { |
||||
return projectParameterService.queryProjectParameterByCode(loginUser, projectCode, code); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.api.service; |
||||
|
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
public interface ProjectParameterService { |
||||
|
||||
Result createProjectParameter(User loginUser, long projectCode, String projectParameterName, |
||||
String projectParameterValue); |
||||
|
||||
Result updateProjectParameter(User loginUser, long projectCode, long code, String projectParameterName, |
||||
String projectParameterValue); |
||||
|
||||
Result deleteProjectParametersByCode(User loginUser, long projectCode, long code); |
||||
|
||||
Result batchDeleteProjectParametersByCodes(User loginUser, long projectCode, String codes); |
||||
|
||||
Result queryProjectParameterListPaging(User loginUser, long projectCode, Integer pageSize, Integer pageNo, |
||||
String searchVal); |
||||
|
||||
Result queryProjectParameterByCode(User loginUser, long projectCode, long code); |
||||
} |
@ -0,0 +1,275 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.api.service.impl; |
||||
|
||||
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status; |
||||
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
||||
import org.apache.dolphinscheduler.api.service.ProjectParameterService; |
||||
import org.apache.dolphinscheduler.api.service.ProjectService; |
||||
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.constants.Constants; |
||||
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
||||
import org.apache.dolphinscheduler.dao.entity.Project; |
||||
import org.apache.dolphinscheduler.dao.entity.ProjectParameter; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectParameterMapper; |
||||
|
||||
import org.apache.commons.collections4.CollectionUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.google.common.collect.Lists; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class ProjectParameterServiceImpl extends BaseServiceImpl implements ProjectParameterService { |
||||
|
||||
@Autowired |
||||
private ProjectParameterMapper projectParameterMapper; |
||||
|
||||
@Autowired |
||||
private ProjectService projectService; |
||||
|
||||
@Autowired |
||||
private ProjectMapper projectMapper; |
||||
|
||||
@Override |
||||
@Transactional |
||||
public Result createProjectParameter(User loginUser, long projectCode, String projectParameterName, |
||||
String projectParameterValue) { |
||||
Result result = new Result(); |
||||
|
||||
// check if user have write perm for project
|
||||
Project project = projectMapper.queryByCode(projectCode); |
||||
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); |
||||
if (!hasProjectAndWritePerm) { |
||||
return result; |
||||
} |
||||
|
||||
ProjectParameter projectParameter = projectParameterMapper.queryByName(projectParameterName); |
||||
if (projectParameter != null) { |
||||
log.warn("ProjectParameter {} already exists.", projectParameter.getParamName()); |
||||
putMsg(result, Status.PROJECT_PARAMETER_ALREADY_EXISTS, projectParameter.getParamName()); |
||||
return result; |
||||
} |
||||
|
||||
Date now = new Date(); |
||||
|
||||
try { |
||||
projectParameter = ProjectParameter |
||||
.builder() |
||||
.paramName(projectParameterName) |
||||
.paramValue(projectParameterValue) |
||||
.code(CodeGenerateUtils.getInstance().genCode()) |
||||
.projectCode(projectCode) |
||||
.userId(loginUser.getId()) |
||||
.createTime(now) |
||||
.updateTime(now) |
||||
.build(); |
||||
} catch (CodeGenerateUtils.CodeGenerateException e) { |
||||
log.error("Generate project parameter code error.", e); |
||||
putMsg(result, Status.CREATE_PROJECT_PARAMETER_ERROR); |
||||
return result; |
||||
} |
||||
|
||||
if (projectParameterMapper.insert(projectParameter) > 0) { |
||||
log.info("Project parameter is created and id is :{}", projectParameter.getId()); |
||||
result.setData(projectParameter); |
||||
putMsg(result, Status.SUCCESS); |
||||
} else { |
||||
log.error("Project parameter create error, projectName:{}.", projectParameter.getParamName()); |
||||
putMsg(result, Status.CREATE_PROJECT_PARAMETER_ERROR); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Result updateProjectParameter(User loginUser, long projectCode, long code, String projectParameterName, |
||||
String projectParameterValue) { |
||||
Result result = new Result(); |
||||
|
||||
// check if user have write perm for project
|
||||
Project project = projectMapper.queryByCode(projectCode); |
||||
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); |
||||
if (!hasProjectAndWritePerm) { |
||||
return result; |
||||
} |
||||
|
||||
ProjectParameter projectParameter = projectParameterMapper.queryByCode(code); |
||||
// check project parameter exists
|
||||
if (projectParameter == null || projectCode != projectParameter.getProjectCode()) { |
||||
log.error("Project parameter does not exist, code:{}.", code); |
||||
putMsg(result, Status.PROJECT_PARAMETER_NOT_EXISTS, String.valueOf(code)); |
||||
return result; |
||||
} |
||||
|
||||
// check if project parameter name exists
|
||||
ProjectParameter tempProjectParameter = projectParameterMapper.queryByName(projectParameterName); |
||||
if (tempProjectParameter != null) { |
||||
log.error("Project parameter name {} already exists", projectParameterName); |
||||
putMsg(result, Status.PROJECT_PARAMETER_ALREADY_EXISTS, projectParameterName); |
||||
return result; |
||||
} |
||||
|
||||
projectParameter.setParamName(projectParameterName); |
||||
projectParameter.setParamValue(projectParameterValue); |
||||
|
||||
if (projectParameterMapper.updateById(projectParameter) > 0) { |
||||
log.info("Project parameter is updated and id is :{}", projectParameter.getId()); |
||||
result.setData(projectParameter); |
||||
putMsg(result, Status.SUCCESS); |
||||
} else { |
||||
log.error("Project parameter update error, {}.", projectParameterName); |
||||
putMsg(result, Status.UPDATE_PROJECT_PARAMETER_ERROR); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Result deleteProjectParametersByCode(User loginUser, long projectCode, long code) { |
||||
Result result = new Result(); |
||||
|
||||
// check if user have write perm for project
|
||||
Project project = projectMapper.queryByCode(projectCode); |
||||
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); |
||||
if (!hasProjectAndWritePerm) { |
||||
return result; |
||||
} |
||||
|
||||
ProjectParameter projectParameter = projectParameterMapper.queryByCode(code); |
||||
// check project parameter exists
|
||||
if (projectParameter == null || projectCode != projectParameter.getProjectCode()) { |
||||
log.error("Project parameter does not exist, code:{}.", code); |
||||
putMsg(result, Status.PROJECT_PARAMETER_NOT_EXISTS, String.valueOf(code)); |
||||
return result; |
||||
} |
||||
|
||||
// TODO: check project parameter is used by workflow
|
||||
|
||||
if (projectParameterMapper.deleteById(projectParameter.getId()) > 0) { |
||||
log.info("Project parameter is deleted and id is :{}.", projectParameter.getId()); |
||||
result.setData(Boolean.TRUE); |
||||
putMsg(result, Status.SUCCESS); |
||||
} else { |
||||
log.error("Project parameter delete error, {}.", projectParameter.getParamName()); |
||||
putMsg(result, Status.DELETE_PROJECT_PARAMETER_ERROR); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Result batchDeleteProjectParametersByCodes(User loginUser, long projectCode, String codes) { |
||||
Result result = new Result(); |
||||
|
||||
if (StringUtils.isEmpty(codes)) { |
||||
log.error("Project parameter codes is empty, projectCode is {}.", projectCode); |
||||
putMsg(result, Status.PROJECT_PARAMETER_CODE_EMPTY); |
||||
return result; |
||||
} |
||||
|
||||
Set<Long> requestCodeSet = Lists.newArrayList(codes.split(Constants.COMMA)).stream().map(Long::parseLong) |
||||
.collect(Collectors.toSet()); |
||||
List<ProjectParameter> projectParameterList = projectParameterMapper.queryByCodes(requestCodeSet); |
||||
Set<Long> actualCodeSet = |
||||
projectParameterList.stream().map(ProjectParameter::getCode).collect(Collectors.toSet()); |
||||
// requestCodeSet - actualCodeSet
|
||||
Set<Long> diffCode = |
||||
requestCodeSet.stream().filter(code -> !actualCodeSet.contains(code)).collect(Collectors.toSet()); |
||||
|
||||
String diffCodeString = diffCode.stream().map(String::valueOf).collect(Collectors.joining(Constants.COMMA)); |
||||
if (CollectionUtils.isNotEmpty(diffCode)) { |
||||
log.error("Project parameter does not exist, codes:{}.", diffCodeString); |
||||
throw new ServiceException(Status.PROJECT_PARAMETER_NOT_EXISTS, diffCodeString); |
||||
} |
||||
|
||||
for (ProjectParameter projectParameter : projectParameterList) { |
||||
try { |
||||
this.deleteProjectParametersByCode(loginUser, projectCode, projectParameter.getCode()); |
||||
} catch (Exception e) { |
||||
throw new ServiceException(Status.DELETE_PROJECT_PARAMETER_ERROR, e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Result queryProjectParameterListPaging(User loginUser, long projectCode, Integer pageSize, Integer pageNo, |
||||
String searchVal) { |
||||
Result result = new Result(); |
||||
|
||||
Project project = projectMapper.queryByCode(projectCode); |
||||
boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result, PROJECT); |
||||
if (!hasProjectAndPerm) { |
||||
return result; |
||||
} |
||||
|
||||
PageInfo<ProjectParameter> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||
Page<ProjectParameter> page = new Page<>(pageNo, pageSize); |
||||
|
||||
IPage<ProjectParameter> iPage = |
||||
projectParameterMapper.queryProjectParameterListPaging(page, null, searchVal); |
||||
|
||||
List<ProjectParameter> projectParameterList = iPage.getRecords(); |
||||
|
||||
pageInfo.setTotal((int) iPage.getTotal()); |
||||
pageInfo.setTotalList(projectParameterList); |
||||
result.setData(pageInfo); |
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Result queryProjectParameterByCode(User loginUser, long projectCode, long code) { |
||||
Result result = new Result(); |
||||
|
||||
Project project = projectMapper.queryByCode(projectCode); |
||||
boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result, PROJECT); |
||||
if (!hasProjectAndPerm) { |
||||
return result; |
||||
} |
||||
|
||||
ProjectParameter projectParameter = projectParameterMapper.queryByCode(code); |
||||
if (projectParameter == null || projectCode != projectParameter.getProjectCode()) { |
||||
log.error("Project parameter does not exist, code:{}.", code); |
||||
putMsg(result, Status.PROJECT_PARAMETER_NOT_EXISTS, String.valueOf(code)); |
||||
return result; |
||||
} |
||||
|
||||
result.setData(projectParameter); |
||||
putMsg(result, Status.SUCCESS); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.dao.entity; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
||||
@Data |
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@TableName("t_ds_project_parameter") |
||||
public class ProjectParameter { |
||||
|
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@TableField("user_id") |
||||
private Integer userId; |
||||
|
||||
private long code; |
||||
|
||||
@TableField("project_code") |
||||
private long projectCode; |
||||
|
||||
@TableField("param_name") |
||||
private String paramName; |
||||
|
||||
@TableField("param_value") |
||||
private String paramValue; |
||||
|
||||
private Date createTime; |
||||
|
||||
private Date updateTime; |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.dao.mapper; |
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.ProjectParameter; |
||||
|
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.List; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
||||
public interface ProjectParameterMapper extends BaseMapper<ProjectParameter> { |
||||
|
||||
ProjectParameter queryByCode(@Param("code") long code); |
||||
|
||||
List<ProjectParameter> queryByCodes(@Param("codes") Collection<Long> codes); |
||||
|
||||
ProjectParameter queryByName(@Param("paramName") String paramName); |
||||
|
||||
IPage<ProjectParameter> queryProjectParameterListPaging(IPage<ProjectParameter> page, |
||||
@Param("projectParameterIds") List<Integer> projectParameterIds, |
||||
@Param("searchName") String searchName); |
||||
} |
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!-- |
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||
~ contributor license agreements. See the NOTICE file distributed with |
||||
~ this work for additional information regarding copyright ownership. |
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
~ (the "License"); you may not use this file except in compliance with |
||||
~ the License. You may obtain a copy of the License at |
||||
~ |
||||
~ http://www.apache.org/licenses/LICENSE-2.0 |
||||
~ |
||||
~ Unless required by applicable law or agreed to in writing, software |
||||
~ distributed under the License is distributed on an "AS IS" BASIS, |
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
~ See the License for the specific language governing permissions and |
||||
~ limitations under the License. |
||||
--> |
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProjectParameterMapper"> |
||||
<sql id="baseSql"> |
||||
id, param_name, param_value, code, project_code, user_id, create_time, update_time |
||||
</sql> |
||||
|
||||
<select id="queryByCode" resultType="org.apache.dolphinscheduler.dao.entity.ProjectParameter"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_project_parameter |
||||
where code = #{code} |
||||
</select> |
||||
|
||||
<select id="queryByCodes" resultType="org.apache.dolphinscheduler.dao.entity.ProjectParameter"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_project_parameter |
||||
where 1 = 1 |
||||
<if test="codes != null and codes.size() != 0"> |
||||
and code in |
||||
<foreach collection="codes" index="index" item="i" open="(" separator="," close=")"> |
||||
#{i} |
||||
</foreach> |
||||
</if> |
||||
</select> |
||||
|
||||
<select id="queryByName" resultType="org.apache.dolphinscheduler.dao.entity.ProjectParameter"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_project_parameter |
||||
where param_name = #{paramName} |
||||
</select> |
||||
|
||||
<select id="queryProjectParameterListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProjectParameter"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_project_parameter |
||||
where 1=1 |
||||
<if test="projectParameterIds != null and projectParameterIds.size() > 0"> |
||||
and id in |
||||
<foreach item="id" index="index" collection="projectParameterIds" open="(" separator="," close=")"> |
||||
#{id} |
||||
</foreach> |
||||
</if> |
||||
<if test="searchName!=null and searchName != ''"> |
||||
AND (param_name LIKE concat('%', #{searchName}, '%') |
||||
OR param_value LIKE concat('%', #{searchName}, '%') |
||||
) |
||||
</if> |
||||
order by id desc |
||||
</select> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue