@Test public void testGetStickyExceptions() throws Exception{ PowerMockito.mockStatic(ESUtils.class); PowerMockito.when(ESUtils.getEsUrl()).thenReturn(""); try { PowerMockito.when(ESUtils.getDataFromES(anyString(), anyString(), anyString(), anyMap(), anyMap(), any(HashMultimap.class), anyList(), anyLong(), anyLong())).thenReturn(new ArrayList()); } catch (Exception e) { } exManager.getStickyExceptions("r1", "ec2"); }
@Override public Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType) throws Exception { Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(RULE_ID_ATTRIBUTE_NAME, ruleId); mustFilter.put(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceType); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("expiryDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), INDEX_FOR_EXCEPTIONS, TYPE_FOR_STICKY_EXCEPTIONS, mustFilter, null, null, null, 0, 20); List<IssueException> stickyExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.STICKY)).collect(Collectors.toList()); mustFilter.clear(); mustFilter.put("latest", true); Map<IssueException, List<String>> exemptedResources = new HashMap<>(); Map<String, List<IssueException>> exceptionResourceSetMap = new HashMap<>(); stickyExceptions.forEach(obj -> { try { exemptedResources.put(obj, ESUtils.getDataFromES(ESUtils.getEsUrl(), obj.getAssetGroup(), resourceType, mustFilter, null, null, null, 0, 20).stream().map(resource -> resource.get(RESOURCE_ID)) .collect(Collectors.toList())); } catch (Exception e) { } }); exemptedResources.entrySet().forEach(entry -> { entry.getValue().forEach(resourceid -> { List<IssueException> exceptionsList = exceptionResourceSetMap.get(resourceid); if (exceptionsList == null) { exceptionsList = new ArrayList<>(); exceptionResourceSetMap.put(resourceid, exceptionsList); } exceptionsList.add(entry.getKey()); }); }); return exceptionResourceSetMap; }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType) throws Exception { Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(RULE_ID_ATTRIBUTE_NAME, ruleId); mustFilter.put(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceType); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("expiryDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), INDEX_FOR_EXCEPTIONS, TYPE_FOR_STICKY_EXCEPTIONS, mustFilter, null, null, null, 0, 20); List<IssueException> stickyExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.STICKY)).collect(Collectors.toList()); mustFilter.clear(); mustFilter.put("latest", true); Map<IssueException, List<String>> exemptedResources = new HashMap<>(); Map<String, List<IssueException>> exceptionResourceSetMap = new HashMap<>(); stickyExceptions.forEach(obj -> { try { exemptedResources.put(obj, ESUtils.getDataFromES(ESUtils.getEsUrl(), obj.getAssetGroup(), resourceType, mustFilter, null, null, null, 0, 20).stream().map(resource -> resource.get(RESOURCE_ID)) .collect(Collectors.toList())); } catch (Exception e) { } }); exemptedResources.entrySet().forEach(entry -> { entry.getValue().forEach(resourceid -> { List<IssueException> exceptionsList = exceptionResourceSetMap.get(resourceid); if (exceptionsList == null) { exceptionsList = new ArrayList<>(); exceptionResourceSetMap.put(resourceid, exceptionsList); } exceptionsList.add(entry.getKey()); }); }); return exceptionResourceSetMap; } }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType) throws Exception { Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(RULE_ID_ATTRIBUTE_NAME, ruleId); mustFilter.put(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceType); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("expiryDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), INDEX_FOR_EXCEPTIONS, TYPE_FOR_STICKY_EXCEPTIONS, mustFilter, null, null, null, 0, 20); List<IssueException> stickyExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.STICKY)).collect(Collectors.toList()); mustFilter.clear(); mustFilter.put("latest", true); Map<IssueException, List<String>> exemptedResources = new HashMap<>(); Map<String, List<IssueException>> exceptionResourceSetMap = new HashMap<>(); stickyExceptions.forEach(obj -> { try { exemptedResources.put(obj, ESUtils.getDataFromES(ESUtils.getEsUrl(), obj.getAssetGroup(), resourceType, mustFilter, null, null, null, 0, 20).stream().map(resource -> resource.get(RESOURCE_ID)) .collect(Collectors.toList())); } catch (Exception e) { } }); exemptedResources.entrySet().forEach(entry -> { entry.getValue().forEach(resourceid -> { List<IssueException> exceptionsList = exceptionResourceSetMap.get(resourceid); if (exceptionsList == null) { exceptionsList = new ArrayList<>(); exceptionResourceSetMap.put(resourceid, exceptionsList); } exceptionsList.add(entry.getKey()); }); }); return exceptionResourceSetMap; }  }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType) throws Exception { Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(RULE_ID_ATTRIBUTE_NAME, ruleId); mustFilter.put(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceType); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("expiryDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), INDEX_FOR_EXCEPTIONS, TYPE_FOR_STICKY_EXCEPTIONS, mustFilter, null, null, null, 0, 20); List<IssueException> stickyExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.STICKY)).collect(Collectors.toList()); mustFilter.clear(); mustFilter.put("latest", true); Map<IssueException, List<String>> exemptedResources = new HashMap<>(); Map<String, List<IssueException>> exceptionResourceSetMap = new HashMap<>(); stickyExceptions.forEach(obj -> { try { exemptedResources.put(obj, ESUtils.getDataFromES(ESUtils.getEsUrl(), obj.getAssetGroup(), resourceType, mustFilter, null, null, null, 0, 20).stream().map(resource -> resource.get(RESOURCE_ID)) .collect(Collectors.toList())); } catch (Exception e) { } }); exemptedResources.entrySet().forEach(entry -> { entry.getValue().forEach(resourceid -> { List<IssueException> exceptionsList = exceptionResourceSetMap.get(resourceid); if (exceptionsList == null) { exceptionsList = new ArrayList<>(); exceptionResourceSetMap.put(resourceid, exceptionsList); } exceptionsList.add(entry.getKey()); }); }); return exceptionResourceSetMap; }  @Override Map<String, IssueException> getIndividualExceptions(String resourceType); @Override Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType); }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType) throws Exception { Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(RULE_ID_ATTRIBUTE_NAME, ruleId); mustFilter.put(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceType); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("expiryDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), INDEX_FOR_EXCEPTIONS, TYPE_FOR_STICKY_EXCEPTIONS, mustFilter, null, null, null, 0, 20); List<IssueException> stickyExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.STICKY)).collect(Collectors.toList()); mustFilter.clear(); mustFilter.put("latest", true); Map<IssueException, List<String>> exemptedResources = new HashMap<>(); Map<String, List<IssueException>> exceptionResourceSetMap = new HashMap<>(); stickyExceptions.forEach(obj -> { try { exemptedResources.put(obj, ESUtils.getDataFromES(ESUtils.getEsUrl(), obj.getAssetGroup(), resourceType, mustFilter, null, null, null, 0, 20).stream().map(resource -> resource.get(RESOURCE_ID)) .collect(Collectors.toList())); } catch (Exception e) { } }); exemptedResources.entrySet().forEach(entry -> { entry.getValue().forEach(resourceid -> { List<IssueException> exceptionsList = exceptionResourceSetMap.get(resourceid); if (exceptionsList == null) { exceptionsList = new ArrayList<>(); exceptionResourceSetMap.put(resourceid, exceptionsList); } exceptionsList.add(entry.getKey()); }); }); return exceptionResourceSetMap; }  @Override Map<String, IssueException> getIndividualExceptions(String resourceType); @Override Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType);  }