public DataResult tableAjax(Map<String, String> filters,
String[] projections, String columnOrder, String columnOrderDir,
int startIndex) throws Exception{
StanowiskoService stanowiskoService = 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 {
stanowiskoService = (StanowiskoService) BusinessUtil
.findBusiness("StanowiskoService");
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(Stanowisko.PROPERTY_ID))) {
criterions.add(Restrictions.eq(Stanowisko.PROPERTY_ID,
Integer.parseInt(filters
.get(Stanowisko.PROPERTY_ID))));
}
if (!ValidatorUtil.isBlankOrNull(filters
.get(Stanowisko.PROPERTY_NAZWA))) {
criterions.add(Restrictions.like(Stanowisko.PROPERTY_NAZWA,
filters.get(Stanowisko.PROPERTY_NAZWA),
MatchMode.START));
}
if (!ValidatorUtil.isBlankOrNull(filters
.get(Stanowisko.PROPERTY_OBJECT_PPRACOWNIKS + "."
+ Pracownik.PROPERTY_ID))) {
criterions.add(Restrictions.eq(
Stanowisko.PROPERTY_OBJECT_PPRACOWNIKS + "."
+ Pracownik.PROPERTY_ID,
Integer.valueOf(filters
.get(Stanowisko.PROPERTY_OBJECT_PPRACOWNIKS
+ "." + Pracownik.PROPERTY_ID))));
}
}
DataResult dane = null;
startIndex = (startIndex - 1) * ROW_AMOUNT;
if (orders != null) {
dane = stanowiskoService.findByParams(projectionList,
criterions, orders, startIndex, ROW_AMOUNT);
} else {
dane = stanowiskoService.findByParams(projectionList,
criterions, startIndex, ROW_AMOUNT);
}
dane.setRowsPerPage(ROW_AMOUNT);
return dane;