Skip to content

Commit 91c3b39

Browse files
committed
FINERACT-2293: Migrate client address module to new command pipeline
1 parent 23c67f7 commit 91c3b39

21 files changed

Lines changed: 546 additions & 445 deletions

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
327327
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
328328
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
329329
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKING_DAYS")
330+
// client address (template before wildcard for specificity)
331+
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/addresses/template"))
332+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
333+
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/*/addresses"))
334+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
335+
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/client/*/addresses"))
336+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_ADDRESS")
337+
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/client/*/addresses"))
338+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_ADDRESS")
330339
// interest rate chart slabs (before charts for specificity)
331340
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*/chartslabs"))
332341
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CHARTSLAB")
Lines changed: 28 additions & 0 deletions
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.portfolio.address.command;
20+
21+
import lombok.Data;
22+
import lombok.EqualsAndHashCode;
23+
import org.apache.fineract.command.core.Command;
24+
import org.apache.fineract.portfolio.client.data.ClientAddressRequest;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class ClientAddressCreateCommand extends Command<ClientAddressRequest> {}
Lines changed: 28 additions & 0 deletions
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.portfolio.address.command;
20+
21+
import lombok.Data;
22+
import lombok.EqualsAndHashCode;
23+
import org.apache.fineract.command.core.Command;
24+
import org.apache.fineract.portfolio.client.data.ClientAddressRequest;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class ClientAddressUpdateCommand extends Command<ClientAddressRequest> {}

fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResourcesSwagger.java renamed to fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/ClientAddressCreateResponse.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,19 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.fineract.portfolio.client.api;
19+
package org.apache.fineract.portfolio.address.data;
2020

21-
import io.swagger.v3.oas.annotations.media.Schema;
21+
import java.io.Serial;
22+
import java.io.Serializable;
23+
import lombok.Builder;
24+
import lombok.Data;
2225

23-
/**
24-
* Created by Chirag Gupta on 01/12/18.
25-
*/
26-
@SuppressWarnings({ "MemberName" })
27-
final class ClientAddressApiResourcesSwagger {
28-
29-
private ClientAddressApiResourcesSwagger() {}
30-
31-
@Schema(description = "PostClientClientIdAddressesResponse")
32-
public static final class PostClientClientIdAddressesResponse {
33-
34-
private PostClientClientIdAddressesResponse() {}
35-
36-
@Schema(example = "15")
37-
public Long resourceId;
38-
}
39-
40-
@Schema(description = "PutClientClientIdAddressesResponse")
41-
public static final class PutClientClientIdAddressesResponse {
26+
@Data
27+
@Builder
28+
public class ClientAddressCreateResponse implements Serializable {
4229

43-
private PutClientClientIdAddressesResponse() {}
30+
@Serial
31+
private static final long serialVersionUID = 1L;
4432

45-
@Schema(example = "67")
46-
public Long resourceId;
47-
}
33+
private Long resourceId;
4834
}
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.portfolio.address.data;
20+
21+
import java.io.Serial;
22+
import java.io.Serializable;
23+
import lombok.Builder;
24+
import lombok.Data;
25+
26+
@Data
27+
@Builder
28+
public class ClientAddressUpdateResponse implements Serializable {
29+
30+
@Serial
31+
private static final long serialVersionUID = 1L;
32+
33+
private Long resourceId;
34+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.portfolio.address.handler;
20+
21+
import io.github.resilience4j.retry.annotation.Retry;
22+
import lombok.RequiredArgsConstructor;
23+
import lombok.extern.slf4j.Slf4j;
24+
import org.apache.fineract.command.core.Command;
25+
import org.apache.fineract.command.core.CommandHandler;
26+
import org.apache.fineract.portfolio.address.data.ClientAddressCreateResponse;
27+
import org.apache.fineract.portfolio.address.service.ClientAddressWriteService;
28+
import org.apache.fineract.portfolio.client.data.ClientAddressRequest;
29+
import org.springframework.stereotype.Component;
30+
import org.springframework.transaction.annotation.Transactional;
31+
32+
@Slf4j
33+
@Component
34+
@RequiredArgsConstructor
35+
public class ClientAddressCreateCommandHandler implements CommandHandler<ClientAddressRequest, ClientAddressCreateResponse> {
36+
37+
private final ClientAddressWriteService writePlatformService;
38+
39+
@Retry(name = "commandClientAddressCreate", fallbackMethod = "fallback")
40+
@Override
41+
@Transactional
42+
public ClientAddressCreateResponse handle(Command<ClientAddressRequest> command) {
43+
return writePlatformService.createClientAddress(command.getPayload());
44+
}
45+
46+
@Override
47+
public ClientAddressCreateResponse fallback(Command<ClientAddressRequest> command, Throwable t) {
48+
return CommandHandler.super.fallback(command, t);
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.portfolio.address.handler;
20+
21+
import io.github.resilience4j.retry.annotation.Retry;
22+
import lombok.RequiredArgsConstructor;
23+
import lombok.extern.slf4j.Slf4j;
24+
import org.apache.fineract.command.core.Command;
25+
import org.apache.fineract.command.core.CommandHandler;
26+
import org.apache.fineract.portfolio.address.data.ClientAddressUpdateResponse;
27+
import org.apache.fineract.portfolio.address.service.ClientAddressWriteService;
28+
import org.apache.fineract.portfolio.client.data.ClientAddressRequest;
29+
import org.springframework.stereotype.Component;
30+
import org.springframework.transaction.annotation.Transactional;
31+
32+
@Slf4j
33+
@Component
34+
@RequiredArgsConstructor
35+
public class ClientAddressUpdateCommandHandler implements CommandHandler<ClientAddressRequest, ClientAddressUpdateResponse> {
36+
37+
private final ClientAddressWriteService writePlatformService;
38+
39+
@Retry(name = "commandClientAddressUpdate", fallbackMethod = "fallback")
40+
@Override
41+
@Transactional
42+
public ClientAddressUpdateResponse handle(Command<ClientAddressRequest> command) {
43+
return writePlatformService.updateClientAddress(command.getPayload());
44+
}
45+
46+
@Override
47+
public ClientAddressUpdateResponse fallback(Command<ClientAddressRequest> command, Throwable t) {
48+
return CommandHandler.super.fallback(command, t);
49+
}
50+
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformService.java renamed to fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.fineract.portfolio.address.data.AddressData;
2323
import org.apache.fineract.portfolio.address.filter.ClientAddressSearchParam;
2424

25-
public interface AddressReadPlatformService {
25+
public interface AddressReadService {
2626

2727
List<AddressData> retrieveAddressFields(long clientid);
2828

fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java renamed to fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadServiceImpl.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,30 @@
2828
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
2929
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
3030
import org.apache.fineract.infrastructure.core.component.FetcherRule;
31-
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
3231
import org.apache.fineract.portfolio.address.data.AddressData;
3332
import org.apache.fineract.portfolio.address.filter.ClientAddressSearchParam;
3433
import org.springframework.jdbc.core.JdbcTemplate;
3534
import org.springframework.jdbc.core.RowMapper;
36-
import org.springframework.stereotype.Service;
3735

38-
@Service
3936
@RequiredArgsConstructor
40-
public class AddressReadPlatformServiceImpl implements AddressReadPlatformService {
37+
public class AddressReadServiceImpl implements AddressReadService {
4138

4239
private final JdbcTemplate jdbcTemplate;
43-
private final PlatformSecurityContext context;
4440
private final CodeValueReadPlatformService readService;
4541

4642
private static final class AddFieldsMapper implements RowMapper<AddressData> {
4743

4844
public String schema() {
49-
return "addr.id as id,client.id as client_id,addr.street as street,addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,"
50-
+ "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district,"
51-
+ "addr.state_province_id as state_province_id, addr.country_id as country_id,addr.postal_code as postal_code,addr.latitude as latitude,"
52-
+ "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by,"
53-
+ "addr.updated_on as updated_on from m_address as addr,m_client client";
45+
return """
46+
addr.id as id,client.id as client_id,addr.street as street,\
47+
addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,\
48+
addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,\
49+
addr.county_district as county_district,\
50+
addr.state_province_id as state_province_id, addr.country_id as country_id,\
51+
addr.postal_code as postal_code,addr.latitude as latitude,\
52+
addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,\
53+
addr.updated_by as updated_by,\
54+
addr.updated_on as updated_on from m_address as addr,m_client client""";
5455
}
5556

5657
@Override
@@ -101,13 +102,22 @@ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final
101102
private static final class AddMapper implements RowMapper<AddressData> {
102103

103104
public String schema() {
104-
return "cv2.code_value as addressType,ca.client_id as client_id,addr.id as id,ca.address_type_id as addresstyp,ca.is_active as is_active,addr.street as street,addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,"
105-
+ "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district,"
106-
+ "addr.state_province_id as state_province_id,cv.code_value as state_name, addr.country_id as country_id,c.code_value as country_name,addr.postal_code as postal_code,addr.latitude as latitude,"
107-
+ "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by,"
108-
+ "addr.updated_on as updated_on" + " from m_address addr left join m_code_value cv on addr.state_province_id=cv.id"
109-
+ " left join m_code_value c on addr.country_id=c.id" + " join m_client_address ca on addr.id= ca.address_id"
110-
+ " join m_code_value cv2 on ca.address_type_id=cv2.id";
105+
return """
106+
cv2.code_value as addressType,ca.client_id as client_id,addr.id as id,\
107+
ca.address_type_id as addresstyp,ca.is_active as is_active,addr.street as street,\
108+
addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,\
109+
addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,\
110+
addr.county_district as county_district,\
111+
addr.state_province_id as state_province_id,cv.code_value as state_name, \
112+
addr.country_id as country_id,c.code_value as country_name,addr.postal_code as postal_code,\
113+
addr.latitude as latitude,\
114+
addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,\
115+
addr.updated_by as updated_by,\
116+
addr.updated_on as updated_on\
117+
from m_address addr left join m_code_value cv on addr.state_province_id=cv.id\
118+
left join m_code_value c on addr.country_id=c.id\
119+
join m_client_address ca on addr.id= ca.address_id\
120+
join m_code_value cv2 on ca.address_type_id=cv2.id""";
111121

112122
}
113123

@@ -172,8 +182,6 @@ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final
172182

173183
@Override
174184
public List<AddressData> retrieveAddressFields(final long clientid) {
175-
this.context.authenticatedUser();
176-
177185
final AddFieldsMapper rm = new AddFieldsMapper();
178186
final String sql = "select " + rm.schema() + " where client.id=?";
179187

@@ -182,16 +190,13 @@ public List<AddressData> retrieveAddressFields(final long clientid) {
182190

183191
@Override
184192
public List<AddressData> retrieveAllClientAddress(final long clientid) {
185-
this.context.authenticatedUser();
186193
final AddMapper rm = new AddMapper();
187194
final String sql = "select " + rm.schema() + " and ca.client_id=?";
188195
return this.jdbcTemplate.query(sql, rm, new Object[] { clientid }); // NOSONAR
189196
}
190197

191198
@Override
192199
public List<AddressData> retrieveAddressbyType(final long clientid, final long typeid) {
193-
this.context.authenticatedUser();
194-
195200
final AddMapper rm = new AddMapper();
196201
final String sql = "select " + rm.schema() + " and ca.client_id=? and ca.address_type_id=?";
197202

@@ -200,7 +205,6 @@ public List<AddressData> retrieveAddressbyType(final long clientid, final long t
200205

201206
@Override
202207
public List<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, final long typeid, final String status) {
203-
this.context.authenticatedUser();
204208
boolean temp = Boolean.parseBoolean(status);
205209

206210
final AddMapper rm = new AddMapper();
@@ -211,7 +215,6 @@ public List<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, fin
211215

212216
@Override
213217
public List<AddressData> retrieveAddressbyStatus(final long clientid, final String status) {
214-
this.context.authenticatedUser();
215218
boolean temp = Boolean.parseBoolean(status);
216219

217220
final AddMapper rm = new AddMapper();

0 commit comments

Comments
 (0)