Skip to content

Commit 11eaa9c

Browse files
FINERACT-2247: Refactor currency api for new concept;
1 parent 8d83b55 commit 11eaa9c

File tree

21 files changed

+317
-184
lines changed

21 files changed

+317
-184
lines changed

fineract-core/src/main/java/org/apache/fineract/organisation/monetary/serialization/CurrencyCommandFromApiJsonDeserializer.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/initializer/global/CurrencyGlobalInitializerStep.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import lombok.RequiredArgsConstructor;
2424
import org.apache.fineract.client.models.CurrencyRequest;
25-
import org.apache.fineract.client.models.PutCurrenciesResponse;
25+
import org.apache.fineract.client.models.CurrencyResponse;
2626
import org.apache.fineract.client.services.CurrencyApi;
2727
import org.apache.fineract.test.support.TestContext;
2828
import org.apache.fineract.test.support.TestContextKey;
@@ -43,8 +43,7 @@ public class CurrencyGlobalInitializerStep implements FineractGlobalInitializerS
4343
@Override
4444
public void initialize() throws Exception {
4545
CurrencyRequest currencyRequest = new CurrencyRequest();
46-
Response<PutCurrenciesResponse> putCurrenciesResponse = currencyApi.updateCurrencies(currencyRequest.currencies(CURRENCIES))
47-
.execute();
46+
Response<CurrencyResponse> putCurrenciesResponse = currencyApi.updateCurrencies(currencyRequest.currencies(CURRENCIES)).execute();
4847
TestContext.INSTANCE.set(TestContextKey.PUT_CURRENCIES_RESPONSE, putCurrenciesResponse);
4948
}
5049
}

fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
130130
.requestMatchers(antMatcher(HttpMethod.POST, "/api/*/self/registration")).permitAll() //
131131
.requestMatchers(antMatcher(HttpMethod.POST, "/api/*/self/registration/user")).permitAll() //
132132
.requestMatchers(antMatcher(HttpMethod.PUT, "/api/*/instance-mode")).permitAll() //
133+
.requestMatchers(antMatcher(HttpMethod.GET, "/api/*/currencies"))
134+
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "READ_CURRENCY") //
133135
.requestMatchers(antMatcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated() //
134136
.requestMatchers(antMatcher("/api/*/twofactor")).fullyAuthenticated() //
135137
.requestMatchers(antMatcher("/api/**"))

fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanDelinquencyRangeChangeBusinessEventSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
import org.apache.fineract.infrastructure.core.service.DateUtils;
3333
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
3434
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanDelinquencyRangeChangeBusinessEvent;
35-
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.generic.CurrencyDataMapper;
3635
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanChargeDataMapper;
3736
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanDelinquencyRangeDataMapper;
3837
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroDateTimeMapper;
3938
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.AbstractBusinessEventWithCustomDataSerializer;
4039
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
4140
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
41+
import org.apache.fineract.organisation.monetary.mapping.CurrencyDataMapper;
4242
import org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService;
4343
import org.apache.fineract.portfolio.loanaccount.data.CollectionData;
4444
import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData;

fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanInstallmentLevelDelinquencyEventProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.apache.fineract.avro.loan.v1.LoanChargeDataRangeViewV1;
3131
import org.apache.fineract.avro.loan.v1.LoanInstallmentDelinquencyBucketDataV1;
3232
import org.apache.fineract.infrastructure.core.service.DateUtils;
33-
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.generic.CurrencyDataMapper;
3433
import org.apache.fineract.organisation.monetary.data.CurrencyData;
34+
import org.apache.fineract.organisation.monetary.mapping.CurrencyDataMapper;
3535
import org.apache.fineract.portfolio.delinquency.data.LoanInstallmentDelinquencyTagData;
3636
import org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService;
3737
import org.apache.fineract.portfolio.loanaccount.domain.Loan;

fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/api/CurrenciesApiResource.java

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,26 @@
1919
package org.apache.fineract.organisation.monetary.api;
2020

2121
import io.swagger.v3.oas.annotations.Operation;
22-
import io.swagger.v3.oas.annotations.Parameter;
23-
import io.swagger.v3.oas.annotations.media.Content;
24-
import io.swagger.v3.oas.annotations.media.Schema;
25-
import io.swagger.v3.oas.annotations.parameters.RequestBody;
26-
import io.swagger.v3.oas.annotations.responses.ApiResponse;
27-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2822
import io.swagger.v3.oas.annotations.tags.Tag;
23+
import jakarta.validation.Valid;
2924
import jakarta.ws.rs.Consumes;
3025
import jakarta.ws.rs.GET;
26+
import jakarta.ws.rs.HeaderParam;
3127
import jakarta.ws.rs.PUT;
3228
import jakarta.ws.rs.Path;
3329
import jakarta.ws.rs.Produces;
3430
import jakarta.ws.rs.core.MediaType;
31+
import java.util.UUID;
32+
import java.util.function.Supplier;
3533
import lombok.RequiredArgsConstructor;
36-
import org.apache.fineract.commands.domain.CommandWrapper;
37-
import org.apache.fineract.commands.service.CommandWrapperBuilder;
38-
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
39-
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
40-
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
41-
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
34+
import org.apache.fineract.command.core.CommandPipeline;
35+
import org.apache.fineract.infrastructure.core.service.DateUtils;
36+
import org.apache.fineract.organisation.monetary.command.UpdateCurrencyCommand;
4237
import org.apache.fineract.organisation.monetary.data.ApplicationCurrencyConfigurationData;
43-
import org.apache.fineract.organisation.monetary.data.request.CurrencyRequest;
38+
import org.apache.fineract.organisation.monetary.data.CurrencyRequest;
39+
import org.apache.fineract.organisation.monetary.data.CurrencyResponse;
40+
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateResultDto;
41+
import org.apache.fineract.organisation.monetary.mapping.CurrencyUpdateMapper;
4442
import org.apache.fineract.organisation.monetary.service.OrganisationCurrencyReadPlatformService;
4543
import org.springframework.stereotype.Component;
4644

@@ -50,39 +48,30 @@
5048
@RequiredArgsConstructor
5149
public class CurrenciesApiResource {
5250

53-
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "CURRENCY";
54-
55-
private final PlatformSecurityContext context;
5651
private final OrganisationCurrencyReadPlatformService readPlatformService;
57-
private final DefaultToApiJsonSerializer<ApplicationCurrencyConfigurationData> toApiJsonSerializer;
58-
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
52+
private final CommandPipeline commandPipeline;
53+
private final CurrencyUpdateMapper currencyUpdateMapper;
5954

6055
@GET
6156
@Consumes({ MediaType.APPLICATION_JSON })
6257
@Produces({ MediaType.APPLICATION_JSON })
6358
@Operation(summary = "Retrieve Currency Configuration", description = "Returns the list of currencies permitted for use AND the list of currencies not selected (but available for selection).\n"
6459
+ "\n" + "Example Requests:\n" + "\n" + "currencies\n" + "\n" + "\n" + "currencies?fields=selectedCurrencyOptions")
6560
public ApplicationCurrencyConfigurationData retrieveCurrencies() {
66-
67-
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
68-
6961
return this.readPlatformService.retrieveCurrencyConfiguration();
7062
}
7163

7264
@PUT
7365
@Consumes({ MediaType.APPLICATION_JSON })
7466
@Produces({ MediaType.APPLICATION_JSON })
7567
@Operation(summary = "Update Currency Configuration", description = "Updates the list of currencies permitted for use.")
76-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CurrencyRequest.class)))
77-
@ApiResponses({
78-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CurrenciesApiResourceSwagger.PutCurrenciesResponse.class))) })
79-
public CommandProcessingResult updateCurrencies(@Parameter(hidden = true) CurrencyRequest currencyRequest) {
80-
81-
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
82-
.updateCurrencies() //
83-
.withJson(toApiJsonSerializer.serialize(currencyRequest)) //
84-
.build();
68+
public CurrencyResponse updateCurrencies(@HeaderParam("Idempotency-Key") @Valid CurrencyRequest currencyRequest) {
69+
var commandUpdate = new UpdateCurrencyCommand();
70+
commandUpdate.setId(UUID.randomUUID());
71+
commandUpdate.setCreatedAt(DateUtils.getAuditOffsetDateTime());
72+
commandUpdate.setPayload(currencyUpdateMapper.map(currencyRequest));
8573

86-
return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
74+
final Supplier<CurrencyUpdateResultDto> result = commandPipeline.send(commandUpdate);
75+
return currencyUpdateMapper.map(result.get());
8776
}
8877
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.organisation.monetary.command;
20+
21+
import lombok.Data;
22+
import lombok.EqualsAndHashCode;
23+
import org.apache.fineract.command.core.Command;
24+
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateDto;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class UpdateCurrencyCommand extends Command<CurrencyUpdateDto> {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.organisation.monetary.data;
20+
21+
import java.util.List;
22+
import lombok.AllArgsConstructor;
23+
import lombok.Builder;
24+
import lombok.Data;
25+
import lombok.NoArgsConstructor;
26+
27+
@Builder
28+
@Data
29+
@NoArgsConstructor
30+
@AllArgsConstructor
31+
public class CurrencyChangeDto {
32+
33+
private List<String> currencies;
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.organisation.monetary.data;
20+
21+
import jakarta.validation.constraints.NotEmpty;
22+
import java.io.Serial;
23+
import java.io.Serializable;
24+
import java.util.List;
25+
import lombok.AllArgsConstructor;
26+
import lombok.Builder;
27+
import lombok.Data;
28+
import lombok.NoArgsConstructor;
29+
30+
@Builder
31+
@Data
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class CurrencyRequest implements Serializable {
35+
36+
@Serial
37+
private static final long serialVersionUID = 1L;
38+
39+
@NotEmpty(message = "${org.apache.fineract.organisation.monetary.data.currencyRequest.currencies.not.empty}")
40+
private List<String> currencies;
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.organisation.monetary.data;
20+
21+
import java.io.Serial;
22+
import java.io.Serializable;
23+
import lombok.AllArgsConstructor;
24+
import lombok.Builder;
25+
import lombok.Data;
26+
import lombok.NoArgsConstructor;
27+
28+
@Builder
29+
@Data
30+
@NoArgsConstructor
31+
@AllArgsConstructor
32+
public class CurrencyResponse implements Serializable {
33+
34+
@Serial
35+
private static final long serialVersionUID = 1L;
36+
37+
private CurrencyChangeDto changes;
38+
}

0 commit comments

Comments
 (0)