public class ShowAllBorrow extends Template {
private static final long serialVersionUID = 30L;
public ShowAllBorrow(final PageParameters parameters) {
super(parameters);
BorrowService borrowService = (BorrowService) ApplicationContextProvider.getApplicationContext().getBean("borrowService");
// RETURN BORROW
StringValue borrowId = parameters.get("borrowId");
if (!borrowId.isEmpty()) {
BorrowTO borrow = borrowService.findBorrowByID(borrowId.toLong());
borrowService.returnBooks(borrow, borrow.getTitlesTO());
setResponsePage(ShowAllBorrow.class);
}
// EXTEND BORROW
StringValue extend = parameters.get("extend");
if (!extend.isEmpty()) {
BorrowTO borrow = borrowService.findBorrowByID(extend.toLong());
Calendar cal = Calendar.getInstance();
cal.setTime(borrow.getExpirationDate());
cal.add(Calendar.MONTH, 1); // add 1 month
borrow.setExpirationDate(cal.getTime());
borrowService.updateExpirationDate(borrow, borrow.getExpirationDate());
setResponsePage(ShowAllBorrow.class);
}
RepeatingView repeating = new RepeatingView("repeating");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
for (BorrowTO borrow : borrowService.findAllBorrows()) {
AbstractItem item = new AbstractItem(repeating.newChildId());
PageParameters pageParameters = new PageParameters();
pageParameters.add("borrowId", borrow.getBorrowID());
PageParameters pageParameters2 = new PageParameters();
pageParameters2.add("extend", borrow.getBorrowID());