18
18
19
19
import stroom .annotation .shared .Annotation ;
20
20
import stroom .annotation .shared .AnnotationDecorationFields ;
21
+ import stroom .annotation .shared .AnnotationTag ;
21
22
import stroom .annotation .shared .EventId ;
22
23
import stroom .expression .matcher .ExpressionMatcher ;
23
24
import stroom .expression .matcher .ExpressionMatcherFactory ;
44
45
45
46
import java .util .ArrayList ;
46
47
import java .util .Arrays ;
48
+ import java .util .Collection ;
47
49
import java .util .HashMap ;
48
50
import java .util .HashSet ;
49
51
import java .util .List ;
52
54
import java .util .Objects ;
53
55
import java .util .Set ;
54
56
import java .util .function .Function ;
57
+ import java .util .stream .Collectors ;
55
58
56
59
class AnnotationReceiverDecoratorFactory implements AnnotationsDecoratorFactory {
57
60
58
61
private static final LambdaLogger LOGGER = LambdaLoggerFactory .getLogger (AnnotationReceiverDecoratorFactory .class );
59
62
63
+ private static final Annotation DEFAULT_ANNOTATION = Annotation .builder ().build ();
64
+ private static AnnotationConfig ANNOTATION_CONFIG ;
65
+
60
66
private static final Map <String , Function <Annotation , Val >> VALUE_MAPPING = Map .ofEntries (
61
67
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_ID , Annotation ::getId ),
62
68
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_UUID , Annotation ::getUuid ),
@@ -66,7 +72,12 @@ class AnnotationReceiverDecoratorFactory implements AnnotationsDecoratorFactory
66
72
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_UPDATED_BY , Annotation ::getUpdateUser ),
67
73
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_TITLE , Annotation ::getName ),
68
74
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_SUBJECT , Annotation ::getSubject ),
69
- nullSafeEntry (AnnotationDecorationFields .ANNOTATION_STATUS , Annotation ::getStatus ),
75
+ nullSafeEntry (AnnotationDecorationFields .ANNOTATION_STATUS ,
76
+ AnnotationReceiverDecoratorFactory ::getStatusString ),
77
+ nullSafeEntry (AnnotationDecorationFields .ANNOTATION_LABEL , annotation ->
78
+ getTagString (annotation .getLabels ())),
79
+ nullSafeEntry (AnnotationDecorationFields .ANNOTATION_COLLECTION , annotation ->
80
+ getTagString (annotation .getCollections ())),
70
81
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_ASSIGNED_TO , annotation ->
71
82
NullSafe .get (annotation .getAssignedTo (), UserRef ::toDisplayString )),
72
83
nullSafeEntry (AnnotationDecorationFields .ANNOTATION_COMMENT , Annotation ::getComment ),
@@ -81,25 +92,52 @@ class AnnotationReceiverDecoratorFactory implements AnnotationsDecoratorFactory
81
92
Map .entry (AnnotationDecorationFields .ANNOTATION_UPDATED_BY , Annotation ::getUpdateUser ),
82
93
Map .entry (AnnotationDecorationFields .ANNOTATION_TITLE , Annotation ::getName ),
83
94
Map .entry (AnnotationDecorationFields .ANNOTATION_SUBJECT , Annotation ::getSubject ),
84
- Map .entry (AnnotationDecorationFields .ANNOTATION_STATUS , Annotation ::getStatus ),
95
+ Map .entry (AnnotationDecorationFields .ANNOTATION_STATUS ,
96
+ AnnotationReceiverDecoratorFactory ::getStatusString ),
97
+ Map .entry (AnnotationDecorationFields .ANNOTATION_LABEL , annotation ->
98
+ getTagString (annotation .getLabels ())),
99
+ Map .entry (AnnotationDecorationFields .ANNOTATION_COLLECTION , annotation ->
100
+ getTagString (annotation .getCollections ())),
85
101
Map .entry (AnnotationDecorationFields .ANNOTATION_ASSIGNED_TO , annotation ->
86
102
NullSafe .get (annotation .getAssignedTo (), UserRef ::toDisplayString )),
87
103
Map .entry (AnnotationDecorationFields .ANNOTATION_COMMENT , Annotation ::getComment ),
88
104
Map .entry (AnnotationDecorationFields .ANNOTATION_HISTORY , Annotation ::getHistory ));
89
105
90
106
private final AnnotationService annotationService ;
91
107
private final ExpressionMatcherFactory expressionMatcherFactory ;
108
+
92
109
private final SecurityContext securityContext ;
93
110
94
111
@ Inject
95
112
AnnotationReceiverDecoratorFactory (final AnnotationService annotationService ,
96
113
final ExpressionMatcherFactory expressionMatcherFactory ,
114
+ final AnnotationConfig annotationConfig ,
97
115
final SecurityContext securityContext ) {
98
116
this .annotationService = annotationService ;
99
117
this .expressionMatcherFactory = expressionMatcherFactory ;
118
+ ANNOTATION_CONFIG = annotationConfig ;
100
119
this .securityContext = securityContext ;
101
120
}
102
121
122
+ private static String getTagString (final Collection <AnnotationTag > tags ) {
123
+ if (tags == null ) {
124
+ return null ;
125
+ }
126
+ return tags .stream ().map (AnnotationTag ::getName ).collect (Collectors .joining ("|" ));
127
+ }
128
+
129
+ private static String getStatusString (final Annotation annotation ) {
130
+ String value = NullSafe .get (ANNOTATION_CONFIG , AnnotationConfig ::getCreateText );
131
+ if (annotation != null ) {
132
+ if (annotation .getStatus () != null ) {
133
+ value = annotation .getStatus ().getName ();
134
+ } else if (annotation .getId () != null ) {
135
+ value = "None" ;
136
+ }
137
+ }
138
+ return value ;
139
+ }
140
+
103
141
@ Override
104
142
public ValuesConsumer create (final ValuesConsumer valuesConsumer ,
105
143
final FieldIndex fieldIndex ,
@@ -122,8 +160,6 @@ public ValuesConsumer create(final ValuesConsumer valuesConsumer,
122
160
return valuesConsumer ;
123
161
}
124
162
125
- final Annotation defaultAnnotation = createDefaultAnnotation ();
126
-
127
163
return values -> {
128
164
// TODO : At present we are just going to do this synchronously but in future we may do asynchronously
129
165
// in which case we would increment the completion count after providing values.
@@ -148,7 +184,7 @@ public ValuesConsumer create(final ValuesConsumer valuesConsumer,
148
184
}
149
185
150
186
if (annotations .isEmpty ()) {
151
- annotations .add (defaultAnnotation );
187
+ annotations .add (DEFAULT_ANNOTATION );
152
188
}
153
189
154
190
Val [] copy = values ;
@@ -174,10 +210,6 @@ public ValuesConsumer create(final ValuesConsumer valuesConsumer,
174
210
};
175
211
}
176
212
177
- private Annotation createDefaultAnnotation () {
178
- return Annotation .builder ().build ();
179
- }
180
-
181
213
private Function <Annotation , Boolean > createFilter (final ExpressionOperator expression ) {
182
214
final ExpressionFilter expressionFilter = ExpressionFilter .builder ()
183
215
.addPrefixIncludeFilter (AnnotationDecorationFields .ANNOTATION_FIELD_PREFIX )
@@ -237,7 +269,7 @@ private void setValue(final Val[] values,
237
269
} else {
238
270
val = ValNull .INSTANCE ;
239
271
}
240
- } catch (Exception e ) {
272
+ } catch (final Exception e ) {
241
273
throw new RuntimeException (e );
242
274
}
243
275
values [index ] = val ;
0 commit comments