111. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/25/2019 8:58:07 AM Central 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.

111.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IMAG_Source\VISA\Java\VistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\worklist WorkItemDAO.java Mon Mar 18 20:39:11 2019 UTC
2 C:\AraxisMergeCompare\Pri_re\IMAG_Source\VISA\Java\VistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\worklist WorkItemDAO.java Tue Mar 19 15:15:12 2019 UTC

111.2 Comparison summary

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

111.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

111.4 Active regular expressions

No regular expressions were active.

111.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Nov,  2009
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:     DNS     louthj
  8     Descript ion: DICOM  Study cac he manager . Maintain s the cach e of study  instances
  9                                and  expires o ld studies  after 15  minutes. 
  10  
  11           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  12           ;;  Property  of the US  Government .
  13           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  14           ;;  Use of un released v ersions of  this soft ware requi res the us er
  15           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  16           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  17           ;;   telephon e (301) 73 4-0100.
  18           ;;
  19           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  20           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  21           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  22           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  23           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  24           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  25  
  26    */
  27  
  28   package go v.va.med.i maging.vis taimagingd atasource. worklist;
  29  
  30   import gov .va.med.im aging.Stri ngUtil;
  31   import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on;
  32   import gov .va.med.im aging.core .interface s.exceptio ns.Invalid WorkItemSt atusExcept ion;
  33   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  34   import gov .va.med.im aging.core .interface s.exceptio ns.WorkIte mNotFoundE xception;
  35   import gov .va.med.im aging.exch ange.busin ess.WorkIt em;
  36   import gov .va.med.im aging.exch ange.busin ess.WorkIt emCounts;
  37   import gov .va.med.im aging.exch ange.busin ess.WorkIt emFilter;
  38   import gov .va.med.im aging.exch ange.busin ess.WorkIt emTag;
  39   import gov .va.med.im aging.exch ange.busin ess.WorkIt emTags;
  40   import gov .va.med.im aging.exch ange.busin ess.storag e.exceptio ns.Retriev alExceptio n;
  41   import gov .va.med.im aging.exch ange.busin ess.storag e.exceptio ns.UpdateE xception;
  42   import gov .va.med.im aging.url. vista.Stri ngUtils;
  43   import gov .va.med.im aging.url. vista.Vist aQuery;
  44   import gov .va.med.im aging.vist aimagingda tasource.c ommon.Vist aSessionFa ctory;
  45  
  46   import jav a.util.Arr ayList;
  47   import jav a.util.Has hMap;
  48   import jav a.util.Lin kedHashMap ;
  49   import jav a.util.Lis t;
  50  
  51   public cla ss WorkIte mDAO exten ds BaseWor kListDAO<W orkItem>
  52   {
  53           pr ivate stat ic String  CREATE_WOR K_ITEM = " MAGV CREAT E WORK ITE M";
  54           pr ivate stat ic String  GET_AND_TR ANSITION_W ORK_ITEM =  "MAGV GET  WORK ITEM ";
  55           pr ivate stat ic String  GET_AND_TR ANSITION_N EXT_WORK_I TEM = "MAG V GET NEXT  WORK ITEM ";
  56           pr ivate stat ic String  FIND_WORK_ ITEMS = "M AGV FIND W ORK ITEM";
  57           pr ivate stat ic String  GET_PRECAC HE_WORK_IT EMS = "MAG N PRECACHE  BY CPT";
  58           pr ivate stat ic String  UPDATE_WOR K_ITEM = " MAGV UPDAT E WORK ITE M";
  59           pr ivate stat ic String  ADD_TAG_TO _EXISTING_ WORK_ITEM  = "MAGV AD D WORK ITE M TAGS";
  60           pr ivate stat ic String  DELETE_WOR K_ITEM = " MAGV DELET E WORK ITE M";
  61           pr ivate stat ic String  DELETE_ALL _WORK_ITEM S = "MAGV  DELETE WOR K ITEMS FI LE";
  62           pr ivate stat ic String  GET_WORK_I TEM_COUNTS  = "MAGV W ORK ITEMS  COUNT";
  63           
  64           pr ivate stat ic String  WorkItemHe ader = "Wo rkItemHead er";
  65           pr ivate stat ic String  MessageLin e = "Messa ge";
  66           pr ivate stat ic String  Tag = "Tag ";
  67           
  68           //
  69           //  Construct or
  70           //
  71           pu blic WorkI temDAO(){}
  72           pu blic WorkI temDAO(Vis taSessionF actory ses sionFactor y)
  73           {
  74                    this .setSessio nFactory(s essionFact ory);
  75           }
  76           
  77           //
  78           //  Creation  overrides
  79           //
  80           @O verride
  81           pu blic Vista Query gene rateCreate Query(Work Item workI tem) 
  82           {
  83                    
  84                    Vist aQuery vm  = new Vist aQuery(CRE ATE_WORK_I TEM);
  85                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getType() );
  86                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getSubtyp e());
  87                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getStatus ());
  88                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getPlaceI d());
  89                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(w orkItem.ge tPriority( )));
  90  
  91                    // A dd the mes sage lines  and tags  to a hashm ap paramet er
  92                    Hash Map<String , String>  hm = getMe ssageLines AndTagsAsH ashMap(wor kItem.getM essage(),  workItem.g etTags());
  93                    vm.a ddParamete r(VistaQue ry.LIST, h m);
  94                    
  95                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getCreati ngUser() +  "");
  96                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem .getCreati ngApplicat ion() + "" );
  97  
  98                    retu rn vm;
  99           }
  100  
  101           pr ivate Hash Map<String , String>  getMessage LinesAndTa gsAsHashMa p(String m essage, Wo rkItemTags  workItemT ags) 
  102           {
  103  
  104                    // S tore in a  LinkedHash Map so ord er is pres erved
  105                    Link edHashMap< String, St ring> hm =  new Linke dHashMap<S tring, Str ing>();
  106  
  107                    int  counter=1;
  108  
  109                    // B reak messa ge up and  add pieces  to the ha shmap
  110                    if ( message !=  null)
  111                    {
  112                             
  113                             String [] message Parts = St ringUtil.b reakString (message,  MAX_M_STRI NG_LENGTH- 4);
  114                             for (i nt i = 0;  i < messag eParts.len gth; i++)  {
  115                                      hm.put(I nteger.toS tring(coun ter), "MSG " + String Utils.BACK TICK + mes sageParts[ i]);
  116                                      counter+ +;
  117                             }
  118                    }
  119                    
  120                    // A dd workite ms to the  hashmap
  121                    if(w orkItemTag s != null  && workIte mTags.getT ags() != n ull )
  122                    {
  123                             List<W orkItemTag > tags = w orkItemTag s.getTags( );
  124                             for (W orkItemTag  tag : tag s)
  125                             {
  126                                      hm.put(I nteger.toS tring(coun ter), tag. getKey() +  StringUti ls.BACKTIC K + tag.ge tValue());
  127                                      counter+ +;
  128                             }
  129                    }                 
  130                    
  131                    retu rn hm;
  132           }
  133  
  134           //
  135           //  Get and T ransition  Work Item
  136           //
  137           pu blic WorkI tem getAnd Transition WorkItem(i nt id, Str ing expect edStatus,  String new Status, St ring updat ingUser, S tring upda tingApplic ation) 
  138           th rows Metho dException , Connecti onExceptio n
  139           {
  140                    Vist aQuery vm  = new Vist aQuery(GET _AND_TRANS ITION_WORK _ITEM);
  141                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(i d));
  142                    vm.a ddParamete r(VistaQue ry.LITERAL , expected Status);
  143                    vm.a ddParamete r(VistaQue ry.LITERAL , newStatu s);
  144                    vm.a ddParamete r(VistaQue ry.LITERAL , updating User);
  145                    vm.a ddParamete r(VistaQue ry.LITERAL , updating Applicatio n);
  146           
  147                    Stri ng result  = executeR PC(vm);
  148                    
  149                    retu rn transla teGetAndTr ansitionWo rkItem(res ult);
  150           }
  151  
  152           pr ivate Work Item trans lateGetAnd Transition WorkItem(S tring resu lt) throws  MethodExc eption 
  153           {
  154  
  155                    Work Item workI tem = null ;
  156                    
  157                    // S plit the r esult into  lines
  158                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  159                    
  160                    // S plit the f irst line  into field s
  161                    Stri ng[] field s = String Utils.Spli t(lines[0] , FIELD_SE PARATOR);
  162                    int  code = Int eger.parse Int(fields [0]);
  163                    // I f the code  is not 0,  throw an  exception  with the m essage
  164                    if ( code>=0)
  165                    {
  166                             // Suc cess
  167                             workIt em = parse SingleWork Item(lines );
  168                    }
  169                    else  if (code  == -5)
  170                    {
  171                             throw  new WorkIt emNotFound Exception( fields[1]) ;
  172                    }
  173                    else  if (code  == -6)
  174                    {
  175                             throw  new Invali dWorkItemS tatusExcep tion(field s[1]);
  176                    }
  177                    else
  178                    {
  179                             throw  new Method Exception( fields[1]) ;
  180                    }
  181  
  182                    retu rn workIte m;
  183           }
  184           
  185           //
  186           //  Get and T ransition  Next Work  Item
  187           //
  188           pu blic WorkI tem getAnd Transition NextWorkIt em(String  type, Stri ng expecte dStatus, S tring newS tatus, Str ing updati ngUser, St ring updat ingApplica tion, Stri ng placeId
  189           th rows Metho dException , Connecti onExceptio n
  190           {
  191                    Vist aQuery vm  = new Vist aQuery(GET _AND_TRANS ITION_NEXT _WORK_ITEM );
  192                    vm.a ddParamete r(VistaQue ry.LITERAL , type);
  193                    vm.a ddParamete r(VistaQue ry.LITERAL , expected Status);
  194                    vm.a ddParamete r(VistaQue ry.LITERAL , newStatu s);
  195                    vm.a ddParamete r(VistaQue ry.LITERAL , updating User);
  196                    vm.a ddParamete r(VistaQue ry.LITERAL , updating Applicatio n);
  197                    vm.a ddParamete r(VistaQue ry.LITERAL , placeId) ;
  198                             
  199                    Stri ng result  = executeR PC(vm);
  200                    
  201                    retu rn transla teGetAndTr ansitionNe xtWorkItem (result);
  202           }
  203  
  204           pr ivate Work Item trans lateGetAnd Transition NextWorkIt em(String  result) th rows Metho dException  
  205           {
  206  
  207                    // S plit the r esult into  lines
  208                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  209                    
  210                    // S plit the f irst line  into field s
  211                    Stri ng[] field s = String Utils.Spli t(lines[0] , FIELD_SE PARATOR);
  212  
  213                    Work Item workI tem = null ;
  214  
  215                    // G et the sta tus code
  216                    int  code = get StatusCode (fields[0] );
  217  
  218                    // I f the code  is 0 (suc cess) pars e and set  the work i tem
  219                    if ( code >= 0  && lines.l ength > 1)
  220                    {
  221                             workIt em = parse SingleWork Item(lines );
  222                    }
  223  
  224                    // R eturn the  work item  or null
  225                    retu rn workIte m;
  226           }
  227           
  228           
  229           pr ivate int  getStatusC ode(String  field) 
  230           {
  231                    int  code;
  232                    
  233                    try
  234                    {
  235                             code =  Integer.p arseInt(fi eld);
  236                    }
  237                    catc h (NumberF ormatExcep tion e)
  238                    {
  239                             code =  -1;
  240                    }
  241                    
  242                    retu rn code;
  243           }
  244           
  245           //
  246           //  Get and T ransition  Next Work  Item
  247           //
  248           @O verride
  249           pu blic Vista Query gene rateFindBy CriteriaQu ery(Object  criteria)
  250           {
  251                    Work ItemFilter  filter =  (WorkItemF ilter)crit eria;
  252                    
  253                    Stri ng subtype  = filter. getSubtype () != null  ? filter. getSubtype () : "";
  254                    Stri ng status  = filter.g etStatus()  != null ?  filter.ge tStatus()  : "";
  255                    Stri ng placeId  = filter. getPlaceId () != null  ? filter. getPlaceId () : "";
  256                    Stri ng priorit y = filter .getItemPr iority() ! = null ? f ilter.getI temPriorit y() : "";
  257                    Stri ng shortCi rcuitTagNa me = filte r.getShort CircuitTag Name() !=  null ? fil ter.getSho rtCircuitT agName() :  "";
  258                    Stri ng maximum NumberOfIt emsToRetur n = filter .getMaximu mNumberOfI temsToRetu rn() != nu ll ? filte r.getMaxim umNumberOf ItemsToRet urn() : "" ;
  259  
  260                    Vist aQuery vm  = new Vist aQuery(FIN D_WORK_ITE MS);
  261                    vm.a ddParamete r(VistaQue ry.LITERAL , filter.g etType());
  262                    vm.a ddParamete r(VistaQue ry.LITERAL , subtype) ;
  263                    vm.a ddParamete r(VistaQue ry.LITERAL , status);
  264                    vm.a ddParamete r(VistaQue ry.LITERAL , placeId) ;
  265                    vm.a ddParamete r(VistaQue ry.LITERAL , priority );
  266                    vm.a ddParamete r(VistaQue ry.LITERAL , shortCir cuitTagNam e);
  267                    vm.a ddParamete r(VistaQue ry.LITERAL , maximumN umberOfIte msToReturn );
  268                    
  269                    // A dd the mes sage lines  and tags  to a hashm ap paramet er
  270                    Hash Map<String , String>  hm = getMe ssageLines AndTagsAsH ashMap(nul l, filter. getTags()) ;
  271                    vm.a ddParamete r(VistaQue ry.LIST, h m);
  272           
  273                    retu rn vm;
  274           }
  275  
  276           @O verride
  277           pu blic Vista Query gene rateFindBy CptQuery(S tring idTy pe, String  patientId , String c ptCode)
  278           {
  279                    Vist aQuery vm  = new Vist aQuery(GET _PRECACHE_ WORK_ITEMS );
  280                    vm.a ddParamete r(VistaQue ry.LITERAL , idType);
  281                    vm.a ddParamete r(VistaQue ry.LITERAL , patientI d);
  282                    vm.a ddParamete r(VistaQue ry.LITERAL , cptCode) ;
  283                    
  284                    retu rn vm;
  285           }
  286  
  287           @O verride
  288           pu blic List< WorkItem>  translateF indByCpt(O bject crit eria, Stri ng returnV alue) 
  289           th rows Metho dException , Retrieva lException
  290           {
  291                    // W e made it  here, so c reate the  list of wo rk items
  292                    List <WorkItem>  workItems  = new Arr ayList<Wor kItem>();
  293                    
  294                    // S plit the r esult into  lines
  295                    Stri ng[] lines  = StringU tils.Split (returnVal ue, LINE_S EPARATOR);
  296                    
  297                    if ( (lines.len gth > 0) & & (lines[0 ].equals(" 1")))
  298                    {
  299                             for (i nt i = 1;  i<lines.le ngth; i++)
  300                             {
  301                                      String l ine = line s[i];
  302                                      logger.d ebug("Tran slating li ne: " + li ne + " to  workitem") ;
  303  
  304                                      WorkItem  workitem  = new Work Item();
  305                                      workitem .setPlaceI d(StringUt ils.Piece( line, Stri ngUtils.CA RET, 1));
  306                                      
  307                                      workitem .addTag("p atienticn" , StringUt ils.Piece( line, Stri ngUtils.CA RET, 3));
  308                                      workitem .addTag("c ontextid",  StringUti ls.Piece(l ine, Strin gUtils.CAR ET, 4).rep lace(Strin gUtils.TIL DE, String Utils.CARE T));
  309                                      workItem s.add(work item);
  310                             }
  311                    }
  312                    
  313                    retu rn workIte ms;
  314           }
  315  
  316           @O verride
  317           pu blic List< WorkItem>  translateF indByCrite ria(Object  criteria,  String re turnValue)  
  318           th rows Metho dException
  319           {
  320  
  321                    // S plit the r esult into  lines
  322                    Stri ng[] lines  = StringU tils.Split (returnVal ue, LINE_S EPARATOR);
  323                    
  324                    // S plit the f irst line  into field s
  325                    Stri ng[] field s = String Utils.Spli t(lines[0] , FIELD_SE PARATOR);
  326                    
  327                    // I f the code  is less t han 0, thr ow an exce ption with  the messa ge
  328                    int  code = Int eger.parse Int(fields [0]);
  329                    
  330                    if ( code < 0)
  331                    {
  332                             throw  new Method Exception( fields[1]) ;
  333                    }
  334                    
  335                    // W e made it  here, so c reate the  list of wo rk items
  336                    List <WorkItem>  workItems  = parseWo rkItems(li nes);
  337                    
  338                    retu rn workIte ms;
  339           }
  340  
  341           
  342           pr ivate Work Item parse SingleWork Item(Strin g[] lines)  
  343           {
  344                    List <WorkItem>  workItems  = parseWo rkItems(li nes);
  345                    if ( workItems  != null &&  workItems .size() >  0)
  346                    {
  347                             return  workItems .get(0);
  348                    }
  349  
  350                    retu rn null;
  351           }
  352           
  353           pr ivate List <WorkItem>  parseWork Items(Stri ng[] lines
  354           {
  355                    List <WorkItem>  workItems  = new Arr ayList<Wor kItem>();
  356                    Work Item workI tem = null ;
  357                    Stri ngBuilder  message =  new String Builder();
  358                    Work ItemTags t ags = new  WorkItemTa gs();
  359  
  360                    // S kip the fi rst line ( which was  the record  count)
  361                    for  (int i=1;  i<lines.le ngth; i++)
  362                    {
  363                             // Fir st, figure  out what  kind of da ta is in t his line.  It will ei ther be 
  364                             String [] fields  = StringUt ils.Split( lines[i],  StringUtil s.BACKTICK );
  365                             String  lineType  = fields[0 ];
  366  
  367                             if (li neType.equ als(WorkIt emHeader))
  368                             {
  369                                      // This  is a heade r line. If  it's not  the first  header lin e (i.e. wo rkItem
  370                                      // is no t null), w e first ha ve to fina lize the c urrent ite m and add  it to the  list
  371                                      // befor e we parse  the new h eader and  reset the  message an d tag vari ables.
  372                                      if (work Item != nu ll)
  373                                      {
  374                                               // Flush c urrent ite m and rese t pieces
  375                                               workItem.s etMessage( message.to String());
  376                                               workItem.s etTags(tag s);
  377                                               workItems. add(workIt em);
  378                                      }
  379  
  380                                      // Parse  the heade r and rese t the mess age and ta gs.
  381                                      workItem  = parseWo rkItemFrom Header(fie lds[1]);
  382                                      message  = new Stri ngBuilder( );
  383                                      tags = n ew WorkIte mTags();
  384                                      
  385                             }
  386                             
  387                             if (li neType.equ als(Messag eLine))
  388                             {
  389                                      message. append(fie lds[1]);
  390                             }
  391                             
  392                             if (li neType.equ als(Tag))
  393                             {
  394                                      if (fiel ds[1].cont ains(Strin gUtils.STI CK))
  395                                      {
  396                                               String[] t agFields =  StringUti ls.Split(f ields[1],  StringUtil s.STICK);
  397                                               tags.addTa g(tagField s[0], tagF ields[1]);
  398                                      }
  399                                      else
  400                                      {
  401                                               tags.addTa g(fields[1 ], fields[ 2]);
  402                                      }
  403                             }
  404                    }
  405                    
  406                    // O nce we've  finished t he main lo op, add th e final wo rkItem (if  any)
  407                    if ( workItem ! = null)
  408                    {
  409                             // Flu sh current  item and  reset piec es
  410                             workIt em.setMess age(messag e.toString ());
  411                             workIt em.setTags (tags);
  412                             workIt ems.add(wo rkItem);
  413                    }
  414                    
  415                    retu rn workIte ms;
  416           }
  417  
  418           pr ivate Work Item parse WorkItemFr omHeader(S tring work ItemHeader
  419           {
  420  
  421                    Stri ng[] field s = String Utils.Spli t(workItem Header, St ringUtils. STICK);
  422                    
  423                    Work Item workI tem = new  WorkItem() ;
  424                    work Item.setId (Integer.p arseInt(fi elds[0]));
  425                    work Item.setCr eatedDate( fields[1]) ;
  426                    work Item.setTy pe(fields[ 2]);
  427                    work Item.setSu btype(fiel ds[3]);
  428                    work Item.setSt atus(field s[4]);
  429                    work Item.setPl aceId(fiel ds[5]);
  430                    work Item.setPr iority(Int eger.parse Int(fields [6]));
  431                    work Item.setCr eatingUser (replaceNu llWithEmpt yString(fi elds[7]));
  432                    work Item.setCr eatingUser DisplayNam e(fields[8 ]);
  433                    work Item.setLa stUpdateDa te(fields[ 9]);
  434                    work Item.setUp datingUser (replaceNu llWithEmpt yString(fi elds[10])) ;
  435                    work Item.setUp datingUser DisplayNam e(fields[1 1]);
  436                    work Item.setCr eatingAppl ication(re placeNullW ithEmptySt ring(field s[12]));
  437                    work Item.setUp datingAppl ication(re placeNullW ithEmptySt ring(field s[13]));
  438                    
  439                    retu rn workIte m;
  440           }
  441  
  442           pr ivate Stri ng replace NullWithEm ptyString( String fie ld) 
  443           {
  444                    retu rn field.e quals("nul l") ? "" :  field;
  445           }
  446           //
  447           //  Update Wo rk Item
  448           //
  449           pu blic boole an updateW orkItem(in t workItem Id, String  expectedS tatus, Str ing newSta tus, Strin g newMessa ge, String  updatingU ser, Strin g updating Applicatio n) 
  450           th rows Metho dException , Connecti onExceptio n
  451           {
  452                    Vist aQuery vm  = new Vist aQuery(UPD ATE_WORK_I TEM);
  453                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(w orkItemId) );
  454                    vm.a ddParamete r(VistaQue ry.LITERAL , expected Status);
  455                    vm.a ddParamete r(VistaQue ry.LITERAL , newStatu s);
  456                    
  457                    Hash Map<String , String>  hm = getMe ssageLines AndTagsAsH ashMap(new Message, n ull);
  458                    vm.a ddParamete r(VistaQue ry.LIST, h m);
  459                    vm.a ddParamete r(VistaQue ry.LITERAL , updating User + "") ;
  460                    vm.a ddParamete r(VistaQue ry.LITERAL , updating Applicatio n + "");
  461           
  462                    Stri ng result  = executeR PC(vm);
  463                    
  464                    retu rn transla teUpdateWo rkItem(res ult);
  465           }
  466  
  467           pr otected bo olean tran slateUpdat eWorkItem( String res ult) throw s UpdateEx ception, M ethodExcep tion {
  468                    Stri ng[] resul ts = Strin gUtils.Spl it(result,  FIELD_SEP ARATOR);
  469  
  470                    if ( !results[0 ].equals(" 0"))
  471                    {
  472                             if(res ults[0].eq uals("-6")  || result s[0].equal s("-9"))
  473                             {                         
  474                                      throw ne w UpdateEx ception(re sults[1]);
  475                             }
  476                             else
  477                             {
  478                                      throw ne w MethodEx ception(re sults[1]);
  479                             }
  480                    }
  481                    
  482                    retu rn true;
  483           }
  484           
  485  
  486           //
  487           //  Add Tag t o Existing  Work Item
  488           //
  489           pu blic boole an addTags ToExisting WorkItem(
  490                             int wo rkItemId, 
  491                             List<S tring> all owedStatus es, 
  492                             List<W orkItemTag > newTags,  
  493                             String  updatingU ser, 
  494                             String  updatingA pplication
  495           th rows Metho dException , Connecti onExceptio n
  496           {
  497                    // B uild a del imited str ing of sta tuses
  498                    Stri ng statusP aram="";
  499                    for  (String st atus : all owedStatus es)
  500                    {
  501                             // Add  a delimit er if we'v e already  got conten t
  502                             if (!s tatusParam .equals("" ))
  503                                      statusPa ram += "`" ;
  504                             
  505                             status Param += s tatus;
  506                    }
  507                    
  508                    // B uild hashm ap for tag s
  509                    int  counter =  1;
  510                    Hash Map<String , String>  hmTags = n ew HashMap <String, S tring>();
  511                    for  (WorkItemT ag tag : n ewTags)
  512                    {
  513                             hmTags .put(Integ er.toStrin g(counter) , tag.getK ey() + "`"  + tag.get Value());
  514                             counte r++;
  515                    }
  516  
  517                    // C reate the  query
  518                    Vist aQuery vm  = new Vist aQuery(ADD _TAG_TO_EX ISTING_WOR K_ITEM);
  519                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(w orkItemId) );
  520                    vm.a ddParamete r(VistaQue ry.LITERAL , statusPa ram);
  521                    vm.a ddParamete r(VistaQue ry.LITERAL , updating User);
  522                    vm.a ddParamete r(VistaQue ry.LITERAL , updating Applicatio n);
  523                    vm.a ddParamete r(VistaQue ry.LIST, h mTags);
  524           
  525                    // C all the RP C
  526                    Stri ng result  = executeR PC(vm);
  527                    
  528                    // T ranslate t he result
  529                    retu rn transla teAddTagTo ExistingWo rkItem(res ult);
  530           }
  531  
  532           pr otected bo olean tran slateAddTa gToExistin gWorkItem( String res ult) 
  533           th rows Updat eException , MethodEx ception 
  534           {
  535                    Stri ng[] resul ts = Strin gUtils.Spl it(result,  FIELD_SEP ARATOR);
  536  
  537                    if ( !results[0 ].equals(" 0"))
  538                    {
  539                             if(res ults[0].eq uals("-5")  || result s[0].equal s("-9"))
  540                             {                         
  541                                      throw ne w UpdateEx ception(re sults[1]);
  542                             }
  543                             else
  544                             {
  545                                      throw ne w MethodEx ception(re sults[1]);
  546                             }
  547                    }
  548                    retu rn true;
  549           }
  550           
  551           //  Delete
  552           @O verride 
  553           pu blic Vista Query gene rateDelete Query(int  id)
  554           {
  555                    // C reate the  query
  556                    Vist aQuery vm  = new Vist aQuery(DEL ETE_WORK_I TEM);
  557                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(i d));
  558                    
  559                    retu rn vm;
  560           }
  561  
  562  
  563           //
  564           //  Delete al l workitem s
  565           //
  566           pu blic void  deleteAllW orkItems()  
  567           th rows Metho dException , Connecti onExceptio n
  568           {
  569                    Vist aQuery vm  = new Vist aQuery(DEL ETE_ALL_WO RK_ITEMS);
  570                    exec uteRPC(vm) ;
  571           }
  572           
  573           pu blic WorkI temCounts  getWorkIte mCounts(St ring workI temType) 
  574           th rows Metho dException , Connecti onExceptio
  575           {
  576                    Vist aQuery vm  = new Vist aQuery(GET _WORK_ITEM _COUNTS);
  577                    vm.a ddParamete r(VistaQue ry.LITERAL , workItem Type);
  578           
  579                    Stri ng result  = executeR PC(vm);
  580                    
  581                    retu rn transla teGetWorkI temCounts( result);
  582           }
  583           
  584           pu blic WorkI temCounts  translateG etWorkItem Counts(Str ing result ) throws M ethodExcep tion 
  585           {
  586                    // S plit the r esult into  lines
  587                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  588                    
  589                    // S plit the f irst line  into field s
  590                    Stri ng[] field s = String Utils.Spli t(lines[0] , FIELD_SE PARATOR);
  591                    
  592                    // I f the code  is less t han 0, thr ow an exce ption with  the messa ge
  593                    int  code = Int eger.parse Int(fields [0]);
  594                    
  595                    if ( code < 0)
  596                    {
  597                             throw  new Method Exception( fields[1]) ;
  598                    }
  599  
  600                    // C reate the  workItem c ounts obje ct, since  we didn't  throw an e xception.
  601                    Work ItemCounts  counts =  new WorkIt emCounts() ;
  602                    
  603                    // I f there ar e more tha n two line s returned  (1 count  line, 1 he ader line) , we have  results, s o process  them.
  604                    // O therwise,  return the  empty wor kItems cou nt object.
  605                    if ( lines.leng th > 2)
  606                    {
  607                             for (i nt i=2; i< lines.leng th; i++)
  608                             {
  609                                      fields =  StringUti ls.Split(l ines[i], F IELD_SEPAR ATOR);
  610                                      counts.a ddCountFor SubtypeAnd Status(fie lds[0], fi elds[1], I nteger.par seInt(fiel ds[2]));
  611                             }
  612                    }
  613                    
  614                    retu rn counts;
  615           }
  616  
  617   }