| 1 | |
package org.jtheque.primary.services.impl; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.persistence.able.DataListener; |
| 20 | |
import org.jtheque.primary.dao.able.IDaoLendings; |
| 21 | |
import org.jtheque.primary.od.able.Lending; |
| 22 | |
import org.jtheque.primary.services.able.ILendingsService; |
| 23 | |
import org.jtheque.utils.bean.IntDate; |
| 24 | |
import org.springframework.transaction.annotation.Transactional; |
| 25 | |
|
| 26 | |
import javax.annotation.Resource; |
| 27 | |
import java.util.Collection; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public final class LendingsService implements ILendingsService { |
| 35 | |
@Resource |
| 36 | |
private IDaoLendings daoLendings; |
| 37 | |
|
| 38 | |
@Override |
| 39 | |
public Lending getLending(int id){ |
| 40 | 0 | return daoLendings.getLending(id); |
| 41 | |
} |
| 42 | |
|
| 43 | |
@Override |
| 44 | |
public boolean hasNoLendings(){ |
| 45 | 0 | return daoLendings.getLendings().isEmpty(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
@Override |
| 49 | |
public Collection<Lending> getLendings(){ |
| 50 | 0 | return daoLendings.getLendings(); |
| 51 | |
} |
| 52 | |
|
| 53 | |
@Override |
| 54 | |
@Transactional |
| 55 | |
public void save(Lending lending){ |
| 56 | 0 | daoLendings.save(lending); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
public Collection<Lending> getDatas(){ |
| 61 | 0 | return daoLendings.getLendings(); |
| 62 | |
} |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
public void addDataListener(DataListener listener){ |
| 66 | 0 | daoLendings.addDataListener(listener); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
@Transactional |
| 71 | |
public void clearAll(){ |
| 72 | 0 | daoLendings.clearAll(); |
| 73 | 0 | } |
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public String getDataType(){ |
| 77 | 0 | return DATA_TYPE; |
| 78 | |
} |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
@Transactional |
| 82 | |
public boolean delete(Lending lending){ |
| 83 | 0 | return daoLendings.delete(lending); |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
@Transactional |
| 88 | |
public void create(Lending lending){ |
| 89 | 0 | daoLendings.create(lending); |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
@Override |
| 93 | |
public boolean isLate(Lending lending, int days){ |
| 94 | 0 | IntDate date = lending.getDate(); |
| 95 | |
|
| 96 | 0 | date.add(IntDate.Fields.DAY, days); |
| 97 | |
|
| 98 | 0 | return date.intValue() > IntDate.today().intValue(); |
| 99 | |
} |
| 100 | |
|
| 101 | |
@Override |
| 102 | |
public Lending getEmptyLending(){ |
| 103 | 0 | return daoLendings.createLending(); |
| 104 | |
} |
| 105 | |
} |