Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9B8DF200D24 for ; Tue, 24 Oct 2017 14:50:29 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9A2B7160BE0; Tue, 24 Oct 2017 12:50:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DF0F1160BDB for ; Tue, 24 Oct 2017 14:50:28 +0200 (CEST) Received: (qmail 93258 invoked by uid 500); 24 Oct 2017 12:50:28 -0000 Mailing-List: contact commits-help@fineract.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.apache.org Delivered-To: mailing list commits@fineract.apache.org Received: (qmail 93249 invoked by uid 99); 24 Oct 2017 12:50:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Oct 2017 12:50:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0030ADFA3C; Tue, 24 Oct 2017 12:50:27 +0000 (UTC) From: nazeer1100126 To: commits@fineract.apache.org Reply-To: commits@fineract.apache.org References: In-Reply-To: Subject: [GitHub] fineract pull request #410: sms notification Content-Type: text/plain Message-Id: <20171024125028.0030ADFA3C@git1-us-west.apache.org> Date: Tue, 24 Oct 2017 12:50:27 +0000 (UTC) archived-at: Tue, 24 Oct 2017 12:50:29 -0000 Github user nazeer1100126 commented on a diff in the pull request: https://github.com/apache/fineract/pull/410#discussion_r146548210 --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/NotificationSenderService.java --- @@ -0,0 +1,128 @@ +/** + * 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.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.infrastructure.gcm.GcmConstants; +import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistration; +import org.apache.fineract.infrastructure.gcm.domain.DeviceRegistrationRepositoryWrapper; +import org.apache.fineract.infrastructure.gcm.domain.Message; +import org.apache.fineract.infrastructure.gcm.domain.Message.Builder; +import org.apache.fineract.infrastructure.gcm.domain.Message.Priority; +import org.apache.fineract.infrastructure.gcm.domain.Notification; +import org.apache.fineract.infrastructure.gcm.domain.Result; +import org.apache.fineract.infrastructure.gcm.domain.Sender; +import org.apache.fineract.infrastructure.sms.domain.SmsMessage; +import org.apache.fineract.infrastructure.sms.domain.SmsMessageRepository; +import org.apache.fineract.infrastructure.sms.domain.SmsMessageStatusType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class NotificationSenderService { + + private final DeviceRegistrationRepositoryWrapper deviceRegistrationRepositoryWrapper; + private final SmsMessageRepository smsMessageRepository; + + @Autowired + public NotificationSenderService( + final DeviceRegistrationRepositoryWrapper deviceRegistrationRepositoryWrapper, + final SmsMessageRepository smsMessageRepository) { + this.deviceRegistrationRepositoryWrapper = deviceRegistrationRepositoryWrapper; + this.smsMessageRepository = smsMessageRepository; + } + + public void sendNotification(List smsMessages) { + Map> notificationByEachClient = getNotificationListByClient(smsMessages); + for (Map.Entry> entry : notificationByEachClient + .entrySet()) { + this.sendNotifiaction(entry.getKey(), entry.getValue()); + } + } + + public Map> getNotificationListByClient( + List smsMessages) { + Map> notificationByEachClient = new HashMap<>(); + for (SmsMessage smsMessage : smsMessages) { + if (smsMessage.getClient() != null) { + Long clientId = smsMessage.getClient().getId(); + if (notificationByEachClient.containsKey(clientId)) { + notificationByEachClient.get(clientId).add(smsMessage); + } else { + List msgList = new ArrayList<>( + Arrays.asList(smsMessage)); + notificationByEachClient.put(clientId, msgList); + } + + } + } + return notificationByEachClient; + } + + public void sendNotifiaction(Long clientId, List smsList) { + + DeviceRegistration deviceRegistration = this.deviceRegistrationRepositoryWrapper + .findDeviceRegistrationByClientId(clientId); + String registrationId = null; + if (deviceRegistration != null) { + registrationId = deviceRegistration.getRegistrationId(); + } + for (SmsMessage smsMessage : smsList) { + try { + Notification notification = new Notification.Builder( + GcmConstants.defaultIcon).title(GcmConstants.title) + .body(smsMessage.getMessage()).build(); + Builder b = new Builder(); + b.notification(notification); + b.dryRun(false); + b.contentAvailable(true); + b.timeToLive(30); --- End diff -- No need of configurable parameter for this. ---