List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:org.caisi.dao.TicklerDAO.java
public int getActiveTicklerCount(String providerNo) { ArrayList paramList = new ArrayList(); //String query = "select count(*) from Tickler t where t.status = 'A' and t.service_date <= ? and (t.task_assigned_to = '"+ providerNo + "' or t.task_assigned_to='All Providers')"; GregorianCalendar currentDate = new GregorianCalendar(); currentDate.setTime(new Date()); /*paramList.add(currentDate.getTime()); //paramList.add(new Date());//ww w . jav a2 s .c o m Object params[] = paramList.toArray(new Object[paramList.size()]); Long count = (Long) getHibernateTemplate().find(query ,params).get(0);*/ String query = "select count(*) from tickler t where t.status = 'A' and t.service_date <= ? and (t.task_assigned_to = '" + providerNo + "' or t.task_assigned_to='All Providers')"; if (org.oscarehr.common.IsPropertiesOn.isMultisitesEnable()) { SuperSiteUtil superSiteUtil = SuperSiteUtil.getInstance(providerNo); List<Site> sites = superSiteUtil.getSitesWhichUserCanOnlyAccess(); String siteStr = ""; if (sites != null && sites.size() > 0) { for (Site site : sites) { if (siteStr.length() == 0) siteStr = "'" + site.getId() + "'"; else siteStr = siteStr + ",'" + site.getId() + "'"; } //get tickler which are not assigned to any demographic or which are assigned to demographic //enrolled in sites in which provider has only access query = "select count(*) from tickler t " + " left join demographicSite ds on t.demographic_no=ds.demographicId " + " where t.status = 'A' " + " and t.service_date <= ? and " + " (t.task_assigned_to = '" + providerNo + "' or t.task_assigned_to='All Providers') " + " and (t.demographic_no is null or t.demographic_no = '' or ds.siteId in (" + siteStr + "))"; } } Query hibernateQuery = getSession().createSQLQuery(query); hibernateQuery.setDate(0, currentDate.getTime()); List resultList = hibernateQuery.list(); int count = 0; if (resultList != null && resultList.size() > 0) count = Integer.parseInt(resultList.get(0) + ""); //return count.intValue(); return count; }
From source file:org.nuxeo.ecm.core.opencmis.impl.CmisSuiteSession.java
@Test public void testLastModifiedServiceWrapper() throws Exception { if (!(isAtomPub || isBrowser)) { // test only makes sense in the context of REST HTTP return;//from www. j a v a2 s .c om } cmisFeatureSession.tearDownCmisSession(); Thread.sleep(1000); // otherwise sometimes fails to set up again // deploy the LastModifiedServiceWrapper harness.deployContrib("org.nuxeo.ecm.core.opencmis.tests.tests", "OSGI-INF/test-servicefactorymanager-contrib.xml"); session = cmisFeatureSession.setUpCmisSession(coreSession.getRepositoryName()); GregorianCalendar lastModifiedCalendar = Helper.getCalendar(2007, 4, 11, 12, 0, 0); // in GMT-02 Folder folder = (Folder) session.getObjectByPath("/testfolder1"); Map<String, Serializable> properties = new HashMap<>(); properties.put("dc:description", "my description"); properties.put("dc:modified", lastModifiedCalendar); folder.updateProperties(properties, true); // TODO XXX fix timezone issues with H2 / SQL Server StorageConfiguration storageConfiguration = coreFeature.getStorageConfiguration(); if (!(storageConfiguration.isVCSH2() || storageConfiguration.isVCSSQLServer())) { assertEquals(lastModifiedCalendar.getTimeInMillis(), ((GregorianCalendar) folder.getPropertyValue("dc:modified")).getTimeInMillis()); } // check Last-Modified Cache Response Header RepositoryInfo ri = session.getRepositoryInfo(); String uri = ri.getThinClientUri() + ri.getId() + "/"; uri += isAtomPub ? "children?id=" : "root?objectId="; uri += folder.getId(); String lastModified = DateUtil.formatDate(lastModifiedCalendar.getTime()); String encoding = Base64.encodeBytes(new String(USERNAME + ":" + PASSWORD).getBytes()); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); HttpResponse response = null; request.setHeader("Authorization", "Basic " + encoding); try { response = client.execute(request); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); // TODO XXX fix timezone issues with H2 / SQL Server if (!(storageConfiguration.isVCSH2() || storageConfiguration.isVCSSQLServer())) { assertEquals(lastModified, response.getLastHeader("Last-Modified").getValue()); } } finally { client.getConnectionManager().shutdown(); } }
From source file:gr.abiss.calipso.controller.AbstractServiceBasedRestController.java
@RequestMapping(value = "reports", produces = { "application/json" }, method = RequestMethod.GET) @ResponseBody/*from w w w.ja v a 2 s . c o m*/ //@ApiOperation(value = "reports", httpMethod = "GET") public Page<ReportDataSet> getReportDatasets( @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false, defaultValue = "10") Integer size, @RequestParam(value = "properties", required = false, defaultValue = "id") String sort, @RequestParam(value = "direction", required = false, defaultValue = "ASC") String direction, @RequestParam(value = "timeUnit", required = false, defaultValue = "DAY") TimeUnit timeUnit, @RequestParam(value = "dateField", required = false, defaultValue = "createdDate") String dateField, @RequestParam(value = "period", required = false) String period, @RequestParam(value = "reportType", required = false) String reportType) { if (StringUtils.isBlank(period)) { GregorianCalendar now = new GregorianCalendar(); StringBuffer buff = new StringBuffer(); if (timeUnit.equals(TimeUnit.DAY)) { buff.append(now.get(Calendar.MONTH)).append('/'); } period = buff.append(now.get(Calendar.YEAR)).toString(); } LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", period: " + period + ", reportName: " + reportType); GregorianCalendar start = null; GregorianCalendar end = null; if (timeUnit.equals(TimeUnit.DAY)) { String[] monthYear = period.split("/"); start = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0); end = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); } else { start = new GregorianCalendar(Integer.parseInt(period), 0, 0); end = new GregorianCalendar(Integer.parseInt(period), 11, 0); end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH)); } start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY)); start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE)); start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND)); start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND)); end.set(Calendar.HOUR_OF_DAY, end.getMinimum(Calendar.HOUR_OF_DAY)); end.set(Calendar.MINUTE, end.getMinimum(Calendar.MINUTE)); end.set(Calendar.SECOND, end.getMinimum(Calendar.SECOND)); end.set(Calendar.MILLISECOND, end.getMinimum(Calendar.MILLISECOND)); Map<String, String[]> paramsMap = request.getParameterMap(); LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", dateFrom: " + start + ", dateTo: " + end + ", reportName: " + reportType); Pageable pageable = buildPageable(page, size, sort, direction, paramsMap); Page<ReportDataSet> results = this.service.getReportDatasets(pageable, timeUnit, dateField, start.getTime(), end.getTime(), reportType); LOGGER.info("getReportDatasets returning " + results.getTotalElements()); return results; }
From source file:org.grails.datastore.mapping.model.types.BasicTypeConverterRegistrar.java
public void register(ConverterRegistry registry) { registry.addConverter(new Converter<Date, String>() { public String convert(Date date) { return String.valueOf(date.getTime()); }/*from w w w. j ava 2 s .com*/ }); registry.addConverter(new Converter<Date, Calendar>() { public Calendar convert(Date date) { final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } }); registry.addConverter(new Converter<Integer, Long>() { public Long convert(Integer integer) { return integer.longValue(); } }); registry.addConverter(new Converter<Long, Integer>() { public Integer convert(Long longValue) { return longValue.intValue(); } }); registry.addConverter(new Converter<Integer, Double>() { public Double convert(Integer integer) { return integer.doubleValue(); } }); registry.addConverter(new Converter<CharSequence, Date>() { public Date convert(CharSequence s) { try { final Long time = Long.valueOf(s.toString()); return new Date(time); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Double>() { public Double convert(CharSequence s) { try { return Double.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Integer>() { public Integer convert(CharSequence s) { try { return Integer.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Long>() { public Long convert(CharSequence s) { try { return Long.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<Object, String>() { public String convert(Object o) { return o.toString(); } }); registry.addConverter(new Converter<Calendar, String>() { public String convert(Calendar calendar) { return String.valueOf(calendar.getTime().getTime()); } }); registry.addConverter(new Converter<CharSequence, Calendar>() { public Calendar convert(CharSequence s) { try { Date date = new Date(Long.valueOf(s.toString())); Calendar c = new GregorianCalendar(); c.setTime(date); return c; } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); }
From source file:org.agnitas.dao.impl.RecipientDaoImpl.java
/** * Load complete Subscriber-Data from DB. customerID must be set first for this method. * * @return Map with Key/Value-Pairs of customer data */// w ww. j a va 2 s. com @Override public CaseInsensitiveMap<Object> getCustomerDataFromDb(int companyID, int customerID) { String aName = null; String aValue = null; int a; java.sql.Timestamp aTime = null; Recipient cust = (Recipient) applicationContext.getBean("Recipient"); if (cust.getCustParameters() == null) { cust.setCustParameters(new CaseInsensitiveMap<Object>()); } String getCust = "SELECT * FROM customer_" + companyID + "_tbl WHERE customer_id=" + customerID; if (cust.getCustDBStructure() == null) { cust.loadCustDBStructure(); } DataSource ds = (DataSource) this.applicationContext.getBean("dataSource"); Connection con = DataSourceUtils.getConnection(ds); try { Statement stmt = con.createStatement(); ResultSet rset = stmt.executeQuery(getCust); if (logger.isInfoEnabled()) { logger.info("getCustomerDataFromDb: " + getCust); } if (rset.next()) { ResultSetMetaData aMeta = rset.getMetaData(); for (a = 1; a <= aMeta.getColumnCount(); a++) { aValue = null; aName = aMeta.getColumnName(a).toLowerCase(); switch (aMeta.getColumnType(a)) { case java.sql.Types.TIMESTAMP: case java.sql.Types.TIME: case java.sql.Types.DATE: try { aTime = rset.getTimestamp(a); } catch (Exception e) { aTime = null; } if (aTime == null) { cust.getCustParameters().put(aName + "_DAY_DATE", ""); cust.getCustParameters().put(aName + "_MONTH_DATE", ""); cust.getCustParameters().put(aName + "_YEAR_DATE", ""); cust.getCustParameters().put(aName + "_HOUR_DATE", ""); cust.getCustParameters().put(aName + "_MINUTE_DATE", ""); cust.getCustParameters().put(aName + "_SECOND_DATE", ""); cust.getCustParameters().put(aName, ""); } else { GregorianCalendar aCal = new GregorianCalendar(); aCal.setTime(aTime); cust.getCustParameters().put(aName + "_DAY_DATE", Integer.toString(aCal.get(GregorianCalendar.DAY_OF_MONTH))); cust.getCustParameters().put(aName + "_MONTH_DATE", Integer.toString(aCal.get(GregorianCalendar.MONTH) + 1)); cust.getCustParameters().put(aName + "_YEAR_DATE", Integer.toString(aCal.get(GregorianCalendar.YEAR))); cust.getCustParameters().put(aName + "_HOUR_DATE", Integer.toString(aCal.get(GregorianCalendar.HOUR_OF_DAY))); cust.getCustParameters().put(aName + "_MINUTE_DATE", Integer.toString(aCal.get(GregorianCalendar.MINUTE))); cust.getCustParameters().put(aName + "_SECOND_DATE", Integer.toString(aCal.get(GregorianCalendar.SECOND))); SimpleDateFormat bdfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cust.getCustParameters().put(aName, bdfmt.format(aCal.getTime())); } break; default: aValue = rset.getString(a); if (aValue == null) { aValue = ""; } cust.getCustParameters().put(aName, aValue); break; } } } rset.close(); stmt.close(); } catch (Exception e) { logger.error("getCustomerDataFromDb: " + getCust, e); AgnUtils.sendExceptionMail("sql:" + getCust, e); } DataSourceUtils.releaseConnection(con, ds); cust.setChangeFlag(false); Map<String, Object> result = cust.getCustParameters(); if (result instanceof CaseInsensitiveMap) { return (CaseInsensitiveMap<Object>) result; } else { return new CaseInsensitiveMap<Object>(result); } }
From source file:com.zoho.creator.jframework.XMLParser.java
private static void parseAndSetCalendarRecords(ZCView zcView, Node calendarNode) { zcView.setGrouped(true);// w w w . ja v a 2 s. c o m NodeList eventsList = calendarNode.getChildNodes(); int year = zcView.getRecordsMonthYear().getTwo() - 1900; int month = zcView.getRecordsMonthYear().getOne(); GregorianCalendar cureentmnthcalendar = new GregorianCalendar(); Date currentDate = new Date(); for (int i = 0; i < eventsList.getLength(); i++) { Node eventNode = eventsList.item(i); NamedNodeMap eventAttrMap = eventNode.getAttributes(); long recordid = Long.parseLong(eventAttrMap.getNamedItem("id").getNodeValue()); //No I18N String title = getChildNodeValue(eventNode, "title"); //eventAttrMap.getNamedItem("title").getNodeValue(); //No I18N boolean isAllDay = Boolean.parseBoolean(eventAttrMap.getNamedItem("allDay").getNodeValue()); //No I18N // 07/31/2013 08:00:00 String dateFormat = "MM/dd/yyyy HH:mm:ss"; //No I18N if (isAllDay) { dateFormat = "MM/dd/yyyy"; //No I18N } Date startTime = getDateValue(eventAttrMap.getNamedItem("start").getNodeValue(), dateFormat); //No I18N ZCRecord record = zcView.getRecord(recordid); record.setEventTitle(title); if (isAllDay) { zcView.setIsAllDay(isAllDay); Node endNode = eventAttrMap.getNamedItem("end");//No I18N Date endTime = null; if (endNode != null) { endTime = getDateValue(endNode.getNodeValue(), dateFormat); } int startDay = -1; if (startTime != null) { startDay = startTime.getDate(); } int endDay = -1; if (endTime != null) { endDay = endTime.getDate(); } if (endDay != -1) { currentDate.setDate(1); currentDate.setMonth(month); currentDate.setYear(year); currentDate.setMinutes(0); currentDate.setHours(0); currentDate.setSeconds(0); cureentmnthcalendar.setTime(currentDate); cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, -6); currentDate = cureentmnthcalendar.getTime(); for (int j = 0; j < 42; j++) { if ((currentDate.getDate() == startTime.getDate() && currentDate.getMonth() == startTime.getMonth() && currentDate.getYear() == startTime.getYear()) || (currentDate.after(startTime) && currentDate.before(endTime)) || (currentDate.getDate() == endTime.getDate() && currentDate.getMonth() == endTime.getMonth() && currentDate.getYear() == endTime.getYear())) { zcView.setEvent(record, currentDate); } cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, 1); currentDate = cureentmnthcalendar.getTime(); } //Collections.sort(eventRecords); } record.setEventDate(startTime); } else { // 07/31/2013 08:00:00 Date endTime = getDateValue(eventAttrMap.getNamedItem("end").getNodeValue(), dateFormat); //No I18N record.setStartTime(startTime); record.setEndTime(endTime); Calendar startCalendar = new GregorianCalendar(); startCalendar.setTime(startTime); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); startCalendar.set(Calendar.MILLISECOND, 0); Calendar endCalendar = new GregorianCalendar(); endCalendar.setTime(endTime); endCalendar.set(Calendar.HOUR_OF_DAY, 0); endCalendar.set(Calendar.MINUTE, 0); endCalendar.set(Calendar.SECOND, 0); endCalendar.set(Calendar.MILLISECOND, 0); Date eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); while ((startCalendar.get(Calendar.YEAR) != endCalendar.get(Calendar.YEAR)) || (startCalendar.get(Calendar.MONTH) != endCalendar.get(Calendar.MONTH)) || (startCalendar.get(Calendar.DATE) != endCalendar.get(Calendar.DATE))) { startCalendar.add(Calendar.DATE, 1); eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); } } } List<ZCGroup> zcGroups = zcView.getGroups(); HashMap<Date, List<ZCRecord>> eventsMap = zcView.getEventRecordsMap(); SortedSet<Date> keys = new TreeSet<Date>(eventsMap.keySet()); for (Date eventDate : keys) { List<ZCRecord> eventRecords = eventsMap.get(eventDate); List<String> groupHeaderValues = new ArrayList<String>(); SimpleDateFormat dateFormat = new SimpleDateFormat(zcView.getDateFormat()); //No I18N groupHeaderValues.add(dateFormat.format(eventDate)); ZCGroup zcGroup = new ZCGroup(groupHeaderValues); zcGroups.add(zcGroup); for (int i = 0; i < eventRecords.size(); i++) { ZCRecord eventRecord = eventRecords.get(i); zcGroup.addRecord(eventRecord); } } zcView.sortRecordsForCalendar(); }
From source file:org.etudes.jforum.view.forum.PostAction.java
/** * Checks to see if the forum is locked after due date * //from w w w . j av a2 s . c o m * @param forumId forum * @return true if forum is not locked after the due date or the user is admin or facilitator * false if forum is locked after the due date and the user is not admin or facilitator * @throws Exception */ private boolean isForumLocked(Forum forum) throws Exception { if (JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser()) return false; if ((forum.getEndDate() == null) || (!forum.isLockForum())) return false; GregorianCalendar gc = new GregorianCalendar(); Date nowDate = gc.getTime(); if (nowDate.getTime() > forum.getEndDate().getTime()) { return true; } else { return false; } }
From source file:org.etudes.jforum.view.forum.PostAction.java
/** * Check to see if forum is open/* www.j ava 2s. co m*/ * * @param forum forum * @return true if forum start date is before the current date/time or the user is admin or facilitator * false if forum start date is after the current date/time or and the user is not admin or facilitator * @throws Exception */ private boolean isForumOpen(Forum forum) throws Exception { if (JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser()) return true; if (forum.getStartDate() == null) return true; GregorianCalendar gc = new GregorianCalendar(); Date nowDate = gc.getTime(); if (nowDate.getTime() > forum.getStartDate().getTime()) { return true; } return false; }
From source file:org.etudes.jforum.view.forum.PostAction.java
/** * Checks to see if the category is locked after due date * //from www. ja v a2s . c om * @param category category * @return true if category is not locked after the due date or the user is admin or facilitator * false if category is locked after the due date and the user is not admin or facilitator * @throws Exception */ private boolean isCategoryLocked(Category category) throws Exception { if (JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser()) return false; if ((category.getEndDate() == null) || (!category.isLockCategory())) return false; GregorianCalendar gc = new GregorianCalendar(); Date nowDate = gc.getTime(); if (nowDate.getTime() > category.getEndDate().getTime()) { return true; } return false; }
From source file:org.etudes.jforum.view.forum.PostAction.java
/** * Check to see if category is open// ww w.ja va 2 s.c o m * * @param category category * @return true if category start date is before the current date/time or the user is admin or facilitator * false if start date is after the current date/time or and the user is not admin or facilitator * @throws Exception */ private boolean isCategoryOpen(Category category) throws Exception { if (JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser()) return true; if (category.getStartDate() == null) return true; GregorianCalendar gc = new GregorianCalendar(); Date nowDate = gc.getTime(); if (nowDate.getTime() > category.getStartDate().getTime()) { return true; } return false; }