Skip to content

Commit

Permalink
fix-messageGateway-config
Browse files Browse the repository at this point in the history
  • Loading branch information
fynmanoj committed Oct 29, 2024
1 parent 5d96e8c commit c62b507
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 22 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ buildscript {
npmRepository = 'https://npm.pkg.github.com'
}
repositories {
maven {
url 'https://archiva-repository.apache.org/archiva/repository/public/'
}
maven { url 'https://plugins.gradle.org/m2/' }
}

Expand Down Expand Up @@ -752,7 +755,6 @@ configure(project.fineractPublishProjects) {
repositories {
def releaseUrl = 'https://repository.apache.org/content/repositories/releases'
def stagingUrl = 'https://repository.apache.org/content/repositories/snapshots'

maven {
name 'apache'
url hasProperty('fineract.release.version') ? releaseUrl : stagingUrl
Expand Down
2 changes: 1 addition & 1 deletion config/docker/compose/fineract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ version: "3.8"
services:
fineract:
# user: "${FINERACT_USER}:${FINERACT_GROUP}"
image: fineract:latest
image: docker.io/openmf/fineract:1.9.0
volumes:
- ${PWD}/config/docker/logback/logback-override.xml:/app/logback-override.xml
- ${PWD}/config/docker/aws/etc/credentials:/etc/aws/credentials:ro
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ services:
- ./config/docker/env/fineract.env
- ./config/docker/env/fineract-common.env
- ./config/docker/env/fineract-mariadb.env
community-app:
image: openmf/community-app:latest
container_name: mifos-ui
restart: always
ports:
- 9090:80
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void storeCommandIdInContext(CommandSource savedCommandSource) {
}

private void publishHookErrorEvent(CommandWrapper wrapper, JsonCommand command, ErrorInfo errorInfo) {
publishHookEvent(wrapper.entityName(), wrapper.actionName(), command, gson.toJson(errorInfo));
publishHookEvent(wrapper.entityName(), wrapper.actionName(), command, errorInfo);
}

private void exceptionWhenTheRequestAlreadyProcessed(CommandWrapper wrapper, String idempotencyKey, boolean retry) {
Expand Down Expand Up @@ -314,6 +314,8 @@ private void publishHookEvent(final String entityName, final String actionName,

reqmap.put("officeId", resultCopy.getOfficeId());
reqmap.put("clientId", resultCopy.getClientId());
reqmap.put("savingsId", resultCopy.getSavingsId());
reqmap.put("loanId", resultCopy.getLoanId());
resultCopy.setOfficeId(null);
reqmap.put("response", resultCopy);
} else if (result instanceof ErrorInfo ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
@ConfigurationProperties(prefix = "fineract")
public class FineractProperties {

private String baseUrl;

private String nodeId;

private String idempotencyKeyHeaderName;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
smsData.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
toSendNotificationMessages.add(smsData);
} else {
String emailAddress = (smsData.getClient() != null) ? smsData.getClient().emailAddress() : null;
SmsMessageApiQueueResourceData apiQueueResourceData = SmsMessageApiQueueResourceData.instance(smsData.getId(),
tenantIdentifier, null, null, smsData.getMobileNo(), smsData.getMessage(),
smsData.getSmsCampaign().getProviderId());
smsData.getSmsCampaign().getProviderId(), emailAddress);
apiQueueResourceDataCollection.add(apiQueueResourceData);
smsData.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
toSaveMessages.add(smsData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -74,28 +73,36 @@ public void process(final Hook hook, final String payload, final String entityNa
String templateName = entityName + "_" + actionName;

// 1 : find template via mapper using entity and action
Template template;
List<Template> templates = this.templateRepository.findByTemplateMapper("SMS_template_Key", templateName);
if (templates.isEmpty()) {
// load default template if set.
template = hook.getUgdTemplate();
} else {
template = templates.get(0);
}
Template template = this.templateRepository.findByName(templateName).orElse(hook.getUgdTemplate());
if (template == null) {
log.error("Error : {} with name {}", "Template not found", templateName);
throw new GeneralPlatformDomainRuleException("error.msg.templates.not.found", "Template not found", templateName);
}

// 2.1 : get customer details for basic template mapping
// 2.2 : cook up scope map
Type type = new TypeToken<Map<String, String>>() {
Type type = new TypeToken<Map<String, Object>>() {

}.getType();
// todo check the decimal issues in Long ids
Map<String, Object> reqMap = new Gson().fromJson(payload, type);
if ("Exception".equals(reqMap.get("status"))) {
log.debug("Operation failed, skipping hook");
return;
}
if (reqMap.get("savingsId") != null) {
Long savingsId = (long) Double.parseDouble(String.valueOf(reqMap.get("savingsId")));
reqMap.put("savingsId", savingsId);
}
if (reqMap.get("loanId") != null) {
Long loanId = (long) Double.parseDouble(String.valueOf(reqMap.get("loanId")));
reqMap.put("loanId", loanId);
}

if (reqMap.get("clientId") != null) {
Long clientId = (Long) reqMap.get("clientId");
Long clientId = (long) Double.parseDouble(String.valueOf(reqMap.get("clientId")));
Client client = clientRepository.findOneWithNotFoundDetection(clientId);
reqMap.put("clientId", clientId);
reqMap.put("clientName", client.getDisplayName());

// 3: compile template using Mustache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ public class SmsMessageApiQueueResourceData {
private String createdOnDate;
private String sourceAddress;
private String mobileNumber;
private String emailAddress;
private String message;
private Long providerId;

/**
* @return a new instance of the SmsMessageApiQueueResourceData class
**/
public static final SmsMessageApiQueueResourceData instance(Long internalId, String mifosTenantIdentifier, String createdOnDate,
String sourceAddress, String mobileNumber, String message, Long providerId) {
String sourceAddress, String mobileNumber, String message, Long providerId, String emailAddress) {

return new SmsMessageApiQueueResourceData().setInternalId(internalId).setTenantId(mifosTenantIdentifier)
.setCreatedOnDate(createdOnDate).setSourceAddress(sourceAddress).setMobileNumber(mobileNumber).setMessage(message)
.setProviderId(providerId);
.setProviderId(providerId).setEmailAddress(emailAddress);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public void sendTriggeredMessages(Map<SmsCampaign, Collection<SmsMessage>> smsDa
smsMessage.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
toSendNotificationMessages.add(smsMessage);
} else {
String emailAddress = (smsMessage.getClient() != null) ? smsMessage.getClient().emailAddress() : null;
SmsMessageApiQueueResourceData apiQueueResourceData = SmsMessageApiQueueResourceData.instance(
smsMessage.getId(), null, null, null, smsMessage.getMobileNo(), smsMessage.getMessage(),
entry.getKey().getProviderId());
entry.getKey().getProviderId(), emailAddress);
apiQueueResourceDatas.add(apiQueueResourceData);
smsMessage.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
toSaveMessages.add(smsMessage);
Expand Down Expand Up @@ -127,8 +128,9 @@ public void sendTriggeredMessage(Collection<SmsMessage> smsMessages, long provid
Collection<SmsMessageApiQueueResourceData> apiQueueResourceDatas = new ArrayList<>();
StringBuilder request = new StringBuilder();
for (SmsMessage smsMessage : smsMessages) {
String emailAddress = (smsMessage.getClient() != null) ? smsMessage.getClient().emailAddress() : null;
SmsMessageApiQueueResourceData apiQueueResourceData = SmsMessageApiQueueResourceData.instance(smsMessage.getId(), null,
null, null, smsMessage.getMobileNo(), smsMessage.getMessage(), providerId);
null, null, smsMessage.getMobileNo(), smsMessage.getMessage(), providerId, emailAddress);
apiQueueResourceDatas.add(apiQueueResourceData);
smsMessage.setStatusType(SmsMessageStatusType.WAITING_FOR_DELIVERY_REPORT.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.template.domain;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -29,4 +30,6 @@ public interface TemplateRepository extends JpaRepository<Template, Long> {

@Query("select t from Template as t left join t.mappers as m where m.mapperkey = :mapperkey and m.mappervalue = :mappervalue")
List<Template> findByTemplateMapper(@Param("mapperkey") String mapperkey, @Param("mappervalue") String mappervalue);

Optional<Template> findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ private Map<String, Object> getCompiledMapFromMappers(final Map<String, String>

mappersMustache.execute(stringWriter, scopes);
String url = stringWriter.toString();
if (scopes.get("BASE_URI") == null) {
scopes.put("BASE_URI", fineractProperties.getBaseUrl());
}
if (!url.startsWith("http")) {
log.info("Base URL : {}", scopes.get("BASE_URI"));
url = scopes.get("BASE_URI") + url;
}
try {
Expand Down Expand Up @@ -167,7 +171,6 @@ protected PasswordAuthentication getPasswordAuthentication() {
connection.setRequestProperty("Authorization", "Basic " + authToken);// NOSONAR
}
TrustModifier.relaxHostChecking(connection);

connection.setDoInput(true);

} catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
Expand Down
3 changes: 2 additions & 1 deletion fineract-provider/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
application.title=Apache Fineract

fineract.node-id=${FINERACT_NODE_ID:1}
fineract.base-url=${FINERACT_BASE_URL:https://localhost:8443/fineract-provider/api/v1/}

fineract.security.basicauth.enabled=${FINERACT_SECURITY_BASICAUTH_ENABLED:true}
fineract.security.oauth.enabled=${FINERACT_SECURITY_OAUTH_ENABLED:false}
Expand Down Expand Up @@ -153,7 +154,7 @@ fineract.content.s3.accessKey=${FINERACT_CONTENT_S3_ACCESS_KEY:}
fineract.content.s3.secretKey=${FINERACT_CONTENT_S3_SECRET_KEY:}

fineract.template.regex-whitelist-enabled=${FINERACT_TEMPLATE_REGEX_WHITELIST_ENABLED:true}
fineract.template.regex-whitelist=${FINERACT_TEMPLATE_REGEX_WHITELIST:}
fineract.template.regex-whitelist=${FINERACT_TEMPLATE_REGEX_WHITELIST:^\.+$}

fineract.report.export.s3.bucket=${FINERACT_REPORT_EXPORT_S3_BUCKET_NAME:}
fineract.report.export.s3.enabled=${FINERACT_REPORT_EXPORT_S3_ENABLED:false}
Expand Down
2 changes: 1 addition & 1 deletion fineract-provider/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/_/ \_\ .__/ \__,_|\___|_| |_|\___| |_| |_|_| |_|\___|_| \__,_|\___|\__|
|_|

${AnsiStyle.FAINT}${AnsiColor.WHITE}(c) 2015-2024 ${application.title} (https://fineract.apache.org)${AnsiColor.BLACK}
${AnsiStyle.FAINT}${AnsiColor.WHITE}(c) 2015-2024 ${application.title} (https://fineract.apache.org)${AnsiColor.BLACK}--TEST--

${AnsiStyle.FAINT}${AnsiColor.WHITE}Powered by Spring Boot ${spring-boot.version}${AnsiColor.BLACK}

0 comments on commit c62b507

Please sign in to comment.