refactor: add lombok to adhocquery module
This commit is contained in:
committed by
Arnold Gálovics
parent
33d781f5fb
commit
c761b40279
+1
-1
@@ -26,7 +26,7 @@ import java.util.Set;
|
|||||||
***/
|
***/
|
||||||
public enum AdHocJsonInputParams {
|
public enum AdHocJsonInputParams {
|
||||||
|
|
||||||
ID("id"), NAME("name"), QUERY("query"), TABLENAME("tableName"), TABLEFIELDS("tableFields"), ISACTIVE("isActive"), REPORT_RUN_FREQUENCY(
|
ID("id"), NAME("name"), QUERY("query"), TABLENAME("tableName"), TABLEFIELDS("tableFields"), ACTIVE("isActive"), REPORT_RUN_FREQUENCY(
|
||||||
"reportRunFrequency"), REPORT_RUN_EVERY("reportRunEvery"), EMAIL("email");
|
"reportRunFrequency"), REPORT_RUN_EVERY("reportRunEvery"), EMAIL("email");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|||||||
+23
-22
@@ -22,8 +22,9 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.Getter;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
import org.apache.fineract.adhocquery.domain.ReportRunFrequency;
|
import org.apache.fineract.adhocquery.domain.ReportRunFrequency;
|
||||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||||
|
|
||||||
@@ -31,32 +32,32 @@ import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
|||||||
* Immutable data object represent note or case information AdHocData
|
* Immutable data object represent note or case information AdHocData
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Data
|
||||||
@RequiredArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
public class AdHocData {
|
public class AdHocData {
|
||||||
|
|
||||||
private final Long id;
|
private Long id;
|
||||||
private final String name;
|
private String name;
|
||||||
private final String query;
|
private String query;
|
||||||
private final String tableName;
|
private String tableName;
|
||||||
private final String tableFields;
|
private String tableFields;
|
||||||
private final String email;
|
private String email;
|
||||||
private final boolean isActive;
|
private boolean isActive;
|
||||||
private final ZonedDateTime createdOn;
|
private ZonedDateTime createdOn;
|
||||||
private final Long createdById;
|
private Long createdById;
|
||||||
private final Long updatedById;
|
private Long updatedById;
|
||||||
private final ZonedDateTime updatedOn;
|
private ZonedDateTime updatedOn;
|
||||||
private final String createdBy;
|
private String createdBy;
|
||||||
private final List<EnumOptionData> reportRunFrequencies;
|
private List<EnumOptionData> reportRunFrequencies;
|
||||||
private final Long reportRunFrequency;
|
private Long reportRunFrequency;
|
||||||
private final Long reportRunEvery;
|
private Long reportRunEvery;
|
||||||
private final ZonedDateTime lastRun;
|
private ZonedDateTime lastRun;
|
||||||
|
|
||||||
public static AdHocData template() {
|
public static AdHocData template() {
|
||||||
List<EnumOptionData> reportRunFrequencies = Arrays.stream(ReportRunFrequency.values())
|
List<EnumOptionData> reportRunFrequencies = Arrays.stream(ReportRunFrequency.values())
|
||||||
.map(rrf -> new EnumOptionData(rrf.getValue(), rrf.getCode(), rrf.getCode())).collect(Collectors.toList());
|
.map(rrf -> new EnumOptionData(rrf.getValue(), rrf.getCode(), rrf.getCode())).collect(Collectors.toList());
|
||||||
|
|
||||||
return new AdHocData(null, null, null, null, null, null, false, null, null, null, null, null, reportRunFrequencies, null, null,
|
return new AdHocData().setReportRunFrequencies(reportRunFrequencies);
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,23 @@ import java.util.Map;
|
|||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.fineract.adhocquery.api.AdHocJsonInputParams;
|
import org.apache.fineract.adhocquery.api.AdHocJsonInputParams;
|
||||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
|
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
|
||||||
import org.apache.fineract.infrastructure.security.utils.SQLInjectionValidator;
|
import org.apache.fineract.infrastructure.security.utils.SQLInjectionValidator;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_adhoc")
|
@Table(name = "m_adhoc")
|
||||||
public final class AdHoc extends AbstractAuditableCustom {
|
public class AdHoc extends AbstractAuditableCustom {
|
||||||
|
|
||||||
@Column(name = "name", length = 100)
|
@Column(name = "name", length = 100)
|
||||||
private String name;
|
private String name;
|
||||||
@@ -56,22 +63,7 @@ public final class AdHoc extends AbstractAuditableCustom {
|
|||||||
private Long reportRunEvery;
|
private Long reportRunEvery;
|
||||||
|
|
||||||
@Column(name = "is_active", nullable = false)
|
@Column(name = "is_active", nullable = false)
|
||||||
private boolean isActive = false;
|
private boolean active;
|
||||||
|
|
||||||
private AdHoc() {}
|
|
||||||
|
|
||||||
private AdHoc(final String name, final String query, final String tableName, final String tableFields, final String email,
|
|
||||||
final Long reportRunFrequency, final Long reportRunEvery, final boolean isActive) {
|
|
||||||
this.name = StringUtils.defaultIfEmpty(name, null);
|
|
||||||
this.query = StringUtils.defaultIfEmpty(query, null);
|
|
||||||
this.tableName = StringUtils.defaultIfEmpty(tableName, null);
|
|
||||||
this.tableFields = StringUtils.defaultIfEmpty(tableFields, null);
|
|
||||||
this.email = StringUtils.defaultIfEmpty(email, null);
|
|
||||||
this.reportRunFrequency = reportRunFrequency;
|
|
||||||
this.reportRunEvery = reportRunEvery;
|
|
||||||
this.isActive = BooleanUtils.toBooleanDefaultIfNull(isActive, false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AdHoc fromJson(final JsonCommand command) {
|
public static AdHoc fromJson(final JsonCommand command) {
|
||||||
final String name = command.stringValueOfParameterNamed(AdHocJsonInputParams.NAME.getValue());
|
final String name = command.stringValueOfParameterNamed(AdHocJsonInputParams.NAME.getValue());
|
||||||
@@ -85,8 +77,11 @@ public final class AdHoc extends AbstractAuditableCustom {
|
|||||||
final String email = command.stringValueOfParameterNamed(AdHocJsonInputParams.EMAIL.getValue());
|
final String email = command.stringValueOfParameterNamed(AdHocJsonInputParams.EMAIL.getValue());
|
||||||
final Long reportRunFrequency = command.longValueOfParameterNamed(AdHocJsonInputParams.REPORT_RUN_FREQUENCY.getValue());
|
final Long reportRunFrequency = command.longValueOfParameterNamed(AdHocJsonInputParams.REPORT_RUN_FREQUENCY.getValue());
|
||||||
final Long reportRunEvery = command.longValueOfParameterNamed(AdHocJsonInputParams.REPORT_RUN_EVERY.getValue());
|
final Long reportRunEvery = command.longValueOfParameterNamed(AdHocJsonInputParams.REPORT_RUN_EVERY.getValue());
|
||||||
final boolean isActive = command.booleanPrimitiveValueOfParameterNamed(AdHocJsonInputParams.ISACTIVE.getValue());
|
final boolean active = command.booleanPrimitiveValueOfParameterNamed(AdHocJsonInputParams.ACTIVE.getValue());
|
||||||
return new AdHoc(name, query, tableName, tableFields, email, reportRunFrequency, reportRunEvery, isActive);
|
return new AdHoc().setName(StringUtils.defaultIfEmpty(name, null)).setQuery(StringUtils.defaultIfEmpty(query, null))
|
||||||
|
.setTableName(StringUtils.defaultIfEmpty(tableName, null)).setTableFields(StringUtils.defaultIfEmpty(tableFields, null))
|
||||||
|
.setEmail(StringUtils.defaultIfEmpty(email, null)).setReportRunFrequency(reportRunFrequency)
|
||||||
|
.setReportRunEvery(reportRunEvery).setActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> update(final JsonCommand command) {
|
public Map<String, Object> update(final JsonCommand command) {
|
||||||
@@ -136,52 +131,13 @@ public final class AdHoc extends AbstractAuditableCustom {
|
|||||||
actualChanges.put(reportRunEvery, newValue);
|
actualChanges.put(reportRunEvery, newValue);
|
||||||
this.reportRunEvery = newValue;
|
this.reportRunEvery = newValue;
|
||||||
}
|
}
|
||||||
final String paramisActive = "isActive";
|
final String paramisActive = "active";
|
||||||
if (command.isChangeInBooleanParameterNamed(paramisActive, this.isActive)) {
|
if (command.isChangeInBooleanParameterNamed(paramisActive, this.active)) {
|
||||||
final Boolean newValue = command.booleanObjectValueOfParameterNamed(paramisActive);
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(paramisActive);
|
||||||
actualChanges.put(paramisActive, newValue);
|
actualChanges.put(paramisActive, newValue);
|
||||||
this.isActive = newValue;
|
this.active = newValue;
|
||||||
}
|
}
|
||||||
return actualChanges;
|
return actualChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQuery() {
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTableName() {
|
|
||||||
return tableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTableFields() {
|
|
||||||
return tableFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive() {
|
|
||||||
return this.isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disableActive() {
|
|
||||||
this.isActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableActive() {
|
|
||||||
this.isActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getReportRunFrequency() {
|
|
||||||
return this.reportRunFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getReportRunEvery() {
|
|
||||||
return this.reportRunEvery;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -97,8 +97,11 @@ public class AdHocReadPlatformServiceImpl implements AdHocReadPlatformService {
|
|||||||
final Long reportRunEvery = JdbcSupport.getLong(rs, "report_run_every");
|
final Long reportRunEvery = JdbcSupport.getLong(rs, "report_run_every");
|
||||||
final ZonedDateTime lastRun = JdbcSupport.getDateTime(rs, "last_run");
|
final ZonedDateTime lastRun = JdbcSupport.getDateTime(rs, "last_run");
|
||||||
|
|
||||||
return new AdHocData(id, name, query, tableName, tableFields, email, isActive, createdDate, createdById, updatedById, updatedOn,
|
return new AdHocData().setId(id).setName(name).setQuery(query).setTableName(tableName).setTableFields(tableFields)
|
||||||
createdByUsername, AdHocData.template().getReportRunFrequencies(), reportRunFrequency, reportRunEvery, lastRun);
|
.setEmail(email).setActive(isActive).setCreatedOn(createdDate).setCreatedById(createdById).setUpdatedById(updatedById)
|
||||||
|
.setUpdatedOn(updatedOn).setCreatedBy(createdByUsername)
|
||||||
|
.setReportRunFrequencies(AdHocData.template().getReportRunFrequencies()).setReportRunFrequency(reportRunFrequency)
|
||||||
|
.setReportRunEvery(reportRunEvery).setLastRun(lastRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String schema() {
|
public String schema() {
|
||||||
|
|||||||
+2
-2
@@ -137,7 +137,7 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
|
|||||||
* Checking the adhocquery present in DB or not using adHocId
|
* Checking the adhocquery present in DB or not using adHocId
|
||||||
*/
|
*/
|
||||||
final AdHoc adHoc = this.adHocRepository.findById(adHocId).orElseThrow(() -> new AdHocNotFoundException(adHocId));
|
final AdHoc adHoc = this.adHocRepository.findById(adHocId).orElseThrow(() -> new AdHocNotFoundException(adHocId));
|
||||||
adHoc.disableActive();
|
adHoc.setActive(true);
|
||||||
this.adHocRepository.save(adHoc);
|
this.adHocRepository.save(adHoc);
|
||||||
return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
|
return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla
|
|||||||
* Checking the adHoc present in DB or not using id
|
* Checking the adHoc present in DB or not using id
|
||||||
*/
|
*/
|
||||||
final AdHoc adHoc = this.adHocRepository.findById(adHocId).orElseThrow(() -> new AdHocNotFoundException(adHocId));
|
final AdHoc adHoc = this.adHocRepository.findById(adHocId).orElseThrow(() -> new AdHocNotFoundException(adHocId));
|
||||||
adHoc.enableActive();
|
adHoc.setActive(false);
|
||||||
this.adHocRepository.save(adHoc);
|
this.adHocRepository.save(adHoc);
|
||||||
return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
|
return new CommandProcessingResultBuilder().withEntityId(adHocId).build();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user