View Javadoc

1   package org.kuali.ole.deliver.calendar.maintenance;
2   
3   import org.kuali.ole.deliver.calendar.bo.*;
4   import org.kuali.ole.deliver.calendar.service.DateUtil;
5   import org.kuali.rice.krad.maintenance.MaintainableImpl;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.maintenance.MaintenanceLock;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   
10  import java.util.*;
11  
12  /**
13   * Created with IntelliJ IDEA.
14   * User: arjuns
15   * Date: 7/30/13
16   * Time: 8:34 PM
17   * To change this template use File | Settings | File Templates.
18   */
19  public class OleCalendarMaintenanceImpl extends MaintainableImpl {
20      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleCalendarMaintenanceImpl.class);
21  
22      @Override
23      public List<MaintenanceLock> generateMaintenanceLocks() {
24          return Collections.emptyList();
25      }
26      @Override
27      public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
28          LOG.debug("Inside retrieveObjectForEditOrCopy()");
29          Object dataObject = null;
30          OleCalendar oleCalendar = new OleCalendar();
31          try {
32              dataObject = getLookupService().findObjectBySearch(getDataObjectClass(), dataObjectKeys);
33              oleCalendar = (OleCalendar) dataObject;
34              DateUtil dateUtil = new DateUtil();
35              // oleCalendar = (OleCalendar) document.getDocumentDataObject();//changed for edit purpose
36              for (OleCalendarWeek oldCalendarWeek : oleCalendar.getOleCalendarWeekList()) {
37  
38                  if (oldCalendarWeek.getOpenTime().equals("") || oldCalendarWeek.getCloseTime().equals("")) {
39                      break;
40                  }
41                  String convertedOpenTime = "";
42                  String convertCloseTime = "";
43                  String oleOpenTime = oldCalendarWeek.getOpenTime();
44                  String oleCloseTime = oldCalendarWeek.getCloseTime();
45                  try {
46                      convertedOpenTime = dateUtil.convertTo12HoursFormat(oleOpenTime);
47                      convertCloseTime = dateUtil.convertTo12HoursFormat(oleCloseTime);
48                  } catch (java.text.ParseException e) {
49                      LOG.error(e, e); //To change body of catch statement use File | Settings | File Templates.
50                  }
51  
52                  if (convertedOpenTime != null) {
53                      oldCalendarWeek.setOpenTime(convertedOpenTime.substring(0, convertedOpenTime.length() - 2));
54                  }
55                  if (convertCloseTime != null) {
56                      oldCalendarWeek.setCloseTime(convertCloseTime.substring(0, convertCloseTime.length() - 2));
57                  }
58              }
59  
60  
61              for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oleCalendar.getOleCalendarExceptionPeriodList()) {
62                  for (OleCalendarExceptionPeriodWeek oleCalendarExceptionPeriodWeek : oleCalendarExceptionPeriod.getOleCalendarExceptionPeriodWeekList()) {
63                      String convOpenTimeExcptPrdWk = "";
64                      String convCloseTimeExcptPrdWk = "";
65                      String oleOpenTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getOpenTime();
66                      String oleCloseTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getCloseTime();
67                      try {
68                          convOpenTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptPrdWk);
69                          convCloseTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptPrdWk);
70                      } catch (java.text.ParseException e) {
71                          LOG.error(e, e);  //To change body of catch statement use File | Settings | File Templates.
72                      }
73  
74                      if (convOpenTimeExcptPrdWk != null) {
75                          oleCalendarExceptionPeriodWeek.setOpenTime(convOpenTimeExcptPrdWk.substring(0, convOpenTimeExcptPrdWk.length() - 2));
76                      }
77                      if (convCloseTimeExcptPrdWk != null) {
78                          oleCalendarExceptionPeriodWeek.setCloseTime(convCloseTimeExcptPrdWk.substring(0, convCloseTimeExcptPrdWk.length() - 2));
79                      }
80                  }
81              }
82  
83  
84              for (OleCalendarExceptionDate oleCalendarExceptionDate : oleCalendar.getOleCalendarExceptionDateList()) {
85                  String convertedOpenTimeExcptDate = "";
86                  String convertedCloseTimeExcptDate = "";
87                  String oleOpenTimeExcptDate = oleCalendarExceptionDate.getOpenTime();
88                  String oleCloseTimeExcptDate = oleCalendarExceptionDate.getCloseTime();
89                  if ((!oleCalendarExceptionDate.getOpenTime().equals("")) && (!oleCalendarExceptionDate.getCloseTime().equals(""))) { //changed
90                      try {
91                          convertedOpenTimeExcptDate = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptDate);
92                          convertedCloseTimeExcptDate = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptDate);
93                      } catch (java.text.ParseException e) {
94                          LOG.error(e, e);  //To change body of catch statement use File | Settings | File Templates.
95                      }
96  
97                      if (convertedOpenTimeExcptDate != null) {
98                          oleCalendarExceptionDate.setOpenTime(convertedOpenTimeExcptDate.substring(0, convertedOpenTimeExcptDate.length() - 2));
99                      }
100                     if (convertedCloseTimeExcptDate != null) {
101                         oleCalendarExceptionDate.setCloseTime(convertedCloseTimeExcptDate.substring(0, convertedCloseTimeExcptDate.length() - 2));
102                     }
103                 }
104             }
105         } catch (Exception e) {
106             LOG.error(e, e);
107         }
108         return oleCalendar;
109     }
110 
111     @Override
112     public void processAfterNew(MaintenanceDocument document,
113                                 Map<String, String[]> requestParameters) {
114         LOG.debug("Inside processAfterNew()");
115         super.processAfterNew(document, requestParameters);
116         document.getDocumentHeader().setDocumentDescription("New Calendar Document");
117 
118     }
119 
120     @Override
121     public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
122         LOG.debug("Inside processAfterCopy()");
123         super.processAfterCopy(document, requestParameters);
124         document.getDocumentHeader().setDocumentDescription("Copied Calendar Document");
125     }
126 
127     @Override
128     public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
129         LOG.debug("Inside processAfterEdit()");
130         super.processAfterEdit(document, requestParameters);
131         document.getDocumentHeader().setDocumentDescription("Edited Calendar Document");
132 
133     }
134 
135     @Override
136     public void processAfterRetrieve() {
137 
138 
139         try {
140             OleCalendar oleCalendar = (OleCalendar) this.getDataObject();
141             Map<String, Object> oleCalendarMap = new HashMap<String, Object>();
142             oleCalendarMap.put("beginDate", oleCalendar.getBeginDate());
143             List<OleCalendar> oleCalendarList = (List<OleCalendar>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCalendar.class, oleCalendarMap);
144             if (oleCalendarList.size() > 0) {
145                 oleCalendar = oleCalendarList.get(0);
146             }
147             if (oleCalendar.getCalendarId() != null) {
148                 DateUtil dateUtil = new DateUtil();
149                 // oleCalendar = (OleCalendar) document.getDocumentDataObject();//changed for edit purpose
150                 List<OleCalendarWeek> oleCalendarWeekList = new ArrayList<OleCalendarWeek>();
151                 for (OleCalendarWeek oldCalendarWeek : oleCalendar.getOleCalendarWeekList()) {
152 
153                     if (oldCalendarWeek.getOpenTime().equals("") || oldCalendarWeek.getCloseTime().equals("")) {
154                         break;
155                     }
156                     String convertedOpenTime = "";
157                     String convertCloseTime = "";
158                     String oleOpenTime = oldCalendarWeek.getOpenTime();
159                     String oleCloseTime = oldCalendarWeek.getCloseTime();
160                     try {
161                         convertedOpenTime = dateUtil.convertTo12HoursFormat(oleOpenTime);
162                         convertCloseTime = dateUtil.convertTo12HoursFormat(oleCloseTime);
163                     } catch (java.text.ParseException e) {
164                         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
165                     }
166 
167                     if (convertedOpenTime != null) {
168                         oldCalendarWeek.setOpenTime(convertedOpenTime.substring(0, convertedOpenTime.length() - 2));
169                     }
170                     if (convertCloseTime != null) {
171                         oldCalendarWeek.setCloseTime(convertCloseTime.substring(0, convertCloseTime.length() - 2));
172                     }
173                     oleCalendarWeekList.add(oldCalendarWeek);
174                 }
175                 oleCalendar.setOleCalendarWeekList(oleCalendarWeekList);
176 
177 
178                 for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oleCalendar.getOleCalendarExceptionPeriodList()) {
179                     for (OleCalendarExceptionPeriodWeek oleCalendarExceptionPeriodWeek : oleCalendarExceptionPeriod.getOleCalendarExceptionPeriodWeekList()) {
180                         String convOpenTimeExcptPrdWk = "";
181                         String convCloseTimeExcptPrdWk = "";
182                         String oleOpenTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getOpenTime();
183                         String oleCloseTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getCloseTime();
184                         try {
185                             convOpenTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptPrdWk);
186                             convCloseTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptPrdWk);
187                         } catch (java.text.ParseException e) {
188                             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
189                         }
190 
191                         if (convOpenTimeExcptPrdWk != null) {
192                             oleCalendarExceptionPeriodWeek.setOpenTime(convOpenTimeExcptPrdWk.substring(0, convOpenTimeExcptPrdWk.length() - 2));
193                         }
194                         if (convCloseTimeExcptPrdWk != null) {
195                             oleCalendarExceptionPeriodWeek.setCloseTime(convCloseTimeExcptPrdWk.substring(0, convCloseTimeExcptPrdWk.length() - 2));
196                         }
197                     }
198                 }
199 
200 
201                 for (OleCalendarExceptionDate oleCalendarExceptionDate : oleCalendar.getOleCalendarExceptionDateList()) {
202                     String convertedOpenTimeExcptDate = "";
203                     String convertedCloseTimeExcptDate = "";
204                     String oleOpenTimeExcptDate = oleCalendarExceptionDate.getOpenTime();
205                     String oleCloseTimeExcptDate = oleCalendarExceptionDate.getCloseTime();
206                     if ((!oleCalendarExceptionDate.getOpenTime().equals("")) && (!oleCalendarExceptionDate.getCloseTime().equals(""))) { //changed
207                         try {
208                             convertedOpenTimeExcptDate = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptDate);
209                             convertedCloseTimeExcptDate = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptDate);
210                         } catch (java.text.ParseException e) {
211                             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
212                         }
213 
214                         if (convertedOpenTimeExcptDate != null) {
215                             oleCalendarExceptionDate.setOpenTime(convertedOpenTimeExcptDate.substring(0, convertedOpenTimeExcptDate.length() - 2));
216                         }
217                         if (convertedCloseTimeExcptDate != null) {
218                             oleCalendarExceptionDate.setCloseTime(convertedCloseTimeExcptDate.substring(0, convertedCloseTimeExcptDate.length() - 2));
219                         }
220                     }
221                 }
222             }
223         } catch (Exception e) {
224             LOG.error(e, e);
225         }
226 
227     }
228 
229 
230 }