IspnDefinitionsServiceImpl implements DefinitionsService { @Override public Page<Trigger> getTriggers(String tenantId, TriggersCriteria criteria, Pager pager) throws Exception { if (isEmpty(tenantId)) { throw new IllegalArgumentException("TenantId must be not null"); } boolean filter = (null != criteria && criteria.hasCriteria()); if (filter) { log.debugf("getTriggers criteria: %s", criteria); } List<IspnTrigger> triggers; if (filter) { StringBuilder query = new StringBuilder( "from org.hawkular.alerts.engine.impl.ispn.model.IspnTrigger where "); query.append("tenantId = '").append(tenantId).append("' and "); if (criteria.hasTriggerIdCriteria()) { Set<String> triggerIds = filterByTriggers(criteria); query.append("("); Iterator<String> iter = triggerIds.iterator(); while (iter.hasNext()) { String triggerId = iter.next(); query.append("triggerId = '").append(triggerId).append("' "); if (iter.hasNext()) { query.append("or "); } } query.append(") "); if (criteria.hasTagCriteria()) { query.append("and "); } } if (criteria.hasTagCriteria()) { Map<String, String> tags = criteria.getTags(); query.append("("); Iterator<Map.Entry<String, String>> iter = tags.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> tag = iter.next(); query.append("tags like '") .append(tag.getKey()) .append(TagsBridge.VALUE) .append(tag.getValue().equals("*") ? "%" : tag.getValue()) .append("' "); if (iter.hasNext()) { query.append("or "); } } query.append(") "); } triggers = queryFactory.create(query.toString()).list(); } else { triggers = queryFactory.from(IspnTrigger.class) .having("tenantId") .eq(tenantId) .build() .list(); } return prepareTriggersPage(triggers.stream().map(t -> t.getTrigger()).collect(Collectors.toList()), pager); }  void init(); void setAlertsEngine(AlertsEngine alertsEngine); void setAlertsContext(AlertsContext alertsContext); void setProperties(PropertiesService properties); @Override void addActionDefinition(String tenantId, ActionDefinition actionDefinition); @Override void addTrigger(String tenantId, Trigger trigger); @Override void addGroupTrigger(String tenantId, Trigger groupTrigger); @Override Trigger addMemberTrigger(String tenantId, String groupId, String memberId, String memberName,
            String memberDescription, Map<String, String> memberContext, Map<String, String> memberTags,
            Map<String, String> dataIdMap); @Override Trigger addDataDrivenMemberTrigger(String tenantId, String groupId, String source); @Override void removeTrigger(String tenantId, String triggerId); @Override void removeGroupTrigger(String tenantId, String groupId, boolean keepNonOrphans, boolean keepOrphans); @Override void updateFullTrigger(String tenantId, FullTrigger fullTrigger); @Override Trigger updateTrigger(String tenantId, Trigger trigger); @Override Trigger updateGroupTrigger(String tenantId, Trigger groupTrigger); @Override void updateGroupTriggerEnablement(String tenantId, String groupTriggerIds, boolean enabled); @Override void updateTriggerEnablement(String tenantId, String triggerIds, boolean enabled); @Override Trigger getTrigger(String tenantId, String triggerId); @Override Page<Trigger> getTriggers(String tenantId, TriggersCriteria criteria, Pager pager); @Override Collection<Trigger> getMemberTriggers(String tenantId, String groupId, boolean includeOrphans); @Override Collection<Trigger> getAllTriggers(); @Override Collection<Trigger> getAllTriggersByTag(String name, String value); @Override Trigger orphanMemberTrigger(String tenantId, String memberId); @Override Trigger unorphanMemberTrigger(String tenantId, String memberId, Map<String, String> memberContext,
            Map<String, String> memberTags, Map<String, String> dataIdMap); @Override Dampening addDampening(String tenantId, Dampening dampening); @Override Dampening addGroupDampening(String tenantId, Dampening groupDampening); @Override void removeDampening(String tenantId, String dampeningId); @Override void removeGroupDampening(String tenantId, String groupDampeningId); @Override Dampening updateDampening(String tenantId, Dampening dampening); @Override Dampening updateGroupDampening(String tenantId, Dampening groupDampening); @Override Dampening getDampening(String tenantId, String dampeningId); @Override Collection<Dampening> getAllDampenings(); @Override Collection<Dampening> getDampenings(String tenantId); @Override Collection<Dampening> getTriggerDampenings(String tenantId, String triggerId, Mode triggerMode); @Override Collection<Condition> setConditions(String tenantId, String triggerId, Mode triggerMode,
            Collection<Condition> conditions); @Override Collection<Condition> setAllConditions(String tenantId, String triggerId,
            Collection<Condition> conditions); @Override Collection<Condition> setGroupConditions(String tenantId, String groupId, Mode triggerMode,
            Collection<Condition> groupConditions, Map<String, Map<String, String>> dataIdMemberMap); @Override Collection<Condition> getAllConditions(); @Override Collection<Condition> getConditions(String tenantId); @Override Collection<Condition> getTriggerConditions(String tenantId, String triggerId, Mode triggerMode); @Override void addActionPlugin(String actionPlugin, Set<String> properties); @Override void addActionPlugin(String actionPlugin, Map<String, String> defaultProperties); @Override void removeActionPlugin(String actionPlugin); @Override void updateActionPlugin(String actionPlugin, Set<String> properties); @Override void updateActionPlugin(String actionPlugin, Map<String, String> defaultProperties); @Override Collection<String> getActionPlugins(); @Override Set<String> getActionPlugin(String actionPlugin); @Override Map<String, String> getDefaultActionPlugin(String actionPlugin); @Override void removeActionDefinition(String tenantId, String actionPlugin, String actionId); @Override void updateActionDefinition(String tenantId, ActionDefinition actionDefinition); @Override Map<String, Map<String, Set<String>>> getAllActionDefinitionIds(); @Override Collection<ActionDefinition> getAllActionDefinitions(); @Override Map<String, Set<String>> getActionDefinitionIds(String tenantId); @Override Collection<String> getActionDefinitionIds(String tenantId, String actionPlugin); @Override ActionDefinition getActionDefinition(String tenantId, String actionPlugin, String actionId); @Override void registerListener(DefinitionsListener listener, DefinitionsEvent.Type eventType,
            DefinitionsEvent.Type... eventTypes); @Override void registerDistributedListener(DistributedListener listener); @Override Definitions exportDefinitions(String tenantId); @Override Definitions importDefinitions(String tenantId, Definitions definitions, ImportType strategy); @Override void createFullTrigger(String tenantId, FullTrigger fullTrigger); @Override FullTrigger getFullTrigger(String tenantId, String triggerId);  }
@Test public void getTriggers() throws Exception { int numTenants = 4; int numTriggers = 10; createTestTriggers(numTenants, numTriggers); assertEquals(4 * 10, definitions.getAllTriggers().size()); assertEquals(4 * 10 / 2, definitions.getAllTriggersByTag("tag0", "*").size()); assertEquals(4 * 10 / 4, definitions.getAllTriggersByTag("tag0", "value0").size()); assertEquals(10, definitions.getTriggers("tenant0", null, null).size()); assertEquals(10, definitions.getTriggers("tenant3", null, null).size()); TriggersCriteria criteria = new TriggersCriteria(); criteria.setTriggerId("trigger0"); assertEquals(1, definitions.getTriggers("tenant0", criteria, null).size()); criteria.setTriggerId(null); criteria.setTriggerIds(Arrays.asList("trigger0", "trigger1", "trigger2", "trigger3")); assertEquals(4, definitions.getTriggers("tenant0", criteria, null).size()); criteria.setTriggerIds(null); Map<String, String> tags = new HashMap<>(); tags.put("tag0", "*"); criteria.setTags(tags); assertEquals(5, definitions.getTriggers("tenant0", criteria, null).size()); criteria.getTags().put("tag0", "value0"); criteria.getTags().put("tag1", "value1"); assertEquals(6, definitions.getTriggers("tenant0", criteria, null).size()); deleteTestTriggers(numTenants, numTriggers); }