111. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/13/2018 10:35:22 AM 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.

111.1 Files compared

# Location File Last Modified
1 v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\ccht\controller ReportConversionService.java Fri Dec 7 17:36:18 2018 UTC
2 v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\ccht\controller ReportConversionService.java Wed Dec 12 22:33:38 2018 UTC

111.2 Comparison summary

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

111.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

111.4 Active regular expressions

No regular expressions were active.

111.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrig ht � 2010  VHA. All r ights rese rved
  3    ********* ********** ********** ********** ********** ********** *********/
  4   package go v.va.med.c cht.contro ller;
  5  
  6   import jav a.util.Col lection;
  7   import jav a.util.Has hSet;
  8   import jav a.util.Lis t;
  9   import jav a.util.Set ;
  10   import jav a.util.Tim eZone;
  11  
  12   import org .apache.co mmons.lang 3.StringUt ils;
  13   import org .apache.lo g4j.Logger ;
  14   import org .springfra mework.ste reotype.Se rvice;
  15  
  16   import gov .va.med.cc ht.model.S chedule;
  17   import gov .va.med.cc ht.model.c ommon.DIRe portParame ters;
  18   import gov .va.med.cc ht.model.c ommon.Faci lity;
  19   import gov .va.med.cc ht.model.c ommon.Repo rtWeek;
  20   import gov .va.med.cc ht.model.c ommon.Simp leVisn;
  21   import gov .va.med.cc ht.model.r eport.Repo rtSchedule ;
  22   import gov .va.med.cc ht.model.r eport.Repo rtSetup;
  23   import gov .va.med.cc ht.model.r eport.Sche duledRepor t;
  24   import gov .va.med.cc ht.model.r eport.Simp leComplete dReport;
  25   import gov .va.med.cc ht.model.r eport.sche duled.Date RangeBound ary;
  26   import gov .va.med.cc ht.model.r eport.sche duled.Date RangeBound aryType;
  27   import gov .va.med.cc ht.model.r eport.sche duled.Fixe dDateType;
  28   import gov .va.med.cc ht.model.r eport.sche duled.Mult iDayTimeUn itType;
  29   import gov .va.med.cc ht.model.r eport.sche duled.Simp leTimeUnit Type;
  30   import gov .va.med.cc ht.model.t erminology .DayOfMont h;
  31   import gov .va.med.cc ht.model.t erminology .DayOfQuar ter;
  32   import gov .va.med.cc ht.model.t erminology .DayOfWeek ;
  33   import gov .va.med.cc ht.model.t erminology .Month;
  34   import gov .va.med.cc ht.model.t erminology .ReportFor mat;
  35   import gov .va.med.cc ht.model.t erminology .ReportTyp e;
  36   import gov .va.med.cc ht.model.t erminology .RunFreque ncy;
  37   import gov .va.med.cc ht.model.t erminology .ScheduleT ype;
  38   import gov .va.med.cc ht.model.t erminology .StandardR eport;
  39   import gov .va.med.cc ht.model.t erminology .WeekOfMon th;
  40   import gov .va.med.cc ht.service .common.Te rminologyE xception;
  41   import gov .va.med.cc ht.service .common.Te rminologyS ervice;
  42   import gov .va.med.cc ht.service .report.Re portConsta nts;
  43   import gov .va.med.cc ht.ui.comm on.Abstrac tConversio nService;
  44   import gov .va.med.cc ht.ui.mode l.Complete dReportFor m;
  45   import gov .va.med.cc ht.ui.mode l.Formatte dDateForm;
  46   import gov .va.med.cc ht.ui.mode l.ReportPa rametersFo rm;
  47   import gov .va.med.cc ht.ui.mode l.ReportSc heduleForm ;
  48   import gov .va.med.cc ht.ui.mode l.ReportSe tupForm;
  49   import gov .va.med.cc ht.ui.mode l.Schedule dReportFor m;
  50   import gov .va.med.cc ht.ui.mode l.Standard ReportForm ;
  51   import gov .va.med.cc ht.util.Tr ansferUtil s;
  52   import gov .va.med.fw .model.Abs tractEntit y;
  53   import gov .va.med.fw .model.loo kup.Lookup ;
  54   import gov .va.med.fw .report.Re portExport edType;
  55   import gov .va.med.fw .security. SecurityCo ntextHelpe r;
  56   import gov .va.med.fw .ui.conver sion.Conve rsionServi ce;
  57   import gov .va.med.fw .ui.conver sion.Conve rsionServi ceExceptio n;
  58   import gov .va.med.fw .ui.model. Form;
  59   import gov .va.med.fw .ui.model. TermType;
  60   //import g ov.va.med. fw.util.Da teUtils;
  61   import gov .va.med.fw .util.date .DateWithT imeZone;
  62   import gov .va.med.fw .util.date .TimeZoneU tils;
  63  
  64   /**
  65    * 
  66    * @author   DNS
  67    */
  68   @Service
  69   public cla ss ReportC onversionS ervice ext ends Abstr actConvers ionService  implement s Conversi onService 
  70           
  71           pr ivate Logg er logger  = Logger.g etLogger(R eportConve rsionServi ce.class);
  72           
  73           @O verride
  74           pu blic void  convert(Sc hedule bom , ReportSc heduleForm  form) { 
  75                    logg er.error(" $$$$$$$ fi x me.");
  76           }
  77           
  78           @O verride
  79           pu blic void  convert(Ab stractEnti ty bom, Fo rm form) t hrows Conv ersionServ iceExcepti on {
  80                    if ( bom instan ceof Sched uledReport  && form i nstanceof  ScheduledR eportForm)  {
  81                             toSche duledRepor tForm((Sch eduledRepo rt) bom, ( ScheduledR eportForm)  form);
  82                    } el se if (bom  instanceo f SimpleCo mpletedRep ort) {
  83                             toComp letedRepor tForm((Sim pleComplet edReport)  bom, (Comp letedRepor tForm) for m);
  84                    } el se if (bom  instanceo f ReportSe tup && for m instance of ReportS etupForm)  {
  85                             toRepo rtSetupFor m((ReportS etup) bom,  (ReportSe tupForm) f orm);
  86                    } el se if (bom  instanceo f Schedule dReport &&  form inst anceof Rep ortSetupFo rm) {
  87                             toRepo rtSetupFor m((Schedul edReport)  bom, (Repo rtSetupFor m) form);                          
  88                    } el se {
  89                             throw  new Conver sionServic eException ("Unsuppor ted conver sion excep tion");
  90                    }
  91           }
  92  
  93           @O verride
  94           pu blic void  convert(Fo rm form, A bstractEnt ity bom) t hrows Conv ersionServ iceExcepti on {
  95                    try  {
  96                             if (fo rm instanc eof Report SetupForm  && bom ins tanceof Sc heduledRep ort) {
  97                                      toSchedu ledReport( (ReportSet upForm) fo rm, (Sched uledReport ) bom);
  98                             }
  99                             else i f (form in stanceof R eportSetup Form && bo m instance of ReportS etup) {
  100                                      toReport Setup((Rep ortSetupFo rm) form,  (ReportSet up) bom);
  101                             }else  {
  102                                      throw ne w Exceptio n ("Unknow n Paramete r types: "  + 
  103                                                       fo rm.getClas s().getNam e() + ", "  + bom.get Class().ge tName());
  104                             }
  105                    } ca tch (Excep tion te) {
  106                             throw  new Conver sionServic eException (te.getMes sage(), te );
  107                    }
  108           }
  109  
  110           pr ivate void  toSchedul edReport(R eportSetup Form repor tSetupForm , Schedule dReport sc heduledRep ort)
  111           th rows Excep tion {
  112                    sche duledRepor t.setId(re portSetupF orm.getId( ) != null  ? new Long (reportSet upForm.get Id())
  113                                      : null);
  114                    
  115                    // c onvert sta ndard repo rt (termin ology look up)
  116                    Stan dardReport  standardR eport = (S tandardRep ort) getBy Code(Stand ardReport. class,
  117                                      reportSe tupForm.ge tStandardR eport().ge tValue());
  118                    sche duledRepor t.setStand ardReport( standardRe port);
  119                    // O utput file  type
  120                    Repo rtExported Type fileT ype = (Rep ortExporte dType) Tra nsferUtils .transferT ermTypeToL ookup(
  121                                      getTermi nologyCach e().getTer minologySe rvice(), R eportExpor tedType.cl ass,
  122                                      reportSe tupForm.ge tFileType( ));
  123                    sche duledRepor t.setFileT ype(fileTy pe);
  124                    
  125                    // c onvert e-m ail addres s
  126                    sche duledRepor t.setEmail (reportSet upForm.get EmailAddre ss());
  127                    // P arameters
  128                    DIRe portParame ters param eters = ne w DIReport Parameters ();
  129                    Repo rtParamete rsForm rpF orm = repo rtSetupFor m.getRepor tParameter s();
  130                    toRe portParame ters(rpFor m, paramet ers);
  131                    sche duledRepor t.setRepor tParameter s(paramete rs);
  132                    
  133                    // S chedule
  134                    Repo rtSchedule  reportSch edule = ne w ReportSc hedule();
  135                    Repo rtSchedule Form repor tScheduleF orm = repo rtSetupFor m.getRepor tSchedule( );
  136                    toSc hedule(rep ortSchedul eForm, rep ortSchedul e);
  137                    sche duledRepor t.setRepor tSchedule( reportSche dule);
  138           }
  139  
  140           
  141           pr ivate void  toReportS etup(Repor tSetupForm  reportSet upForm, Re portSetup  reportSetu p)
  142                             throws  Exception  {
  143                    repo rtSetup.se tId(report SetupForm. getId() !=  null ? ne w Long(rep ortSetupFo rm.getId() )
  144                                      : null);
  145  
  146                    // c onvert sta ndard repo rt (termin ology look up)
  147                    Stan dardReport  standardR eport = (S tandardRep ort) getBy Code(Stand ardReport. class,
  148                                      reportSe tupForm.ge tStandardR eport().ge tValue());
  149                    repo rtSetup.se tStandardR eport(stan dardReport );
  150                    // O utput file  type
  151                    Repo rtExported Type fileT ype = (Rep ortExporte dType) Tra nsferUtils .transferT ermTypeToL ookup(
  152                                      getTermi nologyCach e().getTer minologySe rvice(), R eportExpor tedType.cl ass,
  153                                      reportSe tupForm.ge tFileType( ));
  154                    repo rtSetup.se tFileType( fileType);
  155  
  156                    // c onvert e-m ail addres s
  157                    repo rtSetup.se tEmailAddr ess(report SetupForm. getEmailAd dress());
  158                    // P arameters
  159                    DIRe portParame ters param eters = ne w DIReport Parameters ();
  160                    Repo rtParamete rsForm rpF orm = repo rtSetupFor m.getRepor tParameter s();
  161                    toRe portParame ters(rpFor m, paramet ers);
  162                    repo rtSetup.se tReportPar ameters(pa rameters);
  163                    
  164                    // S chedule
  165                    Repo rtSchedule  reportSch edule = ne w ReportSc hedule();
  166                    Repo rtSchedule Form repor tScheduleF orm = repo rtSetupFor m.getRepor tSchedule( );
  167                    toSc hedule(rep ortSchedul eForm, rep ortSchedul e);
  168                    repo rtSetup.se tReportSch edule(repo rtSchedule );
  169           }
  170  
  171           pr ivate void  toReportP arameters( ReportPara metersForm  rpForm, D IReportPar ameters pa rameters)
  172                             throws  Exception  {
  173                    // c onvert rep ort parame ters             
  174                    para meters.set UserTimeZo ne(getCurr entUser(). getCurrent TimeZone() );
  175                    para meters.set ToDate(rpF orm.getToD ate());
  176                    para meters.set FromDate(r pForm.getF romDate()) ;
  177                    para meters.set AsOfDate(r pForm.getA sOfDate()) ;
  178                    para meters.set ReportName (rpForm.ge tReportNam e());
  179                    if ( rpForm.get ReportSumm aryType()  != null) {
  180                             parame ters.setRe portSummar yType(rpFo rm.getRepo rtSummaryT ype().getV alue());
  181                    }
  182                    if ( rpForm.get SubTotalTy pe() != nu ll) {
  183                             parame ters.setSu bTotalType (rpForm.ge tSubTotalT ype().getV alue());
  184                    }
  185                    para meters.set ReportWeek (rpForm.ge tReportWee k());
  186                    if ( ReportCons tants.REPO RT_SUMMARY _TYPE_VISN .equals(pa rameters.g etReportSu mmaryType( )) && rpFo rm.getVisn () != null ) {                             
  187                             if (Si mpleVisn.A LL_VISNS.g etName().e quals(rpFo rm.getVisn ().getValu e())) {
  188                                      paramete rs.setAllV isns(true) ;
  189                             }else  {         
  190                                      paramete rs.setAllV isns(false );
  191                                      paramete rs.setVisn (getVisnSe rvice().ge tSimpleVis n(rpForm.g etVisn().g etValue()) );
  192                             }
  193                    }
  194                    if ( ReportCons tants.REPO RT_SUMMARY _TYPE_FACI LITY.equal s(paramete rs.getRepo rtSummaryT ype()) &&  rpForm.get Facility()  != null)  {
  195                             if (Fa cility.ALL _FACILITIE S.getName( ).equals(r pForm.getF acility(). getValue() )) {
  196                                      paramete rs.setAllF acilities( true);
  197                             }else  {
  198                                      paramete rs.setAllF acilities( false);
  199                                      paramete rs.setFaci lity(
  200                                               getFacilit yService() .getFacili ty(rpForm. getFacilit y().getVal ue()));
  201                             }
  202                    }        
  203                    //de vice statu ses
  204                    para meters.set AllDeviceS tatuses(rp Form.getAl lDeviceSta tuses());
  205  
  206                    
  207                    //fr om and to  dates for  a schedule d report
  208                    Term Type sched uledReport FromType =  rpForm.ge tScheduled ReportFrom Type();
  209                    if ( scheduledR eportFromT ype != nul l) {
  210                             DateRa ngeBoundar y fromBoun dary = new  DateRange Boundary() ;
  211                             fromBo undary.set FixedDateT ype(toLook up(FixedDa teType.cla ss, rpForm
  212                                               .getSchedu ledReportF romFixedDa teType())) ;
  213                             fromBo undary.set MultiDayTi meUnitType (toLookup( MultiDayTi meUnitType .class, rp Form
  214                                               .getSchedu ledReportF romMultiDa yTimeUnitT ype()));
  215                             fromBo undary.set NumUnitsPr iorToCurre ntDay(rpFo rm
  216                                               .getSchedu ledReportF romNumUnit sPriorToCu rrentDay() );
  217                             fromBo undary.set SpecificFi xedDate(rp Form.getSc heduledRep ortFromSpe cificFixed Date());
  218                             fromBo undary.set Type(toLoo kup(DateRa ngeBoundar yType.clas s, rpForm
  219                                               .getSchedu ledReportF romType()) );
  220                             fromBo undary.set UnitPriorT oCurrentDa y(toLookup (SimpleTim eUnitType. class, rpF orm
  221                                               .getSchedu ledReportF romUnitPri orToCurren tDay()));
  222                             fromBo undary.set UsePreviou sDatePerio d(rpForm
  223                                               .getSchedu ledReportF romUsePrev iousDatePe riod());
  224                             parame ters.setSc heduledRep ortFromDat e(fromBoun dary);
  225                    }
  226  
  227                    Term Type sched uledReport ToType = r pForm.getS cheduledRe portToType ();
  228                    if ( scheduledR eportToTyp e != null)  {
  229                             DateRa ngeBoundar y toBounda ry = new D ateRangeBo undary();
  230                             toBoun dary.setFi xedDateTyp e(toLookup (FixedDate Type.class , rpForm
  231                                               .getSchedu ledReportT oFixedDate Type()));
  232                             toBoun dary.setMu ltiDayTime UnitType(t oLookup(Mu ltiDayTime UnitType.c lass, rpFo rm
  233                                               .getSchedu ledReportT oMultiDayT imeUnitTyp e()));
  234                             toBoun dary.setNu mUnitsPrio rToCurrent Day(rpForm
  235                                               .getSchedu ledReportT oNumUnitsP riorToCurr entDay());
  236                             toBoun dary.setSp ecificFixe dDate(rpFo rm.getSche duledRepor tToSpecifi cFixedDate ());
  237                             toBoun dary.setTy pe(toLooku p(DateRang eBoundaryT ype.class,  rpForm
  238                                               .getSchedu ledReportT oType()));
  239                             toBoun dary.setUn itPriorToC urrentDay( toLookup(S impleTimeU nitType.cl ass, rpFor m
  240                                               .getSchedu ledReportT oUnitPrior ToCurrentD ay()));
  241                             toBoun dary.setUs ePreviousD atePeriod( rpForm.get ScheduledR eportToUse PreviousDa tePeriod() );
  242                             parame ters.setSc heduledRep ortToDate( toBoundary );
  243                    }
  244  
  245                    Inte ger daysTo KeepComple tedReports  = rpForm. getSchedul edReportDa ysToKeepCo mpletedRep orts();
  246                    if ( daysToKeep CompletedR eports !=  null)
  247                             parame ters.setDa ysToKeepCo mpletedRep orts(daysT oKeepCompl etedReport s);
  248  
  249                    // F ormat
  250                    if ( rpForm.get ReportForm at() != nu ll) {
  251                             Report Format rep ortFormat  = (ReportF ormat) get ByCode(Rep ortFormat. class, rpF orm
  252                                               .getReport Format().g etValue()) ;
  253                             parame ters.setRe portFormat (reportFor mat);
  254                    }
  255           }
  256  
  257           pr ivate void  toReportS cheduleFor m(Schedule  rs, Repor tScheduleF orm form)  {
  258                    form .setDateTo Generate(n ew Formatt edDateForm (rs.getDat eToGenerat e()));
  259                    form .setDayOfM onth(toTer mType(rs.g etDayOfMon th()));
  260                    form .setDayOfQ uarter(toT ermType(rs .getDayOfQ uarter())) ;
  261                    form .setDayOfW eek(toTerm Type(rs.ge tDayOfWeek ()));
  262                    form .setDaysOf Week(toTer mTypeList( rs.getDays OfWeek())) ;
  263                    form .setHour(r s.getHour( ));
  264                    form .setMinute (rs.getMin ute());
  265                    form .setMonth( toTermType (rs.getMon th()));
  266                    form .setNumeri cDayOfMont h(rs.getNu mericDayOf Month());
  267                    form .setRunFre quency(toT ermType(rs .getRunFre quency())) ;
  268                    form .setSchedu leType(toT ermType(rs .getSchedu leType())) ;
  269                    form .setWeekOf Month(toTe rmType(rs. getWeekOfM onth()));
  270                    form .setCronEx pression(r s.getCronE xpression( ));
  271                    form .setFriend lyDescript ion(rs.get FriendlyDe scription( ));
  272           }
  273           
  274           pr ivate void  toSchedul e(ReportSc heduleForm  reportSch eduleForm,  Schedule  reportSche dule)
  275                             throws  Terminolo gyExceptio n{
  276                    // c onvert rep ort schedu le
  277                    if ( reportSche duleForm ! = null) {
  278                             Termin ologyServi ce termino logyServic e = getTer minologyCa che().getT erminology Service();
  279                             RunFre quency rep ortRunFreq uency = Tr ansferUtil s.transfer TermTypeTo Lookup(
  280                                               terminolog yService,  RunFrequen cy.class,  reportSche duleForm
  281                                                                .get RunFrequen cy());
  282                             report Schedule.s etRunFrequ ency(repor tRunFreque ncy);
  283                             Schedu leType sch eduleType  = Transfer Utils.tran sferTermTy peToLookup (
  284                                               terminolog yService,  ScheduleTy pe.class,  reportSche duleForm
  285                                                                .get ScheduleTy pe());
  286                             report Schedule.s etSchedule Type(sched uleType);
  287                             DayOfM onth dayOf Month = Tr ansferUtil s.transfer TermTypeTo Lookup(ter minologySe rvice,
  288                                               DayOfMonth .class, re portSchedu leForm.get DayOfMonth ());
  289                             report Schedule.s etDayOfMon th(dayOfMo nth);
  290                             WeekOf Month week OfMonth =  TransferUt ils.transf erTermType ToLookup(t erminology Service,
  291                                               WeekOfMont h.class, r eportSched uleForm.ge tWeekOfMon th());
  292                             report Schedule.s etWeekOfMo nth(weekOf Month);
  293                             // pri vate DayOf Week dayOf Week; stor ed as set  daysOfWeek
  294                             DayOfQ uarter day OfQuarter  = Transfer Utils.tran sferTermTy peToLookup (terminolo gyService,
  295                                               DayOfQuart er.class,  reportSche duleForm.g etDayOfQua rter());
  296                             report Schedule.s etDayOfQua rter(dayOf Quarter);
  297                             Month  month = Tr ansferUtil s.transfer TermTypeTo Lookup(ter minologySe rvice, Mon th.class,
  298                                               reportSche duleForm.g etMonth()) ;
  299                             report Schedule.s etMonth(mo nth);
  300                             report Schedule.s etNumericD ayOfMonth( reportSche duleForm.g etNumericD ayOfMonth( ));
  301                             report Schedule.s etHour(rep ortSchedul eForm.getH our());
  302                             report Schedule.s etMinute(r eportSched uleForm.ge tMinute()) ;
  303                             // day sOfWeek
  304                             Set<Da yOfWeek> r eportDaysO fWeek = ne w HashSet< DayOfWeek> ();
  305                             List<T ermType> d aysOfWeek  = reportSc heduleForm .getDaysOf Week();
  306                             if (da ysOfWeek ! = null &&  daysOfWeek .size() >  0) {
  307                                      for (Ter mType term Type : day sOfWeek) {
  308                                               DayOfWeek  dayOfWeek  = (DayOfWe ek) getByC ode(DayOfW eek.class,  termType
  309                                                                .get Value());
  310                                               reportDays OfWeek.add (dayOfWeek );
  311                                      }
  312                                      reportSc hedule.set DaysOfWeek (reportDay sOfWeek);
  313                             }
  314                             DayOfW eek dayOfW eek = (Day OfWeek) Tr ansferUtil s.transfer TermTypeTo Lookup(
  315                                               terminolog yService,  DayOfWeek. class, rep ortSchedul eForm.getD ayOfWeek() );
  316                             report Schedule.s etDayOfWee k(dayOfWee k);
  317                             DateWi thTimeZone  dt = new  DateWithTi meZone(rep ortSchedul eForm.getD ateToGener ate()
  318                                               .getDate() , Security ContextHel per.getCur rentUser() .getCurren tTimeZone( ));
  319                             report Schedule.s etDateToGe nerate(dt) ;
  320                    }
  321           }
  322  
  323           pr ivate void  toComplet edReportFo rm(SimpleC ompletedRe port compl etedReport ,
  324                             Comple tedReportF orm comple tedRepForm ) throws C onversionS erviceExce ption {
  325                    try  {
  326                             Standa rdReport s tandardRep ort = comp letedRepor t.getStand ardReport( );
  327                             comple tedRepForm .setId(Str ing.valueO f(complete dReport.ge tId()));
  328                             Standa rdReportFo rm stdRepF orm = new  StandardRe portForm() ;
  329                             Report Type repor tType = st andardRepo rt.getRepo rtType();
  330                             stdRep Form.setSt andardRepo rt(new Ter mType(stan dardReport .getName() , standard Report
  331                                               .getCode() ));
  332                             stdRep Form.setRe portType(n ew TermTyp e(reportTy pe.getName (), report Type.getCo de()));
  333                             comple tedRepForm .setStanda rdReport(s tdRepForm) ;
  334                             Format tedDateFor m complete dDate = ne w Formatte dDateForm( );
  335                             comple tedDate.se tDate(comp letedRepor t.getCompl etedDate() );
  336                             comple tedDate.se tFormatted Date(TimeZ oneUtils.c onvertDate ToTimeZone (completed Report
  337                                               .getComple tedDate(),  TimeZone. getDefault ()));
  338                             comple tedRepForm .setComple tedDate(co mpletedDat e);
  339                             Report ExportedTy pe fileTyp e = comple tedReport. getFileTyp e();
  340                             comple tedRepForm .setFileTy pe(new Ter mType(file Type.getNa me(), file Type.getCo de()));
  341                             comple tedRepForm
  342                                               .setReport ParameterT ext(tohtml (completed Report.get ReportPara meterText( )));
  343                             comple tedRepForm .setUserNa me(complet edReport.g etUserName ());
  344                             comple tedRepForm .setUserFu llName(com pletedRepo rt.getUser FullName() );
  345                             if (co mpletedRep ort.getExp irationDat e() != nul l) {
  346                                      Formatte dDateForm  expiration dDate = ne w Formatte dDateForm( );
  347                                      expirati ondDate.se tDate(comp letedRepor t.getExpir ationDate( ));
  348                                      expirati ondDate.se tFormatted Date(TimeZ oneUtils.c onvertDate ToTimeZone (
  349                                                       co mpletedRep ort.getExp irationDat e(), TimeZ one.getDef ault()));
  350                                      complete dRepForm.s etExpirati onDate(exp irationdDa te);
  351                             }
  352                             comple tedRepForm .setReport Name(compl etedReport .getReport Name());
  353                    } ca tch (Excep tion e) {
  354                             throw  new Conver sionServic eException (
  355                                               "Conversio n from Sim pleComplet edReport t o  Complet edReportFo rm failed  ", e);
  356                    }
  357           }
  358  
  359           pr ivate void  toReportS etupForm(R eportSetup  reportSet up, Report SetupForm  reportSetu pForm)
  360                             throws  Conversio nServiceEx ception {
  361                    // c onvert rep ort setup
  362                    Stan dardReport  standardR eport = re portSetup. getStandar dReport();
  363                    repo rtSetupFor m.setId(re portSetup. getId() ==  null ? nu ll : Strin g.valueOf( reportSetu p
  364                                      .getId() ));
  365                    repo rtSetupFor m.setStand ardReport( new TermTy pe(standar dReport.ge tName(), s tandardRep ort
  366                                      .getCode ()));
  367                    repo rtSetupFor m.setFileT ype(new Te rmType(rep ortSetup.g etFileType ().getName (), report Setup
  368                                      .getFile Type().get Code()));
  369                    repo rtSetupFor m.setEmail Address(re portSetup. getEmailAd dress());
  370                    // c onvert rep ort parame ters
  371                    DIRe portParame ters param eters = (D IReportPar ameters) r eportSetup .getReport Parameters ();
  372                    Repo rtParamete rsForm rpF orm = new  ReportPara metersForm ();
  373                    repo rtSetupFor m.setRepor tParameter s(rpForm);
  374                    toRe portParame tersForm(p arameters,  rpForm);
  375           }
  376           
  377           /* *
  378            *  Convert S cheduledRe port to Re portSetupF orm
  379            *  @param sc heduledRep ort
  380            *  @param re portSetupF orm
  381            *  @throws C onversionS erviceExce ption
  382            * /
  383           pr ivate void  toReportS etupForm(S cheduledRe port sched uledReport , ReportSe tupForm re portSetupF orm)
  384           th rows Conve rsionServi ceExceptio n {
  385                    
  386                    Stan dardReport  standardR eport = sc heduledRep ort.getSta ndardRepor t();
  387                    repo rtSetupFor m.setId(sc heduledRep ort.getId( ) == null  ? null : S tring.valu eOf(schedu ledReport
  388                                      .getId() ));
  389                    repo rtSetupFor m.setStand ardReport( new TermTy pe(standar dReport.ge tName(), s tandardRep ort
  390                                      .getCode ()));
  391                    repo rtSetupFor m.setFileT ype(new Te rmType(sch eduledRepo rt.getFile Type().get Name(), sc heduledRep ort
  392                                      .getFile Type().get Code()));
  393                    repo rtSetupFor m.setEmail Address(sc heduledRep ort.getEma il());
  394                    
  395                    // c onvert sch edule
  396                    Repo rtSchedule  reportSch edule = sc heduledRep ort.getRep ortSchedul e();
  397                    Repo rtSchedule Form repor tScheduleF orm = new  ReportSche duleForm() ;
  398                    repo rtSetupFor m.setRepor tSchedule( reportSche duleForm);
  399                    toRe portSchedu leForm(rep ortSchedul e, reportS cheduleFor m);
  400                    
  401                    // c onvert rep ort parame ters
  402                    DIRe portParame ters param eters = (D IReportPar ameters) s cheduledRe port.getRe portParame ters();
  403                    Repo rtParamete rsForm rpF orm = new  ReportPara metersForm ();
  404                    repo rtSetupFor m.setRepor tParameter s(rpForm);
  405                    toRe portParame tersForm(p arameters,  rpForm);
  406           }
  407           
  408           pr ivate void  toSchedul edReportFo rm(Schedul edReport s cheduledRe port,
  409                             Schedu ledReportF orm schedu ledReportF orm) throw s Conversi onServiceE xception {
  410                    sche duledRepor tForm.setI d(String.v alueOf(sch eduledRepo rt.getId() ));
  411                    Stan dardReport  standardR eport = sc heduledRep ort.getSta ndardRepor t();
  412                    Stan dardReport Form stdRe pForm = ne w Standard ReportForm ();
  413                    Repo rtType rep ortType =  standardRe port.getRe portType() ;
  414                    stdR epForm.set StandardRe port(new T ermType(st andardRepo rt.getName (), standa rdReport
  415                                      .getCode ()));
  416                    stdR epForm.set ReportType (new TermT ype(report Type.getNa me(), repo rtType.get Code()));
  417                    sche duledRepor tForm.setS tandardRep ort(stdRep Form);
  418                    Repo rtExported Type fileT ype = sche duledRepor t.getFileT ype();
  419                    sche duledRepor tForm.setF ileType(ne w TermType (fileType. getName(),  fileType. getCode()) );
  420                    sche duledRepor tForm.setS etupUser(s cheduledRe port.getUs erName());
  421                    sche duledRepor tForm.setE mailAddres s(schedule dReport.ge tEmail());
  422                    //sc heduledRep ortForm.se tReportPar ametersTex t(schedule dReport.ge tReportPar ameterText ());
  423                    //sc heduledRep ortForm.se tReportSch eduleText( scheduledR eport.getR eportSched uleText()) ;
  424                    
  425                    //Sc hedule
  426                    sche duledRepor tForm.setF requency(s cheduledRe port.getRe portSchedu le() != nu ll ? sched uledReport
  427                                      .getRepo rtSchedule ().getFrie ndlyDescri ption() :  null);
  428                    
  429                    //TO DO Date Ra nge is not  used yet  for the sc heduled re ports
  430                    DIRe portParame ters rp =  (DIReportP arameters)  scheduled Report.get ReportPara meters();
  431                    if ( rp != null ) {
  432                             if (rp .getFromDa te() != nu ll)
  433                                      //schedu ledReportF orm.setFro mDate(Date Utils.form at(rp.getF romDate(), null));
  434                             if (rp .getToDate () != null )
  435                                      //schedu ledReportF orm.setToD ate(DateUt ils.format (rp.getToD ate(),null ));
  436                             
  437                             if (rp .getReport Week() !=  null) {
  438                                      ReportWe ek rw = rp .getReport Week();
  439                                      //schedu ledReportF orm.setFro mDate(Date Utils.form at(rw.getS tartDate() ,null));
  440                                      //schedu ledReportF orm.setToD ate(DateUt ils.format (rw.getEnd Date(),nul l));
  441                             }
  442                    }
  443           }
  444  
  445           pr ivate void  toReportP arametersF orm(DIRepo rtParamete rs paramet ers, Repor tParameter sForm rpFo rm)
  446                             throws  Conversio nServiceEx ception {
  447  
  448                    // p arameters. setUserTim eZone(getC urrentUser ().getCurr entTimeZon e());
  449                    rpFo rm.setToDa te(paramet ers.getToD ate());
  450                    rpFo rm.setFrom Date(param eters.getF romDate()) ;
  451                    rpFo rm.setAsOf Date(param eters.getA sOfDate()) ;
  452                    rpFo rm.setRepo rtWeek(par ameters.ge tReportWee k());
  453                    rpFo rm.setRepo rtFormat(t oTermType( parameters .getReport Format())) ;
  454                    if ( StringUtil s.isNotEmp ty(paramet ers.getRep ortSummary Type())) {
  455                             rpForm .setReport SummaryTyp e(new Term Type(param eters.getR eportSumma ryType(),p arameters. getReportS ummaryType ()));
  456                    }
  457                    if ( parameters .getAllVis ns()) {
  458                             Simple Visn allVi sns = Simp leVisn.ALL _VISNS;
  459                             rpForm .setVisn(n ew TermTyp e(allVisns .getName() , allVisns .getName() ));                     
  460                    }els e if (para meters.get Visn() !=  null){
  461                             rpForm .setVisn(t oTermType( parameters .getVisn() ));
  462                    }
  463                    if ( parameters .getAllFac ilities())  {
  464                             Facili ty allFaci lities = F acility.AL L_FACILITI ES;
  465                             rpForm .setFacili ty(new Ter mType(allF acilities. getName(),  allFacili ties.getNa me()));
  466                    }els e if (para meters.get Facility()  != null){
  467                             rpForm .setFacili ty(toTermT ype(parame ters.getFa cility())) ;
  468                    }                 
  469                    if ( StringUtil s.isNotEmp ty(paramet ers.getSub TotalType( ))) {
  470                             rpForm .setSubTot alType(new  TermType( parameters .getSubTot alType(),p arameters. getSubTota lType()));
  471                    }
  472                    
  473                    //de vice statu ses
  474                    rpFo rm.setAllD eviceStatu ses(parame ters.getAl lDeviceSta tuses());
  475                    
  476                    //Sc heduling p arameters
  477                    Date RangeBound ary srFrom Date = par ameters.ge tScheduled ReportFrom Date();
  478                    if ( srFromDate  != null)  {
  479                             rpForm .setSchedu ledReportF romFixedDa teType(toT ermType(sr FromDate.g etFixedDat eType()));
  480                             rpForm .setSchedu ledReportF romMultiDa yTimeUnitT ype(toTerm Type(srFro mDate
  481                                               .getMultiD ayTimeUnit Type()));
  482                             rpForm .setSchedu ledReportF romNumUnit sPriorToCu rrentDay(s rFromDate
  483                                               .getNumUni tsPriorToC urrentDay( ));
  484                             rpForm .setSchedu ledReportF romSpecifi cFixedDate (srFromDat e.getSpeci ficFixedDa te());
  485                             rpForm .setSchedu ledReportF romType(to TermType(s rFromDate. getType()) );
  486                             rpForm .setSchedu ledReportF romUnitPri orToCurren tDay(toTer mType(srFr omDate
  487                                               .getUnitPr iorToCurre ntDay()));
  488                             rpForm .setSchedu ledReportF romUsePrev iousDatePe riod(srFro mDate
  489                                               .getUsePre viousDateP eriod());
  490                    }
  491  
  492                    Date RangeBound ary srToDa te = param eters.getS cheduledRe portToDate ();
  493                    if ( srToDate ! = null) {
  494                             rpForm .setSchedu ledReportT oFixedDate Type(toTer mType(srTo Date.getFi xedDateTyp e()));
  495                             rpForm .setSchedu ledReportT oMultiDayT imeUnitTyp e(toTermTy pe(srToDat e
  496                                               .getMultiD ayTimeUnit Type()));
  497                             rpForm .setSchedu ledReportT oNumUnitsP riorToCurr entDay(srT oDate
  498                                               .getNumUni tsPriorToC urrentDay( ));
  499                             rpForm .setSchedu ledReportT oSpecificF ixedDate(s rToDate.ge tSpecificF ixedDate() );
  500                             rpForm .setSchedu ledReportT oType(toTe rmType(srT oDate.getT ype()));
  501                             rpForm .setSchedu ledReportT oUnitPrior ToCurrentD ay(toTermT ype(srToDa te
  502                                               .getUnitPr iorToCurre ntDay()));
  503                             rpForm .setSchedu ledReportT oUsePrevio usDatePeri od(srToDat e.getUsePr eviousDate Period());
  504                    }
  505  
  506                    rpFo rm.setSche duledRepor tDaysToKee pCompleted Reports(pa rameters
  507                                      .getDays ToKeepComp letedRepor ts());
  508                    
  509                    
  510           }
  511  
  512           pr otected <T  extends L ookup> Set <T> toLook upSet(Clas s<T> clazz , Collecti on<TermTyp e> termTyp es)
  513                             throws  Exception  {
  514                    Set< T> lookups  = new Has hSet<T>();
  515                    if ( termTypes  != null &&  termTypes .size() >  0) {
  516                             for (T ermType te rmType : t ermTypes)  {
  517                                      T lookup  = getByCo de(clazz,  termType.g etValue()) ;
  518                                      lookups. add(lookup );
  519                             }
  520                    }
  521                    retu rn lookups ;
  522           }
  523  
  524           pr otected Se t<Boolean>  toBoolean Set(Collec tion<? ext ends TermT ype> termT ypes) thro ws Excepti on {
  525                    Set< Boolean> s et = new H ashSet<Boo lean>();
  526                    if ( termTypes  != null &&  termTypes .size() >  0) {
  527                             for (T ermType te rmType : t ermTypes)  {
  528                                      Boolean  selectedVa lue = Bool ean.parseB oolean(ter mType.getV alue());
  529                                      set.add( selectedVa lue);
  530                             }
  531                    }
  532                    retu rn set;
  533           }
  534  
  535           pr otected Se t<String>  toStringSe t(Collecti on<TermTyp e> termTyp es) throws  Exception  {
  536                    Set< String> se t = new Ha shSet<Stri ng>();
  537                    if ( termTypes  != null &&  termTypes .size() >  0) {
  538                             for (T ermType te rmType : t ermTypes)  {
  539                                      set.add( termType.g etValue()) ;
  540                             }
  541                    }
  542                    retu rn set;
  543           }
  544  
  545           pr otected <T  extends L ookup> T t oLookup(Cl ass<T> cla zz, TermTy pe termTyp e) throws  Terminolog yException {
  546                    retu rn Transfe rUtils.tra nsferTermT ypeToLooku p(getTermi nologyCach e().getTer minologySe rvice(),
  547                                      clazz, t ermType);
  548           }
  549  
  550           pr ivate Stri ng tohtml( String par ametersTex t) {
  551                    Stri ngBuilder  formattedT ext = new  StringBuil der();
  552                    if ( StringUtil s.isNotEmp ty(paramet ersText))  {
  553                             String [] pars =  parameters Text.split (",");
  554                             for (i nt i = 0;  i < pars.l ength; i++ ) {
  555                                      String p arValue =  pars[i];
  556                                      parValue  = parValu e.replace( ":", ",");
  557                                      formatte dText.appe nd(parValu e);
  558                                      formatte dText.appe nd("\n");/ / formatte dText.appe nd("<br>") ;
  559                             }
  560                    }
  561  
  562                    retu rn formatt edText.toS tring();
  563           }
  564  
  565   }