refactor: add lombok codes module

This commit is contained in:
Hemant Gupta
2022-10-13 13:02:49 +02:00
committed by Arnold Gálovics
parent 0f2850fff5
commit b4cd3cf54f
8 changed files with 62 additions and 95 deletions
@@ -134,7 +134,7 @@ public class ChartOfAccountsImportHandler implements ImportHandler {
CodeValueData tagIdCodeValueData = null;
if (ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL, row) != null) {
tagId = Long.parseLong(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL, row));
tagIdCodeValueData = new CodeValueData(tagId);
tagIdCodeValueData = new CodeValueData().setId(tagId);
}
String description = ImportHandlerUtils.readAsString(ChartOfAcountsConstants.DESCRIPTION_COL, row);
if (ImportHandlerUtils.readAsString(ChartOfAcountsConstants.OFFICE_COL, row) != null) {
@@ -19,29 +19,27 @@
package org.apache.fineract.infrastructure.codes.data;
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* Immutable data object representing a code.
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public final class CodeData implements Serializable {
private final Long id;
private Long id;
@SuppressWarnings("unused")
private final String name;
private String name;
@SuppressWarnings("unused")
private final boolean systemDefined;
private boolean systemDefined;
public static CodeData instance(final Long id, final String name, final boolean systemDefined) {
return new CodeData(id, name, systemDefined);
return new CodeData().setId(id).setName(name).setSystemDefined(systemDefined);
}
private CodeData(final Long id, final String name, final boolean systemDefined) {
this.id = id;
this.name = name;
this.systemDefined = systemDefined;
}
public Long getCodeId() {
return this.id;
}
}
@@ -19,47 +19,45 @@
package org.apache.fineract.infrastructure.codes.data;
import java.io.Serializable;
import lombok.Getter;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* Immutable data object represent code-value data in system.
*/
@Getter
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class CodeValueData implements Serializable {
private final Long id;
private final String name;
private final Integer position;
private final String description;
private final boolean active;
private final boolean mandatory;
public CodeValueData(final Long id) {
this.id = id;
this.name = null;
this.position = null;
this.description = null;
this.active = false;
this.mandatory = false;
}
private Long id;
private String name;
private Integer position;
private String description;
private boolean active;
private boolean mandatory;
public static CodeValueData instance(final Long id, final String name, final Integer position, final boolean isActive,
final boolean mandatory) {
String description = null;
return new CodeValueData(id, name, position, description, isActive, mandatory);
return new CodeValueData().setId(id).setName(name).setPosition(position).setDescription(description).setActive(isActive)
.setMandatory(mandatory);
}
public static CodeValueData instance(final Long id, final String name, final String description, final boolean isActive,
final boolean mandatory) {
Integer position = null;
return new CodeValueData(id, name, position, description, isActive, mandatory);
return new CodeValueData().setId(id).setName(name).setPosition(position).setDescription(description).setActive(isActive)
.setMandatory(mandatory);
}
public static CodeValueData instance(final Long id, final String name, final String description, final boolean isActive) {
Integer position = null;
boolean mandatory = false;
return new CodeValueData(id, name, position, description, isActive, mandatory);
return new CodeValueData().setId(id).setName(name).setPosition(position).setDescription(description).setActive(isActive)
.setMandatory(mandatory);
}
public static CodeValueData instance(final Long id, final String name) {
@@ -68,21 +66,13 @@ public class CodeValueData implements Serializable {
boolean isActive = false;
boolean mandatory = false;
return new CodeValueData(id, name, position, description, isActive, mandatory);
return new CodeValueData().setId(id).setName(name).setPosition(position).setDescription(description).setActive(isActive)
.setMandatory(mandatory);
}
public static CodeValueData instance(final Long id, final String name, final Integer position, final String description,
final boolean isActive, final boolean mandatory) {
return new CodeValueData(id, name, position, description, isActive, mandatory);
}
private CodeValueData(final Long id, final String name, final Integer position, final String description, final boolean active,
final boolean mandatory) {
this.id = id;
this.name = name;
this.position = position;
this.description = description;
this.active = active;
this.mandatory = mandatory;
return new CodeValueData().setId(id).setName(name).setPosition(position).setDescription(description).setActive(isActive)
.setMandatory(mandatory);
}
}
@@ -28,6 +28,10 @@ import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -35,6 +39,10 @@ import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@Entity
@Table(name = "m_code", uniqueConstraints = { @UniqueConstraint(columnNames = { "code_name" }, name = "code_name") })
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class Code extends AbstractPersistableCustom {
@Column(name = "code_name", length = 100)
@@ -48,28 +56,11 @@ public class Code extends AbstractPersistableCustom {
public static Code fromJson(final JsonCommand command) {
final String name = command.stringValueOfParameterNamed("name");
return new Code(name);
return new Code().setName(name);
}
public static Code createNew(final String name) {
return new Code(name);
}
protected Code() {
this.systemDefined = false;
}
private Code(final String name) {
this.name = name;
this.systemDefined = false;
}
public String name() {
return this.name;
}
public boolean isSystemDefined() {
return this.systemDefined;
return new Code().setName(name);
}
public Map<String, Object> update(final JsonCommand command) {
@@ -26,6 +26,10 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.CodeConstants.CodevalueJSONinputParams;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
@@ -35,6 +39,10 @@ import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@Entity
@Table(name = "m_code_value", uniqueConstraints = {
@UniqueConstraint(columnNames = { "code_id", "code_value" }, name = "code_value_duplicate") })
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class CodeValue extends AbstractPersistableCustom {
@Column(name = "code_value", length = 100)
@@ -58,29 +66,8 @@ public class CodeValue extends AbstractPersistableCustom {
public static CodeValue createNew(final Code code, final String label, final int position, final String description,
final boolean isActive, final boolean mandatory) {
return new CodeValue(code, label, position, description, isActive, mandatory);
}
protected CodeValue() {
//
}
private CodeValue(final Code code, final String label, final int position, final String description, final boolean isActive,
final boolean mandatory) {
this.code = code;
this.label = StringUtils.defaultIfEmpty(label, null);
this.position = position;
this.description = description;
this.isActive = isActive;
this.mandatory = mandatory;
}
public String label() {
return this.label;
}
public int position() {
return this.position;
return new CodeValue().setCode(code).setLabel(StringUtils.defaultIfEmpty(label, null)).setPosition(position)
.setDescription(description).setActive(isActive).setMandatory(mandatory);
}
public static CodeValue fromJson(final Code code, final JsonCommand command) {
@@ -99,7 +86,8 @@ public class CodeValue extends AbstractPersistableCustom {
Boolean mandatory = command.booleanPrimitiveValueOfParameterNamed(CodevalueJSONinputParams.IS_MANDATORY.getValue());
return new CodeValue(code, label, position, description, isActive, mandatory);
return new CodeValue().setCode(code).setLabel(StringUtils.defaultIfEmpty(label, null)).setPosition(position)
.setDescription(description).setActive(isActive).setMandatory(mandatory);
}
public Map<String, Object> update(final JsonCommand command) {
@@ -538,7 +538,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
if (StringUtils.isNotBlank(code)) {
if (isConstraintApproach) {
codeMappings.put(dataTableNameAlias + "_" + name, this.codeReadPlatformService.retriveCode(code).getCodeId());
codeMappings.put(dataTableNameAlias + "_" + name, this.codeReadPlatformService.retriveCode(code).getId());
String fkName = "fk_" + dataTableNameAlias + "_" + name;
constrainBuilder.append(", CONSTRAINT ").append(sqlGenerator.escape(fkName)).append(" ")
.append("FOREIGN KEY (" + sqlGenerator.escape(name) + ") ").append("REFERENCES ")
@@ -750,7 +750,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
}
}
if (newCode != null) {
codeMappings.put(dataTableNameAlias + "_" + newName, this.codeReadPlatformService.retriveCode(newCode).getCodeId());
codeMappings.put(dataTableNameAlias + "_" + newName, this.codeReadPlatformService.retriveCode(newCode).getId());
if (code == null || !StringUtils.equalsIgnoreCase(name, newName)) {
constrainBuilder.append(",ADD CONSTRAINT ").append(sqlGenerator.escape(newFkName)).append(" ")
.append("FOREIGN KEY (" + sqlGenerator.escape(newName) + ") ").append("REFERENCES ")
@@ -824,7 +824,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
if (StringUtils.isNotBlank(code)) {
if (isConstraintApproach) {
String fkName = "fk_" + dataTableNameAlias + "_" + name;
codeMappings.put(dataTableNameAlias + "_" + name, this.codeReadPlatformService.retriveCode(code).getCodeId());
codeMappings.put(dataTableNameAlias + "_" + name, this.codeReadPlatformService.retriveCode(code).getId());
constrainBuilder.append(",ADD CONSTRAINT ").append(sqlGenerator.escape(fkName)).append(" ")
.append("FOREIGN KEY (" + sqlGenerator.escape(name) + ") ").append("REFERENCES ")
.append(sqlGenerator.escape(CODE_VALUES_TABLE)).append(" (id)");
@@ -79,7 +79,7 @@ public class AccountNumberGenerator {
propertyMap.put(ENTITY_TYPE, "client");
CodeValue clientType = client.clientType();
if (clientType != null) {
propertyMap.put(CLIENT_TYPE, clientType.label());
propertyMap.put(CLIENT_TYPE, clientType.getLabel());
}
return generateAccountNumber(propertyMap, accountNumberFormat);
}
@@ -86,7 +86,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl
final CodeValue documentType = this.codeValueRepository
.findOneWithNotFoundDetection(clientIdentifierCommand.getDocumentTypeId());
documentTypeId = documentType.getId();
documentTypeLabel = documentType.label();
documentTypeLabel = documentType.getLabel();
final ClientIdentifier clientIdentifier = ClientIdentifier.fromJson(client, documentType, command);
@@ -136,7 +136,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl
}
documentTypeId = documentType.getId();
documentTypeLabel = documentType.label();
documentTypeLabel = documentType.getLabel();
clientIdentifierForUpdate.update(documentType);
}