|
33 | 33 | import java.awt.geom.AffineTransform;
|
34 | 34 | import java.awt.image.AffineTransformOp;
|
35 | 35 | import java.awt.image.BufferedImage;
|
36 |
| -import java.io.ByteArrayInputStream; |
37 |
| -import java.io.ByteArrayOutputStream; |
38 |
| -import java.io.IOException; |
| 36 | +import java.io.*; |
39 | 37 | import java.net.URL;
|
40 | 38 | import java.util.*;
|
41 | 39 | import java.util.List;
|
@@ -303,6 +301,52 @@ ResponseEntity<byte[]> getStoreImage(@PathVariable Long id,@RequestParam(require
|
303 | 301 | }
|
304 | 302 | }
|
305 | 303 |
|
| 304 | + @RequestMapping(value = "/index/file", |
| 305 | + method = RequestMethod.POST, |
| 306 | + produces = MediaType.APPLICATION_JSON_VALUE) |
| 307 | + @Timed |
| 308 | + @RolesAllowed(AuthoritiesConstants.ADMIN) |
| 309 | + public void indexFile( |
| 310 | + @RequestParam(required = true) String file, |
| 311 | + @RequestParam(required = false,defaultValue = "false") Boolean async |
| 312 | + ) throws CBIRException, IOException { |
| 313 | + log.debug("REST request to INDEX FULL : file="+file + " async="+async); |
| 314 | + log.debug("REST request to INDEX FULL : file="+new File(file).getAbsolutePath()); |
| 315 | + StringBuffer jsonString = new StringBuffer(); |
| 316 | + |
| 317 | + FileReader fr = new FileReader(new File(file)); |
| 318 | + BufferedReader br = new BufferedReader(fr); |
| 319 | + String line; |
| 320 | + while((line = br.readLine()) != null){ |
| 321 | + jsonString.append(line); |
| 322 | + } |
| 323 | + br.close(); |
| 324 | + fr.close(); |
| 325 | + |
| 326 | + List<Object> list = new JacksonJsonParser().parseList(jsonString.toString()); |
| 327 | + |
| 328 | + for(Object entry : list) { |
| 329 | + try { |
| 330 | + Map map = (Map) entry;//new JacksonJsonParser().parseMap((String)entry); |
| 331 | + Long id = Long.parseLong(map.get("id").toString()); |
| 332 | + String storage = map.get("storage").toString(); |
| 333 | + String cropURL = map.get("url").toString(); |
| 334 | + //read images if on disk |
| 335 | + boolean saveImage = true; |
| 336 | + BufferedImage image = null; |
| 337 | + try { |
| 338 | + image = storeImageService.readIndexImage(id); |
| 339 | + saveImage = false; //don't save image, already on disk! |
| 340 | + } catch (Exception e) { |
| 341 | + image = ImageIO.read(new URL(cropURL)); |
| 342 | + } |
| 343 | + indexPicture(id, storage, "", "", async, image, retrievalService.getRetrievalServer(),saveImage); |
| 344 | + } catch(Exception e) { |
| 345 | + log.error(e.toString()); |
| 346 | + } |
| 347 | + } |
| 348 | + } |
| 349 | + |
306 | 350 | @RequestMapping(value = "/index/full",
|
307 | 351 | method = RequestMethod.POST,
|
308 | 352 | produces = MediaType.APPLICATION_JSON_VALUE)
|
@@ -335,9 +379,6 @@ public void indexFull(
|
335 | 379 | log.error(e.toString());
|
336 | 380 | }
|
337 | 381 | }
|
338 |
| - |
339 |
| - |
340 |
| - |
341 | 382 | }
|
342 | 383 |
|
343 | 384 | private ResponseEntity<ResultsJSON> doSearchSim(Integer max, String storages, BufferedImage image, Boolean saveImage) throws ResourceNotValidException, IOException {
|
|
0 commit comments