Skip to content

Commit

Permalink
Merge pull request #13 from abhigun/bug_fixes
Browse files Browse the repository at this point in the history
Bug fixes and excluding non-serializable fields from Schema Attributes
  • Loading branch information
koushikr authored Dec 5, 2024
2 parents 03e50e1 + 4b79616 commit ab86df9
Show file tree
Hide file tree
Showing 34 changed files with 160 additions and 106 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file.

## [0.0.1-RC8]

- SchemaDetails:
- Moved the nested `SchemaKey` attributes to the class level
- made the getReferenceId() uniform with `SchemaKey` implementation
- FieldUtils: Excluding non-serializable fields(static, transient, @JsonIgnore) for building the schema attributes
- SchemaResource: Bug fix in SchemaValidation resource
- Removed the unused `LeiaCompiledPath` class

## [0.0.1-RC7]

- Introduced a `leia-common` module to host all the common utils classes
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Contributors

* [Koushik R](https://github.com/koushikr)
* [Abhishek](https://github.com/abhigun)
* [Subham](https://github.com/nullsoni)

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Leia is a governance and metadata framework aimed at meeting compliance requirem
<dependency>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-bom</artifactId>
<versio>0.0.1-RC7</version>
<version>latest</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion leia-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
</parent>

<artifactId>leia-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion leia-client-dropwizard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion leia-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<SchemaDetails> getSchemaDetails(final Set<String> namespaces) {
throw new IllegalStateException("The configuration object has returned null data. Something gone wrong with refresher");
}
return refresher.getData().stream()
.filter(each -> namespaces.contains(each.getSchemaKey().getNamespace())).toList();
.filter(each -> namespaces.contains(each.getNamespace())).toList();
}

public boolean valid(SchemaKey schemaKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private Map<SchemaKey, LeiaMessage> getMessages(SchemaKey schemaKey, byte[] sour
.build()
);
final var sourceSchemaDetails = super.getSchemaDetails()
.stream().filter(each -> each.getSchemaKey().equals(schemaKey))
.stream().filter(each -> each.match(schemaKey))
.findFirst().orElse(null);

final var transformationTargets = null == sourceSchemaDetails ? null :
Expand All @@ -112,10 +112,11 @@ public void processMessages(final SchemaKey schemaKey,
@Override
public void start() {
super.getSchemaDetails().forEach(schemaDetails -> {
final var validSchema = super.valid(schemaDetails.getSchemaKey());
final var schemaKey = schemaDetails.getSchemaKey();
final var validSchema = super.valid(schemaKey);
if (!validSchema) {
log.error("The source schema doesn't seem to be valid for schemaKey {}. Please check the schema bindings provided",
schemaDetails.getSchemaKey());
schemaKey);
throw new IllegalStateException("Invalid source schema");
}
final var transformationTargets = schemaDetails.getTransformationTargets();
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion leia-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.grookage.leia.common.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.experimental.UtilityClass;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -28,8 +30,18 @@ public class FieldUtils {
public List<Field> getAllFields(final Class<?> type) {
List<Field> fields = new ArrayList<>();
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
fields.addAll(Arrays.asList(c.getDeclaredFields()));
Arrays.stream(c.getDeclaredFields())
.filter(field -> !isNonSerializable(field))
.forEach(fields::add);
}
return fields;
}

private boolean isNonSerializable(final Field field) {
if (field.isAnnotationPresent(JsonIgnore.class)) {
return true;
}
int modifiers = field.getModifiers();
return Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
import com.grookage.leia.models.qualifiers.PIIQualifier;
import com.grookage.leia.models.schema.SchemaType;
import com.grookage.leia.models.schema.SchemaValidationType;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Set;

class SchemaBuilderTest {
@SneakyThrows
@Test
void testSchemaRequest() {
final var schemaCreateRequest = SchemaBuilder.buildSchemaRequest(TestRecord.class)
.orElse(null);
Assertions.assertNotNull(schemaCreateRequest);
Assertions.assertEquals(5, schemaCreateRequest.getAttributes().size());
final var schemaAttributes = SchemaBuilder.getSchemaAttributes(TestRecord.class);
Assertions.assertEquals(TestRecord.NAME, schemaCreateRequest.getSchemaName());
Assertions.assertEquals(TestRecord.NAMESPACE, schemaCreateRequest.getNamespace());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.grookage.leia.common.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class FieldUtilsTest {
@Test
void testFieldUtils() {
final var fields = FieldUtils.getAllFields(TestData.class);
Assertions.assertFalse(fields.isEmpty());
Assertions.assertEquals(2, fields.size());
Assertions.assertTrue(fields.stream().noneMatch(field -> field.getName().equals("phoneNumber")));
Assertions.assertTrue(fields.stream().noneMatch(field -> field.getName().equals("CONSTANT")));
Assertions.assertTrue(fields.stream().noneMatch(field -> field.getName().equals("exclusion")));
}

static class BaseData {
@JsonIgnore
private String exclusion;
static final String CONSTANT = "CONSTANT";
String name;
}

static class TestData extends BaseData {
String email;
transient String phoneNumber;
}
}
8 changes: 3 additions & 5 deletions leia-common/src/test/resources/validNestedSchema.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"schemaKey": {
"namespace": "testNamespace",
"schemaName": "testSchema",
"version": "V1234"
},
"namespace": "testNamespace",
"schemaName": "testSchema",
"version": "V1234",
"schemaState": "CREATED",
"schemaType": "JSON",
"schemaMeta": {
Expand Down
8 changes: 3 additions & 5 deletions leia-common/src/test/resources/validSchema.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"schemaKey": {
"namespace": "testNamespace",
"schemaName": "testSchema",
"version": "V1234"
},
"namespace": "testNamespace",
"schemaName": "testSchema",
"version": "V1234",
"schemaState": "CREATED",
"schemaType": "JSON",
"schemaMeta": {
Expand Down
2 changes: 1 addition & 1 deletion leia-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ public SchemaDetails toSchemaDetails(final CreateSchemaRequest createSchemaReque
final String email,
final Supplier<VersionIDGenerator> versionSupplier) {
return SchemaDetails.builder()
.schemaKey(SchemaKey.builder()
.namespace(createSchemaRequest.getNamespace())
.schemaName(createSchemaRequest.getSchemaName())
.version(versionSupplier.get().generateVersionId("V"))
.build()
)
.namespace(createSchemaRequest.getNamespace())
.schemaName(createSchemaRequest.getSchemaName())
.version(versionSupplier.get().generateVersionId("V"))
.schemaState(SchemaState.CREATED)
.schemaType(createSchemaRequest.getSchemaType())
.description(createSchemaRequest.getDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ public String generateVersionId(String prefix) {
"testEmail", () -> generator
);
Assertions.assertNotNull(schemaDetails);
final var schemaKey = schemaDetails.getSchemaKey();
Assertions.assertNotNull(schemaKey);
Assertions.assertEquals("testNamespace", schemaKey.getNamespace());
Assertions.assertEquals("testSchema", schemaKey.getSchemaName());
Assertions.assertEquals("V1234", schemaKey.getVersion());
Assertions.assertEquals("testNamespace", schemaDetails.getNamespace());
Assertions.assertEquals("testSchema", schemaDetails.getSchemaName());
Assertions.assertEquals("V1234", schemaDetails.getVersion());
final var schemaMeta = schemaDetails.getSchemaMeta();
Assertions.assertNotNull(schemaMeta);
Assertions.assertEquals("testUser", schemaMeta.getCreatedBy());
Expand Down
2 changes: 1 addition & 1 deletion leia-dropwizard-es/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected Supplier<SchemaRepository> getRepositorySupplier(T configuration) {
return () -> elasticSchemaRepository;
}

@Override
protected List<LeiaHealthCheck> withHealthChecks(T configuration) {
return List.of(new ElasticHealthCheck(elasticConfig, elasticsearchClient));
}
Expand Down
2 changes: 1 addition & 1 deletion leia-dropwizard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import com.codahale.metrics.annotation.ExceptionMetered;
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.databind.JsonNode;
import com.grookage.leia.common.validation.SchemaPayloadValidator;
import com.grookage.leia.core.exception.LeiaErrorCode;
import com.grookage.leia.core.exception.LeiaException;
import com.grookage.leia.core.retrieval.SchemaRetriever;
import com.grookage.leia.models.GenericResponse;
import com.grookage.leia.models.request.NamespaceRequest;
import com.grookage.leia.models.request.ValidateSchemaRequest;
import com.grookage.leia.models.schema.SchemaDetails;
import com.grookage.leia.models.schema.SchemaKey;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -86,11 +86,11 @@ public List<SchemaDetails> getAllSchemaDetails(@Valid final NamespaceRequest nam
@Timed
@ExceptionMetered
@Path("/details/validate")
public GenericResponse<List<String>> validateSchema(@Valid SchemaKey schemaKey,
@Valid JsonNode jsonNode) {
final var schemaDetails = schemaRetriever.getSchemaDetails(schemaKey)
public GenericResponse<List<String>> validateSchema(@Valid final ValidateSchemaRequest validateSchemaRequest) {
final var schemaDetails = schemaRetriever.getSchemaDetails(validateSchemaRequest.getSchemaKey())
.orElseThrow(() -> LeiaException.error(LeiaErrorCode.NO_SCHEMA_FOUND));
final var validationErrors = SchemaPayloadValidator.validate(jsonNode, schemaDetails.getValidationType(),
final var validationErrors = SchemaPayloadValidator.validate(validateSchemaRequest.getJsonNode(),
schemaDetails.getValidationType(),
schemaDetails.getAttributes());
if (validationErrors.isEmpty()) {
return GenericResponse.<List<String>>builder()
Expand Down
2 changes: 1 addition & 1 deletion leia-elastic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion leia-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.grookage.leia</groupId>
<artifactId>leia-parent</artifactId>
<version>0.0.1-RC7</version>
<version>0.0.1-RC8</version>
<relativePath>../leia-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.grookage.leia.models.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.grookage.leia.models.schema.SchemaKey;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ValidateSchemaRequest {
@Valid
@NotNull
private SchemaKey schemaKey;
@NotNull
private JsonNode jsonNode;
}
Loading

0 comments on commit ab86df9

Please sign in to comment.