List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private List<Calendar> expandDayListForMonthlyYearly(List<Calendar> list) { // this func ONLY works for expanding, NOT for contracting assert (mFreq == Frequency.MONTHLY || mFreq == Frequency.YEARLY); if (mByDayList.size() <= 0) return list; List<Calendar> toRet = new ArrayList<Calendar>(); Set<Integer> months = new HashSet<Integer>(); for (Calendar cur : list) { int curYear = cur.get(Calendar.YEAR); int curMonth = cur.get(Calendar.MONTH); if (!months.contains(curMonth)) { months.add(curMonth);//from w w w . j a v a2s. co m for (ZWeekDayNum day : mByDayList) { // find all the cals matching this day-of-week ArrayList<Integer> matching = new ArrayList<Integer>(); cur.set(Calendar.DAY_OF_MONTH, 1); do { if (cur.get(Calendar.DAY_OF_WEEK) == day.mDay.getCalendarDay()) matching.add(cur.get(Calendar.DAY_OF_MONTH)); cur.add(Calendar.DAY_OF_MONTH, 1); } while (cur.get(Calendar.MONTH) == curMonth); cur.set(Calendar.MONTH, curMonth); cur.set(Calendar.YEAR, curYear); if (day.mOrdinal == 0) { for (Integer matchDay : matching) { cur.set(Calendar.DAY_OF_MONTH, matchDay); toRet.add((Calendar) (cur.clone())); } } else { if (day.mOrdinal > 0) { if (day.mOrdinal <= matching.size()) { cur.set(Calendar.DAY_OF_MONTH, matching.get(day.mOrdinal - 1)); toRet.add((Calendar) (cur.clone())); } } else { if ((-1 * day.mOrdinal) <= (matching.size())) { cur.set(Calendar.DAY_OF_MONTH, matching.get(matching.size() + day.mOrdinal)); toRet.add((Calendar) (cur.clone())); } } } } // foreach mByDayList } // month already seen? } // we unfortunately have to sort here because, for example, the "-1FR" could happen before the "-1TH" assert (toRet instanceof ArrayList); Collections.sort(toRet); return toRet; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private List<Calendar> expandMonthDayList(List<Calendar> list) { // this func ONLY works for expanding, NOT for contracting assert (mFreq == Frequency.MONTHLY || mFreq == Frequency.YEARLY); if (mByMonthDayList.size() <= 0) return list; List<Calendar> toRet = new LinkedList<Calendar>(); for (Calendar cur : list) { int curMonth = cur.get(Calendar.MONTH); int lastMonthDay = cur.getActualMaximum(Calendar.DAY_OF_MONTH); boolean seenLastMonthDay = false; for (Integer moday : mByMonthDayList) { if (moday != 0) { if (moday > 0) { if (moday >= lastMonthDay) { if (seenLastMonthDay) continue; seenLastMonthDay = true; moday = lastMonthDay; }//from w w w . java 2 s.c o m cur.set(Calendar.DAY_OF_MONTH, moday); } else { if (moday == -1) { if (seenLastMonthDay) continue; seenLastMonthDay = true; } cur.set(Calendar.DAY_OF_MONTH, 1); cur.roll(Calendar.DAY_OF_MONTH, moday); } assert (cur.get(Calendar.MONTH) == curMonth); toRet.add((Calendar) (cur.clone())); } } } return toRet; }
From source file:org.kuali.kfs.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Sets up the PO document for Quote processing. * * @param mapping An ActionMapping/*from ww w . j a v a 2s. c o m*/ * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @throws Exception * @return An ActionForward */ public ActionForward initiateQuote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); PurchaseOrderForm poForm = (PurchaseOrderForm) form; PurchaseOrderDocument document = (PurchaseOrderDocument) poForm.getDocument(); if (!PurchaseOrderStatuses.APPDOC_IN_PROCESS.equals(document.getApplicationDocumentStatus())) { // PO must be "in process" in order to initiate a quote GlobalVariables.getMessageMap().putError(PurapPropertyConstants.VENDOR_QUOTES, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_NOT_IN_PROCESS); return mapping.findForward(KFSConstants.MAPPING_BASIC); } Calendar currentCalendar = dateTimeService.getCurrentCalendar(); Date currentSqlDate = new java.sql.Date(currentCalendar.getTimeInMillis()); document.setPurchaseOrderQuoteInitializationDate(currentSqlDate); document.updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_QUOTE); document.setStatusChange(PurchaseOrderStatuses.APPDOC_QUOTE); // TODO this needs to be done better, and probably make it a parameter Calendar expCalendar = (Calendar) currentCalendar.clone(); expCalendar.add(Calendar.DAY_OF_MONTH, 10); java.sql.Date expDate = new java.sql.Date(expCalendar.getTimeInMillis()); document.setPurchaseOrderQuoteDueDate(expDate); document.getPurchaseOrderVendorQuotes().clear(); SpringContext.getBean(PurapService.class).saveDocumentNoValidation(document); return mapping.findForward(KFSConstants.MAPPING_BASIC); }
From source file:org.apache.jsp.html.taglib.ui.calendar.page_jsp.java
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null;/*from w w w . j av a 2 s .c o m*/ HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; /** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); // liferay-theme:defineObjects com.liferay.taglib.theme.DefineObjectsTag _jspx_th_liferay_002dtheme_005fdefineObjects_005f0 = (com.liferay.taglib.theme.DefineObjectsTag) _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .get(com.liferay.taglib.theme.DefineObjectsTag.class); _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setPageContext(_jspx_page_context); _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setParent(null); int _jspx_eval_liferay_002dtheme_005fdefineObjects_005f0 = _jspx_th_liferay_002dtheme_005fdefineObjects_005f0 .doStartTag(); if (_jspx_th_liferay_002dtheme_005fdefineObjects_005f0 .doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0); return; } _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0); com.liferay.portal.theme.ThemeDisplay themeDisplay = null; com.liferay.portal.model.Company company = null; com.liferay.portal.model.Account account = null; com.liferay.portal.model.User user = null; com.liferay.portal.model.User realUser = null; com.liferay.portal.model.Contact contact = null; com.liferay.portal.model.Layout layout = null; java.util.List layouts = null; java.lang.Long plid = null; com.liferay.portal.model.LayoutTypePortlet layoutTypePortlet = null; java.lang.Long scopeGroupId = null; com.liferay.portal.security.permission.PermissionChecker permissionChecker = null; java.util.Locale locale = null; java.util.TimeZone timeZone = null; com.liferay.portal.model.Theme theme = null; com.liferay.portal.model.ColorScheme colorScheme = null; com.liferay.portal.theme.PortletDisplay portletDisplay = null; java.lang.Long portletGroupId = null; themeDisplay = (com.liferay.portal.theme.ThemeDisplay) _jspx_page_context.findAttribute("themeDisplay"); company = (com.liferay.portal.model.Company) _jspx_page_context.findAttribute("company"); account = (com.liferay.portal.model.Account) _jspx_page_context.findAttribute("account"); user = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("user"); realUser = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("realUser"); contact = (com.liferay.portal.model.Contact) _jspx_page_context.findAttribute("contact"); layout = (com.liferay.portal.model.Layout) _jspx_page_context.findAttribute("layout"); layouts = (java.util.List) _jspx_page_context.findAttribute("layouts"); plid = (java.lang.Long) _jspx_page_context.findAttribute("plid"); layoutTypePortlet = (com.liferay.portal.model.LayoutTypePortlet) _jspx_page_context .findAttribute("layoutTypePortlet"); scopeGroupId = (java.lang.Long) _jspx_page_context.findAttribute("scopeGroupId"); permissionChecker = (com.liferay.portal.security.permission.PermissionChecker) _jspx_page_context .findAttribute("permissionChecker"); locale = (java.util.Locale) _jspx_page_context.findAttribute("locale"); timeZone = (java.util.TimeZone) _jspx_page_context.findAttribute("timeZone"); theme = (com.liferay.portal.model.Theme) _jspx_page_context.findAttribute("theme"); colorScheme = (com.liferay.portal.model.ColorScheme) _jspx_page_context.findAttribute("colorScheme"); portletDisplay = (com.liferay.portal.theme.PortletDisplay) _jspx_page_context .findAttribute("portletDisplay"); portletGroupId = (java.lang.Long) _jspx_page_context.findAttribute("portletGroupId"); out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ out.write('\n'); out.write('\n'); PortletRequest portletRequest = (PortletRequest) request .getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST); PortletResponse portletResponse = (PortletResponse) request .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE); String namespace = StringPool.BLANK; boolean useNamespace = GetterUtil.getBoolean((String) request.getAttribute("aui:form:useNamespace"), true); if ((portletResponse != null) && useNamespace) { namespace = portletResponse.getNamespace(); } String currentURL = PortalUtil.getCurrentURL(request); out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ out.write('\n'); out.write('\n'); out.write('\n'); out.write('\n'); int month = GetterUtil.getInteger((String) request.getAttribute("liferay-ui:calendar:month")); int day = GetterUtil.getInteger((String) request.getAttribute("liferay-ui:calendar:day")); int year = GetterUtil.getInteger((String) request.getAttribute("liferay-ui:calendar:year")); String headerPattern = (String) request.getAttribute("liferay-ui:calendar:headerPattern"); Format headerFormat = (Format) request.getAttribute("liferay-ui:calendar:headerFormat"); Set data = (Set) request.getAttribute("liferay-ui:calendar:data"); boolean showAllPotentialWeeks = GetterUtil .getBoolean((String) request.getAttribute("liferay-ui:calendar:showAllPotentialWeeks")); Calendar selCal = CalendarFactoryUtil.getCalendar(timeZone, locale); selCal.set(Calendar.MONTH, month); selCal.set(Calendar.DATE, day); selCal.set(Calendar.YEAR, year); int selMonth = selCal.get(Calendar.MONTH); int selDay = selCal.get(Calendar.DATE); int selYear = selCal.get(Calendar.YEAR); int maxDayOfMonth = selCal.getActualMaximum(Calendar.DATE); selCal.set(Calendar.DATE, 1); int dayOfWeek = selCal.get(Calendar.DAY_OF_WEEK); selCal.set(Calendar.DATE, selDay); Calendar curCal = CalendarFactoryUtil.getCalendar(timeZone, locale); int curMonth = curCal.get(Calendar.MONTH); int curDay = curCal.get(Calendar.DATE); int curYear = curCal.get(Calendar.YEAR); Calendar prevCal = (Calendar) selCal.clone(); prevCal.add(Calendar.MONTH, -1); int maxDayOfPrevMonth = prevCal.getActualMaximum(Calendar.DATE); int weekNumber = 1; out.write("\n"); out.write("\n"); out.write("<div class=\"taglib-calendar\">\n"); out.write("\t<table class=\"lfr-table calendar-panel\">\n"); out.write("\n"); out.write("\t"); // c:if org.apache.taglibs.standard.tag.rt.core.IfTag _jspx_th_c_005fif_005f0 = (org.apache.taglibs.standard.tag.rt.core.IfTag) _005fjspx_005ftagPool_005fc_005fif_0026_005ftest .get(org.apache.taglibs.standard.tag.rt.core.IfTag.class); _jspx_th_c_005fif_005f0.setPageContext(_jspx_page_context); _jspx_th_c_005fif_005f0.setParent(null); // /html/taglib/ui/calendar/page.jsp(61,1) name = test type = boolean reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null _jspx_th_c_005fif_005f0.setTest(Validator.isNotNull(headerPattern) || (headerFormat != null)); int _jspx_eval_c_005fif_005f0 = _jspx_th_c_005fif_005f0.doStartTag(); if (_jspx_eval_c_005fif_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) { do { out.write("\n"); out.write("\n"); out.write("\t\t"); Format dateFormat = headerFormat; if (Validator.isNotNull(headerPattern)) { dateFormat = FastDateFormatFactoryUtil.getSimpleDateFormat(headerPattern, locale); } out.write("\n"); out.write("\n"); out.write("\t\t<tr class=\"calendar-header\">\n"); out.write("\t\t\t<th colspan=\"7\">\n"); out.write("\t\t\t\t"); out.print(dateFormat.format(selCal.getTime())); out.write("\n"); out.write("\t\t\t</th>\n"); out.write("\t\t</tr>\n"); out.write("\t"); int evalDoAfterBody = _jspx_th_c_005fif_005f0.doAfterBody(); if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) break; } while (true); } if (_jspx_th_c_005fif_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f0); return; } _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f0); out.write("\n"); out.write("\n"); out.write("\t<tr class=\"portlet-section-header results-header\">\n"); out.write("\n"); out.write("\t\t"); for (int i = 0; i < 7; i++) { int daysIndex = (selCal.getFirstDayOfWeek() + i - 1) % 7; String className = StringPool.BLANK; if (i == 0) { className = "first"; } else if (i == 6) { className = "last"; } out.write("\n"); out.write("\n"); out.write("\t\t\t<th class=\""); out.print(className); out.write("\">\n"); out.write("\t\t\t\t"); out.print(LanguageUtil.get(pageContext, CalendarUtil.DAYS_ABBREVIATION[daysIndex])); out.write("\n"); out.write("\t\t\t</th>\n"); out.write("\n"); out.write("\t\t"); } out.write("\n"); out.write("\n"); out.write("\t</tr>\n"); out.write("\t<tr>\n"); out.write("\n"); out.write("\t\t"); if (((selCal.getFirstDayOfWeek()) == Calendar.MONDAY)) { if (dayOfWeek == 1) { dayOfWeek += 6; } else { dayOfWeek--; } } maxDayOfPrevMonth = (maxDayOfPrevMonth - dayOfWeek) + 1; for (int i = 1; i < dayOfWeek; i++) { String className = "calendar-inactive calendar-previous-month"; if (i == 1) { className += " first"; } else if (i == 7) { className += " last"; } out.write("\n"); out.write("\n"); out.write("\t\t\t<td class=\""); out.print(className); out.write('"'); out.write('>'); out.print(maxDayOfPrevMonth + i); out.write("</td>\n"); out.write("\n"); out.write("\t\t"); } for (int i = 1; i <= maxDayOfMonth; i++) { if (dayOfWeek > 7) { out.write("\n"); out.write("\n"); out.write("\t\t\t\t</tr>\n"); out.write("\t\t\t\t<tr>\n"); out.write("\n"); out.write("\t\t"); dayOfWeek = 1; weekNumber++; } Calendar tempCal = (Calendar) selCal.clone(); tempCal.set(Calendar.MONTH, selMonth); tempCal.set(Calendar.DATE, i); tempCal.set(Calendar.YEAR, selYear); boolean hasData = (data != null) && data.contains(new Integer(i)); String className = ""; if ((selMonth == curMonth) && (i == curDay) && (selYear == curYear)) { className = "calendar-current-day portlet-section-selected"; } if (hasData) { className += " has-events"; } if (dayOfWeek == 1) { className += " first"; } else if (dayOfWeek == 7) { className += " last"; } dayOfWeek++; out.write("\n"); out.write("\n"); out.write("\t\t\t<td class=\""); out.print(className); out.write("\">\n"); out.write("\t\t\t\t<a href=\"javascript:"); out.print(namespace); out.write("updateCalendar("); out.print(selMonth); out.write(','); out.write(' '); out.print(i); out.write(','); out.write(' '); out.print(selYear); out.write(");\"><span>"); out.print(i); out.write("</span></a>\n"); out.write("\t\t\t</td>\n"); out.write("\n"); out.write("\t\t"); } int dayOfNextMonth = 1; for (int i = 7; i >= dayOfWeek; i--) { String className = "calendar-inactive calendar-next-month"; if (dayOfWeek == 1) { className += " first"; } else if (i == dayOfWeek) { className += " last"; } out.write("\n"); out.write("\n"); out.write("\t\t\t<td class=\""); out.print(className); out.write('"'); out.write('>'); out.print(dayOfNextMonth++); out.write("</td>\n"); out.write("\n"); out.write("\t\t"); } if (showAllPotentialWeeks && weekNumber < 6) { out.write("\n"); out.write("\n"); out.write("\t\t\t<tr>\n"); out.write("\n"); out.write("\t\t\t\t"); for (int i = 1; i <= 7; i++) { String className = "calendar-inactive calendar-next-month"; if (i == 1) { className += " first"; } else if (i == 7) { className += " last"; } out.write("\n"); out.write("\n"); out.write("\t\t\t\t\t<td class=\""); out.print(className); out.write('"'); out.write('>'); out.print(dayOfNextMonth++); out.write("</td>\n"); out.write("\n"); out.write("\t\t\t\t"); } out.write("\n"); out.write("\n"); out.write("\t\t\t</tr>\n"); out.write("\n"); out.write("\t\t"); } out.write("\n"); out.write("\n"); out.write("\t</tr>\n"); out.write("\t</table>\n"); out.write("</div>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { out.clearBuffer(); } catch (java.io.IOException e) { } if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
From source file:org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand.java
/** * Create action instances starting from "startMatdTime" to "endMatdTime" and store them into coord action table. * * @param dryrun if this is a dry run// w w w. ja v a 2 s . c o m * @throws Exception thrown if failed to materialize actions */ protected String materializeActions(boolean dryrun) throws Exception { Configuration jobConf = null; try { jobConf = new XConfiguration(new StringReader(coordJob.getConf())); } catch (IOException ioe) { LOG.warn("Configuration parse error. read from DB :" + coordJob.getConf(), ioe); throw new CommandException(ErrorCode.E1005, ioe.getMessage(), ioe); } String jobXml = coordJob.getJobXml(); Element eJob = XmlUtils.parseXml(jobXml); TimeZone appTz = DateUtils.getTimeZone(coordJob.getTimeZone()); String frequency = coordJob.getFrequency(); TimeUnit freqTU = TimeUnit.valueOf(coordJob.getTimeUnitStr()); TimeUnit endOfFlag = TimeUnit.valueOf(eJob.getAttributeValue("end_of_duration")); Calendar start = Calendar.getInstance(appTz); start.setTime(startMatdTime); DateUtils.moveToEnd(start, endOfFlag); Calendar end = Calendar.getInstance(appTz); end.setTime(endMatdTime); lastActionNumber = coordJob.getLastActionNumber(); //Intentionally printing dates in their own timezone, not Oozie timezone LOG.info("materialize actions for tz=" + appTz.getDisplayName() + ",\n start=" + start.getTime() + ", end=" + end.getTime() + ",\n timeUnit " + freqTU.getCalendarUnit() + ",\n frequency :" + frequency + ":" + freqTU + ",\n lastActionNumber " + lastActionNumber); // Keep the actual start time Calendar origStart = Calendar.getInstance(appTz); origStart.setTime(coordJob.getStartTimestamp()); // Move to the End of duration, if needed. DateUtils.moveToEnd(origStart, endOfFlag); StringBuilder actionStrings = new StringBuilder(); Date jobPauseTime = coordJob.getPauseTime(); Calendar pause = null; if (jobPauseTime != null) { pause = Calendar.getInstance(appTz); pause.setTime(DateUtils.convertDateToTimestamp(jobPauseTime)); } String action = null; int numWaitingActions = dryrun ? 0 : jpaService.execute(new CoordActionsActiveCountJPAExecutor(coordJob.getId())); int maxActionToBeCreated = coordJob.getMatThrottling() - numWaitingActions; // If LAST_ONLY and all materialization is in the past, ignore maxActionsToBeCreated boolean ignoreMaxActions = (coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.LAST_ONLY) || coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.NONE)) && endMatdTime.before(new Date()); LOG.debug("Coordinator job :" + coordJob.getId() + ", maxActionToBeCreated :" + maxActionToBeCreated + ", Mat_Throttle :" + coordJob.getMatThrottling() + ", numWaitingActions :" + numWaitingActions); boolean isCronFrequency = false; Calendar effStart = (Calendar) start.clone(); try { int intFrequency = Integer.parseInt(coordJob.getFrequency()); effStart = (Calendar) origStart.clone(); effStart.add(freqTU.getCalendarUnit(), lastActionNumber * intFrequency); } catch (NumberFormatException e) { isCronFrequency = true; } boolean firstMater = true; while (effStart.compareTo(end) < 0 && (ignoreMaxActions || maxActionToBeCreated-- > 0)) { if (pause != null && effStart.compareTo(pause) >= 0) { break; } Date nextTime = effStart.getTime(); if (isCronFrequency) { if (effStart.getTime().compareTo(startMatdTime) == 0 && firstMater) { effStart.add(Calendar.MINUTE, -1); firstMater = false; } nextTime = CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob); effStart.setTime(nextTime); } if (effStart.compareTo(end) < 0) { if (pause != null && effStart.compareTo(pause) >= 0) { break; } CoordinatorActionBean actionBean = new CoordinatorActionBean(); lastActionNumber++; int timeout = coordJob.getTimeout(); LOG.debug("Materializing action for time=" + DateUtils.formatDateOozieTZ(effStart.getTime()) + ", lastactionnumber=" + lastActionNumber + " timeout=" + timeout + " minutes"); Date actualTime = new Date(); action = CoordCommandUtils.materializeOneInstance(jobId, dryrun, (Element) eJob.clone(), nextTime, actualTime, lastActionNumber, jobConf, actionBean); actionBean.setTimeOut(timeout); if (!dryrun) { storeToDB(actionBean, action, jobConf); // Storing to table } else { actionStrings.append("action for new instance"); actionStrings.append(action); } } else { break; } if (!isCronFrequency) { effStart = (Calendar) origStart.clone(); effStart.add(freqTU.getCalendarUnit(), lastActionNumber * Integer.parseInt(coordJob.getFrequency())); } } if (isCronFrequency) { if (effStart.compareTo(end) < 0 && !(ignoreMaxActions || maxActionToBeCreated-- > 0)) { //Since we exceed the throttle, we need to move the nextMadtime forward //to avoid creating duplicate actions if (!firstMater) { effStart.setTime( CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob)); } } } endMatdTime = effStart.getTime(); if (!dryrun) { return action; } else { return actionStrings.toString(); } }
From source file:org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment.java
/** * Creates dialog/*from w w w . java 2s. com*/ */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); long creation = getArguments().getLong(ARG_CREATION); long expiry = getArguments().getLong(ARG_EXPIRY); final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationCal.setTimeInMillis(creation * 1000); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTimeInMillis(expiry * 1000); // date picker works with default time zone, we need to convert from UTC to default timezone creationCal.setTimeZone(TimeZone.getDefault()); expiryCal.setTimeZone(TimeZone.getDefault()); // Explicitly not using DatePickerDialog here! // DatePickerDialog is difficult to customize and has many problems (see old git versions) CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.expiry_date_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.edit_subkey_expiry_dialog, null); alert.setView(view); final CheckBox noExpiry = (CheckBox) view.findViewById(R.id.edit_subkey_expiry_no_expiry); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.edit_subkey_expiry_date_picker); final TextView currentExpiry = (TextView) view.findViewById(R.id.edit_subkey_expiry_current_expiry); final LinearLayout expiryLayout = (LinearLayout) view.findViewById(R.id.edit_subkey_expiry_layout); noExpiry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { expiryLayout.setVisibility(View.GONE); } else { expiryLayout.setVisibility(View.VISIBLE); } } }); if (expiry == 0L) { noExpiry.setChecked(true); expiryLayout.setVisibility(View.GONE); currentExpiry.setText(R.string.btn_no_date); } else { noExpiry.setChecked(false); expiryLayout.setVisibility(View.VISIBLE); currentExpiry.setText(DateFormat.getDateFormat(getActivity()).format(expiryCal.getTime())); } // date picker works based on default time zone Calendar todayCal = Calendar.getInstance(TimeZone.getDefault()); if (creationCal.after(todayCal)) { // NOTE: This is just for the rare cases where creation is _after_ today // Min Date: Creation date + 1 day Calendar creationCalPlusOne = (Calendar) creationCal.clone(); creationCalPlusOne.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(creationCalPlusOne.getTime().getTime()); datePicker.init(creationCalPlusOne.get(Calendar.YEAR), creationCalPlusOne.get(Calendar.MONTH), creationCalPlusOne.get(Calendar.DAY_OF_MONTH), null); } else { // Min Date: today + 1 day // at least one day after creation (today) todayCal.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(todayCal.getTime().getTime()); datePicker.init(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH), todayCal.get(Calendar.DAY_OF_MONTH), null); } alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); long expiry; if (noExpiry.isChecked()) { expiry = 0L; } else { Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault()); //noinspection ResourceType selectedCal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); // date picker uses default time zone, we need to convert to UTC selectedCal.setTimeZone(TimeZone.getTimeZone("UTC")); long numDays = (selectedCal.getTimeInMillis() / 86400000) - (creationCal.getTimeInMillis() / 86400000); if (numDays <= 0) { Activity activity = getActivity(); if (activity != null) { Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show(); } return; } expiry = selectedCal.getTime().getTime() / 1000; } Bundle data = new Bundle(); data.putSerializable(MESSAGE_DATA_EXPIRY, expiry); sendMessageToHandler(MESSAGE_NEW_EXPIRY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.show(); }
From source file:org.oscarehr.managers.ScheduleManager.java
public DayWorkSchedule getDayWorkSchedule(String providerNo, Calendar date) { // algorithm//from w w w .j a v a 2 s .c o m //---------- // select entries from scheduledate for the given day/provider where status = 'A' (for active?) // "hour" setting is the template to apply, i.e. template name // select entry from scheduletemplate to get the template to apply for the given day // timecode is a breakdown of the day into equal slots, where _ means nothing and some letter means a code in scheduletemplatecode // The only way to know the duration of the time code is to divide it up, i.e. minutes_per_day/timecode.length, i.e. 1440 minutes per second / 96 length = 15 minutes per slot. // For each time slot, then look up the scheduletemplatecode DayWorkSchedule dayWorkSchedule = new DayWorkSchedule(); ScheduleHoliday scheduleHoliday = scheduleHolidayDao.find(date.getTime()); dayWorkSchedule.setHoliday(scheduleHoliday != null); ScheduleDate scheduleDate = scheduleDateDao.findByProviderNoAndDate(providerNo, date.getTime()); if (scheduleDate == null) { logger.debug( "No scheduledate for date requested. providerNo=" + providerNo + ", date=" + date.getTime()); return (null); } String scheduleTemplateName = scheduleDate.getHour(); // okay this is a mess, the ScheduleTemplate is messed up because no one links there via a PK, they only link there via the name column // and the name column isn't unique... so... we will have to do a search for the right template. // first we'll check under the providersId, if not we'll check under the public id. ScheduleTemplatePrimaryKey scheduleTemplatePrimaryKey = new ScheduleTemplatePrimaryKey(providerNo, scheduleTemplateName); ScheduleTemplate scheduleTemplate = scheduleTemplateDao.find(scheduleTemplatePrimaryKey); if (scheduleTemplate == null) { scheduleTemplatePrimaryKey = new ScheduleTemplatePrimaryKey( ScheduleTemplatePrimaryKey.DODGY_FAKE_PROVIDER_NO_USED_TO_HOLD_PUBLIC_TEMPLATES, scheduleTemplateName); scheduleTemplate = scheduleTemplateDao.find(scheduleTemplatePrimaryKey); } // if it's still null, then ignore it as there's no schedule for the day. if (scheduleTemplate != null) { // time interval String timecode = scheduleTemplate.getTimecode(); int timeSlotDuration = (60 * 24) / timecode.length(); dayWorkSchedule.setTimeSlotDurationMin(timeSlotDuration); // sort out designated timeslots and their purpose Calendar timeSlot = (Calendar) date.clone(); //make sure the appts returned are in local time. timeSlot.setTimeZone(Calendar.getInstance().getTimeZone()); timeSlot = DateUtils.truncate(timeSlot, Calendar.DAY_OF_MONTH); TreeMap<Calendar, Character> allTimeSlots = dayWorkSchedule.getTimeSlots(); for (int i = 0; i < timecode.length(); i++) { // ignore _ because that's a blank place holder identifier... also not my fault, just processing what's been already written. if ('_' != timecode.charAt(i)) { allTimeSlots.put((Calendar) timeSlot.clone(), timecode.charAt(i)); } timeSlot.add(GregorianCalendar.MINUTE, timeSlotDuration); } } // This method will not log access as the schedule is not private medical data. return (dayWorkSchedule); }
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
@Override public StatisticalResultDTO getSimulateConversionGraph(final ConversionSimulationDTO input) { final LocalSettings localSettings = settingsService.getLocalSettings(); final byte precision = (byte) localSettings.getPrecision().getValue(); // get series final TransactionFeePreviewForRatesDTO temp = simulateConversion(input); final int series = temp.getFees().size(); // get range of points, but without values for A < 0 BigDecimal initialARate = null; RatesResultDTO rates = new RatesResultDTO(); if (input.isUseActualRates()) { rates = rateService.getRatesForTransferFrom(input.getAccount(), input.getAmount(), null); rates.setDate(input.getDate());// w w w . java 2s. c o m initialARate = rates.getaRate(); } else { initialARate = input.getArate(); } // lowerlimit takes care that values for A < 0 are left out of the graph final Double lowerLimit = (initialARate == null) ? null : initialARate.negate().doubleValue(); final Number[] xRange = GraphHelper.getOptimalRangeAround(0, 33, 0, 0.8, lowerLimit); // Data structure to build the table final Number[][] tableCells = new Number[xRange.length][series]; // initialize series names and x labels final String[] seriesNames = new String[series]; final byte[] seriesOrder = new byte[series]; final Calendar[] xPointDates = new Calendar[xRange.length]; final Calendar now = Calendar.getInstance(); BigDecimal inputARate = temp.getARate(); BigDecimal inputDRate = temp.getDRate(); // assign data for (int i = 0; i < xRange.length; i++) { final ConversionSimulationDTO inputPointX = (ConversionSimulationDTO) input.clone(); final Calendar date = (Calendar) ((input.isUseActualRates()) ? input.getDate().clone() : now.clone()); date.add(Calendar.DAY_OF_YEAR, xRange[i].intValue()); xPointDates[i] = date; // Set useActualRates for this input to false, otherwise simulateConversion will use the account's the balance and rates of that date, and // we don't want that. inputPointX.setUseActualRates(false); if (inputARate != null) { final BigDecimal aRate = inputARate.add(new BigDecimal(xRange[i].doubleValue())); inputPointX.setArate(aRate); } if (inputDRate != null) { final BigDecimal dRate = inputDRate.subtract(new BigDecimal(xRange[i].doubleValue())); inputPointX.setDrate(dRate); } final TransactionFeePreviewDTO tempResult = simulateConversion(inputPointX); int j = 0; for (final TransactionFee fee : tempResult.getFees().keySet()) { tableCells[i][j] = new StatisticalNumber(tempResult.getFees().get(fee).doubleValue(), precision); byte index; switch (fee.getChargeType()) { case D_RATE: index = 2; break; case A_RATE: case MIXED_A_D_RATES: index = 3; break; default: index = 1; break; } seriesOrder[j] = index; seriesNames[j++] = fee.getName(); } } // create the graph object final StatisticalResultDTO result = new StatisticalResultDTO(tableCells); result.setBaseKey("conversionSimulation.result.graph"); result.setHelpFile("account_management"); // date labels along x-axis final String[] rowKeys = new String[xRange.length]; Arrays.fill(rowKeys, ""); result.setRowKeys(rowKeys); for (int i = 0; i < rowKeys.length; i++) { final String rowHeader = localSettings.getDateConverterForGraphs().toString(xPointDates[i]); result.setRowHeader(rowHeader, i); } // mark the actual date upon which the x-axis is based as a vertical line final Calendar baseDate = (input.isUseActualRates()) ? (Calendar) input.getDate().clone() : now; final String baseDateString = localSettings.getDateConverterForGraphs().toString(baseDate); final Marker[] markers = new Marker[1]; markers[0] = new CategoryMarker(baseDateString); markers[0].setPaint(Color.ORANGE); final String todayString = localSettings.getDateConverterForGraphs().toString(now); if (todayString.equals(baseDateString)) { markers[0].setLabel("global.today"); } result.setDomainMarkers(markers); // Series labels indicate fee names final String[] columnKeys = new String[series]; Arrays.fill(columnKeys, ""); result.setColumnKeys(columnKeys); for (int j = 0; j < columnKeys.length; j++) { result.setColumnHeader(seriesNames[j], j); } // order the series result.orderSeries(seriesOrder); final TransferType tt = fetchService.fetch(input.getTransferType(), RelationshipHelper.nested(TransferType.Relationships.FROM, AccountType.Relationships.CURRENCY)); result.setYAxisUnits(tt.getCurrency().getSymbol()); result.setShowTable(false); result.setGraphType(StatisticalResultDTO.GraphType.STACKED_AREA); return result; }
From source file:org.apache.oozie.coord.CoordELFunctions.java
private static String coord_latestRange_sync(int startOffset, int endOffset) throws Exception { final XLog LOG = XLog.getLog(CoordELFunctions.class); final Thread currentThread = Thread.currentThread(); ELEvaluator eval = ELEvaluator.getCurrent(); String retVal = ""; int datasetFrequency = (int) getDSFrequency();// in minutes TimeUnit dsTimeUnit = getDSTimeUnit(); int[] instCount = new int[1]; boolean useCurrentTime = Services.get().getConf().getBoolean(LATEST_EL_USE_CURRENT_TIME, false); Calendar nominalInstanceCal;// w ww. jav a 2s .c o m if (useCurrentTime) { nominalInstanceCal = getCurrentInstance(new Date(), instCount); } else { nominalInstanceCal = getCurrentInstance(getActualTime(), instCount); } StringBuilder resolvedInstances = new StringBuilder(); StringBuilder resolvedURIPaths = new StringBuilder(); if (nominalInstanceCal != null) { Calendar initInstance = getInitialInstanceCal(); SyncCoordDataset ds = (SyncCoordDataset) eval.getVariable(DATASET); if (ds == null) { throw new RuntimeException("Associated Dataset should be defined with key " + DATASET); } String uriTemplate = ds.getUriTemplate(); Configuration conf = (Configuration) eval.getVariable(CONFIGURATION); if (conf == null) { throw new RuntimeException("Associated Configuration should be defined with key " + CONFIGURATION); } int available = 0; boolean resolved = false; String user = ParamChecker.notEmpty((String) eval.getVariable(OozieClient.USER_NAME), OozieClient.USER_NAME); String doneFlag = ds.getDoneFlag(); URIHandlerService uriService = Services.get().get(URIHandlerService.class); URIHandler uriHandler = null; Context uriContext = null; try { while (nominalInstanceCal.compareTo(initInstance) >= 0 && !currentThread.isInterrupted()) { ELEvaluator uriEval = getUriEvaluator(nominalInstanceCal); String uriPath = uriEval.evaluate(uriTemplate, String.class); if (uriHandler == null) { URI uri = new URI(uriPath); uriHandler = uriService.getURIHandler(uri); uriContext = uriHandler.getContext(uri, conf, user, true); } String uriWithDoneFlag = uriHandler.getURIWithDoneFlag(uriPath, doneFlag); if (uriHandler.exists(new URI(uriWithDoneFlag), uriContext)) { XLog.getLog(CoordELFunctions.class) .debug("Found latest(" + available + "): " + uriWithDoneFlag); if (available == startOffset) { LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag); resolved = true; resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal)); resolvedURIPaths.append(uriPath); retVal = resolvedInstances.toString(); eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString()); break; } else if (available <= endOffset) { LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag); resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal)) .append(INSTANCE_SEPARATOR); resolvedURIPaths.append(uriPath).append(INSTANCE_SEPARATOR); } available--; } // nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), -datasetFrequency); nominalInstanceCal = (Calendar) initInstance.clone(); instCount[0]--; nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), instCount[0] * datasetFrequency); // DateUtils.moveToEnd(nominalInstanceCal, getDSEndOfFlag()); } if (!StringUtils.isEmpty(resolvedURIPaths.toString()) && eval.getVariable(CoordELConstants.RESOLVED_PATH) == null) { eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString()); } } finally { if (uriContext != null) { uriContext.destroy(); } } if (!resolved) { // return unchanged latest function with variable 'is_resolved' // to 'false' eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE); if (startOffset == endOffset) { retVal = "${coord:latest(" + startOffset + ")}"; } else { retVal = "${coord:latestRange(" + startOffset + "," + endOffset + ")}"; } } else { eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.TRUE); } } else {// No feasible nominal time eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE); } return retVal; }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ?// w w w. j a va2s .com * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList6(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } DeptCode4Yun yun = new DeptCode4Yun(); yun.setClassNo("___" + codeEmpls.get(0).getIdno2().trim()); Example example = Example.create(yun).ignoreCase().enableLike(MatchMode.START); List<Order> orders = new LinkedList<Order>(); orders.add(Order.asc("classNo")); List<DeptCode4Yun> yuns = (List<DeptCode4Yun>) am.findSQLWithCriteria(DeptCode4Yun.class, example, null, orders); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("?"); sheet.setColumnWidth(0, 2000); sheet.setColumnWidth(1, 6000); sheet.setColumnWidth(2, 4000); sheet.setColumnWidth(3, 3000); sheet.setColumnWidth(4, 6000); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); HSSFFont fontSize12 = workbook.createFont(); fontSize12.setFontHeightInPoints((short) 12); fontSize12.setFontName("Arial Unicode MS"); HSSFFont fontSize10 = workbook.createFont(); fontSize10.setFontHeightInPoints((short) 10); fontSize10.setFontName("Arial Unicode MS"); // Header Toolket.setCellValue(workbook, sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + "? (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ")", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); // Column Header Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 2, "????", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 3, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); int index = 2; String sql = "SELECT s.student_no ST1, gs.student_no ST2 " + "FROM StdSkill ss LEFT JOIN stmd s ON ss.studentNo = s.student_no " + "LEFT JOIN Gstmd gs ON ss.studentNo = gs.student_no " + "WHERE ss.deptNo = ? AND ss.licenseValidDate BETWEEN ? AND ? " + "AND (s.depart_class LIKE ? OR gs.depart_class LIKE ?)"; String classNo = null; List<Map> ret = null; Set<String> set = new HashSet<String>(); for (DeptCode4Yun y : yuns) { classNo = y.getClassNo() + "%"; ret = (List<Map>) am.findBySQL(sql, new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime(), classNo, classNo }); set = new HashSet<String>(); if (!ret.isEmpty()) { for (Map o : ret) { if (o.get("ST1") != null) set.add((String) o.get("ST1")); else if (o.get("ST2") != null) set.add((String) o.get("ST2")); } if (!set.isEmpty()) { Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 1, y.getCampusName(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 2, y.getDeptName(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 3, String.valueOf(set.size()), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index++, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } } } index++; Toolket.setCellValue(workbook, sheet, index, 4, "", fontSize10, HSSFCellStyle.ALIGN_RIGHT, false, null); File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList6.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }