refactor: add lombok to notification module
This commit is contained in:
committed by
Arnold Gálovics
parent
5b935eb1ff
commit
0f2850fff5
+6
-16
@@ -21,10 +21,16 @@ package org.apache.fineract.notification.data;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class NotificationData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
private String objectType;
|
||||
private Long objectId;
|
||||
@@ -37,20 +43,4 @@ public class NotificationData implements Serializable {
|
||||
private String createdAt;
|
||||
private Long officeId;
|
||||
private Set<Long> userIds;
|
||||
|
||||
public NotificationData() {}
|
||||
|
||||
public NotificationData(String objectType, Long objectId, String action, Long actorId, String content, boolean isSystemGenerated,
|
||||
boolean isRead, String tenantIdentifier, Long officeId, Set<Long> userIds) {
|
||||
this.objectType = objectType;
|
||||
this.objectId = objectId;
|
||||
this.action = action;
|
||||
this.actorId = actorId;
|
||||
this.content = content;
|
||||
this.isRead = isRead;
|
||||
this.isSystemGenerated = isSystemGenerated;
|
||||
this.tenantIdentifier = tenantIdentifier;
|
||||
this.officeId = officeId;
|
||||
this.userIds = userIds;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-50
@@ -18,6 +18,13 @@
|
||||
*/
|
||||
package org.apache.fineract.notification.data;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class NotificationMapperData {
|
||||
|
||||
private Long id;
|
||||
@@ -25,54 +32,4 @@ public class NotificationMapperData {
|
||||
private Long userId;
|
||||
private boolean isRead;
|
||||
private String createdAt;
|
||||
|
||||
public NotificationMapperData(Long id, Long notificationId, Long userId, boolean isRead, String createdAt) {
|
||||
this.id = id;
|
||||
this.notificationId = notificationId;
|
||||
this.userId = userId;
|
||||
this.isRead = isRead;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public NotificationMapperData() {}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getNotificationId() {
|
||||
return notificationId;
|
||||
}
|
||||
|
||||
public void setNotificationId(Long notificationId) {
|
||||
this.notificationId = notificationId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return isRead;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
isRead = read;
|
||||
}
|
||||
|
||||
public String getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(String createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-68
@@ -22,10 +22,18 @@ import java.time.LocalDateTime;
|
||||
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.core.domain.AbstractPersistableCustom;
|
||||
|
||||
@Entity
|
||||
@Table(name = "notification_generator")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class Notification extends AbstractPersistableCustom {
|
||||
|
||||
@Column(name = "object_type")
|
||||
@@ -48,72 +56,4 @@ public class Notification extends AbstractPersistableCustom {
|
||||
|
||||
@Column(name = "created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public Notification() {}
|
||||
|
||||
public Notification(String objectType, Long objectIdentifier, String action, Long actorId, boolean isSystemGenerated,
|
||||
String notificationContent, LocalDateTime createdAt) {
|
||||
this.objectType = objectType;
|
||||
this.objectIdentifier = objectIdentifier;
|
||||
this.action = action;
|
||||
this.actorId = actorId;
|
||||
this.isSystemGenerated = isSystemGenerated;
|
||||
this.notificationContent = notificationContent;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public String getObjectType() {
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public void setObjectType(String objectType) {
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public Long getObjectIdentifier() {
|
||||
return objectIdentifier;
|
||||
}
|
||||
|
||||
public void setObjectIdentifier(Long objectIdentifier) {
|
||||
this.objectIdentifier = objectIdentifier;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Long getActor() {
|
||||
return actorId;
|
||||
}
|
||||
|
||||
public void setActor(Long actorId) {
|
||||
this.actorId = actorId;
|
||||
}
|
||||
|
||||
public boolean isSystemGenerated() {
|
||||
return isSystemGenerated;
|
||||
}
|
||||
|
||||
public void setSystemGenerated(boolean systemGenerated) {
|
||||
isSystemGenerated = systemGenerated;
|
||||
}
|
||||
|
||||
public String getNotificationContent() {
|
||||
return notificationContent;
|
||||
}
|
||||
|
||||
public void setNotificationContent(String notificationContent) {
|
||||
this.notificationContent = notificationContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Notification [objectType=" + this.objectType + ", objectIdentifier=" + this.objectIdentifier + ", action=" + this.action
|
||||
+ ", actorId=" + this.actorId + ", isSystemGenerated=" + this.isSystemGenerated + ", notificationContent="
|
||||
+ this.notificationContent + ", createdAt=" + this.createdAt + ", getId()=" + this.getId() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
+8
-39
@@ -24,11 +24,19 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
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.useradministration.domain.AppUser;
|
||||
|
||||
@Entity
|
||||
@Table(name = "notification_mapper")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class NotificationMapper extends AbstractPersistableCustom {
|
||||
|
||||
@ManyToOne
|
||||
@@ -44,43 +52,4 @@ public class NotificationMapper extends AbstractPersistableCustom {
|
||||
|
||||
@Column(name = "created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public NotificationMapper() {}
|
||||
|
||||
public NotificationMapper(Notification notification, AppUser userId, boolean isRead, LocalDateTime createdAt) {
|
||||
this.notification = notification;
|
||||
this.userId = userId;
|
||||
this.isRead = isRead;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Notification getNotification() {
|
||||
return notification;
|
||||
}
|
||||
|
||||
public void setNotification(Notification notification) {
|
||||
this.notification = notification;
|
||||
}
|
||||
|
||||
public AppUser getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(AppUser userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return isRead;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
isRead = read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NotificationMapper [notification=" + this.notification + ", userId=" + this.userId + ", isRead=" + this.isRead
|
||||
+ ", createdAt=" + this.createdAt + ", getId()=" + this.getId() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -329,8 +329,9 @@ public class NotificationDomainServiceImpl implements NotificationDomainService
|
||||
|
||||
String tenantIdentifier = ThreadLocalContextUtil.getTenant().getTenantIdentifier();
|
||||
Set<Long> userIds = getNotifiableUserIds(officeId, permission);
|
||||
NotificationData notificationData = new NotificationData(objectType, objectIdentifier, eventType, appUserId, notificationContent,
|
||||
false, false, tenantIdentifier, officeId, userIds);
|
||||
NotificationData notificationData = new NotificationData().setObjectType(objectType).setObjectId(objectIdentifier)
|
||||
.setAction(eventType).setActorId(appUserId).setContent(notificationContent).setRead(false).setSystemGenerated(false)
|
||||
.setTenantIdentifier(tenantIdentifier).setOfficeId(officeId).setUserIds(userIds);
|
||||
try {
|
||||
notificationEventPublisher.broadcastNotification(notificationData);
|
||||
} catch (Exception e) {
|
||||
|
||||
+9
-8
@@ -52,9 +52,9 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl
|
||||
|
||||
private Long insertIntoNotificationMapper(Long userId, Long generatedNotificationId) {
|
||||
AppUser appUser = this.appUserRepository.findById(userId).orElse(null);
|
||||
NotificationMapper notificationMapper = new NotificationMapper(
|
||||
this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId), appUser, false,
|
||||
DateUtils.getLocalDateTimeOfSystem());
|
||||
NotificationMapper notificationMapper = new NotificationMapper()
|
||||
.setNotification(this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId)).setUserId(appUser)
|
||||
.setRead(false).setCreatedAt(DateUtils.getLocalDateTimeOfSystem());
|
||||
|
||||
this.notificationMapperWritePlatformService.create(notificationMapper);
|
||||
return notificationMapper.getId();
|
||||
@@ -63,8 +63,9 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl
|
||||
private Long insertIntoNotificationGenerator(String objectType, Long objectIdentifier, String action, Long actorId,
|
||||
String notificationContent, boolean isSystemGenerated) {
|
||||
|
||||
Notification notification = new Notification(objectType, objectIdentifier, action, actorId, isSystemGenerated, notificationContent,
|
||||
DateUtils.getLocalDateTimeOfSystem());
|
||||
Notification notification = new Notification().setObjectType(objectType).setObjectIdentifier(objectIdentifier).setAction(action)
|
||||
.setActorId(actorId).setSystemGenerated(isSystemGenerated).setNotificationContent(notificationContent)
|
||||
.setCreatedAt(DateUtils.getLocalDateTimeOfSystem());
|
||||
|
||||
return this.notificationGeneratorWritePlatformService.create(notification);
|
||||
}
|
||||
@@ -84,9 +85,9 @@ public class NotificationWritePlatformServiceImpl implements NotificationWritePl
|
||||
List<Long> mappedIds = new ArrayList<>();
|
||||
for (Long userId : userIds) {
|
||||
AppUser appUser = this.appUserRepository.findById(userId).orElseThrow();
|
||||
NotificationMapper notificationMapper = new NotificationMapper(
|
||||
this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId), appUser, false,
|
||||
DateUtils.getLocalDateTimeOfSystem());
|
||||
NotificationMapper notificationMapper = new NotificationMapper()
|
||||
.setNotification(this.notificationGeneratorReadRepositoryWrapper.findById(generatedNotificationId)).setUserId(appUser)
|
||||
.setRead(false).setCreatedAt(DateUtils.getLocalDateTimeOfSystem());
|
||||
this.notificationMapperWritePlatformService.create(notificationMapper);
|
||||
mappedIds.add(notificationMapper.getId());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user