1 24 package org.ofbiz.minilang.method.entityops; 25 26 import java.util.List ; 27 28 import org.ofbiz.base.util.UtilDateTime; 29 import org.ofbiz.base.util.UtilValidate; 30 import org.ofbiz.entity.util.EntityUtil; 31 import org.ofbiz.minilang.SimpleMethod; 32 import org.ofbiz.minilang.method.ContextAccessor; 33 import org.ofbiz.minilang.method.MethodContext; 34 import org.ofbiz.minilang.method.MethodOperation; 35 import org.w3c.dom.Element ; 36 37 44 public class FilterListByDate extends MethodOperation { 45 46 ContextAccessor listAcsr; 47 ContextAccessor toListAcsr; 48 ContextAccessor validDateAcsr; 49 String fromFieldName; 50 String thruFieldName; 51 String allSameStr; 52 53 public FilterListByDate(Element element, SimpleMethod simpleMethod) { 54 super(element, simpleMethod); 55 listAcsr = new ContextAccessor(element.getAttribute("list-name")); 56 toListAcsr = new ContextAccessor(element.getAttribute("to-list-name"), element.getAttribute("list-name")); 57 validDateAcsr = new ContextAccessor(element.getAttribute("valid-date-name")); 58 59 fromFieldName = element.getAttribute("from-field-name"); 60 if (UtilValidate.isEmpty(fromFieldName)) fromFieldName = "fromDate"; 61 thruFieldName = element.getAttribute("thru-field-name"); 62 if (UtilValidate.isEmpty(thruFieldName)) thruFieldName = "thruDate"; 63 64 allSameStr = element.getAttribute("all-same"); 65 } 66 67 public boolean exec(MethodContext methodContext) { 68 String fromFieldName = methodContext.expandString(this.fromFieldName); 69 String thruFieldName = methodContext.expandString(this.thruFieldName); 70 String allSameStr = methodContext.expandString(this.allSameStr); 71 72 boolean allSame = !"false".equals(allSameStr); 73 74 if (!validDateAcsr.isEmpty()) { 75 toListAcsr.put(methodContext, EntityUtil.filterByDate((List ) listAcsr.get(methodContext), (java.sql.Timestamp ) validDateAcsr.get(methodContext), fromFieldName, thruFieldName, true)); 76 } else { 77 toListAcsr.put(methodContext, EntityUtil.filterByDate((List ) listAcsr.get(methodContext), UtilDateTime.nowTimestamp(), fromFieldName, thruFieldName, true)); 78 } 79 return true; 80 } 81 82 public String rawString() { 83 return "<filter-list-by-date/>"; 85 } 86 public String expandedString(MethodContext methodContext) { 87 return this.rawString(); 89 } 90 } 91 92 | Popular Tags |