Produced by Araxis Merge on 12/20/2017 5:56:05 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_v6_bld6.zip\Source Code\TS\Service\term-service\src\main\java\gov\va\genisis2\ts\service\impl | MvpUriGenHelper.java | Thu Dec 14 19:57:19 2017 UTC |
| 2 | Genisis_2.0_v6_bld6.zip\Source Code\TS\Service\term-service\src\main\java\gov\va\genisis2\ts\service\impl | MvpUriGenHelper.java | Wed Dec 20 20:37:39 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 314 |
| Changed | 2 | 4 |
| 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.ts.ser vice.impl; | |
| 2 | ||
| 3 | import jav a.util.Has hMap; | |
| 4 | import jav a.util.Lis t; | |
| 5 | import jav a.util.Map ; | |
| 6 | import jav a.util.Ran dom; | |
| 7 | import jav a.util.reg ex.Matcher ; | |
| 8 | import jav a.util.reg ex.Pattern ; | |
| 9 | ||
| 10 | import org .apache.je na.query.Q ueryExecut ion; | |
| 11 | import org .apache.lo gging.log4 j.LogManag er; | |
| 12 | import org .apache.lo gging.log4 j.Logger; | |
| 13 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 14 | import org .springfra mework.ste reotype.Co mponent; | |
| 15 | ||
| 16 | import gov .va.genisi s2.ts.comm on.dto.Tri pleDTO; | |
| 17 | import gov .va.genisi s2.ts.comm on.excepti on.TSInern alSystemEx ception; | |
| 18 | import gov .va.genisi s2.ts.fuse ki.FusekiC lient; | |
| 19 | import gov .va.genisi s2.ts.util s.TSProper tiesUtil; | |
| 20 | ||
| 21 | @Component | |
| 22 | public cla ss MvpUriG enHelper { | |
| 23 | pr ivate stat ic final L ogger LOGG ER = LogMa nager.getL ogger(MvpU riGenHelpe r.class); | |
| 24 | ||
| 25 | @A utowired | |
| 26 | pr ivate TSPr opertiesUt il propsUt il; | |
| 27 | ||
| 28 | @A utowired | |
| 29 | pr ivate Fuse kiClient f usekiClien t; | |
| 30 | ||
| 31 | pu blic void populateUr isForNewCo ncepts(Lis t<TripleDT O> triples ) { | |
| 32 | Map< String, St ring> uriH ashMap = n ew HashMap <>(); | |
| 33 | ||
| 34 | try { | |
| 35 | if (nu ll == trip les || tri ples.isEmp ty()) { | |
| 36 | LOGGER.e rror("trip les list i s emptry") ; | |
| 37 | } else { | |
| 38 | for (Tri pleDTO tri ple : trip les) { | |
| 39 | // replace _?xx in s ubject | |
| 40 | String val ue = tripl e.getS(); | |
| 41 | String upd atedValue = this.gen erateUri(v alue, uriH ashMap); | |
| 42 | ||
| 43 | if (null ! = updatedV alue) { | |
| 44 | tr iple.setS( updatedVal ue); | |
| 45 | } | |
| 46 | ||
| 47 | // replace _?xx in p redicate | |
| 48 | value = tr iple.getP( ); | |
| 49 | updatedVal ue = this. generateUr i(value, u riHashMap) ; | |
| 50 | ||
| 51 | if (null ! = updatedV alue) { | |
| 52 | tr iple.setP( updatedVal ue); | |
| 53 | } | |
| 54 | ||
| 55 | // replace _?xx in o bject | |
| 56 | value = tr iple.getO( ); | |
| 57 | updatedVal ue = this. generateUr i(value, u riHashMap) ; | |
| 58 | ||
| 59 | if (null ! = updatedV alue) { | |
| 60 | tr iple.setO( updatedVal ue); | |
| 61 | } | |
| 62 | } | |
| 63 | } | |
| 64 | } ca tch (Excep tion e) { | |
| 65 | LOGGER .error("Er ror in pop ulateUrisF orNewConce pts", e); | |
| 66 | throw new TSIner nalSystemE xception(" Error in p opulateUri sForNewCon cepts", e) ; | |
| 67 | } | |
| 68 | ||
| 69 | } | |
| 70 | ||
| 71 | /* * | |
| 72 | * Adds angu lar bracke ts to reso urces.. Th is is done because S PARQL need s | |
| 73 | * resource to be in a ngular bra ckets | |
| 74 | * | |
| 75 | * @param ur i | |
| 76 | * @return | |
| 77 | * / | |
| 78 | pu blic Strin g quoteUri (String ur i) { | |
| 79 | if ( uri.starts With("<")) { | |
| 80 | return uri; | |
| 81 | } | |
| 82 | ||
| 83 | retu rn "<" + u ri + ">"; | |
| 84 | } | |
| 85 | ||
| 86 | /* * | |
| 87 | * Adds doub le quotes to literal s.. This i s done bec ause SPARQ L needs li terals | |
| 88 | * to be dou ble quoted | |
| 89 | * | |
| 90 | * @param qu ery | |
| 91 | * @return | |
| 92 | * / | |
| 93 | pu blic Strin g quoteLit eral(Strin g query) { | |
| 94 | if ( query.star tsWith("<" )) { | |
| 95 | return query; | |
| 96 | } | |
| 97 | retu rn "\"" + query + "\ ""; | |
| 98 | } | |
| 99 | ||
| 100 | pr ivate Stri ng generat eUri(Strin g value, M ap<String, String> u riHashMap) { | |
| 101 | Stri ng updated Value = nu ll; | |
| 102 | bool ean valueH asAngularB racket = f alse; | |
| 103 | Quer yExecution qe = null ; | |
| 104 | ||
| 105 | try { | |
| 106 | // value s tarts with 'http:// URL /mvp-schem a' | |
| 107 | if (nu ll != valu e | |
| 108 | && ((value HasAngular Bracket = value.trim ().startsW ith("<") & & value.tr im().start sWith("<" + propsUti l.getMvpPr efix())) | | value.tr im().start sWith(prop sUtil.getM vpPrefix() )) | |
| 109 | && value.t rim().cont ains(props Util.getMv pUriDelimi ter())) { | |
| 110 | if (valu eHasAngula rBracket) { | |
| 111 | value = va lue.substr ing(1, val ue.length( ) - 1); | |
| 112 | } | |
| 113 | ||
| 114 | // subje ct ends wi th "_?###" . where w e accept f rom 1 to 3 decimal d igits afte r | |
| 115 | // the ' ?' | |
| 116 | Pattern p = Patter n.compile( propsUtil. getMvpNewC onceptRege x()); | |
| 117 | Matcher m = p.matc her(value) ; | |
| 118 | if (m.fi nd()) { | |
| 119 | // is subj ect exists in URIHas hMap | |
| 120 | if (uriHas hMap.conta insKey(val ue)) { | |
| 121 | up datedValue = uriHash Map.get(va lue); | |
| 122 | } else { | |
| 123 | bo olean exis tsInDataba se = true; | |
| 124 | wh ile (exist sInDatabas e) { | |
| 125 | // g enerate 4 digit # an d update s ubject wit h 4 digit # | |
| 126 | upda tedValue = value.sub string(0, value.inde xOf("_?") + 1) + new Random(). nextInt(99 99); | |
| 127 | ||
| 128 | // http:// URL /mvp-schem a#Definiti on_#### ex ists in Je na | |
| 129 | Stri ng sparqlQ uery = Str ing.format (propsUtil .getGenera tedUriExis tsSparqlQu ery(), upd atedValue, updatedVa lue, updat edValue); | |
| 130 | exis tsInDataba se = fusek iClient.pe rformAsk(s parqlQuery , propsUti l.getSparq lEndpoint( )); | |
| 131 | } | |
| 132 | // add to UR IHashMap | |
| 133 | ur iHashMap.p ut(value, updatedVal ue); | |
| 134 | up datedValue = (valueH asAngularB racket) ? "<" + upda tedValue + ">" : upd atedValue; | |
| 135 | } | |
| 136 | } | |
| 137 | } | |
| 138 | } ca tch (Excep tion e) { | |
| 139 | LOGGER .error("Er ror in gen erateUri", e); | |
| 140 | throw new TSIner nalSystemE xception(" Error in g enerateUri ", e); | |
| 141 | } fi nally { | |
| 142 | if (qe != null & & !qe.isCl osed()) { | |
| 143 | qe.close (); | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | retu rn updated Value; | |
| 148 | } | |
| 149 | ||
| 150 | // TODO: fix angular b rackets ha rdcoding | |
| 151 | @S uppressWar nings("unu sed") | |
| 152 | pr ivate Stri ng getAskF orm(Triple DTO triple ) { | |
| 153 | if ( null == tr iple) { | |
| 154 | return null; | |
| 155 | } el se { | |
| 156 | return "ASK { " + quoteUri (triple.ge tS()) + " " + quoteU ri(triple. getP()) + " " + quot eUri(tripl e.getO()) + " }"; | |
| 157 | } | |
| 158 | } | |
| 159 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.