Skip to content

Commit

Permalink
add spotless formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Override-6 committed Jun 13, 2024
1 parent 7e53f04 commit b36a102
Show file tree
Hide file tree
Showing 126 changed files with 4,229 additions and 4,152 deletions.
132 changes: 98 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,78 @@

<name>alvarium-sdk</name>
<url>https://alvarium.org/</url>


<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<formats>
<format>
<includes>
<include>.gitattributes</include>
<include>.gitignore</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>

</format>
</formats>
<java>
<googleJavaFormat>
<version>1.17.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
<formatJavadoc>false</formatJavadoc>
</googleJavaFormat>
<removeUnusedImports/>

<indent>
<tabs>true</tabs>
<spacesPerTab>2</spacesPerTab>
</indent>
<indent>
<spaces>true</spaces>
<spacesPerTab>1</spacesPerTab>
</indent>

<licenseHeader>
<content>/*******************************************************************************
* Copyright 2022 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
</content>
</licenseHeader>

<importOrder>
<order>java,javafx,scala,com,net,org,com.twitter,static</order>
</importOrder>
</java>
</configuration>
</plugin>
</plugins>
</build>


<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

</properties>

<dependencies>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -30,55 +94,55 @@
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.crypto.tink</groupId>
<artifactId>tink</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.8</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.8</version>
</dependency>

<dependency>
<groupId>de.huxhorn.sulky</groupId>
<artifactId>de.huxhorn.sulky.ulid</artifactId>
<version>8.2.0</version>
<groupId>de.huxhorn.sulky</groupId>
<artifactId>de.huxhorn.sulky.ulid</artifactId>
<version>8.2.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.5</version>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.5</version>
</dependency>

<dependency>
<groupId>io.pravega</groupId>
<artifactId>pravega-client</artifactId>
<version>0.10.0</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.21.0</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.pravega</groupId>
<artifactId>pravega-client</artifactId>
<version>0.10.0</version>
<groupId>org.spdx</groupId>
<artifactId>spdx-jackson-store</artifactId>
<version>1.1.9.1</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.21.0</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-jackson-store</artifactId>
<version>1.1.9.1</version>
</dependency>

</dependencies>
</project>
77 changes: 36 additions & 41 deletions src/main/java/com/alvarium/DefaultSdk.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

/*******************************************************************************
* Copyright 2023 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
* Copyright 2022 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package com.alvarium;

import java.util.ArrayList;
Expand Down Expand Up @@ -39,7 +38,8 @@ public class DefaultSdk implements Sdk {
private final StreamProvider stream;
private final Logger logger;

public DefaultSdk(Annotator[] annotators, SdkInfo config, Logger logger) throws StreamException {
public DefaultSdk(Annotator[] annotators, SdkInfo config, Logger logger)
throws StreamException {
this.annotators = annotators;
this.config = config;
this.logger = logger;
Expand All @@ -51,37 +51,35 @@ public DefaultSdk(Annotator[] annotators, SdkInfo config, Logger logger) throws
this.logger.debug("stream provider connected successfully.");
}

public void create(PropertyBag properties, byte[] data) throws AnnotatorException,
StreamException {
public void create(PropertyBag properties, byte[] data)
throws AnnotatorException, StreamException {
final List<Annotation> annotations = this.createAnnotations(properties, data);
this.publishAnnotations(SdkAction.CREATE, annotations);
this.logger.debug("data annotated and published successfully.");
}

public void create(byte[] data) throws AnnotatorException, StreamException {
final PropertyBag properties = new ImmutablePropertyBag(new HashMap<String, Object>());
this.create(properties, data);
}

public void mutate(PropertyBag properties, byte[] oldData, byte[] newData) throws
AnnotatorException, StreamException {
public void mutate(PropertyBag properties, byte[] oldData, byte[] newData)
throws AnnotatorException, StreamException {
final List<Annotation> annotations = new ArrayList<Annotation>();

// source annotate the old data
final AnnotatorFactory annotatorFactory = new AnnotatorFactory();
final Annotator sourceAnnotator = annotatorFactory.getAnnotator(
new AnnotatorConfig(AnnotationType.SOURCE),
this.config,
this.logger
);
final Annotator sourceAnnotator =
annotatorFactory.getAnnotator(
new AnnotatorConfig(AnnotationType.SOURCE), this.config, this.logger);
final Annotation sourceAnnotation = sourceAnnotator.execute(properties, oldData);
annotations.add(sourceAnnotation);

// Add annotations for new data
for (Annotation annotation: this.createAnnotations(properties, newData)) {
for (Annotation annotation : this.createAnnotations(properties, newData)) {
// TLS is ignored in mutate to prevent needless penalization
// See https://github.com/project-alvarium/alvarium-sdk-go/issues/19
if(annotation.getKind() != AnnotationType.TLS) {
if (annotation.getKind() != AnnotationType.TLS) {
annotations.add(annotation);
}
}
Expand All @@ -96,8 +94,8 @@ public void mutate(byte[] oldData, byte[] newData) throws AnnotatorException, St
this.mutate(properties, oldData, newData);
}

public void transit(PropertyBag properties, byte[] data) throws AnnotatorException,
StreamException {
public void transit(PropertyBag properties, byte[] data)
throws AnnotatorException, StreamException {
final List<Annotation> annotations = this.createAnnotations(properties, data);
this.publishAnnotations(SdkAction.TRANSIT, annotations);
this.logger.debug("data annotated and published successfully.");
Expand All @@ -108,13 +106,13 @@ public void transit(byte[] data) throws AnnotatorException, StreamException {
this.transit(properties, data);
}

public void publish(PropertyBag properties, byte[] data) throws AnnotatorException,
StreamException {
public void publish(PropertyBag properties, byte[] data)
throws AnnotatorException, StreamException {
final List<Annotation> annotations = this.createAnnotations(properties, data);
this.publishAnnotations(SdkAction.PUBLISH, annotations);
this.logger.debug("data annotated and published successfully.");
}

public void publish(byte[] data) throws AnnotatorException, StreamException {
final PropertyBag properties = new ImmutablePropertyBag(new HashMap<String, Object>());
this.publish(properties, data);
Expand All @@ -132,12 +130,12 @@ public void close() throws StreamException {
* @return
* @throws AnnotatorException
*/
private List<Annotation> createAnnotations(PropertyBag properties, byte[] data)
private List<Annotation> createAnnotations(PropertyBag properties, byte[] data)
throws AnnotatorException {
final List<Annotation> annotations = new ArrayList<Annotation>();

// Annotate incoming data
for (Annotator annotator: this.annotators) {
for (Annotator annotator : this.annotators) {
final Annotation annotation = annotator.execute(properties, data);
annotations.add(annotation);
}
Expand All @@ -146,22 +144,19 @@ private List<Annotation> createAnnotations(PropertyBag properties, byte[] data)
}

/**
* Wraps the annotation list with a publish wrapper that specifies the SDK action and the
* Wraps the annotation list with a publish wrapper that specifies the SDK action and the
* content type
* @param action
* @param annotations
* @throws StreamException
*/
private void publishAnnotations(SdkAction action, List<Annotation> annotations)
private void publishAnnotations(SdkAction action, List<Annotation> annotations)
throws StreamException {
final AnnotationList annotationList = new AnnotationList(annotations);

// publish list of annotations to the StreamProvider
final PublishWrapper wrapper = new PublishWrapper(
action,
annotationList.getClass().getName(),
annotationList
);
final PublishWrapper wrapper =
new PublishWrapper(action, annotationList.getClass().getName(), annotationList);
this.stream.publish(wrapper);
}
}
Loading

0 comments on commit b36a102

Please sign in to comment.