Produced by Araxis Merge on 12/21/2017 6:15:12 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Genisis_2.0_v7_bld7.zip\TS\CLI\src\main\java\gov\va\genisis2 | TermCli.java | Thu Dec 14 19:56:37 2017 UTC |
| 2 | Genisis_2.0_v7_bld7.zip\TS\CLI\src\main\java\gov\va\genisis2 | TermCli.java | Thu Dec 21 21:04:26 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 428 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.genis is2; | |
| 2 | ||
| 3 | import jav a.io.File; | |
| 4 | import jav a.io.FileI nputStream ; | |
| 5 | import jav a.io.FileN otFoundExc eption; | |
| 6 | import jav a.io.FileO utputStrea m; | |
| 7 | import jav a.io.IOExc eption; | |
| 8 | import jav a.io.Input Stream; | |
| 9 | import jav a.io.Outpu tStream; | |
| 10 | import jav a.util.Lis t; | |
| 11 | import jav a.util.Pro perties; | |
| 12 | ||
| 13 | import org .apache.co mmons.cli. CommandLin e; | |
| 14 | import org .apache.co mmons.cli. CommandLin eParser; | |
| 15 | import org .apache.co mmons.cli. DefaultPar ser; | |
| 16 | import org .apache.co mmons.cli. HelpFormat ter; | |
| 17 | import org .apache.co mmons.cli. Option; | |
| 18 | import org .apache.co mmons.cli. OptionGrou p; | |
| 19 | import org .apache.co mmons.cli. Options; | |
| 20 | import org .apache.co mmons.cli. ParseExcep tion; | |
| 21 | import org .apache.lo g4j.Logger ; | |
| 22 | ||
| 23 | import com .fasterxml .jackson.c ore.type.T ypeReferen ce; | |
| 24 | import com .fasterxml .jackson.d atabind.Ob jectMapper ; | |
| 25 | ||
| 26 | import gov .va.genisi s2.ts.comm on.dto.Tri pleDTO; | |
| 27 | import gov .va.genisi s2.utils.T ermCliCons tants; | |
| 28 | ||
| 29 | /** | |
| 30 | * Command Line Inte rface Entr y Point | |
| 31 | * | |
| 32 | * @author PII | |
| 33 | * | |
| 34 | */ | |
| 35 | public cla ss TermCli { | |
| 36 | ||
| 37 | pr ivate stat ic final L ogger LOGG ER = Logge r.getLogge r(TermCli. class); | |
| 38 | ||
| 39 | pu blic stati c void mai n(String[] args) { | |
| 40 | ||
| 41 | Term CliModel m odel = new TermCliMo del(); | |
| 42 | ||
| 43 | Http Client htt pClient = new HttpCl ient(); | |
| 44 | ||
| 45 | Comm andLinePar ser parser = new Def aultParser (); | |
| 46 | Comm andLine cm dLine = nu ll; | |
| 47 | Opti ons option s = null; | |
| 48 | Prop erties pro perties = new Proper ties(); | |
| 49 | Stri ng termSrv iceUrl = n ull; | |
| 50 | ||
| 51 | try { | |
| 52 | proper ties.load( new FileIn putStream( "cli.prope rties")); | |
| 53 | termSr viceUrl = properties .getProper ty("term.s ervice.url "); | |
| 54 | ||
| 55 | if (nu ll == term SrviceUrl || termSrv iceUrl.tri m().length () == 0) { | |
| 56 | System.e rr.println ("Missing property f or Termino logy Servi ce URL (te rm.service .url) in c li.propert ies"); | |
| 57 | System.e xit(0); | |
| 58 | } | |
| 59 | ||
| 60 | option s = create CommandLin eOptions() ; | |
| 61 | cmdLin e = parser .parse(opt ions, args ); | |
| 62 | } ca tch (Parse Exception e) { | |
| 63 | LOGGER .error("Co uldn't par se command line argu ments " + e); | |
| 64 | System .err.print ln("Error: " + e); | |
| 65 | HelpFo rmatter fo rmatter = new HelpFo rmatter(); | |
| 66 | format ter.printH elp("java -jar tsed- jar-with-d ependencie s.jar", op tions); | |
| 67 | System .exit(0); | |
| 68 | } ca tch (FileN otFoundExc eption e) { | |
| 69 | LOGGER .error("un able to lo cate prope rty file" + e); | |
| 70 | System .err.print ln("unable to locate property file: cli. properties \n" + e); | |
| 71 | System .exit(0); | |
| 72 | } ca tch (IOExc eption e) { | |
| 73 | System .err.print ln("Except ion " + e) ; | |
| 74 | e.prin tStackTrac e(); | |
| 75 | } | |
| 76 | ||
| 77 | if ( cmdLine.ha sOption(Te rmCliConst ants.ADD)) { | |
| 78 | model. setAdd(tru e); | |
| 79 | LOGGER .debug("Ad ding tripl es"); | |
| 80 | } el se { | |
| 81 | // be a drop | |
| 82 | model. setDrop(tr ue); | |
| 83 | LOGGER .debug("Dr opping tri ples"); | |
| 84 | } | |
| 85 | ||
| 86 | if ( cmdLine.ha sOption(Te rmCliConst ants.CHECK _ONLY)) { | |
| 87 | model. setCheckOn ly(true); | |
| 88 | LOGGER .debug("Se tting chec k only mod e true"); | |
| 89 | } | |
| 90 | if ( cmdLine.ha sOption(Te rmCliConst ants.HELP) ) { | |
| 91 | HelpFo rmatter fo rmatter = new HelpFo rmatter(); | |
| 92 | format ter.printH elp("java -jar tsed- jar-with-d ependencie s.jar", op tions); | |
| 93 | System .exit(0); | |
| 94 | } | |
| 95 | if ( cmdLine.ha sOption(Te rmCliConst ants.VERBO SE)) { | |
| 96 | model. setVerbose (true); | |
| 97 | LOGGER .debug("Se tting chec k only mod e true"); | |
| 98 | } | |
| 99 | if ( cmdLine.ha sOption(Te rmCliConst ants.IGNOR E_ERR)) { | |
| 100 | model. setIgnoreE rrors(true ); | |
| 101 | LOGGER .debug("Se tting no i gnore erro r mode tru e"); | |
| 102 | } | |
| 103 | if ( cmdLine.ha sOption(Te rmCliConst ants.ALLOW _ERR)) { | |
| 104 | model. setAllowEr rors(true) ; | |
| 105 | LOGGER .debug("Se tting allo w error mo de true"); | |
| 106 | } | |
| 107 | if ( cmdLine.ha sOption(Te rmCliConst ants.NO_ER R)) { | |
| 108 | model. setNoError s(true); | |
| 109 | LOGGER .debug("Se tting no e rror mode true"); | |
| 110 | } | |
| 111 | ||
| 112 | File input = n ull; | |
| 113 | if ( cmdLine.ha sOption(Te rmCliConst ants.FILE) ) { | |
| 114 | // rea d json fro m file | |
| 115 | input = new File (cmdLine.g etOptionVa lue(TermCl iConstants .FILE)); | |
| 116 | } el se { | |
| 117 | // rea d from sta ndard inpu t | |
| 118 | input = new File (convertSt dnToFile(S ystem.in)) ; | |
| 119 | } | |
| 120 | ||
| 121 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
| 122 | List <TripleDTO > triples = null; | |
| 123 | ||
| 124 | try { | |
| 125 | triple s = mapper .readValue (input, ne w TypeRefe rence<List <TripleDTO >>() { | |
| 126 | }); | |
| 127 | ||
| 128 | } ca tch (IOExc eption e) { | |
| 129 | LOGGER .error("Er ror: parsi ng JSON" + e.getMess age()); | |
| 130 | System .err.print ("Error: p arsing JSO N " + e); | |
| 131 | } | |
| 132 | ||
| 133 | mode l.setPrope rties(trip les); | |
| 134 | ||
| 135 | Syst em.out.pri ntln(model .toJson()) ; | |
| 136 | //// At this p oint we ha ve the dat a...probab ly should check for issues | |
| 137 | //// here but now lets t ry to send the data | |
| 138 | http Client.sen dingUpdate (termSrvic eUrl, mode l.isAdd(), model.toJ son()); | |
| 139 | ||
| 140 | } | |
| 141 | ||
| 142 | /* * | |
| 143 | * Create th e option o bjects use d as comma nd line ar guments | |
| 144 | * | |
| 145 | * @return o rg.apache. commons.cl i.Options | |
| 146 | * / | |
| 147 | pr ivate stat ic Options createCom mandLineOp tions() { | |
| 148 | ||
| 149 | Opti ons option s = new Op tions(); | |
| 150 | ||
| 151 | Opti on helpOpt ion = Opti on.builder (TermCliCo nstants.HE LP).requir ed(false). desc("Disp lays the h elp messag e").build( ); | |
| 152 | ||
| 153 | Opti on fileOpt ion = Opti on.builder (TermCliCo nstants.FI LE).number OfArgs(1). required(f alse).desc ("Used to take in tr iple infor mation fro m a JSON f ormatted f ile").buil d(); | |
| 154 | ||
| 155 | opti ons.addOpt ion(helpOp tion); | |
| 156 | opti ons.addOpt ion(fileOp tion); | |
| 157 | ||
| 158 | // e stablish m utually ex clusive gr oup for re quired add or drop | |
| 159 | Opti onGroup ad dDropGroup = new Opt ionGroup() ; | |
| 160 | addD ropGroup.s etRequired (true); | |
| 161 | ||
| 162 | Opti on add = O ption.buil der(TermCl iConstants .ADD).desc ("Triples will be ad ded to Jen a/Fuseki") .build(); | |
| 163 | ||
| 164 | Opti on drop = Option.bui lder(TermC liConstant s.DROP).de sc("Triple s will be deleted fr om Jena/Fu seki").bui ld(); | |
| 165 | ||
| 166 | addD ropGroup.a ddOption(a dd); | |
| 167 | addD ropGroup.a ddOption(d rop); | |
| 168 | ||
| 169 | opti ons.addOpt ionGroup(a ddDropGrou p); | |
| 170 | ||
| 171 | // e stablish m utually ex clusive gr oup for er rors | |
| 172 | Opti onGroup er rorGroup = new Optio nGroup(); | |
| 173 | erro rGroup.set Required(t rue); | |
| 174 | ||
| 175 | Opti on checkOn lyOption = Option.bu ilder("c") .longOpt(T ermCliCons tants.CHEC K_ONLY).re quired(fal se).desc(" Checks for errors bu t performs no databa se updates ").build() ; | |
| 176 | ||
| 177 | Opti on noError Option = O ption.buil der("noErr ").longOpt (TermCliCo nstants.NO _ERR).requ ired(false ).desc("Pe rforms upd ates if an d only if there are no errors" ).build(); | |
| 178 | ||
| 179 | Opti on allowEr rorOption = Option.b uilder("al lowErr").l ongOpt(Ter mCliConsta nts.ALLOW_ ERR).requi red(false) .desc("Per forms any and all up dates that have no e rrors").bu ild(); | |
| 180 | ||
| 181 | Opti on ignoreE rrorOption = Option. builder("i gnoreErr") .longOpt(T ermCliCons tants.IGNO RE_ERR).re quired(fal se).desc(" Performs u pdates wit h no discr etion. De fault mode ").build() ; | |
| 182 | ||
| 183 | erro rGroup.add Option(che ckOnlyOpti on); | |
| 184 | erro rGroup.add Option(noE rrorOption ); | |
| 185 | erro rGroup.add Option(all owErrorOpt ion); | |
| 186 | erro rGroup.add Option(ign oreErrorOp tion); | |
| 187 | ||
| 188 | opti ons.addOpt ionGroup(e rrorGroup) ; | |
| 189 | ||
| 190 | retu rn options ; | |
| 191 | ||
| 192 | } | |
| 193 | ||
| 194 | pr ivate stat ic String convertStd nToFile(In putStream in) { | |
| 195 | ||
| 196 | try (OutputStr eam output Stream = n ew FileOut putStream( new File(T ermCliCons tants.TEMP _INPUT_FIL E))) { | |
| 197 | int re ad = 0; | |
| 198 | byte[] bytes = n ew byte[10 24]; | |
| 199 | ||
| 200 | while ((read = i n.read(byt es)) != -1 ) { | |
| 201 | outputSt ream.write (bytes, 0, read); | |
| 202 | } | |
| 203 | } ca tch (IOExc eption e) { | |
| 204 | LOGGER .error("Er ror conver ting stdin to file: " + e.getM essage()); | |
| 205 | } fi nally { | |
| 206 | if (in != null) | |
| 207 | try { | |
| 208 | in.close() ; | |
| 209 | } catch (IOExcepti on e) { | |
| 210 | LOGGER.err or("Error couldn't c lose file: " + e.get Message()) ; | |
| 211 | } | |
| 212 | } | |
| 213 | retu rn TermCli Constants. TEMP_INPUT _FILE; | |
| 214 | } | |
| 215 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.