diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 6e8d0e1a4..d7e1956e8 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -1906,6 +1906,103 @@ Update a Slab Delete a Slab + + Teller Cash Management + tellers + Create Teller + List Tellers + + + + + + tellers/{tellerId} + + Find Teller + Update Teller + Delete Teller + + + + tellers/{tellerId}/cashiers + Create Cashier + Retrieve Cashier + + + + + + tellers/{tellerId}/cashiers/{cashierId} + + Find Cashier + Update Cashier + Delete Cashier + + + + tellers/{tellerId}/cashiers/template + + Retrieve Cashier Template + + + + + + tellers/{tellerId}/cashiers/{cashierId}/allocate + Allocate Cash To Cashier + + + + + + + tellers/{tellerId}/cashiers/{cashierId}/settle + Settle Cash From Cashier + + + + + + + tellers/{tellerId}/cashiers/{cashierId}/transactions + + Retrieve Cashier Transactions + + + + + + tellers/{tellerId}/cashiers/{cashierId}/summaryandtransactions + + Retrieve Cashier Transactions With Summary + + + + + + tellers/{tellerId}/cashiers/{cashierId}/transactions/template + + Retrieve Cashier Transaction Template + + + + + + Payment Type + paymenttypes + Create Payment Type + List Payment Types + + + + + + paymenttypes/{paymentTypeId} + + Retrieve Payment Type + Update Payment Type + Delete Payment Type + @@ -33722,6 +33819,1104 @@ No Request Body: + +   +
+
+

Teller Cash Management

+

Teller cash management which will allow an organization to manage their cash transactions at branches or head office more effectively.

+
+
+   +
+
+

List all tellers

+

Retrieves list tellers.


+
+
+ + GET https://DomainName/api/v1/tellers + + + [ + { + "id": 3, + "officeId": 1, + "debitAccountId": 0, + "creditAccountId": 0, + "name": "Teller3", + "description": "cash handling", + "startDate": [ + 2015, + 2, + 1 + ], + "status": "ACTIVE", + "officeName": "Head Office" + }, + { + "id": 2, + "officeId": 1, + "debitAccountId": 0, + "creditAccountId": 0, + "name": "Teller2", + "description": "abcc", + "startDate": [ + 2015, + 2, + 19 + ], + "endDate": [ + 2015, + 3, + 30 + ], + "status": "ACTIVE", + "officeName": "Head Office" + }, + { + "id": 1, + "officeId": 1, + "debitAccountId": 0, + "creditAccountId": 0, + "name": "Teller1", + "description": "abc", + "startDate": [ + 2015, + 2, + 20 + ], + "status": "ACTIVE", + "officeName": "Head Office" + }, + { + "id": 4, + "officeId": 2, + "debitAccountId": 0, + "creditAccountId": 0, + "name": "Teller4", + "description": "cash handling", + "startDate": [ + 2015, + 2, + 1 + ], + "status": "ACTIVE", + "officeName": "Office1" + } + ] + +
+
+ +   +
+
+

Create teller

+

+ + + + + + + +
Mandatory Fields
Teller name, OfficeId, Description, Start Date, Status
+ + + + + + + +
Optional Fields
End Date
+


+
+
+ + POST https://DomainName/api/v1/tellers + + + POST tellers + Content-Type: application/json + Request Body: + { + "officeId":2, + "name":"Teller4", + "description":"cash handling", + "status":300, + "locale":"en", + "dateFormat":"dd MMMM yyyy", + "startDate":"01 February 2015" + } + + + { + "officeId": 2, + "resourceId": 5 + } + +
+
+ +   +
+
+

Retrieve tellers

+


+
+
+ + GET https://DomainName/api/v1/tellers/5 + + + { + "id": 5, + "officeId": 2, + "debitAccountId": 0, + "creditAccountId": 0, + "name": "Teller5", + "description": "cash handling", + "startDate": [ + 2015, + 2, + 1 + ], + "status": "ACTIVE", + "officeName": "Office1" + } + +
+
+ +   +
+
+

Update teller

+


+
+
+ + PUT https://DomainName/api/v1/tellers/{tellerId} + + + PUT tellers/5 + Content-Type: application/json + Request Body: + { + "name":"Teller5", + "officeId":2, + "description":"teller cash handling", + "status":300, + "endDate":"28 February 2015", + "startDate":"01 February 2015", + "locale":"en", + "dateFormat":"dd MMMM yyyy" + } + + + { + "officeId":2, + "resourceId":5, + "changes":{ + "description":"teller cash handling", + "endDate":"28 February 2015", + "dateFormat":"dd MMMM yyyy", + "locale":"en" + } + } + +
+
+ + +   +
+
+

List Cashiers

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers + + + { + "tellerId": 1, + "tellerName": "Teller1", + "officeId": 1, + "officeName": "Head Office", + "cashiers": [ + { + "id": 1, + "tellerId": 1, + "staffId": 1, + "description": "", + "startDate": "Feb 20, 2015 12:00:00 AM", + "endDate": "Feb 27, 2015 12:00:00 AM", + "isFullDay": true, + "startTime": "", + "endTime": "", + "tellerName": "Teller1", + "staffName": "Staff1, Test" + } + ] + } + +
+
+ +   +
+
+

Create Cashiers

+

+ + + + + + + +
Mandatory Fields
Cashier/staff, Fromm Date, To Date, Full Day or From time and To time
+ + + + + + + +
Optional Fields
Description/Notes
+


+
+
+ + POST https://DomainName/api/v1/tellers/{tellerId}/cashiers + + + POST tellers/1/cashiers + { + "endDate":"28 February 2015", + "description":"Cashier created", + "isFullDay":true, + "staffId":3, + "locale":"en", + "dateFormat":"dd MMMM yyyy", + "startDate":"01 February 2015" + } + + + { + "resourceId":1, + "subResourceId":2 + } + +
+
+ +   +
+
+

Retrieve a cashier

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId} + + + { + "id": 1, + "tellerId": 1, + "staffId": 1, + "description": "", + "startDate": "Feb 20, 2015 12:00:00 AM", + "endDate": "Feb 27, 2015 12:00:00 AM", + "isFullDay": true, + "startTime": "", + "endTime": "", + "tellerName": "Teller1", + "staffName": "Staff1, Test" + } + +
+
+ + +   +
+
+

Update Cashier

+


+
+
+ + PUT https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId} + + + + + PUT tellers/1/cashiers/1 + { + "endDate":"25 February 2015", + "description":"Cashier updated.", + "isFullDay":true, + "staffId":4, + "locale":"en", + "dateFormat":"dd MMMM yyyy", + "startDate":"01 February 2015" + } + + + { + "resourceId": 1, + "subResourceId": 1, + "changes": { + "description": "Cashier updated.", + "endDate": "25 February 2015", + "dateFormat": "dd MMMM yyyy", + "locale": "en" + } + } + +
+
+ +   +
+
+

Delete Cashier

+

+
+
+ + DELETE tellers/{tellerId}/cashiers/{cashierId} + + + DELETE tellers/1/cashiers/3 + Content-Type: application/json + Request Body: + { + } + + + { + "resourceId": 3 + } + +
+
+ +   +
+
+

Find Cashiers

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers/template + + + { + "tellerId":1, + "officeId":1, + "officeName":"Head Office", + "tellerName":"Teller1", + "staffOptions":[ + { + "id":1, + "displayName":"Staff1, Test" + }, + { + "id":2, + "displayName":"Staff, 2" + }, + { + "id":3, + "displayName":"Staff, 3" + } + ] + } + +
+
+ + +   +
+
+

Retrieve Cashier Transaction

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId}/transactions + + + [ + { + "id": 8, + "cashierId": 15, + "txnType": { + "id": 104, + "value": "Cash Out" + }, + "txnAmount": 10000, + "txnDate": "Feb 25, 2015 12:00:00 AM", + "entityId": 2, + "entityType": "loans", + "txnNote": "Disbursement, Loan:2-000000002,Client:1-Test 1", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 10, + "cashierId": 15, + "txnType": { + "id": 104, + "value": "Cash Out" + }, + "txnAmount": 8500, + "txnDate": "Feb 25, 2015 12:00:00 AM", + "entityId": 3, + "entityType": "loans", + "txnNote": "Disbursement, Loan:3-000000003,Client:3-Client 1", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 12, + "cashierId": 15, + "txnType": { + "id": 104, + "value": "Cash Out" + }, + "txnAmount": 10000, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 4, + "entityType": "loans", + "txnNote": "Disbursement, Loan:4-000000004,Client:4-Client 2", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 14, + "cashierId": 15, + "txnType": { + "id": 103, + "value": "Cash In" + }, + "txnAmount": 1266.52, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 4, + "entityType": "loans", + "txnNote": "Repayment, Loan:4-000000004,Client:4-Client 2", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 13, + "cashierId": 15, + "txnType": { + "id": 101, + "value": "Allocate Cash" + }, + "txnAmount": 50000, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 0, + "entityType": "", + "txnNote": "cash allocated on 1st Feb 2015", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 10, + "tellerName": "Ramesh(Teller/Cashier)", + "cashierName": "B, Ramesh" + }, + { + "id": 15, + "cashierId": 15, + "txnType": { + "id": 104, + "value": "Cash Out" + }, + "txnAmount": 10000, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 5, + "entityType": "loans", + "txnNote": "Disbursement, Loan:5-000000005,Client:5-Suresh D", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 17, + "cashierId": 15, + "txnType": { + "id": 103, + "value": "Cash In" + }, + "txnAmount": 1266.52, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 5, + "entityType": "loans", + "txnNote": "Repayment, Loan:5-000000005,Client:5-Suresh D", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 0, + "cashierName": "B, Ramesh" + }, + { + "id": 14, + "cashierId": 15, + "txnType": { + "id": 102, + "value": "Settle Cash" + }, + "txnAmount": 10000, + "txnDate": "Feb 1, 2015 12:00:00 AM", + "entityId": 0, + "entityType": "", + "txnNote": "cash settlement on 1 feb with 10k", + "createdDate": "Feb 25, 2015 12:00:00 AM", + "officeId": 1, + "officeName": "Head Office", + "tellerId": 10, + "tellerName": "Ramesh(Teller/Cashier)", + "cashierName": "B, Ramesh" + } + ] + +
+
+ + + +   +
+
+

Allocate Cash To Cashier

+

+ + + + + + + +
Mandatory Fields
Date, Amount, Currency, Notes/Comments
+


+
+
+ + POST https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId}/allocate + + + POST tellers/1/cashiers/1/allocate?command=allocate + { + "currencyCode":"USD", + "txnAmount":"5000", + "txnNote":"allocating cash", + "locale":"en", + "dateFormat":"dd MMMM yyyy", + "txnDate":"01 February 2015" + } + + + { + "resourceId":1, + "subResourceId":4 + } + +
+
+ + +   +
+
+

Settle Cash From Cashier

+

+ + + + + + + +
Mandatory Fields
Date, Amount, Currency, Notes/Comments
+


+
+
+ + POST https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId}/settle + + + POST tellers/1/cashiers/1/settle?command=settle + { + "currencyCode":"USD", + "txnAmount":"2000", + "txnNote":"cash settlement", + "locale":"en", + "dateFormat":"dd MMMM yyyy", + "txnDate":"20 February 2015" + } + + + { + "resourceId":1, + "subResourceId":5 + } + +
+
+ +   +
+
+

Transactions Wtih Summary For Cashier

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId}/summaryandtransactions + + + { + "sumCashAllocation":7000.000000, + "sumInwardCash":0, + "sumOutwardCash":0, + "sumCashSettlement":50.000000, + "netCash":6950.000000, + "officeName":"Head Office", + "tellerId":1, + "tellerName":"Teller1", + "cashierId":1, + "cashierName":"Staff1, Test", + "cashierTransactions":[ + { + "id":2, + "cashierId":1, + "txnType":{ + "id":101, + "value":"Allocate Cash" + }, + "txnAmount":2000.000000, + "txnDate":"Feb 20, 2015 12:00:00 AM", + "entityId":0, + "entityType":"", + "txnNote":"aaaa", + "createdDate":"Feb 20, 2015 12:00:00 AM", + "officeId":1, + "officeName":"Head Office", + "tellerId":1, + "tellerName":"Teller1", + "cashierName":"Staff1, Test" + }, + { + "id":3, + "cashierId":1, + "txnType":{ + "id":102, + "value":"Settle Cash" + }, + "txnAmount":50.000000, + "txnDate":"Feb 20, 2015 12:00:00 AM", + "entityId":0, + "entityType":"", + "txnNote":"bbbbbb", + "createdDate":"Feb 20, 2015 12:00:00 AM", + "officeId":1, + "officeName":"Head Office", + "tellerId":1, + "tellerName":"Teller1", + "cashierName":"Staff1, Test" + }, + { + "id":4, + "cashierId":1, + "txnType":{ + "id":101, + "value":"Allocate Cash" + }, + "txnAmount":5000.000000, + "txnDate":"Feb 1, 2015 12:00:00 AM", + "entityId":0, + "entityType":"", + "txnNote":"allocating cash", + "createdDate":"Feb 23, 2015 12:00:00 AM", + "officeId":1, + "officeName":"Head Office", + "tellerId":1, + "tellerName":"Teller1", + "cashierName":"Staff1, Test" + } + ] + } + +
+
+ + +   +
+
+

Retrieve Cashier Transaction Template

+


+
+
+ + GET https://DomainName/api/v1/tellers/{tellerId}/cashiers/{cashierId}/transactions/template + + + { + "cashierId":1, + "officeName":"Head Office", + "tellerId":1, + "tellerName":"Teller1", + "cashierName":"Staff1, Test", + "cashierData":{ + "id":1, + "tellerId":1, + "staffId":1, + "description":"", + "startDate":"Feb 20, 2015 12:00:00 AM", + "endDate":"Feb 27, 2015 12:00:00 AM", + "isFullDay":true, + "startTime":"", + "endTime":"", + "tellerName":"Teller1", + "staffName":"Staff1, Test" + }, + "startDate":"Feb 20, 2015 12:00:00 AM", + "endDate":"Feb 27, 2015 12:00:00 AM", + "currencyOptions":[ + { + "code":"USD", + "name":"US Dollar", + "decimalPlaces":2, + "displaySymbol":"$", + "nameCode":"currency.USD", + "displayLabel":"US Dollar ($)" + } + ] + } + +
+
+ + + + + + +   +
+
+

Payment Type

+

This defines the payment type + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Field Descriptions
name
Name the payment type +
description
+ Description of payment type +
isCashPayment
+ Determines weather the payment type is cash or not. +
position
+ Can set the order in which the payment type should be displayed. +
+

+
+   +
+
+

Create a Payment Type

+

Creates a new Payment type

+ + + + + + + +
Mandatory Fields
name
+ + + + + + + +
Optional Fields
Description, isCashPayment,Position
+
+
+ + POST https://DomainName/api/v1/paymenttype + + + POST paymenttype + Content-Type: application/json + Request Body: + { + "name":"cash", + "description":"cash payment type", + "isCashPayment":true, + "position":1 + } + + + { + "resourceId": 1 + } + +
+
+   +
+
+

Retrieve all Payment Types

+

Retrieve list of payment types

+ + +
+
+
+ + GET https://DomainName/api/v1/paymenttype + + + [ + { + "id": 24, + "name": "PTC", + "description": "Cash", + "isCashPayment": true, + "position": 0 + }, + { + "id": 25, + "name": "mPay", + "description": "not chash payment", + "isCashPayment": false, + "position": 0 + }, + { + "id": 26, + "name": "mPesa", + "description": "non cash payment", + "isCashPayment": false, + "position": 0 + }, + { + "id": 27, + "name": "Mobile Money", + "description": "money transferred through mobile", + "isCashPayment": false, + "position": 0 + }, + { + "id": 13, + "name": "cash", + "description": "cash Payment", + "isCashPayment": true, + "position": 1 + } + ] + +
+
+   +
+
+

Retrieve a Payment Type

+

Retrieves a payment type

+
+
+ + GET https://DomainName/api/v1/paymenttype/{paymentTypeId} + + + { + "id": 13, + "name": "cash", + "description": "cash Payment", + "isCashPayment": true, + "position": 1 + } + +
+
+   +
+
+

Update a Payment Type

+
+
+ + PUT https://DomainName/api/v1/paymenttype/{paymnetTypeId} + + + PUT interestratecharts/1/paymenttype/13 + { + "name":"mPay", + "description":"not a cash payment type", + "isCashPayment":false, + "position":3 + } + + + { + "resourceId": 13 + } + +
+
+   +
+
+

Delete a Payment Type

+

Deletes payment type

+
+
+ + DELETE https://DomainName/api/v1/paymenttype/{paymentTypeId} + + + DELETE paymnettype/13 + Content-Type: application/json + No Request Body: + + + { + "resourceId": 13 + } + +
+
+ + + +  
diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PaymentTypeIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PaymentTypeIntegrationTest.java new file mode 100644 index 000000000..1010ced34 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PaymentTypeIntegrationTest.java @@ -0,0 +1,80 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.integrationtests; + +import java.util.HashMap; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.PaymentTypeDomain; +import org.mifosplatform.integrationtests.common.PaymentTypeHelper; +import org.mifosplatform.integrationtests.common.Utils; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class PaymentTypeIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void testPaymentType() { + String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); + String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); + Boolean isCashPayment = true; + Integer position = 1; + + Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position); + Assert.assertNotNull(paymentTypeId); + PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId); + PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId); + Assert.assertEquals(name, paymentTypeResponse.getName()); + Assert.assertEquals(description, paymentTypeResponse.getDescription()); + Assert.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment()); + Assert.assertEquals(position, paymentTypeResponse.getPosition()); + + // Update Payment Type + String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5); + String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15); + Boolean isCashPaymentUpdatedValue = false; + Integer newPosition = 2; + + HashMap request = new HashMap(); + request.put("name", newName); + request.put("description", newDescription); + request.put("isCashPayment", isCashPaymentUpdatedValue); + request.put("position", newPosition); + PaymentTypeHelper.updatePaymentType(paymentTypeId, request, requestSpec, responseSpec); + PaymentTypeDomain paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId); + Assert.assertEquals(newName, paymentTypeUpdatedResponse.getName()); + Assert.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription()); + Assert.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment()); + Assert.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition()); + + // Delete + Integer deletedPaymentTypeId = PaymentTypeHelper.deletePaymentType(paymentTypeId, requestSpec, responseSpec); + Assert.assertEquals(paymentTypeId, deletedPaymentTypeId); + ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(403).build(); + PaymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId); + + } + +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeDomain.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeDomain.java new file mode 100644 index 000000000..1d31a3649 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeDomain.java @@ -0,0 +1,66 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.integrationtests.common; + +public class PaymentTypeDomain { + + private Integer id; + private String name; + private String description; + private Boolean isCashPayment; + private Integer position; + + private PaymentTypeDomain(final Integer id, final String name, final String description, final Boolean isCashPayment, + final Integer position) { + this.id = id; + this.name = name; + this.description = description; + this.isCashPayment = isCashPayment; + this.position = position; + + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Boolean getIsCashPayment() { + return this.isCashPayment; + } + + public void setIsCashPayment(Boolean isCashPayment) { + this.isCashPayment = isCashPayment; + } + + public Integer getPosition() { + return this.position; + } + + public void setPosition(Integer position) { + this.position = position; + } + +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeHelper.java new file mode 100644 index 000000000..5fa626288 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PaymentTypeHelper.java @@ -0,0 +1,78 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.integrationtests.common; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class PaymentTypeHelper { + + private static final String CREATE_PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype?" + Utils.TENANT_IDENTIFIER; + private static final String PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype"; + + public static Integer createPaymentType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String name, final String description, final Boolean isCashPayment, final Integer position) { + System.out.println("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_PAYMENTTYPE_URL, + getJsonToCreatePaymentType(name, description, isCashPayment, position), "resourceId"); + } + + public static String getJsonToCreatePaymentType(final String name, final String description, final Boolean isCashPayment, + final Integer position) { + HashMap hm = new HashMap(); + hm.put("name", name); + if (description != null) hm.put("description", description); + hm.put("isCashPayment", isCashPayment); + if (position != null) hm.put("position", position); + + System.out.println("------------------------CREATING PAYMENT TYPE-------------------------" + hm); + return new Gson().toJson(hm); + } + + public static void verifyPaymentTypeCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedPaymentTypeID) { + System.out.println("------------------------------CHECK PAYMENT DETAILS------------------------------------\n"); + final String PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype/" + generatedPaymentTypeID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responsePaymentTypeID = Utils.performServerGet(requestSpec, responseSpec, PAYMENTTYPE_URL, "id"); + assertEquals("ERROR IN CREATING THE PAYMENT TYPE", generatedPaymentTypeID, responsePaymentTypeID); + } + + public static PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, + final Integer paymentTypeId) { + final String GET_PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------GET PAYMENT TYPE---------------------------------------------"); + final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "")); + return new Gson().fromJson(jsonData, new TypeToken() {}.getType()); + + } + + public static HashMap updatePaymentType(final int id, HashMap request, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String UPDATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE PAYMENT TYPE " + id + "---------------------------------------------"); + HashMap hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_PAYMENTTYPE_URL, + new Gson().toJson(request), "changes"); + return hash; + } + + public static Integer deletePaymentType(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String DELETE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------DELETING PAYMENT TYPE " + id + "--------------------------------------------"); + return Utils.performServerDelete(requestSpec, responseSpec, DELETE_PAYMENTTYPE_URL, "resourceId"); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index 60c33b219..af23d3d99 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -7,6 +7,7 @@ package org.mifosplatform.commands.service; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.infrastructure.accountnumberformat.service.AccountNumberFormatConstants; +import org.mifosplatform.portfolio.paymenttype.api.PaymentTypeApiResourceConstants; import org.mifosplatform.portfolio.savings.DepositsApiConstants; import org.mifosplatform.useradministration.api.PasswordPreferencesApiConstants; @@ -2371,17 +2372,17 @@ public class CommandWrapperBuilder { public CommandWrapperBuilder createPaymentType() { this.actionName = "CREATE"; - this.entityName = "PAYMENTTYPE"; + this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME; this.entityId = null; - this.href = "/paymenttype"; + this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME; return this; } public CommandWrapperBuilder updatePaymentType(final Long paymentTypeId) { this.actionName = "UPDATE"; - this.entityName = "PAYMENTTYPE"; + this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME; this.entityId = paymentTypeId; - this.href = "/paymenttype/" + paymentTypeId; + this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId; return this; } @@ -2389,7 +2390,7 @@ public class CommandWrapperBuilder { this.actionName = "DELETE"; this.entityName = "PAYMENTTYPE"; this.entityId = paymentTypeId; - this.href = "/paymenttype/" + paymentTypeId; + this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId; return this; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResource.java index a91d5c878..25c03286b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResource.java @@ -31,11 +31,12 @@ import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSeriali import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.paymenttype.data.PaymentTypeData; +import org.mifosplatform.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper; import org.mifosplatform.portfolio.paymenttype.service.PaymentTypeReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Path("/paymenttype") +@Path("/paymenttypes") @Component public class PaymentTypeApiResource { @@ -44,17 +45,21 @@ public class PaymentTypeApiResource { private final PaymentTypeReadPlatformService readPlatformService; private final PortfolioCommandSourceWritePlatformService commandWritePlatformService; private final ApiRequestParameterHelper apiRequestParameterHelper; - private final String resourceNameForPermissions = "PAYMENT_TYPE"; - private final Set RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "value", "description", "isCashPayment")); + // private final String resourceNameForPermissions = "PAYMENT_TYPE"; + private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper; + + // private final Set RESPONSE_DATA_PARAMETERS = new + // HashSet<>(Arrays.asList("id", "value", "description", "isCashPayment")); @Autowired public PaymentTypeApiResource(PlatformSecurityContext securityContext, DefaultToApiJsonSerializer jsonSerializer, - PaymentTypeReadPlatformService readPlatformService, ApiRequestParameterHelper apiRequestParameterHelper, - PortfolioCommandSourceWritePlatformService commandWritePlatformService) { + PaymentTypeReadPlatformService readPlatformService, PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper, + ApiRequestParameterHelper apiRequestParameterHelper, PortfolioCommandSourceWritePlatformService commandWritePlatformService) { super(); this.securityContext = securityContext; this.jsonSerializer = jsonSerializer; this.readPlatformService = readPlatformService; + this.paymentTypeRepositoryWrapper = paymentTypeRepositoryWrapper; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandWritePlatformService = commandWritePlatformService; } @@ -63,22 +68,22 @@ public class PaymentTypeApiResource { @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON) public String getAllPaymentTypes(@Context final UriInfo uriInfo) { - this.securityContext.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); + this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.resourceNameForPermissions); final Collection paymentTypes = this.readPlatformService.retrieveAllPaymentTypes(); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.jsonSerializer.serialize(settings, paymentTypes, this.RESPONSE_DATA_PARAMETERS); + return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS); } - - + @GET @Path("{paymentTypeId}") @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON) - public String retrieveOnePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId,@Context final UriInfo uriInfo) { - this.securityContext.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); + public String retrieveOnePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId, @Context final UriInfo uriInfo) { + this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.resourceNameForPermissions); + this.paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId); final PaymentTypeData paymentTypes = this.readPlatformService.retrieveOne(paymentTypeId); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.jsonSerializer.serialize(settings, paymentTypes, this.RESPONSE_DATA_PARAMETERS); + return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS); } @POST diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResourceConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResourceConstants.java index a12afa9cd..39286b3ae 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResourceConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/api/PaymentTypeApiResourceConstants.java @@ -11,14 +11,17 @@ import java.util.Set; public class PaymentTypeApiResourceConstants { - public static final String resourceNameForPermissions = "PAYMENTTYPE"; + public static final String RESOURCE_NAME = "paymenttype"; + public static final String ENTITY_NAME = "PAYMENTTYPE"; + + public static final String resourceNameForPermissions = "PAYMENT_TYPE"; public static final String ID = "id"; public static final String NAME = "name"; public static final String DESCRIPTION = "description"; public static final String ISCASHPAYMENT = "isCashPayment"; public static final String POSITION = "position"; - public final Set RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ID, NAME, DESCRIPTION, ISCASHPAYMENT)); + public static final Set RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ID, NAME, DESCRIPTION, ISCASHPAYMENT)); public static final Set CREATE_PAYMENT_TYPE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(NAME, DESCRIPTION, ISCASHPAYMENT, POSITION)); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/data/PaymentTypeDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/data/PaymentTypeDataValidator.java index 6b52bf0c6..17107ce87 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/data/PaymentTypeDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/data/PaymentTypeDataValidator.java @@ -54,13 +54,13 @@ public class PaymentTypeDataValidator { if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.DESCRIPTION, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.DESCRIPTION, element); - baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).notExceedingLengthOf(500); + baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).ignoreIfNull().notExceedingLengthOf(500); } if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element)) { final Boolean isCashPayment = this.fromApiJsonHelper .extractBooleanNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element); - baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment); + baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment).validateForBooleanValue(); } if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.POSITION, element)) { @@ -100,13 +100,13 @@ public class PaymentTypeDataValidator { if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.DESCRIPTION, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.DESCRIPTION, element); - baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).notExceedingLengthOf(500); + baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).ignoreIfNull().notExceedingLengthOf(500); } if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element)) { final Boolean isCashPayment = this.fromApiJsonHelper .extractBooleanNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element); - baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment); + baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment).validateForBooleanValue(); } if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.POSITION, element)) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java index 437445a81..f313a9e7d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java @@ -23,21 +23,8 @@ import org.springframework.stereotype.Service; @Service public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService { - // private final static Logger logger = - // LoggerFactory.getLogger(MifosEntityAccessWriteServiceImpl.class); private final PaymentTypeRepository repository; private final PaymentTypeRepositoryWrapper repositoryWrapper; - - /* - * private final CodeValueRepositoryWrapper codeValueRepositoryWrapper; - * private final MifosEntityAccessRepository entityAccessRepository; private - * final MifosEntityRelationRepositoryWrapper - * mifosEntityRelationRepositoryWrapper; private final - * MifosEntityToEntityMappingRepository - * mifosEntityToEntityMappingRepository; private final - * MifosEntityToEntityMappingRepositoryWrapper - * mifosEntityToEntityMappingRepositoryWrapper; - */ private final PaymentTypeDataValidator fromApiJsonDeserializer; @Autowired @@ -64,7 +51,7 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService { @Override public CommandProcessingResult updatePaymentType(Long paymentTypeId, JsonCommand command) { - // TODO Auto-generated method stub + this.fromApiJsonDeserializer.validateForUpdate(command.json()); final PaymentType paymentType = this.repositoryWrapper.findOneWithNotFoundDetection(paymentTypeId); final Map changes = paymentType.update(command); @@ -78,15 +65,26 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService { @Override public CommandProcessingResult deletePaymentType(Long paymentTypeId) { - // TODO Auto-generated method stub final PaymentType paymentType = this.repositoryWrapper.findOneWithNotFoundDetection(paymentTypeId); try { this.repository.delete(paymentType); + this.repository.flush(); } catch (final DataIntegrityViolationException e) { - throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", - "Unknown data integrity issue with resource: " + e.getMostSpecificCause()); + handleDataIntegrityIssues(e); } return new CommandProcessingResultBuilder().withEntityId(paymentType.getId()).build(); } + private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) { + + final Throwable realCause = dve.getMostSpecificCause(); + if (realCause.getMessage().contains("acc_product_mapping")) { + throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist", + "cannot.delete.payment.type.with.association"); + } else if (realCause.getMessage().contains("payment_type_id")) { throw new PlatformDataIntegrityException( + "error.msg.payment.type.association.exist", "cannot.delete.payment.type.with.association"); } + + throw new PlatformDataIntegrityException("error.msg.paymenttypes.unknown.data.integrity.issue", + "Unknown data integrity issue with resource."); + } }