public Pizza getSpecificPizza(int index) { init(); if (index < 0) { index = 0; } if (index > (data.size() - 1)) { index = data.size() - 1; } Pizza obj = data.get(index); Long id = obj.getId(); return pizzaService.findPizza(id); }
public void init() { int from = 0; int to = 10; data = pizzaService.findPizzaEntries(from, to); if (data == null) { throw new IllegalStateException( "Find entries implementation for 'Pizza' illegally returned null"); } if (!data.isEmpty()) { return; } data = new ArrayList<Pizza>(); for (int i = 0; i < 10; i++) { Pizza obj = getNewTransientPizza(i); try { pizzaService.savePizza(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); } pizzaRepository.flush(); data.add(obj); } }
public Pizza getRandomPizza() { init(); Pizza obj = data.get(rnd.nextInt(data.size())); Long id = obj.getId(); return pizzaService.findPizza(id); }