Produced by Araxis Merge on 2/7/2017 12:14:07 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | cpss.zip\cpss\src\main\java\gov\va\cpss\job | SimpleTestJob.java | Wed Feb 1 21:07:26 2017 UTC |
2 | cpss.zip\cpss\src\main\java\gov\va\cpss\job | SimpleTestJob.java | Fri Feb 3 20:54:41 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 330 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | package go v.va.cpss. job; | |
2 | ||
3 | import jav a.util.Ran dom; | |
4 | ||
5 | import org .apache.lo g4j.Logger ; | |
6 | import org .quartz.Jo bExecution Context; | |
7 | import org .quartz.Jo bExecution Exception; | |
8 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
9 | import org .springfra mework.sch eduling.qu artz.Quart zJobBean; | |
10 | ||
11 | import gov .va.cpss.m odel.Batch Job; | |
12 | import gov .va.cpss.m odel.Batch Run; | |
13 | import gov .va.cpss.s ervice.Bat chService; | |
14 | import gov .va.cpss.s ervice.Ema ilService; | |
15 | ||
16 | /** | |
17 | * Base jo b stub cla ss for CBS S quartz j obs for te mporary de mo purpose s. | |
18 | * Eventua lly all im plementing classes s hould be c onverted t o extend C bssBaseJob . | |
19 | * @author D N S | |
20 | */ | |
21 | public abs tract clas s SimpleTe stJob exte nds Quartz JobBean { | |
22 | ||
23 | pr otected st atic final Logger jo bLogger = Logger.get Logger(Sim pleTestJob .class.get CanonicalN ame()); | |
24 | ||
25 | /* * | |
26 | * The batch job name that is po pulated fr om the dat abase at s cheduler | |
27 | * initializ ation. | |
28 | * / | |
29 | pr otected St ring name; | |
30 | ||
31 | /* * | |
32 | * The servi ce used to manage ba tch issues . | |
33 | * / | |
34 | @A utowired | |
35 | pr ivate Batc hService b atchServic e; | |
36 | ||
37 | /* * | |
38 | * The servi ce used to send emai l. | |
39 | * / | |
40 | @A utowired | |
41 | pr otected Em ailService emailServ ice; | |
42 | ||
43 | /* | |
44 | * The error message f or the bat ch run. | |
45 | * / | |
46 | pr otected St ring error Message; | |
47 | ||
48 | pu blic Strin g getName( ) { | |
49 | retu rn name; | |
50 | } | |
51 | ||
52 | pu blic void setName(St ring name) { | |
53 | this .name = na me; | |
54 | } | |
55 | ||
56 | pr otected vo id execute Internal(J obExecutio nContext c tx) throws JobExecut ionExcepti on { | |
57 | ||
58 | // R eset the e rror messa ge. | |
59 | erro rMessage = null; | |
60 | ||
61 | // G et the bat ch job. | |
62 | Batc hJob bj = batchServi ce.getBatc hJobByName (name); | |
63 | // S tart a bat ch run. | |
64 | Batc hRun bR = batchServi ce.startRu n(bj.getId ()); | |
65 | ||
66 | if ( bR != null ) { | |
67 | jobLog ger.info(" Job " + na me + " Sta rted: " + bR.getStar tDate()); | |
68 | // Run random am ount of ti me in seco nds. | |
69 | Random randomTim e = new Ra ndom(); | |
70 | int sl eep = rand omTime.nex tInt(10); | |
71 | ||
72 | // Ran domly erro r the job. | |
73 | if ((s leep % 3) == 0) { | |
74 | // Simul ate Error. | |
75 | simulate Error(bR); | |
76 | if (batc hService.e rrorRun(bR )) { | |
77 | jobLogger. info("Job " + name + " Complet ed with Er ror: " + b R.getEndDa te()); | |
78 | } else { | |
79 | jobLogger. error("Pro blem Endin g Job " + name + " w ith Error" ); | |
80 | } | |
81 | } else { | |
82 | // Simul ate Job Ru n. | |
83 | try { | |
84 | Thread.sle ep(sleep * 1000); | |
85 | } catch (Exception e) { | |
86 | jobLogger. error("Pro blem Sleep ing " + na me + " , E X: " + e.g etMessage( )); | |
87 | } | |
88 | ||
89 | bR.setMe ssage(buil dEmailCust omInfo().t oString()) ; | |
90 | ||
91 | if (batc hService.c ompleteRun (bR)) { | |
92 | jobLogger. info("Job " + name + " Ended: " + bR.get EndDate()) ; | |
93 | } else { | |
94 | jobLogger. error("Pro blem Endin g Job " + name); | |
95 | } | |
96 | } | |
97 | ||
98 | emailS ervice.cps sReadyToSe ndEmail(bj .getEmail( ), buildEm ailSubject (bj), buil dEmailMess age(bj, bR )); | |
99 | ||
100 | } el se { | |
101 | jobLog ger.error( "Problem S tarting Jo b " + name ); | |
102 | emailS ervice.cps sReadyToSe ndEmail(bj .getEmail( ), buildEm ailSubject (bj), "Pro blem Start ing Job " + name); | |
103 | } | |
104 | } | |
105 | ||
106 | pr otected vo id simulat eError(Bat chRun batc hRun) { | |
107 | erro rMessage = "\n\nErro r Message: \nSimple Error!"; | |
108 | batc hRun.setMe ssage(erro rMessage); | |
109 | } | |
110 | ||
111 | /* * | |
112 | * Build an email subj ect. | |
113 | * | |
114 | * @return | |
115 | * / | |
116 | pr otected St ring build EmailSubje ct(BatchJo b batchJob ) { | |
117 | retu rn batchJo b.getDescr iption(); | |
118 | } | |
119 | ||
120 | /* * | |
121 | * Build an email mess age that c ommunicate s informat ion based on the | |
122 | * specific type of jo b. | |
123 | * / | |
124 | pr otected St ring build EmailMessa ge(BatchJo b batchJob , BatchRun batchRun) { | |
125 | Stri ngBuffer s trBuff = b uildEmailC ommonInfo( batchJob, batchRun); | |
126 | strB uff.append (buildEmai lCustomInf o()); | |
127 | strB uff.append (buildEmai lErrorInfo ()); | |
128 | retu rn strBuff .toString( ); | |
129 | } | |
130 | ||
131 | /* * | |
132 | * Use the B atchRun to return in formation that every job has i n common. | |
133 | * / | |
134 | pr otected St ringBuffer buildEmai lCommonInf o(BatchJob batchJob, BatchRun batchRun) { | |
135 | Stri ngBuffer s trBuff = n ew StringB uffer(); | |
136 | strB uff.append ("\nBatch Process Na me: "); | |
137 | strB uff.append (batchJob. getDescrip tion()); / / Read the Job class running | |
138 | strB uff.append ("\nStart: "); | |
139 | strB uff.append (batchRun. getServerS tartDateSt ring()); / / Read the start | |
140 | // date | |
141 | strB uff.append ("\nEnd: " ); | |
142 | strB uff.append (batchRun. getServerE ndDateStri ng()); // Read the e nd date | |
143 | strB uff.append ("\nStatus : "); | |
144 | strB uff.append (batchRun. getBatchSt atus().get Descriptio n()); // R ead the | |
145 | // s tatus | |
146 | // d escription | |
147 | retu rn strBuff ; | |
148 | } | |
149 | ||
150 | /* * | |
151 | * Build the error por tion of an email. | |
152 | * / | |
153 | pr otected St ringBuffer buildEmai lErrorInfo () { | |
154 | Stri ngBuffer s trBuff = n ew StringB uffer(); | |
155 | if ( (errorMess age != nul l) && !err orMessage. isEmpty()) { | |
156 | strBuf f.append(e rrorMessag e); | |
157 | } | |
158 | retu rn strBuff ; | |
159 | } | |
160 | ||
161 | /* * | |
162 | * Build the second po rtion of a n email th at contain s informat ion specif ic | |
163 | * to the de rived job class. | |
164 | * / | |
165 | ab stract Str ingBuffer buildEmail CustomInfo (); | |
166 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.