Skip to content

Commit 7a7e278

Browse files
authored
Merge pull request #68 from logoutdhaval/newSMSAPI
sms details api added
2 parents 0955895 + c434b8e commit 7a7e278

File tree

4 files changed

+273
-7
lines changed

4 files changed

+273
-7
lines changed

src/main/java/org/fineract/messagegateway/sms/api/SmsApiResource.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
*/
1919
package org.fineract.messagegateway.sms.api;
2020

21-
import java.util.ArrayList;
22-
import java.util.Collection;
23-
import java.util.List;
24-
25-
import com.google.gson.JsonObject;
2621
import org.fineract.messagegateway.constants.MessageGatewayConstants;
2722
import org.fineract.messagegateway.exception.MessageGatewayException;
2823
import org.fineract.messagegateway.sms.data.DeliveryStatusData;
@@ -31,7 +26,6 @@
3126
import org.fineract.messagegateway.sms.exception.ProviderNotDefinedException;
3227
import org.fineract.messagegateway.sms.exception.SMSBridgeNotFoundException;
3328
import org.fineract.messagegateway.sms.providers.SMSProvider;
34-
import org.fineract.messagegateway.sms.providers.impl.infobip.InfoBipApiResource;
3529
import org.fineract.messagegateway.sms.providers.impl.telerivet.TelerivetMessageProvider;
3630
import org.fineract.messagegateway.sms.repository.SMSBridgeRepository;
3731
import org.fineract.messagegateway.sms.repository.SmsOutboundMessageRepository;
@@ -42,12 +36,17 @@
4236
import org.springframework.context.ApplicationContext;
4337
import org.springframework.http.HttpStatus;
4438
import org.springframework.http.ResponseEntity;
39+
import org.springframework.web.bind.annotation.PathVariable;
4540
import org.springframework.web.bind.annotation.RequestBody;
4641
import org.springframework.web.bind.annotation.RequestHeader;
4742
import org.springframework.web.bind.annotation.RequestMapping;
4843
import org.springframework.web.bind.annotation.RequestMethod;
4944
import org.springframework.web.bind.annotation.RestController;
5045

46+
import java.util.ArrayList;
47+
import java.util.Collection;
48+
import java.util.List;
49+
5150
@RestController
5251
@RequestMapping("/sms")
5352
public class SmsApiResource {
@@ -66,6 +65,8 @@ public class SmsApiResource {
6665

6766
@Autowired
6867
private ApplicationContext applicationContext;
68+
@Autowired
69+
private SmsOutboundMessageRepository smsOutboundMessageRepository;
6970

7071
@Autowired
7172
public SmsApiResource(final SMSMessageService smsMessageService) {
@@ -122,4 +123,12 @@ public ResponseEntity<Collection<DeliveryStatusData>> getDeliveryStatus(@Request
122123
return new ResponseEntity<>(deliveryStatus, HttpStatus.OK);
123124

124125
}
126+
@RequestMapping(value = "/details/{internalId}", method = RequestMethod.GET, consumes = {"application/json"}, produces = {"application/json"})
127+
public ResponseEntity<SMSMessage> getMessageDetails(@RequestHeader(MessageGatewayConstants.TENANT_IDENTIFIER_HEADER) final String tenantId,
128+
@RequestHeader(MessageGatewayConstants.TENANT_APPKEY_HEADER) final String appKey,
129+
@PathVariable Long internalId) throws MessageGatewayException {
130+
131+
SMSMessage smsMessages = this.smsOutboundMessageRepository.findByInternalId(internalId);
132+
return new ResponseEntity<>(smsMessages, HttpStatus.OK);
133+
}
125134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.fineract.messagegateway.sms.domain;
20+
21+
import java.util.Date;
22+
23+
import javax.persistence.Column;
24+
import javax.persistence.Entity;
25+
import javax.persistence.Table;
26+
import javax.persistence.Temporal;
27+
import javax.persistence.TemporalType;
28+
29+
import org.fineract.messagegateway.sms.util.SmsMessageStatusType;
30+
31+
@Entity
32+
@Table(name = "m_outbound_messages")
33+
public class OutboundMessages extends AbstractPersistableCustom<Long> {
34+
35+
@com.fasterxml.jackson.annotation.JsonIgnore
36+
@Column(name = "tenant_id", nullable = false)
37+
private Long tenantId;
38+
39+
@Column(name = "external_id", nullable = true)
40+
private String externalId;
41+
42+
@Column(name = "internal_id", nullable = false)
43+
private Long internalId;
44+
45+
@Column(name = "submitted_on_date", nullable = true)
46+
@Temporal(TemporalType.DATE)
47+
private Date submittedOnDate;
48+
49+
@Column(name = "delivered_on_date", nullable = true)
50+
@Temporal(TemporalType.TIMESTAMP)
51+
private Date deliveredOnDate;
52+
53+
@Column(name = "delivery_status", nullable = false)
54+
private Integer deliveryStatus = SmsMessageStatusType.PENDING.getValue();
55+
56+
@Column(name = "delivery_error_message", nullable = true)
57+
private String deliveryErrorMessage;
58+
59+
@Column(name = "source_address", nullable = true)
60+
private String sourceAddress;
61+
62+
@Column(name = "mobile_number", nullable = false)
63+
private String mobileNumber;
64+
65+
@Column(name = "message", nullable = false)
66+
private String message;
67+
68+
@Column(name = "sms_bridge_id", nullable = false)
69+
private Long bridgeId;
70+
71+
@Column(name = "response")
72+
private String response;
73+
74+
protected OutboundMessages() {
75+
76+
}
77+
78+
public OutboundMessages(final String externalId, final Long internalId, final Long tenantId,
79+
final Date submittedOnDate, final Date deliveredOnDate,
80+
final SmsMessageStatusType deliveryStatus, final String deliveryErrorMessage, final String sourceAddress,
81+
final String mobileNumber, final String message, final Long bridgeId) {
82+
this.externalId = externalId;
83+
this.internalId = internalId;
84+
this.tenantId = tenantId;
85+
this.submittedOnDate = submittedOnDate;
86+
this.deliveredOnDate = deliveredOnDate;
87+
this.deliveryStatus = deliveryStatus.getValue();
88+
this.deliveryErrorMessage = deliveryErrorMessage;
89+
this.sourceAddress = sourceAddress;
90+
this.mobileNumber = mobileNumber;
91+
this.message = message;
92+
this.bridgeId = bridgeId;
93+
}
94+
95+
public static OutboundMessages getPendingMessages(final String externalId, final Long internalId,
96+
final Long tenantId, final Date submittedOnDate,
97+
final Date deliveredOnDate, final String deliveryErrorMessage, final String sourceAddress,
98+
final String mobileNumber, final String message, final Long providerId) {
99+
100+
return new OutboundMessages(externalId, internalId, tenantId, submittedOnDate,
101+
deliveredOnDate, SmsMessageStatusType.PENDING, deliveryErrorMessage, sourceAddress, mobileNumber,
102+
message, providerId);
103+
}
104+
105+
/**
106+
* @return an instance of the SmsOutboundMessage class
107+
**/
108+
public OutboundMessages getInstance(final String externalId, final Long internalId, final Long tenantId,
109+
final Date submittedOnDate, final Date deliveredOnDate,
110+
final SmsMessageStatusType deliveryStatus, final String deliveryErrorMessage, final String sourceAddress,
111+
final String mobileNumber, final String message, final Long providerId) {
112+
113+
return new OutboundMessages(externalId, internalId, tenantId, submittedOnDate,
114+
deliveredOnDate, deliveryStatus, deliveryErrorMessage, sourceAddress, mobileNumber, message,
115+
providerId);
116+
}
117+
118+
public Long getInternalId() {
119+
return internalId;
120+
}
121+
122+
public void setExternalId(final String externalId) {
123+
this.externalId = externalId ;
124+
}
125+
126+
public String getExternalId() {
127+
return this.externalId ;
128+
}
129+
130+
public void setInternalId(Long internalId) {
131+
this.internalId = internalId;
132+
}
133+
134+
public Long getTenantId() {
135+
return tenantId;
136+
}
137+
138+
public void setTenant(Long tenantId) {
139+
this.tenantId = tenantId;
140+
}
141+
142+
public String getSourceAddress() {
143+
return sourceAddress;
144+
}
145+
146+
public void setSourceAddress(String sourceAddress) {
147+
this.sourceAddress = sourceAddress;
148+
}
149+
150+
public String getMobileNumber() {
151+
return mobileNumber;
152+
}
153+
154+
public void setMobileNumber(String mobileNumber) {
155+
this.mobileNumber = mobileNumber;
156+
}
157+
158+
public String getMessage() {
159+
return message;
160+
}
161+
162+
public void setMessage(String message) {
163+
this.message = message;
164+
}
165+
166+
public Long getBridgeId() {
167+
return bridgeId;
168+
}
169+
170+
public void setProviderId(Long providerId) {
171+
this.bridgeId = providerId;
172+
}
173+
174+
public void setSubmittedOnDate(final Date submittedDate) {
175+
this.submittedOnDate = submittedDate ;
176+
}
177+
178+
public void setDeliveryErrorMessage(final String deliveryErrorMessage) {
179+
this.deliveryErrorMessage = deliveryErrorMessage ;
180+
}
181+
public String getDeliveryErrorMessage(){
182+
return this.deliveryErrorMessage;
183+
}
184+
185+
public void setDeliveryStatus(final Integer status) {
186+
this.deliveryStatus = status ;
187+
}
188+
189+
public void setDeliveredOnDate(final Date deliveredOnDate) {
190+
this.deliveredOnDate = deliveredOnDate ;
191+
}
192+
193+
public Integer getDeliveryStatus() {
194+
return this.deliveryStatus ;
195+
}
196+
197+
public String getResponse() {
198+
return response;
199+
}
200+
201+
public void setResponse(String response) {
202+
this.response = response;
203+
}
204+
205+
@Override
206+
public String toString() {
207+
return "SmsOutboundMessage [externalId=" + externalId + ", internalId=" + internalId
208+
+ ",TenantIdentifier=" + tenantId + ", submittedOnDate=" + submittedOnDate + ", deliveredOnDate="
209+
+ deliveredOnDate + ", deliveryStatus=" + deliveryStatus + ", deliveryErrorMessage="
210+
+ deliveryErrorMessage + ", sourceAddress=" + sourceAddress + ", mobileNumber=" + mobileNumber
211+
+ ", message=" + message + "]";
212+
}
213+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.fineract.messagegateway.sms.providers;
20+
21+
import java.util.Base64;
22+
23+
import org.fineract.messagegateway.constants.MessageGatewayConstants;
24+
import org.fineract.messagegateway.exception.MessageGatewayException;
25+
import org.fineract.messagegateway.sms.domain.OutboundMessages;
26+
import org.fineract.messagegateway.sms.domain.SMSBridge;
27+
28+
public abstract class Provider {
29+
30+
public abstract void sendMessage(final SMSBridge smsBridgeConfig, final OutboundMessages message)
31+
throws MessageGatewayException ;
32+
33+
protected String encodeBase64(final SMSBridge smsBridgeConfig) {
34+
String tenant = smsBridgeConfig.getTenantId().toString() ;
35+
String username = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_ACCOUNT_ID) ;
36+
String password = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_AUTH_TOKEN) ;
37+
String userPass = username + ":" + password + ":" + tenant;
38+
return Base64.getEncoder().encodeToString(userPass.getBytes());
39+
}
40+
public abstract void updateStatusByMessageId(SMSBridge bridge, String externalId,String orchestrator) throws MessageGatewayException ;
41+
public abstract void publishZeebeVariable(OutboundMessages message);
42+
}

src/main/java/org/fineract/messagegateway/sms/repository/SmsOutboundMessageRepository.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface SmsOutboundMessageRepository extends JpaRepository<SMSMessage,
4747
* @return {@link SmsMessageStatusType}
4848
**/
4949
SMSMessage findByExternalId(String externalId);
50-
50+
5151
/**
5252
* find {@link SmsMessageStatusType} objects with id in "idList" and mifosTenantIdentifier equal to "mifosTenantIdentifier"
5353
*
@@ -56,4 +56,6 @@ public interface SmsOutboundMessageRepository extends JpaRepository<SMSMessage,
5656
* @return List of {@link SmsMessageStatusType} objects
5757
**/
5858
List<SMSMessage> findByIdInAndTenantId(List<Long> idList, String mifosTenantIdentifier);
59+
60+
SMSMessage findByInternalId(Long internalId);
5961
}

0 commit comments

Comments
 (0)