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


##########
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:
   @galovics This is what i tried initially:
   private List<String> 
getExternalEventConfigurationsForTenant(FineractPlatformTenant tenant) {
           DataSource tenantDataSource = tenantDataSourceFactory.create(tenant);
           final JdbcTemplate jdbcTemplate = new JdbcTemplate(tenantDataSource);
           final StringBuilder eventConfigurations = new StringBuilder();
           eventConfigurations.append("select me.type as type from 
m_external_event_configuration me");
           List<String> configuredEventTypes = 
jdbcTemplate.queryForList(eventConfigurations.toString(), String.class);
           return configuredEventTypes;
       }
   Please comment .



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to