luckyman20 commented on a change in pull request #1770:
URL: https://github.com/apache/fineract/pull/1770#discussion_r697830592



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralAPIConstants.java
##########
@@ -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.collateralmanagement.api;
+
+public final class CollateralAPIConstants {
+
+    public CollateralAPIConstants() {
+
+    }
+
+    public enum CollateralJSONinputParams {

Review comment:
       Change its name to "CollateralJSONInputParams" (with a capital i).
   
   Please ensure that it changes wherever it is used.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/service/LoanCollateralAssembler.java
##########
@@ -0,0 +1,132 @@
+/**
+ * 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.collateralmanagement.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.math.BigDecimal;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+import 
org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import 
org.apache.fineract.portfolio.collateralmanagement.domain.ClientCollateralManagement;
+import 
org.apache.fineract.portfolio.collateralmanagement.domain.ClientCollateralManagementRepositoryWrapper;
+import 
org.apache.fineract.portfolio.collateralmanagement.exception.LoanCollateralManagementNotFoundException;
+import 
org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagement;
+import 
org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagementRepository;
+import 
org.apache.fineract.portfolio.loanaccount.exception.InvalidAmountOfCollateralQuantity;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LoanCollateralAssembler {
+
+    private final FromJsonHelper fromApiJsonHelper;
+    private final CodeValueRepositoryWrapper codeValueRepository;
+    private final LoanCollateralManagementRepository loanCollateralRepository;
+    private final ClientCollateralManagementRepositoryWrapper 
clientCollateralManagementRepositoryWrapper;
+
+    @Autowired
+    public LoanCollateralAssembler(final FromJsonHelper fromApiJsonHelper, 
final CodeValueRepositoryWrapper codeValueRepository,
+            final LoanCollateralManagementRepository loanCollateralRepository,
+            final ClientCollateralManagementRepositoryWrapper 
clientCollateralManagementRepositoryWrapper) {
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.codeValueRepository = codeValueRepository;
+        this.loanCollateralRepository = loanCollateralRepository;
+        this.clientCollateralManagementRepositoryWrapper = 
clientCollateralManagementRepositoryWrapper;
+    }
+
+    public Set<LoanCollateralManagement> fromParsedJson(final JsonElement 
element) {
+
+        final Set<LoanCollateralManagement> collateralItems = new HashSet<>();
+
+        JsonObject jsonObject = element.getAsJsonObject();
+        final Locale locale = 
this.fromApiJsonHelper.extractLocaleParameter(jsonObject);
+
+        if (jsonObject.has("collateral") && 
jsonObject.get("collateral").isJsonArray()) {
+            JsonArray collaterals = 
jsonObject.get("collateral").getAsJsonArray();
+
+            for (int i = 0; i < collaterals.size(); i++) {
+                final JsonObject collateralItemElement = 
collaterals.get(i).getAsJsonObject();
+                final Long id = this.fromApiJsonHelper.extractLongNamed("id", 
collateralItemElement);
+                final Long collateralId = 
this.fromApiJsonHelper.extractLongNamed("clientCollateralId", 
collateralItemElement);
+                final ClientCollateralManagement clientCollateral = 
this.clientCollateralManagementRepositoryWrapper
+                        .getCollateral(collateralId);
+                final BigDecimal quantity = 
this.fromApiJsonHelper.extractBigDecimalNamed("quantity", 
collateralItemElement, locale);
+                BigDecimal updatedClientQuantity = null;
+
+                if (id == null) {
+                    updatedClientQuantity = 
clientCollateral.getQuantity().subtract(quantity);
+                    if (BigDecimal.ZERO.compareTo(updatedClientQuantity) > 0) {
+                        throw new InvalidAmountOfCollateralQuantity(quantity);
+                    }
+                    clientCollateral.updateQuantity(updatedClientQuantity);
+                    // 
this.clientCollateralManagementRepositoryWrapper.saveAndFlush(clientCollateral);
+                    
collateralItems.add(LoanCollateralManagement.from(clientCollateral, quantity));
+                } else {
+                    LoanCollateralManagement loanCollateralManagement = 
this.loanCollateralRepository.findById(id)
+                            .orElseThrow(() -> new 
LoanCollateralManagementNotFoundException(id));
+
+                    if 
(loanCollateralManagement.getQuantity().compareTo(quantity) != 0) {
+                        updatedClientQuantity = 
clientCollateral.getQuantity().add(loanCollateralManagement.getQuantity())
+                                .subtract(quantity);
+                        if (BigDecimal.ZERO.compareTo(updatedClientQuantity) > 
0) {
+                            throw new 
InvalidAmountOfCollateralQuantity(quantity);
+                        }
+                    } else {
+                        updatedClientQuantity = quantity;
+                    }
+
+                    // loanCollateralManagement.setQuantity(quantity);
+                    clientCollateral.updateQuantity(updatedClientQuantity);
+                    // 
loanCollateralManagement.setClientCollateralManagement(clientCollateral);
+                    // 
this.clientCollateralManagementRepositoryWrapper.saveAndFlush(clientCollateral);
+                    collateralItems
+                            
.add(LoanCollateralManagement.fromExisting(clientCollateral, quantity, 
loanCollateralManagement.getLoanData(),
+                                    
loanCollateralManagement.getLoanTransaction(), 
loanCollateralManagement.getId()));
+                }
+            }
+        }
+
+        // if (element.isJsonObject()) {

Review comment:
       Please check these commented-out code blocks if they are still relevant. 
Please add more details if they will be needed otherwise remove them.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralManagementAPIResourceSwagger.java
##########
@@ -0,0 +1,169 @@
+/**
+ * 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.collateralmanagement.api;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import java.math.BigDecimal;
+
+final class CollateralManagementAPIResourceSwagger {
+
+    private CollateralManagementAPIResourceSwagger() {}
+
+    @Schema(description = "GetCollateralManagementsResponse")
+    public static final class GetCollateralManagementsResponse {
+
+        private GetCollateralManagementsResponse() {}
+
+        static final class GetCollateralTypeResponse {
+
+            private GetCollateralTypeResponse() {}
+
+            @Schema(example = "22kt")
+            public String quality;
+
+        }
+
+        static final class GetCollateralCurrencyResponse {
+
+            private GetCollateralCurrencyResponse() {}
+
+            @Schema(example = "USD")
+            public String code;
+            // @Schema(example = "US Dollar")

Review comment:
       Are these required or not? If you feel that these might be used later 
then please leave a comment above.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
##########
@@ -270,6 +273,8 @@ private LoanAccountData readLoan(Row row, String locale, 
String dateFormat) {
         Long charge1 = 
ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row);
         Long charge2 = 
ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row);
 
+        Long collateral1 = 
ImportHandlerUtils.readAsLong(LoanConstants.LOAN_COLLATERAL_ID, row);

Review comment:
       This variable name could be more descriptive.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralManagementAPIResource.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.collateralmanagement.api;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+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.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import java.util.Collection;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+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.codes.service.CodeValueReadPlatformService;
+import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
+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.organisation.monetary.data.CurrencyData;
+import 
org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
+import 
org.apache.fineract.portfolio.collateralmanagement.api.CollateralAPIConstants.CollateralJSONinputParams;
+import 
org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementData;
+import 
org.apache.fineract.portfolio.collateralmanagement.service.ClientCollateralManagementReadPlatformService;
+import 
org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadPlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Path("/collateral-management")
+@Component
+@Scope("singleton")
+@Tag(name = "Collateral Management", description = "Collateral Management is 
for managing collateral operations")
+public class CollateralManagementAPIResource {
+
+    private final DefaultToApiJsonSerializer<CollateralManagementData> 
apiJsonSerializerService;
+    private final DefaultToApiJsonSerializer<CurrencyData> 
apiJsonSerializerServiceForCurrency;
+    private final ApiRequestParameterHelper apiRequestParameterHelper;
+    private final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService;
+    private final PlatformSecurityContext context;
+    private final CodeValueReadPlatformService codeValueReadPlatformService;
+    private final CollateralManagementReadPlatformService 
collateralManagementReadPlatformService;
+    private final String collateralReadPermission = "COLLATERAL_PRODUCT";
+    private final ClientCollateralManagementReadPlatformService 
clientCollateralManagementReadPlatformService;
+    private final CurrencyReadPlatformService currencyReadPlatformService;
+
+    @Autowired
+    public CollateralManagementAPIResource(final 
DefaultToApiJsonSerializer<CollateralManagementData> apiJsonSerializerService,
+            final ApiRequestParameterHelper apiRequestParameterHelper,
+            final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService, final PlatformSecurityContext context,
+            final CodeValueReadPlatformService codeValueReadPlatformService,
+            final CollateralManagementReadPlatformService 
collateralManagementReadPlatformService,
+            final ClientCollateralManagementReadPlatformService 
clientCollateralManagementReadPlatformService,
+            final CurrencyReadPlatformService currencyReadPlatformService,
+            final DefaultToApiJsonSerializer<CurrencyData> 
apiJsonSerializerServiceForCurrency) {
+        this.apiJsonSerializerService = apiJsonSerializerService;
+        this.apiRequestParameterHelper = apiRequestParameterHelper;
+        this.commandsSourceWritePlatformService = 
commandsSourceWritePlatformService;
+        this.context = context;
+        this.codeValueReadPlatformService = codeValueReadPlatformService;
+        this.collateralManagementReadPlatformService = 
collateralManagementReadPlatformService;
+        this.clientCollateralManagementReadPlatformService = 
clientCollateralManagementReadPlatformService;
+        this.currencyReadPlatformService = currencyReadPlatformService;
+        this.apiJsonSerializerServiceForCurrency = 
apiJsonSerializerServiceForCurrency;
+    }
+
+    @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 = 
CollateralManagementAPIResourceSwagger.PostCollateralManagementProductRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.PostCollateralManagementProductResponse.class)))
 })
+    public String createCollateral(@Parameter(hidden = true) final String 
apiRequestBodyAsJson) {
+        final CommandWrapper commandWrapper = new 
CommandWrapperBuilder().createCollateral().withJson(apiRequestBodyAsJson).build();
+        final CommandProcessingResult commandProcessingResult = 
this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
+        return 
this.apiJsonSerializerService.serialize(commandProcessingResult);
+    }
+
+    @GET
+    @Path("{collateralId}")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get Collateral", description = "Fetch Collateral")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralManagementsResponse.class)))
 })
+    public String getCollateral(@PathParam("collateralId") 
@Parameter(description = "collateralId") final Long collateralId,
+            @Context final UriInfo uriInfo) {
+
+        
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
+
+        final CollateralManagementData collateralManagementData = 
this.collateralManagementReadPlatformService
+                .getCollateralProduct(collateralId);
+
+        return 
this.apiJsonSerializerService.serialize(collateralManagementData);
+    }
+
+    @GET
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get All Collaterals", description = "Fetch all 
Collateral Products")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(array = @ArraySchema(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralManagementsResponse.class))))
 })
+    public String getAllCollaterals(@Context final UriInfo uriInfo) {
+        
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
+        Collection<CollateralManagementData> collateralManagementDataList = 
this.collateralManagementReadPlatformService
+                .getAllCollateralProducts();
+        return 
this.apiJsonSerializerService.serialize(collateralManagementDataList);
+    }
+
+    @GET
+    @Path("template")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get Collateral Template", description = "Get 
Collateral Template")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(array = @ArraySchema(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralProductTemplate.class)))) })
+    public String getCollateralTemplate(@Context final UriInfo uriInfo) {
+        // 
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());

Review comment:
       If you feel that this line might be useful then please add a comment for 
the same.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralAPIConstants.java
##########
@@ -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.collateralmanagement.api;
+
+public final class CollateralAPIConstants {
+
+    public CollateralAPIConstants() {
+
+    }
+
+    public enum CollateralJSONinputParams {
+
+        NAME("name"), QUALITY("quality"), BASE_PRICE("basePrice"), 
UNIT_TYPE("unitType"), PCT_TO_BASE("pctToBase"), CURRENCY(
+                "currency"), 
COLLATERAL_PRODUCT_READ_PERMISSION("COLLATERAL_PRODUCT"), 
CLIENT_COLLATERAL_PRODUCT_READ_PERMISSION(
+                        "CLIENT_COLLATERAL_PRODUCT"), QUANTITY("quantity"), 
TOTAL_COLLATERAL_VALUE("totalCollateralValue");
+
+        private final String value;
+
+        CollateralJSONinputParams(final String value) {
+            this.value = value;
+        }
+
+        @Override
+        public String toString() {
+            return name().toString().replaceAll("_", " ");

Review comment:
       name() returns a string, do we need to convert it to a string again?

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralManagementAPIResource.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.collateralmanagement.api;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+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.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import java.util.Collection;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+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.codes.service.CodeValueReadPlatformService;
+import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
+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.organisation.monetary.data.CurrencyData;
+import 
org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
+import 
org.apache.fineract.portfolio.collateralmanagement.api.CollateralAPIConstants.CollateralJSONinputParams;
+import 
org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementData;
+import 
org.apache.fineract.portfolio.collateralmanagement.service.ClientCollateralManagementReadPlatformService;
+import 
org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadPlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Path("/collateral-management")
+@Component
+@Scope("singleton")
+@Tag(name = "Collateral Management", description = "Collateral Management is 
for managing collateral operations")
+public class CollateralManagementAPIResource {
+
+    private final DefaultToApiJsonSerializer<CollateralManagementData> 
apiJsonSerializerService;
+    private final DefaultToApiJsonSerializer<CurrencyData> 
apiJsonSerializerServiceForCurrency;
+    private final ApiRequestParameterHelper apiRequestParameterHelper;
+    private final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService;
+    private final PlatformSecurityContext context;
+    private final CodeValueReadPlatformService codeValueReadPlatformService;
+    private final CollateralManagementReadPlatformService 
collateralManagementReadPlatformService;
+    private final String collateralReadPermission = "COLLATERAL_PRODUCT";
+    private final ClientCollateralManagementReadPlatformService 
clientCollateralManagementReadPlatformService;
+    private final CurrencyReadPlatformService currencyReadPlatformService;
+
+    @Autowired
+    public CollateralManagementAPIResource(final 
DefaultToApiJsonSerializer<CollateralManagementData> apiJsonSerializerService,
+            final ApiRequestParameterHelper apiRequestParameterHelper,
+            final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService, final PlatformSecurityContext context,
+            final CodeValueReadPlatformService codeValueReadPlatformService,
+            final CollateralManagementReadPlatformService 
collateralManagementReadPlatformService,
+            final ClientCollateralManagementReadPlatformService 
clientCollateralManagementReadPlatformService,
+            final CurrencyReadPlatformService currencyReadPlatformService,
+            final DefaultToApiJsonSerializer<CurrencyData> 
apiJsonSerializerServiceForCurrency) {
+        this.apiJsonSerializerService = apiJsonSerializerService;
+        this.apiRequestParameterHelper = apiRequestParameterHelper;
+        this.commandsSourceWritePlatformService = 
commandsSourceWritePlatformService;
+        this.context = context;
+        this.codeValueReadPlatformService = codeValueReadPlatformService;
+        this.collateralManagementReadPlatformService = 
collateralManagementReadPlatformService;
+        this.clientCollateralManagementReadPlatformService = 
clientCollateralManagementReadPlatformService;
+        this.currencyReadPlatformService = currencyReadPlatformService;
+        this.apiJsonSerializerServiceForCurrency = 
apiJsonSerializerServiceForCurrency;
+    }
+
+    @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 = 
CollateralManagementAPIResourceSwagger.PostCollateralManagementProductRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.PostCollateralManagementProductResponse.class)))
 })
+    public String createCollateral(@Parameter(hidden = true) final String 
apiRequestBodyAsJson) {
+        final CommandWrapper commandWrapper = new 
CommandWrapperBuilder().createCollateral().withJson(apiRequestBodyAsJson).build();
+        final CommandProcessingResult commandProcessingResult = 
this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
+        return 
this.apiJsonSerializerService.serialize(commandProcessingResult);
+    }
+
+    @GET
+    @Path("{collateralId}")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get Collateral", description = "Fetch Collateral")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralManagementsResponse.class)))
 })
+    public String getCollateral(@PathParam("collateralId") 
@Parameter(description = "collateralId") final Long collateralId,
+            @Context final UriInfo uriInfo) {
+
+        
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
+
+        final CollateralManagementData collateralManagementData = 
this.collateralManagementReadPlatformService
+                .getCollateralProduct(collateralId);
+
+        return 
this.apiJsonSerializerService.serialize(collateralManagementData);
+    }
+
+    @GET
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get All Collaterals", description = "Fetch all 
Collateral Products")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(array = @ArraySchema(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralManagementsResponse.class))))
 })
+    public String getAllCollaterals(@Context final UriInfo uriInfo) {
+        
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
+        Collection<CollateralManagementData> collateralManagementDataList = 
this.collateralManagementReadPlatformService
+                .getAllCollateralProducts();
+        return 
this.apiJsonSerializerService.serialize(collateralManagementDataList);
+    }
+
+    @GET
+    @Path("template")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Get Collateral Template", description = "Get 
Collateral Template")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(array = @ArraySchema(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.GetCollateralProductTemplate.class)))) })
+    public String getCollateralTemplate(@Context final UriInfo uriInfo) {
+        // 
this.context.authenticatedUser().validateHasReadPermission(CollateralJSONinputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
+        Collection<CurrencyData> currencyDataCollection = 
this.currencyReadPlatformService.retrieveAllPlatformCurrencies();
+        return 
this.apiJsonSerializerServiceForCurrency.serialize(currencyDataCollection);
+    }
+
+    @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 = 
CollateralManagementAPIResourceSwagger.PutCollateralProductRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
CollateralManagementAPIResourceSwagger.PutCollateralProductResponse.class))) })
+    public String updateCollateral(@PathParam("collateralId") 
@Parameter(description = "collateralId") final Long collateralId,
+            @Parameter(hidden = true) final String jsonBody) {
+        final CommandWrapper commandWrapper = new 
CommandWrapperBuilder().updateCollateralProduct(collateralId).withJson(jsonBody).build();
+
+        final CommandProcessingResult commandProcessingResult = 
this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
+
+        return 
this.apiJsonSerializerService.serialize(commandProcessingResult);
+
+    }
+
+    /**
+     * TODO: Finalize this DELETE method for collaterals.

Review comment:
       Is this TODO comment still relevant? If yes, please add more details.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to