Skip to content

Commit b9c6178

Browse files
committed
FINERACT-2293: Migrate client address module to new command pipeline
1 parent 86a1323 commit b9c6178

22 files changed

Lines changed: 652 additions & 464 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
@@ -329,6 +329,15 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
329329
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
330330
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
331331
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKING_DAYS")
332+
// client address (template before wildcard for specificity)
333+
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/addresses/template"))
334+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
335+
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/*/addresses"))
336+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
337+
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/client/*/addresses"))
338+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_ADDRESS")
339+
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/client/*/addresses"))
340+
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_ADDRESS")
332341
// interest rate chart slabs (before charts for specificity)
333342
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*/chartslabs"))
334343
.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.ClientAddressCreateRequest;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class ClientAddressCreateCommand extends Command<ClientAddressCreateRequest> {}
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.ClientAddressUpdateRequest;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class ClientAddressUpdateCommand extends Command<ClientAddressUpdateRequest> {}

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.ClientAddressCreateRequest;
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<ClientAddressCreateRequest, ClientAddressCreateResponse> {
36+
37+
private final ClientAddressWriteService writePlatformService;
38+
39+
@Retry(name = "commandClientAddressCreate", fallbackMethod = "fallback")
40+
@Override
41+
@Transactional
42+
public ClientAddressCreateResponse handle(Command<ClientAddressCreateRequest> command) {
43+
return writePlatformService.createClientAddress(command.getPayload());
44+
}
45+
46+
@Override
47+
public ClientAddressCreateResponse fallback(Command<ClientAddressCreateRequest> 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.ClientAddressUpdateRequest;
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<ClientAddressUpdateRequest, ClientAddressUpdateResponse> {
36+
37+
private final ClientAddressWriteService writePlatformService;
38+
39+
@Retry(name = "commandClientAddressUpdate", fallbackMethod = "fallback")
40+
@Override
41+
@Transactional
42+
public ClientAddressUpdateResponse handle(Command<ClientAddressUpdateRequest> command) {
43+
return writePlatformService.updateClientAddress(command.getPayload());
44+
}
45+
46+
@Override
47+
public ClientAddressUpdateResponse fallback(Command<ClientAddressUpdateRequest> command, Throwable t) {
48+
return CommandHandler.super.fallback(command, t);
49+
}
50+
}

0 commit comments

Comments
 (0)