Skip to content
Draft
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 @@ -185,7 +185,6 @@
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_EXTERNALSERVICES;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_EXTERNAL_ASSET_OWNER;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_EXTERNAL_ASSET_OWNER_LOAN_PRODUCT_ATTRIBUTE;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_FAMILYMEMBERS;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_FINANCIALACTIVITYACCOUNT;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_FIXEDDEPOSITACCOUNT;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_FIXEDDEPOSITPRODUCT;
Expand Down Expand Up @@ -382,30 +381,6 @@ public CommandWrapperBuilder updateClientAddress(final long clientId) {
return this;
}

public CommandWrapperBuilder addFamilyMembers(final long clientId) {
this.actionName = ACTION_CREATE;
this.entityName = ENTITY_FAMILYMEMBERS;
this.href = "/clients/" + clientId + "/familymembers";
this.clientId = clientId;
return this;
}

public CommandWrapperBuilder updateFamilyMembers(final long familyMemberId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_FAMILYMEMBERS;
this.href = "/clients/" + clientId + "/familymembers";
this.entityId = familyMemberId;
return this;
}

public CommandWrapperBuilder deleteFamilyMembers(final long familyMemberId) {
this.actionName = ACTION_DELETE;
this.entityName = ENTITY_FAMILYMEMBERS;
this.href = "/clients/" + clientId + "/familymembers";
this.entityId = familyMemberId;
return this;
}

public CommandWrapperBuilder withLoanId(final Long withLoanId) {
this.loanId = withLoanId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fineract.portfolio.client.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
Expand All @@ -32,15 +33,20 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
import org.apache.fineract.command.core.CommandDispatcher;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.client.data.ClientFamilyMemberRequest;
import org.apache.fineract.portfolio.client.command.FamilyMemberCreateCommand;
import org.apache.fineract.portfolio.client.command.FamilyMemberDeleteCommand;
import org.apache.fineract.portfolio.client.command.FamilyMemberUpdateCommand;
import org.apache.fineract.portfolio.client.data.ClientFamilyMembersData;
import org.apache.fineract.portfolio.client.data.FamilyMemberCreateRequest;
import org.apache.fineract.portfolio.client.data.FamilyMemberCreateResponse;
import org.apache.fineract.portfolio.client.data.FamilyMemberDeleteRequest;
import org.apache.fineract.portfolio.client.data.FamilyMemberDeleteResponse;
import org.apache.fineract.portfolio.client.data.FamilyMemberUpdateRequest;
import org.apache.fineract.portfolio.client.data.FamilyMemberUpdateResponse;
import org.apache.fineract.portfolio.client.service.ClientFamilyMembersReadPlatformService;
import org.springframework.stereotype.Component;

Expand All @@ -51,20 +57,18 @@
public class ClientFamilyMembersApiResource {

private static final String RESOURCE_NAME_FOR_PERMISSIONS = "FamilyMembers";

private final PlatformSecurityContext context;
private final ClientFamilyMembersReadPlatformService readPlatformService;
private final ToApiJsonSerializer<ClientFamilyMembersData> toApiJsonSerializer;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final CommandDispatcher dispatcher;

@GET
@Path("/{familyMemberId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a client family member", operationId = "retrieveOneClientFamilyMember")
public ClientFamilyMembersData getFamilyMember(@PathParam("familyMemberId") final Long familyMemberId,
@PathParam("clientId") @Parameter(description = "clientId") final Long clientId) {

this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

return this.readPlatformService.getClientFamilyMember(clientId, familyMemberId);
}

Expand All @@ -85,41 +89,48 @@ public ClientFamilyMembersData getTemplate(@PathParam("clientId") final long cli
return this.readPlatformService.retrieveTemplate();
}

@PUT
@Path("/{familyMemberId}")
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a client family member", operationId = "updateClientFamilyMember")
public CommandProcessingResult updateClientFamilyMembers(@PathParam("familyMemberId") final long familyMemberId,
ClientFamilyMemberRequest clientFamilyMemberRequest,
@PathParam("clientId") @Parameter(description = "clientId") final Long clientId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFamilyMembers(familyMemberId)
.withJson(toApiJsonSerializer.serialize(clientFamilyMemberRequest)).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@Operation(summary = "Add a client family member", operationId = "createClientFamilyMember")
public FamilyMemberCreateResponse addClientFamilyMembers(
@PathParam("clientId") @Parameter(description = "clientId") final Long clientId,
@RequestBody(required = true) @Valid FamilyMemberCreateRequest request) {
request.setClientId(clientId);
final var command = new FamilyMemberCreateCommand();
command.setPayload(request);
final Supplier<FamilyMemberCreateResponse> response = dispatcher.dispatch(command);
return response.get();
}

@POST
@PUT
@Path("/{familyMemberId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Add a client family member", operationId = "createClientFamilyMember")
public CommandProcessingResult addClientFamilyMembers(@PathParam("clientId") final long clientid,
ClientFamilyMemberRequest clientFamilyMemberRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().addFamilyMembers(clientid)
.withJson(toApiJsonSerializer.serialize(clientFamilyMemberRequest)).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@Operation(summary = "Update a client family member", operationId = "updateClientFamilyMember")
public FamilyMemberUpdateResponse updateClientFamilyMembers(
@PathParam("familyMemberId") @Parameter(description = "familyMemberId") final Long familyMemberId,
@PathParam("clientId") @Parameter(description = "clientId") final Long clientId,
@RequestBody(required = true) @Valid FamilyMemberUpdateRequest request) {
request.setId(familyMemberId);
request.setClientId(clientId);
final var command = new FamilyMemberUpdateCommand();
command.setPayload(request);
final Supplier<FamilyMemberUpdateResponse> response = dispatcher.dispatch(command);
return response.get();
}

@DELETE
@Path("/{familyMemberId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a client family member", operationId = "deleteClientFamilyMember")
public CommandProcessingResult deleteClientFamilyMembers(@PathParam("familyMemberId") final long familyMemberId,
public FamilyMemberDeleteResponse deleteClientFamilyMembers(
@PathParam("familyMemberId") @Parameter(description = "familyMemberId") final Long familyMemberId,
@PathParam("clientId") @Parameter(description = "clientId") final Long clientId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteFamilyMembers(familyMemberId).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
final var request = FamilyMemberDeleteRequest.builder().id(familyMemberId).clientId(clientId).build();
final var command = new FamilyMemberDeleteCommand();
command.setPayload(request);
final Supplier<FamilyMemberDeleteResponse> response = dispatcher.dispatch(command);
return response.get();
}

}
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.client.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.client.data.FamilyMemberCreateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class FamilyMemberCreateCommand extends Command<FamilyMemberCreateRequest> {}
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.client.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.client.data.FamilyMemberDeleteRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class FamilyMemberDeleteCommand extends Command<FamilyMemberDeleteRequest> {}
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.client.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.client.data.FamilyMemberUpdateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class FamilyMemberUpdateCommand extends Command<FamilyMemberUpdateRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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.client.data;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Past;
import jakarta.validation.constraints.Positive;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

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

@Serial
private static final long serialVersionUID = 1L;

@Hidden
private Long clientId;

@NotNull(message = "{org.apache.fineract.portfolio.client.familymember.firstname.not-null}")
@Length(max = 100, message = "{org.apache.fineract.portfolio.client.familymember.firstname.max}")
private String firstName;

@Length(max = 100, message = "{org.apache.fineract.portfolio.client.familymember.middlename.max}")
private String middleName;

@NotNull(message = "{org.apache.fineract.portfolio.client.familymember.lastname.not-null}")
@Length(max = 100, message = "{org.apache.fineract.portfolio.client.familymember.lastname.max}")
private String lastName;

@Length(max = 100, message = "{org.apache.fineract.portfolio.client.familymember.qualification.max}")
private String qualification;

@Length(max = 100, message = "{org.apache.fineract.portfolio.client.familymember.mobile-number.max}")
private String mobileNumber;

@Positive(message = "{org.apache.fineract.portfolio.client.familymember.age.positive}")
private Long age;

@JsonProperty("isDependent")
private Boolean isDependent;

@NotNull(message = "{org.apache.fineract.portfolio.client.familymember.relationship-id.not-null}")
@Positive(message = "{org.apache.fineract.portfolio.client.familymember.relationship-id.positive}")
private Long relationshipId;

@Positive(message = "{org.apache.fineract.portfolio.client.familymember.marital-status-id.positive}")
private Long maritalStatusId;

@Positive(message = "{org.apache.fineract.portfolio.client.familymember.gender-id.positive}")
private Long genderId;

@Positive(message = "{org.apache.fineract.portfolio.client.familymember.profession-id.positive}")
private Long professionId;

@Past(message = "{org.apache.fineract.portfolio.client.familymember.date-of-birth.past}")
private LocalDate dateOfBirth;

private String locale;
private String dateFormat;
}
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.client.data;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FamilyMemberCreateResponse {

private Long clientId;
private Long resourceId;
}
Loading
Loading