001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.actionlist.web;
017
018import org.kuali.rice.core.api.util.RiceConstants;
019import org.kuali.rice.kew.actionlist.ActionListFilter;
020import org.kuali.rice.kns.web.struts.form.KualiForm;
021import org.kuali.rice.krad.util.GlobalVariables;
022
023import java.text.ParseException;
024import java.util.List;
025
026
027/**
028 * Struts form class for ActionListFilterAction
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 *
032 */
033public class ActionListFilterForm extends KualiForm {
034
035        private static final long serialVersionUID = -1149636352016711445L;
036    private static String CREATE_DATE_FROM = "createDateFrom";
037    private static String CREATE_DATE_TO = "createDateTo";
038    private static String LAST_ASSIGNED_DATE_FROM = "lastAssignedDateFrom";
039    private static String LAST_ASSIGNED_DATE_TO = "lastAssignedDateTo";
040    private ActionListFilter filter;
041    private String createDateFrom;
042    private String createDateTo;
043    private String lastAssignedDateTo;
044    private String lastAssignedDateFrom;
045    private String methodToCall = "";
046    private String lookupableImplServiceName;
047    private String lookupType;
048    private String docTypeFullName;
049    private List userWorkgroups;
050    private String cssFile = "kuali.css";
051    private String test = "";
052    private String targetSpec;
053
054    public String getTest(){
055        return test;
056    }
057    public void setTest(String test){
058        this.test = test;
059    }
060
061    public ActionListFilterForm() {
062        filter = new ActionListFilter();
063    }
064
065    public String getCreateDateTo() {
066        return createDateTo;
067    }
068    public void setCreateDateTo(String createDateTo) {
069        if(createDateTo == null){
070                createDateTo = "";
071        }
072        else{
073                this.createDateTo = createDateTo.trim();
074        }
075    }
076    public String getLastAssignedDateFrom() {
077        return lastAssignedDateFrom;
078    }
079    public void setLastAssignedDateFrom(String lastAssignedDateFrom) {
080        if(lastAssignedDateFrom == null){
081                lastAssignedDateFrom = "";
082        }
083        else{
084                this.lastAssignedDateFrom = lastAssignedDateFrom.trim();
085        }
086    }
087    public String getCreateDateFrom() {
088        return createDateFrom;
089    }
090    public void setCreateDateFrom(String createDate) {
091        if(createDate == null){
092                createDate = "";
093        }
094        else{
095                this.createDateFrom = createDate.trim();
096        }
097    }
098
099    public ActionListFilter getFilter() {
100        return filter;
101    }
102
103    public String getMethodToCall() {
104        return methodToCall;
105    }
106
107    public void setMethodToCall(String methodToCall) {
108        this.methodToCall = methodToCall;
109    }
110
111    public void setFilter(ActionListFilter filter) {
112        this.filter = filter;
113        if (filter.getCreateDateFrom() != null) {
114            setCreateDateFrom(RiceConstants.getDefaultDateFormat().format(filter.getCreateDateFrom()));
115        }
116        if (filter.getCreateDateTo() != null) {
117            setCreateDateTo(RiceConstants.getDefaultDateFormat().format(filter.getCreateDateTo()));
118        }
119        if (filter.getLastAssignedDateFrom() != null) {
120            setLastAssignedDateFrom(RiceConstants.getDefaultDateFormat().format(filter.getLastAssignedDateFrom()));
121        }
122        if (filter.getLastAssignedDateTo() != null) {
123            setLastAssignedDateTo(RiceConstants.getDefaultDateFormat().format(filter.getLastAssignedDateTo()));
124        }
125    }
126
127    public String getLastAssignedDateTo() {
128        return lastAssignedDateTo;
129    }
130
131    public void setLastAssignedDateTo(String lastAssignedDate) {
132        if(lastAssignedDate == null){
133                lastAssignedDate = "";
134        }
135        else{
136                this.lastAssignedDateTo = lastAssignedDate.trim();
137        }
138    }
139
140    public void validateDates() {
141        //List errors = new ArrayList();
142        //ActionErrors errors = new ActionErrors();
143        if (getCreateDateFrom() != null && getCreateDateFrom().length() != 0) {
144            try {
145                RiceConstants.getDefaultDateFormat().parse(getCreateDateFrom());
146            } catch (ParseException e) {
147                GlobalVariables.getMessageMap().putError(CREATE_DATE_FROM, "general.error.fieldinvalid", "Create Date From");
148            }
149        }
150        if (getCreateDateTo() != null && getCreateDateTo().length() != 0) {
151            try {
152                RiceConstants.getDefaultDateFormat().parse(getCreateDateTo());
153            } catch (ParseException e) {
154                GlobalVariables.getMessageMap().putError(CREATE_DATE_TO, "general.error.fieldinvalid", "Create Date To");
155            }
156        }
157        if (getLastAssignedDateFrom() != null && getLastAssignedDateFrom().length() != 0) {
158            try {
159                RiceConstants.getDefaultDateFormat().parse(getLastAssignedDateFrom());
160            } catch (ParseException e1) {
161                GlobalVariables.getMessageMap().putError(LAST_ASSIGNED_DATE_FROM, "general.error.fieldinvalid", "Last Assigned Date From");
162            }
163        }
164        if (getLastAssignedDateTo() != null && getLastAssignedDateTo().length() != 0) {
165            try {
166                RiceConstants.getDefaultDateFormat().parse(getLastAssignedDateTo());
167            } catch (ParseException e1) {
168                GlobalVariables.getMessageMap().putError(LAST_ASSIGNED_DATE_TO, "general.error.fieldinvalid", "Last Assigned Date To");
169            }
170        }
171    }
172
173    public ActionListFilter getLoadedFilter()/* throws ParseException*/ {
174        try {
175            if (getCreateDateFrom() != null && getCreateDateFrom().length() != 0) {
176                filter.setCreateDateFrom(RiceConstants.getDefaultDateFormat().parse(getCreateDateFrom()));
177            }
178            if (getCreateDateTo() != null && getCreateDateTo().length() != 0) {
179                filter.setCreateDateTo(RiceConstants.getDefaultDateFormat().parse(getCreateDateTo()));
180            }
181            if (getLastAssignedDateFrom() != null && getLastAssignedDateFrom().length() != 0) {
182                filter.setLastAssignedDateFrom(RiceConstants.getDefaultDateFormat().parse(getLastAssignedDateFrom()));
183            }
184            if (getLastAssignedDateTo() != null && getLastAssignedDateTo().length() != 0) {
185                filter.setLastAssignedDateTo(RiceConstants.getDefaultDateFormat().parse(getLastAssignedDateTo()));
186            }
187            if (getDocTypeFullName() != null && ! "".equals(getDocTypeFullName())) {
188                filter.setDocumentType(getDocTypeFullName());
189            }
190        } catch (ParseException e) {
191            //error caught and displayed in validateDates()
192        }
193
194        return filter;
195    }
196
197    public String getLookupableImplServiceName() {
198        return lookupableImplServiceName;
199    }
200
201    public void setLookupableImplServiceName(String lookupableImplServiceName) {
202        this.lookupableImplServiceName = lookupableImplServiceName;
203    }
204
205    public String getLookupType() {
206        return lookupType;
207    }
208
209    public void setLookupType(String lookupType) {
210        this.lookupType = lookupType;
211    }
212
213    public String getDocTypeFullName() {
214        return docTypeFullName;
215    }
216
217    public void setDocTypeFullName(String docTypeFullName) {
218        this.docTypeFullName = docTypeFullName;
219    }
220
221    public List getUserWorkgroups() {
222        return userWorkgroups;
223    }
224
225    public void setUserWorkgroups(List userWorkgroups) {
226        this.userWorkgroups = userWorkgroups;
227    }
228
229        public String getCssFile() {
230                return this.cssFile;
231        }
232
233        public void setCssFile(String cssFile) {
234                this.cssFile = cssFile;
235        }
236
237    public String getTargetSpec() {
238        return targetSpec;
239    }
240
241    public void setTargetSpec(String targetSpec) {
242        this.targetSpec = targetSpec;
243    }
244
245}