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


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/ExternalEventConfigurationRepositoryWrapper.java:
##########
@@ -0,0 +1,47 @@
+/**
+ * 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.repository;
+
+import java.util.Collection;
+import lombok.RequiredArgsConstructor;
+import 
org.apache.fineract.infrastructure.event.external.exception.ExternalEventConfigurationNotFoundException;
+import 
org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class ExternalEventConfigurationRepositoryWrapper {

Review Comment:
   Well, I know we're doing it like this but Spring Data offers extension 
points to actually write custom implementation for Repositories. Here's the 
doc: 
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behavior
   
   Please check it. Would be nicer if we don't confuse ourselves with having a 
regular Repository and a Wrapper. 



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventConfiguration.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.repository.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "m_external_event_configuration")
+@Getter
+@NoArgsConstructor
+public class ExternalEventConfiguration {
+
+    @Id
+    @Column(name = "type", nullable = false)
+    private String type;
+
+    @Column(name = "enabled", nullable = false)
+    private boolean enabled = false;
+
+    public ExternalEventConfiguration(String type, boolean enabled) {

Review Comment:
   You could replace this with an AllArgsConstructor.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/serialization/ExternalEventConfigurationCommandFromApiJsonDeserializer.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * 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.serialization;
+
+import com.google.gson.reflect.TypeToken;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
+import 
org.apache.fineract.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import 
org.apache.fineract.infrastructure.event.external.command.ExternalEventConfigurationCommand;
+import org.springframework.stereotype.Component;
+
+@Component
+@AllArgsConstructor
+public class ExternalEventConfigurationCommandFromApiJsonDeserializer
+        extends 
AbstractFromApiJsonDeserializer<ExternalEventConfigurationCommand> {
+
+    private final Set<String> supportedParameters = new 
HashSet<>(Arrays.asList("externalEventConfigurations"));

Review Comment:
   Could we extract this magic string into a static variable?



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventConfiguration.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.repository.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "m_external_event_configuration")
+@Getter
+@NoArgsConstructor
+public class ExternalEventConfiguration {
+
+    @Id
+    @Column(name = "type", nullable = false)
+    private String type;
+
+    @Column(name = "enabled", nullable = false)
+    private boolean enabled = false;
+
+    public ExternalEventConfiguration(String type, boolean enabled) {
+        this.type = type;
+        this.enabled = enabled;
+    }
+
+    public boolean enableConfiguration(final boolean canEnable) {

Review Comment:
   Not sure we wanna do this tbh. There should be nothing wrong if somebody 
tries to set it enabled when it's already enabled. Thoughts?



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/serialization/ExternalEventConfigurationCommandFromApiJsonDeserializer.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * 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.serialization;
+
+import com.google.gson.reflect.TypeToken;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
+import 
org.apache.fineract.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import 
org.apache.fineract.infrastructure.event.external.command.ExternalEventConfigurationCommand;
+import org.springframework.stereotype.Component;
+
+@Component
+@AllArgsConstructor
+public class ExternalEventConfigurationCommandFromApiJsonDeserializer
+        extends 
AbstractFromApiJsonDeserializer<ExternalEventConfigurationCommand> {
+
+    private final Set<String> supportedParameters = new 
HashSet<>(Arrays.asList("externalEventConfigurations"));
+    private final FromJsonHelper fromApiJsonHelper;
+
+    @Override
+    public ExternalEventConfigurationCommand commandFromApiJson(String json) {
+        if (StringUtils.isBlank(json)) {
+            throw new InvalidJsonException();
+        }
+
+        final Type typeOfMap = new TypeToken<Map<String, Object>>() 
{}.getType();
+        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, 
this.supportedParameters);

Review Comment:
   Let's get rid of the "this." if not needed.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationReadPlatformServiceImpl.java:
##########
@@ -0,0 +1,46 @@
+/**
+ * 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.Collection;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import 
org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationData;
+import 
org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationItemData;
+import 
org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class ExternalEventConfigurationReadPlatformServiceImpl implements 
ExternalEventConfigurationReadPlatformService {
+
+    private final ExternalEventConfigurationRepositoryWrapper repository;
+
+    @Override
+    public ExternalEventConfigurationData findAllExternalEventConfigurations() 
{
+        ExternalEventConfigurationData configurationData = new 
ExternalEventConfigurationData();
+        Collection<ExternalEventConfiguration> eventConfigurations = 
repository.findAllConfigurations();
+        
configurationData.setExternalEventConfiguration(eventConfigurations.stream()

Review Comment:
   How about using a MapStruct mapper to do the mapping for us? I know it's not 
that complicated now but let's keep it that way ;)



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