001package org.kuali.ole.deliver.calendar.maintenance; 002 003import org.kuali.ole.deliver.calendar.bo.*; 004import org.kuali.ole.deliver.calendar.service.DateUtil; 005import org.kuali.rice.krad.maintenance.MaintainableImpl; 006import org.kuali.rice.krad.maintenance.MaintenanceDocument; 007import org.kuali.rice.krad.maintenance.MaintenanceLock; 008import org.kuali.rice.krad.service.KRADServiceLocator; 009 010import java.util.*; 011 012/** 013 * Created with IntelliJ IDEA. 014 * User: arjuns 015 * Date: 7/30/13 016 * Time: 8:34 PM 017 * To change this template use File | Settings | File Templates. 018 */ 019public class OleCalendarMaintenanceImpl extends MaintainableImpl { 020 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleCalendarMaintenanceImpl.class); 021 022 @Override 023 public List<MaintenanceLock> generateMaintenanceLocks() { 024 return Collections.emptyList(); 025 } 026 @Override 027 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) { 028 LOG.debug("Inside retrieveObjectForEditOrCopy()"); 029 Object dataObject = null; 030 OleCalendar oleCalendar = new OleCalendar(); 031 try { 032 dataObject = getLookupService().findObjectBySearch(getDataObjectClass(), dataObjectKeys); 033 oleCalendar = (OleCalendar) dataObject; 034 DateUtil dateUtil = new DateUtil(); 035 // oleCalendar = (OleCalendar) document.getDocumentDataObject();//changed for edit purpose 036 for (OleCalendarWeek oldCalendarWeek : oleCalendar.getOleCalendarWeekList()) { 037 038 if (oldCalendarWeek.getOpenTime().equals("") || oldCalendarWeek.getCloseTime().equals("")) { 039 break; 040 } 041 String convertedOpenTime = ""; 042 String convertCloseTime = ""; 043 String oleOpenTime = oldCalendarWeek.getOpenTime(); 044 String oleCloseTime = oldCalendarWeek.getCloseTime(); 045 try { 046 convertedOpenTime = dateUtil.convertTo12HoursFormat(oleOpenTime); 047 convertCloseTime = dateUtil.convertTo12HoursFormat(oleCloseTime); 048 } catch (java.text.ParseException e) { 049 LOG.error("Exception while converting to 12Hours format", e); //To change body of catch statement use File | Settings | File Templates. 050 } 051 052 if (convertedOpenTime != null) { 053 oldCalendarWeek.setOpenTime(convertedOpenTime.substring(0, convertedOpenTime.length() - 2)); 054 } 055 if (convertCloseTime != null) { 056 oldCalendarWeek.setCloseTime(convertCloseTime.substring(0, convertCloseTime.length() - 2)); 057 } 058 } 059 060 oleCalendar.sortCalendarWeek(oleCalendar); //added for OLE-5381 061 for (OleCalendarExceptionPeriod oleCalendarExceptionPeriod : oleCalendar.getOleCalendarExceptionPeriodList()) { 062 for (OleCalendarExceptionPeriodWeek oleCalendarExceptionPeriodWeek : oleCalendarExceptionPeriod.getOleCalendarExceptionPeriodWeekList()) { 063 String convOpenTimeExcptPrdWk = ""; 064 String convCloseTimeExcptPrdWk = ""; 065 String oleOpenTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getOpenTime(); 066 String oleCloseTimeExcptPrdWk = oleCalendarExceptionPeriodWeek.getCloseTime(); 067 try { 068 convOpenTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptPrdWk); 069 convCloseTimeExcptPrdWk = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptPrdWk); 070 } catch (java.text.ParseException e) { 071 LOG.error("Exception while converting to 12Hours format", e); //To change body of catch statement use File | Settings | File Templates. 072 } 073 074 if (convOpenTimeExcptPrdWk != null) { 075 oleCalendarExceptionPeriodWeek.setOpenTime(convOpenTimeExcptPrdWk.substring(0, convOpenTimeExcptPrdWk.length() - 2)); 076 } 077 if (convCloseTimeExcptPrdWk != null) { 078 oleCalendarExceptionPeriodWeek.setCloseTime(convCloseTimeExcptPrdWk.substring(0, convCloseTimeExcptPrdWk.length() - 2)); 079 } 080 } 081 } 082 083 084 for (OleCalendarExceptionDate oleCalendarExceptionDate : oleCalendar.getOleCalendarExceptionDateList()) { 085 String convertedOpenTimeExcptDate = ""; 086 String convertedCloseTimeExcptDate = ""; 087 String oleOpenTimeExcptDate = oleCalendarExceptionDate.getOpenTime(); 088 String oleCloseTimeExcptDate = oleCalendarExceptionDate.getCloseTime(); 089 if ((!oleCalendarExceptionDate.getOpenTime().equals("")) && (!oleCalendarExceptionDate.getCloseTime().equals(""))) { //changed 090 try { 091 convertedOpenTimeExcptDate = dateUtil.convertTo12HoursFormat(oleOpenTimeExcptDate); 092 convertedCloseTimeExcptDate = dateUtil.convertTo12HoursFormat(oleCloseTimeExcptDate); 093 } catch (java.text.ParseException e) { 094 LOG.error("Exception while converting to 12Hours format", e); //To change body of catch statement use File | Settings | File Templates. 095 } 096 097 if (convertedOpenTimeExcptDate != null) { 098 oleCalendarExceptionDate.setOpenTime(convertedOpenTimeExcptDate.substring(0, convertedOpenTimeExcptDate.length() - 2)); 099 } 100 if (convertedCloseTimeExcptDate != null) { 101 oleCalendarExceptionDate.setCloseTime(convertedCloseTimeExcptDate.substring(0, convertedCloseTimeExcptDate.length() - 2)); 102 } 103 } 104 } 105 } catch (Exception e) { 106 LOG.error("Exception while converting to 12Hours format", 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("Exception", e); 225 } 226 227 } 228 229 230}