Beispiel #1
0
  @Override
  public void removeSubscriber(User user, Test test) {
    Test freshTest = testDAO.get(test.getId());

    Collection<User> testSubscribers = new ArrayList<>(freshTest.getSubscribers());
    for (User testSubscriber : freshTest.getSubscribers()) {
      if (testSubscriber.getId().equals(user.getId())) {
        testSubscribers.remove(testSubscriber);
      }
    }

    test.setSubscribers(testSubscribers);
    testDAO.update(test);
  }
Beispiel #2
0
  @Override
  public Test getFullTest(Long id) {
    Test test = testDAO.get(id);
    if (test == null) {
      return null;
    }
    test = test.clone();
    // TODO: return by named query, with optimized fetching
    Collection<Metric> metrics = test.getMetrics();
    if (metrics != null) {
      List<Metric> clonedMetrics = new ArrayList<Metric>();
      for (Metric metric : metrics) {
        clonedMetrics.add(metric);
      }
      test.setMetrics(clonedMetrics);
    }

    Collection<User> subscribers = test.getSubscribers();
    if (subscribers != null) {
      List<User> subscribersClone = new ArrayList<>();
      for (User subscriber : subscribers) {
        subscribersClone.add(subscriber.clone());
      }
      test.setSubscribers(subscribersClone);
    }

    Collection<Alert> alerts = test.getAlerts();
    if (alerts != null) {
      List<Alert> alertsClone = new ArrayList<>();
      for (Alert alert : alerts) {
        List<Tag> tagsClone = new ArrayList<>();
        for (Tag tag : alert.getTags()) {
          tagsClone.add(tag.clone());
        }
        Alert alertClone = alert.clone();
        alertClone.setTags(tagsClone);
        alertsClone.add(alertClone);
      }
      test.setAlerts(alertsClone);
    }

    return test;
  }