11package com .groupdocs .ui ;
22
33import com .groupdocs .annotation .common .license .License ;
4+ import com .groupdocs .annotation .domain .AnnotationInfo ;
45import com .groupdocs .annotation .domain .config .AnnotationConfig ;
6+ import com .groupdocs .annotation .domain .results .CreateAnnotationResult ;
57import com .groupdocs .annotation .handler .AnnotationImageHandler ;
68import com .groupdocs .annotation .handler .input .IDocumentDataHandler ;
79import com .groupdocs .annotation .handler .input .dataobjects .Document ;
810
9- import java .io .FileInputStream ;
1011import java .io .IOException ;
1112import java .io .InputStream ;
12- import java .nio .file .FileSystem ;
1313import java .nio .file .FileSystems ;
1414import java .nio .file .Files ;
15+ import java .nio .file .Path ;
16+ import java .nio .file .Paths ;
17+ import java .util .Arrays ;
1518import java .util .Properties ;
1619
1720public class Utils {
@@ -22,28 +25,39 @@ public class Utils {
2225
2326 public static AnnotationImageHandler createAnnotationImageHandler () {
2427 AnnotationConfig cfg = new AnnotationConfig ();
25- cfg .setStoragePath (getStoragePath ());
28+ cfg .setStoragePath (getStoragePath (). toString () );
2629 AnnotationImageHandler annotator = new AnnotationImageHandler (cfg );
2730 return annotator ;
2831
2932 }
3033
31- public static Document findDocumentByName (String name ) {
34+ synchronized public static Document findDocumentByName (String name ) {
3235 AnnotationImageHandler imageHandler = Utils .createAnnotationImageHandler ();
3336 IDocumentDataHandler documentDataHandler = imageHandler .getDocumentDataHandler ();
3437 Document doc = documentDataHandler .getDocument (name );
3538 if (doc != null ) {
3639 return doc ;
3740 }
3841
39- long documentId = imageHandler .createDocument (name );
40-
41- try (InputStream original = new FileInputStream (Utils .getStoragePath () + "/" + name )) {
42- // imageHandler.importAnnotations(original, name);
42+ AnnotationInfo [] importedAnnotations ;
43+ try (InputStream original = Files .newInputStream (getStoragePath (name ))) {
44+ importedAnnotations = imageHandler .importAnnotations (original );
4345 } catch (Exception x ) {
4446 throw new RuntimeException (x );
4547 }
46- return documentDataHandler .get (documentId );
48+
49+ long documentId = imageHandler .createDocument (name );
50+ Arrays .stream (importedAnnotations )
51+ .forEach (ai -> {
52+ ai .setDocumentGuid (documentId );
53+ CreateAnnotationResult car = imageHandler .createAnnotation (ai );
54+ Arrays .stream (ai .getReplies ())
55+ .forEach (ari -> {
56+ imageHandler .createAnnotationReply (car .getId (), ari .getMessage ());
57+ });
58+ });
59+ doc = documentDataHandler .get (documentId );
60+ return doc ;
4761 }
4862
4963 public static void loadLicense () {
@@ -56,10 +70,14 @@ public static void loadLicense() {
5670 }
5771 }
5872
59- public static String getStoragePath () {
73+ public static String getSt__oragePath () {
6074 return getProjectProperty ("storage.path" );
6175 }
6276
77+ public static Path getStoragePath (String ... name ) {
78+ return Paths .get (getProjectProperty ("storage.path" ), name );
79+ }
80+
6381 public static String getProjectProperty (String name ) {
6482 Properties p = new Properties ();
6583 try (InputStream i = Utils .class .getResourceAsStream ("/project.properties" )) {
0 commit comments