Skip to content

Commit

Permalink
Merge pull request #290 from opensourceways/develop_test
Browse files Browse the repository at this point in the history
社区增加搜索意见反馈
  • Loading branch information
zhongjun2 authored Dec 18, 2024
2 parents f08f8c9 + 0f80518 commit 5a99eb7
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
17 changes: 16 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.SearchIssueBody;
import com.datastat.model.SigGathering;
import com.datastat.model.TeamupApplyForm;
import com.datastat.model.dto.ContributeRequestParams;
Expand Down Expand Up @@ -766,6 +766,21 @@ public String putGlobalNpsIssue(HttpServletRequest request, @CookieValue(value =
return queryService.putGlobalNpsIssue(request, token, community, body);
}

/**
* submit search issue based on the searchIssue body.
*
* @param request HttpServletRequest request.
* @param token ueser token.
* @param body issue body.
* @return Response string.
*/
@LimitRequest(callTime = 1, callCount = 1000)
@RequestMapping(value = "/search/issue", method = RequestMethod.POST)
public String putSearchNpsByCommunity(HttpServletRequest request, @CookieValue(value = "_Y_G_", required = false) String token,
@RequestParam(value = "community") String community, @Valid @RequestBody SearchIssueBody body) {
return queryService.putSearchNpsByCommunity(request, token, community,body);
}

@RequestMapping("/user/owner/repos")
public String queryUserOwnerRepos(HttpServletRequest request,
@RequestParam(value = "user") String user) throws Exception {
Expand Down
40 changes: 39 additions & 1 deletion 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.SearchIssueBody;
import com.datastat.model.QaBotRequestBody;
import com.datastat.model.SigDetails;
import com.datastat.model.SigDetailsMaintainer;
Expand Down Expand Up @@ -96,7 +97,6 @@
import java.net.InetAddress;
import java.net.URL;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey;

@Primary
@Repository(value = "queryDao")
Expand Down Expand Up @@ -3711,6 +3711,44 @@ public String putGlobalNpsIssue(CustomPropertiesConfig queryConf, String token,
}
}

public String putSearchNpsByCommunity(CustomPropertiesConfig queryConf, String token, String community, SearchIssueBody body) {
HashMap<String, Object> resMap = objectMapper.convertValue(body, new TypeReference<HashMap<String, Object>>() {
});
resMap.put("community", community);
String userId = "";
if (token != null && !"mindspore".equals(community)) {
userId = userIdDao.getUserIdByCommunity(token, community);
if (null == userId || userId.equals("")) {
logger.warn("UserId parse error for token:" + token + ",community:" + community);
throw new IllegalArgumentException("UserId parse error");
}
} else {
userId = "anonymous";
}
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.getSearchNpsIndex());
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 searchNpsIndex;

// -- query str --
private String extOsQueryStr;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/datastat/model/SearchIssueBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 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: 2024
*/

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 SearchIssueBody {

private Boolean searchFlag;

private String keyword;

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

}
8 changes: 8 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.SearchIssueBody;
import com.datastat.model.QaBotRequestBody;
import com.datastat.model.SigGathering;
import com.datastat.model.TeamupApplyForm;
Expand Down Expand Up @@ -1576,6 +1577,13 @@ public String putGlobalNpsIssue(HttpServletRequest request, String token, String
return queryDao.putGlobalNpsIssue(queryConf, token, community, body);
}

public String putSearchNpsByCommunity(HttpServletRequest request, String token, String community, SearchIssueBody body) {
if (!checkCommunity(community)) return ResultUtil.resultJsonStr(404, "error", "not found");
QueryDao queryDao = getQueryDao(request);
CustomPropertiesConfig queryConf = getQueryConf(request);
return queryDao.putSearchNpsByCommunity(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 5a99eb7

Please sign in to comment.