Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openubmc新增搜索反馈 #281

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/com/datastat/controller/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.datastat.model.HmsExportDataReq;
import com.datastat.model.IsvCount;
import com.datastat.model.NpsBody;
import com.datastat.model.QaBotRequestBody;
import com.datastat.model.OpenUbmcSearchNps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QaBotRequestBody 删除后是否有影响

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无影响,这个没有使用过,在vscode中被标注出来了

import com.datastat.model.SigGathering;
import com.datastat.model.TeamupApplyForm;
import com.datastat.model.dto.ContributeRequestParams;
Expand Down Expand Up @@ -766,6 +766,14 @@ public String putGlobalNpsIssue(HttpServletRequest request, @CookieValue(value =
return queryService.putGlobalNpsIssue(request, token, community, body);
}

@LimitRequest(callTime = 1, callCount = 1000)
@RateLimit
@RequestMapping(value = "/search/openubmc/issue", method = RequestMethod.POST)
public String putSearchOpeUbmcIssue(HttpServletRequest request, @CookieValue(value = "_Y_G_") String token,
@RequestParam(value = "community") String community, @Valid @RequestBody OpenUbmcSearchNps body) {
return queryService.putSearchOpeUbmcIssue(request, token, community,body);
}

@RequestMapping("/user/owner/repos")
public String queryUserOwnerRepos(HttpServletRequest request,
@RequestParam(value = "user") String user) throws Exception {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/datastat/dao/QueryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.datastat.model.CustomPropertiesConfig;
import com.datastat.model.IsvCount;
import com.datastat.model.NpsBody;
import com.datastat.model.OpenUbmcSearchNps;
import com.datastat.model.QaBotRequestBody;
import com.datastat.model.SigDetails;
import com.datastat.model.SigDetailsMaintainer;
Expand Down Expand Up @@ -3708,6 +3709,44 @@ public String putGlobalNpsIssue(CustomPropertiesConfig queryConf, String token,
}
}

public String putSearchOpeUbmcIssue(CustomPropertiesConfig queryConf, String token, String community, OpenUbmcSearchNps body) {
HashMap<String, Object> resMap = objectMapper.convertValue(body, new TypeReference<HashMap<String, Object>>() {
});
resMap.put("community", community);
if (token == null) {
logger.info("Token is not allowed null");
throw new IllegalArgumentException("Token can not be null");
}
String userId = userIdDao.getUserIdByCommunity(token, community);
if(null == userId || userId.equals("")) {
logger.info("UserId is null");
throw new IllegalArgumentException("UserId is null");
}
resMap.put("userId", userId);
try {
Date now = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
String nowStr = simpleDateFormat.format(now);
String uuid = UUID.randomUUID().toString();
resMap.put("created_at", nowStr);
BulkRequest request = new BulkRequest();
RestHighLevelClient restHighLevelClient = getRestHighLevelClient();
IndexRequest indexRequest = new IndexRequest(queryConf.getOpenubmcSearchNpsIndex());
String s = queryConf.getOpenubmcSearchNpsIndex();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未使用的变量

indexRequest.id(uuid);
indexRequest.source(resMap, XContentType.JSON);
request.add(indexRequest);
if (request.requests().size() != 0) {
restHighLevelClient.bulk(request, RequestOptions.DEFAULT);
}
restHighLevelClient.close();
return ResultUtil.resultJsonStr(200, objectMapper.valueToTree("success"), "success");
} catch (Exception e) {
logger.error("Search nps issue exception - {}", e.getMessage());
return ResultUtil.resultJsonStr(400, null, "error");
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

功能类似,可以考虑代码重用

@SneakyThrows
public String queryGlobalIssues(CustomPropertiesConfig queryConf, String userId, ContributeRequestParams params) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/datastat/dao/UserIdDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public String getUserId(String token){
}
return userId;
}

public String getUserIdByCommunity(String token, String community) {
String userId = null;
try {
RSAPrivateKey privateKey = RSAUtil.getPrivateKey(env.getProperty("rsa.authing." + community + ".privateKey"));
DecodedJWT decode = JWT.decode(RSAUtil.privateDecrypt(token, privateKey));
userId = decode.getAudience().get(0);
} catch (Exception e) {
logger.error("parse token exception - {}", e.getMessage());
}
return userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class CustomPropertiesConfig {
private String modelEventIndex;
private String datasetEventIndex;
private String openmindRepoIndex;
private String openubmcSearchNpsIndex;

// -- query str --
private String extOsQueryStr;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/datastat/model/OpenUbmcSearchNps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* This project is licensed under the Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
PURPOSE.
See the Mulan PSL v2 for more details.
Create: 2023
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

日期错误

*/

package com.datastat.model;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请添加 copy right


import com.datastat.aop.moderation.ModerationValid;

import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;

@Data
public class OpenUbmcSearchNps {

private Boolean searchFlag;

@Size(max = 100, message = "the length can not exceed 100")
@Pattern(regexp = "^[^<>%&$]*$", message = "Text format error")
@ModerationValid
private String feedbackText;

}
9 changes: 9 additions & 0 deletions src/main/java/com/datastat/service/QueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.datastat.model.HmsExportDataReq;
import com.datastat.model.IsvCount;
import com.datastat.model.NpsBody;
import com.datastat.model.OpenUbmcSearchNps;
import com.datastat.model.QaBotRequestBody;
import com.datastat.model.SigGathering;
import com.datastat.model.TeamupApplyForm;
Expand Down Expand Up @@ -1576,6 +1577,14 @@ public String putGlobalNpsIssue(HttpServletRequest request, String token, String
return queryDao.putGlobalNpsIssue(queryConf, token, community, body);
}

public String putSearchOpeUbmcIssue(HttpServletRequest request, String token, String community,
OpenUbmcSearchNps body) {
if (!checkCommunity(community)) return ResultUtil.resultJsonStr(404, "error", "not found");
QueryDao queryDao = getQueryDao(request);
CustomPropertiesConfig queryConf = getQueryConf(request);
return queryDao.putSearchOpeUbmcIssue(queryConf, token, community, body);
}

public String queryGolbalIssues(HttpServletRequest request,String token, ContributeRequestParams params) throws Exception {
if (!checkCommunity(params.getCommunity())) return ResultUtil.resultJsonStr(404, "error", "not found");
if (token == null) {
Expand Down
Loading