@@ -90,67 +90,30 @@ public RestHighLevelClient getRestClient() {
9090 public static final String INDEX = "harvester" ;
9191 private static final String TYPE = "oai" ;
9292
93- // private DocumentService documentService = null;
94- // private IndexService indexService = null;
95- // private SearchService searchService = null;
96- // private IndexRequest request;
97-
98- // @Autowired
99- // public OaiService(DocumentService documentService, IndexService indexService, SearchService searchService) {
100- // this.documentService = documentService;
101- // this.indexService = indexService;
102- //// indexService.createIndex();
103- // this.searchService = searchService;
104- // }
93+
10594 @ Autowired
10695 public OaiService ()
10796 {
10897
10998 }
11099
111100 public void elasticSave (Article article ) throws IOException {
112- // System.out.println("inside elasticsave");
113-
114- // IndexRequest request = new IndexRequest(INDEX, TYPE).setEntity(article);
115- // System.out.println("before article get Article Identifier");
116- // System.out.println(article.getArticleIdentifier());
117- // if (article.getArticleIdentifier() != null) {
118- // request.setId(String.valueOf(article.getId()));
119- // System.out.println("inside article getid");
120101 IndexRequest request = new IndexRequest (INDEX ,TYPE );
121102 request .setPipeline ("academic-pdf" );
122- // System.out.println(new Gson().toJson(article));
123- request .source (new Gson ().toJson (article ), XContentType .JSON );
103+ // before using this pipeline we have to add pipeline to the elasticsearch by following command
104+ // PUT _ingest/pipeline/academic-pdf
105+ // {
106+ // "description": "parse pdfs and index into ES",
107+ // "processors" :
108+ // [
109+ // { "attachment" : { "field": "pdf" } },
110+ // { "remove" : { "field": "pdf" } }
111+ // ]
124112// }
125113
126-
127-
114+ request .source (new Gson ().toJson (article ), XContentType .JSON );
128115 IndexResponse indexResponse = restClient .index (request );
129116
130- // String index = indexResponse.getIndex();
131- // String type = indexResponse.getType();
132- // String id = indexResponse.getId();
133- // long version = indexResponse.getVersion();
134- // System.out.println(index+" ,"+type+", "+id+", "+version);
135- // if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
136- //
137- // } else if (indexResponse.getResult() == DocWriteResponse.Result.UPDATED) {
138- //
139- // }
140- // ReplicationResponse.ShardInfo shardInfo = indexResponse.getShardInfo();
141- // if (shardInfo.getTotal() != shardInfo.getSuccessful()) {
142- //
143- // }
144- // if (shardInfo.getFailed() > 0) {
145- // for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {
146- // String reason = failure.reason();
147- // }
148- // }
149-
150-
151-
152-
153- // return documentService.index(request);
154117 }
155118
156119
@@ -179,11 +142,9 @@ public void saveRecords(List<RecordType> recordTypes) {
179142 oaiRecord .setState (0 );
180143 oaiRecords .add (oaiRecord );
181144
145+ //TODO: we ave to check all the parts name and assigned according to related name not order
182146 String [] parts = parsedDc .getDc ().split (";;" );
183147 Article article = new Article ();
184- // System.out.println("article create sonrasi article id : "+article.getId());
185- // System.out.println("article create sonrasi oai id : "+oaiRecord.getId());
186-
187148 article .setTitle (parts [0 ].split ("::" )[1 ]);
188149 article .setAuthors (parts [1 ].split ("::" )[1 ]);
189150 article .setKeywords (parts [2 ].split ("::" )[1 ]);
@@ -195,23 +156,18 @@ public void saveRecords(List<RecordType> recordTypes) {
195156 {
196157 String downlaodUrl = parts [10 ].split ("::" )[1 ];
197158 article .setRelation (downlaodUrl );
198- // article.setBase64("not available");
199159 article .setBase64 (UrlPdftoBase64 (downlaodUrl ));
200160 }
201161 else
202162 {
203163 article .setRelation ("not available" );
204- article .setBase64 ("bm90IGF2YWlsYWJsZQ==" );
164+ article .setBase64 ("bm90IGF2YWlsYWJsZQ==" ); //it means not available in base 64
205165 }
206166 article .setDc (parsedDc .getDc ());
207167 article .setArticleIdentifier (parseIdentifier (oaiRecord .getIdentifier ()));
208- // article.setArticleIdentifier(oaiRecord.getIdentifier());
209168
210- // System.out.println("article add oncesi article id : "+article.getId());
211169 articles .add (article );
212170
213- // System.out.println("elastic save oncesi article id : "+article.getId());
214- // System.out.println("elastic save oncesi article title : "+article.getTitle());
215171 try {
216172 elasticSave (article );
217173 } catch (IOException e ) {
@@ -247,13 +203,8 @@ public String UrlPdftoBase64(String url) {
247203 try {
248204 oracle = new URL (url );
249205 URLConnection yc = oracle .openConnection ();
250- // BufferedReader in = new BufferedReader(new InputStreamReader(
251- // yc.getInputStream()));
206+
252207 BufferedInputStream bis = new BufferedInputStream (yc .getInputStream ());
253- // String inputLine;
254- // while ((inputLine = in.readLine()) != null)
255- // System.out.println(inputLine);
256- // in.close();
257208
258209 byte bytes [] = IOUtils .toByteArray (bis );
259210 bis .close ();
@@ -266,31 +217,8 @@ public String UrlPdftoBase64(String url) {
266217 e .printStackTrace ();
267218 }
268219
269-
270-
271-
272220 return base64 ;
273221
274- // String inputLine;
275- // while ((inputLine = in.readLine()) != null)
276- // System.out.println(inputLine);
277- // in.close();
278-
279-
280-
281-
282- // BufferedReader in = new BufferedReader(
283- // new InputStreamReader(oracle.openStream()));
284- // byte bytes[] = IOUtils.toByteArray(oracle);
285-
286-
287- // String b64String = Base64.
288-
289- // String inputLine;
290- // while ((inputLine = in.readLine()) != null)
291- // System.out.println(inputLine);
292- // in.close();
293-
294222 }
295223
296224 private LocalDateTime parseDateTime (String string ) {
0 commit comments