diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index 937452473..d8daeaacc 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -2395,6 +2395,16 @@
|
|
+
+ | External Services |
+ externalservice/{servicename} |
+ |
+ Retrieve
+ a external service configuration |
+ Update
+ external service Configuration |
+ |
+
@@ -16556,6 +16566,94 @@ POST scheduler?command=stop
+
+
+
+
+
External Services
+
External Services Configuration related to set of supported configurations for third party services like Amazon S3 and SMTP:
+
+ - S3 (Amazon S3):
+ - s3_access_key -
+ - s3_bucket_name -
+ - s3_secret_key -
+
+ - SMTP (Email Service):
+ - username -
+ - password -
+ - host -
+ - port -
+ - useTLS -
+
+
+
+
+
+
+
+
+
Retrieve External Services Configuration
+
Returns a external Service configurations based on the Service Name.
+
Service Names supported are S3 and SMTP.
+
Example Requests:
+
externalservice/SMTP
+
+
+
+GET https://DomainName/api/v1/externalservice/{serviceName}
+
+
+
+
+ [
+ {
+ "name": "username",
+ "value": "test@mifos.com"
+ },
+ {
+ "name": "password",
+ "value": "XXXX"
+ },
+ {
+ "name": "host",
+ "value": "smtp.gmail.com"
+ },
+ {
+ "name": "port",
+ "value": "25"
+ },
+ {
+ "name": "useTLS",
+ "value": "true"
+ }
+ ]
+
+
+
+
+
+
+
+
+
+
Update External Service
+
Updates the external Service Configuration for a Service Name.
+
+
+
+PUT https://DomainName/api/v1/externalservice/{serviceName}
+
+
+PUT externalservice/S3
+Content-Type: application/json
+{
+ "username" : "test@mifos.org"
+ "password" : "XXXX"
+}
+
+
+
diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ExternalServicesConfigurationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ExternalServicesConfigurationTest.java
new file mode 100644
index 000000000..55d950580
--- /dev/null
+++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ExternalServicesConfigurationTest.java
@@ -0,0 +1,96 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.integrationtests;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mifosplatform.integrationtests.common.ExternalServicesConfigurationHelper;
+import org.mifosplatform.integrationtests.common.Utils;
+
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.builder.ResponseSpecBuilder;
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.specification.RequestSpecification;
+import com.jayway.restassured.specification.ResponseSpecification;
+
+@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
+public class ExternalServicesConfigurationTest {
+
+ private ResponseSpecification responseSpec;
+ private RequestSpecification requestSpec;
+ private ExternalServicesConfigurationHelper externalServicesConfigurationHelper;
+ private ResponseSpecification httpStatusForidden;
+
+ @Before
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.httpStatusForidden = new ResponseSpecBuilder().expectStatusCode(403).build();
+
+ }
+
+ @Test
+ public void testExternalServicesConfiguration() {
+ this.externalServicesConfigurationHelper = new ExternalServicesConfigurationHelper(this.requestSpec, this.responseSpec);
+
+ // Checking for S3
+ String configName = "s3_access_key";
+ ArrayList externalServicesConfig = this.externalServicesConfigurationHelper
+ .getExternalServicesConfigurationByServiceName(requestSpec, responseSpec, "S3");
+ Assert.assertNotNull(externalServicesConfig);
+ for (Integer configIndex = 0; configIndex < (externalServicesConfig.size()); configIndex++) {
+ String name = (String) externalServicesConfig.get(configIndex).get("name");
+ String value = null;
+ if (name.equals(configName)) {
+ value = (String) externalServicesConfig.get(configIndex).get("value");
+ String newValue = "test";
+ System.out.println(name + ":" + value);
+ HashMap arrayListValue = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
+ responseSpec, "S3", name, newValue);
+ Assert.assertNotNull(arrayListValue.get("value"));
+ Assert.assertEquals(arrayListValue.get("value"), newValue);
+ HashMap arrayListValue1 = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
+ responseSpec, "S3", name, value);
+ Assert.assertNotNull(arrayListValue1.get("value"));
+ Assert.assertEquals(arrayListValue1.get("value"), value);
+ }
+
+ }
+
+ // Checking for SMTP:
+
+ configName = "username";
+ externalServicesConfig = this.externalServicesConfigurationHelper.getExternalServicesConfigurationByServiceName(requestSpec,
+ responseSpec, "SMTP");
+ Assert.assertNotNull(externalServicesConfig);
+ for (Integer configIndex = 0; configIndex < (externalServicesConfig.size()); configIndex++) {
+ String name = (String) externalServicesConfig.get(configIndex).get("name");
+ String value = null;
+ if (name.equals(configName)) {
+ value = (String) externalServicesConfig.get(configIndex).get("value");
+ String newValue = "test";
+ System.out.println(name + ":" + value);
+ HashMap arrayListValue = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
+ responseSpec, "SMTP", name, newValue);
+ Assert.assertNotNull(arrayListValue.get("value"));
+ Assert.assertEquals(arrayListValue.get("value"), newValue);
+ HashMap arrayListValue1 = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
+ responseSpec, "SMTP", name, value);
+ Assert.assertNotNull(arrayListValue1.get("value"));
+ Assert.assertEquals(arrayListValue1.get("value"), value);
+ }
+
+ }
+
+ }
+
+}
diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ExternalServicesConfigurationHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ExternalServicesConfigurationHelper.java
new file mode 100644
index 000000000..c82f85e99
--- /dev/null
+++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ExternalServicesConfigurationHelper.java
@@ -0,0 +1,51 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.integrationtests.common;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import com.google.gson.Gson;
+import com.jayway.restassured.specification.RequestSpecification;
+import com.jayway.restassured.specification.ResponseSpecification;
+
+public class ExternalServicesConfigurationHelper {
+
+ private final RequestSpecification requestSpec;
+ private final ResponseSpecification responseSpec;
+
+ public ExternalServicesConfigurationHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
+ this.requestSpec = requestSpec;
+ this.responseSpec = responseSpec;
+ }
+
+ public static ArrayList getExternalServicesConfigurationByServiceName(final RequestSpecification requestSpec,
+ final ResponseSpecification responseSpec, final String serviceName) {
+ final String GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL = "/mifosng-provider/api/v1/externalservice/" + serviceName + "?"
+ + Utils.TENANT_IDENTIFIER;
+ System.out.println("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
+ return Utils.performServerGet(requestSpec, responseSpec, GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL, "");
+ }
+
+ public static HashMap updateValueForExternaServicesConfiguration(final RequestSpecification requestSpec,
+ final ResponseSpecification responseSpec, final String serviceName, final String name, final String value) {
+ final String EXTERNAL_SERVICES_CONFIG_UPDATE_URL = "/mifosng-provider/api/v1/externalservice/" + serviceName + "?"
+ + Utils.TENANT_IDENTIFIER;
+ System.out.println("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------");
+ HashMap map = Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_SERVICES_CONFIG_UPDATE_URL,
+ updateExternalServicesConfigUpdateValueAsJSON(name, value), "");
+
+ return (HashMap) map.get("changes");
+ }
+
+ public static String updateExternalServicesConfigUpdateValueAsJSON(final String name, final String value) {
+ final HashMap map = new HashMap<>();
+ map.put(name, value);
+ System.out.println("map : " + map);
+ return new Gson().toJson(map);
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
index af23d3d99..c0e24ec2b 100755
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
@@ -29,8 +29,8 @@ public class CommandWrapperBuilder {
private Long templateId;
public CommandWrapper build() {
- return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName,
- this.entityName, this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId);
+ return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName,
+ this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId);
}
public CommandWrapperBuilder withLoanId(final Long withLoanId) {
@@ -1813,7 +1813,8 @@ public class CommandWrapperBuilder {
return this;
}
- public CommandWrapperBuilder saveOrUpdateAttendance(final Long entityId, final String supportedEntityType, final Long supportedEntityId) {
+ public CommandWrapperBuilder saveOrUpdateAttendance(final Long entityId, final String supportedEntityType,
+ final Long supportedEntityId) {
this.actionName = "SAVEORUPDATEATTENDANCE";
this.entityName = "MEETING";
this.entityId = entityId;
@@ -2394,4 +2395,13 @@ public class CommandWrapperBuilder {
return this;
}
+ public CommandWrapperBuilder updateExternalServiceProperties(final String externalServiceName) {
+ this.actionName = "UPDATE";
+ this.entityName = "EXTERNALSERVICES";
+ this.transactionId = externalServiceName;
+
+ this.href = "/externalservices/" + externalServiceName;
+ return this;
+ }
+
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServiceConfigurationApiConstant.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServiceConfigurationApiConstant.java
new file mode 100644
index 000000000..7f8195fb8
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServiceConfigurationApiConstant.java
@@ -0,0 +1,19 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.api;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ExternalServiceConfigurationApiConstant {
+
+ public static final String NAME = "name";
+ public static final String VALUE = "value";
+ public static final String EXTERNAL_SERVICE_RESOURCE_NAME = "externalServiceConfiguration";
+
+ public static final Set EXTERNAL_SERVICE_CONFIGURATION_DATA_PARAMETERS = new HashSet<>(Arrays.asList(NAME, VALUE));
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServicesConfigurationApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServicesConfigurationApiResource.java
new file mode 100644
index 000000000..9affe1005
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/ExternalServicesConfigurationApiResource.java
@@ -0,0 +1,93 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.api;
+
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+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.mifosplatform.commands.domain.CommandWrapper;
+import org.mifosplatform.commands.service.CommandWrapperBuilder;
+import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.mifosplatform.infrastructure.configuration.data.ExternalServicesData;
+import org.mifosplatform.infrastructure.configuration.data.ExternalServicesPropertiesData;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesPropertiesReadPlatformService;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesReadPlatformService;
+import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
+import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
+import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
+import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
+import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Path("/externalservice")
+@Component
+@Scope("singleton")
+public class ExternalServicesConfigurationApiResource {
+
+ private final PlatformSecurityContext context;
+ private final ExternalServicesPropertiesReadPlatformService externalServicePropertiesReadPlatformService;
+ private final ExternalServicesReadPlatformService externalServiceReadPlatformService;
+ private final ToApiJsonSerializer toApiJsonSerializer;
+ // private final ToApiJsonSerializer
+ // s3ToApiJsonSerializer;
+ private final ApiRequestParameterHelper apiRequestParameterHelper;
+ private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+ @Autowired
+ public ExternalServicesConfigurationApiResource(final PlatformSecurityContext context,
+ final ExternalServicesPropertiesReadPlatformService readPlatformService,
+ final ExternalServicesReadPlatformService externalServicesReadPlatformService,
+ final ToApiJsonSerializer toApiJsonSerializer,
+ final ApiRequestParameterHelper apiRequestParameterHelper,
+ final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
+ this.context = context;
+ this.externalServicePropertiesReadPlatformService = readPlatformService;
+ this.toApiJsonSerializer = toApiJsonSerializer;
+ this.externalServiceReadPlatformService = externalServicesReadPlatformService;
+ // this.s3ToApiJsonSerializer = s3ToApiJsonSerializer;
+ this.apiRequestParameterHelper = apiRequestParameterHelper;
+ this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+ }
+
+ @GET
+ @Path("{servicename}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String retrieveOne(@PathParam("servicename") final String serviceName, @Context final UriInfo uriInfo) {
+ this.context.authenticatedUser().validateHasReadPermission(ExternalServiceConfigurationApiConstant.EXTERNAL_SERVICE_RESOURCE_NAME);
+ final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
+ final Collection externalServiceNVPs = this.externalServicePropertiesReadPlatformService
+ .retrieveOne(serviceName);
+ return this.toApiJsonSerializer.serialize(settings, externalServiceNVPs,
+ ExternalServiceConfigurationApiConstant.EXTERNAL_SERVICE_CONFIGURATION_DATA_PARAMETERS);
+ }
+
+ @PUT
+ @Path("{servicename}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String updateExternalServiceProperties(@PathParam("servicename") final String serviceName, final String apiRequestBodyAsJson) {
+ // ExternalServicesData external =
+ // this.externalServiceReadPlatformService.getExternalServiceDetailsByServiceName(serviceName);
+ final CommandWrapper commandRequest = new CommandWrapperBuilder().updateExternalServiceProperties(serviceName)
+ .withJson(apiRequestBodyAsJson).build();
+ final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ return this.toApiJsonSerializer.serialize(result);
+
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesData.java
new file mode 100644
index 000000000..721153a8f
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesData.java
@@ -0,0 +1,26 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.data;
+
+public class ExternalServicesData {
+
+ private final Long id;
+ private final String name;
+
+ public ExternalServicesData(final Long id, final String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesPropertiesData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesPropertiesData.java
new file mode 100644
index 000000000..fd9e583c3
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/ExternalServicesPropertiesData.java
@@ -0,0 +1,28 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.data;
+
+import java.io.Serializable;
+
+public class ExternalServicesPropertiesData implements Serializable {
+
+ private final String name;
+ private final String value;
+
+ public ExternalServicesPropertiesData(final String name, final String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/SMTPCredentialsData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/SMTPCredentialsData.java
new file mode 100644
index 000000000..75aa59934
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/data/SMTPCredentialsData.java
@@ -0,0 +1,44 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.data;
+
+public class SMTPCredentialsData {
+
+ private final String username;
+ private final String password;
+ private final String host;
+ private final String port;
+ private final boolean useTLS;
+
+ public SMTPCredentialsData(final String username, final String password, final String host, final String port, final boolean useTLS) {
+ this.username = username;
+ this.password = password;
+ this.host = host;
+ this.port = port;
+ this.useTLS = useTLS;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public boolean isUseTLS() {
+ return useTLS;
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalService.java
index ec8b30055..bb55326df 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalService.java
@@ -1,5 +1,11 @@
package org.mifosplatform.infrastructure.configuration.domain;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
@@ -8,29 +14,39 @@ package org.mifosplatform.infrastructure.configuration.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import org.apache.commons.lang.StringUtils;
+import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
-@Table(name = "c_external_service", uniqueConstraints = { @UniqueConstraint(columnNames = "name") })
+@Table(name = "c_external_service", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_UNIQUE") })
public class ExternalService extends AbstractPersistable {
- @Column(name = "name", nullable = false)
+ @Column(name = "name", length = 50)
private String name;
- @Column(name = "value", nullable = false)
- private String value;
+ // @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy =
+ // "externalServicePropertiesPK.externalService", orphanRemoval = true)
+ // private Set values;
- public ExternalService(final String name, final String value) {
+ public static ExternalService fromJson(final JsonCommand command) {
+ final String name = command.stringValueOfParameterNamed("name");
+ return new ExternalService(name);
+ }
+
+ private ExternalService(final String name) {
this.name = name;
- this.value = value;
}
protected ExternalService() {}
- public String getValue() {
- return this.value;
+ public String name() {
+ return this.name;
}
+
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicePropertiesPK.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
new file mode 100644
index 000000000..11fb959c1
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
@@ -0,0 +1,43 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.domain;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+import org.springframework.data.annotation.Id;
+
+@Embeddable
+public class ExternalServicePropertiesPK implements Serializable {
+
+ @Column(name = "name", length = 150)
+ private String name;
+
+ @Column(name = "external_service_id")
+ private Long externalServiceId;
+
+ public ExternalServicePropertiesPK() {
+
+ }
+
+ public ExternalServicePropertiesPK(Long externalServiceId, String name) {
+ this.externalServiceId = externalServiceId;
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Long getExternalService() {
+ return externalServiceId;
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesProperties.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesProperties.java
new file mode 100644
index 000000000..582a3b090
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesProperties.java
@@ -0,0 +1,76 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.domain;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.Embedded;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.commons.lang.StringUtils;
+import org.mifosplatform.infrastructure.configuration.data.ExternalServicesPropertiesData;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants.EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants.SMTP_JSON_INPUT_PARAMS;
+import org.mifosplatform.infrastructure.core.api.JsonCommand;
+import org.springframework.data.annotation.Id;
+
+@Entity
+@Table(name = "c_external_service_properties")
+public class ExternalServicesProperties {
+
+ @EmbeddedId
+ ExternalServicePropertiesPK externalServicePropertiesPK;
+
+ @Column(name = "value", length = 250)
+ private String value;
+
+ protected ExternalServicesProperties() {
+
+ }
+
+ private ExternalServicesProperties(final ExternalServicePropertiesPK externalServicePropertiesPK, final String value) {
+ this.externalServicePropertiesPK = externalServicePropertiesPK;
+
+ this.value = value;
+
+ }
+
+ public static ExternalServicesProperties fromJson(final ExternalService externalService, final JsonCommand command) {
+ final String name = command.stringValueOfParameterNamed(EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.NAME.getValue());
+ final String value = command.stringValueOfParameterNamed(EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.VALUE.getValue());
+ return new ExternalServicesProperties(new ExternalServicePropertiesPK(externalService.getId(), name), value);
+ }
+
+ public Map update(final JsonCommand command, String paramName) {
+ final Map actualChanges = new LinkedHashMap<>(2);
+
+ final String valueParamName = EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.VALUE.getValue();
+ if (command.isChangeInStringParameterNamed(paramName, this.value)) {
+ final String newValue = command.stringValueOfParameterNamed(paramName);
+ if (paramName.equals(SMTP_JSON_INPUT_PARAMS.PASSWORD.getValue()) && newValue.equals("XXXX")) {
+ // If Param Name is Password and ParamValue is XXXX that means
+ // the password has not been changed.
+ } else {
+ actualChanges.put(valueParamName, newValue);
+ }
+ this.value = StringUtils.defaultIfEmpty(newValue, null);
+ }
+
+ return actualChanges;
+ }
+
+ public ExternalServicesPropertiesData toData() {
+ return new ExternalServicesPropertiesData(this.externalServicePropertiesPK.getName(), this.value);
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServiceRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
similarity index 56%
rename from mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServiceRepository.java
rename to mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
index baf42651d..48ee6b69d 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServiceRepository.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
@@ -8,7 +8,8 @@ package org.mifosplatform.infrastructure.configuration.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-public interface ExternalServiceRepository extends JpaRepository, JpaSpecificationExecutor {
+public interface ExternalServicesPropertiesRepository extends JpaRepository,
+ JpaSpecificationExecutor {
- ExternalService findOneByName(String name);
+ ExternalServicesProperties findOneByExternalServicePropertiesPK(ExternalServicePropertiesPK externalServicesProptiesPK);
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
new file mode 100644
index 000000000..4895f2f74
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
@@ -0,0 +1,28 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.domain;
+
+import org.mifosplatform.infrastructure.configuration.exception.ExternalServiceConfigurationNotFoundException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ExternalServicesPropertiesRepositoryWrapper {
+
+ private final ExternalServicesPropertiesRepository repository;
+
+ @Autowired
+ public ExternalServicesPropertiesRepositoryWrapper(final ExternalServicesPropertiesRepository repository) {
+ this.repository = repository;
+ }
+
+ public ExternalServicesProperties findOneByIdAndName(Long id, String name, String externalServiceName) {
+ final ExternalServicesProperties externalServicesProperties = this.repository
+ .findOneByExternalServicePropertiesPK(new ExternalServicePropertiesPK(id, name));
+ if (externalServicesProperties == null) throw new ExternalServiceConfigurationNotFoundException(externalServiceName, name);
+ return externalServicesProperties;
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/exception/ExternalServiceConfigurationNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/exception/ExternalServiceConfigurationNotFoundException.java
new file mode 100644
index 000000000..46233d200
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/exception/ExternalServiceConfigurationNotFoundException.java
@@ -0,0 +1,20 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.exception;
+
+import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
+
+public class ExternalServiceConfigurationNotFoundException extends AbstractPlatformResourceNotFoundException {
+
+ public ExternalServiceConfigurationNotFoundException(final String serviceName) {
+ super("error.msg.externalservice.servicename.invalid", "Service Name`" + serviceName + "` does not exist", serviceName);
+ }
+
+ public ExternalServiceConfigurationNotFoundException(final String externalServiceName, final String name) {
+ super("error.msg.externalservice.property.invalid",
+ "Parameter`" + name + "` does not exist for the ServiceName `" + externalServiceName + "`", name, externalServiceName);
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/handler/UpdateExternalServiceConfigurationCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/handler/UpdateExternalServiceConfigurationCommandHandler.java
new file mode 100644
index 000000000..2ff4df255
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/handler/UpdateExternalServiceConfigurationCommandHandler.java
@@ -0,0 +1,34 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.handler;
+
+import org.mifosplatform.commands.annotation.CommandType;
+import org.mifosplatform.commands.handler.NewCommandSourceHandler;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServiceWritePlatformService;
+import org.mifosplatform.infrastructure.core.api.JsonCommand;
+import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@CommandType(entity = "EXTERNALSERVICES", action = "UPDATE")
+public class UpdateExternalServiceConfigurationCommandHandler implements NewCommandSourceHandler {
+
+ private final ExternalServiceWritePlatformService writePlatformService;
+
+ @Autowired
+ public UpdateExternalServiceConfigurationCommandHandler(final ExternalServiceWritePlatformService writePlatformService) {
+ this.writePlatformService = writePlatformService;
+ }
+
+ @Transactional
+ @Override
+ public CommandProcessingResult processCommand(final JsonCommand command) {
+ return this.writePlatformService.updateExternalServicesProperties(command.getTransactionId(), command);
+ }
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/serialization/ExternalServicesPropertiesCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/serialization/ExternalServicesPropertiesCommandFromApiJsonDeserializer.java
new file mode 100644
index 000000000..ce60be3d6
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/serialization/ExternalServicesPropertiesCommandFromApiJsonDeserializer.java
@@ -0,0 +1,72 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.infrastructure.configuration.serialization;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.mifosplatform.infrastructure.configuration.exception.ExternalServiceConfigurationNotFoundException;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants.EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants.S3_JSON_INPUT_PARAMS;
+import org.mifosplatform.infrastructure.configuration.service.ExternalServicesConstants.SMTP_JSON_INPUT_PARAMS;
+import org.mifosplatform.infrastructure.core.data.ApiParameterError;
+import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
+import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
+import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.JsonElement;
+import com.google.gson.reflect.TypeToken;
+
+@Component
+public class ExternalServicesPropertiesCommandFromApiJsonDeserializer {
+
+ private final Set supportedParameters = EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.getAllValues();
+ private final Set S3SupportedParameters = S3_JSON_INPUT_PARAMS.getAllValues();
+ private final Set SMTPSupportedParameters = SMTP_JSON_INPUT_PARAMS.getAllValues();
+ private final FromJsonHelper fromApiJsonHelper;
+
+ @Autowired
+ public ExternalServicesPropertiesCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
+ this.fromApiJsonHelper = fromApiJsonHelper;
+ }
+
+ public void validateForUpdate(final String json, final String externalServiceName) {
+ if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
+
+ final Type typeOfMap = new TypeToken