List of usage examples for org.joda.time DateMidnight DateMidnight
public DateMidnight(Object instant)
From source file:com.stackframe.sarariman.BilledService.java
License:GNU General Public License
public static BilledService lookup(Sarariman sarariman, int id) throws SQLException { Connection connection = sarariman.openConnection(); PreparedStatement ps = connection.prepareStatement("SELECT * from billed_services WHERE id=?"); try {// w w w .j a v a 2 s .c om ps.setInt(1, id); ResultSet resultSet = ps.executeQuery(); try { if (resultSet.next()) { int serviceAgreement = resultSet.getInt("service_agreement"); DateMidnight popStart = new DateMidnight(resultSet.getDate("pop_start")); DateMidnight popEnd = new DateMidnight(resultSet.getDate("pop_end")); String invoice = resultSet.getString("invoice"); return new BilledService(id, serviceAgreement, popStart, popEnd, invoice); } else { return null; } } finally { resultSet.close(); } } finally { ps.close(); connection.close(); } }
From source file:com.stackframe.sarariman.BilledService.java
License:GNU General Public License
public static List<BilledService> lookupByServiceAgreement(Sarariman sarariman, int serviceAgreement) throws SQLException { Connection connection = sarariman.openConnection(); PreparedStatement ps = connection .prepareStatement("SELECT * from billed_services WHERE service_agreement=?"); try {// w w w . j a v a 2 s . co m ps.setInt(1, serviceAgreement); ResultSet resultSet = ps.executeQuery(); try { List<BilledService> billedServices = new ArrayList<BilledService>(); while (resultSet.next()) { int id = resultSet.getInt("id"); DateMidnight popStart = new DateMidnight(resultSet.getDate("pop_start")); DateMidnight popEnd = new DateMidnight(resultSet.getDate("pop_end")); String invoice = resultSet.getString("invoice"); billedServices.add(new BilledService(id, serviceAgreement, popStart, popEnd, invoice)); } return billedServices; } finally { resultSet.close(); } } finally { ps.close(); connection.close(); } }
From source file:com.stackframe.sarariman.LDAPDirectory.java
License:GNU General Public License
/** * Load the directory from LDAP.//from w w w .j a v a 2s . c o m */ private void load() { try { List<Employee> tmp = new ArrayList<Employee>(); NamingEnumeration<SearchResult> answer = context.search("ou=People", null, new String[] { "uid", "sn", "givenName", "employeeNumber", "fulltime", "active", "mail", "birthdate" }); int employeeCount = 0; while (answer.hasMore()) { Attributes attributes = answer.next().getAttributes(); String sn = attributes.get("sn").getAll().next().toString(); //Need to handle these more elegantly if (sn.equals("nobody") || sn.equals("dignitas") || sn.equals("root")) { continue; } //For debugging //if( sn.equals( "root" ) ) //{ // DateMidnight birthdate = new DateMidnight("2001-01-01"); // tmp.add( new EmployeeImpl( "root", "root", 26, true, true, "root@dignitastechnologies.com", birthdate ) ); // continue; //} String name = sn + ", " + attributes.get("givenName").getAll().next(); String uid = attributes.get("uid").getAll().next().toString(); // Odd LDAP null pointer... javax.naming.directory.Attribute temp = attributes.get("mail"); String mail = temp == null ? "null_exception" : temp.getAll().next().toString(); //boolean fulltime = Boolean.parseBoolean(attributes.get("fulltime").getAll().next().toString()); //boolean active = Boolean.parseBoolean(attributes.get("active").getAll().next().toString()); boolean fulltime = true; boolean active = true; //int employeeNumber = Integer.parseInt(attributes.get("employeeNumber").getAll().next().toString()); int employeeNumber = ++employeeCount; //DateMidnight birthdate = new DateMidnight(attributes.get("birthdate").getAll().next().toString()); DateMidnight birthdate = new DateMidnight("2001-01-01"); tmp.add(new EmployeeImpl(name, uid, employeeNumber, fulltime, active, mail, birthdate)); System.out.println("\nName:\t" + name + "\nUID:\t" + uid + "\nNUM:\t" + employeeNumber + "\nMAIL:\t" + mail + "\nBDT:\t" + birthdate + "\n/-/-/-/-/-/-/-/-/-/-\n\n"); } Collections.sort(tmp, new Comparator<Employee>() { public int compare(Employee e1, Employee e2) { return e1.getFullName().compareTo(e2.getFullName()); } }); for (Employee employee : tmp) { byNumber.put(employee.getNumber(), employee); byNumber.put(new Long(employee.getNumber()), employee); byNumber.put(Integer.toString(employee.getNumber()), employee); byUserName.put(employee.getUserName(), employee); } } catch (NamingException ne) { throw new RuntimeException(ne); } }
From source file:com.stackframe.sarariman.ServiceAgreement.java
License:GNU General Public License
public static ServiceAgreement lookup(Sarariman sarariman, int id) throws SQLException { Connection connection = sarariman.openConnection(); PreparedStatement ps = connection.prepareStatement("SELECT * from service_agreements WHERE id=?"); try {//w w w . j av a 2 s. c o m ps.setInt(1, id); ResultSet resultSet = ps.executeQuery(); try { if (resultSet.next()) { int project = resultSet.getInt("project"); DateMidnight popStart = new DateMidnight(resultSet.getDate("pop_start")); DateMidnight popEnd = new DateMidnight(resultSet.getDate("pop_end")); String billingPeriod = resultSet.getString("billing_period"); BigDecimal periodRate = new BigDecimal(resultSet.getString("period_rate")); String description = resultSet.getString("description"); return new ServiceAgreement(id, project, popStart, popEnd, billingPeriod, periodRate, description); } else { return null; } } finally { resultSet.close(); } } finally { ps.close(); connection.close(); } }
From source file:com.stackframe.sarariman.ServiceBillingController.java
License:GNU General Public License
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w.j a v a2 s. com*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Employee user = (Employee) request.getAttribute("user"); if (!user.isAdministrator()) { response.sendError(401); return; } Action action = Action.valueOf(request.getParameter("action")); try { int serviceAgreement = Integer.parseInt(request.getParameter("service_agreement")); DateMidnight popStart = new DateMidnight(request.getParameter("pop_start")); DateMidnight popEnd = new DateMidnight(request.getParameter("pop_end")); switch (action) { case create: createBilling(serviceAgreement, popStart, popEnd); break; default: response.sendError(500); return; } response.sendRedirect( response.encodeRedirectURL(MessageFormat.format("serviceagreement?id={0}", serviceAgreement))); return; } catch (Exception e) { throw new IOException(e); } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addWeeklyReportUrls(PrintWriter pw, int numWeeklyReports, String metricsServiceUrl) { DateTime input = newDateTime();/*from w w w . j a v a2s . c o m*/ LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numWeeklyReports; i++) { try { DateMidnight startOfLastWeek = new DateMidnight( input.minusWeeks(i).withDayOfWeek(DateTimeConstants.MONDAY)); String startDate = urlEncodeDate(startOfLastWeek); LOGGER.debug("Previous Week {} (start): {}", i, startDate); DateTime endOfLastWeek = startOfLastWeek.plusDays(DateTimeConstants.DAYS_PER_WEEK).toDateTime() .minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastWeek); LOGGER.debug("Previous Week {} (end): ", i, endDate); startTableRow(pw, i); addCellLabelForRange(pw, startOfLastWeek, endOfLastWeek); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding weekly reports", e); } } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addMonthlyReportUrls(PrintWriter pw, int numMonthlyReports, String metricsServiceUrl) { DateTime input = newDateTime();/*w w w .j a v a2 s . c om*/ LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numMonthlyReports; i++) { try { DateMidnight startOfLastMonth = new DateMidnight(input.minusMonths(i).withDayOfMonth(1)); String startDate = urlEncodeDate(startOfLastMonth); LOGGER.debug("Previous Month (start): {} (ms = {})", startDate, startOfLastMonth.getMillis()); DateTime endOfLastMonth = startOfLastMonth.plusMonths(1).toDateTime().minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastMonth); LOGGER.debug("Previous Month (end): {} (ms = {})", endOfLastMonth, endOfLastMonth.getMillis()); startTableRow(pw, i); addCellLabelForRange(pw, startOfLastMonth, endOfLastMonth); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding monthly reports", e); } } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addYearlyReportUrls(PrintWriter pw, int numYearlyReports, String metricsServiceUrl) { DateTime input = newDateTime();/*from ww w . j av a 2s . co m*/ LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numYearlyReports; i++) { try { DateMidnight startOfLastYear = new DateMidnight(input.minusYears(1).withDayOfYear(1)); String startDate = urlEncodeDate(startOfLastYear); LOGGER.debug("Previous Year (start): {} (ms = {})", startOfLastYear, startOfLastYear.getMillis()); DateTime endOfLastYear = startOfLastYear.plusYears(1).toDateTime().minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastYear); LOGGER.debug("Previous Year (end): {}, (ms = {})", endOfLastYear, endOfLastYear.getMillis()); String urlText = startOfLastYear.toString("yyyy"); LOGGER.debug("URL text = [{}]", urlText); startTableRow(pw, i); addCellLabel(pw, urlText); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding yearly reports", e); } } }
From source file:de.cpoepke.demos.neo4j.querydsl.converter.LongToDateMidnightConverter.java
License:Open Source License
@Override public DateMidnight convert(Long source) { return new DateMidnight(source); }
From source file:de.hh.changeRing.infrastructure.eclipselink.JodaDateMidnightConverter.java
License:Open Source License
@Override protected DateMidnight toBusinessLayerType(Date dataValue) { return new DateMidnight(dataValue); }