List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:azkaban.reportal.util.Reportal.java
License:Apache License
public void updateSchedules(Reportal report, ScheduleManager scheduleManager, User user, Flow flow) throws ScheduleManagerException { // Clear previous schedules removeSchedules(scheduleManager);/*from w w w . ja v a2 s . c om*/ // Add new schedule if (schedule) { int hour = (Integer.parseInt(scheduleHour) % 12) + (scheduleAmPm.equalsIgnoreCase("pm") ? 12 : 0); int minute = Integer.parseInt(scheduleMinute) % 60; DateTimeZone timeZone = scheduleTimeZone.equalsIgnoreCase("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); DateTime firstSchedTime = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timeZone) .parseDateTime(scheduleDate); firstSchedTime = firstSchedTime.withHourOfDay(hour).withMinuteOfHour(minute).withSecondOfMinute(0) .withMillisOfSecond(0); ReadablePeriod period = null; if (scheduleRepeat) { int intervalQuantity = Integer.parseInt(scheduleIntervalQuantity); if (scheduleInterval.equals("y")) { period = Years.years(intervalQuantity); } else if (scheduleInterval.equals("m")) { period = Months.months(intervalQuantity); } else if (scheduleInterval.equals("w")) { period = Weeks.weeks(intervalQuantity); } else if (scheduleInterval.equals("d")) { period = Days.days(intervalQuantity); } else if (scheduleInterval.equals("h")) { period = Hours.hours(intervalQuantity); } else if (scheduleInterval.equals("M")) { period = Minutes.minutes(intervalQuantity); } } ExecutionOptions options = new ExecutionOptions(); options.getFlowParameters().put("reportal.execution.user", user.getUserId()); options.getFlowParameters().put("reportal.title", report.title); options.getFlowParameters().put("reportal.render.results.as.html", report.renderResultsAsHtml ? "true" : "false"); options.setMailCreator(ReportalMailCreator.REPORTAL_MAIL_CREATOR); scheduleManager.scheduleFlow(-1, project.getId(), project.getName(), flow.getId(), "ready", firstSchedTime.getMillis(), firstSchedTime.getZone(), period, DateTime.now().getMillis(), firstSchedTime.getMillis(), firstSchedTime.getMillis(), user.getUserId(), options, null); } }
From source file:azkaban.utils.WebUtils.java
License:Apache License
public String formatDate(long timeMS) { if (timeMS == -1) { return "-"; }/*from www . j a v a 2 s.c o m*/ return DateTimeFormat.forPattern(DATE_TIME_STRING).print(timeMS); }
From source file:azkaban.utils.WebUtils.java
License:Apache License
public String formatDateTime(DateTime dt) { return DateTimeFormat.forPattern(DATE_TIME_STRING).print(dt); }
From source file:azkaban.web.pages.IndexServlet.java
License:Apache License
private String scheduleJobs(AzkabanApplication app, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String[] jobNames = req.getParameterValues("jobs"); if (!hasParam(req, "jobs")) { addError(req, "You must select at least one job to run."); return ""; }//www . ja v a 2 s . c om if (hasParam(req, "flow_now")) { if (jobNames.length > 1) { addError(req, "Can only run flow instance on one job."); return ""; } String jobName = jobNames[0]; JobManager jobManager = app.getJobManager(); JobDescriptor descriptor = jobManager.getJobDescriptor(jobName); if (descriptor == null) { addError(req, "Can only run flow instance on one job."); return ""; } else { return req.getContextPath() + "/flow?job_id=" + jobName; } } else { for (String job : jobNames) { if (hasParam(req, "schedule")) { int hour = getIntParam(req, "hour"); int minutes = getIntParam(req, "minutes"); boolean isPm = getParam(req, "am_pm").equalsIgnoreCase("pm"); String scheduledDate = req.getParameter("date"); DateTime day = null; if (scheduledDate == null || scheduledDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); } else { try { day = DateTimeFormat.forPattern("MM-dd-yyyy").parseDateTime(scheduledDate); } catch (IllegalArgumentException e) { addError(req, "Invalid date: '" + scheduledDate + "'"); return ""; } } ReadablePeriod thePeriod = null; if (hasParam(req, "is_recurring")) thePeriod = parsePeriod(req); if (isPm && hour < 12) hour += 12; hour %= 24; app.getScheduleManager().schedule(job, day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0), thePeriod, false); addMessage(req, job + " scheduled."); } else if (hasParam(req, "run_now")) { boolean ignoreDeps = !hasParam(req, "include_deps"); try { app.getJobExecutorManager().execute(job, ignoreDeps); } catch (JobExecutionException e) { addError(req, e.getMessage()); return ""; } addMessage(req, "Running " + job); } else { addError(req, "Neither run_now nor schedule param is set."); } } return ""; } }
From source file:azkaban.webapp.servlet.HistoryServlet.java
License:Apache License
private void handleHistoryPage(HttpServletRequest req, HttpServletResponse resp, Session session) throws ServletException { Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/historypage.vm"); int pageNum = getIntParam(req, "page", 1); int pageSize = getIntParam(req, "size", 16); page.add("vmutils", vmHelper); if (pageNum < 0) { pageNum = 1;// w w w .j a v a 2 s . co m } List<ExecutableFlow> history = null; if (hasParam(req, "advfilter")) { String projContain = getParam(req, "projcontain"); String flowContain = getParam(req, "flowcontain"); String userContain = getParam(req, "usercontain"); int status = getIntParam(req, "status"); String begin = getParam(req, "begin"); long beginTime = begin == "" ? -1 : DateTimeFormat.forPattern(FILTER_BY_DATE_PATTERN).parseDateTime(begin).getMillis(); String end = getParam(req, "end"); long endTime = end == "" ? -1 : DateTimeFormat.forPattern(FILTER_BY_DATE_PATTERN).parseDateTime(end).getMillis(); try { history = executorManager.getExecutableFlows(projContain, flowContain, userContain, status, beginTime, endTime, (pageNum - 1) * pageSize, pageSize); } catch (ExecutorManagerException e) { page.add("error", e.getMessage()); } } else if (hasParam(req, "search")) { String searchTerm = getParam(req, "searchterm"); try { history = executorManager.getExecutableFlows(searchTerm, (pageNum - 1) * pageSize, pageSize); } catch (ExecutorManagerException e) { page.add("error", e.getMessage()); } } else { try { history = executorManager.getExecutableFlows((pageNum - 1) * pageSize, pageSize); } catch (ExecutorManagerException e) { e.printStackTrace(); } } page.add("flowHistory", history); page.add("size", pageSize); page.add("page", pageNum); // keep the search terms so that we can navigate to later pages if (hasParam(req, "searchterm") && !getParam(req, "searchterm").equals("")) { page.add("search", "true"); page.add("search_term", getParam(req, "searchterm")); } if (hasParam(req, "advfilter")) { page.add("advfilter", "true"); page.add("projcontain", getParam(req, "projcontain")); page.add("flowcontain", getParam(req, "flowcontain")); page.add("usercontain", getParam(req, "usercontain")); page.add("status", getIntParam(req, "status")); page.add("begin", getParam(req, "begin")); page.add("end", getParam(req, "end")); } if (pageNum == 1) { page.add("previous", new PageSelection(1, pageSize, true, false)); } else { page.add("previous", new PageSelection(pageNum - 1, pageSize, false, false)); } page.add("next", new PageSelection(pageNum + 1, pageSize, false, false)); // Now for the 5 other values. int pageStartValue = 1; if (pageNum > 3) { pageStartValue = pageNum - 2; } page.add("page1", new PageSelection(pageStartValue, pageSize, false, pageStartValue == pageNum)); pageStartValue++; page.add("page2", new PageSelection(pageStartValue, pageSize, false, pageStartValue == pageNum)); pageStartValue++; page.add("page3", new PageSelection(pageStartValue, pageSize, false, pageStartValue == pageNum)); pageStartValue++; page.add("page4", new PageSelection(pageStartValue, pageSize, false, pageStartValue == pageNum)); pageStartValue++; page.add("page5", new PageSelection(pageStartValue, pageSize, false, pageStartValue == pageNum)); pageStartValue++; page.render(); }
From source file:azkaban.webapp.servlet.ScheduleServlet.java
License:Apache License
private DateTime parseDateTime(String scheduleDate, String scheduleTime) { // scheduleTime: 12,00,pm,PDT String[] parts = scheduleTime.split(",", -1); int hour = Integer.parseInt(parts[0]); int minutes = Integer.parseInt(parts[1]); boolean isPm = parts[2].equalsIgnoreCase("pm"); DateTimeZone timezone = parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); // scheduleDate: 02/10/2013 DateTime day = null;/*from w w w.j av a 2 s . com*/ if (scheduleDate == null || scheduleDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); } else { day = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timezone).parseDateTime(scheduleDate); } hour %= 12; if (isPm) hour += 12; DateTime firstSchedTime = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0); return firstSchedTime; }
From source file:azkaban.webapp.servlet.VelocityUtils.java
License:Apache License
public String formatDate(long timestamp, String format) { DateTimeFormatter f = DateTimeFormat.forPattern(format); return f.print(timestamp); }
From source file:backend.util.FileGroup.java
public static void main(String[] args) throws IOException { boolean Done = false; do {/*w w w. j a v a2 s .c o m*/ DateTimeFormatter templFMT = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeFormatter subDirFMT = DateTimeFormat.forPattern("yyMMdd"); JFileChooser fChooser = new JFileChooser("D:\\CGKStudio\\log"); fChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // fChooser.setFileFilter(new FileNameExtensionFilter("LOG File","")); if (fChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) return; File dir = fChooser.getSelectedFile(); List<File> files = new LinkedList(Arrays.asList(dir.listFiles())); DateTime d = new DateTime(2014, 11, 20, 0, 0); DateTime now = DateTime.now(); while (d.compareTo(now) <= 0) { String templ = templFMT.print(d); List<File> moved = new LinkedList(); files.stream().filter((file) -> (file.getName().contains(templ))).forEach((file) -> { moved.add(file); }); files.removeAll(moved); if (moved.size() > 0) { String subDir = dir.getAbsolutePath() + "\\" + subDirFMT.print(d); File subDirFile = new File(subDir); if (!subDirFile.exists()) Files.createDirectory(subDirFile.toPath()); moved.stream().forEach((file) -> { try { File target = new File(subDir + "\\" + file.getName()); if (!target.exists()) { Files.copy(new File(dir.getAbsolutePath() + "\\" + file.getName()).toPath(), target.toPath()); } } catch (IOException ex) { Logger.getLogger(FileGroup.class.getName()).log(Level.SEVERE, null, ex); } }); } d = d.plusDays(1); } int sel; sel = JOptionPane.showConfirmDialog(fChooser, "Do it again?", "Again", JOptionPane.YES_NO_OPTION); if (sel != JOptionPane.YES_OPTION) Done = true; } while (!Done); }
From source file:bamons.process.batch.task.BatchScheduledTasks.java
License:Open Source License
public void sampleJob() throws Exception { try {//from ww w . j ava 2 s. co m DateTime dt = new DateTime(); dt = dt.minusDays(1); String targetDate = dt.toString(DateTimeFormat.forPattern("yyyy-MM-dd")); JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()) .addString("targetDate", targetDate).toJobParameters(); JobExecution execution = jobLauncher.run(sampleJob, jobParameters); } catch (Exception e) { e.printStackTrace(); } }
From source file:beans.utilidades.MetodosGenerales.java
public String esFecha(String f, String format) { /*/*from w ww.java 2 s. c o m*/ * null=invalido ""=aceptado pero vacio "valor"=aceptado (valor para db) */ if (f.trim().length() == 0) { return ""; } try { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeFormatter fmt2 = DateTimeFormat.forPattern(format); DateTime the_date = DateTime.parse(f, fmt2);//trata de convertir al formato "format"(me llega por parametro) return fmt.print(the_date);//lo imprime en el formato "yyyy-MM-dd" } catch (Throwable ex) { return null;//invalida } }