return (List<Deviation>) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
Criteria crit = session
.createCriteria(Deviation.class);
if(deviation.getInitiatedBy()!=null){
crit.add(Restrictions.eq("initiatedBy",
deviation.getInitiatedBy()));
}
if (deviation.getDeviationId() != null) {
crit.add(Restrictions.eq("deviationId",
deviation.getDeviationId()));
}
if (deviation.getUserName() != null) {
crit.add(Restrictions.ilike("userName",
deviation.getUserName()));
}
if (deviation.getResponsible() != null) {
crit.add(Restrictions.ilike("responsible",
deviation.getResponsible()));
}
if (deviation.getOrderNr() != null) {
crit.add(Restrictions.eq("orderNr", deviation
.getOrderNr()));
}
if (deviation.getProjectNr() != null) {
crit.add(Restrictions.eq("projectNr",
deviation.getProjectNr()));
}
if (deviation.getCustomerNr() != null) {
crit.add(Restrictions.eq("customerNr",
deviation.getCustomerNr()));
}
if (deviation.getCustomerName() != null) {
crit.add(Restrictions.ilike("customerName",
deviation.getCustomerName()));
}
if (deviation.getPreventiveAction() != null) {
crit.add(Restrictions.ilike("preventiveAction",
deviation.getPreventiveAction()));
}
if (deviation.getProductArea() != null) {
crit.add(Restrictions.eq("productArea",
deviation.getProductArea()));
}
if (deviation.getProductName() != null) {
crit.add(Restrictions.ilike("productName",
deviation.getProductName()));
}
if (deviation.getIsPostShipment().equalsIgnoreCase(
"Ja")) {
crit
.add(Restrictions
.isNotNull("postShipment"));
}
if (deviation.getDoAssembly() != null) {
crit.add(Restrictions.eq("doAssembly",
deviation.getDoAssembly()));
}
if (deviation.getOwnFunction() != null) {
crit.add(Restrictions.eq("ownFunction",
deviation.getOwnFunction()));
}
if (deviation.getDeviationFunction() != null) {
crit.add(Restrictions.eq("deviationFunction",
deviation.getDeviationFunction()));
}
if (deviation.getFunctionCategory() != null) {
crit.add(Restrictions.eq("functionCategory",
deviation.getFunctionCategory()));
}
if (deviation.getDeviationStatus() != null) {
crit.add(Restrictions.eq("deviationStatus",
deviation.getDeviationStatus()));
}
if (deviation.getDateClosed() != null) {
crit.add(Restrictions.eq("dateClosed",
deviation.getDateClosed()));
}
if (deviation.getChecked() != null) {
crit.add(Restrictions.eq("checked", deviation
.getChecked()));
}
if (deviation.getDateFrom() != null
&& deviation.getDateTo() == null) {
crit.add(Restrictions.gt("registrationDate",
Util.getShortDate(deviation
.getDateFrom())));
}
if (deviation.getDateFrom() == null
&& deviation.getDateTo() != null) {
crit.add(Restrictions.lt("registrationDate",
Util.getShortDateLast(deviation
.getDateTo())));
}
if (deviation.getDateFrom() != null
&& deviation.getDateTo() != null) {
crit.add(Restrictions.between(
"registrationDate", Util
.getShortDate(deviation
.getDateFrom()), Util
.getShortDateLast(deviation
.getDateTo())));
}
return crit.list();
}
});
}
return null;