Esempio n. 1
0
  private boolean checkSegmentDeletionImpact(Condition condition, String segmentToDeleteId) {
    if (condition != null) {
      @SuppressWarnings("unchecked")
      final List<Condition> subConditions =
          (List<Condition>) condition.getParameter("subConditions");
      if (subConditions != null) {
        for (Condition subCondition : subConditions) {
          if (checkSegmentDeletionImpact(subCondition, segmentToDeleteId)) {
            return true;
          }
        }
      } else if ("profileSegmentCondition".equals(condition.getConditionTypeId())) {
        @SuppressWarnings("unchecked")
        final List<String> referencedSegmentIds = (List<String>) condition.getParameter("segments");

        if (referencedSegmentIds.indexOf(segmentToDeleteId) >= 0) {
          return true;
        }
      }
    }
    return false;
  }
Esempio n. 2
0
 /**
  * Return an updated condition that do not contain a condition on the segmentId anymore it's
  * remove the unnecessary boolean condition (if a condition is the only one of a boolean the
  * boolean will be remove and the subcondition returned) it's return null when there is no more
  * condition after (if the condition passed was only a segment condition on the segmentId)
  *
  * @param condition the condition to update
  * @param segmentId the segment id to remove in the condition
  * @return updated condition
  */
 private Condition updateSegmentDependentCondition(Condition condition, String segmentId) {
   if ("booleanCondition".equals(condition.getConditionTypeId())) {
     @SuppressWarnings("unchecked")
     final List<Condition> subConditions =
         (List<Condition>) condition.getParameter("subConditions");
     List<Condition> updatedSubConditions = new LinkedList<>();
     for (Condition subCondition : subConditions) {
       Condition updatedCondition = updateSegmentDependentCondition(subCondition, segmentId);
       if (updatedCondition != null) {
         updatedSubConditions.add(updatedCondition);
       }
     }
     if (!updatedSubConditions.isEmpty()) {
       if (updatedSubConditions.size() == 1) {
         return updatedSubConditions.get(0);
       } else {
         condition.setParameter("subConditions", updatedSubConditions);
         return condition;
       }
     } else {
       return null;
     }
   } else if ("profileSegmentCondition".equals(condition.getConditionTypeId())) {
     @SuppressWarnings("unchecked")
     final List<String> referencedSegmentIds = (List<String>) condition.getParameter("segments");
     if (referencedSegmentIds.indexOf(segmentId) >= 0) {
       referencedSegmentIds.remove(segmentId);
       if (referencedSegmentIds.isEmpty()) {
         return null;
       } else {
         condition.setParameter("segments", referencedSegmentIds);
       }
     }
   }
   return condition;
 }