Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKING_DAYS")
// client address (template before wildcard for specificity)
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/addresses/template"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/client/*/addresses"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_ADDRESS")
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/client/*/addresses"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_ADDRESS")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/client/*/addresses"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_ADDRESS")
// interest rate chart slabs (before charts for specificity)
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*/chartslabs"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CHARTSLAB")
Expand Down
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
Expand Up @@ -16,33 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.client.api;
package org.apache.fineract.portfolio.address.data;

import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;

/**
* Created by Chirag Gupta on 01/12/18.
*/
@SuppressWarnings({ "MemberName" })
final class ClientAddressApiResourcesSwagger {

private ClientAddressApiResourcesSwagger() {}

@Schema(description = "PostClientClientIdAddressesResponse")
public static final class PostClientClientIdAddressesResponse {

private PostClientClientIdAddressesResponse() {}

@Schema(example = "15")
public Long resourceId;
}

@Schema(description = "PutClientClientIdAddressesResponse")
public static final class PutClientClientIdAddressesResponse {
@Data
@Builder
public class ClientAddressCreateResponse implements Serializable {

private PutClientClientIdAddressesResponse() {}
@Serial
private static final long serialVersionUID = 1L;

@Schema(example = "67")
public Long resourceId;
}
private Long resourceId;
}
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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ClientAddressCreateRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


private final ClientAddressWriteService writePlatformService;

@Retry(name = "commandClientAddressCreate", fallbackMethod = "fallback")
@Override
@Transactional
public ClientAddressCreateResponse handle(Command<ClientAddressRequest> command) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientAddressUpdateRequest


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
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ClientAddressReadService?


List<AddressData> retrieveAddressFields(long clientid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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""";

}

Expand Down Expand Up @@ -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=?";

Expand All @@ -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=?";

Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading