diff --git a/leia-client-dropwizard/src/main/java/com/grookage/leia/dw/client/LeiaClientBundle.java b/leia-client-dropwizard/src/main/java/com/grookage/leia/dw/client/LeiaClientBundle.java index 24913a5..89f2a73 100644 --- a/leia-client-dropwizard/src/main/java/com/grookage/leia/dw/client/LeiaClientBundle.java +++ b/leia-client-dropwizard/src/main/java/com/grookage/leia/dw/client/LeiaClientBundle.java @@ -23,7 +23,7 @@ import com.grookage.leia.client.refresher.LeiaClientRefresher; import com.grookage.leia.client.refresher.LeiaClientSupplier; import com.grookage.leia.provider.config.LeiaHttpConfiguration; -import com.grookage.leia.validator.InjectableSchemaValidator; +import com.grookage.leia.validator.StaticSchemaValidator; import com.grookage.leia.validator.LeiaSchemaValidator; import io.dropwizard.Configuration; import io.dropwizard.ConfiguredBundle; @@ -50,12 +50,10 @@ public abstract class LeiaClientBundle implements Confi protected abstract Injector getInjector(Environment environment); protected LeiaSchemaValidator getSchemaValidator(T configuration, - Environment environment, LeiaClientRefresher clientRefresher) { - return InjectableSchemaValidator.builder() + return StaticSchemaValidator.builder() .supplier(clientRefresher::getConfiguration) .packageRoots(getPackageRoots(configuration)) - .injector(getInjector(environment)) .build(); } @@ -76,7 +74,7 @@ public void run(T configuration, Environment environment) { .build()) .configRefreshTimeSeconds(configRefreshSeconds) .build(); - final var validator = getSchemaValidator(configuration, environment, clientRefresher); + final var validator = getSchemaValidator(configuration, clientRefresher); validator.start(); if (withProducerClient) { producerClient = LeiaMessageProduceClient.builder() diff --git a/leia-client/src/main/java/com/grookage/leia/client/datasource/DynamicNamespaceDataSource.java b/leia-client/src/main/java/com/grookage/leia/client/datasource/DynamicNamespaceDataSource.java deleted file mode 100644 index 9425b18..0000000 --- a/leia-client/src/main/java/com/grookage/leia/client/datasource/DynamicNamespaceDataSource.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2024. Koushik R . - * - * 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.grookage.leia.client.datasource; - -import lombok.AllArgsConstructor; - -import java.util.Set; -import java.util.function.Supplier; - -@AllArgsConstructor -public class DynamicNamespaceDataSource implements NamespaceDataSource { - - private final Supplier> namespaceSupplier; - - @Override - public Set getNamespaces() { - return namespaceSupplier.get(); - } - -} diff --git a/leia-client/src/main/java/com/grookage/leia/client/datasource/NamespaceDataSource.java b/leia-client/src/main/java/com/grookage/leia/client/datasource/NamespaceDataSource.java index 6d84bc8..030c497 100644 --- a/leia-client/src/main/java/com/grookage/leia/client/datasource/NamespaceDataSource.java +++ b/leia-client/src/main/java/com/grookage/leia/client/datasource/NamespaceDataSource.java @@ -16,10 +16,17 @@ package com.grookage.leia.client.datasource; +import lombok.AllArgsConstructor; + import java.util.Set; +import java.util.function.Supplier; -public interface NamespaceDataSource { +@AllArgsConstructor +public class NamespaceDataSource { - Set getNamespaces(); + private final Supplier> namespaceSupplier; + public Set getNamespaces() { + return namespaceSupplier.get(); + } } diff --git a/leia-client/src/main/java/com/grookage/leia/client/datasource/StaticNamespaceDataSource.java b/leia-client/src/main/java/com/grookage/leia/client/datasource/StaticNamespaceDataSource.java deleted file mode 100644 index eeb4135..0000000 --- a/leia-client/src/main/java/com/grookage/leia/client/datasource/StaticNamespaceDataSource.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2024. Koushik R . - * - * 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.grookage.leia.client.datasource; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; - -import java.util.Set; - -@AllArgsConstructor -@Data -@Builder -public class StaticNamespaceDataSource implements NamespaceDataSource { - - private final Set namespaces; - - @Override - public Set getNamespaces() { - return namespaces; - } -} diff --git a/leia-dropwizard/src/main/java/com/grookage/leia/dropwizard/bundle/LeiaBundle.java b/leia-dropwizard/src/main/java/com/grookage/leia/dropwizard/bundle/LeiaBundle.java index 84cb803..058096e 100644 --- a/leia-dropwizard/src/main/java/com/grookage/leia/dropwizard/bundle/LeiaBundle.java +++ b/leia-dropwizard/src/main/java/com/grookage/leia/dropwizard/bundle/LeiaBundle.java @@ -69,14 +69,14 @@ protected List withLifecycleManagers(T configuration) { public void run(T configuration, Environment environment) { final var userResolver = userResolver(configuration); Preconditions.checkNotNull(userResolver, "User Resolver can't be null"); + this.schemaRepository = getSchemaRepository(configuration); final var schemaProcessorHub = SchemaProcessorHub.of() - .withSchemaRepository(getSchemaRepository(configuration)) + .withSchemaRepository(schemaRepository) .withVersionIDGenerator(getVersionIDGenerator()) .build(); this.schemaIngestor = new SchemaIngestor() .withProcessorHub(schemaProcessorHub) .build(); - this.schemaRepository = getSchemaRepository(configuration); final var cacheConfig = getCacheConfig(configuration); this.schemaRetriever = new SchemaRetriever(schemaRepository, cacheConfig); withLifecycleManagers(configuration) diff --git a/leia-models/src/main/java/com/grookage/leia/models/attributes/ObjectAttribute.java b/leia-models/src/main/java/com/grookage/leia/models/attributes/ObjectAttribute.java index 65ef7e0..83efa7a 100644 --- a/leia-models/src/main/java/com/grookage/leia/models/attributes/ObjectAttribute.java +++ b/leia-models/src/main/java/com/grookage/leia/models/attributes/ObjectAttribute.java @@ -22,6 +22,8 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import java.util.Set; + @EqualsAndHashCode(callSuper = true) @Data @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java b/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java index b5daeff..1f34844 100644 --- a/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java +++ b/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java @@ -64,7 +64,6 @@ public TimeBasedDataProvider(Supplier configSupplier, T initialDefaultValue, public void start() { this.executorService.scheduleWithFixedDelay(this.updater, 0L, this.delay, this.timeUnit); - this.update(); } public void stop() { diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/InjectableSchemaValidator.java b/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java similarity index 83% rename from leia-schema-validator/src/main/java/com/grookage/leia/validator/InjectableSchemaValidator.java rename to leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java index ff2206b..26a9316 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/InjectableSchemaValidator.java +++ b/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java @@ -36,20 +36,17 @@ import java.util.stream.Collectors; @Slf4j -public class InjectableSchemaValidator implements LeiaSchemaValidator { +public class StaticSchemaValidator implements LeiaSchemaValidator { private final ConcurrentHashMap validationRegistry = new ConcurrentHashMap<>(); private final Supplier> supplier; private final Set packageRoots; - private final Injector injector; @Builder - public InjectableSchemaValidator(Supplier> supplier, - Set packageRoots, - Injector injector) { + public StaticSchemaValidator(Supplier> supplier, + Set packageRoots) { this.supplier = supplier; this.packageRoots = packageRoots; - this.injector = injector; } public Optional getSchemaDetails(final SchemaKey schemaKey) { @@ -58,12 +55,12 @@ public Optional getSchemaDetails(final SchemaKey schemaKey) { } @SneakyThrows - private boolean validate(final SchemaKey schemaKey, T data) { + private boolean validate(final SchemaKey schemaKey, Class clazz) { final var details = getSchemaDetails(schemaKey).orElse(null); if (null == details) { throw SchemaValidationException.error(ValidationErrorCode.NO_SCHEMA_FOUND); } - return SchemaValidationUtils.valid(details, data.getClass()); + return SchemaValidationUtils.valid(details, clazz); } @Override @@ -73,14 +70,13 @@ public void start() { final var reflections = new Reflections(handlerPackage); final var annotatedClasses = reflections.getTypesAnnotatedWith(SchemaValidator.class); annotatedClasses.forEach(annotatedClass -> { - final var instance = injector.getInstance(annotatedClass); - final var annotation = instance.getClass().getAnnotation(SchemaValidator.class); + final var annotation = annotatedClass.getAnnotation(SchemaValidator.class); final var schemaKey = SchemaKey.builder() .schemaName(annotation.schemaName()) .version(annotation.versionId()) .namespace(annotation.namespace()) .build(); - validationRegistry.putIfAbsent(schemaKey, validate(schemaKey, instance)); + validationRegistry.putIfAbsent(schemaKey, validate(schemaKey, annotatedClass)); }); }); final var invalidSchemas = validationRegistry.keySet().stream() diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java b/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java index cba95c9..09da67a 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java +++ b/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java @@ -36,7 +36,7 @@ public static boolean valid(final SchemaDetails schemaDetails, final var validationType = schemaDetails.getValidationType(); final var allAttributesListed = fields.stream().filter(each -> schemaDetails.hasAttribute(each.getName())) .collect(Collectors.toSet()); - if (!allAttributesListed.isEmpty() && + if (allAttributesListed.size() != fields.size() && validationType == SchemaValidationType.STRICT) { log.error("There seems to be attributes present in the class definition that are not in the schema. " + "[Validation Failed]. The extra attributes are {}",