galovics commented on code in PR #2711:
URL: https://github.com/apache/fineract/pull/2711#discussion_r1007050432


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationService.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.event.external.service;
+
+import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfoList;
+import io.github.classgraph.ScanResult;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import 
org.apache.fineract.infrastructure.event.external.exception.ExternalEventConfigurationNotFoundException;
+import 
org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepository;
+import 
org.apache.fineract.infrastructure.security.service.TenantDetailsService;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class ExternalEventConfigurationValidationService implements 
InitializingBean {
+
+    private static final String EXTERNAL_EVENT_CLASSES_BASE_PACKAGE = 
"org.apache.fineract.infrastructure.event.business.domain";
+    private static final String EXTERNAL_EVENT_BUSINESS_INTERFACE = 
"org.apache.fineract.infrastructure.event.business.domain.BusinessEvent";

Review Comment:
   How about getting the fully qualified name from the class itself? 
BusinessEvent.getClass().getName()?



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationService.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.infrastructure.event.external.service;
+
+import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfoList;
+import io.github.classgraph.ScanResult;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import 
org.apache.fineract.infrastructure.event.external.exception.ExternalEventConfigurationNotFoundException;
+import 
org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepository;
+import 
org.apache.fineract.infrastructure.security.service.TenantDetailsService;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class ExternalEventConfigurationValidationService implements 
InitializingBean {
+
+    private static final String EXTERNAL_EVENT_CLASSES_BASE_PACKAGE = 
"org.apache.fineract.infrastructure.event.business.domain";
+    private static final String EXTERNAL_EVENT_BUSINESS_INTERFACE = 
"org.apache.fineract.infrastructure.event.business.domain.BusinessEvent";
+    private static final String BULK_BUSINESS_EVENT = 
"org.apache.fineract.infrastructure.event.business.domain.BulkBusinessEvent";
+    private final TenantDetailsService tenantDetailsService;
+    private final ExternalEventConfigurationRepository repository;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        validateEventConfigurationForAllTenants();
+    }
+
+    private void validateEventConfigurationForAllTenants() throws 
ExternalEventConfigurationNotFoundException {
+        List<String> eventClasses = getAllEventClasses();
+        List<FineractPlatformTenant> tenants = 
tenantDetailsService.findAllTenants();
+
+        if (isNotEmpty(tenants)) {
+            for (FineractPlatformTenant tenant : tenants) {
+                validateEventConfigurationForIndividualTenant(tenant, 
eventClasses);
+            }
+        }
+    }
+
+    private void 
validateEventConfigurationForIndividualTenant(FineractPlatformTenant tenant, 
List<String> eventClasses)
+            throws ExternalEventConfigurationNotFoundException {
+        log.info("Validating external event configuration for {}", 
tenant.getTenantIdentifier());
+        List<String> eventConfigurations = 
getExternalEventConfigurationsForTenant(tenant);
+
+        if (eventClasses.size() != eventConfigurations.size()) {
+            throw new ExternalEventConfigurationNotFoundException();
+        }
+
+        for (String eventTypeClass : eventClasses) {
+            if (!eventConfigurations.contains(eventTypeClass)) {
+                throw new 
ExternalEventConfigurationNotFoundException(eventTypeClass);
+            }
+        }
+    }
+
+    private List<String> 
getExternalEventConfigurationsForTenant(FineractPlatformTenant tenant) {
+        ThreadLocalContextUtil.setTenant(tenant);

Review Comment:
   I'd be careful with this since there's gonna be garbage leftover after the 
last iteration. Either we save the initial ThreadLocalContextUtil state and 
restore after we're done here or you can use the 
`org.apache.fineract.infrastructure.core.service.migration.TenantDataSourceFactory#create`
 method to get a tenant specific DataSource without manipulating the 
threadlocal thingy. Of course this means you get a plain DataSource from which 
you should construct some kind of higher level abstraction data access 
component (all explicitly). Thoughts?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@fineract.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to