35. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/13/2017 3:41:55 PM 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.

35.1 Files compared

# Location File Last Modified
1 Genisis_v3.zip\Source Code\Services\src\main\java\gov\va\genisis2\bo BusinessService.java Wed Jun 28 20:38:28 2017 UTC
2 Genisis_v3.zip\Source Code\Services\src\main\java\gov\va\genisis2\bo BusinessService.java Wed Jul 12 16:46:15 2017 UTC

35.2 Comparison summary

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

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

35.4 Active regular expressions

No regular expressions were active.

35.5 Comparison detail

  1   package go v.va.genis is2.bo;
  2  
  3   import gov .va.genisi s2.common. enums.Comm onEnum;
  4   import gov .va.genisi s2.model.C ommentHist ory;
  5   import gov .va.genisi s2.model.R equest;
  6   import gov .va.genisi s2.model.R equestHist ory;
  7   import gov .va.genisi s2.model.R equestType ;
  8   import gov .va.genisi s2.model.S ource;
  9   import gov .va.genisi s2.model.S tudyApprov al;
  10   import gov .va.genisi s2.model.U sers;
  11   import gov .va.genisi s2.model.W orkflowSta tus;
  12   import gov .va.genisi s2.service .impl.Comm entHistory Service;
  13   import gov .va.genisi s2.service .impl.Look UpService;
  14   import gov .va.genisi s2.service .impl.Requ estService ;
  15   import gov .va.genisi s2.service .impl.Stud yApprovalS ervice;
  16   import gov .va.genisi s2.service .impl.User Management Service;
  17   import gov .va.genisi s2.util.re st.helper. ResponseWr apper;
  18   import gov .va.genisi s2.vo.Copy TableDomai ns;
  19   import gov .va.genisi s2.vo.Copy TableSourc e;
  20   import gov .va.genisi s2.vo.Emai lDetails;
  21   import gov .va.genisi s2.vo.Geni sisPropert ies;
  22  
  23   import jav a.io.Buffe redReader;
  24   import jav a.io.File;
  25   import jav a.io.IOExc eption;
  26   import jav a.io.Input StreamRead er;
  27   import jav a.util.Arr ayList;
  28   import jav a.util.Arr ays;
  29   import jav a.util.Dat e;
  30   import jav a.util.Lis t;
  31   import jav a.util.UUI D;
  32  
  33   import org .apache.co mmons.lang .StringUti ls;
  34   import org .json.JSON Object;
  35   import org .slf4j.Log gerFactory ;
  36   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  37  
  38  
  39   /**
  40    * The Cla ss Busines sService.
  41    * 
  42    * The Bus inessServi ce Class d efines the  methods t hat are ca lled by th e
  43    * Genisis 2Controlle r to perfo rm the bus iness logi c.
  44    * 
  45    */
  46   /*
  47    * TBD: Co nsolidate  all genisi s2.propert ies into g enisisProp erties
  48    */
  49  
  50   public cla ss Busines sService i mplements  IBusiness  {
  51  
  52           /* * The logg er. */
  53           pr ivate fina l org.slf4 j.Logger l ogger = Lo ggerFactor y.getLogge r(Business Service.cl ass);
  54           
  55           /* * The requ est servic e. */
  56           pr ivate Requ estService  requestSe rvice;
  57  
  58           /* * The stud y approval  service.  */
  59           pr ivate Stud yApprovalS ervice stu dyApproval Service;
  60  
  61           /* * The comm ent histor y service.  */
  62           pr ivate Comm entHistory Service co mmentHisto ryService;
  63  
  64           /* * The user  managemen t service.  */
  65           pr ivate User Management Service us erManageme ntService;
  66  
  67           /* * The acti viti servi ce. */
  68           pr ivate Acti vitiServic e activiti Service;
  69  
  70           /* * The look  up servic e. */
  71           pr ivate Look UpService  lookUpServ ice;
  72  
  73           /* * The copy  table sou rce. */
  74           pr ivate Copy TableSourc e copyTabl eSource;
  75           
  76           /*
  77            *  The copy  table doma in details  
  78            * /
  79           pr ivate Copy TableDomai ns copyTab leDomains;
  80           
  81           /*
  82            *  The genis isProperti es
  83            * /
  84           pr ivate Geni sisPropert ies genisi sPropertie s;
  85           
  86  
  87           
  88           
  89           
  90           /* *
  91            *  Creates t he study a pproval.
  92            *
  93            *  @param st udyApprova lIn The st udyApprova lIn.
  94            *  @return R esponseWra pper This  returns wr apper.
  95            * /
  96           @O verride
  97           pu blic Respo nseWrapper   createSt udyApprova l(StudyApp roval stud yApprovalI n) {
  98                    logg er.info("B usinessSer vice:  cre ateStudyAp proval");
  99                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  100                    Stud yApproval  studyAppro val = Busi nessHelper .handleStu dyApproval Payload(st udyApprova lIn);
  101                    int  id = getSt udyApprova lService() .createStu dyApproval (studyAppr oval);
  102                    if ( id > 0) {
  103                             wrappe r = this.g etStudyApp rovalsByID (id);
  104                             wrappe r.setSucce ss(true);
  105                             wrappe r.setMessa ge(null);
  106                    } el se {
  107                             List<S tudyApprov al> studyA pprovalLis t = Busine ssHelper
  108                                               .prepareSt udyApprova lResponseP ayload(Arr ays.asList (studyAppr oval));
  109                             wrappe r.setRespo nse(studyA pprovalLis t.get(0));
  110                             wrappe r.setSucce ss(false);
  111                             wrappe r.setMessa ge("Unable  to create  Study App roval");
  112                    }
  113                    retu rn wrapper ;
  114           }
  115  
  116           /* *
  117            *  Update st udy approv al.
  118            *
  119            *  @param st udyApprova lIn The st udyApprova lIn.
  120            *  @return R esponseWra pper This  returns wr apper.
  121            * /
  122           @O verride
  123           pu blic Respo nseWrapper   updateSt udyApprova l(StudyApp roval stud yApprovalI n) {
  124                    logg er.info("B usinessSer vice: upda teStudyApp roval");
  125                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  126                    Stud yApproval  studyAppro val = Busi nessHelper .handleStu dyApproval Payload(st udyApprova lIn);
  127                    int  id = study Approval.g etId();
  128                    if ( id > 0) {
  129                             getStu dyApproval Service(). updateStud yApproval( studyAppro val);
  130                             wrappe r = this.g etStudyApp rovalsByID (id);
  131                    } el se {
  132                             List<S tudyApprov al> studyA pprovalLis t = Busine ssHelper
  133                                               .prepareSt udyApprova lResponseP ayload(Arr ays.asList (studyAppr oval));
  134                             wrappe r.setRespo nse(studyA pprovalLis t.get(0));
  135                             wrappe r.setSucce ss(false);
  136                             wrappe r.setMessa ge("Unable  to update  Study App roval");
  137                    }
  138                    retu rn wrapper ;
  139           }
  140  
  141           /* *
  142            *  Gets the  study appr ovals by I D.
  143            *
  144            *  @param id     The id .
  145            *  @return R esponseWra pper This  returns Re sponseWrap per.
  146            * /
  147           @O verride
  148           pu blic Respo nseWrapper   getStudy ApprovalsB yID(int id ) {
  149                    logg er.info("B usinessSer vice:  get StudyAppro valsByID:"  + id);
  150                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  151                    Stud yApproval  studyAppro val = getS tudyApprov alService( ).getStudy ApprovalsB yID(id);
  152                    if ( studyAppro val != nul l) {
  153                             List<S tudyApprov al> studyA pprovalLis t = Busine ssHelper
  154                                               .prepareSt udyApprova lResponseP ayload(Arr ays.asList (studyAppr oval));
  155                             wrappe r.setRespo nse(studyA pprovalLis t.get(0));
  156                    }
  157                    retu rn createR esponseWra pper(wrapp er);  
  158           }
  159  
  160           /* *
  161            *  Gets the  study appr ovals by U ID.
  162            *
  163            *  @param ui d The uid.
  164            *  @return R esponseWra pper This  returns Re sponseWrap per.
  165            * /
  166           @O verride
  167           pu blic Respo nseWrapper  getStudyA pprovalsBy UID(String  uid) {
  168                    logg er.info("B usinessSer vice:  get StudyAppro vals by us er:" + uid );
  169                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  170                    List <StudyAppr oval> stud yApprovalL ist = getS tudyApprov alService( ).getStudy ApprovalsB yUID(uid);
  171                    stud yApprovalL ist = Busi nessHelper .prepareSt udyApprova lResponseP ayload(stu dyApproval List);
  172                    wrap per.setRes ponse(stud yApprovalL ist);
  173                    retu rn createR esponseWra pper(wrapp er);
  174           }
  175  
  176           /* *
  177            *  Gets the  study appr ovals.
  178            *
  179            *  @return R esponseWra pper This  returns Re sponseWrap per.
  180            * /
  181           @O verride
  182           pu blic Respo nseWrapper   getStudy Approvals( ) {
  183                    logg er.info("B usinessSer vice:  get StudyAppro vals");
  184                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  185                    List <StudyAppr oval> stud yApprovalL ist = getS tudyApprov alService( ).getStudy Approvals( );
  186                    stud yApprovalL ist = Busi nessHelper .prepareSt udyApprova lResponseP ayload(stu dyApproval List);
  187                    wrap per.setRes ponse(stud yApprovalL ist);
  188                    retu rn createR esponseWra pper(wrapp er);
  189           }
  190  
  191           /* *
  192            *  Gets the  request da ta sources .
  193            *
  194            *  @return R esponseWra pper This  returns Re sponseWrap per.
  195            * /
  196           @O verride
  197           pu blic Respo nseWrapper   getReque stDataSour ces() {
  198                    logg er.info("B usinessSer vice:  get DataSource s");
  199                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  200                    List <Source> l istDatasou rces = get RequestSer vice().get DataSource s();
  201                    wrap per.setRes ponse(list Datasource s);
  202                    retu rn createR esponseWra pper(wrapp er);
  203           }
  204  
  205           /* *
  206            *  Gets the  request ty pes.
  207            *
  208            *  @return R esponseWra pper This  returns Re sponseWrap per.
  209            * /
  210           @O verride
  211           pu blic Respo nseWrapper   getReque stTypes()  {
  212                    logg er.info("B usinessSer vice:  get RequestTyp es");
  213                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  214                    List <RequestTy pe> listRe questTypes  = getRequ estService ().getRequ estTypes() ;
  215                    wrap per.setRes ponse(list RequestTyp es);
  216                    retu rn createR esponseWra pper(wrapp er);
  217           }
  218  
  219           /* *
  220            *  Creates t he respons e wrapper.
  221            *
  222            *  @param wr apper
  223            *              The wrap per.
  224            *  @return R esponseWra pper This  returns wr apper.
  225            * /
  226           pr ivate Resp onseWrappe r createRe sponseWrap per(Respon seWrapper  wrapper) {
  227                    logg er.info("B usinessSer vice:  cre ating Resp onse Wrapp er");
  228                    if ( wrapper ==  null) {
  229                             Respon seWrapper  wrapperLoc al = new R esponseWra pper();
  230                             wrappe rLocal.set Message("I nternal Sy stem Error . Could no t perform  requested  Opeartion" );
  231                             wrappe rLocal.set Response(n ull);
  232                             wrappe rLocal.set Success(fa lse);
  233                             return  wrapperLo cal;
  234                    }
  235  
  236                    if ( wrapper.ge tResponse( ) == null)  {
  237                             wrappe r.setSucce ss(true);
  238                             wrappe r.setRespo nse(null);
  239                             wrappe r.setMessa ge(CommonE num.NO_REC ORD_FOUND. getText()) ;
  240                             return  wrapper;
  241                    } 
  242                    
  243                    
  244                    Obje ct object  = wrapper. getRespons e();
  245                    
  246                    Stri ng isOk;
  247                    for  (;;) {
  248                             if (ob ject insta nceof Arra yList<?>
  249                                               || object  instanceof  StudyAppr oval
  250                                               || object  instanceof  CommentHi story
  251                                               || object  instanceof  Request)  {
  252                                      isOk = " true";
  253                                      
  254                             }
  255                             else { isOk = "fa lse";}
  256                             break;
  257                    }
  258                                      
  259                    if ( isOk=="fal se") {
  260                             wrappe r.setSucce ss(true);
  261                             wrappe r.setRespo nse(null);
  262                             wrappe r.setMessa ge(CommonE num.NO_REC ORD_FOUND. getText()) ;
  263                             return  wrapper;
  264                    }
  265                             
  266                    if   (!(object  instanceof  ArrayList <?>)) {
  267                             wrappe r.setSucce ss(true);
  268                             wrappe r.setMessa ge(null);
  269                             wrappe r.setRespo nse(object );
  270                             return  wrapper;
  271                    }
  272                    
  273                    try  {
  274                             wrappe r.setSucce ss(true);
  275                             wrappe r.setMessa ge(null);
  276  
  277                             if ((( ArrayList)  object).s ize() == 1 ) {
  278                                      Object o bj = ((Arr ayList<?>)  object).g et(0);
  279  
  280                                      if (obj  instanceof  StudyAppr oval) {
  281                                               StudyAppro val studyA pproval =  (StudyAppr oval) (obj );
  282                                               wrapper.se tResponse( studyAppro val);
  283                                      } else i f (obj ins tanceof Co mmentHisto ry) {
  284                                               CommentHis tory comme ntHistory  = (Comment History) ( obj);
  285                                               wrapper.se tResponse( commentHis tory);
  286                                      }
  287  
  288                                      return w rapper;
  289                             }
  290  
  291                    } ca tch (Excep tion ex) {
  292                             logger .error(
  293                                               "Exception  occured i n the meth od createR esponseWra pper. Reas on: "
  294                                                                + ex .getMessag e() + " ",  ex);
  295  
  296                    }
  297                    
  298                    retu rn wrapper ;
  299           }
  300  
  301           /* *
  302            *  Get user  details by  email.
  303            *
  304            *  @param em ail
  305            *              The emai l.
  306            *  @return R esponseWra pper This  returns wr apper.
  307            * /
  308           @O verride
  309           pu blic Respo nseWrapper   getUserD etailsByEm ail(String  email) {
  310                    logg er.info("B usinessSer vice:  use r details  by email:"  + email);
  311                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  312                    User s users =  null;
  313  
  314                    try  {
  315                             users  = userMana gementServ ice.getUse rDetailsBy Email(emai l);
  316                    } ca tch (Excep tion ex) {
  317                             logger .error("Er ror occure d while ge tting user  details o n email. "  + email +  ". Reason : " + ex.g etMessage( ) + " ", e x);
  318                             wrappe r.setRespo nse(users) ;
  319                             wrappe r.setSucce ss(false);
  320                             wrappe r.setMessa ge("Error  ocuured wh ile gettin g User det ails for "  + email);
  321                             return  wrapper;
  322                    }
  323  
  324                    if ( users == n ull) {
  325                             wrappe r.setMessa ge("No rec ords found .");
  326                             wrappe r.setSucce ss(false);
  327                             wrappe r.setRespo nse(null);
  328                    } el se {
  329                             wrappe r.setSucce ss(true);
  330                             wrappe r.setRespo nse(users) ;
  331                    }
  332  
  333                    retu rn wrapper ;
  334           }
  335  
  336           /* *
  337            *  Get user  details by  id.
  338            *
  339            *  @param id    The id.
  340            *  @return R esponseWra pper This  returns wr apper.
  341            * /
  342           @O verride
  343           pu blic Respo nseWrapper   getUserD etailsById (int id) {
  344                    logg er.info("B usinessSer vice:  use r details  by Id:" +  id);
  345                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  346                    User s users =  null;
  347  
  348                    try  {
  349                             users  = userMana gementServ ice.getUse rDetailsBy Id(id);
  350                    } ca tch (Excep tion ex) {
  351                             logger .error("Er ror occure d while ge tting user  details o n id-'" +  id + "'. R eason: " +  ex.getMes sage() + "  ", ex);
  352                             wrappe r.setRespo nse(users) ;
  353                             wrappe r.setSucce ss(false);
  354                             wrappe r.setMessa ge("Error  ocuured wh ile gettin g User det ails for "  + id);
  355                             return  wrapper;
  356                    }
  357  
  358                    if ( users == n ull) {
  359                             wrappe r.setMessa ge("No rec ords found .");
  360                             wrappe r.setSucce ss(false);
  361                             wrappe r.setRespo nse(null);
  362                    } el se {
  363                             wrappe r.setRespo nse(users) ;
  364                             wrappe r.setSucce ss(true);
  365                    }
  366  
  367                    retu rn wrapper ;
  368           }
  369  
  370           /* *
  371            *  Gets the  user role.
  372            *
  373            *  @param ui d   The ui d.
  374            *  @return R esponseWra pper This  returns wr apper.
  375            * /
  376           @O verride
  377           pu blic Respo nseWrapper   getUserR ole(int ui d) {
  378                    logg er.info("B usinessSer vice:  use r role by  uid:" + ui d);
  379                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  380                    Stri ng userRol e = userMa nagementSe rvice.getU serRole(ui d);
  381  
  382                    if ( StringUtil s.isBlank( userRole)  ) {
  383                             wrappe r.setMessa ge("No rol es found." );
  384                             wrappe r.setRespo nse(null);
  385                             wrappe r.setSucce ss(false);
  386                    } el se {
  387                             wrappe r.setRespo nse(userRo le);
  388                             wrappe r.setSucce ss(true);
  389                    }
  390  
  391                    retu rn wrapper ;
  392           }
  393  
  394           /* *
  395            *  Creates t he request .
  396            *
  397            *  @param re questIn Th e requestI n.
  398            *  @return R esponseWra pper This  returns wr apper.
  399            * /
  400           @O verride
  401           pu blic Respo nseWrapper   createRe quest(Requ est reques tIn) {
  402                    logg er.info("B usinessSer vice: crea teRequest" );
  403                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  404                    Requ est reques t = Busine ssHelper.h andleReque stPayload( requestIn) ;
  405  
  406                    if ( StringUtil s.isBlank( request.ge tApproverI d())) {
  407                             Users  user = thi s.userMana gementServ ice.getUse rDetailsBy Email(requ est.getCre atedBy());
  408                             if (us er != null )
  409                             reques t.setAppro verId(user .getApprov er());
  410                    }
  411  
  412                    // I mplement w orkflow
  413                    bool ean workfl owProcessI dRequired  = true;
  414                    if ( request.ge tId() != 0 ) {
  415                             Reques t existing Request =  getRequest Service(). getRequest sById(requ est.getId( ));
  416                             if (ex istingRequ est.getId( ) != 0) {
  417                                      workflow ProcessIdR equired =  false;
  418                             }
  419                    }
  420                    if ( workflowPr ocessIdReq uired) {
  421                    
  422                             String  processIn stanceId =  StringUti ls.EMPTY;
  423  
  424                             try {
  425                                      processI nstanceId  = activiti Service.st artProcess (request.g etCreatedB y());
  426                             } catc h (Excepti on e) {
  427                                      logger.e rror("Unab le to star t process  for " + re quest.getC reatedBy()  + ". Reas on: " + e. getMessage () + " ",  e);
  428                             }
  429  
  430                             if (St ringUtils. isBlank(pr ocessInsta nceId)) {
  431                                      request. setProcess Id(0);
  432                             } else  {
  433                                      int intP rocessInst anceId = I nteger.par seInt(proc essInstanc eId);
  434                                      request. setProcess Id(intProc essInstanc eId);
  435                             }
  436                    }
  437  
  438                    if ( request.ge tProcessId () == 0) {
  439                             List<R equest> re questList  = Business Helper.pre pareReques tResponseP ayload(Arr ays.asList (request)) ;
  440  
  441                             wrappe r.setRespo nse(reques tList.get( 0));
  442                             wrappe r.setSucce ss(false);
  443                             wrappe r.setMessa ge("Unable  to create  Request.  Business p rocess fai led to sta rt.");
  444                             return  wrapper;
  445                    }
  446  
  447                    int  id = getRe questServi ce().creat eRequest(r equest);
  448                    if ( id > 0) {
  449                             this.p reserveHis tory(reque st);
  450                             wrappe r = this.g etRequestB yID(id);
  451                             wrappe r.setSucce ss(true);
  452                             wrappe r.setMessa ge(null);
  453                    } el se {
  454                             List<R equest> re questList  = Business Helper.pre pareReques tResponseP ayload(Arr ays.asList (request)) ;
  455  
  456                             wrappe r.setRespo nse(reques tList.get( 0));
  457                             wrappe r.setSucce ss(false);
  458                             wrappe r.setMessa ge("Unable  to create  Request") ;
  459                    }
  460                    retu rn wrapper ;
  461           }
  462  
  463           /* *
  464            *  Gets the  request by  ID.
  465            *
  466            *  @param id    The id.
  467            *  @return R esponseWra pper This  returns Re sponseWrap per.
  468            * /
  469           @O verride
  470           pu blic Respo nseWrapper   getReque stByID(int  id) {
  471                    logg er.info("B usinessSer vice: get  Request by  Id:" + id );
  472                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  473                    Requ est reques t = getReq uestServic e().getReq uestsById( id);
  474                    if ( request !=  null) {
  475                             List<R equest> re questList  = Business Helper.pre pareReques tResponseP ayload(Arr ays.asList (request)) ;
  476  
  477                             wrappe r.setRespo nse(reques tList.get( 0));
  478                    }
  479                    retu rn createR esponseWra pper(wrapp er);
  480           }
  481  
  482           /* *
  483            *  Gets the  request tr acking by  ID.
  484            *
  485            *  @param id   The id.
  486            *  @return R esponseWra pper This  returns Re sponseWrap per.
  487            * /
  488           @O verride
  489           pu blic Respo nseWrapper   getReque stTracking ByID(int i d) {
  490                    logg er.info("B usinessSer vice: get  Audit Requ est by Id: " + id);
  491                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  492                    Requ est reques t = getReq uestServic e().getReq uestsById( id);
  493                    if ( request !=  null) {
  494                             List<R equestHist ory> track ingList =  getRequest Service(). getRequest HistoryByI d(id);
  495                             if (tr ackingList  == null | | tracking List.isEmp ty())
  496                                      wrapper. setRespons e(null);
  497                             else {
  498                                      // trans form track ingList
  499                                      wrapper. setRespons e(this.get AuditTrail WithCommen ts(trackin gList));
  500                             }
  501                    }
  502                    retu rn createR esponseWra pper(wrapp er);
  503           }
  504  
  505           /* *
  506            *  Gets the  requests b y UID.
  507            *
  508            *  @param ui d     The  uid.
  509            *  @return R esponseWra pper This  returns Re sponseWrap per.
  510            * /
  511           @O verride
  512           pu blic Respo nseWrapper   getReque stsByUID(S tring uid)  {
  513                    logg er.info("B usinessSer vice: get  Request by  User:" +  uid);
  514                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  515                    List <Request>  requestLis t = getReq uestServic e().getReq uestsByUID (uid);
  516                    requ estList =  this.filte rRequestLi st(request List, uid) ;
  517                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  518                    wrap per.setRes ponse(requ estList);
  519                    retu rn createR esponseWra pper(wrapp er);
  520           }
  521  
  522           /* *
  523            *  Gets the  requests b y data man agers.
  524            *
  525            *  @param ui d    The u id.
  526            *  @return R esponseWra pper This  returns Re sponseWrap per.
  527            * /
  528           @O verride
  529           pu blic Respo nseWrapper   getReque stsByDataM anagers(St ring uid)  {
  530                    logg er.info("B usinessSer vice: get  Request by   Data Man agers");
  531                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  532                    List <Request>  requestLis t = getReq uestServic e().getReq uestsDataM anagers(ui d);
  533                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  534                    wrap per.setRes ponse(requ estList);
  535                    retu rn createR esponseWra pper(wrapp er);
  536           }
  537  
  538           /* *
  539            *  Gets the  requests b y data sou rce manage rs.
  540            *
  541            *  @param ui d The uid.
  542            *  @return R esponseWra pper This  returns Re sponseWrap per.
  543            * /
  544           @O verride
  545           pu blic Respo nseWrapper  getReques tsDataSour ceManagers (String ui d) {
  546                    logg er.info("B usinessSer vice: get  Request by  Data Sour ce Manager s");
  547                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  548                    List <Request>  requestLis t = getReq uestServic e().getReq uestsDataS ourceManag ers(uid);
  549                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  550                    wrap per.setRes ponse(requ estList);
  551                    retu rn createR esponseWra pper(wrapp er);
  552           }
  553           
  554           /* *
  555            *  Filter re quest list .
  556            *
  557            *  @param re questList
  558            *              The requ estList.
  559            *  @param ui d   The ui d.
  560            *  @return L ist<Reques t> This re turns filt eredReques tList.
  561            * /
  562           pr ivate List <Request>  filterRequ estList(Li st<Request > requestL ist, Strin g uid) {
  563                    List <Request>  filteredRe questList  = new Arra yList<Requ est>();
  564  
  565                    for  (Request r equest : r equestList ) {
  566                             if (!( !StringUti ls.equalsI gnoreCase( request.ge tCreatedBy (), uid)
  567                                               && StringU tils.equal sIgnoreCas e(request. getStatusD escription (), "Draft "))) {
  568                                      filtered RequestLis t.add(requ est);
  569                             }
  570                    }
  571                    retu rn filtere dRequestLi st;
  572           }
  573  
  574           /* *
  575            *  Gets the  all reques ts.
  576            *
  577            *  @return R esponseWra pper This  returns Re sponseWrap per.
  578            * /
  579           @O verride
  580           pu blic Respo nseWrapper   getAllRe quests() {
  581                    logg er.info("B usinessSer vice: get  all Reques ts");
  582                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  583                    List <Request>  requestLis t = getReq uestServic e().getAll Requests() ;
  584                    logg er.info("G ot Request s count:"  + requestL ist.size() );
  585                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  586                    wrap per.setRes ponse(requ estList);
  587                    retu rn createR esponseWra pper(wrapp er);
  588           }
  589  
  590           /* *
  591            *  Gets the  all reques ts by stud y approval .
  592            *
  593            *  @param st udyApprova lId The st udyApprova lId.
  594            *  @return R esponseWra pper This  returns Re sponseWrap per.
  595            * /
  596           @O verride
  597           pu blic Respo nseWrapper   getAllRe questsBySt udyApprova l(int stud yApprovalI d) {
  598                    logg er.info("B usinessSer vice: getA llRequests ByStudyApp roval:" +  studyAppro valId);
  599                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  600                    List <Request>  requestLis t = getReq uestServic e().getAll RequestsBy StudyAppro val(studyA pprovalId) ;
  601                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  602                    wrap per.setRes ponse(requ estList);
  603                    retu rn createR esponseWra pper(wrapp er);
  604                    
  605           }
  606  
  607           /* *
  608            *  Gets the  all reques ts by stau s.
  609            *
  610            *  @param st atus  The  status.
  611            *  @return R esponseWra pper This  returns Re sponseWrap per.
  612            * /
  613           @O verride
  614           pu blic Respo nseWrapper   getAllRe questsBySt aus(String  status) {
  615                    logg er.info("B usinessSer vice: get  all Reques ts by Stat us:" + sta tus);
  616                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  617                    List <Request>  requestLis t = getReq uestServic e().getAll RequestsBy Staus(stat us);
  618                    requ estList =  BusinessHe lper.prepa reRequestR esponsePay load(reque stList);
  619                    wrap per.setRes ponse(requ estList);
  620                    retu rn createR esponseWra pper(wrapp er);
  621           }
  622  
  623           /* *
  624            *  Submit or  modify.
  625            *
  626            *  @param re quest    T he request .
  627            *  status
  628            * /
  629           @O verride
  630           pu blic Respo nseWrapper   submitOr Modify(Req uest reque st) {
  631                    logg er.info("B usinessSer vice: Sumb it/Modify  Request");
  632                    retu rn this.cr eateReques t(request) ;
  633           }
  634  
  635           /* *
  636            *  This meth od is used  to Persis t an entit iy.
  637            *
  638            *  @param id  The id.
  639            *  @param ch angeReques tIn The ch angeReques tIn.
  640            *  @param op eration Th e operatio n.
  641            *  @return R esponseWra pper This  returns wr apper.
  642            * /
  643           @O verride
  644           pu blic Respo nseWrapper  persist(i nt id, Req uest chang eRequestIn , String o peration)  {
  645                    logg er.info("B usinessSer vice: Pers isting: "  + operatio n);
  646                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  647                    Requ est change Request =  new Reques t();
  648                    if ( StringUtil s.equalsIg noreCase(o peration,  "Update")  || StringU tils.equal sIgnoreCas e(operatio n, "Submit ted")) {
  649                             change Request =  BusinessHe lper.handl eRequestPa yload(chan geRequestI n);
  650                    }
  651                    Requ est databa seRequest  = requestS ervice.get RequestsBy Id(id);
  652  
  653                    if ( databaseRe quest == n ull) {
  654                             change Request.se tId(id);
  655                             wrappe r.setRespo nse(change Request);
  656                             wrappe r.setMessa ge("No suc h request  found in d atabase");
  657                             wrappe r.setSucce ss(false);
  658                             return  wrapper;
  659                    }
  660  
  661                    Stri ng status  = StringUt ils.trim(d atabaseReq uest.getSt atusDescri ption());
  662  
  663                    if ( StringUtil s.equalsIg noreCase(s tatus, "Re jected"))  {
  664                             wrappe r.setRespo nse(change Request);
  665                             wrappe r.setMessa ge("You ca n't submit  this requ est.");
  666                             wrappe r.setSucce ss(false);
  667                             return  wrapper;
  668                    }
  669  
  670                    if ( !StringUti ls.equals( operation,  "Update") )
  671                             change Request.se tStatusDes cription(o peration);
  672  
  673                    if ( changeRequ est.getPro cessId() = = 0)
  674                             change Request.se tProcessId (databaseR equest.get ProcessId( ));
  675                    
  676                    if ( changeRequ est.getSou rce() == n ull)
  677                             change Request.se tSource(da tabaseRequ est.getSou rce());
  678                    
  679                    if ( changeRequ est.getStu dyApproval () == null )
  680                             change Request.se tStudyAppr oval(datab aseRequest .getStudyA pproval()) ;
  681                    
  682                    if ( changeRequ est.getReq uestType()  == null)
  683                             change Request.se tRequestTy pe(databas eRequest.g etRequestT ype());
  684  
  685                    if ( StringUtil s.isBlank( changeRequ est.getSta tusDescrip tion()))
  686                             change Request.se tStatusDes cription(d atabaseReq uest.getSt atusDescri ption());
  687  
  688                    if ( StringUtil s.isBlank( changeRequ est.getTit le()))
  689                             change Request.se tTitle(dat abaseReque st.getTitl e());
  690  
  691                    if ( StringUtil s.isBlank( changeRequ est.getDes cription() ))
  692                             change Request.se tDescripti on(databas eRequest.g etDescript ion());
  693  
  694                    chan geRequest. setModifie dOn(new Da te());
  695                    chan geRequest. setModifie dBy(change RequestIn. getCreated By());
  696  
  697                    chan geRequest. setCreated By(databas eRequest.g etCreatedB y());
  698                    chan geRequest. setCreated On(databas eRequest.g etCreatedO n());
  699                    chan geRequest. setApprove rId(databa seRequest. getApprove rId());
  700  
  701                    chan geRequest. setId(id);
  702                    
  703                    if ( changeRequ estIn.getC omments()  == null) {
  704                             change Request.se tComments( StringUtil s.EMPTY);
  705                    } el se {
  706                             change Request.se tComments( changeRequ estIn.getC omments()) ;
  707                    }
  708                    bool ean status CompleteWo rkflowProc ess = this .completeW orkflowPro cess(id, o peration,  changeRequ est);
  709  
  710                    if ( !statusCom pleteWorkf lowProcess ) {
  711                             List<R equest> re questList  = Business Helper.pre pareReques tResponseP ayload(Arr ays.asList (changeReq uest));
  712                             wrappe r.setRespo nse(reques tList.get( 0));
  713                             wrappe r.setSucce ss(false);
  714                             wrappe r.setMessa ge(
  715                                               operation  + " failed . Error oc cured on t he workflo w. Please  contact sy stem admin istrator.  Id#" + id) ;
  716                         return wra pper;
  717                    }
  718  
  719                    UUID  uuid = UU ID.randomU UID();
  720                    chan geRequest. setTaskId( uuid.toStr ing());
  721  
  722                    int  submitOrMo difyId = r equestServ ice.submit OrModify(c hangeReque st);
  723  
  724                    if ( submitOrMo difyId > 0 ) {
  725                             wrappe r = this.g etRequestB yID(submit OrModifyId );
  726                             wrappe r.setSucce ss(true);
  727                             wrappe r.setMessa ge(null);
  728                             preser veHistory( requestSer vice.getRe questsById (submitOrM odifyId));
  729                             if (!S tringUtils .isBlank(c hangeReque st.getComm ents())) {
  730                                      // Save  Comments f or decline s in Comme ntHistory
  731                                      CommentH istory com mentHistor y = new Co mmentHisto ry();
  732                                      commentH istory.set Comments(c hangeReque st.getComm ents());
  733                                      Request  request =  getRequest Service(). getRequest sById(subm itOrModify Id);
  734  
  735                                      int stat usId = get LookUpServ ice().getS tatusId(re quest.getS tatusDescr iption());
  736  
  737                                      Workflow Status wor kflowStatu s = new Wo rkflowStat us();
  738                                      workflow Status.set Id(statusI d);
  739                                      commentH istory.set WorkflowSt atus(workf lowStatus) ;
  740                                      commentH istory.set Request(re quest);
  741                                      commentH istory.set CreatedBy( changeRequ est.getMod ifiedBy()) ;
  742                                      commentH istory.set Type("acti on");
  743                                      commentH istory.set TaskId(uui d.toString ());
  744                                      getComme ntHistoryS ervice().s ubmitOrMod ify(commen tHistory);
  745                             }
  746                    } el se {
  747                             List<R equest> re questList  = Business Helper.pre pareReques tResponseP ayload(Arr ays.asList (changeReq uest));
  748  
  749                             wrappe r.setRespo nse(reques tList.get( 0));
  750                             wrappe r.setSucce ss(false);
  751                             wrappe r.setMessa ge("Unable  to create  Request") ;
  752                    }
  753                    retu rn wrapper ;
  754           }
  755  
  756           /* *
  757            *  Complete  workflow p rocess.
  758            *
  759            *  @param re questId Th e requestI d.
  760            *  @param op eration Th e operatio n.
  761            *  @param ch angeReques t The chan geRequest.
  762            *  @return b oolean Thi s returns  true, if s uccessful.
  763            * /
  764           pr ivate bool ean comple teWorkflow Process(in t requestI d, String  operation,  Request c hangeReque st) {
  765                    bool ean succes s = true;
  766           
  767                    Stri ng comment s = change Request.ge tComments( );
  768                    if ( comments = = null)
  769                             commen ts = Strin gUtils.EMP TY;
  770  
  771                    List <EmailDeta ils> email Details =  new ArrayL ist<EmailD etails>();
  772                             
  773                    Stri ng request orId=null;
  774                    Stri ng approve rId=null;
  775                             
  776                    Requ est reques t = getReq uestServic e().getReq uestsById( requestId) ;
  777                             
  778                    Requ estType re questType  = getReque stService( ).getReque stType(req uest.getRe questType( ).getId()) ;
  779                    Sour ce source  = getReque stService( ).getSourc e(request. getSource( ).getId()) ;
  780                    
  781                    User s requeste rUsers = u serManagem entService .getUserDe tailsByEma il(request .getCreate dBy());
  782                    User s approver Users = us erManageme ntService. getUserDet ailsByEmai l(requeste rUsers.get Approver() );
  783                    
  784                    User s anyAppro verUsers=n ull;
  785                    if ( !StringUti ls.isBlank (changeReq uest.getMo difiedBy() ))
  786                     any ApproverUs ers = user Management Service.ge tUserDetai lsByEmail( changeRequ est.getMod ifiedBy()) ;
  787                    
  788           
  789                    Stri ng status  = request. getStatusD escription ();
  790                    Stud yApproval  studyAppro val = getS tudyApprov alService( ).getStudy ApprovalsB yID(reques t.getStudy Approval() .getId());
  791           
  792                    if ( approverUs ers == nul l) {
  793                             approv erId = Str ingUtils.E MPTY;
  794                    } el se {
  795                             if (!S tringUtils .isBlank(a pproverUse rs.getEmai lId()))
  796                                      approver Id = appro verUsers.g etEmailId( );
  797                    }
  798  
  799                    if ( requesterU sers == nu ll) {
  800                             reques torId = St ringUtils. EMPTY;
  801                    } el se {
  802                             if (!S tringUtils .isBlank(r equesterUs ers.getEma ilId()))
  803                                      requesto rId = requ esterUsers .getEmailI d();
  804                    }
  805                    
  806                    
  807                    JSON Object jso n = new JS ONObject() ;
  808                    json .put(Commo nEnum.EMAI L_OPERATIO N.getText( ), operati on);
  809                    json .put(Commo nEnum.EMAI L_REQUESTO R_ID.getTe xt(), requ estorId);
  810                    json .put(Commo nEnum.EMAI L_APPROVER _DECISION. getText(),  status);
  811                    json .put(Commo nEnum.EMAI L_FULFILLM ENT_DECISI ON.getText (), "");
  812                    json .put(Commo nEnum.EMAI L_RESULT_A CCEPTANCE_ DECISION.g etText(),  "");
  813                    json .put(Commo nEnum.EMAI L_APPROVER _ID.getTex t(), appro verId);
  814                    json .put(Commo nEnum.EMAI L_CC_USERS .getText() ,"");
  815                    
  816                    
  817                                      
  818                    Stri ng pid = S tring.valu eOf(reques t.getProce ssId());
  819           
  820                    if ( StringUtil s.equals(o peration,  CommonEnum .REQUEST_S UBMIT.getT ext())) {
  821                             
  822                                              
  823                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  824                             
  825                             String  emailReci pient=null ;
  826                             
  827                             if (ap proverUser s == null)  {
  828                                      emailRec ipient = S tringUtils .EMPTY;
  829                             } else  {
  830                                      if (!Str ingUtils.i sBlank(app roverUsers .getEmailI d()))
  831                                               emailRecip ient = app roverUsers .getEmailI d();
  832                             }
  833                             
  834                                                       
  835                             json.p ut(CommonE num.EMAIL_ APPROVER_D ECISION.ge tText(), " ");
  836  
  837                             String  emailSubj ect = "ACT ION REQUIR ED: Submit ted Reques t - " + re questId +  " - " + re quest.getT itle();
  838                             String  emailBody  = "A new  data reque st " + req uestId + "  has been  Submitted  by " + req uestorId +  " for rev iew. ";
  839                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  840                             emailD etails.add (emailDet) ;
  841  
  842                             emailS ender = Co mmonEnum.E MAIL_NO_RE PLY_SENDER .getText() ;
  843                             emailR ecipient =  requester Users.getE mailId();
  844                             
  845                             emailS ubject = " Submitted  Request -  " + reques tId + " -  " + reques t.getTitle ();
  846                             emailB ody = "You r new data  request "  + request Id + " has  been Subm itted to "  + approve rId + " fo r review.  ";
  847                             emailD et = new E mailDetail s(emailSen der, email Recipient,   emailSub ject, emai lBody,Stri ngUtils.EM PTY);
  848                             emailD etails.add (emailDet) ;
  849                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  850  
  851                             try {
  852                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get CreatedBy( ), json);
  853                             } catc h (Excepti on e) {
  854                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Reques t Submit.  Reason: "  + e.getMes sage() + "  ", e);
  855                                      success  = false;
  856                             }
  857                    }
  858  
  859                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.REQU EST_RETURN ED.getText ())) {
  860                             
  861                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  862                             String  emailReci pient =  r equesterUs ers.getEma ilId();
  863                             
  864  
  865                             json.p ut(CommonE num.EMAIL_ APPROVER_D ECISION.ge tText(), " Return");
  866  
  867                             String  emailSubj ect = "Ret urned Requ est - " +  requestId  + " - " +  request.ge tTitle();
  868                             String  emailBody  = "Your d ata reques t " + requ estId + "   has been  Returned b y " + appr overId + S ystem.line Separator( );
  869  
  870                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  871                             
  872  
  873                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  874                             emailD etails.add (emailDet) ;
  875                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  876  
  877                             try {
  878                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  879                             } catc h (Excepti on e) {
  880                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Reques t Returned . Reason:  " + e.getM essage() +  " ", e);
  881                                      success  = false;
  882                             }
  883                    }
  884  
  885                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.REQU EST_DENIED .getText() )) {
  886                             
  887                                              
  888                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  889                             String  emailReci pient =  r equesterUs ers.getEma ilId();
  890                             json.p ut(CommonE num.EMAIL_ APPROVER_D ECISION.ge tText(), " Reject");
  891  
  892                             String  emailSubj ect = "Req uest Denie d  - " + r equestId +  " - " + r equest.get Title();
  893                             String  emailBody  = "Your d ata reques t " + requ estId + "   has been  Denied by  " + approv erId + "."
  894                                               + System.l ineSeparat or();
  895  
  896                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  897  
  898                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  899                             emailD etails.add (emailDet) ;
  900                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  901  
  902                             try {
  903                                      activiti Service.cl aimAndComp leteHumanT ask(pid, a nyApprover Users == n ull ? Stri ngUtils.EM PTY : anyA pproverUse rs.getEmai lId(), jso n);
  904                             } catc h (Excepti on e) {
  905                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Reques t Denied.  Reason: "  + e.getMes sage() + "  ", e);
  906                                      success  = false;
  907                             }
  908  
  909                    }
  910  
  911                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.REQU EST_SENT.g etText()))  {
  912                             
  913                                      
  914                             String  datasourc emanagers= genisisPro perties.ge tDatasourc emanagers( );
  915                             
  916                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  917                             String  emailReci pient = St ringUtils. EMPTY;
  918                             String Builder st ringBuilde r = new St ringBuilde r("");
  919                             
  920                             String  result[]  = StringUt ils.split( datasource managers,  "\\,");
  921                             for (i nt i = 0;  i < result .length; i ++) {
  922  
  923                                      if (!Str ingUtils.i sBlank(res ult[i])) {
  924                                               if (i == 0 ) {
  925                                                       em ailRecipie nt = resul t[i];
  926                                               } else {
  927                                                       if  (i < resu lt.length  - 1)
  928                                                                stri ngBuilder. append(res ult[i]).ap pend(",");
  929                                                       el se
  930                                                                stri ngBuilder. append(res ult[i]);
  931                                               }
  932                                      }
  933                             }
  934                             String  cc;
  935                             if (St ringUtils. isBlank(st ringBuilde r.toString ()))
  936                                      cc = Str ingUtils.E MPTY;
  937                             else
  938                                      cc = str ingBuilder .toString( );
  939                             
  940                             json.p ut(CommonE num.EMAIL_ APPROVER_D ECISION.ge tText(), " Sent");
  941  
  942                             String  emailSubj ect = "ACT ION REQUIR ED: Genisi s Data Req uest - " +  requestId  + " - " +  request.g etTitle();
  943                             String  emailBody  = "A new  " + reques tType.getD escription () + " dat a request  " + reques tId + " ha s been rev iewed by "
  944                                               + approver Id + " and  determine d to have  sufficient  informati on for dat a research . "
  945                                               + System.l ineSeparat or();
  946                             emailB ody = emai lBody + "R equest ID:  " + reque stId + Sys tem.lineSe parator();
  947                             emailB ody = emai lBody + "R equest Typ e: " + req uestType.g etDescript ion() + Sy stem.lineS eparator() ;
  948                             emailB ody = emai lBody + "D ata Source : " + sour ce.getDesc ription()  + System.l ineSeparat or();
  949                             emailB ody = emai lBody + "A pproved St udy: " + s tudyApprov al.getDesc ription()  + System.l ineSeparat or();
  950                             emailB ody = emai lBody + "D escription : " + requ est.getDes cription()  + System. lineSepara tor();
  951                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  952  
  953                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,cc  );
  954                             emailD etails.add (emailDet) ;
  955  
  956                             emailS ender = Co mmonEnum.E MAIL_NO_RE PLY_SENDER .getText() ;
  957                             emailR ecipient =   requeste rUsers.get EmailId();
  958                             
  959                             emailS ubject = " Submitted  Request -  " + reques tId + " -  Accepted";
  960                             emailB ody = "You r new data  request "  + request Id + " has  been Acce pted and s ent to " +  source.ge tDescripti on()
  961                                               + " for re search.";
  962                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  963                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  964                             emailD etails.add (emailDet) ;
  965                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  966                             try {
  967                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  968                             } catc h (Excepti on e) {
  969                                      logger.e rror(
  970                                                       "U nable to C laim and C omplete Ta sk for Req uest Sent  to VINCI.  Reason: "  + e.getMes sage() + "  ", e);
  971                                      success  = false;
  972                             }
  973  
  974                    }
  975  
  976                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.REQU EST_NOT_AC CEPTED.get Text())) {
  977                    
  978                             
  979                             String   emailSen der = Comm onEnum.EMA IL_NO_REPL Y_SENDER.g etText();
  980                             String   emailRec ipient =   requesterU sers.getEm ailId();
  981                             
  982                             
  983                             json.p ut(CommonE num.EMAIL_ FULFILLMEN T_DECISION .getText() , "Unfulfi lled");
  984  
  985                             String            emailSubje ct = "Geni sis Data R equest Can not Be Ful filled  -  " + reques tId + " -  " + reques t.getTitle ();
  986                             String   emailBod y = Common Enum.EMAIL _YOUR_DATE _REQUEST.g etText() +  requestId  + " Canno t Be Fulfi lled.  " +  System.li neSeparato r();
  987  
  988  
  989                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  990  
  991                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  992                             emailD etails.add (emailDet) ;
  993                             
  994                             emailR ecipient=  request.ge tModifiedB y();
  995                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  996                             emailD etails.add (emailDet) ;
  997                             
  998                             
  999                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  1000  
  1001                             try {
  1002                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  1003                             } catc h (Excepti on e) {
  1004                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Reques t Not Acce pted by VI NCI. Reaso n: "
  1005                                                       +  e.getMessa ge() + " " , e);
  1006                                      success  = false;
  1007                             }
  1008  
  1009                    }
  1010  
  1011                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.REQU EST_ACCEPT ED.getText ())) {
  1012                             
  1013                             
  1014                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  1015                             String  emailReci pient =  r equesterUs ers.getEma ilId();
  1016                             
  1017                             json.p ut(CommonE num.EMAIL_ FULFILLMEN T_DECISION .getText() , "Fulfill ed");
  1018                             json.p ut("cc_use rs", "");
  1019  
  1020                             String  emailSubj ect = "Gen isis Data  Request -  " + reques tId + " -  " + reques t.getTitle ();
  1021                             String  emailBody  = CommonE num.EMAIL_ YOUR_DATE_ REQUEST.ge tText() +  requestId  + " has be en Accepte d for revi ew.  " + S ystem.line Separator( );
  1022  
  1023                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  1024  
  1025                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  1026                             emailD etails.add (emailDet) ;
  1027                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  1028                             
  1029                             
  1030                             emailR ecipient=  request.ge tModifiedB y();
  1031                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  1032                             emailD etails.add (emailDet) ;
  1033                                      
  1034  
  1035                             try {
  1036                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  1037                             } catc h (Excepti on e) {
  1038                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Reques t Accepted  by VINCI.  Reason: "
  1039                                                       +  e.getMessa ge() + " " , e);
  1040                                      success  = false;
  1041                             }
  1042  
  1043                    }
  1044  
  1045                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.RESU LTS_DELIVE RED.getTex t())) {
  1046                             
  1047                             
  1048                       L ist<Reques tHistory>  requestHis tory=getRe questServi ce().getRe questHisto ryByReques tIdAndStat us(request .getId(),  CommonEnum .REQUEST_S ENT.getTex t());
  1049                             json.p ut("cc_use rs", "vinc i.datasour ce@gmail.c om");
  1050                                              
  1051                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  1052                             String  emailReci pient =  r equestHist ory.get(0) .getModifi edBy();
  1053                             
  1054                             String  emailSubj ect = "ACT ION REQUIR ED: Genisi s Data Req uest  - "  + requestI d + " - "  + request. getTitle() ;
  1055                             String  emailBody  = "The re sults from  the resea rch for  "  + request Id
  1056                                               + " have b een Comple ted and re ady for yo ur review.   " + Syst em.lineSep arator();
  1057                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  1058                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  1059                             emailD etails.add (emailDet) ;
  1060                             
  1061                             
  1062                             emailS ender = Co mmonEnum.E MAIL_NO_RE PLY_SENDER .getText() ;
  1063                             emailR ecipient =   requeste rUsers.get EmailId();
  1064                             emailS ubject = " Genisis Da ta Request    - " + r equestId +  " - " + r equest.get Title();
  1065                             emailB ody = Comm onEnum.EMA IL_YOUR_DA TE_REQUEST .getText()  + request Id + " res ults were  Delivered  to " + app roverId +  " for revi ew.  "
  1066                                               + System.l ineSeparat or();
  1067  
  1068                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  1069                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  1070                             emailD etails.add (emailDet) ;
  1071  
  1072                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  1073  
  1074                             try {
  1075                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  1076                             } catc h (Excepti on e) {
  1077                                      logger.e rror(
  1078                                                       "U nable to C laim and C omplete Ta sk for Res ults Deliv ered. Reas on: " + e. getMessage () + " ",  e);
  1079                                      success  = false;
  1080                             }
  1081  
  1082                    }
  1083  
  1084                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.RESU LTS_NOT_AC CEPTED.get Text())) {
  1085                             
  1086                    
  1087                             json.p ut(CommonE num.EMAIL_ RESULT_ACC EPTANCE_DE CISION.get Text(), "R eject");
  1088                              List< RequestHis tory> requ estHistory =getReques tService() .getReques tHistoryBy RequestIdA ndStatus(r equest.get Id(), Comm onEnum.RES ULTS_DELIV ERED.getTe xt());
  1089                             
  1090                             
  1091                              Strin g emailSen der = Comm onEnum.EMA IL_NO_REPL Y_SENDER.g etText();
  1092                              Strin g emailRec ipient =   requesterU sers.getEm ailId();
  1093                              Strin g emailSub ject = "Re sults Not   Accepted    - " + re questId +  " - " + re quest.getT itle();
  1094                              Strin g emailBod y = "The r esults fro m the rese arch of  "  + request Id + " hav e been rev iewed and  Not Accept ed by "
  1095                                               + approver Id + ".  "  + System. lineSepara tor();
  1096                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  1097                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  1098                             emailD etails.add (emailDet) ;
  1099                             
  1100                             
  1101                             emailS ender = Co mmonEnum.E MAIL_NO_RE PLY_SENDER .getText() ;
  1102                             emailR ecipient=  requestHis tory.get(0 ).getModif iedBy();
  1103                             
  1104                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  1105                             emailD etails.add (emailDet) ;
  1106  
  1107                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  1108  
  1109                             try {
  1110                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  1111                             } catc h (Excepti on e) {
  1112                                      logger.e rror(
  1113                                                       "U nable to C laim and C omplete Ta sk for Res ults Not A ccepted. R eason: " +  e.getMess age() + "  ", e);
  1114                                      success  = false;
  1115                             }
  1116  
  1117                    }
  1118  
  1119                    else  if (Strin gUtils.equ als(operat ion, Commo nEnum.RESU LTS_ACCEPT ED.getText ())) {
  1120                                              
  1121                              List< RequestHis tory> requ estHistory =getReques tService() .getReques tHistoryBy RequestIdA ndStatus(r equest.get Id(), Comm onEnum.RES ULTS_DELIV ERED.getTe xt());
  1122                                      
  1123                             json.p ut(CommonE num.EMAIL_ RESULT_ACC EPTANCE_DE CISION.get Text(), "A ccept");
  1124                             
  1125  
  1126                             String  emailSend er = Commo nEnum.EMAI L_NO_REPLY _SENDER.ge tText();
  1127                             String  emailReci pient =  r equesterUs ers.getEma ilId();
  1128                             String  emailSubj ect = "Res ults  Acce pted    -  " + reques tId + " -  " + reques t.getTitle ();
  1129                             String  emailBody  = "The re sults from  the resea rch of  "  + requestI d + "  hav e been rev iewed and  Accepted b y  "
  1130                                               + approver Id + ".  "  + System. lineSepara tor();
  1131                             emailB ody = emai lBody + Co mmonEnum.E MAIL_COMME NTS.getTex t() + comm ents;
  1132                             EmailD etails ema ilDet = ne w EmailDet ails(email Sender, em ailRecipie nt, emailS ubject, em ailBody,St ringUtils. EMPTY);
  1133                             emailD etails.add (emailDet) ;
  1134                             
  1135                             emailS ender = Co mmonEnum.E MAIL_NO_RE PLY_SENDER .getText() ;
  1136                             emailR ecipient=  requestHis tory.get(0 ).getModif iedBy();
  1137                             
  1138                             emailD et = new E mailDetail s(emailSen der, email Recipient,  emailSubj ect, email Body,Strin gUtils.EMP TY);
  1139                             emailD etails.add (emailDet) ;
  1140  
  1141                             json.p ut(CommonE num.EMAIL_ LIST.getTe xt(), emai lDetails);
  1142  
  1143                             try {
  1144                                      activiti Service.cl aimAndComp leteHumanT ask(pid, r equest.get ApproverId (), json);
  1145                             } catc h (Excepti on e) {
  1146                                      logger.e rror("Unab le to Clai m and Comp lete Task  for Result s Accepted . Reason:  " + e.getM essage() +  " ", e);
  1147                                      success  = false;
  1148                             }
  1149                    }
  1150                    logg er.info("C ompleteWor kflowProce ss:    Suc cess statu s: " + suc cess);
  1151                    retu rn success ;
  1152           }
  1153  
  1154           /* *
  1155            *  Preserve  history.
  1156            *
  1157            *  @param re quest
  1158            *              The requ est.
  1159            * /
  1160           pr ivate void  preserveH istory(Req uest reque st) {
  1161           
  1162                    
  1163  
  1164                    Requ estHistory  requestHi story = ne w RequestH istory(0,  request, r equest.get ProcessId( ), request .getTitle( ),
  1165                                      request. getDescrip tion(),  
  1166                                      request. getStatusD escription (), reques t.getReque stType().g etId(), re quest.getS ource().ge tId(),
  1167                                 re quest.getS tudyApprov al().getId (), reques t.getCreat edOn(),
  1168                                      request. getModifie dOn(), req uest.getCr eatedBy(),  request.g etModified By(), requ est.getApp roverId(),
  1169                                      request. getTaskId( ));
  1170  
  1171                    int  returnId =  getReques tService() .submitOrM odify(requ estHistory );
  1172                    if ( returnId >  0) {
  1173  
  1174                             logger .info(requ estHistory .getReques t().getId( ) + " with  status "  + requestH istory.get StatusDesc ription()
  1175                                               + " added  to the his tory succe ssfully!!" );
  1176                    } el se {
  1177                             logger .warn(requ estHistory .getReques t().getId( ) + " with  status "  + requestH istory.get StatusDesc ription()
  1178                                               + " could  not be add ed to the  history.") ;
  1179                    }
  1180  
  1181           }
  1182  
  1183           /* *
  1184            *  Creates t he comment  history.
  1185            *
  1186            *  @param co mmentHisto ry
  1187            *              The comm entHistory .
  1188            *  @return R esponseWra pper This  returns wr apper.
  1189            * /
  1190           @O verride
  1191           pu blic Respo nseWrapper   createCo mmentHisto ry(Comment History co mmentHisto ry) {
  1192                    logg er.info("B usinessSer vice:  cre ateComment History");
  1193                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  1194                    int  statusId =  getLookUp Service(). getStatusI d(commentH istory.get Status());
  1195                    Work flowStatus  workflowS tatus = ne w Workflow Status();
  1196                    work flowStatus .setId(sta tusId);
  1197  
  1198                    Requ est reques t = getReq uestServic e().getReq uestsById( commentHis tory.getRe questId()) ;
  1199                    comm entHistory .setWorkfl owStatus(w orkflowSta tus);
  1200                    comm entHistory .setReques t(request) ;
  1201  
  1202                    comm entHistory .setTaskId (request.g etTaskId() );
  1203  
  1204                    int  id = getCo mmentHisto ryService( ).submitOr Modify(com mentHistor y);
  1205  
  1206                    if ( id > 0) {
  1207                    
  1208                             Commen tHistory r eturnComme ntHistoryR esp = getC ommentHist oryService ().getComm entHistory ByCommentI d(id);
  1209                             return CommentHis toryResp.s etRequestI d(commentH istory.get RequestId( ));
  1210                             return CommentHis toryResp.s etStatus(c ommentHist ory.getSta tus());
  1211                             wrappe r.setRespo nse(return CommentHis toryResp);
  1212  
  1213                             wrappe r.setSucce ss(true);
  1214                             wrappe r.setMessa ge(null);
  1215                    } el se {
  1216                             List<C ommentHist ory> comme ntHistoryL ist = Busi nessHelper
  1217                                               .prepareCo mmentHisto ryResponse Payload(Ar rays.asLis t(commentH istory));
  1218                             wrappe r.setRespo nse(commen tHistoryLi st.get(0)) ;
  1219                             wrappe r.setSucce ss(false);
  1220                             wrappe r.setMessa ge("Unable  to create  Comment H istory");
  1221                    }
  1222                    retu rn wrapper ;
  1223           }
  1224  
  1225           /* *
  1226            *  Gets the  audit trai l with com ments.
  1227            *
  1228            *  @param tr ackingList  The track ingList.
  1229            *  @return L ist<gov.va .genisis2. vo.Request History> T his return s returnRe questHisto ry.
  1230            * /
  1231           pr ivate List <gov.va.ge nisis2.vo. RequestHis tory> getA uditTrailW ithComment s(List<Req uestHistor y> trackin gList) {
  1232                    List <gov.va.ge nisis2.vo. RequestHis tory> retu rnRequestH istory = n ew ArrayLi st<gov.va. genisis2.v o.RequestH istory>();
  1233                    for  (RequestHi story requ estHistory  : trackin gList) {
  1234  
  1235                             List<C ommentHist ory> comme ntHistory  = getComme ntHistoryS ervice().g etCommentH istoryByRe questIdSta tusId(
  1236                                               requestHis tory.getRe quest().ge tId(), req uestHistor y.getTaskI d());
  1237  
  1238                             gov.va .genisis2. vo.Request History el ement = ne w gov.va.g enisis2.vo .RequestHi story();
  1239                             elemen t.setComme ntHistory( commentHis tory);
  1240                             elemen t.setCreat edBy(reque stHistory. getCreated By());
  1241                             elemen t.setCreat edOn(reque stHistory. getCreated On());
  1242                             elemen t.setStatu sDescripti on(request History.ge tStatusDes cription() );
  1243                             elemen t.setTitle (requestHi story.getT itle());
  1244                             elemen t.setDescr iption(req uestHistor y.getDescr iption());
  1245                             elemen t.setModif iedBy(requ estHistory .getModifi edBy());
  1246                             elemen t.setModif iedOn(requ estHistory .getModifi edOn());
  1247  
  1248                             return RequestHis tory.add(e lement);
  1249  
  1250                    }
  1251                    retu rn returnR equestHist ory;
  1252           }
  1253  
  1254           /* *
  1255            *  Perform t able copy  transfer.
  1256            *
  1257            *  @param js onRequest           T he jsonReq uest.
  1258            *  @param re questId            Th e requestI d.
  1259            *  @return R esponseWra pper This  returns wr apper.
  1260            * /
  1261           @O verride
  1262           pu blic Respo nseWrapper   performT ableCopyTr ansfer(Cop yTableSour ce jsonReq uest, int  requestId)  {
  1263                    logg er.info("B usinessSer vice:  per formTableC opyTransfe r");
  1264                    
  1265                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  1266                    wrap per.setSuc cess(true) ;
  1267                    
  1268           
  1269                    // G et require d properti es
  1270                    Stri ng tcSourc eDataBaseS erverName= copyTableS ource.getT cSourceDat aBaseServe rName();
  1271                    Stri ng tcSourc eDataBaseN ame=copyTa bleSource. getTcSourc eDataBaseN ame();
  1272                    Stri ng sourceS chemaName= jsonReques t.getSourc eSchemaNam e();
  1273                    Stri ng tcDesti nationData BaseServer Name=copyT ableSource .getTcDest inationDat aBaseServe rName();
  1274                    Stri ng tcDesti nationData BaseUserNa me=copyTab leSource.g etTcDestin ationDataB aseUserNam e();
  1275                    Stri ng tcDesti nationData BaseUserPa ssword=cop yTableSour ce.getTcDe stinationD ataBaseUse rPassword( );
  1276                    Stri ng tcDesti nationServ erDataBase Name=copyT ableSource .getTcDest inationSer verDataBas eName();
  1277                    Stri ng destina tionSchema Name=jsonR equest.get Destinatio nSchemaNam e();
  1278                    Stri ng tcManag ementDataB aseServerN ame=copyTa bleSource. getTcManag ementDataB aseServerN ame();
  1279                    Stri ng tcManag ementDataB aseUserNam e=copyTabl eSource.ge tTcManagem entDataBas eUserName( );
  1280                    Stri ng tcManag ementDataB aseUserPas sword=copy TableSourc e.getTcMan agementDat aBaseUserP assword();
  1281                    Stri ng tcManag ementDataB aseSchema= copyTableS ource.getT cManagemen tDataBaseS chema();
  1282                    Stri ng copyTab le = jsonR equest.get TableName( );
  1283                    Stri ng copyTab leScript =  copyTable Source.get CmdFilePat h();
  1284                    Stri ng tcManag ementDataB aseName=co pyTableSou rce.getTcM anagementD ataBaseNam e();
  1285                    Stri ng tcTempo raryDataBa seName=cop yTableSour ce.getTcTe mporaryDat aBaseName( );
  1286                    
  1287                    // C heck for a ll propert ies are pr esent
  1288                       i f (StringU tils.isBla nk(tcSourc eDataBaseS erverName)  || String Utils.isBl ank(tcSour ceDataBase Name)
  1289                             || Str ingUtils.i sBlank(sou rceSchemaN ame) || St ringUtils. isBlank(tc Destinatio nDataBaseS erverName)
  1290                                      || Strin gUtils.isB lank(tcDes tinationDa taBaseUser Name) || S tringUtils .isBlank(t cDestinati onDataBase UserPasswo rd)
  1291                                      || Strin gUtils.isB lank(tcDes tinationSe rverDataBa seName) ||  StringUti ls.isBlank (destinati onSchemaNa me)
  1292                                      || Strin gUtils.isB lank(tcMan agementDat aBaseServe rName) ||  StringUtil s.isBlank( tcManageme ntDataBase UserName)
  1293                                      || Strin gUtils.isB lank(tcMan agementDat aBaseUserP assword) | | StringUt ils.isBlan k(tcManage mentDataBa seSchema)
  1294                                      || Strin gUtils.isB lank(tcMan agementDat aBaseName)  || String Utils.isBl ank(tcTemp oraryDataB aseName)
  1295                                      || Strin gUtils.isB lank(copyT able) || S tringUtils .isBlank(c opyTableSc ript)
  1296                                      ) {
  1297  
  1298                             logger .error("On e or more  properties  in genisi s2.propert ies file s eems blank ");
  1299                             wrappe r.setRespo nse(jsonRe quest);
  1300                             wrappe r.setMessa ge("One or  more prop erties in  genisis2.p roperties  file seems  blank");
  1301                             wrappe r.setSucce ss(false);
  1302                             return  wrapper;
  1303                    }
  1304  
  1305                    File  file = ne w File(cop yTableScri pt);
  1306  
  1307                    // C heck shell  script av ailable on  Linux ser ver
  1308                    if ( !file.isFi le()) {
  1309                             logger .error("Th e file " +  copyTable Script + "  does not  exist");
  1310                             wrappe r.setRespo nse(jsonRe quest);
  1311                             wrappe r.setMessa ge("Copy t able faile d. " + cop yTableScri pt + " doe s not exis t");
  1312                             wrappe r.setSucce ss(false);
  1313                             return  wrapper;
  1314                    }
  1315                    
  1316           /*        IP             GENISISDAT ASOURCE df lt  IP             data_ops g enisis20!7  GENISISDA TADEST dbo   IP             data_ops g enisis20!7  
  1317              dbo vinciT able1,vinc iTable2    */
  1318                    
  1319                    Stri ngBuilder  builder =  new String Builder();
  1320                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1321                    buil der.append (StringUti ls.trim(co pyTableScr ipt)).appe nd('\'');
  1322                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1323                    buil der.append (StringUti ls.trim(tc SourceData BaseServer Name)).app end('\'');
  1324                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1325                    buil der.append (StringUti ls.trim(tc SourceData BaseName)) .append('\ '');
  1326                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1327                    buil der.append (StringUti ls.trim(so urceSchema Name)).app end('\'');
  1328                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1329                    buil der.append (StringUti ls.trim(tc Destinatio nDataBaseS erverName) ).append(' \'');
  1330                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1331                    buil der.append (StringUti ls.trim(tc Destinatio nDataBaseU serName)). append('\' ');
  1332                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1333                    buil der.append (StringUti ls.trim(tc Destinatio nDataBaseU serPasswor d)).append ('\'');
  1334                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1335                    buil der.append (StringUti ls.trim(tc Destinatio nServerDat aBaseName) ).append(' \'');
  1336                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1337                    buil der.append (StringUti ls.trim(de stinationS chemaName) ).append(' \'');
  1338                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1339                    buil der.append (StringUti ls.trim(tc Management DataBaseSe rverName)) .append('\ '');
  1340                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1341                    buil der.append (StringUti ls.trim(tc Management DataBaseUs erName)).a ppend('\'' );
  1342                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1343                    buil der.append (StringUti ls.trim(tc Management DataBaseUs erPassword )).append( '\'');
  1344                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1345                    buil der.append (StringUti ls.trim(tc Management DataBaseNa me)).appen d('\'');
  1346                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1347                    buil der.append (StringUti ls.trim(tc TemporaryD ataBaseNam e)).append ('\'');
  1348                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1349                    buil der.append (StringUti ls.trim(tc Management DataBaseSc hema)).app end('\'');
  1350                    buil der.append (CommonEnu m.SPACE.ge tText()).a ppend('\'' );
  1351                    buil der.append (StringUti ls.trim(co pyTable)). append('\' ');
  1352                    logg er.info("A rguments b eing passe d to DataO ps : " +bu ilder.toSt ring());
  1353                    
  1354                     Str ing[] comm and = new  String[16] ;
  1355                     com mand[0] =  copyTableS cript;
  1356                     com mand[1] =  tcSourceDa taBaseServ erName;
  1357                     com mand[2] =  tcSourceDa taBaseName ;
  1358                     com mand[3] =  sourceSche maName;
  1359                     com mand[4] =  tcDestinat ionDataBas eServerNam e;
  1360                     com mand[5] =  tcDestinat ionDataBas eUserName;
  1361                     com mand[6] =  tcDestinat ionDataBas eUserPassw ord;
  1362                     com mand[7] =  tcDestinat ionServerD ataBaseNam e;
  1363                     com mand[8] =   destinati onSchemaNa me;
  1364                     com mand[9] =  tcManageme ntDataBase ServerName ;
  1365                     com mand[10] =  tcManagem entDataBas eUserName;
  1366                     com mand[11] =  tcManagem entDataBas eUserPassw ord;
  1367                     com mand[12] =  tcManagem entDataBas eName;
  1368                     com mand[13] =  tcTempora ryDataBase Name;
  1369                     com mand[14] =  tcManagem entDataBas eSchema;
  1370                     com mand[15] =  copyTable ;
  1371  
  1372                    Proc ess proces s = null;
  1373                    Buff eredReader  reader =  null;
  1374                    Stri ng line =  StringUtil s.EMPTY;
  1375                    logg er.info( " Table/Copy  arguments : " + Arra ys.toStrin g(command) );
  1376                    
  1377  
  1378                    try  {
  1379                             Runtim e runtime  = Runtime. getRuntime ();
  1380                             proces s = runtim e.exec(com mand);
  1381                             proces s.waitFor( );
  1382                             reader  = new Buf feredReade r(new Inpu tStreamRea der(proces s.getInput Stream())) ;
  1383                             while  ((line = r eader.read Line()) !=  null) {
  1384                                      wrapper. setRespons e(line);
  1385                             }
  1386                             
  1387                             logger .info( "Da taOps  Res ponse: " +  wrapper.g etResponse ());
  1388                    //}  catch (IOE xception |  Interrupt edExceptio n  ex) {
  1389                     } c atch (Exce ption ex)  {
  1390                             logger .error("Er ror occure d while co pying tabl e(s). Reas on: " + ex .getMessag e() + " ",  ex);
  1391                             wrappe r.setRespo nse(jsonRe quest);
  1392                             wrappe r.setMessa ge("Copy T able faile d. Please  contact sy stem admin istrator." );
  1393                             wrappe r.setSucce ss(false);
  1394                    } fi nally {
  1395                             try {
  1396                                      if (proc ess != nul l && proce ss.isAlive ())
  1397                                               process.de stroy();
  1398                                      if (read er != null )
  1399                                               reader.clo se();
  1400                             } catc h (IOExcep tion ex) {
  1401                                      logger.e rror("Erro r occured  while clos ing the re sources. R eason: " +  ex.getMes sage(), ex );
  1402                             }
  1403                    }
  1404                    retu rn wrapper ;
  1405           }
  1406  
  1407           /* *
  1408            *  Gets the  copy table  domains.
  1409            *
  1410            *  @return R esponseWra pper This  returns wr apper.
  1411            * /
  1412           @O verride
  1413           pu blic Respo nseWrapper   getCopyT ableDomain s() {
  1414                    logg er.info("B usinessSer vice: Copy  Table Dom ains");
  1415                    Resp onseWrappe r wrapper  = new Resp onseWrappe r();
  1416                    wrap per.setMes sage("");
  1417                    wrap per.setSuc cess(true) ;
  1418                             
  1419                    Copy TableDomai ns tableDo mains = ne w CopyTabl eDomains(c opyTableDo mains.getS ourceDBNam e(),
  1420                                      copyTabl eDomains.g etDestinat ionDBName( ), copyTab leDomains. getSourceD BServerNam e(),
  1421                                      copyTabl eDomains.g etDestinat ionDBServe rName(), c opyTableDo mains.gets Username() ,
  1422                                      copyTabl eDomains.g etdUsernam e());
  1423                    wrap per.setRes ponse(tabl eDomains);
  1424                    retu rn wrapper ;
  1425           }
  1426  
  1427  
  1428           
  1429           
  1430  
  1431           
  1432  
  1433           /* *
  1434            *  @return t he genisis Properties
  1435            * /
  1436           pu blic Genis isProperti es getGeni sisPropert ies() {
  1437                    retu rn genisis Properties ;
  1438           }
  1439  
  1440           /* *
  1441            *  @param ge nisisPrope rties the  genisisPro perties to  set
  1442            * /
  1443           @A utowired
  1444           pu blic void  setGenisis Properties (GenisisPr operties g enisisProp erties) {
  1445                    this .genisisPr operties =  genisisPr operties;
  1446           }
  1447  
  1448           /* *
  1449            *  @return t he copyTab leSource
  1450            * /
  1451           pu blic CopyT ableSource  getCopyTa bleSource( ) {
  1452                    retu rn copyTab leSource;
  1453           }
  1454  
  1455           /* *
  1456            *  @param co pyTableSou rce the co pyTableSou rce to set
  1457            * /
  1458           pu blic void  setCopyTab leSource(C opyTableSo urce copyT ableSource ) {
  1459                    this .copyTable Source = c opyTableSo urce;
  1460           }
  1461  
  1462           /* *
  1463            *  @param co pyTableDom ains the c opyTableDo mains to s et
  1464            * /
  1465           @A utowired
  1466           pu blic void  setCopyTab leDomains( CopyTableD omains cop yTableDoma ins) {
  1467                    this .copyTable Domains =  copyTableD omains;
  1468           }
  1469  
  1470           /* *
  1471            *  Gets the  copy table  source.
  1472            *
  1473            *  @param co pyTableSou rce the co py table s ource
  1474            *
  1475            * /
  1476           @A utowired
  1477           pu blic void  getCopyTab leSource(C opyTableSo urce copyT ableSource ) {
  1478                    this .copyTable Source = c opyTableSo urce;
  1479           }
  1480  
  1481           /* *
  1482            *  Gets the  look up se rvice.
  1483            *
  1484            *  @return L ookUpServi ce This re turns look UpService.
  1485            * /
  1486           pu blic LookU pService g etLookUpSe rvice() {
  1487                    retu rn lookUpS ervice;
  1488           }
  1489  
  1490           /* *
  1491            *  Sets the  look up se rvice.
  1492            *
  1493            *  @param lo okUpServic e The look UpService.
  1494            * /
  1495           @A utowired
  1496           pu blic void  setLookUpS ervice(Loo kUpService  lookUpSer vice) {
  1497                    this .lookUpSer vice = loo kUpService ;
  1498           }
  1499  
  1500           /* *
  1501            *  Gets the  activiti s ervice.
  1502            *
  1503            *  @return A ctivitiSer vice This  returns ac tiviti ser vice.
  1504            * /
  1505           pu blic Activ itiService  getActivi tiService( ) {
  1506                    retu rn activit iService;
  1507           }
  1508  
  1509           /* *
  1510            *  Sets the  activiti s ervice.
  1511            *
  1512            *  @param ac tivitiServ ice The ac tivitiServ ice.
  1513            * /
  1514           @A utowired
  1515           pu blic void  setActivit iService(A ctivitiSer vice activ itiService ) {
  1516                    this .activitiS ervice = a ctivitiSer vice;
  1517           }
  1518  
  1519           /* *
  1520            *  Gets the  request se rvice.
  1521            *
  1522            *  @return R equestServ ice This r eturns req uestServic e.
  1523            * /
  1524           pu blic Reque stService  getRequest Service()  {
  1525                    retu rn request Service;
  1526           }
  1527  
  1528           /* *
  1529            *  Sets the  request se rvice.
  1530            *
  1531            *  @param re questServi ce The req uestServic e.
  1532            * /
  1533           @A utowired
  1534           pu blic void  setRequest Service(Re questServi ce request Service) {
  1535                    this .requestSe rvice = re questServi ce;
  1536           }
  1537  
  1538           /* *
  1539            *  Gets the  study appr oval servi ce.
  1540            *
  1541            *  @return S tudyApprov alService  This retur ns studyAp provalServ ice.
  1542            * /
  1543           pu blic Study ApprovalSe rvice getS tudyApprov alService( ) {
  1544                    retu rn studyAp provalServ ice;
  1545           }
  1546  
  1547           /* *
  1548            *  Sets the  study appr oval servi ce.
  1549            *
  1550            *  @param st udyApprova lService T he studyAp provalServ ice.
  1551            * /
  1552           @A utowired
  1553           pu blic void  setStudyAp provalServ ice(StudyA pprovalSer vice study ApprovalSe rvice) {
  1554                    this .studyAppr ovalServic e = studyA pprovalSer vice;
  1555           }
  1556  
  1557           /* *
  1558            *  Gets the  comment hi story serv ice.
  1559            *
  1560            *  @return C ommentHist oryService  This retu rns commen tHistorySe rvice.
  1561            * /
  1562           pu blic Comme ntHistoryS ervice get CommentHis toryServic e() {
  1563                    retu rn comment HistorySer vice;
  1564           }
  1565  
  1566           /* *
  1567            *  Sets the  comment hi story serv ice.
  1568            *
  1569            *  @param co mmentHisto ryService  The commen tHistorySe rvice.
  1570            * /
  1571           @A utowired
  1572           pu blic void  setComment HistorySer vice(Comme ntHistoryS ervice com mentHistor yService)  {
  1573                    this .commentHi storyServi ce = comme ntHistoryS ervice;
  1574           }
  1575  
  1576           /* *
  1577            *  Get the u ser manage ment servi ce.
  1578            *
  1579            *  @return U serManagem entService  This retu rns userMa nagementSe rvice.
  1580            * /
  1581           pu blic UserM anagementS ervice get UserManage mentServic e() {
  1582                    retu rn userMan agementSer vice;
  1583           }
  1584  
  1585           /* *
  1586            *  Set the u ser manage ment servi ce.
  1587            *
  1588            *  @param us erManageme ntService  The userMa nagementSe rvice.
  1589            * /
  1590           @A utowired
  1591           pu blic void  setUserMan agementSer vice(UserM anagementS ervice use rManagemen tService)  {
  1592                    this .userManag ementServi ce = userM anagementS ervice;
  1593           }
  1594  
  1595           
  1596   }