refactor: add lombok to configuration module

This commit is contained in:
Hemant Gupta
2022-09-13 14:54:54 +02:00
committed by Arnold Gálovics
parent e67b859ea1
commit f258aa258c
15 changed files with 122 additions and 288 deletions
@@ -18,22 +18,15 @@
*/
package org.apache.fineract.infrastructure.configuration.data;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class ExternalServicesData {
private final Long id;
private final String name;
public ExternalServicesData(final Long id, final String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
private Long id;
private String name;
}
@@ -19,23 +19,18 @@
package org.apache.fineract.infrastructure.configuration.data;
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class ExternalServicesPropertiesData implements Serializable {
private final String name;
private final String value;
private static final long serialVersionUID = 1L;
public ExternalServicesPropertiesData(final String name, final String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
private String name;
private String value;
}
@@ -19,16 +19,19 @@
package org.apache.fineract.infrastructure.configuration.data;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* Immutable data object for global configuration.
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class GlobalConfigurationData {
@SuppressWarnings("unused")
private final List<GlobalConfigurationPropertyData> globalConfiguration;
public GlobalConfigurationData(final List<GlobalConfigurationPropertyData> globalConfiguration) {
this.globalConfiguration = globalConfiguration;
}
private List<GlobalConfigurationPropertyData> globalConfiguration;
}
@@ -19,82 +19,33 @@
package org.apache.fineract.infrastructure.configuration.data;
import java.time.LocalDate;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* Immutable data object for global configuration property.
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class GlobalConfigurationPropertyData {
@SuppressWarnings("unused")
private final String name;
private String name;
@SuppressWarnings("unused")
private final boolean enabled;
private boolean enabled;
@SuppressWarnings("unused")
private final Long value;
private Long value;
@SuppressWarnings("unused")
private final LocalDate dateValue;
private LocalDate dateValue;
private String stringValue;
@SuppressWarnings("unused")
private final Long id;
private Long id;
@SuppressWarnings("unused")
private final String description;
private String description;
@SuppressWarnings("unused")
private final boolean trapDoor;
public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, final LocalDate dateValue,
final String stringValue, final String description, final boolean trapDoor) {
this.name = name;
this.enabled = enabled;
this.value = value;
this.dateValue = dateValue;
this.stringValue = stringValue;
this.id = null;
this.description = description;
this.trapDoor = trapDoor;
}
public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, LocalDate dateValue,
final String stringValue, final Long id, final String description, final boolean isTrapDoor) {
this.name = name;
this.enabled = enabled;
this.value = value;
this.dateValue = dateValue;
this.stringValue = stringValue;
this.id = id;
this.description = description;
this.trapDoor = isTrapDoor;
}
public String getName() {
return this.name;
}
public boolean isEnabled() {
return this.enabled;
}
public Long getValue() {
return this.value;
}
public String getStringValue() {
return this.stringValue;
}
public LocalDate getDateValue() {
return this.dateValue;
}
public Long getId() {
return this.id;
}
public String getDescription() {
return this.description;
}
public boolean isTrapDoor() {
return this.trapDoor;
}
private boolean trapDoor;
}
@@ -18,28 +18,16 @@
*/
package org.apache.fineract.infrastructure.configuration.data;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class S3CredentialsData {
private final String bucketName;
private final String accessKey;
private final String secretKey;
public S3CredentialsData(final String bucketName, final String accessKey, final String secretKey) {
this.bucketName = bucketName;
this.accessKey = accessKey;
this.secretKey = secretKey;
}
public String getBucketName() {
return this.bucketName;
}
public String getAccessKey() {
return this.accessKey;
}
public String getSecretKey() {
return this.secretKey;
}
private String bucketName;
private String accessKey;
private String secretKey;
}
@@ -18,46 +18,22 @@
*/
package org.apache.fineract.infrastructure.configuration.data;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class SMTPCredentialsData {
private final String username;
private final String password;
private final String host;
private final String port;
private final boolean useTLS;
private final String fromEmail;
private final String fromName;
public SMTPCredentialsData(final String username, final String password, final String host, final String port, final boolean useTLS,
String fromEmail, String fromName) {
this.username = username;
this.password = password;
this.host = host;
this.port = port;
this.useTLS = useTLS;
this.fromEmail = fromEmail;
this.fromName = fromName;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getHost() {
return host;
}
public String getPort() {
return port;
}
public boolean isUseTLS() {
return useTLS;
}
private String username;
private String password;
private String host;
private String port;
private boolean useTLS;
private String fromEmail;
private String fromName;
public String getFromEmail() {
return fromEmail != null ? fromEmail : username;
@@ -22,11 +22,19 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@Entity
@Table(name = "c_external_service", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_UNIQUE") })
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ExternalService extends AbstractPersistableCustom {
@Column(name = "name", length = 50)
@@ -38,17 +46,6 @@ public class ExternalService extends AbstractPersistableCustom {
public static ExternalService fromJson(final JsonCommand command) {
final String name = command.stringValueOfParameterNamed("name");
return new ExternalService(name);
return new ExternalService().setName(name);
}
private ExternalService(final String name) {
this.name = name;
}
protected ExternalService() {}
public String name() {
return this.name;
}
}
@@ -21,35 +21,27 @@ package org.apache.fineract.infrastructure.configuration.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@Embeddable
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ExternalServicePropertiesPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "name", length = 150)
private String name;
@Column(name = "external_service_id")
private Long externalServiceId;
public ExternalServicePropertiesPK() {
}
public ExternalServicePropertiesPK(Long externalServiceId, String name) {
this.externalServiceId = externalServiceId;
this.name = name;
}
public String getName() {
return name;
}
public Long getExternalService() {
return externalServiceId;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
@@ -24,6 +24,10 @@ import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.configuration.data.ExternalServicesPropertiesData;
import org.apache.fineract.infrastructure.configuration.service.ExternalServicesConstants.ExternalservicePropertiesJSONinputParams;
@@ -32,6 +36,10 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
@Entity
@Table(name = "c_external_service_properties")
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ExternalServicesProperties {
@EmbeddedId
@@ -40,21 +48,11 @@ public class ExternalServicesProperties {
@Column(name = "value", length = 250)
private String value;
protected ExternalServicesProperties() {
}
private ExternalServicesProperties(final ExternalServicePropertiesPK externalServicePropertiesPK, final String value) {
this.externalServicePropertiesPK = externalServicePropertiesPK;
this.value = value;
}
public static ExternalServicesProperties fromJson(final ExternalService externalService, final JsonCommand command) {
final String name = command.stringValueOfParameterNamed(ExternalservicePropertiesJSONinputParams.NAME.getValue());
final String value = command.stringValueOfParameterNamed(ExternalservicePropertiesJSONinputParams.VALUE.getValue());
return new ExternalServicesProperties(new ExternalServicePropertiesPK(externalService.getId(), name), value);
return new ExternalServicesProperties().setExternalServicePropertiesPK(
new ExternalServicePropertiesPK().setExternalServiceId(externalService.getId()).setName(name)).setValue(value);
}
public Map<String, Object> update(final JsonCommand command, String paramName) {
@@ -76,6 +74,6 @@ public class ExternalServicesProperties {
}
public ExternalServicesPropertiesData toData() {
return new ExternalServicesPropertiesData(this.externalServicePropertiesPK.getName(), this.value);
return new ExternalServicesPropertiesData().setName(this.externalServicePropertiesPK.getName()).setValue(this.value);
}
}
@@ -24,6 +24,10 @@ import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData;
import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -32,6 +36,10 @@ import org.apache.fineract.infrastructure.security.exception.ForcePasswordResetE
@Entity
@Table(name = "c_configuration")
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class GlobalConfigurationProperty extends AbstractPersistableCustom {
@Column(name = "name", nullable = false)
@@ -55,43 +63,6 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
@Column(name = "is_trap_door", nullable = false)
private boolean isTrapDoor;
protected GlobalConfigurationProperty() {
this.name = null;
this.enabled = false;
this.value = null;
this.dateValue = null;
this.stringValue = null;
this.description = null;
this.isTrapDoor = false;
}
public GlobalConfigurationProperty(final String name, final boolean enabled, final Long value, final LocalDate dateValue,
final String stringValue, final String description, final boolean isTrapDoor) {
this.name = name;
this.enabled = enabled;
this.value = value;
this.dateValue = dateValue;
this.stringValue = stringValue;
this.description = description;
this.isTrapDoor = isTrapDoor;
}
public boolean isEnabled() {
return this.enabled;
}
public Long getValue() {
return this.value;
}
public LocalDate getDateValue() {
return this.dateValue;
}
public String getStringValue() {
return this.stringValue;
}
public Map<String, Object> update(final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
@@ -142,16 +113,13 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
}
public static GlobalConfigurationProperty newSurveyConfiguration(final String name) {
return new GlobalConfigurationProperty(name, false, null, null, null, null, false);
return new GlobalConfigurationProperty().setName(name);
}
public GlobalConfigurationPropertyData toData() {
return new GlobalConfigurationPropertyData(getName(), isEnabled(), getValue(), getDateValue(), getStringValue(), this.getId(),
this.description, this.isTrapDoor);
}
return new GlobalConfigurationPropertyData().setName(getName()).setEnabled(isEnabled()).setValue(getValue())
.setDateValue(getDateValue()).setStringValue(getStringValue()).setId(this.getId()).setDescription(this.description)
.setTrapDoor(this.isTrapDoor);
public String getName() {
return this.name;
}
}
@@ -64,7 +64,7 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
final List<GlobalConfigurationPropertyData> globalConfiguration = this.jdbcTemplate.query(sql, this.rm,
survey ? new Object[] { DataTableApiConstant.CATEGORY_PPI } : new Object[] {});
return new GlobalConfigurationData(globalConfiguration);
return new GlobalConfigurationData().setGlobalConfiguration(globalConfiguration);
}
@Override
@@ -107,7 +107,8 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
final Long id = rs.getLong("id");
final boolean isTrapDoor = rs.getBoolean("is_trap_door");
final LocalDate localDate = dateValue != null ? dateValue.toLocalDate() : null;
return new GlobalConfigurationPropertyData(name, enabled, value, localDate, stringValue, id, description, isTrapDoor);
return new GlobalConfigurationPropertyData().setName(name).setEnabled(enabled).setValue(value).setDateValue(localDate)
.setStringValue(stringValue).setId(id).setDescription(description).setTrapDoor(isTrapDoor);
}
}
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.configuration.data.ExternalServicesData;
import org.apache.fineract.infrastructure.configuration.domain.ExternalServicesProperties;
import org.apache.fineract.infrastructure.configuration.domain.ExternalServicesPropertiesRepository;
@@ -33,11 +34,11 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuild
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class ExternalServiceWritePlatformServiceJpaRepositoryImpl implements ExternalServiceWritePlatformService {
@SuppressWarnings("unused")
@@ -49,19 +50,6 @@ public class ExternalServiceWritePlatformServiceJpaRepositoryImpl implements Ext
private final ExternalServicesPropertiesCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final ExternalServicesReadPlatformService readPlatformService;
@Autowired
public ExternalServiceWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final ExternalServicesPropertiesRepositoryWrapper repositoryWrapper, final ExternalServicesPropertiesRepository repository,
final ExternalServicesPropertiesCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final ExternalServicesReadPlatformService readPlatformService) {
this.context = context;
this.repositoryWrapper = repositoryWrapper;
this.repository = repository;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.readPlatformService = readPlatformService;
}
@Transactional
@Override
public CommandProcessingResult updateExternalServicesProperties(String externalServiceName, JsonCommand command) {
@@ -21,13 +21,13 @@ package org.apache.fineract.infrastructure.configuration.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.campaigns.sms.data.MessageGatewayConfigurationData;
import org.apache.fineract.infrastructure.configuration.data.ExternalServicesPropertiesData;
import org.apache.fineract.infrastructure.configuration.data.S3CredentialsData;
import org.apache.fineract.infrastructure.configuration.data.SMTPCredentialsData;
import org.apache.fineract.infrastructure.configuration.exception.ExternalServiceConfigurationNotFoundException;
import org.apache.fineract.infrastructure.gcm.domain.NotificationConfigurationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
@@ -35,15 +35,11 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ExternalServicesPropertiesReadPlatformServiceImpl implements ExternalServicesPropertiesReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public ExternalServicesPropertiesReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
private static final class S3CredentialsDataExtractor implements ResultSetExtractor<S3CredentialsData> {
@Override
@@ -60,7 +56,7 @@ public class ExternalServicesPropertiesReadPlatformServiceImpl implements Extern
secretKey = rs.getString("value");
}
}
return new S3CredentialsData(bucketName, accessKey, secretKey);
return new S3CredentialsData().setBucketName(bucketName).setAccessKey(accessKey).setSecretKey(secretKey);
}
}
@@ -96,7 +92,8 @@ public class ExternalServicesPropertiesReadPlatformServiceImpl implements Extern
fromName = value;
}
}
return new SMTPCredentialsData(username, password, host, port, useTLS, fromEmail, fromName);
return new SMTPCredentialsData().setUsername(username).setPassword(password).setHost(host).setPort(port).setUseTLS(useTLS)
.setFromEmail(fromEmail).setFromName(fromName);
}
}
@@ -111,7 +108,7 @@ public class ExternalServicesPropertiesReadPlatformServiceImpl implements Extern
if (name != null && "password".equalsIgnoreCase(name)) {
value = "XXXX";
}
return new ExternalServicesPropertiesData(name, value);
return new ExternalServicesPropertiesData().setName(name).setValue(value);
}
}
@@ -20,24 +20,20 @@ package org.apache.fineract.infrastructure.configuration.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.configuration.data.ExternalServicesData;
import org.apache.fineract.infrastructure.configuration.exception.ExternalServiceConfigurationNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ExternalServicesReadPlatformServiceImpl implements ExternalServicesReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public ExternalServicesReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public ExternalServicesData getExternalServiceDetailsByServiceName(String serviceName) {
// TODO Auto-generated method stub
@@ -80,7 +76,8 @@ public class ExternalServicesReadPlatformServiceImpl implements ExternalServices
id = rs.getLong("id");
}
return new ExternalServicesData(id, name);
return new ExternalServicesData().setId(id).setName(name);
}
}
@@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.configuration.service;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationDataValidator;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
@@ -30,7 +31,6 @@ import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityEx
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.orm.jpa.JpaSystemException;
@@ -38,6 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements GlobalConfigurationWritePlatformService {
private static final Logger LOG = LoggerFactory.getLogger(GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.class);
@@ -47,17 +48,6 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements
private final GlobalConfigurationDataValidator globalConfigurationDataValidator;
private final ConfigurationDomainService configurationDomainService;
@Autowired
public GlobalConfigurationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final GlobalConfigurationRepositoryWrapper codeRepository, final GlobalConfigurationDataValidator dataValidator,
final ConfigurationDomainService configurationDomainService) {
this.context = context;
this.repository = codeRepository;
this.globalConfigurationDataValidator = dataValidator;
this.configurationDomainService = configurationDomainService;
}
@Transactional
@Override
public CommandProcessingResult update(final Long configId, final JsonCommand command) {