Browse Source
* [Feature][Api] Refactor org.apache.dolphinscheduler.api.controller.ProjectController3.1.0-release
xuhhui
2 years ago
committed by
GitHub
19 changed files with 1123 additions and 169 deletions
@ -0,0 +1,290 @@ |
|||||||
|
/* |
||||||
|
* 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_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROJECT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_PROJECT; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_USER; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS_BY_CODE_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_PROJECT_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectCreateRequest; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectCreateResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectDeleteResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectListPagingResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectListResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryRequest; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateRequest; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.user.UserListResponse; |
||||||
|
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProjectService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.utils.ParameterUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping; |
||||||
|
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.RequestBody; |
||||||
|
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.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import springfox.documentation.annotations.ApiIgnore; |
||||||
|
|
||||||
|
/** |
||||||
|
* project controller |
||||||
|
*/ |
||||||
|
@Api(tags = "PROJECT_TAG") |
||||||
|
@RestController |
||||||
|
@RequestMapping("/v2/projects") |
||||||
|
public class ProjectV2Controller extends BaseController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectService projectService; |
||||||
|
|
||||||
|
/** |
||||||
|
* create project |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCreateRequest projectCreateRequest |
||||||
|
* @return ProjectResponse ProjectResponse |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "create", notes = "CREATE_PROJECT_NOTES") |
||||||
|
@PostMapping(consumes = {"application/json"}) |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
@ApiException(CREATE_PROJECT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectCreateResponse createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestBody ProjectCreateRequest projectCreateRequest) { |
||||||
|
Result result = projectService.createProject(loginUser, projectCreateRequest.getProjectName(), |
||||||
|
projectCreateRequest.getDescription()); |
||||||
|
return new ProjectCreateResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update project |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code project code |
||||||
|
* @param projectUpdateReq projectUpdateRequest |
||||||
|
* @return result Result |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "update", notes = "UPDATE_PROJECT_NOTES") |
||||||
|
@PutMapping(value = "/{code}", consumes = {"application/json"}) |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(UPDATE_PROJECT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectUpdateResponse updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@PathVariable("code") Long code, |
||||||
|
@RequestBody ProjectUpdateRequest projectUpdateReq) { |
||||||
|
Result result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(), |
||||||
|
projectUpdateReq.getDescription(), projectUpdateReq.getUserName()); |
||||||
|
return new ProjectUpdateResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query project details by project code |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code project code |
||||||
|
* @return project detail information |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryProjectByCode", notes = "QUERY_PROJECT_BY_ID_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/{code}") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_PROJECT_DETAILS_BY_CODE_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectQueryResponse queryProjectByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@PathVariable("code") long code) { |
||||||
|
Result result = projectService.queryByCode(loginUser, code); |
||||||
|
return new ProjectQueryResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query project list paging |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectQueryReq projectQueryReq |
||||||
|
* @return project list which the login user have permission to see |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryProjectListPaging", notes = "QUERY_PROJECT_LIST_PAGING_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String", example = "test"), |
||||||
|
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10"), |
||||||
|
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1") |
||||||
|
}) |
||||||
|
@GetMapping(consumes = {"application/json"}) |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectListPagingResponse queryProjectListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
ProjectQueryRequest projectQueryReq) { |
||||||
|
Result result = checkPageParams(projectQueryReq.getPageNo(), projectQueryReq.getPageSize()); |
||||||
|
if (!result.checkResult()) { |
||||||
|
return new ProjectListPagingResponse(result); |
||||||
|
} |
||||||
|
String searchVal = ParameterUtils.handleEscapes(projectQueryReq.getSearchVal()); |
||||||
|
result = projectService.queryProjectListPaging(loginUser, projectQueryReq.getPageSize(), |
||||||
|
projectQueryReq.getPageNo(), searchVal); |
||||||
|
return new ProjectListPagingResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete project by code |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param code project code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "delete", notes = "DELETE_PROJECT_BY_ID_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456", required = true) |
||||||
|
}) |
||||||
|
@DeleteMapping(value = "/{code}") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_PROJECT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectDeleteResponse deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@PathVariable("code") Long code) { |
||||||
|
Result result = projectService.deleteProject(loginUser, code); |
||||||
|
return new ProjectDeleteResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query unauthorized project |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param userId user id |
||||||
|
* @return the projects which user have not permission to see |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryUnauthorizedProject", notes = "QUERY_UNAUTHORIZED_PROJECT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/unauth-project") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_UNAUTHORIZED_PROJECT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectListResponse queryUnauthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("userId") Integer userId) { |
||||||
|
Result result = projectService.queryUnauthorizedProject(loginUser, userId); |
||||||
|
return new ProjectListResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query authorized project |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param userId user id |
||||||
|
* @return projects which the user have permission to see, Except for items created by this user |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryAuthorizedProject", notes = "QUERY_AUTHORIZED_PROJECT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/authed-project") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_AUTHORIZED_PROJECT) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectListResponse queryAuthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("userId") Integer userId) { |
||||||
|
Result result = projectService.queryAuthorizedProject(loginUser, userId); |
||||||
|
return new ProjectListResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query authorized user |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @return users who have permission for the specified project |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryAuthorizedUser", notes = "QUERY_AUTHORIZED_USER_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/authed-user") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_AUTHORIZED_USER) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public UserListResponse queryAuthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("projectCode") Long projectCode) { |
||||||
|
Result result = projectService.queryAuthorizedUser(loginUser, projectCode); |
||||||
|
return new UserListResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query authorized and user created project |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @return projects which the user create and authorized |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryProjectCreatedAndAuthorizedByUser", notes = "QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "loginUser", value = "LOGIN_USER", dataType = "Object", example = "\"{id:100}\"", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/created-and-authed") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectListResponse queryProjectCreatedAndAuthorizedByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
Result result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); |
||||||
|
return new ProjectListResponse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all project list |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @return all project list |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryAllProjectList", notes = "QUERY_ALL_PROJECT_LIST_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "loginUser", value = "LOGIN_USER", dataType = "Object", example = "\"{id:100}\"", required = true) |
||||||
|
}) |
||||||
|
@GetMapping(value = "/list") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public ProjectListResponse queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
Result result = projectService.queryAllProjectList(loginUser); |
||||||
|
return new ProjectListResponse(result); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* 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.dto; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* page query dto |
||||||
|
*/ |
||||||
|
@ApiModel("QUERY-PAGE-INFO") |
||||||
|
@Data |
||||||
|
public class PageQueryDto { |
||||||
|
|
||||||
|
@ApiModelProperty(example = "10", required = true) |
||||||
|
private Integer pageSize; |
||||||
|
|
||||||
|
@ApiModelProperty(example = "1", required = true) |
||||||
|
private Integer pageNo; |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project create request |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectCreateRequest { |
||||||
|
|
||||||
|
@ApiModelProperty(example = "pro123", required = true) |
||||||
|
private String projectName; |
||||||
|
|
||||||
|
@ApiModelProperty(example = "this is a project") |
||||||
|
private String description; |
||||||
|
} |
@ -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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project create response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectCreateResponse extends Result { |
||||||
|
|
||||||
|
private Project data; |
||||||
|
|
||||||
|
public ProjectCreateResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData((Project) result.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project delete response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectDeleteResponse extends Result { |
||||||
|
|
||||||
|
private Boolean data; |
||||||
|
|
||||||
|
public ProjectDeleteResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData((Boolean) result.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project List paging response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectListPagingResponse extends Result { |
||||||
|
|
||||||
|
private PageInfo<Project> data; |
||||||
|
|
||||||
|
public ProjectListPagingResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData(result.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project List response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectListResponse extends Result { |
||||||
|
|
||||||
|
private List<Project> data; |
||||||
|
|
||||||
|
public ProjectListResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData(JSONUtils.toList(JSONUtils.toJsonString(result.getData()), Project.class)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.dto.PageQueryDto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project query request |
||||||
|
*/ |
||||||
|
@ApiModel("PROJECT-QUERY") |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
@Data |
||||||
|
public class ProjectQueryRequest extends PageQueryDto { |
||||||
|
|
||||||
|
@ApiModelProperty(example = "pro123") |
||||||
|
private String searchVal; |
||||||
|
} |
@ -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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project query response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectQueryResponse extends Result { |
||||||
|
|
||||||
|
private Project data; |
||||||
|
|
||||||
|
public ProjectQueryResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData((Project) result.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.project; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project update request |
||||||
|
*/ |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
@Data |
||||||
|
public class ProjectUpdateRequest { |
||||||
|
|
||||||
|
@ApiModelProperty(example = "admin", required = true) |
||||||
|
private String userName; |
||||||
|
|
||||||
|
@ApiModelProperty(example = "pro123", required = true) |
||||||
|
private String projectName; |
||||||
|
|
||||||
|
@ApiModelProperty(example = "this is a project") |
||||||
|
private String description; |
||||||
|
} |
@ -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.dto.project; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* project update response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ProjectUpdateResponse extends Result { |
||||||
|
|
||||||
|
private Project data; |
||||||
|
|
||||||
|
public ProjectUpdateResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData((Project) result.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* 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.dto.user; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* user List response |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class UserListResponse extends Result { |
||||||
|
|
||||||
|
private List<User> data; |
||||||
|
|
||||||
|
public UserListResponse(Result result) { |
||||||
|
super(); |
||||||
|
this.setCode(result.getCode()); |
||||||
|
this.setMsg(result.getMsg()); |
||||||
|
this.setData(JSONUtils.toList(JSONUtils.toJsonString(result.getData()), User.class)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,165 @@ |
|||||||
|
/* |
||||||
|
* 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 org.apache.dolphinscheduler.api.dto.project.ProjectListResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryRequest; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectQueryResponse; |
||||||
|
import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateRequest; |
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.enums.UserType; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Resource; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||||
|
|
||||||
|
import java.text.MessageFormat; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.InjectMocks; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
|
||||||
|
/** |
||||||
|
* project v2 controller test |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.Silent.class) |
||||||
|
public class ProjectV2ControllerTest { |
||||||
|
|
||||||
|
protected User user; |
||||||
|
@InjectMocks |
||||||
|
private ProjectV2Controller projectV2Controller; |
||||||
|
@Mock |
||||||
|
private ProjectServiceImpl projectService; |
||||||
|
@Mock |
||||||
|
private ProjectMapper projectMapper; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void before() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
loginUser.setUserName("admin"); |
||||||
|
user = loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdateProject() { |
||||||
|
Result result = new Result(); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
|
||||||
|
long projectCode = 1L; |
||||||
|
ProjectUpdateRequest projectUpdateReq = new ProjectUpdateRequest(); |
||||||
|
projectUpdateReq.setProjectName("james"); |
||||||
|
projectUpdateReq.setDescription("james lbj"); |
||||||
|
projectUpdateReq.setUserName("admin"); |
||||||
|
Mockito.when(projectService.update(user, projectCode, projectUpdateReq.getProjectName(), |
||||||
|
projectUpdateReq.getDescription(), projectUpdateReq.getUserName())).thenReturn(result); |
||||||
|
Result response = projectV2Controller.updateProject(user, projectCode, projectUpdateReq); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryProjectByCode() { |
||||||
|
Result result = new Result(); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
long projectCode = 1L; |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject()); |
||||||
|
Mockito.when(projectService.queryByCode(user, projectCode)).thenReturn(result); |
||||||
|
ProjectQueryResponse response = projectV2Controller.queryProjectByCode(user, projectCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryProjectListPaging() { |
||||||
|
ProjectQueryRequest projectQueryReq = new ProjectQueryRequest(); |
||||||
|
projectQueryReq.setSearchVal("james"); |
||||||
|
projectQueryReq.setPageNo(1); |
||||||
|
projectQueryReq.setPageSize(10); |
||||||
|
|
||||||
|
Result result = Result.success(new PageInfo<Resource>(1, 10)); |
||||||
|
Mockito.when(projectService.queryProjectListPaging(user, projectQueryReq.getPageSize(), |
||||||
|
projectQueryReq.getPageNo(), projectQueryReq.getSearchVal())).thenReturn(result); |
||||||
|
Result response = projectV2Controller.queryProjectListPaging(user, projectQueryReq); |
||||||
|
Assert.assertTrue(response != null && response.isSuccess()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryUnauthorizedProject() { |
||||||
|
Result result = new Result(); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
Mockito.when(projectService.queryUnauthorizedProject(user, 2)).thenReturn(result); |
||||||
|
ProjectListResponse response = projectV2Controller.queryUnauthorizedProject(user, 2); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAuthorizedProject() { |
||||||
|
Result result = new Result(); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
Mockito.when(projectService.queryAuthorizedProject(user, 2)).thenReturn(result); |
||||||
|
ProjectListResponse response = projectV2Controller.queryAuthorizedProject(user, 2); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAuthorizedUser() { |
||||||
|
Result result = new Result(); |
||||||
|
this.putMsg(result, Status.SUCCESS); |
||||||
|
|
||||||
|
Mockito.when(this.projectService.queryAuthorizedUser(this.user, 3682329499136L)).thenReturn(result); |
||||||
|
Result response = this.projectV2Controller.queryAuthorizedUser(this.user, 3682329499136L); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryAllProjectList() { |
||||||
|
User user = new User(); |
||||||
|
user.setId(0); |
||||||
|
Result result = new Result(); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
Mockito.when(projectService.queryAllProjectList(user)).thenReturn(result); |
||||||
|
Result response = projectV2Controller.queryAllProjectList(user); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
private Project getProject() { |
||||||
|
Project project = new Project(); |
||||||
|
project.setCode(1L); |
||||||
|
project.setId(1); |
||||||
|
project.setName("test"); |
||||||
|
project.setUserId(1); |
||||||
|
return project; |
||||||
|
} |
||||||
|
|
||||||
|
private void putMsg(Result result, Status status, Object... statusParams) { |
||||||
|
result.setCode(status.getCode()); |
||||||
|
if (statusParams != null && statusParams.length > 0) { |
||||||
|
result.setMsg(MessageFormat.format(status.getMsg(), statusParams)); |
||||||
|
} else { |
||||||
|
result.setMsg(status.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue