Exemplo n.º 1
0
 /**
  * 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);
   }
 }
Exemplo n.º 2
0
  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);
            }
          }
        }
      }
    }
  }
Exemplo n.º 3
0
 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());
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * Retrieves the metadata for all known rules.
  *
  * @return the Set of known metadata
  */
 @GET
 @Path("/")
 public Set<Metadata> getRuleMetadatas() {
   return rulesService.getRuleMetadatas();
 }
Exemplo n.º 8
0
 /**
  * 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);
 }