List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:com.esd.ps.LoginController.java
/** * ,//from ww w.jav a2 s.com * @return */ @RequestMapping(value = "/moneyList", method = RequestMethod.POST) @ResponseBody public Map<String, Object> moneyListPost() { Map<String, Object> map = new HashMap<String, Object>(); // Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int week = cal.get(Calendar.DAY_OF_WEEK); // if (week == 7) { week = 0; } //logger.debug("week:{}",week); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // ()? GregorianCalendar gc = new GregorianCalendar(); // ?? gc.setTime(new Date()); // ?? gc.add(5, -week); // String beginDate = sdf.format(gc.getTime()); String endDate = sdf.format(new Date()); SimpleDateFormat sdf1 = new SimpleDateFormat("MMdd"); String beginDate1 = sdf1.format(gc.getTime()); String endDate1 = sdf1.format(new Date()); //logger.debug("beginDate:{},endDate:{}",beginDate,endDate); manager manager = managerService.selectByPrimaryKey(1); List<Map<String, Object>> monthList = salaryService.getMoneyList("", "", endDate); List<Map<String, Object>> weekList = salaryService.getMoneyList(beginDate, endDate, ""); List<Map<String, Object>> totleList = salaryService.getMoneyList("", "", ""); map.put("salary", manager.getSalary()); map.put("monthList", monthList); map.put("weekList", weekList); map.put("totleList", totleList); map.put("weekDate", beginDate1 + "-" + endDate1); return map; }
From source file:fr.paris.lutece.plugins.calendar.service.XMLUtils.java
/** * Get the XML of a calendar//w w w . j a v a2s.c o m * @param local The locale * @param cal The calendar * @param request The request * @return The XML */ public static String getXMLPortletCalendar(Locale local, Calendar cal, HttpServletRequest request) { StringBuffer strXml = new StringBuffer(); String strDay = null; Calendar calendar = new GregorianCalendar(); //Set the calendar in the beginning of the month calendar.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //If day of week is sunday: nDayOfWeek = 8 if (nDayOfWeek == 1) { nDayOfWeek = 8; } Calendar calendar2 = new GregorianCalendar(); calendar2.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), calendar.getMaximum(Calendar.DAY_OF_MONTH)); //Beginning of the main xml block: month XmlUtil.beginElement(strXml, TAG_AGENDA_MONTH); String strBaseUrl = AppPathService.getPortalUrl(); UrlItem urlMonth = new UrlItem(strBaseUrl); urlMonth.addParameter(Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME); urlMonth.addParameter(Constants.PARAMETER_ACTION, Constants.ACTION_DO_SEARCH); urlMonth.addParameter(Constants.PARAMETER_DATE_START, DateUtil.getDateString(calendar.getTime(), local)); urlMonth.addParameter(Constants.PARAMETER_DATE_END, DateUtil.getDateString(calendar2.getTime(), local)); urlMonth.addParameter(Constants.PARAMETER_PERIOD, Constants.PROPERTY_PERIOD_RANGE); String strMonthLabel = Utils.getMonthLabel(Utils.getDate(calendar), local); String strUrlMonth = BEGIN_A_TAG + urlMonth.getUrl() + "\">" + strMonthLabel + END_A_TAG; XmlUtil.addElementHtml(strXml, TAG_AGENDA_MONTH_LABEL, strUrlMonth); //Shortcut tags //Begenning of the xml block: week-shortcuts XmlUtil.beginElement(strXml, TAG_WEEK_SHORTCUTS); //Today shortcut XmlUtil.beginElement(strXml, TAG_WEEK_SHORTCUT); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTCUT_TODAY, local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_PERIOD, Constants.PROPERTY_PERIOD_TODAY); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_START, DateUtil.getDateString(new Date(), local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_END, DateUtil.getDateString(new Date(), local)); XmlUtil.endElement(strXml, TAG_WEEK_SHORTCUT); //Tomorrow shortcut Calendar calTomorrow = new GregorianCalendar(); calTomorrow.add(Calendar.DATE, 1); XmlUtil.beginElement(strXml, TAG_WEEK_SHORTCUT); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTCUT_TOMORROW, local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_PERIOD, Constants.PROPERTY_PERIOD_RANGE); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_START, DateUtil.getDateString(calTomorrow.getTime(), local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_END, DateUtil.getDateString(calTomorrow.getTime(), local)); XmlUtil.endElement(strXml, TAG_WEEK_SHORTCUT); //Week shortcut Date dateBeginWeek = null; Date dateEndWeek = null; Calendar calendarToday = new GregorianCalendar(); Calendar calendarFirstDay = Calendar.getInstance(); Calendar calendarLastDay = new GregorianCalendar(); calendarFirstDay = calendarToday; calendarFirstDay.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); calendarLastDay = (GregorianCalendar) calendarFirstDay.clone(); calendarLastDay.add(Calendar.DATE, 6); dateBeginWeek = calendarFirstDay.getTime(); dateEndWeek = calendarLastDay.getTime(); XmlUtil.beginElement(strXml, TAG_WEEK_SHORTCUT); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTCUT_WEEK, local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_PERIOD, Constants.PROPERTY_PERIOD_WEEK); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_START, DateUtil.getDateString(dateBeginWeek, local)); XmlUtil.addElement(strXml, TAG_WEEK_SHORTCUT_DATE_END, DateUtil.getDateString(dateEndWeek, local)); XmlUtil.endElement(strXml, TAG_WEEK_SHORTCUT); //Ending of the xml block: week-shortcuts XmlUtil.endElement(strXml, TAG_WEEK_SHORTCUTS); //Begenning of the xml block: weeks XmlUtil.beginElement(strXml, TAG_AGENDA_WEEKS); //Day label tags XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_MONDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_TUESDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_WEDNESDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_THURSDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_FRIDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_SATURDAY, local)); XmlUtil.addElement(strXml, TAG_AGENDA_DAY_LABEL, I18nService.getLocalizedString(Constants.PROPERTY_SHORTLABEL_SUNDAY, local)); //Check if the month is ended boolean bDone = false; //check if the month is started boolean bStarted = false; //While the month isn't over... while (!bDone) { //Begenning of the xml block: week XmlUtil.beginElement(strXml, TAG_AGENDA_WEEK); for (int i = 0; i < 7; i++) { if ((((i + 2) != nDayOfWeek) && !bStarted) || bDone) { XmlUtil.beginElement(strXml, TAG_AGENDA_DAY); strDay = BEGIN_TD_TAG + getDayClass(calendar) + ">" + PROPERTY_EMPTY_DAY + END_TD_TAG; XmlUtil.addElementHtml(strXml, TAG_AGENDA_DAY_CODE, strDay); XmlUtil.endElement(strXml, TAG_AGENDA_DAY); continue; } bStarted = true; //put parameters in the url UrlItem urlDay = new UrlItem(strBaseUrl); String strPageId = request != null ? request.getParameter(Constants.PARAMETER_PAGE_ID) : StringUtils.EMPTY; if (StringUtils.isNotBlank(strPageId) && StringUtils.isNumeric(strPageId)) { urlDay.addParameter(Constants.PARAMETER_PAGE_ID, strPageId); } urlDay.addParameter(Constants.PARAMETER_DATE, DateUtil.getDateString(calendar.getTime(), local)); //construct on url based on day String strUrlDay = new String(); strUrlDay = BEGIN_A_TAG + urlDay.getUrl() + "\">" + Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)) + END_A_TAG; XmlUtil.beginElement(strXml, TAG_AGENDA_DAY); Date date = Utils.getDate(Utils.getDate(calendar)); Plugin plugin = PluginService.getPlugin(CalendarPlugin.PLUGIN_NAME); String[] arrayCalendarIds = Utils.getCalendarIds(request); List<Event> listEvent = CalendarSearchService.getInstance().getSearchResults(arrayCalendarIds, null, "", date, date, plugin); if (listEvent.size() != 0) { strDay = BEGIN_TD_TAG + Constants.STYLE_CLASS_SMALLMONTH_DAY + Constants.STYLE_CLASS_SUFFIX_EVENT + ">" + BEGIN_BOLD_TAG + strUrlDay + END_BOLD_TAG + END_TD_TAG; } else { strDay = BEGIN_TD_TAG + getDayClass(calendar) + ">" + Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)) + END_TD_TAG; } XmlUtil.addElementHtml(strXml, TAG_AGENDA_DAY_CODE, strDay); XmlUtil.endElement(strXml, TAG_AGENDA_DAY); int nDay = calendar.get(Calendar.DAY_OF_MONTH); calendar.roll(Calendar.DAY_OF_MONTH, true); int nNewDay = calendar.get(Calendar.DAY_OF_MONTH); if (nNewDay < nDay) { bDone = true; } } //Ending of the xml block: week XmlUtil.endElement(strXml, TAG_AGENDA_WEEK); } //Ending of the xml block: weeks XmlUtil.endElement(strXml, TAG_AGENDA_WEEKS); //Ending of the xml block: month XmlUtil.endElement(strXml, TAG_AGENDA_MONTH); return strXml.toString(); }
From source file:org.eevolution.form.VCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);//from w ww . jav a 2 s . co m gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; /* * Vit4B Modificado para que tome 28 dias y * * */ while (day < 29) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code> <code>week</code>. * /* w w w. j av a 2 s. c om*/ * <pre class="code"> * 2015-7-29 14:08 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) =2015-01-02 00:00:00.000 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) =2015-01-05 00:00:00.000 * </pre> * * <p> * {@link Calendar#DAY_OF_WEEK_IN_MONTH} ?. DAY_OF_WEEK ,???.<br> * {@link Calendar#WEEK_OF_MONTH} {@link Calendar#WEEK_OF_YEAR} ??,?? {@link Calendar#getFirstDayOfWeek()} * {@link Calendar#getMinimalDaysInFirstWeek()}. * </p> * * <p> * DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1;<br> * 8 14 DAY_OF_WEEK_IN_MONTH 2,?.<br> * DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ?.<br> * ?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1.<br> * ?,????.<br> * , 31 , DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? * </p> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return <code>date</code> null, {@link NullPointerException} * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); return CalendarUtil.toDate(calendar); }
From source file:egovframework.oe1.cms.com.web.EgovOe1CalRestdeManageController.java
/** * ? // w w w. j a va 2s. com * @param restde * @param model * @return "/cmm/sym/cal/EgovNormalMonthCalendar" * @throws Exception */ @RequestMapping(value = "/com/EgovNormalMonthCalendar.do") public String selectNormalMonthCalendar(EgovOe1Restde restde, ModelMap model) throws Exception { Calendar cal = Calendar.getInstance(); if (restde.getYear() == null || restde.getYear().equals("")) { restde.setYear(Integer.toString(cal.get(Calendar.YEAR))); } if (restde.getMonth() == null || restde.getMonth().equals("")) { restde.setMonth(Integer.toString(cal.get(Calendar.MONTH) + 1)); } int iYear = Integer.parseInt(restde.getYear()); int iMonth = Integer.parseInt(restde.getMonth()); if (iMonth < 1) { iYear--; iMonth = 12; } if (iMonth > 12) { iYear++; iMonth = 1; } if (iYear < 1) { iYear = 1; iMonth = 1; } if (iYear > 9999) { iYear = 9999; iMonth = 12; } restde.setYear(Integer.toString(iYear)); restde.setMonth(Integer.toString(iMonth)); cal.set(iYear, iMonth - 1, 1); restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK)); restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE)); List CalInfoList = restdeManageService.selectNormalRestdePopup(restde); List NormalMonthRestdeList = restdeManageService.selectNormalMonthRestde(restde); model.addAttribute("resultList", CalInfoList); model.addAttribute("RestdeList", NormalMonthRestdeList); return "/cms/com/EgovNormalMonthCalendar"; }
From source file:Holidays.java
public java.util.Calendar MartinLutherKingObserved(int nYear) { // Third Monday in January int nX;//www.j av a2 s .c o m int nMonth = 0; // January java.util.Calendar cal; cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 1); nX = cal.get(Calendar.DAY_OF_WEEK); switch (nX) { case 0: {// Sunday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 16); return cal; } case 1: {// Monday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 15); return cal; } case 2: // Tuesday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 21); return cal; } case 3: // Wednesday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 20); return cal; } case 4: // Thrusday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 19); return cal; } case 5: // Friday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 18); return cal; } default: // Saturday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 17); return cal; } } }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @return interger//from www . j a v a 2 s. co m * @ ? ****************************************/ public static int getWeekNumOfYearDay(String strDate) throws ParseException { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date curDate = format.parse(strDate); int iWeekNum; calendar.setTime(curDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1; } else { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR); } return iWeekNum; }
From source file:Time.java
/** * Return the day of week of this day. NOTE: Must be compared to * Calendar.MONDAY, TUSEDAY etc.// w w w. j a v a2 s . co m * * @return Day of week of this day. */ public int getDayOfWeek() { return calendar_.get(Calendar.DAY_OF_WEEK); }
From source file:edu.stanford.epad.epadws.processing.pipeline.task.EpadStatisticsTask.java
@Override public void run() { try {/*from w w w .j a v a 2s . co m*/ log.info("Getting epad statistics"); EpadStatistics es = new EpadStatistics(); int users = new User().getCount(""); int projects = new Project().getCount(""); int patients = new Subject().getCount(""); int studies = new Study().getCount(""); int files = new EpadFile().getCount(""); int templates = new EpadFile().getCount("filetype = '" + FileType.TEMPLATE.getName() + "'"); int plugins = new Plugin().getCount(""); int series = epadDatabaseOperations.getNumberOfSeries(); int npacs = RemotePACService.getInstance().getRemotePACs().size(); int aims = epadDatabaseOperations.getNumberOfAIMs("1 = 1"); int dsos = epadDatabaseOperations.getNumberOfAIMs("DSOSeriesUID is not null or DSOSeriesUID != ''"); int pacQueries = new RemotePACQuery().getCount(""); int wls = 0; try { wls = new WorkList().getCount(""); } catch (Exception x) { } String host = EPADConfig.xnatServer; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = System.getenv("DOCKER_HOST"); ; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = System.getenv("HOSTNAME"); ; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = InetAddress.getLocalHost().getHostName(); if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = getIPAddress(); es.setHost(host); es.setNumOfUsers(users); es.setNumOfProjects(projects); es.setNumOfPatients(patients); es.setNumOfStudies(studies); es.setNumOfSeries(series); es.setNumOfAims(aims); es.setNumOfDSOs(dsos); es.setNumOfWorkLists(wls); es.setNumOfPacs(npacs); es.setNumOfAutoQueries(pacQueries); es.setNumOfFiles(files); es.setNumOfPlugins(plugins); es.setNumOfTemplates(templates); es.setCreator("admin"); es.save(); //get the template statistics List<EpadStatisticsTemplate> templateStats = epadDatabaseOperations.getTemplateStats(); Calendar now = Calendar.getInstance(); boolean daily = true; if ("Weekly".equalsIgnoreCase(EPADConfig.getParamValue("StatisticsPeriod", "Daily"))) daily = false; if (!"true".equalsIgnoreCase(EPADConfig.getParamValue("DISABLE_STATISTICS_TRANSMIT"))) { if (daily || now.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { long delay = new Random().nextInt(1800 + 1); if (EPADConfig.xnatServer.indexOf("stanford") == -1) Thread.sleep(1000 * delay); // So that all don't do this at the same time //send the number statistics String epadUrl = EPADConfig.getParamValue("EpadStatisticsURL", "https://epad-public.stanford.edu/epad/statistics/"); epadUrl = epadUrl + "?numOfUsers=" + users; epadUrl = epadUrl + "&numOfProjects=" + projects; epadUrl = epadUrl + "&numOfPatients=" + patients; epadUrl = epadUrl + "&numOfStudies=" + studies; epadUrl = epadUrl + "&numOfSeries=" + series; epadUrl = epadUrl + "&numOfAims=" + aims; epadUrl = epadUrl + "&numOfDSOs=" + dsos; epadUrl = epadUrl + "&numOfWorkLists=" + wls; epadUrl = epadUrl + "&numOfFiles=" + files; epadUrl = epadUrl + "&numOfPlugins=" + plugins; epadUrl = epadUrl + "&numOfTemplates=" + templates; epadUrl = epadUrl + "&host=" + host; HttpClient client = new HttpClient(); PutMethod putMethod = new PutMethod(epadUrl); try { log.info("Sending statistics to Central Epad, url:" + epadUrl); int status = client.executeMethod(putMethod); log.info("Done Sending, status:" + putMethod.getStatusLine()); } catch (IOException e) { log.warning("Error calling Central Epad with URL " + epadUrl, e); } finally { putMethod.releaseConnection(); } //send statistics for templates for (EpadStatisticsTemplate st : templateStats) { //get the xml first String filePath = st.getFilePath() + st.getFileId() + ".xml"; log.info("path " + filePath); File f = null; if (filePath != null && (f = new File(filePath)).exists()) { st.setTemplateText(EPADFileUtils.readFileAsString(f)); } st.setCreator("admin"); //persist to db st.save(); epadUrl = EPADConfig.getParamValue("EpadTemplateStatisticsURL", "https://epad-public.stanford.edu/epad/statistics/templates/"); epadUrl = epadUrl + "?templateCode=" + encode(st.getTemplateCode()); epadUrl = epadUrl + "&templateName=" + encode(st.getTemplateName()); epadUrl = epadUrl + "&authors=" + encode(st.getAuthors()); epadUrl = epadUrl + "&version=" + encode(st.getVersion()); epadUrl = epadUrl + "&templateLevelType=" + encode(st.getTemplateLevelType()); epadUrl = epadUrl + "&templateDescription=" + encode(st.getTemplateDescription()); epadUrl = epadUrl + "&numOfAims=" + st.getNumOfAims(); epadUrl = epadUrl + "&host=" + host; putMethod = new PutMethod(epadUrl); putMethod.setRequestEntity( new StringRequestEntity(st.getTemplateText(), "text/xml", "UTF-8")); try { log.info("Sending template statistics to Central Epad, url:" + epadUrl); int status = client.executeMethod(putMethod); log.info("Done Sending, status:" + putMethod.getStatusLine()); } catch (IOException e) { log.warning("Error calling Central Epad with URL " + epadUrl, e); } finally { putMethod.releaseConnection(); } } } } } catch (Exception e) { log.warning("Error is saving/sending statistics", e); } GetMethod getMethod = null; try { String epadUrl = EPADConfig.getParamValue("EpadStatusURL", "https://epad-public.stanford.edu/epad/status/"); HttpClient client = new HttpClient(); getMethod = new GetMethod(epadUrl); int status = client.executeMethod(getMethod); if (status == HttpServletResponse.SC_OK) { String response = getMethod.getResponseBodyAsString(); int versInd = response.indexOf("Version:"); if (versInd != -1) { String version = response.substring(versInd + "Version:".length() + 1); if (version.indexOf("\n") != -1) version = version.substring(0, version.indexOf("\n")); if (version.indexOf(" ") != -1) version = version.substring(0, version.indexOf(" ")); log.info("Current ePAD version:" + version + " Our Version:" + new EPadWebServerVersion().getVersion()); if (!version.equals(new EPadWebServerVersion().getVersion())) { newEPADVersion = version; newEPADVersionAvailable = true; String msg = "A new version of ePAD: " + version + " is available, please go to ftp://epad-distribution.stanford.edu/ to download"; log.info(msg); List<User> admins = new User().getObjects("admin = 1 and enabled = 1"); for (User admin : admins) { List<Map<String, String>> userEvents = epadDatabaseOperations .getEpadEventsForSessionID(admin.getUsername(), false); boolean skip = false; for (Map<String, String> event : userEvents) { if (event.get("aim_name").equals("Upgrade")) { skip = true; break; } } if (skip) continue; if (EPADConfig.xnatServer.indexOf("stanford") == -1) epadDatabaseOperations.insertEpadEvent(admin.getUsername(), msg, // Message "", "", // aimUID, aimName "", // patient ID "", // patient Name "", // templateID "", // templateName "Please update ePAD"); // PluginName } } } } else log.warning("Error is getting epad version"); } catch (Exception x) { log.warning("Error is getting epad version", x); } finally { getMethod.releaseConnection(); } //done with calculating and sending the statistics //calculate a monthly cumulative if it is there is no record for the month boolean isAlreadyCalced = false; Calendar now = Calendar.getInstance(); try { EPADUsageList monthly = epadOperations.getMonthlyUsageSummaryForMonth(now.get(Calendar.MONTH) + 1); if (monthly != null && monthly.ResultSet.totalRecords > 0) isAlreadyCalced = true; } catch (Exception e) { log.warning("Couldn't get if the monthly cumulative statistics already calculated, assuming no", e); } if (isAlreadyCalced == false) { epadDatabaseOperations.calcMonthlyCumulatives(); } }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart with TimeLine (JFreeChart object) from TimeSeriesCollection. Is used when granularity is set to hours. * Adjusts display of the chart, not the values itself. * /*w ww . ja v a 2 s .com*/ * @param collection TimeSeriesCollection that should be used as basis of chart. * @param timeGranularity Selected granularity. Value is similar to granularity contained in TimeSeriesCollection "collection". * @param time first element of time that is displayed. Is used for caption text and axis text. * @param unit Unit of displayed values (kWh or kWh/TNF). * @return Returns finished JFreeChart object. */ private JFreeChart createTimeLineChart(TimeSeriesCollection collection, String timeGranularity, String time, String unit) { // Modification of X-Axis Label int day = Integer.parseInt(time.substring(8, 10)); int month = Integer.parseInt(time.substring(5, 7)); int year = Integer.parseInt(time.substring(0, 4)); //get Weekday Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, 0, 0); int weekDay = c.get(Calendar.DAY_OF_WEEK); String dayString = new DateFormatSymbols(Locale.US).getWeekdays()[weekDay] + ", " + day + ". "; String monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; String xAxisLabel = "" + dayString + monthString + " " + time.substring(0, 4); //Creation of the lineChart JFreeChart lineChart = ChartFactory.createTimeSeriesChart("Line Chart", // title xAxisLabel, // x-axis label // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data true, // create legend? false, // generate tooltips? false // generate URLs? ); //graphical modifications for LineChart lineChart.setBackgroundPaint(Color.white); XYPlot plot = lineChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); return lineChart; }