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 @@ -365,15 +365,6 @@ public CommandWrapperBuilder updateCreditBureauConfiguration(final long configur
return this;
}

public CommandWrapperBuilder addClientAddress(final long clientId, final long addressTypeId) {
this.actionName = ACTION_CREATE;
this.entityName = ENTITY_ADDRESS;
this.entityId = addressTypeId;
this.href = "/clients/" + clientId + "/addresses";
this.clientId = clientId;
return this;
}

public CommandWrapperBuilder updateClientAddress(final long clientId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_ADDRESS;
Expand Down
2 changes: 2 additions & 0 deletions fineract-provider/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies {
implementation(project(path: ':fineract-security'))
implementation(project(path: ':fineract-working-capital-loan'))
implementation(project(path: ':fineract-mix'))
implementation 'org.mapstruct:mapstruct'
annotationProcessor 'org.mapstruct:mapstruct-processor'

providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_HOOK")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/hooks/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_HOOK")

// template
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/templates/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_TEMPLATE")
Expand All @@ -413,6 +414,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/standinginstructionrunhistory"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_STANDINGINSTRUCTION")

// client address
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/client/*/addresses"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_ADDRESS")

.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/**")).access(allOfRequestManagers(authorizationManagers));
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.address.data.AddressCreateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class AddressCreateCommand extends Command<AddressCreateRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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 com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public class AddressCreateRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@JsonIgnore
@NotNull(message = "{org.apache.fineract.portfolio.address.create.assertion.client-id-required}")
@Positive(message = "{org.apache.fineract.portfolio.address.create.assertion.client-id-positive}")
private Long clientId;

@JsonIgnore
@NotNull(message = "{org.apache.fineract.portfolio.address.create.assertion.address-type-id-required}")
@Positive(message = "{org.apache.fineract.portfolio.address.create.assertion.address-type-id-positive}")
private Long addressTypeId;

@Size(max = 100)
private String city;

private Long countryId;

private Boolean isActive;

@Size(max = 20)
private String postalCode;

@Size(max = 100)
private String addressLine1;

@Size(max = 100)
private String addressLine2;

@Size(max = 100)
private String addressLine3;

@Size(max = 100)
private String townVillage;

@Size(max = 100)
private String countyDistrict;

private Long stateProvinceId;

private BigDecimal latitude;

private BigDecimal longitude;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AddressCreateResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long resourceId;
private Long clientId;
}
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.AddressCreateRequest;
import org.apache.fineract.portfolio.address.data.AddressCreateResponse;
import org.apache.fineract.portfolio.address.service.AddressDomainService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RequiredArgsConstructor
public class AddressCreateCommandHandler implements CommandHandler<AddressCreateRequest, AddressCreateResponse> {

private final AddressDomainService domainService;

@Retry(name = "commandAddressCreate", fallbackMethod = "fallback")
@Override
@Transactional
public AddressCreateResponse handle(Command<AddressCreateRequest> command) {
return domainService.create(command.getPayload());
}

@Override
public AddressCreateResponse fallback(Command<AddressCreateRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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.mapper;

import org.apache.fineract.portfolio.address.data.AddressCreateRequest;
import org.apache.fineract.portfolio.address.domain.Address;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface AddressMapper {

@Mapping(target = "id", ignore = true)
@Mapping(target = "clientaddress", ignore = true)
@Mapping(target = "stateProvince", ignore = true)
@Mapping(target = "country", ignore = true)
@Mapping(target = "createdBy", ignore = true)
@Mapping(target = "createdOn", ignore = true)
@Mapping(target = "updatedBy", ignore = true)
@Mapping(target = "updatedOn", ignore = true)
@Mapping(target = "street", ignore = true)
Address toAddress(AddressCreateRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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.service;

import org.apache.fineract.portfolio.address.data.AddressCreateRequest;
import org.apache.fineract.portfolio.address.data.AddressCreateResponse;

public interface AddressDomainService {

AddressCreateResponse create(AddressCreateRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* 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.service;

import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.address.data.AddressCreateRequest;
import org.apache.fineract.portfolio.address.data.AddressCreateResponse;
import org.apache.fineract.portfolio.address.domain.Address;
import org.apache.fineract.portfolio.address.domain.AddressRepository;
import org.apache.fineract.portfolio.address.mapper.AddressMapper;
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.portfolio.client.domain.ClientAddress;
import org.apache.fineract.portfolio.client.domain.ClientAddressRepository;
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnMissingBean(value = AddressDomainService.class, ignored = AddressDomainServiceImpl.class)
public class AddressDomainServiceImpl implements AddressDomainService {

private final AddressRepository addressRepository;
private final ClientAddressRepository clientAddressRepository;
private final ClientRepositoryWrapper clientRepositoryWrapper;
private final CodeValueRepository codeValueRepository;
private final AddressMapper addressMapper;

@Override
@Transactional
public AddressCreateResponse create(final AddressCreateRequest request) {
final Client client = clientRepositoryWrapper.findOneWithNotFoundDetection(request.getClientId());
final CodeValue addressTypeIdCodeValue = codeValueRepository.getReferenceById(request.getAddressTypeId());

CodeValue stateIdCodeValue = null;
if (request.getStateProvinceId() != null) {
stateIdCodeValue = codeValueRepository.getReferenceById(request.getStateProvinceId());
}

CodeValue countryIdCodeValue = null;
if (request.getCountryId() != null) {
countryIdCodeValue = codeValueRepository.getReferenceById(request.getCountryId());
}

final Address address = addressMapper.toAddress(request);
address.setStateProvince(stateIdCodeValue);
address.setCountry(countryIdCodeValue);
address.setCreatedOn(LocalDate.now(DateUtils.getDateTimeZoneOfTenant()));
address.setUpdatedOn(LocalDate.now(DateUtils.getDateTimeZoneOfTenant()));
addressRepository.save(address);

final boolean isActive = Boolean.TRUE.equals(request.getIsActive());
final ClientAddress clientAddress = ClientAddress.fromJson(isActive, client, address, addressTypeIdCodeValue);
clientAddressRepository.saveAndFlush(clientAddress);

return AddressCreateResponse.builder().resourceId(clientAddress.getId()).clientId(client.getId()).build();
}
}
Loading