/** * TODO: remove * * @deprecated not needed anymore */ @GET @Path("/resetQueries") public void resetQueries() { for (Metadata metadata : rulesService.getRuleMetadatas()) { Rule r = rulesService.getRule(metadata.getId()); rulesService.setRule(r); } }
private void getAutoGeneratedRules( Metadata metadata, Condition condition, Condition parentCondition, List<Rule> rules) { Set<String> tags = condition.getConditionType().getMetadata().getTags(); if (tags.contains("eventCondition") && !tags.contains("profileCondition")) { try { Map<String, Object> m = new HashMap<>(3); m.put("scope", metadata.getScope()); m.put("condition", condition); m.put("numberOfDays", parentCondition.getParameter("numberOfDays")); String key = CustomObjectMapper.getObjectMapper().writeValueAsString(m); key = "eventTriggered" + getMD5(key); parentCondition.setParameter("generatedPropertyKey", key); Rule rule = rulesService.getRule(key); if (rule == null) { rule = new Rule( new Metadata( metadata.getScope(), key, "Auto generated rule for " + metadata.getName(), "")); rule.setCondition(condition); rule.getMetadata().setHidden(true); final Action action = new Action(); action.setActionType(definitionsService.getActionType("setEventOccurenceCountAction")); action.setParameter("pastEventCondition", parentCondition); rule.setActions(Arrays.asList(action)); rule.setLinkedItems(Arrays.asList(metadata.getId())); rules.add(rule); updateExistingProfilesForPastEventCondition(condition, parentCondition); } else { rule.getLinkedItems().add(metadata.getId()); rules.add(rule); } } catch (JsonProcessingException e) { logger.error(e.getMessage(), e); } } else { Collection<Object> values = new ArrayList<>(condition.getParameterValues().values()); for (Object parameterValue : values) { if (parameterValue instanceof Condition) { getAutoGeneratedRules(metadata, (Condition) parameterValue, condition, rules); } else if (parameterValue instanceof Collection) { for (Object subCondition : (Collection<?>) parameterValue) { if (subCondition instanceof Condition) { getAutoGeneratedRules(metadata, (Condition) subCondition, condition, rules); } } } } } }
/** * Retrieves the rule identified by the specified identifier. * * @param ruleId the identifier of the rule we want to retrieve * @return the rule identified by the specified identifier or {@code null} if no such rule exists. */ @GET @Path("/{ruleId}") public Rule getRule(@PathParam("ruleId") String ruleId) { return rulesService.getRule(ruleId); }