diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java b/fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java index d867511f1..b25af17ef 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java +++ b/fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java @@ -3590,4 +3590,11 @@ public class CommandWrapperBuilder { this.jobName = jobName; return this; } + + public CommandWrapperBuilder updateExternalEventConfigurations() { + this.actionName = "UPDATE"; + this.entityName = "EXTERNAL_EVENT_CONFIGURATION"; + this.href = "/externaleventconfiguration"; + return this; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResource.java new file mode 100644 index 000000000..85e0fa32a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResource.java @@ -0,0 +1,100 @@ +/** + * 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.event.external.api; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.commands.domain.CommandWrapper; +import org.apache.fineract.commands.service.CommandWrapperBuilder; +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; +import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; +import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; +import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationData; +import org.apache.fineract.infrastructure.event.external.service.ExternalEventConfigurationReadPlatformService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Path("/externalevents/configuration") +@Component +@Tag(name = "External event configuration", description = "External event configuration enables user to enable/disable event posting to downstream message channel") +public class ExternalEventConfigurationApiResource { + + private static final Set RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("type", "enabled")); + + private static final String RESOURCE_NAME_FOR_PERMISSIONS = "EXTERNAL_EVENT_CONFIGURATION"; + + private final PlatformSecurityContext context; + private final ApiRequestParameterHelper apiRequestParameterHelper; + private final PortfolioCommandSourceWritePlatformService commandWritePlatformService; + private final DefaultToApiJsonSerializer jsonSerializer; + private final ExternalEventConfigurationReadPlatformService readPlatformService; + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + @Operation(summary = "List all external event configurations", description = "") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "List of all external event configurations", content = @Content(schema = @Schema(implementation = ExternalEventConfigurationApiResourceSwagger.GetExternalEventConfigurationsResponse.class))) }) + public String retrieveExternalEventConfiguration(@Context final UriInfo uriInfo) { + context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); + final ExternalEventConfigurationData configurationData = readPlatformService.findAllExternalEventConfigurations(); + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return jsonSerializer.serialize(settings, configurationData, RESPONSE_DATA_PARAMETERS); + } + + @PUT + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + @Operation(summary = "Enable/Disable external events posting", description = "") + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = ExternalEventConfigurationApiResourceSwagger.PutExternalEventConfigurationsRequest.class))) + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) }) + + public String updateExternalEventConfigurationsDetails(@Parameter(hidden = true) final String apiRequestBodyAsJson) { + context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .updateExternalEventConfigurations() // + .withJson(apiRequestBodyAsJson) // + .build(); + final CommandProcessingResult result = this.commandWritePlatformService.logCommandSource(commandRequest); + return this.jsonSerializer.serialize(result); + + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResourceSwagger.java new file mode 100644 index 000000000..bb473a949 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/api/ExternalEventConfigurationApiResourceSwagger.java @@ -0,0 +1,48 @@ +/** + * 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.event.external.api; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import java.util.Map; +import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationItemData; + +final class ExternalEventConfigurationApiResourceSwagger { + + private ExternalEventConfigurationApiResourceSwagger() {} + + @Schema(description = "GetExternalEventConfigurationsResponse") + public static final class GetExternalEventConfigurationsResponse { + + private GetExternalEventConfigurationsResponse() {} + + public List externalEventConfiguration; + } + + @Schema(description = "PutExternalEventConfigurationsRequest") + public static final class PutExternalEventConfigurationsRequest { + + private PutExternalEventConfigurationsRequest() {} + + @Schema(example = "\"CentersCreateBusinessEvent\":true,\n" + "\"ClientActivateBusinessEvent\":true") + public Map> externalEventConfigurations; + + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/handler/ExternalEventConfigurationUpdateHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/handler/ExternalEventConfigurationUpdateHandler.java new file mode 100644 index 000000000..b299c756d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/handler/ExternalEventConfigurationUpdateHandler.java @@ -0,0 +1,43 @@ +/** + * 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.event.external.handler; + +import javax.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.commands.annotation.CommandType; +import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.external.service.ExternalEventConfigurationWritePlatformService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@CommandType(entity = "EXTERNAL_EVENT_CONFIGURATION", action = "UPDATE") +public class ExternalEventConfigurationUpdateHandler implements NewCommandSourceHandler { + + private final ExternalEventConfigurationWritePlatformService writePlatformService; + + @Transactional + @Override + public CommandProcessingResult processCommand(@NotNull final JsonCommand command) { + return writePlatformService.updateConfigurations(command); + } +} diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index 8e90dbb53..021e6e960 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -82,4 +82,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0063_add_permissions_for_external_event_configuration.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0063_add_permissions_for_external_event_configuration.xml new file mode 100644 index 000000000..0141a1574 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0063_add_permissions_for_external_event_configuration.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java new file mode 100644 index 000000000..fcddf43ba --- /dev/null +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java @@ -0,0 +1,87 @@ +/** + * 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.integrationtests; + +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.http.ContentType; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; +import java.util.ArrayList; +import java.util.Map; +import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ExternalEventConfigurationIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @BeforeEach + 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(); + + } + + @Test + public void getExternalEventConfigurations() { + final ArrayList> externalEventConfigurations = ExternalEventConfigurationHelper + .getAllExternalEventConfigurations(requestSpec, responseSpec); + Assertions.assertNotNull(externalEventConfigurations); + final ArrayList> defaultConfigurations = ExternalEventConfigurationHelper + .getDefaultExternalEventConfigurations(); + Assertions.assertEquals(defaultConfigurations.size(), externalEventConfigurations.size()); + verifyAllEventConfigurations(externalEventConfigurations, defaultConfigurations); + + } + + private void verifyAllEventConfigurations(ArrayList> actualEventConfigurations, + ArrayList> defaultConfigurations) { + + for (int index = 0; index < actualEventConfigurations.size(); index++) { + Assertions.assertTrue(defaultConfigurations.contains(actualEventConfigurations.get(index))); + } + } + + @Test + public void updateExternalEventConfigurations() { + String updateRequestJson = ExternalEventConfigurationHelper.getExternalEventConfigurationsForUpdateJSON(); + final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, + responseSpec, updateRequestJson); + Assertions.assertEquals(updatedConfigurations.size(), 2); + Assertions.assertTrue(updatedConfigurations.containsKey("CentersCreateBusinessEvent")); + Assertions.assertTrue(updatedConfigurations.containsKey("ClientActivateBusinessEvent")); + Assertions.assertTrue(updatedConfigurations.get("CentersCreateBusinessEvent")); + Assertions.assertTrue(updatedConfigurations.get("ClientActivateBusinessEvent")); + + } + + @AfterEach + public void tearDown() { + ExternalEventConfigurationHelper.resetDefaultConfigurations(requestSpec, responseSpec); + } + +} diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java new file mode 100644 index 000000000..385a44329 --- /dev/null +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java @@ -0,0 +1,458 @@ +/** + * 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.integrationtests.common; + +import com.google.gson.Gson; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class ExternalEventConfigurationHelper { + + private static final String EXTERNAL_EVENT_CONFIGURATION = "externalEventConfiguration"; + private static final String EXTERNAL_EVENT_CONFIGURATION_RESPONSE = "externalEventConfigurations"; + + protected ExternalEventConfigurationHelper() {} + + private static final String EXTERNAL_EVENT_CONFIGURATION_URL = "/fineract-provider/api/v1/externalevents/configuration?" + + Utils.TENANT_IDENTIFIER; + + public static ArrayList> getAllExternalEventConfigurations(RequestSpecification requestSpec, + ResponseSpecification responseSpec) { + Map>> response = Utils.performServerGet(requestSpec, responseSpec, + EXTERNAL_EVENT_CONFIGURATION_URL, ""); + return response.get(EXTERNAL_EVENT_CONFIGURATION); + } + + public static ArrayList> getDefaultExternalEventConfigurations() { + ArrayList> defaults = new ArrayList<>(); + + Map centersCreateBusinessEvent = new HashMap<>(); + centersCreateBusinessEvent.put("type", "CentersCreateBusinessEvent"); + centersCreateBusinessEvent.put("enabled", false); + defaults.add(centersCreateBusinessEvent); + + Map clientActivateBusinessEvent = new HashMap<>(); + clientActivateBusinessEvent.put("type", "ClientActivateBusinessEvent"); + clientActivateBusinessEvent.put("enabled", false); + defaults.add(clientActivateBusinessEvent); + + Map clientCreateBusinessEvent = new HashMap<>(); + clientCreateBusinessEvent.put("type", "ClientCreateBusinessEvent"); + clientCreateBusinessEvent.put("enabled", false); + defaults.add(clientCreateBusinessEvent); + + Map clientRejectBusinessEvent = new HashMap<>(); + clientRejectBusinessEvent.put("type", "ClientRejectBusinessEvent"); + clientRejectBusinessEvent.put("enabled", false); + defaults.add(clientRejectBusinessEvent); + + Map fixedDepositAccountCreateBusinessEvent = new HashMap<>(); + fixedDepositAccountCreateBusinessEvent.put("type", "FixedDepositAccountCreateBusinessEvent"); + fixedDepositAccountCreateBusinessEvent.put("enabled", false); + defaults.add(fixedDepositAccountCreateBusinessEvent); + + Map groupsCreateBusinessEvent = new HashMap<>(); + groupsCreateBusinessEvent.put("type", "GroupsCreateBusinessEvent"); + groupsCreateBusinessEvent.put("enabled", false); + defaults.add(groupsCreateBusinessEvent); + + Map loanAcceptTransferBusinessEvent = new HashMap<>(); + loanAcceptTransferBusinessEvent.put("type", "LoanAcceptTransferBusinessEvent"); + loanAcceptTransferBusinessEvent.put("enabled", false); + defaults.add(loanAcceptTransferBusinessEvent); + + Map loanAddChargeBusinessEvent = new HashMap<>(); + loanAddChargeBusinessEvent.put("type", "LoanAddChargeBusinessEvent"); + loanAddChargeBusinessEvent.put("enabled", false); + defaults.add(loanAddChargeBusinessEvent); + + Map loanAdjustTransactionBusinessEvent = new HashMap<>(); + loanAdjustTransactionBusinessEvent.put("type", "LoanAdjustTransactionBusinessEvent"); + loanAdjustTransactionBusinessEvent.put("enabled", false); + defaults.add(loanAdjustTransactionBusinessEvent); + + Map loanApplyOverdueChargeBusinessEvent = new HashMap<>(); + loanApplyOverdueChargeBusinessEvent.put("type", "LoanApplyOverdueChargeBusinessEvent"); + loanApplyOverdueChargeBusinessEvent.put("enabled", false); + defaults.add(loanApplyOverdueChargeBusinessEvent); + + Map loanApprovedBusinessEvent = new HashMap<>(); + loanApprovedBusinessEvent.put("type", "LoanApprovedBusinessEvent"); + loanApprovedBusinessEvent.put("enabled", false); + defaults.add(loanApprovedBusinessEvent); + + Map loanBalanceChangedBusinessEvent = new HashMap<>(); + loanBalanceChangedBusinessEvent.put("type", "LoanBalanceChangedBusinessEvent"); + loanBalanceChangedBusinessEvent.put("enabled", false); + defaults.add(loanBalanceChangedBusinessEvent); + + Map loanChargebackTransactionBusinessEvent = new HashMap<>(); + loanChargebackTransactionBusinessEvent.put("type", "LoanChargebackTransactionBusinessEvent"); + loanChargebackTransactionBusinessEvent.put("enabled", false); + defaults.add(loanChargebackTransactionBusinessEvent); + + Map loanChargePaymentPostBusinessEvent = new HashMap<>(); + loanChargePaymentPostBusinessEvent.put("type", "LoanChargePaymentPostBusinessEvent"); + loanChargePaymentPostBusinessEvent.put("enabled", false); + defaults.add(loanChargePaymentPostBusinessEvent); + + Map loanChargePaymentPreBusinessEvent = new HashMap<>(); + loanChargePaymentPreBusinessEvent.put("type", "LoanChargePaymentPreBusinessEvent"); + loanChargePaymentPreBusinessEvent.put("enabled", false); + defaults.add(loanChargePaymentPreBusinessEvent); + + Map loanChargeRefundBusinessEvent = new HashMap<>(); + loanChargeRefundBusinessEvent.put("type", "LoanChargeRefundBusinessEvent"); + loanChargeRefundBusinessEvent.put("enabled", false); + defaults.add(loanChargeRefundBusinessEvent); + + Map loanCloseAsRescheduleBusinessEvent = new HashMap<>(); + loanCloseAsRescheduleBusinessEvent.put("type", "LoanCloseAsRescheduleBusinessEvent"); + loanCloseAsRescheduleBusinessEvent.put("enabled", false); + defaults.add(loanCloseAsRescheduleBusinessEvent); + + Map loanCloseBusinessEvent = new HashMap<>(); + loanCloseBusinessEvent.put("type", "LoanCloseBusinessEvent"); + loanCloseBusinessEvent.put("enabled", false); + defaults.add(loanCloseBusinessEvent); + + Map loanCreatedBusinessEvent = new HashMap<>(); + loanCreatedBusinessEvent.put("type", "LoanCreatedBusinessEvent"); + loanCreatedBusinessEvent.put("enabled", false); + defaults.add(loanCreatedBusinessEvent); + + Map loanCreditBalanceRefundPostBusinessEvent = new HashMap<>(); + loanCreditBalanceRefundPostBusinessEvent.put("type", "LoanCreditBalanceRefundPostBusinessEvent"); + loanCreditBalanceRefundPostBusinessEvent.put("enabled", false); + defaults.add(loanCreditBalanceRefundPostBusinessEvent); + + Map loanCreditBalanceRefundPreBusinessEvent = new HashMap<>(); + loanCreditBalanceRefundPreBusinessEvent.put("type", "LoanCreditBalanceRefundPreBusinessEvent"); + loanCreditBalanceRefundPreBusinessEvent.put("enabled", false); + defaults.add(loanCreditBalanceRefundPreBusinessEvent); + + Map loanDeleteChargeBusinessEvent = new HashMap<>(); + loanDeleteChargeBusinessEvent.put("type", "LoanDeleteChargeBusinessEvent"); + loanDeleteChargeBusinessEvent.put("enabled", false); + defaults.add(loanDeleteChargeBusinessEvent); + + Map loanDisbursalBusinessEvent = new HashMap<>(); + loanDisbursalBusinessEvent.put("type", "LoanDisbursalBusinessEvent"); + loanDisbursalBusinessEvent.put("enabled", false); + defaults.add(loanDisbursalBusinessEvent); + + Map loanDisbursalTransactionBusinessEvent = new HashMap<>(); + loanDisbursalTransactionBusinessEvent.put("type", "LoanDisbursalTransactionBusinessEvent"); + loanDisbursalTransactionBusinessEvent.put("enabled", false); + defaults.add(loanDisbursalTransactionBusinessEvent); + + Map loanForeClosurePostBusinessEvent = new HashMap<>(); + loanForeClosurePostBusinessEvent.put("type", "LoanForeClosurePostBusinessEvent"); + loanForeClosurePostBusinessEvent.put("enabled", false); + defaults.add(loanForeClosurePostBusinessEvent); + + Map loanForeClosurePreBusinessEvent = new HashMap<>(); + loanForeClosurePreBusinessEvent.put("type", "LoanForeClosurePreBusinessEvent"); + loanForeClosurePreBusinessEvent.put("enabled", false); + defaults.add(loanForeClosurePreBusinessEvent); + + Map loanInitiateTransferBusinessEvent = new HashMap<>(); + loanInitiateTransferBusinessEvent.put("type", "LoanInitiateTransferBusinessEvent"); + loanInitiateTransferBusinessEvent.put("enabled", false); + defaults.add(loanInitiateTransferBusinessEvent); + + Map loanInterestRecalculationBusinessEvent = new HashMap<>(); + loanInterestRecalculationBusinessEvent.put("type", "LoanInterestRecalculationBusinessEvent"); + loanInterestRecalculationBusinessEvent.put("enabled", false); + defaults.add(loanInterestRecalculationBusinessEvent); + + Map loanProductCreateBusinessEvent = new HashMap<>(); + loanProductCreateBusinessEvent.put("type", "LoanProductCreateBusinessEvent"); + loanProductCreateBusinessEvent.put("enabled", false); + defaults.add(loanProductCreateBusinessEvent); + + Map loanReassignOfficerBusinessEvent = new HashMap<>(); + loanReassignOfficerBusinessEvent.put("type", "LoanReassignOfficerBusinessEvent"); + loanReassignOfficerBusinessEvent.put("enabled", false); + defaults.add(loanReassignOfficerBusinessEvent); + + Map loanRefundPostBusinessEvent = new HashMap<>(); + loanRefundPostBusinessEvent.put("type", "LoanRefundPostBusinessEvent"); + loanRefundPostBusinessEvent.put("enabled", false); + defaults.add(loanRefundPostBusinessEvent); + + Map loanRefundPreBusinessEvent = new HashMap<>(); + loanRefundPreBusinessEvent.put("type", "LoanRefundPreBusinessEvent"); + loanRefundPreBusinessEvent.put("enabled", false); + defaults.add(loanRefundPreBusinessEvent); + + Map loanRejectedBusinessEvent = new HashMap<>(); + loanRejectedBusinessEvent.put("type", "LoanRejectedBusinessEvent"); + loanRejectedBusinessEvent.put("enabled", false); + defaults.add(loanRejectedBusinessEvent); + + Map loanRejectTransferBusinessEvent = new HashMap<>(); + loanRejectTransferBusinessEvent.put("type", "LoanRejectTransferBusinessEvent"); + loanRejectTransferBusinessEvent.put("enabled", false); + defaults.add(loanRejectTransferBusinessEvent); + + Map loanRemoveOfficerBusinessEvent = new HashMap<>(); + loanRemoveOfficerBusinessEvent.put("type", "LoanRemoveOfficerBusinessEvent"); + loanRemoveOfficerBusinessEvent.put("enabled", false); + defaults.add(loanRemoveOfficerBusinessEvent); + + Map loanRescheduledDueCalendarChangeBusinessEvent = new HashMap<>(); + loanRescheduledDueCalendarChangeBusinessEvent.put("type", "LoanRescheduledDueCalendarChangeBusinessEvent"); + loanRescheduledDueCalendarChangeBusinessEvent.put("enabled", false); + defaults.add(loanRescheduledDueCalendarChangeBusinessEvent); + + Map loanRescheduledDueHolidayBusinessEvent = new HashMap<>(); + loanRescheduledDueHolidayBusinessEvent.put("type", "LoanRescheduledDueHolidayBusinessEvent"); + loanRescheduledDueHolidayBusinessEvent.put("enabled", false); + defaults.add(loanRescheduledDueHolidayBusinessEvent); + + Map loanScheduleVariationsAddedBusinessEvent = new HashMap<>(); + loanScheduleVariationsAddedBusinessEvent.put("type", "LoanScheduleVariationsAddedBusinessEvent"); + loanScheduleVariationsAddedBusinessEvent.put("enabled", false); + defaults.add(loanScheduleVariationsAddedBusinessEvent); + + Map loanScheduleVariationsDeletedBusinessEvent = new HashMap<>(); + loanScheduleVariationsDeletedBusinessEvent.put("type", "LoanScheduleVariationsDeletedBusinessEvent"); + loanScheduleVariationsDeletedBusinessEvent.put("enabled", false); + defaults.add(loanScheduleVariationsDeletedBusinessEvent); + + Map loanStatusChangedBusinessEvent = new HashMap<>(); + loanStatusChangedBusinessEvent.put("type", "LoanStatusChangedBusinessEvent"); + loanStatusChangedBusinessEvent.put("enabled", false); + defaults.add(loanStatusChangedBusinessEvent); + + Map loanTransactionGoodwillCreditPostBusinessEvent = new HashMap<>(); + loanTransactionGoodwillCreditPostBusinessEvent.put("type", "LoanTransactionGoodwillCreditPostBusinessEvent"); + loanTransactionGoodwillCreditPostBusinessEvent.put("enabled", false); + defaults.add(loanTransactionGoodwillCreditPostBusinessEvent); + + Map loanTransactionGoodwillCreditPreBusinessEvent = new HashMap<>(); + loanTransactionGoodwillCreditPreBusinessEvent.put("type", "LoanTransactionGoodwillCreditPreBusinessEvent"); + loanTransactionGoodwillCreditPreBusinessEvent.put("enabled", false); + defaults.add(loanTransactionGoodwillCreditPreBusinessEvent); + + Map loanTransactionMakeRepaymentPostBusinessEvent = new HashMap<>(); + loanTransactionMakeRepaymentPostBusinessEvent.put("type", "LoanTransactionMakeRepaymentPostBusinessEvent"); + loanTransactionMakeRepaymentPostBusinessEvent.put("enabled", false); + defaults.add(loanTransactionMakeRepaymentPostBusinessEvent); + + Map loanTransactionMakeRepaymentPreBusinessEvent = new HashMap<>(); + loanTransactionMakeRepaymentPreBusinessEvent.put("type", "LoanTransactionMakeRepaymentPreBusinessEvent"); + loanTransactionMakeRepaymentPreBusinessEvent.put("enabled", false); + defaults.add(loanTransactionMakeRepaymentPreBusinessEvent); + + Map loanTransactionMerchantIssuedRefundPostBusinessEvent = new HashMap<>(); + loanTransactionMerchantIssuedRefundPostBusinessEvent.put("type", "LoanTransactionMerchantIssuedRefundPostBusinessEvent"); + loanTransactionMerchantIssuedRefundPostBusinessEvent.put("enabled", false); + defaults.add(loanTransactionMerchantIssuedRefundPostBusinessEvent); + + Map loanTransactionMerchantIssuedRefundPreBusinessEvent = new HashMap<>(); + loanTransactionMerchantIssuedRefundPreBusinessEvent.put("type", "LoanTransactionMerchantIssuedRefundPreBusinessEvent"); + loanTransactionMerchantIssuedRefundPreBusinessEvent.put("enabled", false); + defaults.add(loanTransactionMerchantIssuedRefundPreBusinessEvent); + + Map loanTransactionPayoutRefundPostBusinessEvent = new HashMap<>(); + loanTransactionPayoutRefundPostBusinessEvent.put("type", "LoanTransactionPayoutRefundPostBusinessEvent"); + loanTransactionPayoutRefundPostBusinessEvent.put("enabled", false); + defaults.add(loanTransactionPayoutRefundPostBusinessEvent); + + Map loanTransactionPayoutRefundPreBusinessEvent = new HashMap<>(); + loanTransactionPayoutRefundPreBusinessEvent.put("type", "LoanTransactionPayoutRefundPreBusinessEvent"); + loanTransactionPayoutRefundPreBusinessEvent.put("enabled", false); + defaults.add(loanTransactionPayoutRefundPreBusinessEvent); + + Map loanTransactionRecoveryPaymentPostBusinessEvent = new HashMap<>(); + loanTransactionRecoveryPaymentPostBusinessEvent.put("type", "LoanTransactionRecoveryPaymentPostBusinessEvent"); + loanTransactionRecoveryPaymentPostBusinessEvent.put("enabled", false); + defaults.add(loanTransactionRecoveryPaymentPostBusinessEvent); + + Map loanTransactionRecoveryPaymentPreBusinessEvent = new HashMap<>(); + loanTransactionRecoveryPaymentPreBusinessEvent.put("type", "LoanTransactionRecoveryPaymentPreBusinessEvent"); + loanTransactionRecoveryPaymentPreBusinessEvent.put("enabled", false); + defaults.add(loanTransactionRecoveryPaymentPreBusinessEvent); + + Map loanUndoApprovalBusinessEvent = new HashMap<>(); + loanUndoApprovalBusinessEvent.put("type", "LoanUndoApprovalBusinessEvent"); + loanUndoApprovalBusinessEvent.put("enabled", false); + defaults.add(loanUndoApprovalBusinessEvent); + + Map loanUndoDisbursalBusinessEvent = new HashMap<>(); + loanUndoDisbursalBusinessEvent.put("type", "LoanUndoDisbursalBusinessEvent"); + loanUndoDisbursalBusinessEvent.put("enabled", false); + defaults.add(loanUndoDisbursalBusinessEvent); + + Map loanUndoLastDisbursalBusinessEvent = new HashMap<>(); + loanUndoLastDisbursalBusinessEvent.put("type", "LoanUndoLastDisbursalBusinessEvent"); + loanUndoLastDisbursalBusinessEvent.put("enabled", false); + defaults.add(loanUndoLastDisbursalBusinessEvent); + + Map loanUndoWrittenOffBusinessEvent = new HashMap<>(); + loanUndoWrittenOffBusinessEvent.put("type", "LoanUndoWrittenOffBusinessEvent"); + loanUndoWrittenOffBusinessEvent.put("enabled", false); + defaults.add(loanUndoWrittenOffBusinessEvent); + + Map loanUpdateChargeBusinessEvent = new HashMap<>(); + loanUpdateChargeBusinessEvent.put("type", "LoanUpdateChargeBusinessEvent"); + loanUpdateChargeBusinessEvent.put("enabled", false); + defaults.add(loanUpdateChargeBusinessEvent); + + Map loanUpdateDisbursementDataBusinessEvent = new HashMap<>(); + loanUpdateDisbursementDataBusinessEvent.put("type", "LoanUpdateDisbursementDataBusinessEvent"); + loanUpdateDisbursementDataBusinessEvent.put("enabled", false); + defaults.add(loanUpdateDisbursementDataBusinessEvent); + + Map loanWaiveChargeBusinessEvent = new HashMap<>(); + loanWaiveChargeBusinessEvent.put("type", "LoanWaiveChargeBusinessEvent"); + loanWaiveChargeBusinessEvent.put("enabled", false); + defaults.add(loanWaiveChargeBusinessEvent); + + Map loanWaiveChargeUndoBusinessEvent = new HashMap<>(); + loanWaiveChargeUndoBusinessEvent.put("type", "LoanWaiveChargeUndoBusinessEvent"); + loanWaiveChargeUndoBusinessEvent.put("enabled", false); + defaults.add(loanWaiveChargeUndoBusinessEvent); + + Map loanWaiveInterestBusinessEvent = new HashMap<>(); + loanWaiveInterestBusinessEvent.put("type", "LoanWaiveInterestBusinessEvent"); + loanWaiveInterestBusinessEvent.put("enabled", false); + defaults.add(loanWaiveInterestBusinessEvent); + + Map loanWithdrawTransferBusinessEvent = new HashMap<>(); + loanWithdrawTransferBusinessEvent.put("type", "LoanWithdrawTransferBusinessEvent"); + loanWithdrawTransferBusinessEvent.put("enabled", false); + defaults.add(loanWithdrawTransferBusinessEvent); + + Map loanWrittenOffPostBusinessEvent = new HashMap<>(); + loanWrittenOffPostBusinessEvent.put("type", "LoanWrittenOffPostBusinessEvent"); + loanWrittenOffPostBusinessEvent.put("enabled", false); + defaults.add(loanWrittenOffPostBusinessEvent); + + Map loanWrittenOffPreBusinessEvent = new HashMap<>(); + loanWrittenOffPreBusinessEvent.put("type", "LoanWrittenOffPreBusinessEvent"); + loanWrittenOffPreBusinessEvent.put("enabled", false); + defaults.add(loanWrittenOffPreBusinessEvent); + + Map recurringDepositAccountCreateBusinessEvent = new HashMap<>(); + recurringDepositAccountCreateBusinessEvent.put("type", "RecurringDepositAccountCreateBusinessEvent"); + recurringDepositAccountCreateBusinessEvent.put("enabled", false); + defaults.add(recurringDepositAccountCreateBusinessEvent); + + Map savingsActivateBusinessEvent = new HashMap<>(); + savingsActivateBusinessEvent.put("type", "SavingsActivateBusinessEvent"); + savingsActivateBusinessEvent.put("enabled", false); + defaults.add(savingsActivateBusinessEvent); + + Map savingsApproveBusinessEvent = new HashMap<>(); + savingsApproveBusinessEvent.put("type", "SavingsApproveBusinessEvent"); + savingsApproveBusinessEvent.put("enabled", false); + defaults.add(savingsApproveBusinessEvent); + + Map savingsCloseBusinessEvent = new HashMap<>(); + savingsCloseBusinessEvent.put("type", "SavingsCloseBusinessEvent"); + savingsCloseBusinessEvent.put("enabled", false); + defaults.add(savingsCloseBusinessEvent); + + Map savingsCreateBusinessEvent = new HashMap<>(); + savingsCreateBusinessEvent.put("type", "SavingsCreateBusinessEvent"); + savingsCreateBusinessEvent.put("enabled", false); + defaults.add(savingsCreateBusinessEvent); + + Map savingsDepositBusinessEvent = new HashMap<>(); + savingsDepositBusinessEvent.put("type", "SavingsDepositBusinessEvent"); + savingsDepositBusinessEvent.put("enabled", false); + defaults.add(savingsDepositBusinessEvent); + + Map savingsPostInterestBusinessEvent = new HashMap<>(); + savingsPostInterestBusinessEvent.put("type", "SavingsPostInterestBusinessEvent"); + savingsPostInterestBusinessEvent.put("enabled", false); + defaults.add(savingsPostInterestBusinessEvent); + + Map savingsRejectBusinessEvent = new HashMap<>(); + savingsRejectBusinessEvent.put("type", "SavingsRejectBusinessEvent"); + savingsRejectBusinessEvent.put("enabled", false); + defaults.add(savingsRejectBusinessEvent); + + Map savingsWithdrawalBusinessEvent = new HashMap<>(); + savingsWithdrawalBusinessEvent.put("type", "SavingsWithdrawalBusinessEvent"); + savingsWithdrawalBusinessEvent.put("enabled", false); + defaults.add(savingsWithdrawalBusinessEvent); + + Map shareAccountApproveBusinessEvent = new HashMap<>(); + shareAccountApproveBusinessEvent.put("type", "ShareAccountApproveBusinessEvent"); + shareAccountApproveBusinessEvent.put("enabled", false); + defaults.add(shareAccountApproveBusinessEvent); + + Map shareAccountCreateBusinessEvent = new HashMap<>(); + shareAccountCreateBusinessEvent.put("type", "ShareAccountCreateBusinessEvent"); + shareAccountCreateBusinessEvent.put("enabled", false); + defaults.add(shareAccountCreateBusinessEvent); + + Map shareProductDividentsCreateBusinessEvent = new HashMap<>(); + shareProductDividentsCreateBusinessEvent.put("type", "ShareProductDividentsCreateBusinessEvent"); + shareProductDividentsCreateBusinessEvent.put("enabled", false); + defaults.add(shareProductDividentsCreateBusinessEvent); + + return defaults; + + } + + public static String getExternalEventConfigurationsForUpdateJSON() { + + Map> configurationsForUpdate = new HashMap<>(); + + Map configurations = new HashMap<>(); + + configurations.put("CentersCreateBusinessEvent", true); + configurations.put("ClientActivateBusinessEvent", true); + + configurationsForUpdate.put("externalEventConfigurations", configurations); + + return new Gson().toJson(configurationsForUpdate); + + } + + public static Map updateExternalEventConfigurations(RequestSpecification requestSpec, + ResponseSpecification responseSpec, String json) { + Map> response = Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_EVENT_CONFIGURATION_URL, + json, "changes"); + return response.get(EXTERNAL_EVENT_CONFIGURATION_RESPONSE); + } + + public static void resetDefaultConfigurations(RequestSpecification requestSpec, ResponseSpecification responseSpec) { + Map> configurationsForReset = new HashMap<>(); + + Map configurations = new HashMap<>(); + + configurations.put("CentersCreateBusinessEvent", false); + configurations.put("ClientActivateBusinessEvent", false); + + configurationsForReset.put("externalEventConfigurations", configurations); + + String jsonForResettingConfigurations = new Gson().toJson(configurationsForReset); + Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_EVENT_CONFIGURATION_URL, jsonForResettingConfigurations, ""); + + } +}