refactor: add lombok to reportmailingjob module

This commit is contained in:
Hemant Gupta
2022-10-12 12:55:28 +02:00
committed by Arnold Gálovics
parent 8862f1f824
commit 6d2447e327
11 changed files with 156 additions and 796 deletions
@@ -165,25 +165,25 @@ public class ExecuteReportMailingJobsTasklet implements Tasklet {
final LocalDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); final LocalDateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();
ReportMailingJobPreviousRunStatus reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.SUCCESS; ReportMailingJobPreviousRunStatus reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.SUCCESS;
reportMailingJob.updatePreviousRunErrorLog(null); reportMailingJob.setPreviousRunErrorLog(null);
if (errorLog != null && errorLog.length() > 0) { if (errorLog != null && errorLog.length() > 0) {
reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.ERROR; reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.ERROR;
reportMailingJob.updatePreviousRunErrorLog(errorLog.toString()); reportMailingJob.setPreviousRunErrorLog(errorLog.toString());
} }
reportMailingJob.increaseNumberOfRunsByOne(); reportMailingJob.increaseNumberOfRunsByOne();
reportMailingJob.updatePreviousRunStatus(reportMailingJobPreviousRunStatus.getValue()); reportMailingJob.setPreviousRunStatus(reportMailingJobPreviousRunStatus.getValue());
reportMailingJob.updatePreviousRunDateTime(reportMailingJob.getNextRunDateTime()); reportMailingJob.setPreviousRunDateTime(reportMailingJob.getNextRunDateTime());
if (StringUtils.isEmpty(recurrence)) { if (StringUtils.isEmpty(recurrence)) {
reportMailingJob.deactivate(); reportMailingJob.setActive(false);
reportMailingJob.updateNextRunDateTime(null); reportMailingJob.setNextRunDateTime(null);
} else if (nextRunDateTime != null) { } else if (nextRunDateTime != null) {
final LocalDateTime nextRecurringDateTime = createNextRecurringDateTime(recurrence, nextRunDateTime); final LocalDateTime nextRecurringDateTime = createNextRecurringDateTime(recurrence, nextRunDateTime);
reportMailingJob.updateNextRunDateTime(nextRecurringDateTime); reportMailingJob.setNextRunDateTime(nextRecurringDateTime);
} }
reportMailingJobRepository.save(reportMailingJob); reportMailingJobRepository.save(reportMailingJob);
@@ -202,8 +202,8 @@ public class ExecuteReportMailingJobsTasklet implements Tasklet {
byteArrayOutputStream.writeTo(outputStream); byteArrayOutputStream.writeTo(outputStream);
for (String emailRecipient : emailRecipients) { for (String emailRecipient : emailRecipients) {
final ReportMailingJobEmailData reportMailingJobEmailData = new ReportMailingJobEmailData(emailRecipient, final ReportMailingJobEmailData reportMailingJobEmailData = new ReportMailingJobEmailData().setTo(emailRecipient)
reportMailingJob.getEmailMessage(), reportMailingJob.getEmailSubject(), file); .setText(reportMailingJob.getEmailMessage()).setSubject(reportMailingJob.getEmailSubject()).setAttachment(file);
reportMailingJobEmailService.sendEmailWithAttachment(reportMailingJobEmailData); reportMailingJobEmailService.sendEmailWithAttachment(reportMailingJobEmailData);
} }
@@ -18,23 +18,21 @@
*/ */
package org.apache.fineract.infrastructure.reportmailingjob.data; package org.apache.fineract.infrastructure.reportmailingjob.data;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/** /**
* Immutable data object representing report mailing job configuration data. * Immutable data object representing report mailing job configuration data.
**/ **/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public final class ReportMailingJobConfigurationData { public final class ReportMailingJobConfigurationData {
private final int id; private int id;
private final String name; private String name;
private final String value; private String value;
/**
* ReportMailingJobConfigurationData private constructor
**/
private ReportMailingJobConfigurationData(final int id, final String name, final String value) {
this.id = id;
this.name = name;
this.value = value;
}
/** /**
* creates an instance of the ReportMailingJobConfigurationData class * creates an instance of the ReportMailingJobConfigurationData class
@@ -42,27 +40,6 @@ public final class ReportMailingJobConfigurationData {
* @return ReportMailingJobConfigurationData object * @return ReportMailingJobConfigurationData object
**/ **/
public static ReportMailingJobConfigurationData newInstance(final int id, final String name, final String value) { public static ReportMailingJobConfigurationData newInstance(final int id, final String name, final String value) {
return new ReportMailingJobConfigurationData(id, name, value); return new ReportMailingJobConfigurationData().setId(id).setName(name).setValue(value);
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the value
*/
public String getValue() {
return value;
} }
} }
@@ -20,67 +20,42 @@ package org.apache.fineract.infrastructure.reportmailingjob.data;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.dataqueries.data.ReportData; import org.apache.fineract.infrastructure.dataqueries.data.ReportData;
/** /**
* Immutable data object representing report mailing job data. * Immutable data object representing report mailing job data.
**/ **/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public final class ReportMailingJobData { public final class ReportMailingJobData {
private final Long id; private Long id;
private final String name; private String name;
private final String description; private String description;
private final ZonedDateTime startDateTime; private ZonedDateTime startDateTime;
private final String recurrence; private String recurrence;
private final ReportMailingJobTimelineData timeline; private ReportMailingJobTimelineData timeline;
private final String emailRecipients; private String emailRecipients;
private final String emailSubject; private String emailSubject;
private final String emailMessage; private String emailMessage;
private final EnumOptionData emailAttachmentFileFormat; private EnumOptionData emailAttachmentFileFormat;
private final ReportData stretchyReport; private ReportData stretchyReport;
private final String stretchyReportParamMap; private String stretchyReportParamMap;
private final ZonedDateTime previousRunDateTime; private ZonedDateTime previousRunDateTime;
private final ZonedDateTime nextRunDateTime; private ZonedDateTime nextRunDateTime;
private final String previousRunStatus; private String previousRunStatus;
private final String previousRunErrorLog; private String previousRunErrorLog;
private final String previousRunErrorMessage; private String previousRunErrorMessage;
private final Integer numberOfRuns; private Integer numberOfRuns;
private final boolean isActive; private boolean isActive;
private final List<EnumOptionData> emailAttachmentFileFormatOptions; private List<EnumOptionData> emailAttachmentFileFormatOptions;
private final List<EnumOptionData> stretchyReportParamDateOptions; private List<EnumOptionData> stretchyReportParamDateOptions;
private final Long runAsUserId; private Long runAsUserId;
private ReportMailingJobData(final Long id, final String name, final String description, final ZonedDateTime startDateTime,
final String recurrence, final ReportMailingJobTimelineData timeline, final String emailRecipients, final String emailSubject,
final String emailMessage, final EnumOptionData emailAttachmentFileFormat, final ReportData stretchyReport,
final String stretchyReportParamMap, final ZonedDateTime previousRunDateTime, final ZonedDateTime nextRunDateTime,
final String previousRunStatus, final String previousRunErrorLog, final String previousRunErrorMessage,
final Integer numberOfRuns, final boolean isActive, final List<EnumOptionData> emailAttachmentFileFormatOptions,
final List<EnumOptionData> stretchyReportParamDateOptions, final Long runAsUserId) {
this.id = id;
this.name = name;
this.description = description;
this.startDateTime = startDateTime;
this.recurrence = recurrence;
this.timeline = timeline;
this.emailRecipients = emailRecipients;
this.emailMessage = emailMessage;
this.emailSubject = emailSubject;
this.emailAttachmentFileFormat = emailAttachmentFileFormat;
this.stretchyReport = stretchyReport;
this.stretchyReportParamMap = stretchyReportParamMap;
this.previousRunDateTime = previousRunDateTime;
this.nextRunDateTime = nextRunDateTime;
this.previousRunStatus = previousRunStatus;
this.previousRunErrorLog = previousRunErrorLog;
this.previousRunErrorMessage = previousRunErrorMessage;
this.isActive = isActive;
this.numberOfRuns = numberOfRuns;
this.emailAttachmentFileFormatOptions = emailAttachmentFileFormatOptions;
this.stretchyReportParamDateOptions = stretchyReportParamDateOptions;
this.runAsUserId = runAsUserId;
}
/** /**
* @return an instance of the ReportMailingJobData class * @return an instance of the ReportMailingJobData class
@@ -92,9 +67,13 @@ public final class ReportMailingJobData {
final ZonedDateTime previousRunDateTime, final ZonedDateTime nextRunDateTime, final String previousRunStatus, final ZonedDateTime previousRunDateTime, final ZonedDateTime nextRunDateTime, final String previousRunStatus,
final String previousRunErrorLog, final String previousRunErrorMessage, final Integer numberOfRuns, final boolean isActive, final String previousRunErrorLog, final String previousRunErrorMessage, final Integer numberOfRuns, final boolean isActive,
final Long runAsUserId) { final Long runAsUserId) {
return new ReportMailingJobData(id, name, description, startDateTime, recurrence, timeline, emailRecipients, emailSubject, return new ReportMailingJobData().setId(id).setName(name).setDescription(description).setStartDateTime(startDateTime)
emailMessage, emailAttachmentFileFormat, stretchyReport, stretchyReportParamMap, previousRunDateTime, nextRunDateTime, .setRecurrence(recurrence).setTimeline(timeline).setEmailRecipients(emailRecipients).setEmailSubject(emailSubject)
previousRunStatus, previousRunErrorLog, previousRunErrorMessage, numberOfRuns, isActive, null, null, runAsUserId); .setEmailMessage(emailMessage).setEmailAttachmentFileFormat(emailAttachmentFileFormat).setStretchyReport(stretchyReport)
.setStretchyReportParamMap(stretchyReportParamMap).setPreviousRunDateTime(previousRunDateTime)
.setNextRunDateTime(nextRunDateTime).setPreviousRunStatus(previousRunStatus).setPreviousRunErrorLog(previousRunErrorLog)
.setPreviousRunErrorMessage(previousRunErrorMessage).setNumberOfRuns(numberOfRuns).setActive(isActive)
.setRunAsUserId(runAsUserId);
} }
/** /**
@@ -102,8 +81,8 @@ public final class ReportMailingJobData {
**/ **/
public static ReportMailingJobData newInstance(final List<EnumOptionData> emailAttachmentFileFormatOptions, public static ReportMailingJobData newInstance(final List<EnumOptionData> emailAttachmentFileFormatOptions,
final List<EnumOptionData> stretchyReportParamDateOptions) { final List<EnumOptionData> stretchyReportParamDateOptions) {
return new ReportMailingJobData(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, return new ReportMailingJobData().setEmailAttachmentFileFormatOptions(emailAttachmentFileFormatOptions)
null, null, false, emailAttachmentFileFormatOptions, stretchyReportParamDateOptions, null); .setStretchyReportParamDateOptions(stretchyReportParamDateOptions);
} }
/** /**
@@ -111,168 +90,21 @@ public final class ReportMailingJobData {
**/ **/
public static ReportMailingJobData newInstance(final ReportMailingJobData dataWithoutEnumOptions, public static ReportMailingJobData newInstance(final ReportMailingJobData dataWithoutEnumOptions,
final ReportMailingJobData dataWithEnumOptions) { final ReportMailingJobData dataWithEnumOptions) {
return new ReportMailingJobData(dataWithoutEnumOptions.id, dataWithoutEnumOptions.name, dataWithoutEnumOptions.description, return new ReportMailingJobData().setId(dataWithoutEnumOptions.id).setName(dataWithoutEnumOptions.name)
dataWithoutEnumOptions.startDateTime, dataWithoutEnumOptions.recurrence, dataWithoutEnumOptions.timeline, .setDescription(dataWithoutEnumOptions.description).setStartDateTime(dataWithoutEnumOptions.startDateTime)
dataWithoutEnumOptions.emailRecipients, dataWithoutEnumOptions.emailSubject, dataWithoutEnumOptions.emailMessage, .setRecurrence(dataWithoutEnumOptions.recurrence).setTimeline(dataWithoutEnumOptions.timeline)
dataWithoutEnumOptions.emailAttachmentFileFormat, dataWithoutEnumOptions.stretchyReport, .setEmailRecipients(dataWithoutEnumOptions.emailRecipients).setEmailSubject(dataWithoutEnumOptions.emailSubject)
dataWithoutEnumOptions.stretchyReportParamMap, dataWithoutEnumOptions.previousRunDateTime, .setEmailMessage(dataWithoutEnumOptions.emailMessage)
dataWithoutEnumOptions.nextRunDateTime, dataWithoutEnumOptions.previousRunStatus, .setEmailAttachmentFileFormat(dataWithoutEnumOptions.emailAttachmentFileFormat)
dataWithoutEnumOptions.previousRunErrorLog, dataWithoutEnumOptions.previousRunErrorMessage, .setStretchyReport(dataWithoutEnumOptions.stretchyReport)
dataWithoutEnumOptions.numberOfRuns, dataWithoutEnumOptions.isActive, dataWithEnumOptions.emailAttachmentFileFormatOptions, .setStretchyReportParamMap(dataWithoutEnumOptions.stretchyReportParamMap)
dataWithEnumOptions.stretchyReportParamDateOptions, dataWithoutEnumOptions.runAsUserId); .setPreviousRunDateTime(dataWithoutEnumOptions.previousRunDateTime)
} .setNextRunDateTime(dataWithoutEnumOptions.nextRunDateTime).setPreviousRunStatus(dataWithoutEnumOptions.previousRunStatus)
.setPreviousRunErrorLog(dataWithoutEnumOptions.previousRunErrorLog)
/** .setPreviousRunErrorMessage(dataWithoutEnumOptions.previousRunErrorMessage)
* @return the id .setNumberOfRuns(dataWithoutEnumOptions.numberOfRuns).setActive(dataWithoutEnumOptions.isActive)
*/ .setEmailAttachmentFileFormatOptions(dataWithEnumOptions.emailAttachmentFileFormatOptions)
public Long getId() { .setStretchyReportParamDateOptions(dataWithEnumOptions.stretchyReportParamDateOptions)
return id; .setRunAsUserId(dataWithoutEnumOptions.runAsUserId);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @return the startDateTime
*/
public ZonedDateTime getStartDateTime() {
return startDateTime;
}
/**
* @return the recurrence
*/
public String getRecurrence() {
return recurrence;
}
/**
* @return the timeline
*/
public ReportMailingJobTimelineData getTimeline() {
return timeline;
}
/**
* @return the emailRecipients
*/
public String getEmailRecipients() {
return emailRecipients;
}
/**
* @return the emailSubject
*/
public String getEmailSubject() {
return emailSubject;
}
/**
* @return the emailMessage
*/
public String getEmailMessage() {
return emailMessage;
}
/**
* @return the emailAttachmentFileFormat
*/
public EnumOptionData getEmailAttachmentFileFormat() {
return emailAttachmentFileFormat;
}
/**
* @return the stretchyReport
*/
public ReportData getStretchyReport() {
return stretchyReport;
}
/**
* @return the stretchyReportParamMap
*/
public String getStretchyReportParamMap() {
return stretchyReportParamMap;
}
/**
* @return the previousRunDateTime
*/
public ZonedDateTime getPreviousRunDateTime() {
return previousRunDateTime;
}
/**
* @return the nextRunDateTime
*/
public ZonedDateTime getNextRunDateTime() {
return nextRunDateTime;
}
/**
* @return the previousRunStatus
*/
public String getPreviousRunStatus() {
return previousRunStatus;
}
/**
* @return the previousRunErrorLog
*/
public String getPreviousRunErrorLog() {
return previousRunErrorLog;
}
/**
* @return the previousRunErrorMessage
*/
public String getPreviousRunErrorMessage() {
return previousRunErrorMessage;
}
/**
* @return the isActive
*/
public boolean isActive() {
return isActive;
}
/**
* @return the emailAttachmentFileFormatOptions
*/
public List<EnumOptionData> getEmailAttachmentFileFormatOptions() {
return emailAttachmentFileFormatOptions;
}
/**
* @return the stretchyReportParamDateOptions
**/
public List<EnumOptionData> getStretchyReportParamDateOptions() {
return this.stretchyReportParamDateOptions;
}
/**
* @return the numberOfRuns
*/
public Integer getNumberOfRuns() {
return numberOfRuns;
}
/**
* @return the runAsUserId
*/
public Long getRunAsUserId() {
return runAsUserId;
} }
} }
@@ -19,49 +19,21 @@
package org.apache.fineract.infrastructure.reportmailingjob.data; package org.apache.fineract.infrastructure.reportmailingjob.data;
import java.io.File; import java.io.File;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/** /**
* Immutable data object representing report mailing job email data. * Immutable data object representing report mailing job email data.
**/ **/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class ReportMailingJobEmailData { public class ReportMailingJobEmailData {
private final String to; private String to;
private final String text; private String text;
private final String subject; private String subject;
private final File attachment; private File attachment;
public ReportMailingJobEmailData(final String to, final String text, final String subject, final File attachment) {
this.to = to;
this.text = text;
this.subject = subject;
this.attachment = attachment;
}
/**
* @return the to
*/
public String getTo() {
return to;
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @return the subject
*/
public String getSubject() {
return subject;
}
/**
* @return the attachment
*/
public File getAttachment() {
return attachment;
}
} }
@@ -19,33 +19,25 @@
package org.apache.fineract.infrastructure.reportmailingjob.data; package org.apache.fineract.infrastructure.reportmailingjob.data;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/** /**
* Immutable data object representing report mailing job run history data. * Immutable data object representing report mailing job run history data.
**/ **/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public final class ReportMailingJobRunHistoryData { public final class ReportMailingJobRunHistoryData {
private final Long id; private Long id;
private final Long reportMailingJobId; private Long reportMailingJobId;
private final ZonedDateTime startDateTime; private ZonedDateTime startDateTime;
private final ZonedDateTime endDateTime; private ZonedDateTime endDateTime;
private final String status; private String status;
private final String errorMessage; private String errorMessage;
private final String errorLog; private String errorLog;
/**
* ReportMailingJobRunHistoryData private constructor
**/
private ReportMailingJobRunHistoryData(Long id, Long reportMailingJobId, ZonedDateTime startDateTime, ZonedDateTime endDateTime,
String status, String errorMessage, String errorLog) {
this.id = id;
this.reportMailingJobId = reportMailingJobId;
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
this.status = status;
this.errorMessage = errorMessage;
this.errorLog = errorLog;
}
/** /**
* creates an instance of the ReportMailingJobRunHistoryData class * creates an instance of the ReportMailingJobRunHistoryData class
@@ -54,55 +46,7 @@ public final class ReportMailingJobRunHistoryData {
**/ **/
public static ReportMailingJobRunHistoryData newInstance(Long id, Long reportMailingJobId, ZonedDateTime startDateTime, public static ReportMailingJobRunHistoryData newInstance(Long id, Long reportMailingJobId, ZonedDateTime startDateTime,
ZonedDateTime endDateTime, String status, String errorMessage, String errorLog) { ZonedDateTime endDateTime, String status, String errorMessage, String errorLog) {
return new ReportMailingJobRunHistoryData(id, reportMailingJobId, startDateTime, endDateTime, status, errorMessage, errorLog); return new ReportMailingJobRunHistoryData().setId(id).setReportMailingJobId(reportMailingJobId).setStartDateTime(startDateTime)
} .setEndDateTime(endDateTime).setStatus(status).setErrorMessage(errorMessage).setErrorLog(errorLog);
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @return the reportMailingJobId
*/
public Long getReportMailingJobId() {
return reportMailingJobId;
}
/**
* @return the startDateTime
*/
public ZonedDateTime getStartDateTime() {
return startDateTime;
}
/**
* @return the endDateTime
*/
public ZonedDateTime getEndDateTime() {
return endDateTime;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @return the errorMessage
*/
public String getErrorMessage() {
return errorMessage;
}
/**
* @return the errorLog
*/
public String getErrorLog() {
return errorLog;
} }
} }
@@ -19,42 +19,25 @@
package org.apache.fineract.infrastructure.reportmailingjob.data; package org.apache.fineract.infrastructure.reportmailingjob.data;
import java.time.LocalDate; import java.time.LocalDate;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/** /**
* Immutable data object represent the timeline events of a report mailing job (creation) * Immutable data object represent the timeline events of a report mailing job (creation)
**/ **/
@Data
@NoArgsConstructor
@Accessors(chain = true)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ReportMailingJobTimelineData { public class ReportMailingJobTimelineData {
private final LocalDate createdOnDate; private LocalDate createdOnDate;
private final String createdByUsername; private String createdByUsername;
private final String createdByFirstname; private String createdByFirstname;
private final String createdByLastname; private String createdByLastname;
private final LocalDate updatedOnDate; private LocalDate updatedOnDate;
private final String updatedByUsername; private String updatedByUsername;
private final String updatedByFirstname; private String updatedByFirstname;
private final String updatedByLastname; private String updatedByLastname;
/**
* @param createdOnDate
* @param createdByUsername
* @param createdByFirstname
* @param createdByLastname
* @param updatedOnDate
* @param updatedByUsername
* @param updatedByFirstname
* @param updatedByLastname
*/
public ReportMailingJobTimelineData(LocalDate createdOnDate, String createdByUsername, String createdByFirstname,
String createdByLastname, LocalDate updatedOnDate, String updatedByUsername, String updatedByFirstname,
String updatedByLastname) {
this.createdOnDate = createdOnDate;
this.createdByUsername = createdByUsername;
this.createdByFirstname = createdByFirstname;
this.createdByLastname = createdByLastname;
this.updatedOnDate = updatedOnDate;
this.updatedByUsername = updatedByUsername;
this.updatedByFirstname = updatedByFirstname;
this.updatedByLastname = updatedByLastname;
}
} }
@@ -28,6 +28,10 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; 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.commons.lang3.StringUtils;
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;
@@ -35,11 +39,14 @@ import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.dataqueries.domain.Report; import org.apache.fineract.infrastructure.dataqueries.domain.Report;
import org.apache.fineract.infrastructure.reportmailingjob.ReportMailingJobConstants; import org.apache.fineract.infrastructure.reportmailingjob.ReportMailingJobConstants;
import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailAttachmentFileFormat; import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailAttachmentFileFormat;
import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobPreviousRunStatus;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
@Entity @Entity
@Table(name = "m_report_mailing_job", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "unique_name") }) @Table(name = "m_report_mailing_job", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "unique_name") })
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ReportMailingJob extends AbstractAuditableCustom { public class ReportMailingJob extends AbstractAuditableCustom {
private static final long serialVersionUID = -2197602941230009227L; private static final long serialVersionUID = -2197602941230009227L;
@@ -103,64 +110,6 @@ public class ReportMailingJob extends AbstractAuditableCustom {
@JoinColumn(name = "run_as_userid", nullable = false) @JoinColumn(name = "run_as_userid", nullable = false)
private AppUser runAsUser; private AppUser runAsUser;
/**
* ReportMailingJob protected constructor
**/
protected ReportMailingJob() {}
/**
* ReportMailingJob private constructor
**/
private ReportMailingJob(final String name, final String description, final LocalDateTime startDateTime, final String recurrence,
final String emailRecipients, final String emailSubject, final String emailMessage,
final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat, final Report stretchyReport,
final String stretchyReportParamMap, final LocalDateTime previousRunDateTime, final LocalDateTime nextRunDateTime,
final ReportMailingJobPreviousRunStatus previousRunStatus, final String previousRunErrorLog,
final String previousRunErrorMessage, final boolean isActive, final boolean isDeleted, final AppUser runAsUser) {
this.name = name;
this.description = description;
this.startDateTime = null;
if (startDateTime != null) {
this.startDateTime = startDateTime;
}
this.recurrence = recurrence;
this.emailRecipients = emailRecipients;
this.emailSubject = emailSubject;
this.emailMessage = emailMessage;
this.emailAttachmentFileFormat = emailAttachmentFileFormat.getValue();
this.stretchyReport = stretchyReport;
this.stretchyReportParamMap = stretchyReportParamMap;
this.previousRunDateTime = null;
if (previousRunDateTime != null) {
this.previousRunDateTime = previousRunDateTime;
}
this.nextRunDateTime = null;
if (nextRunDateTime != null) {
this.nextRunDateTime = nextRunDateTime;
}
this.previousRunStatus = null;
if (previousRunStatus != null) {
this.previousRunStatus = previousRunStatus.getValue();
}
if (numberOfRuns == null) {
this.numberOfRuns = 0;
}
this.previousRunErrorLog = previousRunErrorLog;
this.previousRunErrorMessage = previousRunErrorMessage;
this.isActive = isActive;
this.isDeleted = isDeleted;
this.runAsUser = runAsUser;
}
/** /**
* create a new instance of the ReportMailingJob for a new entry * create a new instance of the ReportMailingJob for a new entry
* *
@@ -170,9 +119,10 @@ public class ReportMailingJob extends AbstractAuditableCustom {
final String recurrence, final String emailRecipients, final String emailSubject, final String emailMessage, final String recurrence, final String emailRecipients, final String emailSubject, final String emailMessage,
final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat, final Report stretchyReport, final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat, final Report stretchyReport,
final String stretchyReportParamMap, final boolean isActive, final AppUser runAsUser) { final String stretchyReportParamMap, final boolean isActive, final AppUser runAsUser) {
return new ReportMailingJob(name, description, startDateTime, recurrence, emailRecipients, emailSubject, emailMessage, return new ReportMailingJob().setName(name).setDescription(description).setStartDateTime(startDateTime).setRecurrence(recurrence)
emailAttachmentFileFormat, stretchyReport, stretchyReportParamMap, null, null, null, null, null, isActive, false, .setEmailRecipients(emailRecipients).setEmailSubject(emailSubject).setEmailMessage(emailMessage)
runAsUser); .setEmailAttachmentFileFormat(emailAttachmentFileFormat.getValue()).setStretchyReport(stretchyReport)
.setStretchyReportParamMap(stretchyReportParamMap).setActive(isActive).setDeleted(false).setRunAsUser(runAsUser);
} }
/** /**
@@ -207,9 +157,11 @@ public class ReportMailingJob extends AbstractAuditableCustom {
} }
} }
return new ReportMailingJob(name, description, startDateTime, recurrence, emailRecipients, emailSubject, emailMessage, return new ReportMailingJob().setName(name).setDescription(description).setStartDateTime(startDateTime).setRecurrence(recurrence)
emailAttachmentFileFormat, stretchyReport, stretchyReportParamMap, null, startDateTime, null, null, null, isActive, false, .setEmailRecipients(emailRecipients).setEmailSubject(emailSubject).setEmailMessage(emailMessage)
runAsUser); .setEmailAttachmentFileFormat(emailAttachmentFileFormat.getValue()).setStretchyReport(stretchyReport)
.setStretchyReportParamMap(stretchyReportParamMap).setNextRunDateTime(startDateTime).setActive(isActive).setDeleted(false)
.setRunAsUser(runAsUser);
} }
/** /**
@@ -324,19 +276,6 @@ public class ReportMailingJob extends AbstractAuditableCustom {
return actualChanges; return actualChanges;
} }
/**
* update the stretchy report entity associated with the credit check
*
* @param stretchyReport
* -- Report entity
*
**/
public void update(final Report stretchyReport) {
if (stretchyReport != null) {
this.stretchyReport = stretchyReport;
}
}
/** /**
* delete the report mailing job, set the isDeleted property to 1 and alter the name * delete the report mailing job, set the isDeleted property to 1 and alter the name
* *
@@ -348,153 +287,6 @@ public class ReportMailingJob extends AbstractAuditableCustom {
this.name = this.name + "_deleted_" + this.getId(); this.name = this.name + "_deleted_" + this.getId();
} }
/**
* @return the value of the name property
**/
public String getName() {
return this.name;
}
/**
* @return the value of the description property
**/
public String getDescription() {
return this.description;
}
/**
* @return the value of the startDateTime property
**/
public LocalDateTime getStartDateTime() {
return this.startDateTime;
}
/**
* @return the value of the recurrence property
**/
public String getRecurrence() {
return this.recurrence;
}
/**
* @return value of the isDeleted property
**/
public boolean isDeleted() {
return this.isDeleted;
}
/**
* @return boolean true if isDeleted property equals 0, else false
**/
public boolean isNotDeleted() {
return !this.isDeleted;
}
/**
* @return the value of the isActive property
**/
public boolean isActive() {
return this.isActive;
}
/**
* @return boolean true if isActive property equals 0, else false
**/
public boolean isNotActive() {
return !this.isActive;
}
/**
* @return the emailRecipients
*/
public String getEmailRecipients() {
return emailRecipients;
}
/**
* @return the emailSubject
*/
public String getEmailSubject() {
return emailSubject;
}
/**
* @return the emailMessage
*/
public String getEmailMessage() {
return emailMessage;
}
/**
* @return the emailAttachmentFileFormat
*/
public String getEmailAttachmentFileFormat() {
return emailAttachmentFileFormat;
}
/**
* @return the stretchyReport
*/
public Report getStretchyReport() {
return stretchyReport;
}
/**
* @return the stretchyReportParamMap
*/
public String getStretchyReportParamMap() {
return stretchyReportParamMap;
}
/**
* @return the previousRunDateTime
*/
public LocalDateTime getPreviousRunDateTime() {
return this.previousRunDateTime;
}
/**
* @return the nextRunDateTime
*/
public LocalDateTime getNextRunDateTime() {
return this.nextRunDateTime;
}
/**
* @return the previousRunStatus
*/
public String getPreviousRunStatus() {
return previousRunStatus;
}
/**
* @return the previousRunErrorLog
*/
public String getPreviousRunErrorLog() {
return previousRunErrorLog;
}
/**
* @return the previousRunErrorMessage
*/
public String getPreviousRunErrorMessage() {
return previousRunErrorMessage;
}
/**
* @return the numberOfRuns
*/
public Integer getNumberOfRuns() {
return numberOfRuns;
}
/**
* @return the runAsUser
*/
public AppUser getRunAsUser() {
return runAsUser;
}
/** /**
* increase the numberOfRuns by 1 * increase the numberOfRuns by 1
* *
@@ -504,66 +296,4 @@ public class ReportMailingJob extends AbstractAuditableCustom {
this.numberOfRuns++; this.numberOfRuns++;
} }
/**
* update the previousRunStatus
*
* @param previousRunStatus
* -- the status of the previous job execution
*
**/
public void updatePreviousRunStatus(final String previousRunStatus) {
if (!StringUtils.isEmpty(previousRunStatus)) {
this.previousRunStatus = previousRunStatus;
}
}
/**
* update the previousRunDateTime
*
* @param previousRunDateTime
* -- previous run date
*
**/
public void updatePreviousRunDateTime(final LocalDateTime previousRunDateTime) {
if (previousRunDateTime != null) {
this.previousRunDateTime = previousRunDateTime;
}
}
/**
* update the nextRunDateTime
*
* @param nextRunDateTime
* -- the next run DateTime
*
**/
public void updateNextRunDateTime(final LocalDateTime nextRunDateTime) {
if (nextRunDateTime != null) {
this.nextRunDateTime = nextRunDateTime;
}
else {
this.nextRunDateTime = null;
}
}
/**
* deactivate the report mailing job by setting the isActive property to 0
*
*
**/
public void deactivate() {
this.isActive = false;
}
/**
* update the previousRunErrorLog property
*
* @param previousRunErrorLog
* -- the previous job run error log
*
**/
public void updatePreviousRunErrorLog(final String previousRunErrorLog) {
this.previousRunErrorLog = previousRunErrorLog;
}
} }
@@ -22,11 +22,19 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@Entity @Entity
@Table(name = "m_report_mailing_job_configuration", uniqueConstraints = { @Table(name = "m_report_mailing_job_configuration", uniqueConstraints = {
@UniqueConstraint(columnNames = { "name" }, name = "unique_name") }) @UniqueConstraint(columnNames = { "name" }, name = "unique_name") })
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ReportMailingJobConfiguration extends AbstractPersistableCustom { public class ReportMailingJobConfiguration extends AbstractPersistableCustom {
private static final long serialVersionUID = 3099279770861263184L; private static final long serialVersionUID = 3099279770861263184L;
@@ -37,39 +45,12 @@ public class ReportMailingJobConfiguration extends AbstractPersistableCustom {
@Column(name = "value", nullable = false) @Column(name = "value", nullable = false)
private String value; private String value;
/**
* ReportMailingJobConfiguration protected constructor
**/
protected ReportMailingJobConfiguration() {}
/**
* ReportMailingJobConfiguration private constructor
**/
private ReportMailingJobConfiguration(final String name, final String value) {
this.name = name;
this.value = value;
}
/** /**
* creates an instance of the ReportMailingJobConfiguration class * creates an instance of the ReportMailingJobConfiguration class
* *
* @return ReportMailingJobConfiguration object * @return ReportMailingJobConfiguration object
**/ **/
public static ReportMailingJobConfiguration newInstance(final String name, final String value) { public static ReportMailingJobConfiguration newInstance(final String name, final String value) {
return new ReportMailingJobConfiguration(name, value); return new ReportMailingJobConfiguration().setName(name).setValue(value);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the value
*/
public String getValue() {
return value;
} }
} }
@@ -24,10 +24,18 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@Entity @Entity
@Table(name = "m_report_mailing_job_run_history") @Table(name = "m_report_mailing_job_run_history")
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ReportMailingJobRunHistory extends AbstractPersistableCustom { public class ReportMailingJobRunHistory extends AbstractPersistableCustom {
private static final long serialVersionUID = -3757370929988421076L; private static final long serialVersionUID = -3757370929988421076L;
@@ -51,34 +59,6 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom {
@Column(name = "error_log", nullable = false) @Column(name = "error_log", nullable = false)
private String errorLog; private String errorLog;
/**
* ReportMailingJobRunHistory protected constructor
**/
protected ReportMailingJobRunHistory() {}
/**
* ReportMailingJobRunHistory private constructor
**/
private ReportMailingJobRunHistory(final ReportMailingJob reportMailingJob, final LocalDateTime startDateTime,
final LocalDateTime endDateTime, final String status, final String errorMessage, final String errorLog) {
this.reportMailingJob = reportMailingJob;
this.startDateTime = null;
if (startDateTime != null) {
this.startDateTime = startDateTime;
}
this.endDateTime = null;
if (endDateTime != null) {
this.endDateTime = endDateTime;
}
this.status = status;
this.errorMessage = errorMessage;
this.errorLog = errorLog;
}
/** /**
* Creates an instance of the ReportMailingJobRunHistory class * Creates an instance of the ReportMailingJobRunHistory class
* *
@@ -86,48 +66,7 @@ public class ReportMailingJobRunHistory extends AbstractPersistableCustom {
**/ **/
public static ReportMailingJobRunHistory newInstance(final ReportMailingJob reportMailingJob, final LocalDateTime startDateTime, public static ReportMailingJobRunHistory newInstance(final ReportMailingJob reportMailingJob, final LocalDateTime startDateTime,
final LocalDateTime endDateTime, final String status, final String errorMessage, final String errorLog) { final LocalDateTime endDateTime, final String status, final String errorMessage, final String errorLog) {
return new ReportMailingJobRunHistory(reportMailingJob, startDateTime, endDateTime, status, errorMessage, errorLog); return new ReportMailingJobRunHistory().setReportMailingJob(reportMailingJob).setStartDateTime(startDateTime)
} .setEndDateTime(endDateTime).setStatus(status).setErrorMessage(errorMessage).setErrorLog(errorLog);
/**
* @return the reportMailingJobId
*/
public ReportMailingJob getReportMailingJob() {
return this.reportMailingJob;
}
/**
* @return the startDateTime
*/
public LocalDateTime getStartDateTime() {
return this.startDateTime;
}
/**
* @return the endDateTime
*/
public LocalDateTime getEndDateTime() {
return this.endDateTime;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @return the errorMessage
*/
public String getErrorMessage() {
return errorMessage;
}
/**
* @return the errorLog
*/
public String getErrorLog() {
return errorLog;
} }
} }
@@ -181,8 +181,10 @@ public class ReportMailingJobReadPlatformServiceImpl implements ReportMailingJob
final String updatedByUsername = rs.getString("updatedByUsername"); final String updatedByUsername = rs.getString("updatedByUsername");
final String updatedByFirstname = rs.getString("updatedByFirstname"); final String updatedByFirstname = rs.getString("updatedByFirstname");
final String updatedByLastname = rs.getString("updatedByLastname"); final String updatedByLastname = rs.getString("updatedByLastname");
final ReportMailingJobTimelineData timeline = new ReportMailingJobTimelineData(createdOnDate, createdByUsername, final ReportMailingJobTimelineData timeline = new ReportMailingJobTimelineData().setCreatedOnDate(createdOnDate)
createdByFirstname, createdByLastname, updatedOnDate, updatedByUsername, updatedByFirstname, updatedByLastname); .setCreatedByUsername(createdByUsername).setCreatedByFirstname(createdByFirstname)
.setCreatedByLastname(createdByLastname).setUpdatedOnDate(updatedOnDate).setUpdatedByUsername(updatedByUsername)
.setUpdatedByFirstname(updatedByFirstname).setUpdatedByLastname(updatedByLastname);
final Long runAsUserId = JdbcSupport.getLong(rs, "runAsUserId"); final Long runAsUserId = JdbcSupport.getLong(rs, "runAsUserId");
final Long reportId = JdbcSupport.getLong(rs, "reportId"); final Long reportId = JdbcSupport.getLong(rs, "reportId");
@@ -123,7 +123,7 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo
final Report stretchyReport = this.reportRepositoryWrapper.findOneThrowExceptionIfNotFound(stretchyReportId); final Report stretchyReport = this.reportRepositoryWrapper.findOneThrowExceptionIfNotFound(stretchyReportId);
// update the stretchy report // update the stretchy report
reportMailingJob.update(stretchyReport); reportMailingJob.setStretchyReport(stretchyReport);
} }
// check if the recurrence was updated // check if the recurrence was updated
@@ -146,13 +146,13 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo
final LocalDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime); final LocalDateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime);
// update the next run time property // update the next run time property
reportMailingJob.updateNextRunDateTime(nextRecurringDateTime); reportMailingJob.setNextRunDateTime(nextRecurringDateTime);
// check if the next run LocalDateTime is not empty and the // check if the next run LocalDateTime is not empty and the
// recurrence is empty // recurrence is empty
} else if (StringUtils.isBlank(recurrence) && (nextRunDateTime != null)) { } else if (StringUtils.isBlank(recurrence) && (nextRunDateTime != null)) {
// the next run LocalDateTime should be set to null // the next run LocalDateTime should be set to null
reportMailingJob.updateNextRunDateTime(null); reportMailingJob.setNextRunDateTime(null);
} }
} }
@@ -170,7 +170,7 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo
} }
// update the next run time property // update the next run time property
reportMailingJob.updateNextRunDateTime(nextRecurringDateTime); reportMailingJob.setNextRunDateTime(nextRecurringDateTime);
} }
if (!changes.isEmpty()) { if (!changes.isEmpty()) {