Skip to content

Commit 555a267

Browse files
authored
Add AGENTS.md and align Javadoc with its standards (#538)
1 parent b471a13 commit 555a267

25 files changed

Lines changed: 273 additions & 146 deletions

AGENTS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Agent Instructions
2+
3+
## Repository Structure
4+
5+
- `kstreamplify-core`: core Kafka Streams functionality.
6+
- `kstreamplify-core-test`: test utilities and base classes for testing topologies.
7+
- `kstreamplify-spring-boot`: Spring Boot autoconfiguration and web services.
8+
9+
## Commands
10+
11+
- Build with `mvn clean package`.
12+
- Run the tests with `mvn test`.
13+
- Run `mvn spotless:apply` before committing to apply Palantir Java Format.
14+
15+
## Coding Standards
16+
17+
- Target Java 17.
18+
- Code follows Palantir Java Format.
19+
- Add minimal Javadoc to every method in production code (`src/main`), including `@Override` methods, with descriptions for parameters and return values. Start each description with an uppercase letter.
20+
21+
## Testing Standards
22+
23+
- Name test classes `<ClassName>Test`.
24+
- Name unit tests with the "should..." convention (e.g. `shouldNotRegisterPropertiesWhenNull`).
25+
- Use JUnit Jupiter assertions (`org.junit.jupiter.api.Assertions`).
26+
- Use Mockito with `@ExtendWith(MockitoExtension.class)`.
27+
- Use Testcontainers for Kafka integration tests.

kstreamplify-core-test/src/main/java/com/michelin/kstreamplify/KafkaStreamsStarterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected Map<String, String> getSpecificProperties() {
136136
/**
137137
* Close everything after each test.
138138
*
139-
* @throws IOException if an I/O error occurs while deleting the state directory
139+
* @throws IOException If an I/O error occurs while deleting the state directory
140140
*/
141141
@AfterEach
142142
protected void generalTearDown() throws IOException {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/converter/AvroToJsonConverter.java

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class AvroToJsonConverter {
5151
.setPrettyPrinting()
5252
.create();
5353

54+
/** Private constructor. */
5455
private AvroToJsonConverter() {}
5556

5657
/**
@@ -82,20 +83,20 @@ public static String convertObject(List<Object> values) {
8283
}
8384

8485
/**
85-
* Convert the record from avro format to json format.
86+
* Convert the record from avro format to JSON format.
8687
*
87-
* @param inputRecord the record in avro format
88-
* @return the record in json format
88+
* @param inputRecord The record in avro format
89+
* @return The record in JSON format
8990
*/
9091
public static String convertRecord(GenericRecord inputRecord) {
9192
return gson.toJson(recordAsMap(inputRecord));
9293
}
9394

9495
/**
95-
* Convert avro to a map for json format.
96+
* Convert avro to a map for JSON format.
9697
*
97-
* @param inputRecord record in avro
98-
* @return map for json format
98+
* @param inputRecord Record in avro
99+
* @return Map for JSON format
99100
*/
100101
private static Map<String, Object> recordAsMap(GenericRecord inputRecord) {
101102
Map<String, Object> recordMapping = new HashMap<>();
@@ -145,12 +146,29 @@ private static Map<String, Object> recordAsMap(GenericRecord inputRecord) {
145146
private static class LocalDateTypeAdapter implements JsonSerializer<LocalDate>, JsonDeserializer<LocalDate> {
146147
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
147148

149+
/**
150+
* Serialize a {@link LocalDate} to its JSON representation.
151+
*
152+
* @param date The date to serialize
153+
* @param typeOfSrc The type of the source object
154+
* @param context The serialization context
155+
* @return The serialized JSON element
156+
*/
148157
@Override
149158
public JsonElement serialize(
150159
final LocalDate date, final Type typeOfSrc, final JsonSerializationContext context) {
151160
return new JsonPrimitive(date.format(formatter));
152161
}
153162

163+
/**
164+
* Deserialize a {@link LocalDate} from its JSON representation.
165+
*
166+
* @param json The JSON element to deserialize
167+
* @param typeOfT The type of the target object
168+
* @param context The deserialization context
169+
* @return The deserialized date
170+
* @throws JsonParseException If the JSON element cannot be parsed
171+
*/
154172
@Override
155173
public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
156174
throws JsonParseException {
@@ -165,6 +183,14 @@ private static class LocalDateTimeTypeAdapter
165183
private static final DateTimeFormatter formatterNano =
166184
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS");
167185

186+
/**
187+
* Serialize a {@link LocalDateTime} to its JSON representation.
188+
*
189+
* @param localDateTime The date-time to serialize
190+
* @param srcType The type of the source object
191+
* @param context The serialization context
192+
* @return The serialized JSON element
193+
*/
168194
@Override
169195
public JsonElement serialize(LocalDateTime localDateTime, Type srcType, JsonSerializationContext context) {
170196
if (localDateTime.toString().length() == 29) {
@@ -173,6 +199,15 @@ public JsonElement serialize(LocalDateTime localDateTime, Type srcType, JsonSeri
173199
return new JsonPrimitive(formatter.format(localDateTime));
174200
}
175201

202+
/**
203+
* Deserialize a {@link LocalDateTime} from its JSON representation.
204+
*
205+
* @param json The JSON element to deserialize
206+
* @param typeOfT The type of the target object
207+
* @param context The deserialization context
208+
* @return The deserialized date-time
209+
* @throws JsonParseException If the JSON element cannot be parsed
210+
*/
176211
@Override
177212
public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
178213
throws JsonParseException {
@@ -184,6 +219,14 @@ private static class LocalTimeTypeAdapter implements JsonSerializer<LocalTime>,
184219
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
185220
private static final DateTimeFormatter formatterNano = DateTimeFormatter.ofPattern("HH:mm:ss.SSSSSS");
186221

222+
/**
223+
* Serialize a {@link LocalTime} to its JSON representation.
224+
*
225+
* @param localTime The time to serialize
226+
* @param srcType The type of the source object
227+
* @param context The serialization context
228+
* @return The serialized JSON element
229+
*/
187230
@Override
188231
public JsonElement serialize(LocalTime localTime, Type srcType, JsonSerializationContext context) {
189232
if (localTime.toString().length() == 15) {
@@ -192,6 +235,15 @@ public JsonElement serialize(LocalTime localTime, Type srcType, JsonSerializatio
192235
return new JsonPrimitive(formatter.format(localTime));
193236
}
194237

238+
/**
239+
* Deserialize a {@link LocalTime} from its JSON representation.
240+
*
241+
* @param json The JSON element to deserialize
242+
* @param typeOfT The type of the target object
243+
* @param context The deserialization context
244+
* @return The deserialized time
245+
* @throws JsonParseException If the JSON element cannot be parsed
246+
*/
195247
@Override
196248
public LocalTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
197249
throws JsonParseException {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/converter/JsonToAvroConverter.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ public class JsonToAvroConverter {
5252
.setPrettyPrinting()
5353
.create();
5454

55+
/** Private constructor. */
5556
private JsonToAvroConverter() {}
5657

5758
/**
58-
* Convert a json string to an object.
59+
* Convert a JSON string to an object.
5960
*
60-
* @param json the json string
61-
* @return the object
61+
* @param json The JSON string
62+
* @return The object
6263
*/
6364
public static Object jsonToObject(String json) {
6465
if (json == null) {
@@ -69,22 +70,22 @@ public static Object jsonToObject(String json) {
6970
}
7071

7172
/**
72-
* Convert a file in json to avro.
73+
* Convert a file in JSON to avro.
7374
*
74-
* @param file the file in json
75-
* @param schema the avro schema to use
76-
* @return the record in avro
75+
* @param file The file in json
76+
* @param schema The avro schema to use
77+
* @return The record in avro
7778
*/
7879
public static SpecificRecordBase jsonToAvro(String file, Schema schema) {
7980
return jsonToAvro(JsonParser.parseString(file).getAsJsonObject(), schema);
8081
}
8182

8283
/**
83-
* Convert json to avro.
84+
* Convert JSON to Avro.
8485
*
85-
* @param jsonEvent the json record
86-
* @param schema the avro schema to use
87-
* @return the record in avro
86+
* @param jsonEvent The JSON record
87+
* @param schema The avro schema to use
88+
* @return The record in avro
8889
*/
8990
public static SpecificRecordBase jsonToAvro(JsonObject jsonEvent, Schema schema) {
9091
try {
@@ -101,8 +102,8 @@ public static SpecificRecordBase jsonToAvro(JsonObject jsonEvent, Schema schema)
101102
/**
102103
* Populate avro records from json.
103104
*
104-
* @param jsonObject json data to provide to the avro record
105-
* @param message the avro record to populate
105+
* @param jsonObject Json data to provide to the avro record
106+
* @param message The avro record to populate
106107
*/
107108
private static void populateGenericRecordFromJson(JsonObject jsonObject, SpecificRecordBase message) {
108109
// Iterate over object attributes
@@ -211,9 +212,9 @@ private static void populateGenericRecordFromJson(JsonObject jsonObject, Specifi
211212
/**
212213
* Populate field with corresponding type.
213214
*
214-
* @param jsonElement the json element to convert
215-
* @param type the type of the element
216-
* @return the element converted with the corresponding type
215+
* @param jsonElement The JSON element to convert
216+
* @param type The type of the element
217+
* @return The element converted with the corresponding type
217218
*/
218219
private static Object populateFieldWithCorrespondingType(JsonElement jsonElement, Schema.Type type) {
219220
return switch (type) {
@@ -229,9 +230,9 @@ private static Object populateFieldWithCorrespondingType(JsonElement jsonElement
229230
/**
230231
* Populate field in record with corresponding type.
231232
*
232-
* @param jsonObject data to provide to the avro record
233-
* @param fieldName the name to populate
234-
* @param result the avro record populated
233+
* @param jsonObject Data to provide to the avro record
234+
* @param fieldName The name to populate
235+
* @param result The avro record populated
235236
*/
236237
@SuppressWarnings("unchecked")
237238
private static void populateFieldInRecordWithCorrespondingType(
@@ -379,9 +380,9 @@ private static void populateFieldInRecordWithCorrespondingType(
379380
/**
380381
* Get base class.
381382
*
382-
* @param baseNamespace the namespace of the class
383-
* @param typeName the class type
384-
* @return the base class
383+
* @param baseNamespace The namespace of the class
384+
* @param typeName The class type
385+
* @return The base class
385386
*/
386387
@SuppressWarnings("unchecked")
387388
private static Class<SpecificRecordBase> baseClass(String baseNamespace, String typeName) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupHeadersProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public DedupHeadersProcessor(
6363
/**
6464
* Get the header value for a given key
6565
*
66-
* @param headers headers of the record
67-
* @param key the key to look for in the headers
66+
* @param headers Headers of the record
67+
* @param key The key to look for in the headers
6868
* @return The header value for the given key, or an empty string if the header is not present or has no value.
6969
*/
7070
private static String getHeader(Headers headers, String key) {
@@ -79,7 +79,7 @@ private static String getHeader(Headers headers, String key) {
7979
/**
8080
* Initialize the processor.
8181
*
82-
* @param context the processor context
82+
* @param context The processor context
8383
*/
8484
@Override
8585
public void init(ProcessorContext<String, V> context) {
@@ -90,7 +90,7 @@ public void init(ProcessorContext<String, V> context) {
9090
/**
9191
* Process a record.
9292
*
93-
* @param message the record to process
93+
* @param message The record to process
9494
*/
9595
@Override
9696
public void process(Record<String, V> message) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupHeadersProcessorWithErrors.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public DedupHeadersProcessorWithErrors(
6565
/**
6666
* Initialize the processor.
6767
*
68-
* @param context the processor context
68+
* @param context The processor context
6969
*/
7070
@Override
7171
public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
@@ -76,7 +76,7 @@ public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
7676
/**
7777
* Process a record.
7878
*
79-
* @param message the record to process
79+
* @param message The record to process
8080
*/
8181
@Override
8282
public void process(Record<String, V> message) {
@@ -121,8 +121,8 @@ private String buildIdentifier(Headers headers) {
121121
/**
122122
* Get the header value for a given key
123123
*
124-
* @param headers headers of the record
125-
* @param key the key to look for in the headers
124+
* @param headers Headers of the record
125+
* @param key The key to look for in the headers
126126
* @return The header value for the given key, or an empty string if the header is not present or has no value.
127127
*/
128128
private static String getHeader(Headers headers, String key) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupKeyProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public DedupKeyProcessor(String windowStoreName, Duration retentionWindowDuratio
5353
/**
5454
* Initialize the processor.
5555
*
56-
* @param context the processor context
56+
* @param context The processor context
5757
*/
5858
@Override
5959
public void init(ProcessorContext<String, V> context) {
@@ -64,7 +64,7 @@ public void init(ProcessorContext<String, V> context) {
6464
/**
6565
* Process a record.
6666
*
67-
* @param message the record to process
67+
* @param message The record to process
6868
*/
6969
@Override
7070
public void process(Record<String, V> message) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupKeyProcessorWithErrors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DedupKeyProcessorWithErrors(String windowStoreName, Duration retentionWin
5555
/**
5656
* Initialize the processor.
5757
*
58-
* @param context the processor context
58+
* @param context The processor context
5959
*/
6060
@Override
6161
public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
@@ -66,7 +66,7 @@ public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
6666
/**
6767
* Process a record.
6868
*
69-
* @param message the record to process
69+
* @param message The record to process
7070
*/
7171
@Override
7272
public void process(Record<String, V> message) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupKeyValueProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public DedupKeyValueProcessor(String windowStoreName, Duration retentionWindowHo
5353
/**
5454
* Initialize the processor.
5555
*
56-
* @param context the processor context
56+
* @param context The processor context
5757
*/
5858
@Override
5959
public void init(ProcessorContext<String, V> context) {
@@ -64,7 +64,7 @@ public void init(ProcessorContext<String, V> context) {
6464
/**
6565
* Process a record.
6666
*
67-
* @param message the record to process
67+
* @param message The record to process
6868
*/
6969
@Override
7070
public void process(Record<String, V> message) {

kstreamplify-core/src/main/java/com/michelin/kstreamplify/deduplication/DedupKeyValueProcessorWithErrors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DedupKeyValueProcessorWithErrors(String windowStoreName, Duration retenti
5555
/**
5656
* Initialize the processor.
5757
*
58-
* @param context the processor context
58+
* @param context The processor context
5959
*/
6060
@Override
6161
public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
@@ -66,7 +66,7 @@ public void init(ProcessorContext<String, ProcessingResult<V, V>> context) {
6666
/**
6767
* Process a record.
6868
*
69-
* @param message the record to process
69+
* @param message The record to process
7070
*/
7171
@Override
7272
public void process(Record<String, V> message) {

0 commit comments

Comments
 (0)