-
Notifications
You must be signed in to change notification settings - Fork 2.4k
FINERACT-2293: Migrate client address module to new command pipeline #5657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * 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.portfolio.address.command; | ||
|
|
||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import org.apache.fineract.command.core.Command; | ||
| import org.apache.fineract.portfolio.client.data.ClientAddressRequest; | ||
|
|
||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class ClientAddressCreateCommand extends Command<ClientAddressRequest> {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * 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.portfolio.address.command; | ||
|
|
||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import org.apache.fineract.command.core.Command; | ||
| import org.apache.fineract.portfolio.client.data.ClientAddressRequest; | ||
|
|
||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class ClientAddressUpdateCommand extends Command<ClientAddressRequest> {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * 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.portfolio.address.data; | ||
|
|
||
| import java.io.Serial; | ||
| import java.io.Serializable; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class ClientAddressUpdateResponse implements Serializable { | ||
|
|
||
| @Serial | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private Long resourceId; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * 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.portfolio.address.handler; | ||
|
|
||
| import io.github.resilience4j.retry.annotation.Retry; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.fineract.command.core.Command; | ||
| import org.apache.fineract.command.core.CommandHandler; | ||
| import org.apache.fineract.portfolio.address.data.ClientAddressCreateResponse; | ||
| import org.apache.fineract.portfolio.address.service.ClientAddressWriteService; | ||
| import org.apache.fineract.portfolio.client.data.ClientAddressRequest; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class ClientAddressCreateCommandHandler implements CommandHandler<ClientAddressRequest, ClientAddressCreateResponse> { | ||
|
|
||
| private final ClientAddressWriteService writePlatformService; | ||
|
|
||
| @Retry(name = "commandClientAddressCreate", fallbackMethod = "fallback") | ||
| @Override | ||
| @Transactional | ||
| public ClientAddressCreateResponse handle(Command<ClientAddressRequest> command) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment |
||
| return writePlatformService.createClientAddress(command.getPayload()); | ||
| } | ||
|
|
||
| @Override | ||
| public ClientAddressCreateResponse fallback(Command<ClientAddressRequest> command, Throwable t) { | ||
| return CommandHandler.super.fallback(command, t); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * 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.portfolio.address.handler; | ||
|
|
||
| import io.github.resilience4j.retry.annotation.Retry; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.fineract.command.core.Command; | ||
| import org.apache.fineract.command.core.CommandHandler; | ||
| import org.apache.fineract.portfolio.address.data.ClientAddressUpdateResponse; | ||
| import org.apache.fineract.portfolio.address.service.ClientAddressWriteService; | ||
| import org.apache.fineract.portfolio.client.data.ClientAddressRequest; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class ClientAddressUpdateCommandHandler implements CommandHandler<ClientAddressRequest, ClientAddressUpdateResponse> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private final ClientAddressWriteService writePlatformService; | ||
|
|
||
| @Retry(name = "commandClientAddressUpdate", fallbackMethod = "fallback") | ||
| @Override | ||
| @Transactional | ||
| public ClientAddressUpdateResponse handle(Command<ClientAddressRequest> command) { | ||
| return writePlatformService.updateClientAddress(command.getPayload()); | ||
| } | ||
|
|
||
| @Override | ||
| public ClientAddressUpdateResponse fallback(Command<ClientAddressRequest> command, Throwable t) { | ||
| return CommandHandler.super.fallback(command, t); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| import org.apache.fineract.portfolio.address.data.AddressData; | ||
| import org.apache.fineract.portfolio.address.filter.ClientAddressSearchParam; | ||
|
|
||
| public interface AddressReadPlatformService { | ||
| public interface AddressReadService { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
|
|
||
| List<AddressData> retrieveAddressFields(long clientid); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,29 +28,30 @@ | |
| import org.apache.fineract.infrastructure.codes.data.CodeValueData; | ||
| import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; | ||
| import org.apache.fineract.infrastructure.core.component.FetcherRule; | ||
| import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; | ||
| import org.apache.fineract.portfolio.address.data.AddressData; | ||
| import org.apache.fineract.portfolio.address.filter.ClientAddressSearchParam; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.jdbc.core.RowMapper; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AddressReadPlatformServiceImpl implements AddressReadPlatformService { | ||
| public class AddressReadServiceImpl implements AddressReadService { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment |
||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
| private final PlatformSecurityContext context; | ||
| private final CodeValueReadPlatformService readService; | ||
|
|
||
| private static final class AddFieldsMapper implements RowMapper<AddressData> { | ||
|
|
||
| public String schema() { | ||
| 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," | ||
| + "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district," | ||
| + "addr.state_province_id as state_province_id, addr.country_id as country_id,addr.postal_code as postal_code,addr.latitude as latitude," | ||
| + "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by," | ||
| + "addr.updated_on as updated_on from m_address as addr,m_client client"; | ||
| 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,\ | ||
| addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,\ | ||
| addr.county_district as county_district,\ | ||
| addr.state_province_id as state_province_id, addr.country_id as country_id,\ | ||
| addr.postal_code as postal_code,addr.latitude as latitude,\ | ||
| addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,\ | ||
| addr.updated_by as updated_by,\ | ||
| addr.updated_on as updated_on from m_address as addr,m_client client"""; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -101,13 +102,22 @@ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final | |
| private static final class AddMapper implements RowMapper<AddressData> { | ||
|
|
||
| public String schema() { | ||
| 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," | ||
| + "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district," | ||
| + "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," | ||
| + "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by," | ||
| + "addr.updated_on as updated_on" + " from m_address addr left join m_code_value cv on addr.state_province_id=cv.id" | ||
| + " left join m_code_value c on addr.country_id=c.id" + " join m_client_address ca on addr.id= ca.address_id" | ||
| + " join m_code_value cv2 on ca.address_type_id=cv2.id"; | ||
| 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,\ | ||
| addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,\ | ||
| addr.county_district as county_district,\ | ||
| 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,\ | ||
| addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,\ | ||
| addr.updated_by as updated_by,\ | ||
| addr.updated_on as updated_on\ | ||
| from m_address addr left join m_code_value cv on addr.state_province_id=cv.id\ | ||
| left join m_code_value c on addr.country_id=c.id\ | ||
| join m_client_address ca on addr.id= ca.address_id\ | ||
| join m_code_value cv2 on ca.address_type_id=cv2.id"""; | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -172,8 +182,6 @@ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final | |
|
|
||
| @Override | ||
| public List<AddressData> retrieveAddressFields(final long clientid) { | ||
| this.context.authenticatedUser(); | ||
|
|
||
| final AddFieldsMapper rm = new AddFieldsMapper(); | ||
| final String sql = "select " + rm.schema() + " where client.id=?"; | ||
|
|
||
|
|
@@ -182,16 +190,13 @@ public List<AddressData> retrieveAddressFields(final long clientid) { | |
|
|
||
| @Override | ||
| public List<AddressData> retrieveAllClientAddress(final long clientid) { | ||
| this.context.authenticatedUser(); | ||
| final AddMapper rm = new AddMapper(); | ||
| final String sql = "select " + rm.schema() + " and ca.client_id=?"; | ||
| return this.jdbcTemplate.query(sql, rm, new Object[] { clientid }); // NOSONAR | ||
| } | ||
|
|
||
| @Override | ||
| public List<AddressData> retrieveAddressbyType(final long clientid, final long typeid) { | ||
| this.context.authenticatedUser(); | ||
|
|
||
| final AddMapper rm = new AddMapper(); | ||
| final String sql = "select " + rm.schema() + " and ca.client_id=? and ca.address_type_id=?"; | ||
|
|
||
|
|
@@ -200,7 +205,6 @@ public List<AddressData> retrieveAddressbyType(final long clientid, final long t | |
|
|
||
| @Override | ||
| public List<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, final long typeid, final String status) { | ||
| this.context.authenticatedUser(); | ||
| boolean temp = Boolean.parseBoolean(status); | ||
|
|
||
| final AddMapper rm = new AddMapper(); | ||
|
|
@@ -211,7 +215,6 @@ public List<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, fin | |
|
|
||
| @Override | ||
| public List<AddressData> retrieveAddressbyStatus(final long clientid, final String status) { | ||
| this.context.authenticatedUser(); | ||
| boolean temp = Boolean.parseBoolean(status); | ||
|
|
||
| final AddMapper rm = new AddMapper(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
ClientAddressCreateRequest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done