20
20
import stroom .cache .api .LoadingStroomCache ;
21
21
import stroom .docref .DocRef ;
22
22
import stroom .docref .DocRefInfo ;
23
- import stroom .docstore .api .DocumentActionHandler ;
24
23
import stroom .docstore .api .DocumentActionHandlers ;
25
24
import stroom .docstore .api .DocumentNotFoundException ;
26
25
import stroom .security .api .SecurityContext ;
26
+ import stroom .util .NullSafe ;
27
27
import stroom .util .entityevent .EntityAction ;
28
28
import stroom .util .entityevent .EntityEvent ;
29
29
import stroom .util .entityevent .EntityEventHandler ;
35
35
import org .slf4j .Logger ;
36
36
import org .slf4j .LoggerFactory ;
37
37
38
+ import java .util .HashSet ;
38
39
import java .util .Objects ;
39
40
import java .util .Optional ;
41
+ import java .util .Set ;
40
42
41
43
@ Singleton
42
44
@ EntityEventHandler (action = {
@@ -53,15 +55,18 @@ class DocRefInfoCache implements EntityEvent.Handler, Clearable {
53
55
private final SecurityContext securityContext ;
54
56
// Provider to avoid circular guice dependency issue
55
57
private final Provider <DocumentActionHandlers > documentActionHandlersProvider ;
58
+ private final ExplorerActionHandlers explorerActionHandlers ;
56
59
57
60
58
61
@ Inject
59
62
DocRefInfoCache (final CacheManager cacheManager ,
60
63
final Provider <ExplorerConfig > explorerConfigProvider ,
61
64
final SecurityContext securityContext ,
62
- final Provider <DocumentActionHandlers > documentActionHandlersProvider ) {
65
+ final Provider <DocumentActionHandlers > documentActionHandlersProvider ,
66
+ final ExplorerActionHandlers explorerActionHandlers ) {
63
67
this .securityContext = securityContext ;
64
68
this .documentActionHandlersProvider = documentActionHandlersProvider ;
69
+ this .explorerActionHandlers = explorerActionHandlers ;
65
70
66
71
cache = cacheManager .createLoadingCache (
67
72
CACHE_NAME ,
@@ -76,28 +81,9 @@ private Optional<DocRefInfo> loadDocRefInfo(final DocRefCacheKey docRefCacheKey)
76
81
docRefInfo = securityContext .asProcessingUserResult (() -> {
77
82
final DocRef docRef = docRefCacheKey .getDocRef ();
78
83
if (docRef .getType () != null ) {
79
- final DocumentActionHandler <?> handler = documentActionHandlersProvider .get ()
80
- .getHandler (docRef .getType ());
81
- if (handler == null ) {
82
- return null ;
83
- }
84
- return handler .info (docRef .getUuid ());
84
+ return getDocRefInfoWithType (docRef );
85
85
} else {
86
- final String uuid = docRef .getUuid ();
87
- // No type so need to check all handlers and return the one that has it.
88
- // Hopefully next time it will still be in the cache so this won't be needed
89
- final Optional <DocRefInfo > optInfo = documentActionHandlersProvider .get ()
90
- .stream ()
91
- .map (handler -> {
92
- try {
93
- return handler .info (uuid );
94
- } catch (DocumentNotFoundException e ) {
95
- return null ;
96
- }
97
- })
98
- .filter (Objects ::nonNull )
99
- .findAny ();
100
- return optInfo .orElse (null );
86
+ return getDocRefInfoWithoutType (docRef );
101
87
}
102
88
});
103
89
} catch (final RuntimeException e ) {
@@ -106,6 +92,58 @@ private Optional<DocRefInfo> loadDocRefInfo(final DocRefCacheKey docRefCacheKey)
106
92
return Optional .ofNullable (docRefInfo );
107
93
}
108
94
95
+ private DocRefInfo getDocRefInfoWithoutType (final DocRef docRef ) {
96
+ final String uuid = docRef .getUuid ();
97
+ // No type so need to check all handlers and return the one that has it.
98
+ // Hopefully next time it will still be in the cache so this won't be needed
99
+ final Set <String > typesChecked = new HashSet <>();
100
+ final Optional <DocRefInfo > optInfo = documentActionHandlersProvider .get ()
101
+ .stream ()
102
+ .map (handler -> {
103
+ typesChecked .add (handler .getType ());
104
+ try {
105
+ return handler .info (uuid );
106
+ } catch (DocumentNotFoundException e ) {
107
+ return null ;
108
+ }
109
+ })
110
+ .filter (Objects ::nonNull )
111
+ .findAny ();
112
+
113
+ // Folder is not a DocumentActionHandler so check in ExplorerActionHandlers
114
+ return optInfo
115
+ .or (() ->
116
+ explorerActionHandlers .stream ()
117
+ .filter (handler ->
118
+ !typesChecked .contains (handler .getDocumentType ().getType ()))
119
+ .map (handler -> {
120
+ try {
121
+ return handler .info (uuid );
122
+ } catch (DocumentNotFoundException e ) {
123
+ return null ;
124
+ }
125
+ })
126
+ .filter (Objects ::nonNull )
127
+ .findAny ())
128
+ .orElse (null );
129
+ }
130
+
131
+ private DocRefInfo getDocRefInfoWithType (final DocRef docRef ) {
132
+ final String type = docRef .getType ();
133
+ final String uuid = docRef .getUuid ();
134
+
135
+ DocRefInfo docRefInfo = NullSafe .get (
136
+ documentActionHandlersProvider .get ().getHandler (type ),
137
+ handler -> handler .info (uuid ));
138
+
139
+ if (docRefInfo == null ) {
140
+ docRefInfo = NullSafe .get (
141
+ explorerActionHandlers .getHandler (type ),
142
+ handler -> handler .info (uuid ));
143
+ }
144
+ return docRefInfo ;
145
+ }
146
+
109
147
Optional <DocRefInfo > get (final DocRef docRef ) {
110
148
return cache .get (new DocRefCacheKey (docRef ));
111
149
}
0 commit comments