60. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/11/2019 10:54:10 AM Eastern Daylight 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.

60.1 Files compared

# Location File Last Modified
1 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\report\impl StandardReportServiceImpl.java Wed May 29 15:26:04 2019 UTC
2 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\report\impl StandardReportServiceImpl.java Mon Jun 10 19:27:46 2019 UTC

60.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1710
Changed 1 2
Inserted 0 0
Removed 0 0

60.3 Comparison options

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

60.4 Active regular expressions

No regular expressions were active.

60.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrig ht � 2010  VHA. All r ights rese rved
  3    ********* ********** ********** ********** ********** ********** *********/
  4   // Package
  5   package go v.va.med.c cht.servic e.report.i mpl;
  6  
  7   // Java cl asses
  8   import jav a.io.IOExc eption;
  9   import jav a.io.Seria lizable;
  10   import jav a.text.Par seExceptio n;
  11   import jav a.util.Arr ayList;
  12   import jav a.util.Dat e;
  13   import jav a.util.Has hMap;
  14   import jav a.util.Lin kedHashMap ;
  15   import jav a.util.Lis t;
  16   import jav a.util.Map ;
  17   import jav a.util.Set ;
  18  
  19   import org .apache.co mmons.lang 3.Validate ;
  20   import org .quartz.Cr onSchedule Builder;
  21   import org .quartz.Cr onTrigger;
  22   import org .quartz.Jo bDetail;
  23   import org .quartz.Sc hedulerExc eption;
  24   import org .quartz.Tr igger;
  25   import org .quartz.Tr iggerBuild er;
  26   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  27   import org .springfra mework.bea ns.factory .annotatio n.Qualifie r;
  28   import org .springfra mework.bea ns.factory .annotatio n.Value;
  29   import org .springfra mework.ste reotype.Se rvice;
  30  
  31   import gov .va.med.cc ht.model.r eport.Comp letedRepor t;
  32   import gov .va.med.cc ht.model.r eport.Comp letedRepor tFieldType ;
  33   import gov .va.med.cc ht.model.r eport.Repo rtParamete rs;
  34   import gov .va.med.cc ht.model.r eport.Repo rtSetup;
  35   import gov .va.med.cc ht.model.r eport.Sche duledRepor t;
  36   import gov .va.med.cc ht.model.r eport.Simp leComplete dReport;
  37   import gov .va.med.cc ht.model.t erminology .ReportFor mat;
  38   import gov .va.med.cc ht.model.t erminology .StandardR eport;
  39   import gov .va.med.cc ht.persist ent.Report DAO;
  40   import gov .va.med.cc ht.service .common.Ba tchProcess TriggerGro ups;
  41   import gov .va.med.cc ht.service .common.Te rminologyS ervice;
  42   import gov .va.med.cc ht.service .report.Co mpletedRep ortsSearch QueryInfo;
  43   import gov .va.med.cc ht.service .report.Re portConsta nts;
  44   import gov .va.med.cc ht.service .report.Re portFilter ;
  45   import gov .va.med.cc ht.service .report.Re portFilter SearchQuer yInfo;
  46   import gov .va.med.cc ht.service .report.Re portParame terConvers ionService ;
  47   import gov .va.med.cc ht.service .report.Re portPersis tenceServi ce;
  48   import gov .va.med.cc ht.service .report.St andardRepo rtCriteria ;
  49   import gov .va.med.cc ht.service .report.St andardRepo rtService;
  50   import gov .va.med.fw .model.Ent ityKey;
  51   import gov .va.med.fw .model.loo kup.Lookup ;
  52   import gov .va.med.fw .persisten t.DAOExcep tion;
  53   import gov .va.med.fw .persisten t.NoRecord FoundExcep tion;
  54   import gov .va.med.fw .report.Re portConfig uration;
  55   import gov .va.med.fw .report.Re portExcept ion;
  56   import gov .va.med.fw .report.Re portExport edType;
  57   import gov .va.med.fw .report.Re portServic e;
  58   import gov .va.med.fw .schedulin g.Auditabl eScheduled Process;
  59   import gov .va.med.fw .schedulin g.Schedule dProcessIn vocationCo ntext;
  60   import gov .va.med.fw .schedulin g.Scheduli ngService;
  61   import gov .va.med.fw .security. Permission ;
  62   import gov .va.med.fw .security. SecuritySe rvice;
  63   import gov .va.med.fw .security. UserPrinci pal;
  64   import gov .va.med.fw .service.A bstractCom ponent;
  65   import gov .va.med.fw .service.I nvalidSche duleExcept ion;
  66   import gov .va.med.fw .service.S erviceExce ption;
  67   import gov .va.med.fw .service.j ms.JMSPayl oad;
  68   import gov .va.med.fw .service.j ms.Message ProducerSe rvice;
  69   import gov .va.med.fw .util.Date Utils;
  70   import gov .va.med.fw .util.Stri ngUtils;
  71   import gov .va.med.fw .util.date .TimeZoneU tils;
  72  
  73   /**
  74    * Provide s services  to genera te and to  query stan dard repor ts in ESR
  75    * 
  76    * Project : Common</ br> Create d on: 12:0 0:00 PM </ br>
  77    * 
  78    * @author   DN S
  79    */
  80   @Service
  81   public cla ss Standar dReportSer viceImpl e xtends Abs tractCompo nent imple ments Stan dardReport Service,
  82                    Audi tableSched uledProces s, ReportC onstants {
  83           
  84           @A utowired
  85           pr ivate Repo rtDAO repo rtDAO = nu ll;
  86           @A utowired
  87           pr ivate Repo rtService  reportServ ice = null ;
  88           @A utowired
  89           pr ivate Term inologySer vice termi nologyServ ice = null ;
  90           @A utowired
  91           pr ivate Repo rtParamete rConversio nService r eportParam eterConver sionServic e = null;
  92           @A utowired
  93           pr ivate Sche dulingServ ice schedu lingServic e = null;
  94           @A utowired
  95           pr ivate Secu rityServic e security Service;
  96           @A utowired
  97           @Q ualifier(" common.jms .producer. reportingE vents")
  98           pr ivate Mess ageProduce rService m essageProd ucerServic e;
  99           @A utowired
  100           pr ivate Repo rtPersiste nceService  reportPer sistenceSe rvice;
  101  
  102           pr ivate Stri ng schedul edReportJo bName = nu ll;
  103           pr ivate Stri ng createR eportJMSPa yloadName;
  104           
  105           @V alue("${da ysToRetain CompletedR eports}")
  106           pr ivate Inte ger daysTo RetainComp letedRepor ts = 365;
  107           @V alue("${da ysToWarnBe foreDeleti ngReports} ")
  108           pr ivate Inte ger daysTo WarnBefore Deletion =  30;
  109  
  110  
  111           pr ivate stat ic final S tring PERI OD = ".";
  112  
  113           pu blic stati c final St ring SCHED ULED_REPOR T = "sched uledReport ";
  114           pu blic stati c final St ring DEFAU LT_AUDIT_N AME = SCHE DULED_PROC ESS_AUDIT_ PREFIX + " ScheduledR eport";
  115  
  116           pr ivate stat ic final l ong serial VersionUID  = 7440299 9970172453 73L;
  117  
  118           pu blic Stand ardReportS erviceImpl () {
  119                    supe r();
  120           }
  121  
  122  
  123   //      pu blic List< Date[]> ge tScheduleP review(Use rPrincipal  user, Rep ortSetup r eportSetup ,
  124   //                        int nu mDates, Da te startin gDate) thr ows Servic eException  {
  125   //               Repo rtSchedule  schedule  = reportSe tup.getRep ortSchedul e();
  126   //               Repo rtParamete rs params  = reportSe tup.getRep ortParamet ers();
  127   //               Date RangeBound ary report FromDate =  params.ge tScheduled ReportFrom Date();
  128   //               Date RangeBound ary report ToDate = p arams.getS cheduledRe portToDate ();
  129   //
  130   //               Stri ng cron =  SchedulerU tils.getCr onExpressi on(schedul e);
  131   //
  132   //               Time Zone timez one = Time ZoneUtils. getTimeZon e();
  133   //               if ( user != nu ll && user .getCurren tTimeZone( ) != null)
  134   //                        timezo ne = user. getCurrent TimeZone() ;
  135   //               /*if  (schedule .getDateTo Generate()  != null)
  136   //                        timezo ne = sched ule.getDat eToGenerat e().getTim eZone();
  137   //               */
  138   //
  139   //               fina l String t riggerName  = "";
  140   //               fina l String t riggerGrou p = "";
  141   //               fina l String t riggerJobN ame = "";
  142   //               fina l String t riggerJobG roup = "";
  143   //
  144   //               Cron Trigger tr igger = ne w CronTrig gerImpl(tr iggerName,  triggerGr oup, trigg erJobName,  triggerJo bGroup, cr on.toStrin g(), timez one);
  145   //               
  146   //               trig ger.setSta rtTime(sta rtingDate) ;
  147   //
  148   //               Date  timeIndex  = startin gDate;
  149   //               List <Date[]> r esults = n ew ArrayLi st<Date[]> ();
  150   //
  151   //               for  (int i = 0 ; i < numD ates; i++)  {
  152   //                        timeIn dex = trig ger.getFir eTimeAfter (timeIndex );
  153   //                        if (ti meIndex ==  null)
  154   //                                 break;
  155   //
  156   //                        result s.add(new  Date[] { t imeIndex,  reportFrom Date.calcu lateDate(t imeIndex),
  157   //                                          reportToDa te.calcula teDate(tim eIndex) }) ;
  158   //               }
  159   //               retu rn results ;
  160   //      }
  161  
  162           /* *
  163            *  @see gov. va.med.cch t.service. report.esr .service.r eport.Stan dardReport Service#ge tStandardR eports(gov .va.med.fw .security. UserPrinci pal)
  164            * /
  165           pu blic List< StandardRe port> getS tandardRep orts() thr ows Servic eException  {
  166                    List <StandardR eport> res ult = null ;
  167                    try  {
  168                             result  = termino logyServic e.findAllA ctive(Stan dardReport .class);
  169                    } ca tch (Excep tion ex) {
  170                             throw  new Servic eException (ex);
  171                    }
  172                    retu rn result;
  173           }
  174  
  175           /* *
  176            *  @see gov. va.med.cch t.service. report.esr .service.r eport.Stan dardReport Service#ge tStandardR eports(gov .va.med.fw .security. UserPrinci pal)
  177            * /
  178           pu blic List< StandardRe port> getS tandardRep orts(UserP rincipal u ser) throw s ServiceE xception {
  179                    Vali date.notNu ll(user, " A user pri ncipal mus t not be n ull");
  180                    List <StandardR eport> std Reports =  new ArrayL ist<Standa rdReport>( );
  181                    List <StandardR eport> all  = this.ge tStandardR eports();
  182                    if ( all != nul l) {
  183                             for (S tandardRep ort stdRep ort : all)
  184                                      if (this .isUserPer mittedToSc heduleRun( user, stdR eport))
  185                                               stdReports .add(stdRe port);
  186                    }
  187                    retu rn stdRepo rts;
  188           }
  189  
  190           /* *
  191            *  @see gov. va.med.cch t.service. report.esr .service.r eport.Stan dardReport Service#ge tReportSet up
  192            * /
  193           pu blic Sched uledReport  getSchedu ledReport( EntityKey< ScheduledR eport> ide ntifier) t hrows Serv iceExcepti on {
  194                    Vali date.notNu ll(identif ier, "A us er princip al must no t be null" );
  195                    Sche duledRepor t result =  null;
  196  
  197                    try  {
  198                             result  = reportD AO.getSche duledRepor t(identifi er);
  199                             report ParameterC onversionS ervice.con vertFromTe xt(result) ;
  200                    } ca tch (DAOEx ception e)  {
  201                             throw  new Servic eException ("Failed t o get a li st of repo rt setup w ith identi fier "
  202                                               + identifi er.getKeyV alueAsStri ng(), e);
  203                    } ca tch (Excep tion e) {
  204                             throw  new Servic eException ("Failed t o get a li st of repo rt setup w ith identi fier ", e) ;
  205                    }
  206                    retu rn result;
  207           }
  208  
  209           /* *
  210            *  @see gov. va.med.cch t.service. report.esr .service.r eport.Stan dardReport Service#sa veReportSe tup
  211            * /
  212           pu blic Sched uledReport  saveSched uledReport (Scheduled Report sch eduledRepo rt, boolea n convertT oText) thr ows Servic eException  {
  213  
  214                    Vali date.notNu ll(schedul edReport,  "Scheduled Report to  save must  not be nul l");
  215                    try  {
  216                             if (co nvertToTex t) {
  217                                      reportPa rameterCon versionSer vice.conve rtToText(s cheduledRe port);
  218                             }
  219                             // CCR  407.  Avo id modifyi ng CISS fr amework so  changes a re made 
  220                             // in  ReportDAOI mpl to ret urn a pers istent ent ity to ret rieve an I D
  221                             return  reportDAO .saveSched uledReport (scheduled Report);
  222                    } ca tch (DAOEx ception e)  {
  223                             throw  new Servic eException ("Failed t o save rep ort setup  with ident ifier "
  224                                               + schedule dReport.ge tEntityKey ().getKeyV alueAsStri ng(), e);
  225                    } ca tch (Excep tion e) {
  226                             throw  new Servic eException (e.getMess age(), e);
  227                    }
  228           }
  229  
  230           /* *
  231            *  @see gov. va.med.cch t.service. report.esr .service.r eport.Stan dardReport Service#ge tCompleted Report
  232            * /
  233           pu blic Compl etedReport  getComple tedReport( EntityKey< CompletedR eport> ide ntifier)
  234                             throws  ServiceEx ception {
  235                    Vali date.notNu ll(identif ier, "A us er princip al must no t be null" );
  236                    Comp letedRepor t result =  null;
  237                    try  {
  238                             result  = reportD AO.getComp letedRepor t(identifi er);
  239                    } ca tch (DAOEx ception e)  {
  240                             throw  new Servic eException ("Failed t o get a li st of comp leted repo rt with id entifier "
  241                                               + identifi er.getKeyV alueAsStri ng(), e);
  242                    }
  243                    retu rn result;
  244           }
  245           
  246           pu blic void  saveReport Criteria(R eportSetup  reportSet up) throws  ServiceEx ception {
  247                    repo rtPersiste nceService .saveRepor tCriteria( reportSetu p);
  248           }
  249           
  250  
  251           /*
  252            *  (non-Java doc)
  253            *  
  254            *  @see
  255            *  gov.va.me d.esr.serv ice.Standa rdReportSe rvice#buil dReport(Re portSetup)
  256            * /
  257           pu blic void  buildRepor t(ReportSe tup setup)  throws Se rviceExcep tion {
  258                             UserPr incipal us er = null;
  259  
  260                             if (se tup != nul l) {
  261                                      user = t his.securi tyService. getUser(se tup.getSet upUser());
  262                                      // set d efault rep ort format
  263                                      ReportFo rmat repor tFormat =  getTermino logyServic e().getByC ode(Report Format.cla ss,
  264                                                       Re portFormat .SUMMARY);
  265                                      if (setu p.getRepor tParameter s() == nul l) {
  266                                               setup.setR eportParam eters(new  ReportPara meters());
  267                                      }
  268                                      if (setu p.getRepor tParameter s().getRep ortFormat( ) == null)  {
  269                                               setup.getR eportParam eters().se tReportFor mat(report Format);
  270                                      }
  271  
  272                                      // gener ateReport( user, setu p);
  273                                      ReportCo nfiguratio n config =  null;
  274                                      try {
  275                                               config = t his.getRep ortConfigu ration(use r, setup);
  276                                               if (config  != null)  {
  277                                                       // if (logger .isInfoEna bled()) {
  278                                                       //       logg er.info("G enerating  Report ["  + config.g etReportID () + "]");
  279                                                       // }
  280                                                       //  Generate  a report w ith the sp ecific rep ort data s et
  281                                                       re portServic e.buildRep ort(config );
  282                                               }
  283                                      } catch  (IOExcepti on ioe) {
  284                                               logger.err or("Unable  to get th e Report c onfigurati on");
  285                                               throw new  ServiceExc eption("Un able to ge t the Repo rt configu ration", i oe);
  286                                      }
  287                             } else  {
  288                                      logger.e rror("Repo rt Setup O bject Not  found to G enerate th e Report") ;
  289                             }
  290           }
  291  
  292           /* *
  293            *  
  294            *  @param se tup
  295            * /
  296  
  297           pu blic void  generateRe port(Repor tSetup set up) throws  ServiceEx ception {
  298                    Vali date.notNu ll(setup,  "A report  setup must  not be nu ll");
  299  
  300                    try  {
  301                             report ParameterC onversionS ervice.con vertToText (setup);
  302                             Map<St ring, Obje ct> map =  new HashMa p<String,  Object>();
  303  
  304                             map.pu t(REPORT_P ARAMETERS,  setup.get ReportPara metersText ());
  305                             map.pu t(REPORT_S CHEDULE, s etup.getRe portSchedu leText());
  306                             map.pu t(REPORT_P ARAM_EMAIL _REPORT_TO , setup.ge tEmailAddr ess());
  307                             map.pu t(REPORT_P ARAM_USER,  setup.get SetupUser( ));
  308                             map.pu t(REPORT_S TANDARD_TY PE, setup. getStandar dReport(). getCode()) ;
  309                             map.pu t(REPORT_P ARAM_FILE_ TYPE, setu p.getFileT ype().getC ode());
  310  
  311                             JMSPay load paylo ad = (JMSP ayload) ge tApplicati onContext( ).getBean( createRepo rtJMSPaylo adName);
  312                             payloa d.setPaylo ad((Serial izable) ma p);
  313                             messag eProducerS ervice.sen d(payload) ;
  314  
  315                    } ca tch (Excep tion e) {
  316                             throw  new Servic eException ("Failed t o generate  a report" , e);
  317                    }
  318           }
  319  
  320           @S uppressWar nings("unc hecked")
  321           pu blic void  scheduleRe port(Sched uledReport  scheduled Report) th rows Servi ceExceptio n {
  322  
  323                    Exce ption debu g = null;
  324                    try  {
  325                             Valida te.notNull (scheduled Report, "S cheduled R eport id m ust not be  null");
  326                             
  327                             // Ste p 2 Get a  job detail  and popul ate with u ser and re port
  328                             // set up
  329                             String Builder gr oup_name =  new Strin gBuilder(B atchProces sTriggerGr oups.DYNAM IC_BATCH_J OBS);
  330                             String  name = ge tJobName(s cheduledRe port);
  331  
  332                             JobDet ail jobDet ail = (Job Detail) th is.getComp onent(this .scheduled ReportJobN ame);
  333                             jobDet ail.getJob DataMap(). put("name" , name);
  334                             jobDet ail.getJob DataMap(). put("group ", group_n ame.toStri ng());
  335  
  336                             // Pop ulate dyna mic argume nts to pas s to a met hod for in vocation
  337                             Map<St ring, Obje ct> data =  jobDetail .getJobDat aMap();
  338                             data.p ut(REPORT_ SETUP_ID,  scheduledR eport.getI d().toStri ng());
  339                             this.s chedulingS ervice.get Scheduler( ).addJob(j obDetail,  true);
  340  
  341                             // Ste p 4: Get a  schedulin g service  to schedul e a job4
  342                             CronTr igger cron trigger =  TriggerBui lder.newTr igger()
  343                                               .withIdent ity(name,  group_name .toString( ))
  344                                          .wit hSchedule( CronSchedu leBuilder. cronSchedu le(schedul edReport.g etReportSc hedule().g etCronExpr ession()). inTimeZone (TimeZoneU tils.getTi meZone()))
  345                                          .sta rtNow()
  346                                          .bui ld();
  347                             
  348                             if (lo gger.isInf oEnabled() ) {
  349                                      logger.i nfo("Sched ule a repo rt to run  at " + cro ntrigger.g etStartTim e()
  350                                                       +  " using cr on express ion: " + s cheduledRe port.getRe portSchedu le().getCr onExpressi on());
  351                             }                         
  352                             
  353                    }
  354                    catc h (Schedul erExceptio n e) {
  355                             debug  = e;
  356                             throw  new Invali dScheduleE xception(" Invalid sc hedule. Ex ception me ssage: " +  e.getMess age() );
  357                    } 
  358                    catc h (Runtime Exception  e) {
  359                             debug  = e;
  360                             throw  new Servic eException ("Unexpect ed excepti on: " + e. getClass() .getName()  + " messa ge: " + e. getMessage ());
  361                    }
  362                    fina lly {
  363                             if( de bug != nul l && logge r.isDebugE nabled() )  {
  364                                      logger.d ebug( debu g );
  365                             }
  366                    }
  367           }
  368  
  369           /* *
  370            *  Construct  the job n ame from R eportSetup  object
  371            *  
  372            *  @param se tup
  373            *  @return
  374            * /
  375           pr ivate Stri ng getJobN ame(Schedu ledReport  scheduledR eport) {
  376                    Stri ngBuilder  name = new  StringBui lder(SCHED ULED_REPOR T);
  377                    name .append(PE RIOD).appe nd(schedul edReport.g etUserName ()).append (PERIOD).a ppend(
  378                                      schedule dReport.ge tStandardR eport().ge tCode()).a ppend(PERI OD);
  379                    if ( scheduledR eport.getE ntityKey()  == null)  {
  380                             name.a ppend(Date Utils.form at(new Dat e(), "HHmm ss"));
  381                    } el se {
  382                             name.a ppend(sche duledRepor t.getEntit yKey().get KeyValueAs String());
  383                    }
  384  
  385                    retu rn name.to String();
  386           }
  387  
  388           pu blic void  cancelSche duledRepor t(EntityKe y<Schedule dReport> i dentifier)
  389                             throws  NoRecordF oundExcept ion, Servi ceExceptio n {
  390  
  391                    Vali date.notNu ll(identif ier, "Sche duledRepor t identifi er must no t be null" );
  392                    Vali date.notNu ll(identif ier.getKey Value(), " ScheduledR eport iden tifier key  can not b e null.");
  393  
  394                    Sche duledRepor t setup =  null;
  395  
  396                    setu p = this.g etSchedule dReport(id entifier);
  397  
  398                    if ( setup == n ull) {
  399                             throw  new NoReco rdFoundExc eption("Re portSetup  does not e xist for i dentifier:  "
  400                                               + identifi er.getKeyV alueAsStri ng());
  401                    }
  402  
  403                    try  {
  404                                      scheduli ngService. unschedule (getJobNam e(setup),  BatchProce ssTriggerG roups.DYNA MIC_BATCH_ JOBS);
  405                                      reportDA O.deleteSc heduledRep ort(identi fier);
  406                    } ca tch (Sched ulerExcept ion e) {
  407                             throw  new Servic eException (
  408                                               "Failed to  unschedul e triggers  for repor t setup wi th identif ier "
  409                                                                + id entifier.g etKeyValue AsString() , e);
  410                    } ca tch (DAOEx ception e)  {
  411                             throw  new Servic eException ("Failed t o delete r eport setu p with ide ntifier "
  412                                               + identifi er.getKeyV alueAsStri ng(), e);
  413                    }
  414           }
  415  
  416           /* *
  417            *  @param us er
  418            *  @param se tup
  419            *  @return
  420            *  @throws I OException
  421            * /
  422           pr otected Re portConfig uration ge tReportCon figuration (UserPrinc ipal user,  ReportSet up setup)
  423                             throws  IOExcepti on {
  424  
  425                    Stan dardReport Criteria c riteria =  new Standa rdReportCr iteria();
  426                    crit eria.setRe portSetup( setup);
  427                    crit eria.setRe portUser(u ser);
  428  
  429                    retu rn this.ge tReportCon figuration (user, set up, criter ia);
  430           }
  431  
  432           pr otected Re portConfig uration ge tReportCon figuration (UserPrinc ipal user,  ReportSet up setup,
  433                             Standa rdReportCr iteria cri teria) thr ows IOExce ption {
  434  
  435                    Stan dardReport  report =  setup.getS tandardRep ort();
  436                    Stri ng id = re port.getCo de();
  437                    Stri ng reportN ame = Stri ngUtils.de leteWhites pace(id);
  438  
  439                    Repo rtParamete rs paramet erSet = se tup.getRep ortParamet ers();
  440                    Repo rtExported Type type  = setup.ge tFileType( );
  441                    Repo rtExported Type.Code  code = typ e != null  ? ReportEx portedType .Code.getB yCode(type
  442                                      .getCode ()) : null ;
  443  
  444                    Stri ng formatC ode = getL ookupName( parameterS et != null  ? paramet erSet.getR eportForma t()
  445                                      : null);
  446  
  447                    Stri ngBuilder  output = n ew StringB uilder();
  448                    outp ut.append( id).append ("-").appe nd(report. getName()) ;
  449                    if ( formatCode  != null)  {
  450                             output .append("- ").append( formatCode );
  451                    }
  452                    if(c ode!=null)
  453                    {
  454                      ou tput.appen d(".").app end(code.g etAlias(). toLowerCas e());
  455                    }
  456                    Repo rtConfigur ation conf ig = new R eportConfi guration(r eportName,  id, code,  StringUti ls
  457                                      .deleteW hitespace( output.toS tring()));
  458  
  459                    conf ig.setRepo rtUser(use r);
  460                    conf ig.setQuer yCriteria( criteria);
  461                    conf ig.setReso urceMappin g(criteria .getCriter ia());
  462  
  463                    retu rn config;
  464           }
  465  
  466           pr ivate Stri ng getLook upName(Loo kup lookup ) {
  467                    retu rn lookup  != null ?  lookup.get Name() : n ull;
  468           }
  469  
  470           /* *
  471            *  Verifies  whether us er has run /schedule/ archive/de lete privi lege.
  472            *  
  473            *  @param us er
  474            *  @param re port
  475            *  @return
  476            * /
  477           pr otected bo olean isUs erPermitte dToSchedul eRun(UserP rincipal u ser, Stand ardReport  report) {
  478                    Set< Permission > rptCaps  = (report  != null) ?  report.ge tPermissio ns() : nul l;
  479                    if ( rptCaps !=  null) {
  480                             for (P ermission  p : rptCap s)
  481                                      if (user .isPermiss ionGranted (p.getName ()))
  482                                               return tru e;
  483                    }
  484                    retu rn false;
  485           }
  486  
  487           /* *
  488            *  Verifies  whether us er has pri vilege to  inactivate  a report.
  489            *  
  490            *  @param us er
  491            *  @param re port
  492            *  @return
  493            * /
  494           pr otected bo olean isUs erPermitte dToInactiv ate(UserPr incipal us er, Comple tedReport  report) {
  495                    Vali date.notNu ll(user, " UserPrinci pal is nul l");
  496                    Vali date.notNu ll(report,  "report i s null");
  497  
  498                    /*
  499                     * I f the repo rt is gene rated by s ame user o r National  Administr ator and
  500                     * h as a capab ility of S chedule/Ru n/Delete/A rchive, re turn true.
  501                     */
  502  
  503                    if ( report.get UserName() .equalsIgn oreCase(us er.getUser name())) {
  504                             return  true; 
  505                    }
  506                    retu rn false;
  507           }
  508  
  509           /* *
  510            *  Verifies  whether us er has pri vilege to  delete a r eport.
  511            *  
  512            *  @param us er
  513            *  @param re port
  514            *  @return
  515            * /
  516           pr otected bo olean isUs erPermitte dToDelete( UserPrinci pal user,  CompletedR eport repo rt) {
  517  
  518                    /*
  519                     * I f the repo rt is gene rated by s ame user o r System A dminstrato r or if
  520                     * i t a inacti ve report  and has a  capability  of
  521                     * S chedule/Ru n/Delete/A rchive, re turn true.
  522                     */
  523                    if ( report.get UserName()  != null & & user.get Username() .equalsIgn oreCase((r eport.getU serName()) )) {
  524                             return  true;
  525                    }
  526                    retu rn false;
  527           }
  528  
  529           /*
  530            *  @see
  531            *  gov.va.me d.esr.serv ice.Standa rdReportSe rvice#getS impleCompl etedReport
  532            *  (EntityKe y identifi er)
  533            * /
  534           pu blic Simpl eCompleted Report get SimpleComp letedRepor t(
  535                             Entity Key<Simple CompletedR eport> ide ntifier) t hrows Serv iceExcepti on {
  536                    Vali date.notNu ll(identif ier, "Simp leComplete dReport id entifier m ust not be  null");
  537                    Simp leComplete dReport re sult = nul l;
  538                    try  {
  539                             result  = getRepo rtDAO().ge tSimpleCom pletedRepo rt(identif ier);
  540                    } ca tch (DAOEx ception e)  {
  541                             throw  new Servic eException (
  542                                               "Failed to  get a Sim pleComplet edReport r eport with  identifie r "
  543                                                                + id entifier.g etKeyValue AsString() , e);
  544                    }
  545                    retu rn result;
  546           }
  547  
  548           /*
  549            *  (non-Java doc)
  550            *  
  551            *  @seegov.v a.med.IHTA .service.r eport.Stan dardReport Service#
  552            *  getComple tedReportP arameters( gov.va.med .fw.model. EntityKey)
  553            * /
  554           pu blic Repor tSetup get CompletedR eportParam eters(Enti tyKey<Simp leComplete dReport> i dentifier)
  555                             throws  ServiceEx ception,Pa rseExcepti on {
  556                    Vali date.notNu ll(identif ier, "Comp letedRepor t identifi er must no t be null" );
  557  
  558                    try  {
  559                             Simple CompletedR eport comp letedRepor t = getRep ortDAO().g etSimpleCo mpletedRep ort(
  560                                               identifier );
  561                             if (co mpletedRep ort != nul l) {
  562                                      ReportSe tup report Setup = ne w ReportSe tup();
  563                                      reportSe tup.setSta ndardRepor t(complete dReport.ge tStandardR eport());
  564                                      reportSe tup.setRep ortParamet ersText(co mpletedRep ort.getRep ortParamet erText());
  565                                      reportSe tup.setFil eType(comp letedRepor t.getFileT ype());
  566                                      reportSe tup.setSet upUser(com pletedRepo rt.getUser Name());
  567                                      // conve rt schedul e and repo rt paramet ers
  568                                      reportPa rameterCon versionSer vice.conve rtFromText (reportSet up);
  569                                      return r eportSetup ;
  570                             }
  571                    } ca tch (DAOEx ception e)  {
  572                             throw  new Servic eException (
  573                                               "Failed to  get a Sim pleComplet edReport r eport with  identifie r "
  574                                                                + id entifier.g etKeyValue AsString() , e);
  575                    }
  576                    retu rn null;
  577           }
  578  
  579           /*
  580            *  @see
  581            *  gov.va.me d.esr.serv ice.Standa rdReportSe rvice#dele teComplete dReport(go v
  582            *  .va.med.f w.model.En tityKey, U serPrincip al user )
  583            * /
  584           pu blic void  deleteComp letedRepor t(EntityKe y<Complete dReport> i dentifier,  UserPrinc ipal user)
  585                             throws  NoRecordF oundExcept ion, Servi ceExceptio n {
  586  
  587                    Vali date.notNu ll(identif ier, "Comp letedRepor t identifi er must no t be null" );
  588                    Vali date.notNu ll(identif ier.getKey Value(),
  589                                      "Complet edReport i dentifier  key can no t be null. ");
  590  
  591                    Comp letedRepor t complete dReport =  getComplet edReport(i dentifier) ;
  592  
  593                    if ( completedR eport == n ull) {
  594                             throw  new NoReco rdFoundExc eption(
  595                                               "SimpleCom pletedRepo rt does no t exist fo r identifi er: "
  596                                                                + id entifier.g etKeyValue AsString() );
  597                    }
  598                    try  {
  599                             if (is UserPermit tedToDelet e(user, co mpletedRep ort)) {
  600                                      getRepor tDAO().del eteComplet edReport(i dentifier) ;
  601                             } else
  602                                      throw ne w ServiceE xception(" User doesn 't have pe rmissions  to delete  a report:  "
  603                                                       +  user.getUs ername());
  604                    } ca tch (DAOEx ception e)  {
  605                             throw  new Servic eException ("Failed t o delete S impleCompl etedReport  with iden tifier "
  606                                               + identifi er.getKeyV alueAsStri ng(), e);
  607                    }
  608           }
  609  
  610           /*
  611            *  @see
  612            *  gov.va.me d.esr.serv ice.Standa rdReportSe rvice#inac tivateComp letedRepor t
  613            *  (gov.va.m ed.fw.mode l.EntityKe y, UserPri ncipal use r )
  614            * /
  615           pu blic void  inactivate CompletedR eport(Enti tyKey<Comp letedRepor t> identif ier, UserP rincipal u ser)
  616                             throws  NoRecordF oundExcept ion, Servi ceExceptio n, ReportE xception {
  617  
  618                    Vali date.notNu ll(identif ier, "Comp letedRepor t identifi er must no t be null" );
  619                    Vali date.notNu ll(identif ier.getKey Value(),
  620                                      "Complet edReport i dentifier  key can no t be null. ");
  621  
  622                    Comp letedRepor t complete dReport =  getComplet edReport(i dentifier) ;
  623  
  624                    if ( completedR eport == n ull) {
  625                             throw  new NoReco rdFoundExc eption("Co mpletedRep ort does n ot exist f or identif ier: "
  626                                               + identifi er.getKeyV alueAsStri ng());
  627                    }
  628                    // I f it is an  inactive  report thr ow an exce ption
  629                    if ( completedR eport.getI nactivated Date() !=  null)
  630                             throw  new Report Exception( "This repo rt is an i nactive re port");
  631                    try  {
  632                             // If  user has p ermission  to inactiv ate
  633                             // Set  inactivat e date to  sys date.
  634                             if (is UserPermit tedToInact ivate(user , complete dReport))  {
  635                                      complete dReport.se tInactivat edDate(new  Date());
  636                                      getRepor tDAO().sav eCompleted Report(com pletedRepo rt);
  637                             } else
  638                                      throw ne w ServiceE xception(" User doesn 't have pe rmissions  to inactiv ate a repo rt:"
  639                                                       +  user.getUs ername());
  640                    } ca tch (DAOEx ception e)  {
  641                             throw  new Servic eException ("Failed t o inactiva te Complet edReport w ith identi fier "
  642                                               + identifi er.getKeyV alueAsStri ng(), e);
  643                    }
  644           }
  645  
  646           /* *
  647            *  Deleted e xpired com pleted rep orts older  than 365  days or a  configured
  648            *  value
  649            *  
  650            *  @param pu rgeQuerySt ring
  651            *  @param au ditInfo
  652            *  @param sy stemParame ter
  653            *  @return
  654            *  @throws S erviceExce ption
  655            * /
  656           pu blic Integ er purgeCo mpletedRep orts() thr ows Servic eException  {
  657                    try  {
  658                             return  getReport DAO().purg eCompleted Reports();
  659                    } ca tch (DAOEx ception e)  {
  660                             throw  new Servic eException ("Error Pu rging Comp leted Repo rts data "  + e);
  661                    }
  662           }
  663  
  664           pu blic Map<S tring, Str ing> getEx piringRepo rtIdUserMa p() throws  ServiceEx ception {
  665                    try  {
  666                             return  getReport DAO().getE xpiringRep ortIdUserM ap(daysToR etainCompl etedReport s,
  667                                               daysToWarn BeforeDele tion);
  668                    } ca tch (Excep tion e) {
  669                             throw  new Servic eException ("getExpir ingReportU serIds fai led " + e. getMessage (), e);
  670                    }
  671           }
  672  
  673           pu blic void  updateComp letedRepor t(SimpleCo mpletedRep ort simple CompletedR eport)
  674                             throws  ServiceEx ception {
  675                    logg er.error(" $$$$$ fix  me.");
  676  
  677   //               try  {
  678   //                        getRep ortDAO().u pdate(simp leComplete dReport);
  679   //               } ca tch (DAOEx ception e)  {
  680   //                        throw  new Servic eException ("Unable t o extend C ompleted R eport expi raion date ", e);
  681   //               }
  682           }
  683  
  684           pu blic void  updateSche duledRepor t(Schedule dReport sc heduledRep ort)
  685                             throws  ServiceEx ception {
  686                    logg er.error(" $$$$$ fix  me.");
  687  
  688   //               Vali date.notNu ll(schedul edReport,  "Scheduled Report to  save must  not be nul l");
  689   //               try  {
  690   //                        Schedu ledReport  oldSchedul edReport =  (Schedule dReport) r eportDAO.g etByKey(sc heduledRep ort.getEnt ityKey());
  691   //                        schedu lingServic e.unschedu le(getJobN ame(oldSch eduledRepo rt), Batch ProcessTri ggerGroups .DYNAMIC_B ATCH_JOBS) ;
  692   //
  693   //                        oldSch eduledRepo rt.setRepo rtGenerate Date(sched uledReport .getReport GenerateDa te());
  694   //                        oldSch eduledRepo rt.setEmai l(schedule dReport.ge tEmail());
  695   //                        oldSch eduledRepo rt.setFile Type(sched uledReport .getFileTy pe());
  696   //                        oldSch eduledRepo rt.setRepo rtParamete rText(sche duledRepor t.getRepor tParameter Text());
  697   //                        oldSch eduledRepo rt.setRepo rtSchedule Text(sched uledReport .getReport ScheduleTe xt());
  698   //                        oldSch eduledRepo rt.setUser Name(sched uledReport .getUserNa me());
  699   //                        oldSch eduledRepo rt.setStan dardReport (scheduled Report.get StandardRe port());
  700   //
  701   //                        schedu leReport(s cheduledRe port);
  702   //                        report DAO.update (oldSchedu ledReport) ;
  703   //               } ca tch (DAOEx ception e)  {
  704   //                        throw  new Servic eException ("Failed t o save Sch eduledRepo rt with id entifier "
  705   //                                          + schedule dReport.ge tEntityKey ().getKeyV alueAsStri ng(), e);
  706   //               } ca tch (Excep tion e) {
  707   //                        throw  new Servic eException (e.getMess age(), e);
  708   //               }
  709           }
  710  
  711           /*
  712            *  @see
  713            *  gov.va.me d.esr.serv ice.Standa rdReportSe rvice#getC ompletedRe portFilter ()
  714            * /
  715           pu blic Repor tFilter ge tCompleted ReportFilt er() throw s ServiceE xception {
  716                    Repo rtFilter r eportFilte r = new Re portFilter ();
  717                    try  {
  718                             report Filter.set StandardRe ports(getR eportDAO() .getDistin ctStandard Reports()) ;
  719                             report Filter.set ReportFile Types(getR eportDAO() .getDistin ctReportEx portTypes( ));
  720                    } ca tch (DAOEx ception e)  {
  721                             throw  new Servic eException ("Error ge tting the  standard r eports " +  e);
  722                    }
  723                    retu rn reportF ilter;
  724           }
  725  
  726           /* *
  727            *  @return R eturns the  securityS ervice.
  728            * /
  729           pu blic Secur ityService  getSecuri tyService( ) {
  730                    retu rn securit yService;
  731           }
  732  
  733           /* *
  734            *  @param se curityServ ice
  735            *              The secu rityServic e to set.
  736            * /
  737           pu blic void  setSecurit yService(S ecuritySer vice secur ityService ) {
  738                    this .securityS ervice = s ecuritySer vice;
  739           }
  740  
  741           /*
  742            *  (non-Java doc)
  743            *  
  744            *  @see
  745            *  gov.va.me d.fw.sched uling.Audi tableSched uledProces s#getAudit Info(gov.v a
  746            *  .med.fw.s cheduling. ScheduledP rocessInvo cationCont ext)
  747            * /
  748           pu blic Strin g getAudit Info(Sched uledProces sInvocatio nContext c ontext) {
  749                    // d efault imp lementatio n
  750                    retu rn DEFAULT _AUDIT_NAM E;
  751           }
  752  
  753           pu blic Termi nologyServ ice getTer minologySe rvice() {
  754                    retu rn termino logyServic e;
  755           }
  756  
  757           pu blic void  setTermino logyServic e(Terminol ogyService  terminolo gyService)  {
  758                    this .terminolo gyService  = terminol ogyService ;
  759           }
  760  
  761           pu blic Repor tParameter Conversion Service ge tReportPar ameterConv ersionServ ice() {
  762                    retu rn reportP arameterCo nversionSe rvice;
  763           }
  764  
  765           pu blic void  setReportP arameterCo nversionSe rvice(
  766                             Report ParameterC onversionS ervice rep ortParamet erConversi onService)  {
  767                    this .reportPar ameterConv ersionServ ice = repo rtParamete rConversio nService;
  768           }
  769           /* *
  770            *  Search Sc heduled re ports
  771            * /
  772           pu blic List< ScheduledR eport> sea rchSchedul edReports( ReportFilt erSearchQu eryInfo se archQueryI nfo) throw s ServiceE xception {
  773                    // I nitialize  the list o f return v alues
  774                    List <Scheduled Report> sc heduledRep orts = new  ArrayList <Scheduled Report>();
  775  
  776                    try  {
  777                             // Fir st filter  against th e entered  search cri teria at t hd DAO
  778                             // lev el.
  779                             List<S cheduledRe port> rptI tems = get ReportDAO( ).searchSc heduledRep orts(searc hQueryInfo );
  780  
  781                             // The n filter a gainst Tri gger.nextF ireTime fo r the next  fire time
  782                             // sin ce this is  stored
  783                             // in  Quartz and  not in th e database
  784                             if (rp tItems !=  null && !r ptItems.is Empty()) {
  785                                      // Itera te through  each retu rned Repor tSetupLite  object
  786                                      for (Sch eduledRepo rt schedul edReport :  rptItems)  {
  787  
  788                                               // skip ov er and ret urn record  if the se tup user i s null!
  789                                               // TOD Rem ove the tr ue flag
  790                                               if (schedu ledReport. getUserNam e() == nul l) {
  791                                                       sc heduledRep orts.add(s cheduledRe port);
  792                                               } else {
  793                                                       //  Get the n ame of the  trigger
  794                                                       St ring trigg erName = S CHEDULED_R EPORT + ". " + schedu ledReport. getUserNam e() + "."
  795                                                                         + sche duledRepor t.getStand ardReport( ).getCode( ) + "."
  796                                                                         + sche duledRepor t.getEntit yKey().get KeyValueAs String();
  797                                                       tr y {
  798                                                                // G et the sch eduled tri gger
  799                                                                Trig ger trigge r = schedu lingServic e.getTrigg er(trigger Name,
  800                                                                                  BatchPro cessTrigge rGroups.DY NAMIC_BATC H_JOBS);
  801  
  802                                                                // G et the nex t fire tim e
  803                                                                Date  nextFireT ime = trig ger != nul l ? trigge r.getNextF ireTime()  : null;
  804  
  805                                                                // O nly add th e report s etup to th e return l ist if
  806                                                                // t he date fi lter passe d
  807                                                                if ( (nextFireT ime == nul l)
  808                                                                                  || (sear chQueryInf o.getDateF rom() == n ull || !ne xtFireTime
  809                                                                                                   .b efore(sear chQueryInf o.getDateF rom()))
  810                                                                                  && (sear chQueryInf o.getDateT o() == nul l || !next FireTime
  811                                                                                                   .a fter(searc hQueryInfo .getDateTo ()))) {
  812                                                                         // Set  the next  fire time  on the ret urned repo rt
  813                                                                         // set up and add  it to the  returned  list
  814                                                                         schedu ledReport. setReportG enerateDat e(nextFire Time);
  815                                                                         schedu ledReports .add(sched uledReport );
  816                                                                }
  817                                                       }  catch (Sch edulerExce ption scEx ) {
  818                                                                thro w new Serv iceExcepti on("Error  getting tr igger with  Id: "
  819                                                                                  + trigge rName, scE x);
  820                                                       }
  821                                               }
  822                                      }
  823                             }
  824                    } ca tch (DAOEx ception e)  {
  825                             throw  new Servic eException ("Schedule dReports S earch Fail ed.  searc hQueryInfo : "
  826                                               + searchQu eryInfo, e );
  827                    }
  828                    retu rn schedul edReports;
  829           }
  830           
  831           pu blic List< SimpleComp letedRepor t> searchC ompletedRe ports(Comp letedRepor tsSearchQu eryInfo se archQueryI nfo) throw s ServiceE xception {
  832  
  833                    try  {
  834                             return  getReport DAO().sear chComplete dReports(s earchQuery Info);
  835                    } ca tch (DAOEx ception e)  {
  836                             throw  new Servic eException ("Complete dReports S earch Fail ed.  searc hQueryInfo  = "
  837                                               + searchQu eryInfo, e );
  838                    }
  839           }
  840  
  841           pu blic Linke dHashMap<S tring, Str ing> getUn iqueFilter Values(Com pletedRepo rtFieldTyp e fieldTyp e) {
  842                    retu rn getRepo rtDAO().ge tUniqueFil terValues( fieldType) ;
  843           }
  844           
  845           
  846           pr ivate Repo rtDAO getR eportDAO()  {
  847                    retu rn reportD AO;
  848           }
  849           
  850           @O verride
  851           pu blic List< Date[]> ge tScheduleP review(Use rPrincipal  user, Rep ortSetup r eportSetup , int numD ates, Date  startingD ate)
  852                             throws  ServiceEx ception {
  853                    // T ODO Auto-g enerated m ethod stub
  854                    retu rn null;
  855           }
  856   }