You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by nazeer1100126 <gi...@git.apache.org> on 2017/10/25 13:09:59 UTC
[GitHub] fineract pull request #419: sms notification
GitHub user nazeer1100126 opened a pull request:
https://github.com/apache/fineract/pull/419
sms notification
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nazeer1100126/incubator-fineract notification_sms
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/fineract/pull/419.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #419
----
commit 8b3bdb2bdddaa0ff3779e3a9a30bb7f7614ba8a3
Author: nazeer shaik <na...@confluxtechnologies.com>
Date: 2017-10-25T13:05:26Z
sms notification
----
---
[GitHub] fineract pull request #419: sms notification
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 closed the pull request at:
https://github.com/apache/fineract/pull/419
---
[GitHub] fineract pull request #419: sms notification
Posted by avikganguly01 <gi...@git.apache.org>.
Github user avikganguly01 commented on a diff in the pull request:
https://github.com/apache/fineract/pull/419#discussion_r147701237
--- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/GcmConstants.java ---
@@ -0,0 +1,309 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.gcm;
+
+/**
+ * Constants used on GCM service communication.
+ */
+public final class GcmConstants {
+
+
+ /**
+ * Title for notification
+ */
+ public static final String title = "Hello !";
+
+ /**
+ * icon for notification.
+ */
+ public static final String defaultIcon = "default";
+
+
+ /**
+ * Parameter for to field.
+ */
+ public static final String PARAM_TO = "to";
+
+ /**
+ * Prefix of the topic.
+ */
+ public static final String TOPIC_PREFIX = "/topics/";
+
+ /**
+ * HTTP parameter for registration id.
+ */
+ public static final String PARAM_REGISTRATION_ID = "registration_id";
+
+ /**
+ * HTTP parameter for collapse key.
+ */
+ public static final String PARAM_COLLAPSE_KEY = "collapse_key";
+
+ /**
+ * HTTP parameter for delaying the message delivery if the device is idle.
+ */
+ public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";
+
+ /**
+ * HTTP parameter for telling gcm to validate the message without actually
+ * sending it.
+ */
+ public static final String PARAM_DRY_RUN = "dry_run";
+
+ /**
+ * HTTP parameter for package name that can be used to restrict message
+ * delivery by matching against the package name used to generate the
+ * registration id.
+ */
+ public static final String PARAM_RESTRICTED_PACKAGE_NAME = "restricted_package_name";
+
+ /**
+ * Prefix to HTTP parameter used to pass key-values in the message payload.
+ */
+ public static final String PARAM_PAYLOAD_PREFIX = "data.";
+
+ /**
+ * Parameter used to set the message time-to-live.
+ */
+ public static final String PARAM_TIME_TO_LIVE = "time_to_live";
+
+ /**
+ * Parameter used to set the message priority.
+ */
+ public static final String PARAM_PRIORITY = "priority";
+
+ /**
+ * Parameter used to set the content available (iOS only)
+ */
+ public static final String PARAM_CONTENT_AVAILABLE = "content_available";
+
+ /**
+ * Value used to set message priority to normal.
+ */
+ public static final String MESSAGE_PRIORITY_NORMAL = "normal";
+
+ /**
+ * Value used to set message priority to high.
+ */
+ public static final String MESSAGE_PRIORITY_HIGH = "high";
+
+ /**
+ * Too many messages sent by the sender. Retry after a while.
+ */
+ public static final String ERROR_QUOTA_EXCEEDED = "QuotaExceeded";
+
+ /**
+ * Too many messages sent by the sender to a specific device. Retry after a
+ * while.
+ */
+ public static final String ERROR_DEVICE_QUOTA_EXCEEDED = "DeviceQuotaExceeded";
+
+ /**
+ * Missing registration_id. Sender should always add the registration_id to
+ * the request.
+ */
+ public static final String ERROR_MISSING_REGISTRATION = "MissingRegistration";
+
+ /**
+ * Bad registration_id. Sender should remove this registration_id.
+ */
+ public static final String ERROR_INVALID_REGISTRATION = "InvalidRegistration";
+
+ /**
+ * The sender_id contained in the registration_id does not match the
+ * sender_id used to register with the GCM servers.
+ */
+ public static final String ERROR_MISMATCH_SENDER_ID = "MismatchSenderId";
+
+ /**
+ * The user has uninstalled the application or turned off notifications.
+ * Sender should stop sending messages to this device and delete the
+ * registration_id. The client needs to re-register with the GCM servers to
+ * receive notifications again.
+ */
+ public static final String ERROR_NOT_REGISTERED = "NotRegistered";
+
+ /**
+ * The payload of the message is too big, see the limitations. Reduce the
+ * size of the message.
+ */
+ public static final String ERROR_MESSAGE_TOO_BIG = "MessageTooBig";
+
--- End diff --
Am I missing something? None of these constants are referenced anywhere in this PR code.
---
[GitHub] fineract pull request #419: sms notification
Posted by avikganguly01 <gi...@git.apache.org>.
Github user avikganguly01 commented on a diff in the pull request:
https://github.com/apache/fineract/pull/419#discussion_r147701657
--- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/GcmConstants.java ---
@@ -0,0 +1,309 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.gcm;
+
+/**
+ * Constants used on GCM service communication.
+ */
+public final class GcmConstants {
+
+
+ /**
+ * Title for notification
+ */
+ public static final String title = "Hello !";
+
+ /**
+ * icon for notification.
+ */
+ public static final String defaultIcon = "default";
+
+
+ /**
+ * Parameter for to field.
+ */
+ public static final String PARAM_TO = "to";
+
+ /**
+ * Prefix of the topic.
+ */
+ public static final String TOPIC_PREFIX = "/topics/";
+
+ /**
+ * HTTP parameter for registration id.
+ */
+ public static final String PARAM_REGISTRATION_ID = "registration_id";
+
+ /**
+ * HTTP parameter for collapse key.
+ */
+ public static final String PARAM_COLLAPSE_KEY = "collapse_key";
+
+ /**
+ * HTTP parameter for delaying the message delivery if the device is idle.
+ */
+ public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";
+
+ /**
+ * HTTP parameter for telling gcm to validate the message without actually
+ * sending it.
+ */
+ public static final String PARAM_DRY_RUN = "dry_run";
+
+ /**
+ * HTTP parameter for package name that can be used to restrict message
+ * delivery by matching against the package name used to generate the
+ * registration id.
+ */
+ public static final String PARAM_RESTRICTED_PACKAGE_NAME = "restricted_package_name";
+
+ /**
+ * Prefix to HTTP parameter used to pass key-values in the message payload.
+ */
+ public static final String PARAM_PAYLOAD_PREFIX = "data.";
+
+ /**
+ * Parameter used to set the message time-to-live.
+ */
+ public static final String PARAM_TIME_TO_LIVE = "time_to_live";
+
+ /**
+ * Parameter used to set the message priority.
+ */
+ public static final String PARAM_PRIORITY = "priority";
+
+ /**
+ * Parameter used to set the content available (iOS only)
+ */
+ public static final String PARAM_CONTENT_AVAILABLE = "content_available";
+
+ /**
+ * Value used to set message priority to normal.
+ */
+ public static final String MESSAGE_PRIORITY_NORMAL = "normal";
+
+ /**
+ * Value used to set message priority to high.
+ */
+ public static final String MESSAGE_PRIORITY_HIGH = "high";
+
+ /**
+ * Too many messages sent by the sender. Retry after a while.
+ */
+ public static final String ERROR_QUOTA_EXCEEDED = "QuotaExceeded";
+
+ /**
+ * Too many messages sent by the sender to a specific device. Retry after a
+ * while.
+ */
+ public static final String ERROR_DEVICE_QUOTA_EXCEEDED = "DeviceQuotaExceeded";
+
+ /**
+ * Missing registration_id. Sender should always add the registration_id to
+ * the request.
+ */
+ public static final String ERROR_MISSING_REGISTRATION = "MissingRegistration";
+
+ /**
+ * Bad registration_id. Sender should remove this registration_id.
+ */
+ public static final String ERROR_INVALID_REGISTRATION = "InvalidRegistration";
+
+ /**
+ * The sender_id contained in the registration_id does not match the
+ * sender_id used to register with the GCM servers.
+ */
+ public static final String ERROR_MISMATCH_SENDER_ID = "MismatchSenderId";
+
+ /**
+ * The user has uninstalled the application or turned off notifications.
+ * Sender should stop sending messages to this device and delete the
+ * registration_id. The client needs to re-register with the GCM servers to
+ * receive notifications again.
+ */
+ public static final String ERROR_NOT_REGISTERED = "NotRegistered";
+
+ /**
+ * The payload of the message is too big, see the limitations. Reduce the
+ * size of the message.
+ */
+ public static final String ERROR_MESSAGE_TOO_BIG = "MessageTooBig";
+
+ /**
+ * Collapse key is required. Include collapse key in the request.
+ */
+ public static final String ERROR_MISSING_COLLAPSE_KEY = "MissingCollapseKey";
+
+ /**
+ * A particular message could not be sent because the GCM servers were not
+ * available. Used only on JSON requests, as in plain text requests
+ * unavailability is indicated by a 503 response.
+ */
+ public static final String ERROR_UNAVAILABLE = "Unavailable";
+
+ /**
+ * A particular message could not be sent because the GCM servers
+ * encountered an error. Used only on JSON requests, as in plain text
+ * requests internal errors are indicated by a 500 response.
+ */
+ public static final String ERROR_INTERNAL_SERVER_ERROR = "InternalServerError";
+
--- End diff --
It is a good idea to tie retry logic to such error codes.
---
[GitHub] fineract pull request #419: sms notification
Posted by avikganguly01 <gi...@git.apache.org>.
Github user avikganguly01 commented on a diff in the pull request:
https://github.com/apache/fineract/pull/419#discussion_r147696993
--- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/api/DeviceRegistrationApiResource.java ---
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.gcm.api;
+
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
+import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistration;
+import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistrationData;
+import org.apache.fineract.infrastructure.gcm.service.DeviceRegistrationReadPlatformService;
+import org.apache.fineract.infrastructure.gcm.service.DeviceRegistrationWritePlatformService;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+@Path("/device/registration")
+@Component
+@Scope("singleton")
+public class DeviceRegistrationApiResource {
+
+ private final PlatformSecurityContext context;
+ private final DeviceRegistrationWritePlatformService deviceRegistrationWritePlatformService;
+ private final DefaultToApiJsonSerializer<DeviceRegistrationData> toApiJsonSerializer;
+ private final DeviceRegistrationReadPlatformService deviceRegistrationReadPlatformService;
+
+ @Autowired
+ public DeviceRegistrationApiResource(
+ PlatformSecurityContext context,
+ final DefaultToApiJsonSerializer<DeviceRegistrationData> toApiJsonSerializer,
+ final DeviceRegistrationReadPlatformService deviceRegistrationReadPlatformService,
+ final DeviceRegistrationWritePlatformService deviceRegistrationWritePlatformService) {
+ this.context = context;
+ this.toApiJsonSerializer = toApiJsonSerializer;
+ this.deviceRegistrationReadPlatformService = deviceRegistrationReadPlatformService;
+ this.deviceRegistrationWritePlatformService = deviceRegistrationWritePlatformService;
+ }
+
+ @POST
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String registerDevice(final String apiRequestBodyAsJson) {
+ this.context.authenticatedUser();
+ Gson gson = new Gson();
+ JsonObject json = new Gson().fromJson(apiRequestBodyAsJson,
+ JsonObject.class);
+ Long clientId = json.get(
+ DeviceRegistrationApiConstants.clientIdParamName).getAsLong();
+ String registrationId = json.get(
+ DeviceRegistrationApiConstants.registrationIdParamName)
+ .getAsString();
+ DeviceRegistration deviceRegistration = this.deviceRegistrationWritePlatformService
+ .registerDevice(clientId, registrationId);
+ String response = gson.toJson(deviceRegistration);
+ return response;
+ }
+
+ @GET
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String retrieveAllDeviceRegistrations(@Context final UriInfo uriInfo) {
+
+ this.context.authenticatedUser();
+
+ Collection<DeviceRegistrationData> deviceRegistrationDataList = this.deviceRegistrationReadPlatformService
+ .retrieveAllDeviceRegiistrations();
+
+ return this.toApiJsonSerializer.serialize(deviceRegistrationDataList);
+ }
+
+ @GET
+ @Path("client/{clientId}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String retrieveDeviceRegistrationByClientId(
+ @PathParam("clientId") final Long clientId,
+ @Context final UriInfo uriInfo) {
+
+ this.context.authenticatedUser();
+
+ DeviceRegistrationData deviceRegistrationData = this.deviceRegistrationReadPlatformService
+ .retrieveDeviceRegiistrationByClientId(clientId);
+
+ return this.toApiJsonSerializer.serialize(deviceRegistrationData);
+ }
+
+ @GET
+ @Path("{id}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String retrieveDeviceRegiistration(@PathParam("id") final Long id,
+ @Context final UriInfo uriInfo) {
+
+ this.context.authenticatedUser();
+
+ DeviceRegistrationData deviceRegistrationData = this.deviceRegistrationReadPlatformService
+ .retrieveDeviceRegiistration(id);
+
+ return this.toApiJsonSerializer.serialize(deviceRegistrationData);
+ }
+
+ @PUT
+ @Path("{id}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String updateDeviceRegistration(@PathParam("id") final Long id,
+ final String apiRequestBodyAsJson) {
--- End diff --
Is there no requirement to unsubscribe / de-register device?
---
[GitHub] fineract pull request #419: sms notification
Posted by avikganguly01 <gi...@git.apache.org>.
Github user avikganguly01 commented on a diff in the pull request:
https://github.com/apache/fineract/pull/419#discussion_r147694537
--- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/data/SmsCampaignData.java ---
@@ -44,6 +44,8 @@
private final DateTime recurrenceStartDate;
private final String recurrence;
private final Long providerId;
+ private final boolean isNotification;
+
--- End diff --
I would have preferred abstraction of CampaignData to SmsCampaignData and NotificationCampaignData in case it diverges further but it's ok for now.
---
[GitHub] fineract issue #419: sms notification
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on the issue:
https://github.com/apache/fineract/pull/419
@avikganguly01 can you please review this PR
---
[GitHub] fineract pull request #419: sms notification
Posted by avikganguly01 <gi...@git.apache.org>.
Github user avikganguly01 commented on a diff in the pull request:
https://github.com/apache/fineract/pull/419#discussion_r147700405
--- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/scheduler/SmsMessageScheduledJobServiceImpl.java ---
@@ -118,18 +122,26 @@ public void sendMessagesToGateway() {
Collection<SmsMessageApiQueueResourceData> apiQueueResourceDatas = new ArrayList<>();
while (pendingMessageIterator.hasNext()) {
SmsMessage smsData = pendingMessageIterator.next();
-
- SmsMessageApiQueueResourceData apiQueueResourceData = SmsMessageApiQueueResourceData.instance(smsData.getId(),
- tenantIdentifier, null, null, smsData.getMobileNo(), smsData.getMessage(), smsData.getSmsCampaign()
- .getProviderId());
- apiQueueResourceDatas.add(apiQueueResourceData);
- smsData.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
- toSaveMessages.add(smsData) ;
+ if(smsData.isNotification()){
+ smsData.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
--- End diff --
What is the status lifecycle of SmsMessage? Is it the same for notifications as well? Is it the same for GCM and FCM?
---