Produced by Araxis Merge on 12/21/2017 6:15:13 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\Service\term-service\src\main\java\gov\va\genisis2\ts\service\impl | SolrService.java | Thu Dec 14 19:57:17 2017 UTC |
| 2 | Genisis_2.0_v7_bld7.zip\TS\Service\term-service\src\main\java\gov\va\genisis2\ts\service\impl | SolrService.java | Thu Dec 21 22:12:34 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 440 |
| 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.ts.ser vice.impl; | |
| 2 | ||
| 3 | import jav a.io.IOExc eption; | |
| 4 | import jav a.util.Has hMap; | |
| 5 | import jav a.util.Lis t; | |
| 6 | import jav a.util.Map ; | |
| 7 | import jav a.util.Opt ional; | |
| 8 | import jav a.util.fun ction.Supp lier; | |
| 9 | import jav a.util.reg ex.Pattern ; | |
| 10 | import jav a.util.str eam.Collec tors; | |
| 11 | ||
| 12 | import org .apache.lo gging.log4 j.LogManag er; | |
| 13 | import org .apache.lo gging.log4 j.Logger; | |
| 14 | import org .apache.so lr.client. solrj.Solr Client; | |
| 15 | import org .apache.so lr.client. solrj.Solr Query; | |
| 16 | import org .apache.so lr.client. solrj.Solr ServerExce ption; | |
| 17 | import org .apache.so lr.client. solrj.resp onse.Query Response; | |
| 18 | import org .apache.so lr.client. solrj.resp onse.Updat eResponse; | |
| 19 | import org .apache.so lr.common. SolrDocume nt; | |
| 20 | import org .apache.so lr.common. SolrInputD ocument; | |
| 21 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 22 | import org .springfra mework.ste reotype.Se rvice; | |
| 23 | ||
| 24 | import gov .va.genisi s2.ts.conv erter.Solr ConceptDoc umentConve rter; | |
| 25 | import gov .va.genisi s2.ts.dto. ConceptCar dDTO; | |
| 26 | import gov .va.genisi s2.ts.serv ice.ISolrS ervice; | |
| 27 | import gov .va.genisi s2.ts.util s.TSProper tiesUtil; | |
| 28 | ||
| 29 | /** | |
| 30 | * | |
| 31 | * @author PII | |
| 32 | * | |
| 33 | */ | |
| 34 | @Service | |
| 35 | public cla ss SolrSer vice imple ments ISol rService { | |
| 36 | ||
| 37 | pr ivate stat ic final L ogger LOGG ER = LogMa nager.getL ogger(Solr Service.cl ass); | |
| 38 | ||
| 39 | pr ivate stat ic final S tring ID = "id"; | |
| 40 | pr ivate stat ic final S tring LABE L = "Label "; | |
| 41 | pr ivate stat ic final S tring DEFI NITION = " Definition "; | |
| 42 | pr ivate stat ic final S tring ALT_ DEFINITION = "Alt_De finition"; | |
| 43 | pr ivate stat ic final S tring SYNO NYMS = "Sy nonyms"; | |
| 44 | pr ivate stat ic final S tring PARE NT = "Pare nt"; | |
| 45 | pr ivate stat ic final S tring CHIL D = "Child "; | |
| 46 | pr ivate stat ic final S tring SOUR CE_ONTOLOG Y = "Sourc e_Ontology "; | |
| 47 | pr ivate stat ic final S tring DATA _ELEMENT_M APPING = " Data_Eleme nt_Mapping "; | |
| 48 | pr ivate stat ic final S tring VERS ION = "_ve rsion_"; | |
| 49 | ||
| 50 | // Solr query needs to be escaped | |
| 51 | pr ivate stat ic final P attern SPE CIAL_CHARS = Pattern .compile(" [{}()\\[\\ ]:+*?^$\\\ \|]"); | |
| 52 | ||
| 53 | @A utowired | |
| 54 | pr ivate Solr ConceptDoc umentConve rter docum entConvert er; | |
| 55 | ||
| 56 | @A utowired | |
| 57 | pr ivate TSPr opertiesUt il propsUt il; | |
| 58 | ||
| 59 | @S uppressWar nings("unu sed") | |
| 60 | @O verride | |
| 61 | pu blic void addTripleT oSolrDocum ent(List<C onceptCard DTO> conce ptCards, S olrClient solrClient ) { | |
| 62 | ||
| 63 | Map< String, So lrConceptD ocument> d ocumentMap = new Has hMap<Strin g, SolrCon ceptDocume nt>(); | |
| 64 | for (ConceptCa rdDTO conc ept : conc eptCards) { | |
| 65 | ||
| 66 | SolrCo nceptDocum ent solrDo cument = d ocumentCon verter.con vert(conce pt); | |
| 67 | ||
| 68 | if (!d ocumentMap .containsK ey(solrDoc ument.getI d())) { | |
| 69 | // check for data element ma pping here ?? | |
| 70 | document Map.put(so lrDocument .getId(), solrDocume nt); | |
| 71 | } else { | |
| 72 | SolrConc eptDocumen t existing Doc = docu mentMap.ge t(solrDocu ment.getId ()); | |
| 73 | ||
| 74 | // coale se with th e new docu ment here | |
| 75 | SolrConc eptDocumen t combined Doc = comb ineConcept Document(s olrDocumen t, existin gDoc); | |
| 76 | ||
| 77 | // place the docum ent back i nto the ma p | |
| 78 | document Map.put(co mbinedDoc. getId(), c ombinedDoc ); | |
| 79 | } | |
| 80 | } | |
| 81 | // h ere you sh ould have a map that contains batch chan ge of docu ments | |
| 82 | // t his list s hould have unique id s | |
| 83 | ||
| 84 | // n ow on to t he the wor k... | |
| 85 | ||
| 86 | for (Map.Entry <String, S olrConcept Document> entry : do cumentMap. entrySet() ) { | |
| 87 | SolrCo nceptDocum ent docume nt = entry .getValue( ); | |
| 88 | SolrQu ery solrQu ery = new SolrQuery( ID + ":" + | |
| 89 | solrRegexQ uery(docum ent.getId( ))); | |
| 90 | ||
| 91 | try { | |
| 92 | QueryRes ponse resp onse = sol rClient.qu ery(solrQu ery); | |
| 93 | UpdateRe sponse upd ateRespons e; | |
| 94 | ||
| 95 | Optional <SolrDocum ent> oldDo c = resolv e(() -> re sponse.get Results(). get(0)); | |
| 96 | ||
| 97 | if (oldD oc.isPrese nt()) { | |
| 98 | ||
| 99 | // delete the old gu y! | |
| 100 | updateResp onse = sol rClient.de leteById(d ocument.ge tId()); | |
| 101 | solrClient .commit(); //commit changed im mediately | |
| 102 | ||
| 103 | SolrDocume nt theOldD oc = oldDo c.get(); | |
| 104 | ||
| 105 | // update the old do cuments | |
| 106 | theOldDoc. setField(D EFINITION, document. getDefinit ion()); | |
| 107 | theOldDoc. setField(A LT_DEFINIT ION, docum ent.getAlt Definition ()); | |
| 108 | theOldDoc. setField(S YNONYMS, d ocument.ge tSynonyms( )); | |
| 109 | theOldDoc. setField(P ARENT, doc ument.getP arent()); | |
| 110 | theOldDoc. setField(C HILD, docu ment.getCh ild()); | |
| 111 | ||
| 112 | updateResp onse = sol rClient.ad d(toSolrIn putDocumen t(theOldDo c)); | |
| 113 | ||
| 114 | } else { | |
| 115 | // the doc ument does nt exist s o create a new one a nd add | |
| 116 | SolrInputD ocument ne wInputDoc = new Solr InputDocum ent(); | |
| 117 | ||
| 118 | newInputDo c.addField (ID, docum ent.getId( )); | |
| 119 | newInputDo c.addField (LABEL, do cument.get Label()); | |
| 120 | newInputDo c.addField (DEFINITIO N, documen t.getDefin ition()); | |
| 121 | newInputDo c.addField (ALT_DEFIN ITION, doc ument.getA ltDefiniti on()); | |
| 122 | newInputDo c.addField (SYNONYMS, document. getSynonym s()); | |
| 123 | newInputDo c.addField (PARENT, d ocument.ge tParent()) ; | |
| 124 | newInputDo c.addField (CHILD, do cument.get Child()); | |
| 125 | newInputDo c.addField (SOURCE_ON TOLOGY, do cument.get SourceOnto logy()); | |
| 126 | newInputDo c.addField (DATA_ELEM ENT_MAPPIN G, documen t.getDataE lementMapp ing()); | |
| 127 | ||
| 128 | updateResp onse = sol rClient.ad d(newInput Doc); | |
| 129 | ||
| 130 | } | |
| 131 | updateRe sponse = s olrClient. commit(); | |
| 132 | } catc h (SolrSer verExcepti on | IOExc eption e) { | |
| 133 | LOGGER.e rror(e.get Message()) ; | |
| 134 | } | |
| 135 | } | |
| 136 | } | |
| 137 | ||
| 138 | /* * | |
| 139 | * Combines new docume nt informa tion into an existin g document | |
| 140 | * @param co nceptUris | |
| 141 | * @param so lrClient | |
| 142 | * @return O ld documen t with the combined new inform ation | |
| 143 | * / | |
| 144 | @O verride | |
| 145 | pu blic void deleteTrip leToSolrDo cument(Lis t<String> conceptUri s, SolrCli ent solrCl ient) { | |
| 146 | ||
| 147 | Upda teResponse response; | |
| 148 | try { | |
| 149 | respo nse = solr Client.del eteById(co nceptUris | |
| 150 | .stream() | |
| 151 | .distinct () | |
| 152 | .collect( Collectors .toList()) ); | |
| 153 | ||
| 154 | solrC lient.comm it(); | |
| 155 | }cat ch (SolrSe rverExcept ion | IOEx ception e) { | |
| 156 | LOGGER .error(e.g etMessage( )); | |
| 157 | } | |
| 158 | } | |
| 159 | ||
| 160 | /* * | |
| 161 | * Combines new docume nt informa tion into an existin g document | |
| 162 | * @param ne wDoc | |
| 163 | * @param ol dDoc | |
| 164 | * @return O ld documen t with the combined new inform ation | |
| 165 | * / | |
| 166 | pu blic SolrC onceptDocu ment combi neConceptD ocument(So lrConceptD ocument ne wDoc, Solr ConceptDoc ument oldD oc) { | |
| 167 | oldD oc.setDefi nition(old Doc.getDef inition() + " " +new Doc.getDef inition()) ; | |
| 168 | oldD oc.setAltD efinition( oldDoc.get AltDefinit ion() + " " + newDoc .getAltDef inition()) ; | |
| 169 | oldD oc.setSyno nyms(oldDo c.getSynon yms() + " " + newDoc .getSynony ms()); | |
| 170 | oldD oc.setPare nt(oldDoc. getParent( ) + " " + newDoc.get Parent()); | |
| 171 | oldD oc.setChil d(oldDoc.g etChild() + " " + ne wDoc.getCh ild()); | |
| 172 | ||
| 173 | retu rn oldDoc; | |
| 174 | } | |
| 175 | ||
| 176 | /* * | |
| 177 | * Resolves a supplier function to check f or nulls | |
| 178 | * @param re solver | |
| 179 | * @return t he optiona l object o r null if found | |
| 180 | * / | |
| 181 | pr ivate stat ic <T> Opt ional<T> r esolve(Sup plier<T> r esolver) { | |
| 182 | try { | |
| 183 | T resu lt = resol ver.get(); | |
| 184 | return Optional. ofNullable (result); | |
| 185 | } ca tch (Excep tion e) { | |
| 186 | return Optional. empty(); | |
| 187 | } | |
| 188 | } | |
| 189 | ||
| 190 | /* * | |
| 191 | * Convert a SorlDocum ent into a n SolrInpu tDocument for transm ission | |
| 192 | * | |
| 193 | * @param so lrDoc | |
| 194 | * @return S olrInputDo cument | |
| 195 | * / | |
| 196 | pu blic SolrI nputDocume nt toSolrI nputDocume nt(SolrDoc ument solr Doc) { | |
| 197 | Solr InputDocum ent doc = new SolrIn putDocumen t(); | |
| 198 | ||
| 199 | for (String na me : solrD oc.getFiel dNames()) { | |
| 200 | doc.ad dField(nam e, solrDoc .getFieldV alue(name) ); | |
| 201 | } | |
| 202 | //ig nore versi oning info rmation fo r now | |
| 203 | doc. setField(V ERSION, 0) ; | |
| 204 | if( isDataElem entPrefix( (String) solrDoc.ge t(ID))) | |
| 205 | doc.se tField(DAT A_ELEMENT_ MAPPING, t rue, 100); //adding boost valu e | |
| 206 | retu rn doc; | |
| 207 | } | |
| 208 | ||
| 209 | pu blic bool ean isData ElementPre fix(String uri) { | |
| 210 | retu rn uri.sta rtsWith(pr opsUtil.ge tBaselineS urveyPrefi x()); | |
| 211 | } | |
| 212 | ||
| 213 | /* * | |
| 214 | * Regex use d to escap e characte rs for a s olr query | |
| 215 | * @param qu ery | |
| 216 | * @return e scaped que ry form | |
| 217 | * / | |
| 218 | pr ivate stat ic String solrRegexQ uery(Strin g query) { | |
| 219 | retu rn SPECIAL _CHARS.mat cher(query ).replaceA ll("\\\\$0 "); | |
| 220 | } | |
| 221 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.