refactor: add lombok to gcm module
This commit is contained in:
committed by
Arnold Gálovics
parent
ae71df17df
commit
5d1d20e577
+1
-1
@@ -212,7 +212,7 @@ public class ExternalServicesPropertiesReadPlatformServiceImpl implements Extern
|
||||
fcmEndPoint = rs.getString("value");
|
||||
}
|
||||
}
|
||||
return new NotificationConfigurationData(null, serverKey, gcmEndPoint, fcmEndPoint);
|
||||
return new NotificationConfigurationData().setServerKey(serverKey).setGcmEndPoint(gcmEndPoint).setFcmEndPoint(fcmEndPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-34
@@ -24,13 +24,21 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
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.service.DateUtils;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
|
||||
@Entity
|
||||
@Table(name = "client_device_registration")
|
||||
public final class DeviceRegistration extends AbstractPersistableCustom {
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class DeviceRegistration extends AbstractPersistableCustom {
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "client_id", nullable = false, unique = true)
|
||||
@@ -42,40 +50,9 @@ public final class DeviceRegistration extends AbstractPersistableCustom {
|
||||
@Column(name = "updatedon_date", nullable = false)
|
||||
private LocalDateTime updatedOnDate;
|
||||
|
||||
private DeviceRegistration() {}
|
||||
|
||||
private DeviceRegistration(final Client client, final String registrationId) {
|
||||
this.client = client;
|
||||
this.registrationId = registrationId;
|
||||
this.updatedOnDate = DateUtils.getLocalDateTimeOfTenant();
|
||||
}
|
||||
|
||||
public static DeviceRegistration instance(final Client client, final String registrationId) {
|
||||
return new DeviceRegistration(client, registrationId);
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public String getRegistrationId() {
|
||||
return this.registrationId;
|
||||
}
|
||||
|
||||
public void setRegistrationId(String registrationId) {
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedOnDate() {
|
||||
return this.updatedOnDate;
|
||||
}
|
||||
|
||||
public void setUpdatedOnDate(LocalDateTime updatedOnDate) {
|
||||
this.updatedOnDate = updatedOnDate;
|
||||
return new DeviceRegistration().setRegistrationId(registrationId).setClient(client)
|
||||
.setUpdatedOnDate(DateUtils.getLocalDateTimeOfTenant());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-10
@@ -19,26 +19,27 @@
|
||||
package org.apache.fineract.infrastructure.gcm.domain;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.fineract.portfolio.client.data.ClientData;
|
||||
|
||||
public final class DeviceRegistrationData {
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class DeviceRegistrationData {
|
||||
|
||||
public Long id;
|
||||
public ClientData clientData;
|
||||
public String registrationId;
|
||||
public OffsetDateTime updatedOnDate;
|
||||
|
||||
private DeviceRegistrationData(final Long id, final ClientData clientData, final String registrationId,
|
||||
final OffsetDateTime updatedOnDate) {
|
||||
this.id = id;
|
||||
this.clientData = clientData;
|
||||
this.registrationId = registrationId;
|
||||
this.updatedOnDate = updatedOnDate;
|
||||
}
|
||||
|
||||
public static DeviceRegistrationData instance(final Long id, final ClientData clientData, final String registrationId,
|
||||
final OffsetDateTime updatedOnDate) {
|
||||
return new DeviceRegistrationData(id, clientData, registrationId, updatedOnDate);
|
||||
return new DeviceRegistrationData().setId(id).setClientData(clientData).setRegistrationId(registrationId)
|
||||
.setUpdatedOnDate(updatedOnDate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+18
-72
@@ -22,6 +22,9 @@ import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.fineract.infrastructure.gcm.GcmConstants;
|
||||
|
||||
/**
|
||||
@@ -72,17 +75,23 @@ import org.apache.fineract.infrastructure.gcm.GcmConstants;
|
||||
*
|
||||
* </code>
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public final class Message implements Serializable {
|
||||
|
||||
private final String collapseKey;
|
||||
private final Boolean delayWhileIdle;
|
||||
private final Integer timeToLive;
|
||||
private final Map<String, String> data;
|
||||
private final Boolean dryRun;
|
||||
private final String restrictedPackageName;
|
||||
private final String priority;
|
||||
private final Boolean contentAvailable;
|
||||
private final Notification notification;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String collapseKey;
|
||||
private Boolean delayWhileIdle;
|
||||
private Integer timeToLive;
|
||||
private Map<String, String> data;
|
||||
private Boolean dryRun;
|
||||
private String restrictedPackageName;
|
||||
private String priority;
|
||||
private Boolean contentAvailable;
|
||||
private Notification notification;
|
||||
|
||||
public enum Priority {
|
||||
NORMAL, HIGH
|
||||
@@ -203,69 +212,6 @@ public final class Message implements Serializable {
|
||||
notification = builder.notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the collapse key.
|
||||
*/
|
||||
public String getCollapseKey() {
|
||||
return collapseKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delayWhileIdle flag.
|
||||
*/
|
||||
public Boolean isDelayWhileIdle() {
|
||||
return delayWhileIdle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time to live (in seconds).
|
||||
*/
|
||||
public Integer getTimeToLive() {
|
||||
return timeToLive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dryRun flag.
|
||||
*/
|
||||
public Boolean isDryRun() {
|
||||
return dryRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the restricted package name.
|
||||
*/
|
||||
public String getRestrictedPackageName() {
|
||||
return restrictedPackageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message priority value.
|
||||
*/
|
||||
public String getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contentAvailable value
|
||||
*/
|
||||
public Boolean getContentAvailable() {
|
||||
return contentAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the payload data, which is immutable.
|
||||
*/
|
||||
public Map<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets notification payload, which is immutable.
|
||||
*/
|
||||
public Notification getNotification() {
|
||||
return notification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("Message(");
|
||||
|
||||
+15
-67
@@ -22,18 +22,27 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Result of a GCM multicast message request .
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public final class MulticastResult implements Serializable {
|
||||
|
||||
private final int success;
|
||||
private final int failure;
|
||||
private final int canonicalIds;
|
||||
private final long multicastId;
|
||||
private final List<Result> results;
|
||||
private final List<Long> retryMulticastIds;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int success;
|
||||
private int failure;
|
||||
private int canonicalIds;
|
||||
private long multicastId;
|
||||
private List<Result> results;
|
||||
private List<Long> retryMulticastIds;
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
@@ -82,65 +91,4 @@ public final class MulticastResult implements Serializable {
|
||||
}
|
||||
retryMulticastIds = Collections.unmodifiableList(tmpList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the multicast id.
|
||||
*/
|
||||
public long getMulticastId() {
|
||||
return multicastId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of successful messages.
|
||||
*/
|
||||
public int getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of messages sent, regardless of the status.
|
||||
*/
|
||||
public int getTotal() {
|
||||
return success + failure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of failed messages.
|
||||
*/
|
||||
public int getFailure() {
|
||||
return failure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of successful messages that also returned a canonical registration id.
|
||||
*/
|
||||
public int getCanonicalIds() {
|
||||
return canonicalIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the results of each individual message, which is immutable.
|
||||
*/
|
||||
public List<Result> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets additional ids if more than one multicast message was sent.
|
||||
*/
|
||||
public List<Long> getRetryMulticastIds() {
|
||||
return retryMulticastIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("MulticastResult(").append("multicast_id=").append(multicastId).append(",")
|
||||
.append("total=").append(getTotal()).append(",").append("success=").append(success).append(",").append("failure=")
|
||||
.append(failure).append(",").append("canonical_ids=").append(canonicalIds).append(",");
|
||||
if (!results.isEmpty()) {
|
||||
builder.append("results: " + results);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+19
-96
@@ -21,6 +21,9 @@ package org.apache.fineract.infrastructure.gcm.domain;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* GCM message notification part.
|
||||
@@ -49,20 +52,24 @@ import java.util.List;
|
||||
*
|
||||
* </code>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public final class Notification implements Serializable {
|
||||
|
||||
private final String title;
|
||||
private final String body;
|
||||
private final String icon;
|
||||
private final String sound;
|
||||
private final Integer badge;
|
||||
private final String tag;
|
||||
private final String color;
|
||||
private final String clickAction;
|
||||
private final String bodyLocKey;
|
||||
private final List<String> bodyLocArgs;
|
||||
private final String titleLocKey;
|
||||
private final List<String> titleLocArgs;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String title;
|
||||
private String body;
|
||||
private String icon;
|
||||
private String sound;
|
||||
private Integer badge;
|
||||
private String tag;
|
||||
private String color;
|
||||
private String clickAction;
|
||||
private String bodyLocKey;
|
||||
private List<String> bodyLocArgs;
|
||||
private String titleLocKey;
|
||||
private List<String> titleLocArgs;
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
@@ -196,90 +203,6 @@ public final class Notification implements Serializable {
|
||||
titleLocArgs = builder.titleLocArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title.
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the body.
|
||||
*/
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon.
|
||||
*/
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sound.
|
||||
*/
|
||||
public String getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the badge.
|
||||
*/
|
||||
public Integer getBadge() {
|
||||
return badge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag.
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
*/
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the click action.
|
||||
*/
|
||||
public String getClickAction() {
|
||||
return clickAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the body localization key.
|
||||
*/
|
||||
public String getBodyLocKey() {
|
||||
return bodyLocKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the body localization values list, which is immutable.
|
||||
*/
|
||||
public List<String> getBodyLocArgs() {
|
||||
return bodyLocArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title localization key.
|
||||
*/
|
||||
public String getTitleLocKey() {
|
||||
return titleLocKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title localization values list, which is immutable.
|
||||
*/
|
||||
public List<String> getTitleLocArgs() {
|
||||
return titleLocArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("Notification(");
|
||||
|
||||
+11
-27
@@ -18,34 +18,18 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.gcm.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class NotificationConfigurationData {
|
||||
|
||||
private final Long id;
|
||||
private final String serverKey;
|
||||
private final String gcmEndPoint;
|
||||
private final String fcmEndPoint;
|
||||
|
||||
public NotificationConfigurationData(Long id, String serverKey, final String gcmEndPoint, final String fcmEndPoint) {
|
||||
this.id = id;
|
||||
this.serverKey = serverKey;
|
||||
this.gcmEndPoint = gcmEndPoint;
|
||||
this.fcmEndPoint = fcmEndPoint;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getServerKey() {
|
||||
return serverKey;
|
||||
}
|
||||
|
||||
public String getGcmEndPoint() {
|
||||
return gcmEndPoint;
|
||||
}
|
||||
|
||||
public String getFcmEndPoint() {
|
||||
return fcmEndPoint;
|
||||
}
|
||||
private Long id;
|
||||
private String serverKey;
|
||||
private String gcmEndPoint;
|
||||
private String fcmEndPoint;
|
||||
|
||||
}
|
||||
|
||||
+18
-47
@@ -20,14 +20,17 @@ package org.apache.fineract.infrastructure.gcm.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Result of a GCM message request that returned HTTP status code 200.
|
||||
*
|
||||
* <p>
|
||||
* If the message is successfully created, the {@link #getMessageId()} returns the message id and
|
||||
* {@link #getErrorCodeName()} returns {@literal null}; otherwise, {@link #getMessageId()} returns {@literal null} and
|
||||
* {@link #getErrorCodeName()} returns the code of the error.
|
||||
* {@link #getErrorCode()} returns {@literal null}; otherwise, {@link #getMessageId()} returns {@literal null} and
|
||||
* {@link #getErrorCode()} returns the code of the error.
|
||||
*
|
||||
* <p>
|
||||
* There are cases when a request is accept and the message successfully created, but GCM has a canonical registration
|
||||
@@ -39,22 +42,27 @@ import java.util.List;
|
||||
*
|
||||
* <pre>
|
||||
* - Call {@link #getMessageId()}:
|
||||
* - {@literal null} means error, call {@link #getErrorCodeName()}
|
||||
* - {@literal null} means error, call {@link #getErrorCode()}
|
||||
* - non-{@literal null} means the message was created:
|
||||
* - Call {@link #getCanonicalRegistrationId()}
|
||||
* - if it returns {@literal null}, do nothing.
|
||||
* - otherwise, update the server datastore with the new id.
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public final class Result implements Serializable {
|
||||
|
||||
private final String messageId;
|
||||
private final String canonicalRegistrationId;
|
||||
private final String errorCode;
|
||||
private final Integer success;
|
||||
private final Integer failure;
|
||||
private final List<String> failedRegistrationIds;
|
||||
private final int status;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String messageId;
|
||||
private String canonicalRegistrationId;
|
||||
private String errorCode;
|
||||
private Integer success;
|
||||
private Integer failure;
|
||||
private List<String> failedRegistrationIds;
|
||||
private int status;
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
@@ -117,39 +125,6 @@ public final class Result implements Serializable {
|
||||
status = builder.status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message id, if any.
|
||||
*/
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the canonical registration id, if any.
|
||||
*/
|
||||
public String getCanonicalRegistrationId() {
|
||||
return canonicalRegistrationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the error code, if any.
|
||||
*/
|
||||
public String getErrorCodeName() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public Integer getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public Integer getFailure() {
|
||||
return failure;
|
||||
}
|
||||
|
||||
public List<String> getFailedRegistrationIds() {
|
||||
return failedRegistrationIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("[");
|
||||
@@ -174,8 +149,4 @@ public final class Result implements Serializable {
|
||||
return builder.append(" ]").toString();
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -416,7 +416,7 @@ public class Sender {
|
||||
String regId = unsentRegIds.get(i);
|
||||
Result result = results.get(i);
|
||||
allResults.put(regId, result);
|
||||
String error = result.getErrorCodeName();
|
||||
String error = result.getErrorCode();
|
||||
if (error != null && (error.equals(GcmConstants.ERROR_UNAVAILABLE) || error.equals(GcmConstants.ERROR_INTERNAL_SERVER_ERROR))) {
|
||||
newUnsentRegIds.add(regId);
|
||||
}
|
||||
@@ -537,8 +537,8 @@ public class Sender {
|
||||
setJsonField(mapRequest, PARAM_TIME_TO_LIVE, message.getTimeToLive());
|
||||
setJsonField(mapRequest, PARAM_COLLAPSE_KEY, message.getCollapseKey());
|
||||
setJsonField(mapRequest, PARAM_RESTRICTED_PACKAGE_NAME, message.getRestrictedPackageName());
|
||||
setJsonField(mapRequest, PARAM_DELAY_WHILE_IDLE, message.isDelayWhileIdle());
|
||||
setJsonField(mapRequest, PARAM_DRY_RUN, message.isDryRun());
|
||||
setJsonField(mapRequest, PARAM_DELAY_WHILE_IDLE, message.getDelayWhileIdle());
|
||||
setJsonField(mapRequest, PARAM_DRY_RUN, message.getDryRun());
|
||||
Map<String, String> payload = message.getData();
|
||||
if (!payload.isEmpty()) {
|
||||
mapRequest.put(JSON_PAYLOAD, payload);
|
||||
|
||||
Reference in New Issue
Block a user