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 @@ -179,7 +179,6 @@ private CommandWrapperConstants() {}
public static final String ENTITY_CODE = "CODE";
public static final String ENTITY_HOOK = "HOOK";
public static final String ENTITY_CHARGE = "CHARGE";
public static final String ENTITY_COLLATERAL_PRODUCT = "COLLATERAL_PRODUCT";
public static final String ENTITY_LOANPRODUCT = "LOANPRODUCT";
public static final String ENTITY_WORKINGCAPITALLOANPRODUCT = "WORKINGCAPITALLOANPRODUCT";
public static final String ENTITY_WORKINGCAPITALLOAN = "WORKINGCAPITALLOAN";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_CODE;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_CODEVALUE;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_COLLATERAL;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_COLLATERAL_PRODUCT;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_COLLECTIONSHEET;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_CONFIGURATION;
import static org.apache.fineract.commands.domain.CommandWrapperConstants.ENTITY_CREDITBUREAU_CONFIGURATION;
Expand Down Expand Up @@ -704,14 +703,6 @@ public CommandWrapperBuilder createCharge() {
return this;
}

public CommandWrapperBuilder createCollateral() {
this.actionName = ACTION_CREATE;
this.entityId = null;
this.entityName = ENTITY_COLLATERAL_PRODUCT;
this.href = "/collateral-product";
return this;
}

public CommandWrapperBuilder updateCharge(final Long chargeId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_CHARGE;
Expand Down Expand Up @@ -2312,14 +2303,6 @@ public CommandWrapperBuilder updateCollateral(final Long loanId, final Long coll
return this;
}

public CommandWrapperBuilder updateCollateralProduct(final Long collateralId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_COLLATERAL_PRODUCT;
this.entityId = collateralId;
this.href = "/collateral-management/" + collateralId;
return this;
}

public CommandWrapperBuilder updateClientCollateralProduct(final Long clientId, final Long collateralId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_CLIENT_COLLATERAL_PRODUCT;
Expand Down Expand Up @@ -2347,14 +2330,6 @@ public CommandWrapperBuilder deleteCollateral(final Long loanId, final Long coll
return this;
}

public CommandWrapperBuilder deleteCollateralProduct(final Long collateralId) {
this.actionName = ACTION_DELETE;
this.entityName = ENTITY_COLLATERAL_PRODUCT;
this.entityId = collateralId;
this.href = "/collateral-management/" + collateralId;
return this;
}

public CommandWrapperBuilder deleteClientCollateralProduct(final Long collateralId, final Long clientId) {
this.actionName = ACTION_DELETE;
this.entityName = ENTITY_CLIENT_COLLATERAL_PRODUCT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.organisation.monetary.domain.ApplicationCurrency;
import org.apache.fineract.portfolio.collateralmanagement.api.CollateralManagementJsonInputParams;

@Entity
@Table(name = "m_collateral_management")
@Getter
@Setter
@NoArgsConstructor
public class CollateralManagementDomain extends AbstractPersistableCustom<Long> {

@Column(name = "name", length = 20, columnDefinition = " ")
Expand All @@ -61,100 +64,17 @@ public class CollateralManagementDomain extends AbstractPersistableCustom<Long>
private ApplicationCurrency currency;

@OneToMany(mappedBy = "collateral", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@Setter(AccessLevel.NONE)
private Set<ClientCollateralManagement> clientCollateralManagements = new HashSet<>();

public CollateralManagementDomain() {

}

private CollateralManagementDomain(final String quality, final BigDecimal basePrice, final String unitType, final BigDecimal pctToBase,
final ApplicationCurrency currency, final String name) {
@Builder
private CollateralManagementDomain(final String name, final String quality, final BigDecimal basePrice, final String unitType,
final BigDecimal pctToBase, final ApplicationCurrency currency) {
this.name = name;
this.quality = quality;
this.basePrice = basePrice;
this.currency = currency;
this.pctToBase = pctToBase;
this.unitType = unitType;
this.quality = quality;
this.name = name;
}

public static CollateralManagementDomain createNew(JsonCommand jsonCommand, final ApplicationCurrency applicationCurrency) {
String quality = jsonCommand.stringValueOfParameterNamed("quality");
BigDecimal basePrice = jsonCommand.bigDecimalValueOfParameterNamed("basePrice");
BigDecimal pctToBase = jsonCommand.bigDecimalValueOfParameterNamedDefaultToNullIfZero("pctToBase");
String unitType = jsonCommand.stringValueOfParameterNamed("unitType");
String name = jsonCommand.stringValueOfParameterNamed("name");
return new CollateralManagementDomain(quality, basePrice, unitType, pctToBase, applicationCurrency, name);
}

public Map<String, Object> update(final JsonCommand command, final ApplicationCurrency applicationCurrency) {
final Map<String, Object> changes = new LinkedHashMap<>(5);
final String nameParamName = CollateralManagementJsonInputParams.NAME.getValue();

if (command.isChangeInStringParameterNamed(nameParamName, this.name)) {
final String newValue = command.stringValueOfParameterNamed(nameParamName);
this.name = StringUtils.defaultIfEmpty(newValue, null);
changes.put(nameParamName, this.name);
}

final String qualityParamName = CollateralManagementJsonInputParams.QUALITY.getValue();
if (command.isChangeInStringParameterNamed(qualityParamName, this.quality)) {
final String newValue = command.stringValueOfParameterNamed(qualityParamName);
this.quality = newValue;
changes.put(qualityParamName, this.quality);
}

final String unitTypeParamName = CollateralManagementJsonInputParams.UNIT_TYPE.getValue();
if (command.isChangeInStringParameterNamed(unitTypeParamName, this.unitType)) {
final String newValue = command.stringValueOfParameterNamed(unitTypeParamName);
this.unitType = newValue;
changes.put(unitTypeParamName, this.unitType);
}

this.currency = applicationCurrency;

final String basePriceParamName = CollateralManagementJsonInputParams.BASE_PRICE.getValue();
if (command.isChangeInBigDecimalParameterNamed(basePriceParamName, this.basePrice)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(basePriceParamName);
this.basePrice = newValue;
changes.put(basePriceParamName, this.basePrice);
}

final String pctToBaseParamName = CollateralManagementJsonInputParams.PCT_TO_BASE.getValue();
if (command.isChangeInBigDecimalParameterNamed(pctToBaseParamName, this.pctToBase)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(pctToBaseParamName);
this.pctToBase = newValue;
changes.put(pctToBaseParamName, this.pctToBase);
}

return changes;
}

public String getQuality() {
return this.quality;
}

public String getUnitType() {
return this.unitType;
}

public ApplicationCurrency getCurrency() {
return this.currency;
}

public BigDecimal getBasePrice() {
return this.basePrice;
}

public BigDecimal getPctToBase() {
return this.pctToBase;
}

public String getName() {
return this.name;
}

public Set<ClientCollateralManagement> getClientCollateralManagements() {
return this.clientCollateralManagements;
this.pctToBase = pctToBase;
this.currency = currency;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_STAFFIMAGE")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/staff/*/images"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_STAFFIMAGE")
// collateral: products
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/collateral-management"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_COLLATERAL_PRODUCT")
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/collateral-management/template"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_COLLATERAL_PRODUCT")
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/collateral-management/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_COLLATERAL_PRODUCT")
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/collateral-management"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_COLLATERAL_PRODUCT")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/collateral-management/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_COLLATERAL_PRODUCT")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/collateral-management/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_COLLATERAL_PRODUCT")
// bulk import
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/import"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_IMPORT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
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 @@ -36,103 +33,83 @@
import jakarta.ws.rs.core.MediaType;
import java.util.List;
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.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.command.core.CommandDispatcher;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
import org.apache.fineract.portfolio.collateralmanagement.command.CollateralProductCreateCommand;
import org.apache.fineract.portfolio.collateralmanagement.command.CollateralProductDeleteCommand;
import org.apache.fineract.portfolio.collateralmanagement.command.CollateralProductUpdateCommand;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementData;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementProductRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductRequest;
import org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadPlatformService;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductCreateRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductCreateResponse;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductDeleteRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductDeleteResponse;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductUpdateRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductUpdateResponse;
import org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadService;
import org.springframework.stereotype.Component;

@Path("/v1/collateral-management")
@Component
@Tag(name = "Collateral Management", description = "Collateral Management is for managing collateral operations")
@RequiredArgsConstructor
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public class CollateralManagementApiResource {

private final DefaultToApiJsonSerializer<CollateralManagementData> apiJsonSerializerService;
private final DefaultToApiJsonSerializer<CurrencyData> apiJsonSerializerServiceForCurrency;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PlatformSecurityContext context;
private final CollateralManagementReadPlatformService collateralManagementReadPlatformService;
private final CommandDispatcher dispatcher;
private final CollateralManagementReadService collateralManagementReadService;
private final CurrencyReadPlatformService currencyReadPlatformService;

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a new collateral", description = "Collateral Creation")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementProductRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PostCollateralManagementProductResponse.class)))
public CommandProcessingResult createCollateral(
@Parameter(hidden = true) final CollateralManagementProductRequest collateralManagementProductRequest) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().createCollateral()
.withJson(apiJsonSerializerService.serialize(collateralManagementProductRequest)).build();
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
public CollateralProductCreateResponse createCollateral(@Valid CollateralProductCreateRequest request) {
final var command = new CollateralProductCreateCommand();
command.setPayload(request);
return dispatcher.<CollateralProductCreateRequest, CollateralProductCreateResponse>dispatch(command).get();
}

@GET
@Path("{collateralId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get Collateral", description = "Fetch Collateral")
public CollateralManagementData getCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {

this.context.authenticatedUser()
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());

return this.collateralManagementReadPlatformService.getCollateralProduct(collateralId);
return collateralManagementReadService.getCollateralProduct(collateralId);
}

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get All Collaterals", description = "Fetch all Collateral Products")
public List<CollateralManagementData> getAllCollaterals() {
this.context.authenticatedUser()
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
return this.collateralManagementReadPlatformService.getAllCollateralProducts();
return collateralManagementReadService.getAllCollateralProducts();
}

@GET
@Path("template")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get Collateral Template", description = "Get Collateral Template")
public List<CurrencyData> getCollateralTemplate() {
return currencyReadPlatformService.retrieveAllPlatformCurrencies();
}

@PUT
@Path("{collateralId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update Collateral", description = "Update Collateral")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralProductRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PutCollateralProductResponse.class)))
public CommandProcessingResult updateCollateral(
public CollateralProductUpdateResponse updateCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
@Parameter(hidden = true) final CollateralProductRequest collateralProductRequest) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().updateCollateralProduct(collateralId)
.withJson(apiJsonSerializerService.serialize(collateralProductRequest)).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
@Valid CollateralProductUpdateRequest request) {
request.setCollateralId(collateralId);
final var command = new CollateralProductUpdateCommand();
command.setPayload(request);
return dispatcher.<CollateralProductUpdateRequest, CollateralProductUpdateResponse>dispatch(command).get();
}

@DELETE
@Path("{collateralId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a Collateral", description = "Delete Collateral")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.DeleteCollateralProductResponse.class)))
public CommandProcessingResult deleteCollateral(
public CollateralProductDeleteResponse deleteCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {

final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteCollateralProduct(collateralId).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
final var request = CollateralProductDeleteRequest.builder().collateralId(collateralId).build();
final var command = new CollateralProductDeleteCommand();
command.setPayload(request);
return dispatcher.<CollateralProductDeleteRequest, CollateralProductDeleteResponse>dispatch(command).get();
}

}
Loading
Loading