adamsaghy commented on code in PR #2667:
URL: https://github.com/apache/fineract/pull/2667#discussion_r995590438


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationWritePlatformServiceImpl.java:
##########
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
+import 
org.apache.fineract.infrastructure.event.external.command.ExternalEventConfigurationCommand;
+import 
org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration;
+import 
org.apache.fineract.infrastructure.event.external.serialization.ExternalEventConfigurationCommandFromApiJsonDeserializer;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@AllArgsConstructor
+public class ExternalEventConfigurationWritePlatformServiceImpl implements 
ExternalEventConfigurationWritePlatformService {
+
+    private final ExternalEventConfigurationRepositoryWrapper repository;
+    private final ExternalEventConfigurationCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Transactional
+    @Override
+    public CommandProcessingResult updateConfigurations(final JsonCommand 
command) {
+        final ExternalEventConfigurationCommand configurationCommand = 
fromApiJsonDeserializer.commandFromApiJson(command.json());
+        final Map<String, Boolean> commandConfigurations = 
configurationCommand.getExternalEventConfigurations();
+        final Map<String, Object> changes = new HashMap<>();
+        final Map<String, Boolean> changedConfigurations = new HashMap<>();
+        final List<ExternalEventConfiguration> modifiedConfigurations = new 
ArrayList<>();
+        for (final String eventType : commandConfigurations.keySet()) {
+            final ExternalEventConfiguration configuration = repository
+                    
.findExternalEventConfigurationByTypeWithNotFoundDetection(eventType);
+            final boolean canEnable = 
commandConfigurations.get(eventType).booleanValue();
+            final boolean modified = 
configuration.enableConfiguration(canEnable);

Review Comment:
   Unnecessary to check whether it got changed or not. Entitymanager will do 
the job for us.
   This can be simplify by simply:
   - Update the enable field according the value in the request and save all of 
the entities
   
   Behind the curtains the entitymanager was recording and managing the state 
of each entity and if there was any change it will save it, if not just simply 
ignoring it.



-- 
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