Skip to content

Commit

Permalink
openubmc新增搜索反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
2511689622 committed Dec 11, 2024
1 parent 107c85a commit 559265a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
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;
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();
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");
}
}

@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
19 changes: 19 additions & 0 deletions src/main/java/com/datastat/model/OpenUbmcSearchNps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.datastat.model;

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

0 comments on commit 559265a

Please sign in to comment.