Example #1
0
 public Cart getSpecificCart(int index) {
   init();
   if (index < 0) {
     index = 0;
   }
   if (index > (data.size() - 1)) {
     index = data.size() - 1;
   }
   Cart obj = data.get(index);
   Long id = obj.getId();
   return cartRepository.findOne(id);
 }
Example #2
0
  public void init() {
    int from = 0;
    int to = 10;
    data =
        cartRepository
            .findAll(new org.springframework.data.domain.PageRequest(from / to, to))
            .getContent();
    if (data == null) {
      throw new IllegalStateException(
          "Find entries implementation for 'Cart' illegally returned null");
    }
    if (!data.isEmpty()) {
      return;
    }

    data = new ArrayList<Cart>();
    for (int i = 0; i < 10; i++) {
      Cart obj = getNewTransientCart(i);
      try {
        cartRepository.save(obj);
      } catch (ConstraintViolationException e) {
        StringBuilder msg = new StringBuilder();
        for (Iterator<ConstraintViolation<?>> iter = e.getConstraintViolations().iterator();
            iter.hasNext(); ) {
          ConstraintViolation<?> cv = iter.next();
          msg.append("[")
              .append(cv.getConstraintDescriptor())
              .append(":")
              .append(cv.getMessage())
              .append("=")
              .append(cv.getInvalidValue())
              .append("]");
        }
        throw new RuntimeException(msg.toString(), e);
      }
      cartRepository.flush();
      data.add(obj);
    }
  }
Example #3
0
 public Cart getRandomCart() {
   init();
   Cart obj = data.get(rnd.nextInt(data.size()));
   Long id = obj.getId();
   return cartRepository.findOne(id);
 }