diff --git a/src/main/java/com/datastat/controller/QueryController.java b/src/main/java/com/datastat/controller/QueryController.java index aa9a61a..b951ac4 100644 --- a/src/main/java/com/datastat/controller/QueryController.java +++ b/src/main/java/com/datastat/controller/QueryController.java @@ -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; @@ -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 { diff --git a/src/main/java/com/datastat/dao/QueryDao.java b/src/main/java/com/datastat/dao/QueryDao.java index baebf3d..faa36d6 100644 --- a/src/main/java/com/datastat/dao/QueryDao.java +++ b/src/main/java/com/datastat/dao/QueryDao.java @@ -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; @@ -3708,6 +3709,44 @@ public String putGlobalNpsIssue(CustomPropertiesConfig queryConf, String token, } } + public String putSearchOpeUbmcIssue(CustomPropertiesConfig queryConf, String token, String community, OpenUbmcSearchNps body) { + HashMap resMap = objectMapper.convertValue(body, new TypeReference>() { + }); + 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(); diff --git a/src/main/java/com/datastat/dao/UserIdDao.java b/src/main/java/com/datastat/dao/UserIdDao.java index c271233..9a10648 100644 --- a/src/main/java/com/datastat/dao/UserIdDao.java +++ b/src/main/java/com/datastat/dao/UserIdDao.java @@ -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; + } } diff --git a/src/main/java/com/datastat/model/CustomPropertiesConfig.java b/src/main/java/com/datastat/model/CustomPropertiesConfig.java index c51aeb4..ba07ac8 100644 --- a/src/main/java/com/datastat/model/CustomPropertiesConfig.java +++ b/src/main/java/com/datastat/model/CustomPropertiesConfig.java @@ -113,6 +113,7 @@ public class CustomPropertiesConfig { private String modelEventIndex; private String datasetEventIndex; private String openmindRepoIndex; + private String openubmcSearchNpsIndex; // -- query str -- private String extOsQueryStr; diff --git a/src/main/java/com/datastat/model/OpenUbmcSearchNps.java b/src/main/java/com/datastat/model/OpenUbmcSearchNps.java new file mode 100644 index 0000000..be494bf --- /dev/null +++ b/src/main/java/com/datastat/model/OpenUbmcSearchNps.java @@ -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; + +} diff --git a/src/main/java/com/datastat/service/QueryService.java b/src/main/java/com/datastat/service/QueryService.java index 081f48d..0b2214a 100644 --- a/src/main/java/com/datastat/service/QueryService.java +++ b/src/main/java/com/datastat/service/QueryService.java @@ -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; @@ -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) {