public DataResult tableAjax(Map<String, String> filters,
String[] projections, String columnOrder, String columnOrderDir,
int startIndex) throws Exception {
//dostep do sesji
DzialService dzialService = null;
List<Order> orders = null;
// stala czesc sluzaca sortowaniu
if (columnOrder.compareTo("null") != 0) {
orders = new ArrayList<Order>();
if (columnOrderDir.compareTo("desc") == 0) {
orders.add(Order.desc(columnOrder));
} else {
orders.add(Order.asc(columnOrder));
}
}
try {
dzialService = (DzialService) BusinessUtil
.findBusiness("DzialService");
ProjectionList projectionList = Projections.projectionList();
for (int i = 0; i < projections.length; i++) {
projectionList.add(Projections.property(projections[i]));
}
List<Criterion> criterions = new ArrayList<Criterion>();
if (filters.size() > 0) {
if (!ValidatorUtil.isBlankOrNull(filters
.get(Dzial.PROPERTY_ID))) {
criterions.add(Restrictions.eq(Dzial.PROPERTY_ID,
Integer.parseInt(filters
.get(Dzial.PROPERTY_ID))));
}
if (!ValidatorUtil.isBlankOrNull(filters
.get(Dzial.PROPERTY_NAZWA_DZIALU))) {
criterions.add(Restrictions.like(Dzial.PROPERTY_NAZWA_DZIALU,
filters.get(Dzial.PROPERTY_NAZWA_DZIALU),
MatchMode.START));
}
if (!ValidatorUtil.isBlankOrNull(filters
.get(Dzial.PROPERTY_TYP))) {
criterions.add(Restrictions.eq(Dzial.PROPERTY_TYP,
filters.get(Dzial.PROPERTY_TYP)));
}
if (!ValidatorUtil.isBlankOrNull(filters
.get(Dzial.PROPERTY_OBJECT_PRACOWNIKS + "."
+ Pracownik.PROPERTY_ID))) {
criterions.add(Restrictions.eq(
Dzial.PROPERTY_OBJECT_PRACOWNIKS + "."
+ Pracownik.PROPERTY_ID,
Integer.valueOf(filters
.get(Dzial.PROPERTY_OBJECT_PRACOWNIKS
+ "." + Pracownik.PROPERTY_ID))));
}
}
DataResult dane = null;
startIndex = (startIndex - 1) * ROW_AMOUNT;
if (orders != null) {
dane = dzialService.findByParams(projectionList,
criterions, orders, startIndex, ROW_AMOUNT);
} else {
dane = dzialService.findByParams(projectionList,
criterions, startIndex, ROW_AMOUNT);
}
//Ta petla bedzie maksymalnie takiej dlugosci ile wierszy na tabeli w
//tym przypadku 10