Skip to content

Commit 1c5d775

Browse files
authored
Merge pull request #548 from ElishaZhang/dev-1.0.1
Dev 1.0.1
2 parents f3f4845 + 87d50be commit 1c5d775

File tree

5 files changed

+249
-30
lines changed

5 files changed

+249
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
*
3+
* * Copyright 2019 WeBank
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package com.webank.wedatasphere.dss.apiservice.core.dao;
20+
21+
22+
import com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo;
23+
import org.apache.ibatis.annotations.Param;
24+
25+
import java.util.List;
26+
27+
28+
public interface ApiServiceApprovalDao {
29+
30+
/**
31+
* 新增一条审批单
32+
*/
33+
void insert(ApprovalVo approvalVo);
34+
35+
/**
36+
* 查询审批单
37+
* */
38+
List<ApprovalVo> queryByApprovalNo(@Param("approvalNo") String approvalNo);
39+
40+
/**
41+
* set status to success
42+
* */
43+
void setApprovalStatusSuccess(@Param("approvalNo") String approvalNo);
44+
45+
/**
46+
* set status to failed
47+
* */
48+
void setApprovalStatusFailed(@Param("approvalNo") String approvalNo);
49+
50+
/**
51+
* set status to init
52+
* */
53+
void setApprovalStatusInit(@Param("approvalNo") String approvalNo);
54+
55+
/**
56+
* set status to applying
57+
* */
58+
void setApprovalStatusApplying(@Param("approvalNo") String approvalNo);
59+
60+
/**
61+
* update status
62+
* */
63+
void updateApprovalStatus(@Param("approvalNo") String approvalNo, @Param("status") Integer status);
64+
65+
66+
/**
67+
* delete approval
68+
* */
69+
void deleteApproval(@Param("approvalNo") String approvalNo);
70+
71+
/**
72+
* 通过版本ID查询审批单
73+
* */
74+
ApprovalVo queryByVersionId(@Param("apiVersionId") Long apiVersionId);
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ /*
4+
~ * Copyright 2019 WeBank
5+
~ *
6+
~ * Licensed under the Apache License, Version 2.0 (the "License");
7+
~ * you may not use this file except in compliance with the License.
8+
~ * You may obtain a copy of the License at
9+
~ *
10+
~ * http://www.apache.org/licenses/LICENSE-2.0
11+
~ *
12+
~ * Unless required by applicable law or agreed to in writing, software
13+
~ * distributed under the License is distributed on an "AS IS" BASIS,
14+
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ * See the License for the specific language governing permissions and
16+
~ * limitations under the License.
17+
~ */
18+
-->
19+
20+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
21+
<mapper namespace="com.webank.wedatasphere.dss.apiservice.core.dao.ApiServiceApprovalDao">
22+
23+
<resultMap id="approvalMap" type="com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo">
24+
<result property="id" column="id"/>
25+
<result property="apiId" column="api_id"/>
26+
<result property="apiVersionId" column="api_version_id"/>
27+
<result property="approvalName" column="approval_name"/>
28+
<result property="applyUser" column="apply_user"/>
29+
<result property="executeUser" column="execute_user"/>
30+
<result property="creator" column="creator"/>
31+
<result property="status" column="status"/>
32+
<result property="createTime" column="create_time"/>
33+
<result property="updateTime" column="update_time"/>
34+
<result property="approvalNo" column="approval_no"/>
35+
</resultMap>
36+
37+
<sql id="fields">
38+
`api_id`, `api_version_id`, `approval_name`, `apply_user`, `execute_user`, `creator`,
39+
`status`, `create_time`, `update_time`, `approval_no`
40+
</sql>
41+
42+
<sql id="fields_query">
43+
`id`, `api_version_id`, `api_id`, `approval_name`, `apply_user`, `execute_user`, `creator`,
44+
`status`, `create_time`, `update_time`, `approval_no`
45+
</sql>
46+
47+
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo">
48+
<![CDATA[INSERT INTO `dss_apiservice_approval`(]]>
49+
<include refid="fields"/>
50+
<![CDATA[) VALUES(#{apiId}, #{apiVersionId}, #{approvalName}, #{applyUser}, #{executeUser}, #{creator},
51+
#{status}, #{createTime}, #{updateTime}, #{approvalNo})]]>
52+
</insert>
53+
54+
<select id="queryByApprovalNo" parameterType="java.lang.String" resultMap="approvalMap">
55+
<![CDATA[SELECT]]>
56+
<include refid="fields_query"/>
57+
<![CDATA[ FROM `dss_apiservice_approval` ]]>
58+
<where>
59+
`approval_no` = #{approvalNo}
60+
</where>
61+
</select>
62+
63+
<update id="setApprovalStatusSuccess" parameterType="java.lang.String">
64+
UPDATE `dss_apiservice_approval`
65+
SET `status` = 3
66+
WHERE `approval_no` = #{approvalNo}
67+
</update>
68+
69+
<update id="setApprovalStatusFailed" parameterType="java.lang.String">
70+
UPDATE `dss_apiservice_approval`
71+
SET `status` = 4
72+
WHERE `approval_no` = #{approvalNo}
73+
</update>
74+
75+
<update id="setApprovalStatusInit" parameterType="java.lang.String">
76+
UPDATE `dss_apiservice_approval`
77+
SET `status` = 1
78+
WHERE `approval_no` = #{approvalNo}
79+
</update>
80+
81+
<update id="setApprovalStatusApplying" parameterType="java.lang.String">
82+
UPDATE `dss_apiservice_approval`
83+
SET `status` = 2
84+
WHERE `approval_no` = #{approvalNo}
85+
</update>
86+
87+
<update id="updateApprovalStatus">
88+
UPDATE `dss_apiservice_approval`
89+
SET `status` = #{status}
90+
WHERE `approval_no` = #{approvalNo}
91+
</update>
92+
93+
<delete id="deleteApproval" parameterType="java.lang.String">
94+
DELETE FROM
95+
`dss_apiservice_approval`
96+
WHERE `approval_no` = #{approvalNo}
97+
</delete>
98+
99+
<select id="queryByVersionId" parameterType="java.lang.Long" resultMap="approvalMap">
100+
<![CDATA[SELECT]]>
101+
<include refid="fields_query"/>
102+
<![CDATA[ FROM `dss_apiservice_approval` ]]>
103+
<where>
104+
`api_version_id` = #{apiVersionId}
105+
</where>
106+
</select>
107+
108+
109+
</mapper>

dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceExecuteRestfulApi.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
import javax.servlet.http.HttpServletRequest;
4646
import javax.servlet.http.HttpServletResponse;
47-
import javax.ws.rs.DefaultValue;
4847
import javax.ws.rs.HttpMethod;
4948
import javax.ws.rs.core.Response;
5049
import java.io.IOException;
@@ -67,7 +66,7 @@ public class ApiServiceExecuteRestfulApi {
6766

6867
@RequestMapping(value = "/execute/{path:.*}",method = RequestMethod.POST)
6968
public Message post(@PathVariable("path") VariableString path, @RequestBody QueryRequest queryRequest,
70-
HttpServletRequest req) {
69+
HttpServletRequest req) {
7170
String userName = SecurityFilter.getLoginUsername(req);
7271
return getResponse(userName,path.getPath(), queryRequest, HttpMethod.POST);
7372
}
@@ -94,8 +93,8 @@ public Message get(@PathVariable("path") VariableString path,
9493
queryRequest.setParams(params);
9594
}
9695
String paramsJsonStr = req.getParameter("params");
97-
JavaType javaType = BDPJettyServerHelper.jacksonJson().getTypeFactory().constructParametricType(Map.class,String.class,Object.class);
98-
Map<String,Object> parmas = BDPJettyServerHelper.jacksonJson().readValue(paramsJsonStr, javaType);
96+
JavaType javaType = BDPJettyServerHelper.jacksonJson().getTypeFactory().constructParametricType(Map.class, String.class, Object.class);
97+
Map<String, Object> parmas = BDPJettyServerHelper.jacksonJson().readValue(paramsJsonStr, javaType);
9998
queryRequest.setParams(parmas);
10099

101100
if (StringUtils.isEmpty(queryRequest.getModuleName())) {
@@ -107,14 +106,14 @@ public Message get(@PathVariable("path") VariableString path,
107106

108107
@RequestMapping(value = "/execute/{path:.*}",method = RequestMethod.PUT)
109108
public Message put(@PathVariable("path") VariableString path, @RequestBody QueryRequest queryRequest,
110-
HttpServletRequest req) {
109+
HttpServletRequest req) {
111110
String userName = SecurityFilter.getLoginUsername(req);
112111
return getResponse(userName,path.getPath(), queryRequest, HttpMethod.PUT);
113112
}
114113

115114
@RequestMapping(value = "/execute/{path:.*}",method = RequestMethod.DELETE)
116115
public Message delete(@PathVariable("path") VariableString path, @RequestBody QueryRequest queryRequest,
117-
HttpServletRequest req) {
116+
HttpServletRequest req) {
118117
String userName = SecurityFilter.getLoginUsername(req);
119118
return getResponse(userName,path.getPath(), queryRequest, HttpMethod.DELETE);
120119
}
@@ -131,7 +130,7 @@ public void getDirFileTrees(HttpServletRequest req, HttpServletResponse resp,
131130
@RequestParam(required = false, name = "taskId") String taskId) throws IOException, ApiServiceQueryException {
132131
String userName = SecurityFilter.getLoginUsername(req);
133132
if (StringUtils.isEmpty(path)) {
134-
throw new ApiServiceQueryException(80004, path);
133+
throw new ApiServiceQueryException(80004, path);
135134
}
136135
String dirFileTree="";
137136
ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
@@ -154,18 +153,18 @@ public void getDirFileTrees(HttpServletRequest req, HttpServletResponse resp,
154153

155154
@RequestMapping(value = "/openFile",method = RequestMethod.GET)
156155
public void openFile(HttpServletRequest req,
157-
@RequestParam(required = false, name = "path") String path,
158-
@RequestParam(required = false, name = "taskId") String taskId,
159-
@DefaultValue("1") @RequestParam(required = false, name = "page") Integer page,
160-
@DefaultValue("5000") @RequestParam(required = false, name = "pageSize") Integer pageSize,
161-
@DefaultValue("utf-8") @RequestParam(required = false, name = "charset") String charset,
162-
HttpServletResponse resp) throws IOException, ApiServiceQueryException {
156+
@RequestParam(required = false, name = "path") String path,
157+
@RequestParam(required = false, name = "taskId") String taskId,
158+
@RequestParam(required = false, defaultValue = ("1"), name = "page") Integer page,
159+
@RequestParam(required = false, defaultValue = "5000", name = "pageSize") Integer pageSize,
160+
@RequestParam(required = false, name = "charset", defaultValue = "utf-8") String charset,
161+
HttpServletResponse resp) throws IOException, ApiServiceQueryException {
163162
String userName = SecurityFilter.getLoginUsername(req);
164163
if (StringUtils.isEmpty(path)) {
165-
throw new ApiServiceQueryException(80004, path);
164+
throw new ApiServiceQueryException(80004, path);
166165
}
167166
if(StringUtils.isEmpty(taskId)){
168-
throw new ApiServiceQueryException(80005, "taskId is null");
167+
throw new ApiServiceQueryException(80005, "taskId is null");
169168
}
170169
String fileContent="";
171170
ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
@@ -186,12 +185,12 @@ public void resultsetToExcel(
186185
HttpServletResponse resp,
187186
@RequestParam(required = false, name = "path") String path,
188187
@RequestParam(required = false, name = "taskId") String taskId,
189-
@DefaultValue("utf-8") @RequestParam(required = false, name = "charset") String charset,
190-
@DefaultValue("csv") @RequestParam(required = false, name = "outputFileType") String outputFileType,
191-
@DefaultValue(",") @RequestParam(required = false, name = "csvSeperator") String csvSeperator,
192-
@DefaultValue("downloadResultset") @RequestParam(required = false, name = "outputFileName") String outputFileName,
193-
@DefaultValue("result") @RequestParam(required = false, name = "sheetName") String sheetName,
194-
@DefaultValue("NULL") @RequestParam(required = false, name = "nullValue") String nullValue) throws ApiServiceQueryException, IOException {
188+
@RequestParam(required = false, name = "charset", defaultValue = ("utf-8")) String charset,
189+
@RequestParam(required = false, name = "outputFileType", defaultValue = ("csv")) String outputFileType,
190+
@RequestParam(required = false, name = "csvSeperator", defaultValue = (",")) String csvSeperator,
191+
@RequestParam(required = false, name = "outputFileName", defaultValue = ("downloadResultset")) String outputFileName,
192+
@RequestParam(required = false, name = "sheetName", defaultValue = ("result")) String sheetName,
193+
@RequestParam(required = false, name = "nullValue", defaultValue = ("NULL")) String nullValue) throws ApiServiceQueryException, IOException {
195194

196195
resp.addHeader("Content-Disposition", "attachment;filename="
197196
+ new String(outputFileName.getBytes("UTF-8"), "ISO8859-1") + "." + outputFileType);
@@ -211,7 +210,7 @@ public void resultsetToExcel(
211210

212211
String userName = SecurityFilter.getLoginUsername(req);
213212
if (StringUtils.isEmpty(path)) {
214-
throw new ApiServiceQueryException(80005, path);
213+
throw new ApiServiceQueryException(80005, path);
215214
}
216215
InputStream inputStream;
217216
ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
@@ -256,7 +255,7 @@ public Message getTaskByID(HttpServletRequest req, @PathVariable("id") Long task
256255
}
257256
}
258257

259-
private Message getResponse(String user,String path, QueryRequest queryRequest, String httpMethod) {
258+
private Message getResponse(String user, String path, QueryRequest queryRequest, String httpMethod) {
260259
Response response = ApiUtils.doAndResponse(() -> {
261260
validParam(queryRequest);
262261
String token = queryRequest.getParams().get(ApiServiceConfiguration.API_SERVICE_TOKEN_KEY.getValue()).toString();
@@ -283,7 +282,7 @@ private Message getResponse(String user,String path, QueryRequest queryRequest,
283282
return messageVo;
284283
}
285284

286-
HashMap<String,Object> queryRes = new HashMap<>();
285+
HashMap<String, Object> queryRes = new HashMap<>();
287286
queryRes.put("taskId",query.getTaskId());
288287
queryRes.put("execId",query.getExecId());
289288
messageVo = new MessageVo().setData(queryRes);

dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceImpl.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public class ApiServiceImpl implements ApiService {
7878
@Autowired
7979
private ApiServiceTokenManagerDao apiServiceTokenManagerDao;
8080

81+
@Autowired
82+
ApiServiceApprovalDao apiServiceApprovalDao;
83+
8184
@Autowired
8285
TokenAuth tokenAuth;
8386

@@ -137,9 +140,7 @@ public void save(ApiServiceVo apiService) throws Exception {
137140
//todo update by query
138141
apiVersionVo.setMetadataInfo("default");
139142
apiServiceVersionDao.insert(apiVersionVo);
140-
141-
142-
143+
addApprovalToDB(apiService,apiVersionVo.getId(),apiVersionVo.getAuthId());
143144
// insert linkis_oneservice_params
144145
List<ParamVo> params = apiService.getParams();
145146
if (params != null && !params.isEmpty()) {
@@ -200,7 +201,7 @@ public void saveByApp(ApiServiceVo apiService) throws Exception {
200201
//顺序不能改变,版本信息依赖审批单信息
201202
apiServiceVersionDao.insert(apiVersionVo);
202203

203-
// addApprovalToDB(apiService,apiVersionVo.getId(),apiVersionVo.getAuthId());
204+
addApprovalToDB(apiService,apiVersionVo.getId(),apiVersionVo.getAuthId());
204205

205206
// insert linkis_oneservice_params
206207
List<ParamVo> params = apiService.getParams();
@@ -285,7 +286,7 @@ public void update(ApiServiceVo apiService) throws Exception {
285286
}
286287
}
287288

288-
// addApprovalToDB(apiService, apiServiceVersionVo.getId(), apiServiceVersionVo.getAuthId());
289+
addApprovalToDB(apiService, apiServiceVersionVo.getId(), apiServiceVersionVo.getAuthId());
289290

290291
//insert a token record for self
291292
genTokenForPublisher(apiService, apiServiceVersionVo.getId());
@@ -305,6 +306,26 @@ public void update(ApiServiceVo apiService) throws Exception {
305306
}
306307
}
307308

309+
public void addApprovalToDB(ApiServiceVo apiService, Long apiVersionId, String approvalNumber) {
310+
311+
ApprovalVo approvalVo = apiService.getApprovalVo();
312+
// 需要插入审批单记录
313+
approvalVo.setApiId(apiService.getId() != null ? apiService.getId() : 0);
314+
approvalVo.setApiVersionId(apiVersionId != null ? apiVersionId : 0);
315+
approvalVo.setApprovalNo(approvalNumber != null ? approvalNumber : "");
316+
approvalVo.setCreator(apiService.getCreator() != null ? apiService.getCreator() : "");
317+
approvalVo.setStatus(3);
318+
approvalVo.setCreateTime(new Date());
319+
approvalVo.setUpdateTime(new Date());
320+
if (StringUtils.isEmpty(approvalVo.getExecuteUser())) {
321+
approvalVo.setExecuteUser(approvalVo.getCreator());
322+
}
323+
if (approvalVo.getApprovalName() == null) {
324+
approvalVo.setApprovalName("");
325+
}
326+
apiServiceApprovalDao.insert(approvalVo);
327+
}
328+
308329
@Override
309330
public List<ApiServiceVo> query(ApiServiceQuery apiServiceQuery) throws ApiServiceQueryException {
310331
//todo 查询需要优化,量小时不影响效率
@@ -348,6 +369,11 @@ public List<ApiServiceVo> query(ApiServiceQuery apiServiceQuery) throws ApiServi
348369
@Override
349370
public List<ApiServiceVo> queryByWorkspaceId(Integer workspaceId, String userName){
350371
List<ApiServiceVo> result = apiServiceDao.queryByWorkspaceId(workspaceId,userName);
372+
result.stream().forEach(apiServiceVo -> {
373+
ApiVersionVo apiVersionVo = getMaxVersion(apiServiceVo.getId());
374+
ApprovalVo approvalVo =apiServiceApprovalDao.queryByVersionId(apiVersionVo.getId());
375+
apiServiceVo.setApprovalVo(approvalVo);
376+
});
351377
return result;
352378
}
353379

0 commit comments

Comments
 (0)