1
1
package com .groupdocs .ui ;
2
2
3
3
import com .groupdocs .annotation .common .license .License ;
4
+ import com .groupdocs .annotation .domain .AnnotationInfo ;
4
5
import com .groupdocs .annotation .domain .config .AnnotationConfig ;
6
+ import com .groupdocs .annotation .domain .results .CreateAnnotationResult ;
5
7
import com .groupdocs .annotation .handler .AnnotationImageHandler ;
6
8
import com .groupdocs .annotation .handler .input .IDocumentDataHandler ;
7
9
import com .groupdocs .annotation .handler .input .dataobjects .Document ;
8
10
9
- import java .io .FileInputStream ;
10
11
import java .io .IOException ;
11
12
import java .io .InputStream ;
12
- import java .nio .file .FileSystem ;
13
13
import java .nio .file .FileSystems ;
14
14
import java .nio .file .Files ;
15
+ import java .nio .file .Path ;
16
+ import java .nio .file .Paths ;
17
+ import java .util .Arrays ;
15
18
import java .util .Properties ;
16
19
17
20
public class Utils {
@@ -22,28 +25,39 @@ public class Utils {
22
25
23
26
public static AnnotationImageHandler createAnnotationImageHandler () {
24
27
AnnotationConfig cfg = new AnnotationConfig ();
25
- cfg .setStoragePath (getStoragePath ());
28
+ cfg .setStoragePath (getStoragePath (). toString () );
26
29
AnnotationImageHandler annotator = new AnnotationImageHandler (cfg );
27
30
return annotator ;
28
31
29
32
}
30
33
31
- public static Document findDocumentByName (String name ) {
34
+ synchronized public static Document findDocumentByName (String name ) {
32
35
AnnotationImageHandler imageHandler = Utils .createAnnotationImageHandler ();
33
36
IDocumentDataHandler documentDataHandler = imageHandler .getDocumentDataHandler ();
34
37
Document doc = documentDataHandler .getDocument (name );
35
38
if (doc != null ) {
36
39
return doc ;
37
40
}
38
41
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 );
43
45
} catch (Exception x ) {
44
46
throw new RuntimeException (x );
45
47
}
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 ;
47
61
}
48
62
49
63
public static void loadLicense () {
@@ -56,10 +70,14 @@ public static void loadLicense() {
56
70
}
57
71
}
58
72
59
- public static String getStoragePath () {
73
+ public static String getSt__oragePath () {
60
74
return getProjectProperty ("storage.path" );
61
75
}
62
76
77
+ public static Path getStoragePath (String ... name ) {
78
+ return Paths .get (getProjectProperty ("storage.path" ), name );
79
+ }
80
+
63
81
public static String getProjectProperty (String name ) {
64
82
Properties p = new Properties ();
65
83
try (InputStream i = Utils .class .getResourceAsStream ("/project.properties" )) {
0 commit comments