FINERACT-2081: Fix code quality issues in Cashier domain class

This commit is contained in:
Hossam Hatem
2025-02-27 10:30:47 +01:00
committed by Adam Saghy
parent d9bb820cc6
commit 17d1aa580d
@@ -29,7 +29,6 @@ import jakarta.persistence.Transient;
import jakarta.persistence.UniqueConstraint; import jakarta.persistence.UniqueConstraint;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@@ -58,8 +57,8 @@ import org.apache.fineract.organisation.staff.domain.Staff;
@Accessors(chain = true) @Accessors(chain = true)
public class Cashier extends AbstractPersistableCustom<Long> { public class Cashier extends AbstractPersistableCustom<Long> {
// ManyToOne(fetch = FetchType.LAZY) private static final String IS_FULL_DAY_PARAM_NAME = "isFullDay";
// JoinColumn(name = "office_id", nullable = false)
@Transient @Transient
private Office office; private Office office;
@@ -91,23 +90,16 @@ public class Cashier extends AbstractPersistableCustom<Long> {
public static Cashier fromJson(final Office cashierOffice, final Teller teller, final Staff staff, final String startTime, public static Cashier fromJson(final Office cashierOffice, final Teller teller, final Staff staff, final String startTime,
final String endTime, final JsonCommand command) { final String endTime, final JsonCommand command) {
// final Long tellerId = teller.getId();
// final Long staffId = command.longValueOfParameterNamed("staffId");
final String description = command.stringValueOfParameterNamed("description"); final String description = command.stringValueOfParameterNamed("description");
final LocalDate startDate = command.localDateValueOfParameterNamed("startDate"); final LocalDate startDate = command.localDateValueOfParameterNamed("startDate");
final LocalDate endDate = command.localDateValueOfParameterNamed("endDate"); final LocalDate endDate = command.localDateValueOfParameterNamed("endDate");
final Boolean isFullDay = command.booleanObjectValueOfParameterNamed("isFullDay"); final Boolean isFullDay = command.booleanObjectValueOfParameterNamed(IS_FULL_DAY_PARAM_NAME);
/*
* final String startTime = command.stringValueOfParameterNamed("startTime"); final String endTime =
* command.stringValueOfParameterNamed("endTime");
*/
return new Cashier().setOffice(cashierOffice).setTeller(teller).setStaff(staff).setDescription(description).setStartDate(startDate) return new Cashier().setOffice(cashierOffice).setTeller(teller).setStaff(staff).setDescription(description).setStartDate(startDate)
.setEndDate(endDate).setIsFullDay(isFullDay).setStartTime(startTime).setEndTime(endTime); .setEndDate(endDate).setIsFullDay(isFullDay).setStartTime(startTime).setEndTime(endTime);
} }
public Map<String, Object> update(final JsonCommand command) { public Map<String, Object> update(final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<>(7); final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
final String dateFormatAsInput = command.dateFormat(); final String dateFormatAsInput = command.dateFormat();
@@ -140,19 +132,14 @@ public class Cashier extends AbstractPersistableCustom<Long> {
this.endDate = command.localDateValueOfParameterNamed(endDateParamName); this.endDate = command.localDateValueOfParameterNamed(endDateParamName);
} }
final Boolean isFullDay = command.booleanObjectValueOfParameterNamed("isFullDay"); final Boolean fullDayFlag = command.booleanObjectValueOfParameterNamed(IS_FULL_DAY_PARAM_NAME);
if (command.isChangeInBooleanParameterNamed(IS_FULL_DAY_PARAM_NAME, this.isFullDay)) {
final String isFullDayParamName = "isFullDay"; final Boolean newValue = command.booleanObjectValueOfParameterNamed(IS_FULL_DAY_PARAM_NAME);
if (command.isChangeInBooleanParameterNamed(isFullDayParamName, this.isFullDay)) { actualChanges.put(IS_FULL_DAY_PARAM_NAME, newValue);
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isFullDayParamName);
actualChanges.put(isFullDayParamName, newValue);
/*
* this.startTime="00"; this.endTime="00";
*/
this.isFullDay = newValue; this.isFullDay = newValue;
} }
if (!isFullDay) { if (!fullDayFlag) {
String newStartHour = ""; String newStartHour = "";
String newStartMin = ""; String newStartMin = "";
String newEndHour = ""; String newEndHour = "";
@@ -161,11 +148,12 @@ public class Cashier extends AbstractPersistableCustom<Long> {
final String minStartTimeParamName = "minStartTime"; final String minStartTimeParamName = "minStartTime";
final String hourEndTimeParamName = "hourEndTime"; final String hourEndTimeParamName = "hourEndTime";
final String minEndTimeParamName = "minEndTime"; final String minEndTimeParamName = "minEndTime";
if (command.isChangeInLongParameterNamed(hourStartTimeParamName, this.getHourFromStartTime()) if (command.isChangeInLongParameterNamed(hourStartTimeParamName, this.getHourFromStartTime())
|| command.isChangeInLongParameterNamed(minStartTimeParamName, this.getMinFromStartTime())) { || command.isChangeInLongParameterNamed(minStartTimeParamName, this.getMinFromStartTime())) {
newStartHour = command.stringValueOfParameterNamed(hourStartTimeParamName); newStartHour = command.stringValueOfParameterNamed(hourStartTimeParamName);
if (newEndHour.equalsIgnoreCase("0")) { if (newStartHour.equalsIgnoreCase("0")) {
newEndHour = newEndHour + "0"; newStartHour = newStartHour + "0";
} }
actualChanges.put(hourStartTimeParamName, newStartHour); actualChanges.put(hourStartTimeParamName, newStartHour);
newStartMin = command.stringValueOfParameterNamed(minStartTimeParamName); newStartMin = command.stringValueOfParameterNamed(minStartTimeParamName);
@@ -190,45 +178,26 @@ public class Cashier extends AbstractPersistableCustom<Long> {
actualChanges.put(minEndTimeParamName, newEndMin); actualChanges.put(minEndTimeParamName, newEndMin);
this.endTime = newEndHour + ":" + newEndMin; this.endTime = newEndHour + ":" + newEndMin;
} }
} }
return actualChanges; return actualChanges;
} }
public Long getHourFromStartTime() { public Long getHourFromStartTime() {
if (this.startTime != null && !this.startTime.equalsIgnoreCase("")) { return (this.startTime != null && !this.startTime.isEmpty()) ? Long.parseLong(Splitter.on(':').splitToList(this.startTime).get(1))
List<String> extractHourFromStartTime = Splitter.on(':').splitToList(this.startTime); : null;
Long hour = Long.parseLong(extractHourFromStartTime.get(1));
return hour;
}
return null;
} }
public Long getMinFromStartTime() { public Long getMinFromStartTime() {
if (this.startTime != null && !this.startTime.equalsIgnoreCase("")) { return (this.startTime != null && !this.startTime.isEmpty()) ? Long.parseLong(Splitter.on(':').splitToList(this.startTime).get(1))
List<String> extractMinFromStartTime = Splitter.on(':').splitToList(this.startTime); : null;
Long min = Long.parseLong(extractMinFromStartTime.get(1));
return min;
}
return null;
} }
public Long getHourFromEndTime() { public Long getHourFromEndTime() {
if (this.endTime != null && !this.endTime.equalsIgnoreCase("")) { return (this.endTime != null && !this.endTime.isEmpty()) ? Long.parseLong(Splitter.on(':').splitToList(this.endTime).get(0)) : null;
List<String> extractHourFromEndTime = Splitter.on(':').splitToList(this.endTime);
Long hour = Long.parseLong(extractHourFromEndTime.get(0));
return hour;
}
return null;
} }
public Long getMinFromEndTime() { public Long getMinFromEndTime() {
if (this.endTime != null && !this.endTime.equalsIgnoreCase("")) { return (this.endTime != null && !this.endTime.isEmpty()) ? Long.parseLong(Splitter.on(':').splitToList(this.endTime).get(1)) : null;
List<String> extractMinFromEndTime = Splitter.on(':').splitToList(this.endTime);
Long min = Long.parseLong(extractMinFromEndTime.get(1));
return min;
}
return null;
} }
} }