List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:com.jaspersoft.jasperserver.test.ReportSchedulingTestTestNG.java
/** * Test that exercises scheduleJobsOnceNow * * For the test:/*from ww w .j a va 2s . c o m*/ * 0. Define a time window that we will search within * 1. Schedule 1 job, it will fire outside of our test window period * 2. Retrieve the ReportJob from the REPO and use the 'scheduleJobsOnceNow' facility to schedule an immediate run * 3. Query to find job within our window and verify that we fetch the expected one which is the runOnceNow job. */ @Test() public void doScheduleJobsOnceNowTest() { m_logger.info("\n\nReportSchedulingTestTestNG => doScheduleJobsOnceNowTest() called"); // REPORT JOB 1 The Job that we want to execute 'onceNow' at a later time Date now = new Date(); long nowMillis = now.getTime(); long windowIntervalMillis = 1000 * 60 * 6; // size of the query time window 6 minutes long queryWindowStart = nowMillis - 10; // wind clock back just to be sure long queryWindowEnd = nowMillis + windowIntervalMillis; Date report01StartDate = new Date(queryWindowStart + (1000 * 60 * 20)); // start in 20 minutes Date startDate = new Date(queryWindowStart); Date endDate = new Date(queryWindowEnd); m_logger.info("at test start, trigger query window startDate=" + startDate + ", endDate=" + endDate); ReportJobSource source = new ReportJobSource(); // validator requires a REAL report source.setReportUnitURI("/reports/samples/AllAccounts"); Map params = new HashMap(); source.setParametersMap(params); ReportJobSimpleTrigger trigger = new ReportJobSimpleTrigger(); trigger.setStartDate(report01StartDate); trigger.setOccurrenceCount(5); trigger.setRecurrenceInterval(1); trigger.setRecurrenceIntervalUnit(ReportJobSimpleTrigger.INTERVAL_MINUTE); ReportJobRepositoryDestination repositoryDestination = new ReportJobRepositoryDestination(); // validator requires a REAL folder repositoryDestination.setFolderURI("/reports/samples"); repositoryDestination.setOutputDescription("report output"); repositoryDestination.setSequentialFilenames(true); repositoryDestination.setTimestampPattern("yyyyMMdd"); repositoryDestination.setDefaultReportOutputFolderURI("/default/report_output/folder"); repositoryDestination.setUsingDefaultReportOutputFolderURI(true); ReportJobMailNotification mailNotification = new ReportJobMailNotification(); mailNotification.addTo("john@smith.com"); mailNotification.setSubject("Scheduled report"); mailNotification.setMessageText("Executed report"); ReportJob job_01 = new ReportJob(); job_01.setLabel("hoo"); job_01.setDescription("bar"); job_01.setSource(source); job_01.setTrigger(trigger); job_01.setBaseOutputFilename("hoo_" + (new Date().getTime())); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_PDF); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_RTF); job_01.setContentRepositoryDestination(repositoryDestination); job_01.setMailNotification(mailNotification); job_01 = m_reportSchedulingService.scheduleJob(m_executionContext, job_01); m_logger.info("scheduled Job 01 id='" + job_01.getId() + "' label='" + job_01.getLabel() + " for " + report01StartDate); assertTrue(job_01 != null); long jobId_01 = job_01.getId(); ReportJob readJob_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); assertTrue("Fatal error ! we were unable to retrieve job '" + jobId_01 + "' that we just scheduled !", readJob_01 != null); // now schedule that same report to run onceNow using the reportJob as the model to clone List<ReportJob> l = new ArrayList<ReportJob>(); l.add(readJob_01); List<ReportJob> scheduledOnceList = m_reportSchedulingService.scheduleJobsOnceNow(m_executionContext, l); if (scheduledOnceList == null || scheduledOnceList.size() <= 0) assertEquals("Error our scheduleOnceList should contain 1 report, instead it is null or empty", 1 == 2); assertEquals("Error our scheduleOnceList should contain 1 report, instead it contains " + scheduledOnceList.size(), scheduledOnceList.size(), 1); ReportJob scheduledOnceJob = scheduledOnceList.get(0); long scheduledOnceJobId = scheduledOnceJob.getId(); // now verify that the trigger for the runOnce job got set by Quartz m_logger.info("get jobs with nextFIreTime between start=" + startDate + " and end=" + endDate); m_logger.info( "verify that our scheduleOnce Job " + scheduledOnceJobId + " has a nextFireTime before " + endDate); boolean deleted = false; try { List<ReportJobSummary> summaryList = m_reportSchedulingService.getJobsByNextFireTime(m_executionContext, null, startDate, endDate, null); StringBuilder sb = new StringBuilder(); int count = 0; ReportJobSummary theSummary = null; ReportJobRuntimeInformation theInfo = null; for (ReportJobSummary js : summaryList) { ReportJobRuntimeInformation ri = js.getRuntimeInformation(); if (js.getId() == scheduledOnceJobId) { theInfo = ri; theSummary = js; } Date nextFireTime = (ri == null ? null : ri.getNextFireTime()); String time = (nextFireTime == null ? "NULL" : nextFireTime.toString()); sb.append((count++) + " job " + js.getId() + " " + nextFireTime + " = " + time + "\n"); } m_logger.info(sb.toString()); int expectedNumberOfReports = 1; m_logger.info( "expecting query to return " + expectedNumberOfReports + " reports, got " + summaryList.size()); assertEquals( "Error ! expected to get back " + expectedNumberOfReports + " Reports in window but instead we got " + summaryList.size(), expectedNumberOfReports, summaryList.size()); Date nextFireTime = theInfo.getNextFireTime(); assertTrue("Error ! Expected non-NULL Trigger.nextFireTime for runOnceNowJob " + scheduledOnceJobId, nextFireTime != null); assertTrue("Error ! Expected our runOnceNow Job to have a nextTriggerFireTime " + "before " + endDate + ", but instead it is set for " + nextFireTime, nextFireTime.before(endDate)); try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(theSummary.getId())); deleted = true; } catch (Throwable th) { m_logger.info("Error ! Throwable while attempting to delete job '" + th.getMessage() + "'"); } job_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); assertNull(job_01); ReportJob job_02 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(theSummary.getId())); assertNull(job_02); } finally { if (!deleted) { try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); } catch (Throwable th) { } try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(scheduledOnceJobId)); } catch (Throwable th) { } } } }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste de l'historique des notes * pour un concept (type CustomNote, ScopeNote, HistoryNote) une date * prcise// w w w. j a v a 2s. c o m * * @param ds * @param idConcept * @param idThesaurus * @param idTerm * @param idLang * @param date * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getNoteHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, String idTerm, String idLang, Date date) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT id, notetypecode, lexicalvalue, modified, username FROM note_historique, users" + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and (id_concept = '" + idConcept + "' OR id_term = '" + idTerm + "' )" + " and note_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { boolean exist = false; for (NodeNote nn : nodeNotes) { if (nn.getNotetypecode().equals(resultSet.getString("notetypecode"))) { if (nn.getModified().before(resultSet.getDate("modified"))) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(idLang); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setIdUser(resultSet.getString("username")); nodeNotes.add(nodeNote); } exist = true; } } if (!exist) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(idLang); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setIdUser(resultSet.getString("username")); nodeNotes.add(nodeNote); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date historique Notes of Concept : " + idConcept, sqle); } return nodeNotes; }
From source file:com.clustercontrol.monitor.run.factory.RunMonitor.java
/** * ?????/*from w ww .j a va2s. com*/ * <p> * ???????????? * <ol> * <li>ID???<code>null</code>????????</li> * <li>????{@link com.clustercontrol.monitor.message.LogOutputNotifyInfo }???? * ???????????????? * </li> * <li>??????</li> * </ol> * * @param isNode ???</code> true </code> * @param facilityId ?ID * @param result ? * @param generationDate ?? * @throws HinemosUnknown * @since 2.0.0 * * @see com.clustercontrol.monitor.message.LogOutputNotifyInfo * @see com.clustercontrol.repository.session.RepositoryControllerBean#getFacilityPath(java.lang.String, java.lang.String) * @see #getNotifyRelationInfos() * @see #getPriority(int) * @see #getMessage(int) * @see #getMessageOrg(int) * @see #getJobRunInfo(int) * @see #getMessageForScope(int) * @see #getMessageOrgForScope(int) * @see #getJobRunInfoForScope(int) */ protected void notify(boolean isNode, String facilityId, int result, Date generationDate) throws HinemosUnknown { // for debug if (m_log.isDebugEnabled()) { m_log.debug("notify() isNode = " + isNode + ", facilityId = " + facilityId + ", result = " + result + ", generationDate = " + generationDate.toString()); } // ?????? if (!m_monitor.getMonitorFlg()) { m_log.debug("notify() isNode = " + isNode + ", facilityId = " + facilityId + ", result = " + result + ", generationDate = " + generationDate.toString() + ", monitorFlg is false"); return; } // ID??????????? String notifyGroupId = getNotifyGroupId(); List<NotifyRelationInfo> notifyRelationList = m_monitor.getNotifyRelationList(); if (notifyRelationList == null || notifyRelationList.size() == 0) { return; } // OutputBasicInfo notifyInfo = new OutputBasicInfo(); notifyInfo.setPluginId(m_monitorTypeId); notifyInfo.setMonitorId(m_monitorId); notifyInfo.setApplication(m_monitor.getApplication()); String facilityPath = new RepositoryControllerBean().getFacilityPath(facilityId, null); notifyInfo.setFacilityId(facilityId); notifyInfo.setScopeText(facilityPath); int priority = -1; String message = ""; String messageOrg = ""; if (isNode) { // ?? priority = getPriority(result); message = getMessage(result); messageOrg = getMessageOrg(result); } else { // ?? priority = result; message = getMessageForScope(result); messageOrg = getMessageOrgForScope(result); } notifyInfo.setPriority(priority); notifyInfo.setMessage(message); notifyInfo.setMessageOrg(messageOrg); if (generationDate != null) { notifyInfo.setGenerationDate(generationDate.getTime()); } // for debug if (m_log.isDebugEnabled()) { m_log.debug("notify() priority = " + priority + " , message = " + message + " , messageOrg = " + messageOrg + ", generationDate = " + generationDate); } // ? if (m_log.isDebugEnabled()) { m_log.debug("sending message" + " : priority=" + notifyInfo.getPriority() + " generationDate=" + notifyInfo.getGenerationDate() + " pluginId=" + notifyInfo.getPluginId() + " monitorId=" + notifyInfo.getMonitorId() + " facilityId=" + notifyInfo.getFacilityId() + " subKey=" + notifyInfo.getSubKey() + ")"); } new NotifyControllerBean().notify(notifyInfo, notifyGroupId); }
From source file:org.couchbase.mock.client.ClientViewTest.java
/** * This test case adds two non-JSON documents and * utilises a special view that returns them. * * @pre Create non-JSON documents and set them to the db. * Prepare a view query with docs and iterate over the response. * Find the non json documents in the result set and assert them. * @post This makes sure that the view handlers don't break when * non-JSON data is read from the view.//from www . j a v a 2 s. c om */ @Test public void testViewWithBinaryDocs() throws Exception { // Create non-JSON documents Date now = new Date(); client.set("nonjson1", 0, now, PersistTo.MASTER).get(PERSIST_WAIT_TIME, TimeUnit.SECONDS); client.set("nonjson2", 0, 42, PersistTo.MASTER).get(PERSIST_WAIT_TIME, TimeUnit.SECONDS); View view = client.getView(DESIGN_DOC_BINARY, VIEW_NAME_BINARY); Query query = new Query(); query.setIncludeDocs(true); query.setReduce(false); query.setStale(Stale.FALSE); assert view != null : "Could not retrieve view"; ViewResponse response = client.query(view, query); Iterator<ViewRow> itr = response.iterator(); while (itr.hasNext()) { ViewRow row = itr.next(); if (row.getKey().equals("nonjson1")) { assertEquals(now.toString(), row.getDocument().toString()); } if (row.getKey().equals("nonjson2")) { assertEquals(42, row.getDocument()); } } /* FIXME: I have no idea how the tests here ever worked properly, since these documents are not deleted afterwards. Here' I'm going to delete them so bad things don't happen to the tets. */ client.delete("nonjson1").get(); client.delete("nonjson2").get(); }
From source file:com.jaspersoft.jasperserver.test.ReportSchedulingTestTestNG.java
/** * Test that exercises getJobsByNextFireTime * * For the test:// ww w .j ava2s .c om * 0. Define a time window that we will search within * 1. Schedule 2 jobs, 1 will fire within our window and 1 will fire outside of our window * 2. Query to find jobs within our window and verify that we fetch the expected one. * 3. Query all jobs and verify that we get both back. * * * We'll schedule 2 jobs */ @Test() public void doBasicFindByNextFireTimePersistenceTest() { m_logger.info("\n\nReportSchedulingTestTestNG => doBasicFindByNextFireTimePersistenceTest() called"); // REPORT JOB 1 The Job that we want out query to find Date now = new Date(); long nowMillis = now.getTime(); long windowIntervalMillis = 1000 * 60 * 6; // size of the query time window 6 minutes long queryWindowStart = nowMillis - 10; // wind clock back just to be sure long queryWindowEnd = nowMillis + windowIntervalMillis; Date report01StartDate = new Date(queryWindowStart + (1000 * 60 * 4)); // start in 4 minutes Date report02StartDate = new Date(queryWindowStart + (1000 * 60 * 10)); // start in 10 minutes Date startDate = new Date(queryWindowStart); Date endDate = new Date(queryWindowEnd); ReportJobSource source = new ReportJobSource(); // validator requires a REAL report source.setReportUnitURI("/reports/samples/AllAccounts"); Map params = new HashMap(); //params.put("param1", new Integer(5)); //params.put("param2", "value2"); source.setParametersMap(params); ReportJobSimpleTrigger trigger = new ReportJobSimpleTrigger(); trigger.setStartDate(report01StartDate); trigger.setOccurrenceCount(5); trigger.setRecurrenceInterval(1); trigger.setRecurrenceIntervalUnit(ReportJobSimpleTrigger.INTERVAL_MINUTE); ReportJobRepositoryDestination repositoryDestination = new ReportJobRepositoryDestination(); // validator requires a REAL folder repositoryDestination.setFolderURI("/reports/samples"); repositoryDestination.setOutputDescription("report output"); repositoryDestination.setSequentialFilenames(true); repositoryDestination.setTimestampPattern("yyyyMMdd"); repositoryDestination.setDefaultReportOutputFolderURI("/default/report_output/folder"); repositoryDestination.setUsingDefaultReportOutputFolderURI(true); ReportJobMailNotification mailNotification = new ReportJobMailNotification(); mailNotification.addTo("john@smith.com"); mailNotification.setSubject("Scheduled report"); mailNotification.setMessageText("Executed report"); ReportJob job_01 = new ReportJob(); job_01.setLabel("foo"); job_01.setDescription("bar"); job_01.setSource(source); job_01.setTrigger(trigger); job_01.setBaseOutputFilename("foo_" + (new Date().getTime())); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_PDF); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_RTF); job_01.setContentRepositoryDestination(repositoryDestination); job_01.setMailNotification(mailNotification); job_01 = m_reportSchedulingService.scheduleJob(m_executionContext, job_01); m_logger.info("scheduled Job 01 id='" + job_01.getId() + "' label='" + job_01.getLabel() + " for " + report01StartDate); assertNotNull(job_01); long jobId_01 = job_01.getId(); String userName = job_01.getUsername(); // Report Job 02 The Job that we DON'T want our query to find source = new ReportJobSource(); // validator requires a REAL report source.setReportUnitURI("/reports/samples/AllAccounts"); params = new HashMap(); source.setParametersMap(params); ReportJobSimpleTrigger trigger2 = new ReportJobSimpleTrigger(); trigger2.setStartDate(report02StartDate); trigger2.setOccurrenceCount(5); trigger2.setRecurrenceInterval(1); trigger2.setRecurrenceIntervalUnit(ReportJobSimpleTrigger.INTERVAL_MINUTE); repositoryDestination = new ReportJobRepositoryDestination(); // validator requires a REAL folder repositoryDestination.setFolderURI("/reports/samples"); repositoryDestination.setOutputDescription("report output"); repositoryDestination.setSequentialFilenames(false); repositoryDestination.setTimestampPattern("yyyyMMdd"); repositoryDestination.setSaveToRepository(false); mailNotification = new ReportJobMailNotification(); mailNotification.addTo("john@smith.com"); mailNotification.addTo("peter@pan.com"); mailNotification.setSubject("Scheduled report"); mailNotification.setMessageText("Executed report"); ReportJob job_02 = new ReportJob(); job_02.setLabel("A_ReportJob_2"); job_02.setDescription("bar"); job_02.setSource(source); job_02.setTrigger(trigger2); job_02.setBaseOutputFilename("aReportJob_2_OUTPUT_" + (new Date().getTime())); job_02.addOutputFormat(ReportJob.OUTPUT_FORMAT_PDF); job_02.addOutputFormat(ReportJob.OUTPUT_FORMAT_RTF); job_02.setContentRepositoryDestination(repositoryDestination); boolean exceptionCaught = false; try { job_02.setMailNotification(mailNotification); } catch (Exception ex) { exceptionCaught = true; } assertTrue(exceptionCaught); mailNotification.setResultSendTypeCode(mailNotification.RESULT_SEND_ATTACHMENT); job_02.setMailNotification(mailNotification); job_02 = m_reportSchedulingService.scheduleJob(m_executionContext, job_02); m_logger.info("scheduled Job 02 id='" + job_02.getId() + "' label='" + job_02.getLabel() + " for " + report02StartDate); assertEquals(false, job_02.getContentRepositoryDestination().isSaveToRepository()); assertNotNull(job_02); long jobId_02 = job_02.getId(); boolean deleted = false; try { List<ReportJobSummary> summaryList = m_reportSchedulingService.getJobsByNextFireTime(m_executionContext, null, startDate, endDate, null); StringBuilder sb = new StringBuilder(); int count = 0; for (ReportJobSummary js : summaryList) { ReportJobRuntimeInformation ri = js.getRuntimeInformation(); Date nextFireTime = (ri == null ? null : ri.getNextFireTime()); String time = (nextFireTime == null ? "NULL" : nextFireTime.toString()); sb.append((count++) + " job " + js.getId() + " " + nextFireTime + " = " + time + "\n"); } m_logger.info(sb.toString()); m_logger.info("expecting query to return 1 report, got " + summaryList.size()); int expectedNumberOfReports = 1; assertEquals("Error ! expected to get back 1 Report in window but instead we got " + summaryList.size(), expectedNumberOfReports, summaryList.size()); ReportJobSummary rjs = summaryList.get(0); long id1 = rjs.getId(); m_logger.info("Expected to get back jobId='" + jobId_01 + "', got '" + id1 + "'"); assertEquals("Error ! expected to get back job01 id = '" + jobId_01 + "', but instead we got '" + id1 + ", note: job02 id = '" + jobId_02, id1, jobId_01); summaryList = m_reportSchedulingService.getJobsByNextFireTime(m_executionContext, null, null, null, null); sb.setLength(0); count = 0; for (ReportJobSummary js : summaryList) { ReportJobRuntimeInformation ri = js.getRuntimeInformation(); Date nextFireTime = (ri == null ? null : ri.getNextFireTime()); String time = (nextFireTime == null ? "NULL" : nextFireTime.toString()); sb.append((count++) + " job " + js.getId() + " " + nextFireTime + " = " + time + "\n"); } m_logger.info(sb.toString()); m_logger.info("expecting query to return 2 report, got " + summaryList.size()); expectedNumberOfReports = 2; assertEquals("Error ! expected to get back 2 Reports but instead we got " + summaryList.size(), expectedNumberOfReports, summaryList.size()); try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_02)); deleted = true; } catch (Throwable th) { m_logger.info("Error ! Throwable while attempting to delete job '" + th.getMessage() + "'"); } m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_02)); job_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); assertNull(job_01); job_02 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_02)); assertNull(job_02); } finally { if (!deleted) { try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); } catch (Throwable th) { } try { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_02)); } catch (Throwable th) { } } } }
From source file:org.opencastproject.capture.impl.SchedulerImplTest.java
private void checkTime(Calendar start, int offset, ScheduledEvent scheduleEvent) { Date before = new Date(); Date after = new Date(); // Create a calendar event a second before the time we expect. before = new Date( before.getTime() + (CaptureParameters.MINUTES * CaptureParameters.MILLISECONDS * offset) - 3000); // Create a calendar event a second after the time we expect. after = new Date( after.getTime() + (CaptureParameters.MINUTES * CaptureParameters.MILLISECONDS * offset) + 3000); Date time = new Date(scheduleEvent.getStartTime()); Assert.assertTrue("getSchedule() returned " + new Date(scheduleEvent.getStartTime()).toString() + " as a start time for the event when it should have been " + offset + " minutes after right now and 1 second after " + before, before.before(time)); Assert.assertTrue("getSchedule() returned " + new Date(scheduleEvent.getStartTime()).toString() + " as a start time for the event when it should have been " + offset + " minutes before right now and 1 second before " + after.toString(), after.after(time)); }
From source file:com.clustercontrol.monitor.run.factory.RunMonitor.java
/** * ?????(?)/*from w ww .j a v a 2 s . c o m*/ * <p> * ???????????? * <ol> * <li>ID???<code>null</code>????????</li> * <li>????{@link com.clustercontrol.monitor.message.LogOutputNotifyInfo }???? * ???????????????? * </li> * <li>??????</li> * </ol> * * @param isNode ???</code> true </code> * @param facilityId ?ID * @param result ? * @param generationDate ?? * @param resultList ? * @throws HinemosUnknown * @since 2.0.0 * * @see com.clustercontrol.monitor.message.LogOutputNotifyInfo * @see com.clustercontrol.repository.session.RepositoryControllerBean#getFacilityPath(java.lang.String, java.lang.String) * @see #getNotifyRelationInfos() * @see #getPriority(int) * @see #getMessage(int) * @see #getMessageOrg(int) * @see #getJobRunInfo(int) * @see #getMessageForScope(int) * @see #getMessageOrgForScope(int) * @see #getJobRunInfoForScope(int) */ protected void notify(boolean isNode, String facilityId, int result, Date generationDate, MonitorRunResultInfo resultInfo) throws HinemosUnknown { // for debug if (m_log.isDebugEnabled()) { m_log.debug("notify() isNode = " + isNode + ", facilityId = " + facilityId + ", result = " + result + ", generationDate = " + generationDate.toString() + ", resultInfo = " + resultInfo.getMessage()); } boolean monitorFlg = false; monitorFlg = m_monitor.getMonitorFlg(); // ?????? if (!monitorFlg) { m_log.debug("notify() isNode = " + isNode + ", facilityId = " + facilityId + ", result = " + result + ", generationDate = " + generationDate.toString() + ", resultInfo = " + resultInfo.getMessage() + ", monitorFlg is false"); return; } // ID??????????? String notifyGroupId = resultInfo.getNotifyGroupId(); if (notifyGroupId == null || "".equals(notifyGroupId)) { return; } // OutputBasicInfo notifyInfo = new OutputBasicInfo(); notifyInfo.setPluginId(m_monitorTypeId); notifyInfo.setMonitorId(m_monitorId); notifyInfo.setApplication(m_monitor.getApplication()); String facilityPath = new RepositoryControllerBean().getFacilityPath(facilityId, null); notifyInfo.setFacilityId(facilityId); notifyInfo.setScopeText(facilityPath); int priority = -1; String message = ""; String messageOrg = ""; if (isNode) { // ?? priority = resultInfo.getPriority(); message = resultInfo.getMessage(); messageOrg = resultInfo.getMessageOrg(); } else { // ?? priority = result; message = getMessageForScope(result); messageOrg = getMessageOrgForScope(result); } notifyInfo.setPriority(priority); // ? if (resultInfo.getDisplayName() != null && !"".equals(resultInfo.getDisplayName())) { // ??????????????? notifyInfo.setSubKey(resultInfo.getDisplayName()); } else if (resultInfo.getPatternText() != null) { // ????????????? notifyInfo.setSubKey(resultInfo.getPatternText()); } notifyInfo.setMessage(message); notifyInfo.setMessageOrg(messageOrg); if (generationDate != null) { notifyInfo.setGenerationDate(generationDate.getTime()); } // for debug if (m_log.isDebugEnabled()) { m_log.debug("notify() priority = " + priority + " , message = " + message + " , messageOrg = " + messageOrg + ", generationDate = " + generationDate); } // ? if (m_log.isDebugEnabled()) { m_log.debug("sending message" + " : priority=" + notifyInfo.getPriority() + " generationDate=" + notifyInfo.getGenerationDate() + " pluginId=" + notifyInfo.getPluginId() + " monitorId=" + notifyInfo.getMonitorId() + " facilityId=" + notifyInfo.getFacilityId() + " subKey=" + notifyInfo.getSubKey() + ")"); } new NotifyControllerBean().notify(notifyInfo, notifyGroupId); }
From source file:org.jini.commands.files.FindFiles.java
/** * Search for files with specific extensions * * @param dirName/*from ww w .j a va 2 s .c o m*/ * @param extensions * @param recursive */ void findFileWithExtension(String dirName, String[] extensions, boolean recursive) { PrintChar printChar = new PrintChar(); printChar.setOutPutChar(">"); if ((this.getJcError() == false) && (this.isDir(dirName) == false)) { this.setJcError(true); this.addErrorMessages("Error : Directory [" + dirName + "] does not exsist."); } if (this.getJcError() == false) { printChar.start(); File root = new File(dirName); try { Collection files = FileUtils.listFiles(root, extensions, recursive); TablePrinter tableF = new TablePrinter("Name", "Type", "Readable", "Writable", "Executable", "Size KB", "Size MB", "Last Modified"); for (Iterator iterator = files.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); if (this.withDetails == false) { System.out.println(file.getAbsolutePath()); } else { java.util.Date lastModified = new java.util.Date(file.lastModified()); long filesizeInKB = file.length() / 1024; double bytes = file.length(); double kilobytes = (bytes / 1024); double megabytes = (kilobytes / 1024); String type = ""; DecimalFormat df = new DecimalFormat("####.####"); if (file.isDirectory()) { type = "Dir"; } if (file.isFile()) { type = "File"; } if (file.isFile() && file.isHidden()) { type = "File (Hidden)"; } if (file.isDirectory() && (file.isHidden())) { type = "Dir (Hidden)"; } String canExec = "" + file.canExecute(); String canRead = "" + file.canRead(); String canWrite = "" + file.canWrite(); String filesizeInKBStr = Long.toString(filesizeInKB); String filesizeInMBStr = df.format(megabytes); tableF.addRow(file.getAbsolutePath(), type, canRead, canWrite, canExec, filesizeInKBStr, filesizeInMBStr, lastModified.toString()); } } if (this.withDetails == true) { if (files.isEmpty() == false) { tableF.print(); } } printChar.setStopPrinting(true); } catch (Exception e) { this.setJcError(true); this.addErrorMessages("Error : " + e.toString()); } } this.done = true; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createVertretungsliste(Date parsedFrom, Date parsedTo, OutputStream out) throws DocumentException, BadElementException, IOException { Document document = new Document(); Log.d("create Vertretungsliste von " + parsedFrom.toString() + " bis" + parsedTo.toString()); GregorianCalendar cf = (GregorianCalendar) GregorianCalendar.getInstance(); cf.setTime(parsedFrom);//ww w. j a v a2 s .c om GregorianCalendar ct = (GregorianCalendar) GregorianCalendar.getInstance(); ct.setTime(parsedTo); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); String kopf = ""; kopf += ("<table border='1' align='center' width='100%'>"); kopf += ("<tr>"); kopf += ("<td rowspan=\"3\" width='150px'></td>"); kopf += ("<td align='center'><h2>Multi Media Berufsbildende Schulen Hannover</h2></td>"); kopf += ("<td colspan=\"2\" align='center'><b>Digitales Klassenbuch Vertretungsliste</b></td>"); kopf += ("</tr>"); kopf += ("<tr>"); kopf += ("<td align='center' rowspan=\"2\"><h3>von " + toReadableDate(cf) + " bis " + toReadableDate(ct) + "</h3></td>"); kopf += ("<td style=\"font-size: 11;padding:4px;height:30px;\">Verantwortlicher: BO </td>"); kopf += ("<td style=\"font-size: 11;padding:4px;\">geprft</td>"); kopf += ("</tr>"); kopf += ("<tr>"); DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); Calendar c = df.getCalendar(); c.setTimeInMillis(System.currentTimeMillis()); String dat = c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR); kopf += ("<td style=\"font-size: 11;\">Ausdruck am: " + dat + "</td>"); kopf += ("<td style=\"font-size: 11;\">Datum</td>"); kopf += ("</tr>"); kopf += ("</table>"); kopf += ("<p> </p>"); htmlString.append(kopf); document.open(); Query qb = em.createNamedQuery("findVertretungbyDate"); qb.setParameter("paramFromDate", parsedFrom); qb.setParameter("paramToDate", parsedTo); List<Vertretung> vl = qb.getResultList(); Log.d("Result Liste = " + vl); for (Vertretung v : vl) { htmlString.append("<h3>Absenz von " + v.getAbsenzVon() + " am " + toReadableFromat(v.getAbsenzAm()) + " eingereicht von " + v.getEingereichtVon() + " am " + toReadableFromat(v.getEingereichtAm()) + "</h3>"); htmlString.append("<h4>" + v.getKommentar() + "</h4>"); htmlString.append("<p> </p>"); htmlString.append("<table border='0.5' align='center' width='100%'>"); htmlString.append("<tr>"); htmlString.append( "<td width='10%' style=\"padding:4px;\">Stunde</td><td width='15%' style=\"padding:4px;\">Klasse</td><td width='15%' style=\"padding:4px;\">Aktion</td><td width='10%' style=\"padding:4px;\">Vertreter</td><td style=\"padding:4px;\">Kommentar</td>"); htmlString.append("</tr>"); JSONParser jsonParser = new JSONParser(); try { JSONArray ja = (JSONArray) jsonParser.parse(v.getJsonString()); for (int i = 0; i < ja.size(); i++) { JSONObject jo = (JSONObject) ja.get(i); htmlString.append("<tr>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='10%'>" + jo.get("stunde") + "</td>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='15%'>" + jo.get("Klasse") + "</td>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='15%'>" + jo.get("Aktion") + "</td>"); htmlString.append("<td style=\"font-size: 11;padding:4px;\" width='10%'>" + jo.get("Vertreter") + "</td>"); htmlString.append("<td style=\"font-size: 11;padding:4px;\">" + jo.get("Kommentar") + "</td>"); htmlString.append("</tr>"); } } catch (org.json.simple.parser.ParseException ex) { ex.printStackTrace(); Logger.getLogger(DokuServlet.class.getName()).log(Level.SEVERE, null, ex); } htmlString.append("</table>"); htmlString.append("<p></p>"); } //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:org.apache.hadoop.hive.service.HSSessionItem.java
public HSSessionItem(HSAuth auth, String sessionName, TTransport trans) throws FileNotFoundException { this.jobid = 0; this.auth = auth; this.sessionName = sessionName; this.home = "."; this.runable = null; this.jr = null; this.config = new SessionConfig(jobType.ONESHOT); this.jobStatus = HSSessionItem.JobStatus.INIT; this.date = new Date(); this.opdate = this.date; if (SessionState.get() != null) { this.to = SessionState.get().getConf().getIntVar(HiveConf.ConfVars.HIVESESSIONTIMEOUT); if (this.to > 7200 || this.to < 0) { this.to = 60; }/*from w w w .ja v a 2 s . co m*/ } else { this.to = 7200; } this.transSet = new HashSet(); if (trans != null) transSet.add(trans); l4j.debug("HSSessionItem created"); status = SessionItemStatus.NEW; l4j.debug("Wait for NEW->READY transition"); l4j.debug("NEW->READY transition complete"); queryInfo = new HashMap<Integer, GregorianCalendar>(); this.current_query_count = 0; InetAddress localhost = null; try { localhost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } if (localhost != null) hostip = localhost.getHostAddress(); try { TSocket tSocket = (TSocket) trans; Socket socket = tSocket.getSocket(); InetAddress addr = socket.getInetAddress(); this.clientip = addr.getHostAddress(); l4j.debug("client address: " + addr.getHostAddress() + " client port: " + socket.getPort()); } catch (Exception e) { l4j.debug("get IP, PORT failed in create session"); } if ((conf_file_loc == null) || conf_file_loc.length() == 0) { return; } File f = new File(conf_file_loc); if (!f.exists()) { if (!f.mkdir()) { return; } } try { sessionFileName = conf_file_loc + "/" + sessionName + ".txt"; File thefile = new File(sessionFileName); if (!thefile.exists()) { dayLogStream = new PrintWriter(new FileWriter(sessionFileName, true)); } else { dayLogStream = new PrintWriter(new FileWriter(sessionFileName, true)); dayLogStream.print("+++++++++++++++++++++++++++++++++++++++++++++++++++"); dayLogStream.print('\n'); dayLogStream.print("A new session is appended here! "); dayLogStream.print('\n'); Calendar rightNow = Calendar.getInstance(); Date time = rightNow.getTime(); dayLogStream.print(time.toString()); dayLogStream.print('\n'); dayLogStream.print("+++++++++++++++++++++++++++++++++++++++++++++++++++"); dayLogStream.print('\n'); } } catch (Exception ex) { } }