@Test public void getUntaggedTargetTypeIssuesTest() throws Exception { String response = "{\"count\":239,\"_shards\":{\"total\":176,\"successful\":176,\"skipped\":0,\"failed\":0}}"; mockStatic(PacHttpUtils.class); when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(response); ReflectionTestUtils.setField(taggingRepositoryImpl, "esUrl", "dummyEsURL"); UntaggedTargetTypeRequest request = new UntaggedTargetTypeRequest(); request.setAg("aws-all"); List<String> tagList = new ArrayList<>(); tagList.add("tag1"); tagList.add("tag2"); assertThat(taggingRepositoryImpl.getUntaggedTargetTypeIssues(request, tagList), is(notNullValue())); tagList = new ArrayList<>(); assertThat(taggingRepositoryImpl.getUntaggedTargetTypeIssues(request, tagList), is(notNullValue())); when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenThrow(new DataException()); List<String> tagListfinal = new ArrayList<>(); assertThatThrownBy(() -> taggingRepositoryImpl.getUntaggedTargetTypeIssues(request, tagListfinal)) .isInstanceOf(DataException.class); }
public String getUntaggedTargetTypeIssues( UntaggedTargetTypeRequest request, List<String> tagsList) throws DataException { String assetGroup = request.getAg(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append(assetGroup).append("/").append(SEARCH); StringBuilder requestBody = null; String body = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"type.keyword\":{\"value\":\"issue\"}}},{\"term\":{\"policyId.keyword\":{\"value\":\"" + TAGGIG_POLICY + "\"}}},{\"term\":{\"issueStatus.keyword\":{\"value\":\"open\"}}}]"; if (!tagsList.isEmpty()) { body = body + ",\"should\":["; for (String tag : tagsList) { body = body + "{\"match_phrase_prefix\":{\"missingTags\":\"" + tag + "\"}},"; } body = body.substring(0, body.length() - 1); body = body + "]"; body = body + ",\"minimum_should_match\":1"; } body = body + "}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"targetType.keyword\",\"size\":1000}}}}"; requestBody = new StringBuilder(body); try{ return PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch (Exception e) { logger.error(e.getMessage()); throw new DataException(e); } }
TaggingRepositoryImpl implements TaggingRepository, Constants { public String getUntaggedTargetTypeIssues( UntaggedTargetTypeRequest request, List<String> tagsList) throws DataException { String assetGroup = request.getAg(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append(assetGroup).append("/").append(SEARCH); StringBuilder requestBody = null; String body = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"type.keyword\":{\"value\":\"issue\"}}},{\"term\":{\"policyId.keyword\":{\"value\":\"" + TAGGIG_POLICY + "\"}}},{\"term\":{\"issueStatus.keyword\":{\"value\":\"open\"}}}]"; if (!tagsList.isEmpty()) { body = body + ",\"should\":["; for (String tag : tagsList) { body = body + "{\"match_phrase_prefix\":{\"missingTags\":\"" + tag + "\"}},"; } body = body.substring(0, body.length() - 1); body = body + "]"; body = body + ",\"minimum_should_match\":1"; } body = body + "}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"targetType.keyword\",\"size\":1000}}}}"; requestBody = new StringBuilder(body); try{ return PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch (Exception e) { logger.error(e.getMessage()); throw new DataException(e); } } }
TaggingRepositoryImpl implements TaggingRepository, Constants { public String getUntaggedTargetTypeIssues( UntaggedTargetTypeRequest request, List<String> tagsList) throws DataException { String assetGroup = request.getAg(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append(assetGroup).append("/").append(SEARCH); StringBuilder requestBody = null; String body = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"type.keyword\":{\"value\":\"issue\"}}},{\"term\":{\"policyId.keyword\":{\"value\":\"" + TAGGIG_POLICY + "\"}}},{\"term\":{\"issueStatus.keyword\":{\"value\":\"open\"}}}]"; if (!tagsList.isEmpty()) { body = body + ",\"should\":["; for (String tag : tagsList) { body = body + "{\"match_phrase_prefix\":{\"missingTags\":\"" + tag + "\"}},"; } body = body.substring(0, body.length() - 1); body = body + "]"; body = body + ",\"minimum_should_match\":1"; } body = body + "}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"targetType.keyword\",\"size\":1000}}}}"; requestBody = new StringBuilder(body); try{ return PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch (Exception e) { logger.error(e.getMessage()); throw new DataException(e); } }  }
TaggingRepositoryImpl implements TaggingRepository, Constants { public String getUntaggedTargetTypeIssues( UntaggedTargetTypeRequest request, List<String> tagsList) throws DataException { String assetGroup = request.getAg(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append(assetGroup).append("/").append(SEARCH); StringBuilder requestBody = null; String body = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"type.keyword\":{\"value\":\"issue\"}}},{\"term\":{\"policyId.keyword\":{\"value\":\"" + TAGGIG_POLICY + "\"}}},{\"term\":{\"issueStatus.keyword\":{\"value\":\"open\"}}}]"; if (!tagsList.isEmpty()) { body = body + ",\"should\":["; for (String tag : tagsList) { body = body + "{\"match_phrase_prefix\":{\"missingTags\":\"" + tag + "\"}},"; } body = body.substring(0, body.length() - 1); body = body + "]"; body = body + ",\"minimum_should_match\":1"; } body = body + "}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"targetType.keyword\",\"size\":1000}}}}"; requestBody = new StringBuilder(body); try{ return PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch (Exception e) { logger.error(e.getMessage()); throw new DataException(e); } }  JsonArray getUntaggedIssuesByapplicationFromES(String assetGroup,
            String mandatoryTags, String searchText, int from, int size); List<Map<String, Object>> getRuleParamsFromDbByPolicyId(
            String policyId); Long getUntaggedIssues(String assetGroup, String mandatoryTag); List<Map<String, Object>> getRuleTargetTypesFromDbByPolicyId(
            String policyId); String getUntaggedTargetTypeIssues(
            UntaggedTargetTypeRequest request, List<String> tagsList); @Override String getTaggingByApplication(String ag, String targetType); }
TaggingRepositoryImpl implements TaggingRepository, Constants { public String getUntaggedTargetTypeIssues( UntaggedTargetTypeRequest request, List<String> tagsList) throws DataException { String assetGroup = request.getAg(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append(assetGroup).append("/").append(SEARCH); StringBuilder requestBody = null; String body = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"type.keyword\":{\"value\":\"issue\"}}},{\"term\":{\"policyId.keyword\":{\"value\":\"" + TAGGIG_POLICY + "\"}}},{\"term\":{\"issueStatus.keyword\":{\"value\":\"open\"}}}]"; if (!tagsList.isEmpty()) { body = body + ",\"should\":["; for (String tag : tagsList) { body = body + "{\"match_phrase_prefix\":{\"missingTags\":\"" + tag + "\"}},"; } body = body.substring(0, body.length() - 1); body = body + "]"; body = body + ",\"minimum_should_match\":1"; } body = body + "}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"targetType.keyword\",\"size\":1000}}}}"; requestBody = new StringBuilder(body); try{ return PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch (Exception e) { logger.error(e.getMessage()); throw new DataException(e); } }  JsonArray getUntaggedIssuesByapplicationFromES(String assetGroup,
            String mandatoryTags, String searchText, int from, int size); List<Map<String, Object>> getRuleParamsFromDbByPolicyId(
            String policyId); Long getUntaggedIssues(String assetGroup, String mandatoryTag); List<Map<String, Object>> getRuleTargetTypesFromDbByPolicyId(
            String policyId); String getUntaggedTargetTypeIssues(
            UntaggedTargetTypeRequest request, List<String> tagsList); @Override String getTaggingByApplication(String ag, String targetType);  }