1-
21/*******************************************************************************
3- * Copyright 2023 Dell Inc.
4- *
5- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6- * in compliance with the License. You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software distributed under the License
11- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12- * or implied. See the License for the specific language governing permissions and limitations under
13- * the License.
14- *******************************************************************************/
2+ * Copyright 2022 Dell Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+ * in compliance with the License. You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+ * or implied. See the License for the specific language governing permissions and limitations under
12+ * the License.
13+ *******************************************************************************/
1514package com .alvarium ;
1615
1716import java .util .ArrayList ;
@@ -39,7 +38,8 @@ public class DefaultSdk implements Sdk {
3938 private final StreamProvider stream ;
4039 private final Logger logger ;
4140
42- public DefaultSdk (Annotator [] annotators , SdkInfo config , Logger logger ) throws StreamException {
41+ public DefaultSdk (Annotator [] annotators , SdkInfo config , Logger logger )
42+ throws StreamException {
4343 this .annotators = annotators ;
4444 this .config = config ;
4545 this .logger = logger ;
@@ -51,37 +51,35 @@ public DefaultSdk(Annotator[] annotators, SdkInfo config, Logger logger) throws
5151 this .logger .debug ("stream provider connected successfully." );
5252 }
5353
54- public void create (PropertyBag properties , byte [] data ) throws AnnotatorException ,
55- StreamException {
54+ public void create (PropertyBag properties , byte [] data )
55+ throws AnnotatorException , StreamException {
5656 final List <Annotation > annotations = this .createAnnotations (properties , data );
5757 this .publishAnnotations (SdkAction .CREATE , annotations );
5858 this .logger .debug ("data annotated and published successfully." );
5959 }
60-
60+
6161 public void create (byte [] data ) throws AnnotatorException , StreamException {
6262 final PropertyBag properties = new ImmutablePropertyBag (new HashMap <String , Object >());
6363 this .create (properties , data );
6464 }
6565
66- public void mutate (PropertyBag properties , byte [] oldData , byte [] newData ) throws
67- AnnotatorException , StreamException {
66+ public void mutate (PropertyBag properties , byte [] oldData , byte [] newData )
67+ throws AnnotatorException , StreamException {
6868 final List <Annotation > annotations = new ArrayList <Annotation >();
6969
7070 // source annotate the old data
7171 final AnnotatorFactory annotatorFactory = new AnnotatorFactory ();
72- final Annotator sourceAnnotator = annotatorFactory .getAnnotator (
73- new AnnotatorConfig (AnnotationType .SOURCE ),
74- this .config ,
75- this .logger
76- );
72+ final Annotator sourceAnnotator =
73+ annotatorFactory .getAnnotator (
74+ new AnnotatorConfig (AnnotationType .SOURCE ), this .config , this .logger );
7775 final Annotation sourceAnnotation = sourceAnnotator .execute (properties , oldData );
7876 annotations .add (sourceAnnotation );
7977
8078 // Add annotations for new data
81- for (Annotation annotation : this .createAnnotations (properties , newData )) {
79+ for (Annotation annotation : this .createAnnotations (properties , newData )) {
8280 // TLS is ignored in mutate to prevent needless penalization
8381 // See https://github.com/project-alvarium/alvarium-sdk-go/issues/19
84- if (annotation .getKind () != AnnotationType .TLS ) {
82+ if (annotation .getKind () != AnnotationType .TLS ) {
8583 annotations .add (annotation );
8684 }
8785 }
@@ -96,8 +94,8 @@ public void mutate(byte[] oldData, byte[] newData) throws AnnotatorException, St
9694 this .mutate (properties , oldData , newData );
9795 }
9896
99- public void transit (PropertyBag properties , byte [] data ) throws AnnotatorException ,
100- StreamException {
97+ public void transit (PropertyBag properties , byte [] data )
98+ throws AnnotatorException , StreamException {
10199 final List <Annotation > annotations = this .createAnnotations (properties , data );
102100 this .publishAnnotations (SdkAction .TRANSIT , annotations );
103101 this .logger .debug ("data annotated and published successfully." );
@@ -108,13 +106,13 @@ public void transit(byte[] data) throws AnnotatorException, StreamException {
108106 this .transit (properties , data );
109107 }
110108
111- public void publish (PropertyBag properties , byte [] data ) throws AnnotatorException ,
112- StreamException {
109+ public void publish (PropertyBag properties , byte [] data )
110+ throws AnnotatorException , StreamException {
113111 final List <Annotation > annotations = this .createAnnotations (properties , data );
114112 this .publishAnnotations (SdkAction .PUBLISH , annotations );
115113 this .logger .debug ("data annotated and published successfully." );
116114 }
117-
115+
118116 public void publish (byte [] data ) throws AnnotatorException , StreamException {
119117 final PropertyBag properties = new ImmutablePropertyBag (new HashMap <String , Object >());
120118 this .publish (properties , data );
@@ -132,12 +130,12 @@ public void close() throws StreamException {
132130 * @return
133131 * @throws AnnotatorException
134132 */
135- private List <Annotation > createAnnotations (PropertyBag properties , byte [] data )
133+ private List <Annotation > createAnnotations (PropertyBag properties , byte [] data )
136134 throws AnnotatorException {
137135 final List <Annotation > annotations = new ArrayList <Annotation >();
138136
139137 // Annotate incoming data
140- for (Annotator annotator : this .annotators ) {
138+ for (Annotator annotator : this .annotators ) {
141139 final Annotation annotation = annotator .execute (properties , data );
142140 annotations .add (annotation );
143141 }
@@ -146,22 +144,19 @@ private List<Annotation> createAnnotations(PropertyBag properties, byte[] data)
146144 }
147145
148146 /**
149- * Wraps the annotation list with a publish wrapper that specifies the SDK action and the
147+ * Wraps the annotation list with a publish wrapper that specifies the SDK action and the
150148 * content type
151149 * @param action
152150 * @param annotations
153151 * @throws StreamException
154152 */
155- private void publishAnnotations (SdkAction action , List <Annotation > annotations )
153+ private void publishAnnotations (SdkAction action , List <Annotation > annotations )
156154 throws StreamException {
157155 final AnnotationList annotationList = new AnnotationList (annotations );
158-
156+
159157 // publish list of annotations to the StreamProvider
160- final PublishWrapper wrapper = new PublishWrapper (
161- action ,
162- annotationList .getClass ().getName (),
163- annotationList
164- );
158+ final PublishWrapper wrapper =
159+ new PublishWrapper (action , annotationList .getClass ().getName (), annotationList );
165160 this .stream .publish (wrapper );
166161 }
167162}
0 commit comments