FINERACT-2169: Apply dto for external event config api;
This commit is contained in:
committed by
Adam Saghy
parent
9fe993342b
commit
84c101ab14
+9
-29
@@ -23,28 +23,20 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
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 io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.PUT;
|
import jakarta.ws.rs.PUT;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.Context;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.UriInfo;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||||
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
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.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
|
||||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.command.ExternalEventConfigurationCommand;
|
||||||
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationData;
|
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationData;
|
||||||
import org.apache.fineract.infrastructure.event.external.service.ExternalEventConfigurationReadPlatformService;
|
import org.apache.fineract.infrastructure.event.external.service.ExternalEventConfigurationReadPlatformService;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
@@ -56,12 +48,9 @@ import org.springframework.stereotype.Component;
|
|||||||
@Tag(name = "External event configuration", description = "External event configuration enables user to enable/disable event posting to downstream message channel")
|
@Tag(name = "External event configuration", description = "External event configuration enables user to enable/disable event posting to downstream message channel")
|
||||||
public class ExternalEventConfigurationApiResource {
|
public class ExternalEventConfigurationApiResource {
|
||||||
|
|
||||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("type", "enabled"));
|
|
||||||
|
|
||||||
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "EXTERNAL_EVENT_CONFIGURATION";
|
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "EXTERNAL_EVENT_CONFIGURATION";
|
||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
|
||||||
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
|
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
|
||||||
private final DefaultToApiJsonSerializer<ExternalEventConfigurationData> jsonSerializer;
|
private final DefaultToApiJsonSerializer<ExternalEventConfigurationData> jsonSerializer;
|
||||||
private final ExternalEventConfigurationReadPlatformService readPlatformService;
|
private final ExternalEventConfigurationReadPlatformService readPlatformService;
|
||||||
@@ -70,30 +59,21 @@ public class ExternalEventConfigurationApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "List all external event configurations", description = "")
|
@Operation(summary = "List all external event configurations", description = "")
|
||||||
@ApiResponses({
|
public ExternalEventConfigurationData retrieveExternalEventConfiguration() {
|
||||||
@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);
|
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||||
final ExternalEventConfigurationData configurationData = readPlatformService.findAllExternalEventConfigurations();
|
return readPlatformService.findAllExternalEventConfigurations();
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
|
||||||
return jsonSerializer.serialize(settings, configurationData, RESPONSE_DATA_PARAMETERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Enable/Disable external events posting", description = "")
|
@Operation(summary = "Enable/Disable external events posting", description = "")
|
||||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = ExternalEventConfigurationApiResourceSwagger.PutExternalEventConfigurationsRequest.class)))
|
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = ExternalEventConfigurationCommand.class)))
|
||||||
@ApiResponses({
|
public CommandProcessingResult updateExternalEventConfigurationsDetails(
|
||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class))) })
|
@Parameter(hidden = true) ExternalEventConfigurationCommand command) {
|
||||||
public String updateExternalEventConfigurationsDetails(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
|
||||||
context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateExternalEventConfigurations()
|
||||||
.updateExternalEventConfigurations() //
|
.withJson(jsonSerializer.serialize(command)).build();
|
||||||
.withJson(apiRequestBodyAsJson) //
|
return commandWritePlatformService.logCommandSource(commandRequest);
|
||||||
.build();
|
|
||||||
final CommandProcessingResult result = this.commandWritePlatformService.logCommandSource(commandRequest);
|
|
||||||
return this.jsonSerializer.serialize(result);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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<ExternalEventConfigurationItemData> externalEventConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Schema(description = "PutExternalEventConfigurationsRequest")
|
|
||||||
public static final class PutExternalEventConfigurationsRequest {
|
|
||||||
|
|
||||||
private PutExternalEventConfigurationsRequest() {}
|
|
||||||
|
|
||||||
@Schema(example = "\"CentersCreateBusinessEvent\":true,\n" + "\"ClientActivateBusinessEvent\":true")
|
|
||||||
public Map<String, Boolean> externalEventConfigurations;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+6
-6
@@ -18,13 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.event.external.command;
|
package org.apache.fineract.infrastructure.event.external.command;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
public record ExternalEventConfigurationCommand(Map<String, Boolean> externalEventConfigurations) implements Serializable {
|
||||||
@Getter
|
|
||||||
public class ExternalEventConfigurationCommand {
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final Map<String, Boolean> externalEventConfigurations;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ public class ExternalEventConfigurationWritePlatformServiceImpl implements Exter
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult updateConfigurations(final JsonCommand command) {
|
public CommandProcessingResult updateConfigurations(final JsonCommand command) {
|
||||||
final ExternalEventConfigurationCommand configurationCommand = fromApiJsonDeserializer.commandFromApiJson(command.json());
|
final ExternalEventConfigurationCommand configurationCommand = fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||||
final Map<String, Boolean> commandConfigurations = configurationCommand.getExternalEventConfigurations();
|
final Map<String, Boolean> commandConfigurations = configurationCommand.externalEventConfigurations();
|
||||||
final Map<String, Object> changes = new HashMap<>();
|
final Map<String, Object> changes = new HashMap<>();
|
||||||
final Map<String, Boolean> changedConfigurations = new HashMap<>();
|
final Map<String, Boolean> changedConfigurations = new HashMap<>();
|
||||||
final List<ExternalEventConfiguration> modifiedConfigurations = new ArrayList<>();
|
final List<ExternalEventConfiguration> modifiedConfigurations = new ArrayList<>();
|
||||||
|
|||||||
+4
-5
@@ -24,9 +24,9 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.client.models.ExternalEventConfigurationCommand;
|
||||||
|
import org.apache.fineract.client.models.ExternalEventConfigurationData;
|
||||||
import org.apache.fineract.client.models.ExternalEventConfigurationItemData;
|
import org.apache.fineract.client.models.ExternalEventConfigurationItemData;
|
||||||
import org.apache.fineract.client.models.GetExternalEventConfigurationsResponse;
|
|
||||||
import org.apache.fineract.client.models.PutExternalEventConfigurationsRequest;
|
|
||||||
import org.apache.fineract.client.services.ExternalEventConfigurationApi;
|
import org.apache.fineract.client.services.ExternalEventConfigurationApi;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@@ -41,7 +41,7 @@ public class ExternalEventSuiteInitializerStep implements FineractSuiteInitializ
|
|||||||
public void initializeForSuite() throws Exception {
|
public void initializeForSuite() throws Exception {
|
||||||
Map<String, Boolean> eventConfigMap = new HashMap<>();
|
Map<String, Boolean> eventConfigMap = new HashMap<>();
|
||||||
|
|
||||||
Response<GetExternalEventConfigurationsResponse> response = eventConfigurationApi.retrieveExternalEventConfiguration().execute();
|
Response<ExternalEventConfigurationData> response = eventConfigurationApi.retrieveExternalEventConfiguration().execute();
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
String responseBody = response.errorBody().string();
|
String responseBody = response.errorBody().string();
|
||||||
throw new RuntimeException("Cannot configure external events due to " + lineSeparator() + responseBody);
|
throw new RuntimeException("Cannot configure external events due to " + lineSeparator() + responseBody);
|
||||||
@@ -52,8 +52,7 @@ public class ExternalEventSuiteInitializerStep implements FineractSuiteInitializ
|
|||||||
eventConfigMap.put(e.getType(), true);
|
eventConfigMap.put(e.getType(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
PutExternalEventConfigurationsRequest request = new PutExternalEventConfigurationsRequest()
|
ExternalEventConfigurationCommand request = new ExternalEventConfigurationCommand().externalEventConfigurations(eventConfigMap);
|
||||||
.externalEventConfigurations(eventConfigMap);
|
|
||||||
|
|
||||||
eventConfigurationApi.updateExternalEventConfigurationsDetails(request).execute();
|
eventConfigurationApi.updateExternalEventConfigurationsDetails(request).execute();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ import java.util.Map;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.fineract.client.models.CommandProcessingResult;
|
import org.apache.fineract.client.models.CommandProcessingResult;
|
||||||
import org.apache.fineract.client.models.PutExternalEventConfigurationsRequest;
|
import org.apache.fineract.client.models.ExternalEventConfigurationCommand;
|
||||||
import org.apache.fineract.client.util.Calls;
|
import org.apache.fineract.client.util.Calls;
|
||||||
import org.apache.fineract.client.util.JSON;
|
import org.apache.fineract.client.util.JSON;
|
||||||
import org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
|
import org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
|
||||||
@@ -124,7 +124,7 @@ public final class ExternalEventHelper {
|
|||||||
public void configureBusinessEvent(String eventName, boolean enabled) {
|
public void configureBusinessEvent(String eventName, boolean enabled) {
|
||||||
CommandProcessingResult result = Calls
|
CommandProcessingResult result = Calls
|
||||||
.ok(FineractClientHelper.getFineractClient().externalEventConfigurationApi.updateExternalEventConfigurationsDetails(
|
.ok(FineractClientHelper.getFineractClient().externalEventConfigurationApi.updateExternalEventConfigurationsDetails(
|
||||||
new PutExternalEventConfigurationsRequest().putExternalEventConfigurationsItem(eventName, enabled)));
|
new ExternalEventConfigurationCommand().putExternalEventConfigurationsItem(eventName, enabled)));
|
||||||
Map<String, Object> changes = result.getChanges();
|
Map<String, Object> changes = result.getChanges();
|
||||||
Assertions.assertNotNull(changes);
|
Assertions.assertNotNull(changes);
|
||||||
Assertions.assertInstanceOf(Map.class, changes);
|
Assertions.assertInstanceOf(Map.class, changes);
|
||||||
|
|||||||
Reference in New Issue
Block a user