/**
  * 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);
            }
          }
        }
      }
    }
  }
 public void updateAutoGeneratedRules(Metadata metadata, Condition condition) {
   List<Rule> previousRules =
       persistenceService.query("linkedItems", metadata.getId(), null, Rule.class);
   List<Rule> rules = new ArrayList<Rule>();
   if (condition != null) {
     getAutoGeneratedRules(metadata, condition, null, rules);
   }
   for (Rule rule : rules) {
     rulesService.setRule(rule);
   }
   previousRules.removeAll(rules);
   clearAutoGeneratedRules(previousRules, metadata.getId());
 }
 /**
  * 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);
 }
 /**
  * Retrieves rule metadatas for rules matching the specified {@link Query}.
  *
  * @param query the query the rules which metadata we want to retrieve must match
  * @return a {@link PartialList} of rules metadata for the rules matching the specified query
  */
 @POST
 @Path("/query")
 public PartialList<Metadata> getRuleMetadatas(Query query) {
   return rulesService.getRuleMetadatas(query);
 }
 /**
  * Persists the specified rule to the context server.
  *
  * @param rule the rule to be persisted
  */
 @POST
 @Path("/")
 public void setRule(Rule rule) {
   rulesService.setRule(rule);
 }
 /**
  * Retrieves the metadata for all known rules.
  *
  * @return the Set of known metadata
  */
 @GET
 @Path("/")
 public Set<Metadata> getRuleMetadatas() {
   return rulesService.getRuleMetadatas();
 }
 /**
  * Deletes the rule identified by the specified identifier.
  *
  * @param ruleId the identifier of the rule we want to delete
  */
 @DELETE
 @Path("/{ruleId}")
 public void removeRule(@PathParam("ruleId") String ruleId) {
   rulesService.removeRule(ruleId);
 }