Skip to content

Commit fe78f91

Browse files
committed
indewx full with async mode
1 parent 28ef0da commit fe78f91

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/main/java/org/cbir/retrieval/Application.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import javax.annotation.PostConstruct;
1818
import javax.inject.Inject;
1919
import javax.servlet.ServletContext;
20+
import java.io.File;
2021
import java.io.IOException;
2122
import java.nio.file.Files;
2223
import java.nio.file.Path;
@@ -44,6 +45,7 @@ public class Application {
4445
@PostConstruct
4546
public void initApplication() throws IOException {
4647
log.info("*** initApplication ***");
48+
log.info("HOME="+new File("./").getAbsolutePath());
4749
log.info(System.getProperty("spring.profiles.active"));
4850
log.info(Arrays.toString(env.getActiveProfiles()));
4951

src/main/java/org/cbir/retrieval/web/rest/ImageResource.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
import java.awt.geom.AffineTransform;
3434
import java.awt.image.AffineTransformOp;
3535
import java.awt.image.BufferedImage;
36-
import java.io.ByteArrayInputStream;
37-
import java.io.ByteArrayOutputStream;
38-
import java.io.IOException;
36+
import java.io.*;
3937
import java.net.URL;
4038
import java.util.*;
4139
import java.util.List;
@@ -303,6 +301,52 @@ ResponseEntity<byte[]> getStoreImage(@PathVariable Long id,@RequestParam(require
303301
}
304302
}
305303

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+
306350
@RequestMapping(value = "/index/full",
307351
method = RequestMethod.POST,
308352
produces = MediaType.APPLICATION_JSON_VALUE)
@@ -335,9 +379,6 @@ public void indexFull(
335379
log.error(e.toString());
336380
}
337381
}
338-
339-
340-
341382
}
342383

343384
private ResponseEntity<ResultsJSON> doSearchSim(Integer max, String storages, BufferedImage image, Boolean saveImage) throws ResourceNotValidException, IOException {

0 commit comments

Comments
 (0)