diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 3e00b3122..21c4576db 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -404,7 +404,7 @@ - + clients/{clientId}/charges/{clientChargeId}?command=pay Pay a Client Charge @@ -415,7 +415,7 @@ clients/{clientId}/charges/{clientChargeId}?command=waive - Waive a Client Charge + Waive a Client Charge @@ -424,7 +424,7 @@ Client Transactions clients/{clientId}/transactions - List Client Transactions + List Client Transactions @@ -439,7 +439,7 @@ - + @@ -1504,8 +1504,8 @@ - - + + Collection Sheet collectionsheet?command=generateCollectionSheet @@ -1679,7 +1679,7 @@ - + Provisioning Entries provisioningentries @@ -1697,7 +1697,7 @@ Add Provisioning Journal Entries - + @@ -2912,6 +2912,99 @@ + +
+

SPM

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
RESOURCES
+
+ + + + + + +
POST
create/complex + update
+ + + + + + +
GET
read
+ + + + + + +
PUT
update
+ + + + + + +
DELETE
delete
SurveysurveysCreate a SurveyList Surveys
surveys/{id}Retrieve a SurveyDeactivate a Survey
Lookup Tablesurveys/{id}/lookuptablesCreate a Lookup Table entryList Lookup Table entries
surveys/{id}/lookuptables/{id}Retrieve an Entry
Scorecardsurveys/{id}/scorecardsCreate a Scorecard entryList Scorecard entries
+
+
+
+
@@ -3124,7 +3217,7 @@

Default authentication is using HTTP Basic Auth. Oauth2 can be enabled by using -Psecurity=oauth option on gradle build command , refer - the platform setup wiki for additional details. + the platform setup wiki for additional details.

The platform has been configured to reject plain HTTP requests and @@ -3253,7 +3346,7 @@ function executeAjaxRequest(url, verbType, jsonData, authKey, successFunction, e

- +  
@@ -5731,7 +5824,7 @@ Request Body: POST collectionsheet?command=generateCollectionSheet Content-Type: application/json Request Body: -{ +{ "dateFormat":"dd MMMM yyyy", "locale":"en", "transactionDate":"15 January 2015", @@ -5812,7 +5905,7 @@ Request Body:
- +  
@@ -5849,13 +5942,13 @@ Request Body: }
-
+  

Save Collection Sheet

-

This Api allows the loan officer to perform bulk repayments of individual loans and deposit of mandatory savings on a given meeting date.

+

This Api allows the loan officer to perform bulk repayments of individual loans and deposit of mandatory savings on a given meeting date.

POST https://Domain Name/api/v1/collectionsheet?command=saveCollectionSheet @@ -5891,7 +5984,7 @@ Request Body:
- +  
@@ -8940,7 +9033,7 @@ Request Body: expectedDisbursementDate - +
@@ -9813,8 +9906,8 @@ Request Body:
- - + +  
@@ -9824,7 +9917,7 @@ Request Body:
POST https://DomainName/api/v1/loans/{loanId}/transactions?command=prepayLoan or
- + https://DomainName/api/v1/loans/{loanId}/transactions?command=prepayLoan&dateFormat=dd+MMMM+yyyy&locale=en&transactionDate=02+April+2015
@@ -9845,7 +9938,7 @@ Request Body:
- +  
@@ -11844,7 +11937,7 @@ Request Body: canDefineInstallmentAmount - if provided as true, then fixed instalment amount can be provided from loan account. + if provided as true, then fixed instalment amount can be provided from loan account. @@ -11977,7 +12070,7 @@ An enumeration that indicates the type of transaction processing strategy to be Specifies compounding frequency start date for interest recalculation.
- + recalculationRestFrequencyType @@ -13328,7 +13421,7 @@ GET https://DomainName/api/v1/loanproducts/{productId} isArrearsBasedOnOriginalSchedule, preClosureInterestCalculationStrategy - +
@@ -13336,7 +13429,7 @@ GET https://DomainName/api/v1/loanproducts/{productId}
Additional Optional Fields if interest recalculation is enabled(true) and recalculationRestFrequencyType is not same as repayment period
recalculationRestFrequencyInterval, recalculationRestFrequencyDate
- +
@@ -13344,9 +13437,9 @@ GET https://DomainName/api/v1/loanproducts/{productId}
Additional Optional Fields if interest recalculation is enabled(true) and interestRecalculationCompoundingMethod is enabled
recalculationCompoundingFrequencyType
- +
- @@ -13408,7 +13501,7 @@ Request Body: } ], "allowAttributeOverrides": - {amortizationType : true, + {amortizationType : true, interestType : true, transactionProcessingStrategyId : false, interestCalculationPeriodType : true, @@ -13416,7 +13509,7 @@ Request Body: repaymentEvery : true, graceOnPrincipalAndInterestPayment : true, graceOnArrearsAgeing : true}, - + "accountingRule":"2", "name":"product 5", "shortName":"prd5", @@ -14278,7 +14371,7 @@ Request Body: - +
Additional Optional Fields if interest recalculation is enabled(true) and interestRecalculationCompoundingMethod is enabled and +
Additional Optional Fields if interest recalculation is enabled(true) and interestRecalculationCompoundingMethod is enabled and recalculationCompoundingFrequencyType is not same as repayment period
locale must be provided.
@@ -16779,7 +16872,7 @@ POST scheduler?command=stop - +  
@@ -16797,11 +16890,11 @@ POST scheduler?command=stop
  • host -
  • port -
  • useTLS -
  • - +
    - +  
    @@ -16816,7 +16909,7 @@ POST scheduler?command=stop GET https://DomainName/api/v1/externalservice/{serviceName} - + [ { @@ -16845,7 +16938,7 @@ GET https://DomainName/api/v1/externalservice/{serviceName}
    - +  
    @@ -16863,7 +16956,7 @@ Content-Type: application/json { "username" : "test@mifos.org" "password" : "XXXX" -} +}
    @@ -17204,8 +17297,8 @@ Request Body: - - + +  
    @@ -17347,7 +17440,7 @@ Request Body:
    -
    incomeAccount
    This field is Optional and can be used only when a charge is applied to a Client. It indicates the Income or Liability account which gets + This field is Optional and can be used only when a charge is applied to a Client. It indicates the Income or Liability account which gets credited when a payment is made on this charge
    @@ -29448,7 +29541,7 @@ Request Body: class="old-syle-anchor"> 
    -

    Retreive surveys

    +

    Retrieve surveys

    Retrieve surveys. This allows to retrieve the list of survey tables registered .

    @@ -29585,7 +29678,7 @@ Request Body: class="old-syle-anchor"> 
    -

    Retreive survey

    +

    Retrieve survey

    Lists a registered survey table details and the Mifos X Core application table they are registered to.

    @@ -30897,7 +30990,7 @@ No Request Body Mandatory field. - Indicates the client application identity. + Indicates the client application identity. @@ -30905,7 +30998,7 @@ No Request Body Optional field. - Indicates the client application password. + Indicates the client application password. @@ -30913,7 +31006,7 @@ No Request Body Mandatory field. - Application User(resource) login name. + Application User(resource) login name. @@ -30921,7 +31014,7 @@ No Request Body Mandatory field. - Application User(resource) password. + Application User(resource) password. @@ -30953,8 +31046,8 @@ No Request Body
    - - + +  
    @@ -30978,7 +31071,7 @@ No Request Body Mandatory field. - Indicates the client application identity. + Indicates the client application identity. @@ -30986,7 +31079,7 @@ No Request Body Optional field. - Indicates the client application password. + Indicates the client application password. @@ -30994,7 +31087,7 @@ No Request Body Mandatory field. - Application refresh token to generate access token. + Application refresh token to generate access token. @@ -31113,7 +31206,7 @@ No Request Body
    - +  
    @@ -31440,8 +31533,8 @@ GET https://DomainName/api/v1/roles
    - - + +  
    @@ -31460,7 +31553,7 @@ No Request Body { "resourceId":1 -} +}
    @@ -31585,7 +31678,7 @@ GET https://DomainName/api/v1/roles/{roleId}/permissions
    - +  
    @@ -31598,17 +31691,17 @@ POST https://DomainName/api/v1/roles/{roleId}?command=enable POST roles/1?command=enable -Content-Type: application/json +Content-Type: application/json No Request Body { "resourceId":1 -} +}
    - +  
    @@ -31621,7 +31714,7 @@ POST https://DomainName/api/v1/roles/{roleId}?command=disable POST roles/1?command=disable -Content-Type: application/json +Content-Type: application/json No Request Body @@ -31797,7 +31890,7 @@ GET https://DomainName/api/v1/passwordpreferences/template ]
    - +
    GET https://DomainName/api/v1/passwordpreferences/ @@ -33703,11 +33796,11 @@ Request Body: Boolean variable whether to add journal entries for generated provisioning entries - +
    - +  
    @@ -33750,7 +33843,7 @@ Request Body: "locale":"en", "dateFormat":"dd MMMM yyyy", "createjournalentries":true - } + } { @@ -33759,14 +33852,14 @@ Request Body:
    - +  

    List all Provisioning Entries

    List all Provisioning Entries

    - +
    @@ -33777,8 +33870,8 @@ Request Body: Content-Type: application/json Request Body: { - - } + + } {[ @@ -33789,14 +33882,14 @@ Request Body:
    - +  

    Retrieves a Provisioning Entry

    Returns the details of a generated Provisioning Entry.

    - +
    @@ -33807,14 +33900,14 @@ Request Body: Content-Type: application/json Request Body: { - - } + + } { - "id":1, - "journalEntry":true, - "createdUser":"mifos", + "id":1, + "journalEntry":true, + "createdUser":"mifos", "createdDate":"16 October 2014", "provisioningEntries":[ {"historyId":1, @@ -33831,9 +33924,9 @@ Request Body: "expenseAccount":6, "expenseCode":"Expense Account Name" }, - {"id":2, - "journalEntry":true, - "createdUser":"mifos", + {"id":2, + "journalEntry":true, + "createdUser":"mifos", "createdDate":"16 October 2014", "provisioningEntries":[ {"historyId":1, @@ -33851,20 +33944,20 @@ Request Body: "expenseCode":"Expense Account Name" } ] - + }
    - - + +  

    Recreates Provisioning Entry

    Recreates Provisioning Entry.

    - +
    @@ -33876,7 +33969,7 @@ Request Body: Request Body: { "command":"recreateprovisioningentry" - } + } { @@ -33885,14 +33978,14 @@ Request Body:
    - +  

    Retrieves a Provisioning Entry

    Returns the details of a generated Provisioning Entry.

    - +
    @@ -33904,9 +33997,9 @@ Request Body: Request Body: { "command":"createjournalentry" - } + } - + { "resourceId": 1 @@ -33914,8 +34007,8 @@ Request Body:
    - - + + @@ -34053,7 +34146,7 @@ GET https://DomainName/api/v1/search?query=000000111 } ] - + GET https://DomainName/api/v1/search?query=000000001&exactMatch=true @@ -36002,11 +36095,11 @@ No Request Body: Define minimum, maximum, percentage, liability account, expense account for all provisioning categories - + - +  
    @@ -36045,21 +36138,21 @@ No Request Body: "criteriaName":"High Risk Products Criteria", "loanProducts": [ {"id": 1, - "name": "LOAN_PRODUCT_3ODPK1", + "name": "LOAN_PRODUCT_3ODPK1", "includeInBorrowerCycle": false}, {"id": 2, - "name": "LOAN_PRODUCT_BXW8NC", + "name": "LOAN_PRODUCT_BXW8NC", includeInBorrowerCycle": false} ], "provisioningcriteria": [ - {"categoryId": 1, - "categoryName": "STANDARD", - "minAge": 0, - "maxAge": 3, + {"categoryId": 1, + "categoryName": "STANDARD", + "minAge": 0, + "maxAge": 3, "provisioningPercentage": 1, - "liabilityAccount": 8, + "liabilityAccount": 8, "expenseAccount": 14}, - {"categoryId": 2, + {"categoryId": 2, "categoryName": "SUB-STANDARD", "minAge": 1, "maxAge": 5, @@ -36078,9 +36171,9 @@ No Request Body: "minAge": 3, "maxAge": 7, "provisioningPercentage": 4, - "liabilityAccount": 10, + "liabilityAccount": 10, "expenseAccount": 9}] - } + } { @@ -36104,8 +36197,8 @@ No Request Body: GET provisioningcriteria Content-Type: application/json Request Body: - { - } + { + } { @@ -36116,7 +36209,7 @@ No Request Body: {"criteriaId":2, "criteriaName":"Low Risk Products Criteria", "createdBy":"mifos"} - ] + ] }
    @@ -36136,8 +36229,8 @@ No Request Body: GET provisioningcriteria/{criteriaId} Content-Type: application/json Request Body: - { - } + { + } { @@ -36145,21 +36238,21 @@ No Request Body: "criteriaName":"High Risk Products Criteria", "loanProducts": [ {"id": 1, - "name": "LOAN_PRODUCT_3ODPK1", + "name": "LOAN_PRODUCT_3ODPK1", "includeInBorrowerCycle": false}, {"id": 2, - "name": "LOAN_PRODUCT_BXW8NC", + "name": "LOAN_PRODUCT_BXW8NC", includeInBorrowerCycle": false} ], "provisioningcriteria": [ - {"categoryId": 1, - "categoryName": "STANDARD", - "minAge": 0, - "maxAge": 3, + {"categoryId": 1, + "categoryName": "STANDARD", + "minAge": 0, + "maxAge": 3, "provisioningPercentage": 1, - "liabilityAccount": 8, + "liabilityAccount": 8, "expenseAccount": 14}, - {"categoryId": 2, + {"categoryId": 2, "categoryName": "SUB-STANDARD", "minAge": 1, "maxAge": 5, @@ -36178,7 +36271,7 @@ No Request Body: "minAge": 3, "maxAge": 7, "provisioningPercentage": 4, - "liabilityAccount": 10, + "liabilityAccount": 10, "expenseAccount": 9}] } @@ -36211,21 +36304,21 @@ No Request Body: "criteriaName":"High Risk Products Criteria1", "loanProducts": [ {"id": 1, - "name": "LOAN_PRODUCT_3ODPK1", + "name": "LOAN_PRODUCT_3ODPK1", "includeInBorrowerCycle": false}, {"id": 2, - "name": "LOAN_PRODUCT_BXW8NC", + "name": "LOAN_PRODUCT_BXW8NC", includeInBorrowerCycle": false} ], "provisioningcriteria": [ - {"categoryId": 1, - "categoryName": "STANDARD", - "minAge": 0, - "maxAge": 3, + {"categoryId": 1, + "categoryName": "STANDARD", + "minAge": 0, + "maxAge": 3, "provisioningPercentage": 1, - "liabilityAccount": 8, + "liabilityAccount": 8, "expenseAccount": 14}, - {"categoryId": 2, + {"categoryId": 2, "categoryName": "SUB-STANDARD", "minAge": 1, "maxAge": 5, @@ -36244,9 +36337,9 @@ No Request Body: "minAge": 3, "maxAge": 7, "provisioningPercentage": 4, - "liabilityAccount": 10, + "liabilityAccount": 10, "expenseAccount": 9}] - } + } { @@ -36274,7 +36367,7 @@ No Request Body: Content-Type: application/json Request Body: { - } + } { @@ -36282,7 +36375,7 @@ No Request Body: } - +   @@ -36324,7 +36417,7 @@ No Request Body: Array of ratePeriod JSON objects as defined in below section. - +

    This defines the Floating Rates Periods

    @@ -36359,7 +36452,7 @@ No Request Body:
    - +  
    @@ -36415,7 +36508,7 @@ No Request Body: "dateFormat":"dd MMMM yyyy" } ] - } + } { @@ -36526,7 +36619,7 @@ No Request Body:

    Update Floating Rate

    -

    Updates new Floating Rate. Rate Periods in the past cannot be modified. +

    Updates new Floating Rate. Rate Periods in the past cannot be modified. All the future rateperiods would be replaced with the new ratePeriods data sent.

    @@ -36555,7 +36648,7 @@ No Request Body: "dateFormat":"dd MMMM yyyy" } ] - } + } { @@ -36890,8 +36983,8 @@ Request Body:
    - - + +   @@ -36937,11 +37030,11 @@ Request Body: it specifies the due date - +
    - +  
    @@ -36992,7 +37085,7 @@ Request Body: Effective date of the transaction - +
    @@ -37015,9 +37108,9 @@ Request Body:
    Restricts the size of results returned. To override the default and return all entries you must explicitly pass a non-positive integer value for limit e.g. limit=0, or limit=-1
    -

    Example Requests:

    +

    Example Requests:

    clients/189/transactions
    -
    clients/189/transactions?offset=10&limit=50
    +
    clients/189/transactions?offset=10&limit=50
    @@ -37171,7 +37264,7 @@ Request Body:

    List Client Charges

    - +

    The list capability of client charges supports pagination.

    Optional Arguments
    @@ -37193,9 +37286,9 @@ Request Body:
    Filters charges that are pending payment (neither paid or waived).
    -

    Example Requests:

    -
    clients/1/charges
    -
    clients/1/charges?offset=0&limit=5
    +

    Example Requests:

    +
    clients/1/charges
    +
    clients/1/charges?offset=0&limit=5
    @@ -37206,7 +37299,7 @@ GET clients/1/charges?limit=5&offset=0 Content-Type: application/json No Request Body - + { "totalFilteredRecords": 4, "pageItems": [ @@ -37363,8 +37456,8 @@ No Request Body "isWaived": true } ] -} - +} +
    @@ -37442,8 +37535,8 @@ GET https://DomainName/api/v1/clients/{clientId}/charges/{clientChargeId} }
    - - + +  
    @@ -37452,7 +37545,7 @@ GET https://DomainName/api/v1/clients/{clientId}/charges/{clientChargeId} Deletes a Client Charge on which no transactions have taken place (either payments or waivers).

    - + DELETE https://DomainName/api/v1/clients/{clientId}/charges/{clientChargeId} @@ -37474,7 +37567,7 @@ No Request Body

    Pay a Client Charge

    -
    Pay either a part of or the entire due amount for a charge. +
    Pay either a part of or the entire due amount for a charge.

    @@ -37486,10 +37579,10 @@ No Request Body
    -
    +
    - + POST https://DomainName/api/v1/clients/{clientId}/charges/{clientChargeId}?command=paycharge @@ -37505,7 +37598,7 @@ Request Body: } - + { "officeId":1, "clientId":189, @@ -37520,21 +37613,21 @@ Request Body:

    Waive a Client Charge

    -
    This API provides the facility of waiving off the remaining amount on a client charge +
    This API provides the facility of waiving off the remaining amount on a client charge

    - +
    - + POST https://DomainName/api/v1/clients/{clientId}/charges/{clientChargeId}?command=waive -POST clients/189/charges/157?command=waive +POST clients/189/charges/157?command=waive Content-Type: application/json No Request Body - + { "clientId":"189", "resourceId":157 @@ -37542,23 +37635,23 @@ No Request Body
    - +  

    Undo a Client Transaction

    - + POST https://DomainName/api/v1/clients/{clientId}/transactions/{transactionId}?command=undo -POST clients/189/transactions/222?command=undo +POST clients/189/transactions/222?command=undo Content-Type: application/json No Request Body - + { "officeId":1, "clientId":189, @@ -37566,8 +37659,8 @@ No Request Body }
    -
    - +
    +  
    @@ -37592,14 +37685,394 @@ No Request Body:
    + +   +
    +
    +

    SPM API

    +

    + The Mifos X SPM API provides the ability to create custom surveys to collect social performance measurentment data or any additional questionnaire a financial institute want to collect. +

    +
    +
    +   +
    +
    +

    Create a Survey

    +

    Adds a new survey to collect client related data.

    + + + + + + + +
    Mandatory Fields
    countryCode, key, name, questions, responses, sequenceNo, text, value
    +
    +
    + +POST https://DomainName/api/v1/surveys + + +POST surveys +Content-Type: application/json +Request Body: +{ + "key":"ppi-kenya-2010", + "name":"PPI Survey for Kenya, version 2010", + "description":null, + "countryCode":"KE", + "validFrom":null, + "validTo":null, + "components": + [ + { + "key":"Household", + "text":"Information about the household." + "description":null, + "sequenceNo":1 + } + ] + "questions": + [ + { + "componentKey":"Household", + "key":"Familiy members", + "text":"How many persons live in the household?" + "description":null, + "sequenceNo":1, + "responses": + [ + { + "text":"1 to 3", + "value":1, + "sequenceNo":1 + }, + { + "text":"3 to 7", + "value":5, + "sequenceNo":2 + }, + { + "text":"more than 7", + "value":13, + "sequenceNo":3 + } + ] + } + ] +} + +200 OK + +
    +
    +   +
    +
    +

    List all Surveys

    +
    +
    + +GET https://DomainName/api/v1/surveys + + +GET surveys +Content-Type: application/json +No Request Body + + +[ + { + "id":1 + "key":"ppi-kenya-2010", + "name":"PPI Survey for Kenya, version 2010", + "description":null, + "countryCode":"KE", + "validFrom":"2015-11-25T00:00:00.000Z", + "validTo":"2115-12-31T23:59:59.999Z", + "components": + [ + { + "key":"Household", + "text":"Information about the household." + "description":null, + "sequenceNo":1 + } + ] + "questions": + [ + { + "componentKey":"Household", + "key":"Familiy members", + "text":"How many persons live in the household?" + "description":null, + "sequenceNo":1, + "responses": + [ + { + "text":"1 to 3", + "value":1, + "sequenceNo":1 + }, + { + "text":"3 to 7", + "value":5, + "sequenceNo":2 + }, + { + "text":"more than 7", + "value":13, + "sequenceNo":3 + } + ] + } + ] + } +] + +
    +
    +   +
    +
    +

    Retrieve a Survey

    +
    +
    + +GET https://DomainName/api/v1/surveys/1 + + +GET surveys/1 +Content-Type: application/json +No Request Body + + +{ + "id":1 + "key":"ppi-kenya-2010", + "name":"PPI Survey for Kenya, version 2010", + "description":null, + "countryCode":"KE", + "validFrom":"2015-11-25T00:00:00.000Z", + "validTo":"2115-12-31T23:59:59.999Z", + "components": + [ + { + "key":"Household", + "text":"Information about the household." + "description":null, + "sequenceNo":1 + } + ] + "questions": + [ + { + "componentKey":"Household", + "key":"Familiy members", + "text":"How many persons live in the household?" + "description":null, + "sequenceNo":1, + "responses": + [ + { + "text":"1 to 3", + "value":1, + "sequenceNo":1 + }, + { + "text":"3 to 7", + "value":5, + "sequenceNo":2 + }, + { + "text":"more than 7", + "value":13, + "sequenceNo":3 + } + ] + } + ] +} + +
    +
    +   +
    +
    +

    Deactivate Survey

    +
    +
    + +DELETE https://DomainName/api/v1/surveys/1 + + +DELETE surveys/1 +Content-Type: application/json +No Request Body + + +200 OK + +
    +
    +   +
    +
    +

    Create a Lookup Table entry

    +

    Add a new netry to a survey.

    + + + + + + + +
    Mandatory Fields
    key, score, validFrom, validTo
    +
    +
    + +POST https://DomainName/api/v1/surveys/1/lookuptables + + +POST surveys/1/lookuptables +Content-Type: application/json +Request Body: +{ + "key":"lookup-table-1", + "description":null, + "valueFrom":0, + "valueTo":5, + "score":100.00 +} + + +200 OK + +
    +
    +   +
    +
    +

    List all Lookup Table entries

    +

    List all Lookup Table entries for a survey.

    +
    +
    + +GET https://DomainName/api/v1/surveys/1/lookuptables + + +GET surveys/1/lookuptables +Content-Type: application/json +No Request Body + + +[ + { + "id":1 + "key":"lookup-table-1", + "description":null, + "valueFrom":0, + "valueTo":5, + "score":100.00 + } +] + +
    +
    +   +
    +
    +

    Retrieve a Lookup Table entry

    +

    Retrieve a Lookup Table entry for a survey.

    +
    +
    + +GET https://DomainName/api/v1/surveys/1/lookuptables/1 + + +GET surveys/1/lookuptables/1 +Content-Type: application/json +No Request Body + + +{ + "id":1, + "key":"lookup-table-1", + "description":null, + "valueFrom":0, + "valueTo":5, + "score":100.00 +} + +
    +
    - - - - - - +   +
    +
    +

    Create a Scorecard entry

    +

    Add a new netry to a survey.

    + + + + + + + +
    Mandatory Fields
    clientId, createdOn, questionId, responseId, staffId
    +
    +
    + +POST https://DomainName/api/v1/surveys/1/scorecards + + +POST surveys/1/scorecards +Content-Type: application/json +Request Body: +{ + "questionId":1, + "responseId":1, + "staffId":1, + "clientId":1, + "createdOn":"2015-11-26T09:50:34.647Z" +} + + +200 OK + +
    +
    +   +
    +
    +

    List all Scorecard entries

    +

    List all Scorecard entries for a survey.

    +
    +
    + +GET https://DomainName/api/v1/surveys/1/scorecards + + +GET surveys/1/scorecards +Content-Type: application/json +No Request Body + + +[ + { + "questionId":1, + "responseId":1, + "staffId":1, + "clientId":1, + "createdOn":"2015-11-26T09:50:34.647Z" + } +] + +
    +
    +
    diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java new file mode 100644 index 000000000..e70ceb271 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java @@ -0,0 +1,104 @@ +/** + * 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.spm.api; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.spm.data.LookupTableData; +import org.mifosplatform.spm.domain.LookupTable; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.exception.LookupTableNotFoundException; +import org.mifosplatform.spm.exception.SurveyNotFoundException; +import org.mifosplatform.spm.service.LookupTableService; +import org.mifosplatform.spm.service.SpmService; +import org.mifosplatform.spm.util.LookupTableMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; +import java.util.List; + +@Path("/surveys/{surveyId}/lookuptables") +@Component +@Scope("singleton") +public class LookupTableApiResource { + + private final PlatformSecurityContext securityContext; + private final SpmService spmService; + private final LookupTableService lookupTableService; + + @Autowired + public LookupTableApiResource(final PlatformSecurityContext securityContext, + final SpmService spmService, + final LookupTableService lookupTableService) { + super(); + this.securityContext = securityContext; + this.spmService = spmService; + this.lookupTableService = lookupTableService; + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public List fetchLookupTables(@PathParam("surveyId") final Long surveyId) { + this.securityContext.authenticatedUser(); + + final Survey survey = findSurvey(surveyId); + + final List result = new ArrayList<>(); + + final List lookupTables = this.lookupTableService.findBySurvey(survey); + + if (lookupTables != null) { + for (final LookupTable lookupTable : lookupTables) { + result.add(LookupTableMapper.map(lookupTable)); + } + } + + return result; + } + + @GET + @Path("/{id}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public LookupTableData findLookupTable(@PathParam("surveyId") final Long surveyId, + @PathParam("id") final Long id) { + this.securityContext.authenticatedUser(); + + findSurvey(surveyId); + + final LookupTable lookupTable = this.lookupTableService.findById(id); + + if (lookupTable == null) { + throw new LookupTableNotFoundException(id); + } + + return LookupTableMapper.map(lookupTable); + } + + @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public void createLookupTable(@PathParam("surveyId") final Long surveyId, + final LookupTableData lookupTableData) { + this.securityContext.authenticatedUser(); + + final Survey survey = findSurvey(surveyId); + + this.lookupTableService.createLookupTable(LookupTableMapper.map(lookupTableData, survey)); + } + + private Survey findSurvey(final Long surveyId) { + final Survey survey = this.spmService.findById(surveyId); + if (survey == null) { + throw new SurveyNotFoundException(surveyId); + } + return survey; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java new file mode 100644 index 000000000..3bb7dd7f2 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java @@ -0,0 +1,105 @@ +/** + * 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.spm.api; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.organisation.staff.domain.Staff; +import org.mifosplatform.organisation.staff.domain.StaffRepository; +import org.mifosplatform.organisation.staff.exception.StaffNotFoundException; +import org.mifosplatform.portfolio.client.domain.Client; +import org.mifosplatform.portfolio.client.domain.ClientRepository; +import org.mifosplatform.portfolio.client.exception.ClientNotFoundException; +import org.mifosplatform.spm.data.ScorecardData; +import org.mifosplatform.spm.domain.Scorecard; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.exception.SurveyNotFoundException; +import org.mifosplatform.spm.service.ScorecardService; +import org.mifosplatform.spm.service.SpmService; +import org.mifosplatform.spm.util.ScorecardMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; +import java.util.List; + +@Path("/surveys/{surveyId}/scorecards") +@Component +@Scope("singleton") +public class ScorecardApiResource { + + private final PlatformSecurityContext securityContext; + private final SpmService spmService; + private final ScorecardService scorecardService; + private final StaffRepository staffRepository; + private final ClientRepository clientRepository; + + @Autowired + public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService, + final ScorecardService scorecardService, final StaffRepository staffRepository, + final ClientRepository clientRepository) { + super(); + this.securityContext = securityContext; + this.spmService = spmService; + this.scorecardService = scorecardService; + this.staffRepository = staffRepository; + this.clientRepository = clientRepository; + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public List findBySurvey(@PathParam("surveyId") final Long surveyId) { + this.securityContext.authenticatedUser(); + + final Survey survey = findSurvey(surveyId); + + final List result = new ArrayList<>(); + + final List scorecards = this.scorecardService.findBySurvey(survey); + + if (scorecards == null) { + for (final Scorecard scorecard : scorecards) { + result.add(ScorecardMapper.map(scorecard)); + } + } + + return result; + } + + @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) { + this.securityContext.authenticatedUser(); + + final Survey survey = findSurvey(surveyId); + + final Staff staff = this.staffRepository.findOne(scorecardData.getStaffId()); + + if (staff == null) { + throw new StaffNotFoundException(scorecardData.getStaffId()); + } + + final Client client = this.clientRepository.findOne(scorecardData.getClientId()); + + if (client == null) { + throw new ClientNotFoundException(scorecardData.getClientId()); + } + + this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, staff, client)); + } + + private Survey findSurvey(final Long surveyId) { + final Survey survey = this.spmService.findById(surveyId); + if (survey == null) { + throw new SurveyNotFoundException(surveyId); + } + return survey; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/SpmApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/SpmApiResource.java new file mode 100644 index 000000000..c994f6c3a --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/SpmApiResource.java @@ -0,0 +1,93 @@ +/** + * 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.spm.api; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.spm.data.SurveyData; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.exception.SurveyNotFoundException; +import org.mifosplatform.spm.service.SpmService; +import org.mifosplatform.spm.util.SurveyMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; +import java.util.List; + +@Path("/surveys") +@Component +@Scope("singleton") +public class SpmApiResource { + + private final PlatformSecurityContext securityContext; + private final SpmService spmService; + + @Autowired + public SpmApiResource(final PlatformSecurityContext securityContext, + final SpmService spmService) { + this.securityContext = securityContext; + this.spmService = spmService; + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public List fetchActiveSurveys() { + this.securityContext.authenticatedUser(); + + final List result = new ArrayList<>(); + + final List surveys = this.spmService.fetchValidSurveys(); + + if (surveys != null) { + for (final Survey survey : surveys) { + result.add(SurveyMapper.map(survey)); + } + } + + return result; + } + + @GET + @Path("/{id}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public SurveyData findSurvey(@PathParam("id") final Long id) { + this.securityContext.authenticatedUser(); + + final Survey survey = this.spmService.findById(id); + + if (survey == null) { + throw new SurveyNotFoundException(id); + } + + return SurveyMapper.map(survey); + } + + @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public void createSurvey(final SurveyData surveyData) { + this.securityContext.authenticatedUser(); + + final Survey survey = SurveyMapper.map(surveyData); + + this.spmService.createSurvey(survey); + } + + @DELETE + @Path("/{id}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public void deactivateSurvey(@PathParam("id") final Long id) { + this.securityContext.authenticatedUser(); + + this.spmService.deactivateSurvey(id); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ComponentData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ComponentData.java new file mode 100644 index 000000000..ee221e9e2 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ComponentData.java @@ -0,0 +1,59 @@ +/** + * 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.spm.data; + +public class ComponentData { + + private String key; + private String text; + private String description; + private Integer sequenceNo; + + public ComponentData() { + super(); + } + + public ComponentData(final String key, final String text, + final String description, final Integer sequenceNo) { + super(); + this.key = key; + this.text = text; + this.description = description; + this.sequenceNo = sequenceNo; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getText() { + return text; + } + + public void setText(String title) { + this.text = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java new file mode 100644 index 000000000..005f57610 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java @@ -0,0 +1,79 @@ +/** + * 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.spm.data; + +public class LookupTableData { + + private Long id; + private String key; + private String description; + private Integer valueFrom; + private Integer valueTo; + private Double score; + + public LookupTableData() { + super(); + } + + public LookupTableData(final Long id, final String key, final String description, final Integer valueFrom, + final Integer valueTo, final Double score) { + super(); + this.id = id; + this.key = key; + this.description = description; + this.valueFrom = valueFrom; + this.valueTo = valueTo; + this.score = score; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getValueFrom() { + return valueFrom; + } + + public void setValueFrom(Integer valueFrom) { + this.valueFrom = valueFrom; + } + + public Integer getValueTo() { + return valueTo; + } + + public void setValueTo(Integer valueTo) { + this.valueTo = valueTo; + } + + public Double getScore() { + return score; + } + + public void setScore(Double score) { + this.score = score; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/QuestionData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/QuestionData.java new file mode 100644 index 000000000..31f6d990f --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/QuestionData.java @@ -0,0 +1,81 @@ +/** + * 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.spm.data; + +import java.util.List; + +public class QuestionData { + + private List responseDatas; + private String componentKey; + private String key; + private String text; + private String description; + private Integer sequenceNo; + + public QuestionData() { + super(); + } + + public QuestionData(final List responseDatas, final String componentKey, final String key, + final String text, final String description, final Integer sequenceNo) { + super(); + this.responseDatas = responseDatas; + this.componentKey = componentKey; + this.key = key; + this.text = text; + this.description = description; + this.sequenceNo = sequenceNo; + } + + public List getResponseDatas() { + return responseDatas; + } + + public void setResponseDatas(List responseDatas) { + this.responseDatas = responseDatas; + } + + public String getComponentKey() { + return componentKey; + } + + public void setComponentKey(String componentKey) { + this.componentKey = componentKey; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ResponseData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ResponseData.java new file mode 100644 index 000000000..c96bafac8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ResponseData.java @@ -0,0 +1,49 @@ +/** + * 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.spm.data; + +public class ResponseData { + + private String text; + private Integer value; + private Integer sequenceNo; + + public ResponseData() { + super(); + } + + public ResponseData(final String text, final Integer value, + final Integer sequenceNo) { + super(); + this.text = text; + this.value = value; + this.sequenceNo = sequenceNo; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java new file mode 100644 index 000000000..fd1d511b3 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java @@ -0,0 +1,81 @@ +/** + * 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.spm.data; + +import java.util.Date; + +public class ScorecardData { + + private Long questionId; + private Long responseId; + private Long staffId; + private Long clientId; + private Date createdOn; + private Integer value; + + public ScorecardData() { + super(); + } + + public ScorecardData(final Long questionId, final Long responseId, final Long staffId, final Long clientId, + final Date createdOn, final Integer value) { + super(); + this.questionId = questionId; + this.responseId = responseId; + this.staffId = staffId; + this.clientId = clientId; + this.createdOn = createdOn; + this.value = value; + } + + public Long getQuestionId() { + return questionId; + } + + public void setQuestionId(Long questionId) { + this.questionId = questionId; + } + + public Long getResponseId() { + return responseId; + } + + public void setResponseId(Long responseId) { + this.responseId = responseId; + } + + public Long getStaffId() { + return staffId; + } + + public void setStaffId(Long staffId) { + this.staffId = staffId; + } + + public Long getClientId() { + return clientId; + } + + public void setClientId(Long clientId) { + this.clientId = clientId; + } + + public Date getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(Date createdOn) { + this.createdOn = createdOn; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/SurveyData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/SurveyData.java new file mode 100644 index 000000000..1cee8ee07 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/SurveyData.java @@ -0,0 +1,113 @@ +/** + * 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.spm.data; + +import java.util.Date; +import java.util.List; + +public class SurveyData { + + private Long id; + private List componentDatas; + private List questionDatas; + private String key; + private String name; + private String description; + private String countryCode; + private Date validFrom; + private Date validTo; + + public SurveyData() { + super(); + } + + public SurveyData(final Long id, final List componentDatas, final List questionDatas, + final String key, final String name, final String description, final String countryCode, + final Date validFrom, final Date validTo) { + super(); + this.id = id; + this.componentDatas = componentDatas; + this.questionDatas = questionDatas; + this.key = key; + this.name = name; + this.description = description; + this.countryCode = countryCode; + this.validFrom = validFrom; + this.validTo = validTo; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getComponentDatas() { + return componentDatas; + } + + public void setComponentDatas(List componentDatas) { + this.componentDatas = componentDatas; + } + + public List getQuestionDatas() { + return questionDatas; + } + + public void setQuestionDatas(List questionDatas) { + this.questionDatas = questionDatas; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + + public Date getValidFrom() { + return validFrom; + } + + public void setValidFrom(Date validFrom) { + this.validFrom = validFrom; + } + + public Date getValidTo() { + return validTo; + } + + public void setValidTo(Date validTo) { + this.validTo = validTo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Component.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Component.java new file mode 100644 index 000000000..4a21a7918 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Component.java @@ -0,0 +1,75 @@ +/** + * 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.spm.domain; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; + +@Entity +@Table(name = "m_survey_components") +public class Component extends AbstractPersistable { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + @Column(name = "a_key", length = 32) + private String key; + + @Column(name = "a_text", length = 255) + private String text; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "sequence_no", precision = 4) + private Integer sequenceNo; + + public Component() { + super(); + } + + public Survey getSurvey() { + return survey; + } + + public void setSurvey(Survey survey) { + this.survey = survey; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getText() { + return text; + } + + public void setText(String title) { + this.text = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/LookupTable.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/LookupTable.java new file mode 100644 index 000000000..f33e67e66 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/LookupTable.java @@ -0,0 +1,86 @@ +/** + * 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.spm.domain; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; + +@Entity +@Table(name = "m_survey_lookup_tables") +public class LookupTable extends AbstractPersistable { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + @Column(name = "a_key", length = 32) + private String key; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "value_from", precision = 4) + private Integer valueFrom; + + @Column(name = "value_to", precision = 4) + private Integer valueTo; + + @Column(name = "score", precision = 5, scale = 2) + private Double score; + + public LookupTable() { + super(); + } + + public Survey getSurvey() { + return survey; + } + + public void setSurvey(Survey survey) { + this.survey = survey; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getValueFrom() { + return valueFrom; + } + + public void setValueFrom(Integer valueFrom) { + this.valueFrom = valueFrom; + } + + public Integer getValueTo() { + return valueTo; + } + + public void setValueTo(Integer valueTo) { + this.valueTo = valueTo; + } + + public Double getScore() { + return score; + } + + public void setScore(Double score) { + this.score = score; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Question.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Question.java new file mode 100644 index 000000000..0d4c3c36f --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Question.java @@ -0,0 +1,99 @@ +/** + * 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.spm.domain; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; +import java.util.List; + +@Entity +@Table(name = "m_survey_questions") +public class Question extends AbstractPersistable { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + @OneToMany(mappedBy = "question", fetch = FetchType.EAGER) + @OrderBy("sequenceNo") + private List responses; + + @Column(name = "component_key", length = 32) + private String componentKey; + + @Column(name = "a_key", length = 32) + private String key; + + @Column(name = "a_text", length = 255) + private String text; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "sequence_no", precision = 4) + private Integer sequenceNo; + + public Question() { + super(); + } + + public Survey getSurvey() { + return survey; + } + + public void setSurvey(Survey survey) { + this.survey = survey; + } + + public List getResponses() { + return responses; + } + + public void setResponses(List responses) { + this.responses = responses; + } + + public String getComponentKey() { + return componentKey; + } + + public void setComponentKey(String componentKey) { + this.componentKey = componentKey; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Response.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Response.java new file mode 100644 index 000000000..93182f2ee --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Response.java @@ -0,0 +1,64 @@ +/** + * 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.spm.domain; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; + +@Entity +@Table(name = "m_survey_responses") +public class Response extends AbstractPersistable { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private Question question; + + @Column(name = "a_text", length = 255) + private String text; + + @Column(name = "a_value", precision = 4) + private Integer value; + + @Column(name = "sequence_no", precision = 4) + private Integer sequenceNo; + + public Response() { + super(); + } + + public Question getQuestion() { + return question; + } + + public void setQuestion(Question question) { + this.question = question; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public Integer getSequenceNo() { + return sequenceNo; + } + + public void setSequenceNo(Integer sequenceNo) { + this.sequenceNo = sequenceNo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Scorecard.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Scorecard.java new file mode 100644 index 000000000..5069ed8ac --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Scorecard.java @@ -0,0 +1,106 @@ +/** + * 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.spm.domain; + +import org.mifosplatform.organisation.staff.domain.Staff; +import org.mifosplatform.portfolio.client.domain.Client; +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Table(name = "m_survey_scorecards") +public class Scorecard extends AbstractPersistable { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private Question question; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "response_id") + private Response response; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "staff_id") + private Staff staff; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "client_id") + private Client client; + + @Column(name = "created_on") + @Temporal(value = TemporalType.TIMESTAMP) + @OrderBy("createdOn DESC") + private Date createdOn; + + @Column(name = "a_value", precision = 4) + private Integer value; + + public Scorecard() { + super(); + } + + public Survey getSurvey() { + return survey; + } + + public void setSurvey(Survey survey) { + this.survey = survey; + } + + public Question getQuestion() { + return question; + } + + public void setQuestion(Question question) { + this.question = question; + } + + public Response getResponse() { + return response; + } + + public void setResponse(Response response) { + this.response = response; + } + + public Staff getStaff() { + return staff; + } + + public void setStaff(Staff staff) { + this.staff = staff; + } + + public Client getClient() { + return client; + } + + public void setClient(Client client) { + this.client = client; + } + + public Date getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(Date createdOn) { + this.createdOn = createdOn; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Survey.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Survey.java new file mode 100644 index 000000000..4d61786f0 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/domain/Survey.java @@ -0,0 +1,113 @@ +/** + * 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.spm.domain; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +@Entity +@Table(name = "m_surveys") +public class Survey extends AbstractPersistable { + + @OneToMany(mappedBy = "survey", fetch = FetchType.EAGER) + @OrderBy("sequenceNo") + private List components; + + @OneToMany(mappedBy = "survey", fetch = FetchType.EAGER) + @OrderBy("sequenceNo") + private List questions; + + @Column(name = "a_key", length = 32) + private String key; + + @Column(name = "a_name", length = 255) + private String name; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "country_code", length = 2) + private String countryCode; + + @Column(name = "valid_from") + @Temporal(value = TemporalType.TIMESTAMP) + private Date validFrom; + + @Column(name = "valid_to") + @Temporal(value = TemporalType.TIMESTAMP) + private Date validTo; + + public Survey() { + super(); + } + + public List getComponents() { + return components; + } + + public void setComponents(List components) { + this.components = components; + } + + public List getQuestions() { + return questions; + } + + public void setQuestions(List questions) { + this.questions = questions; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + + public Date getValidFrom() { + return validFrom; + } + + public void setValidFrom(Date validFrom) { + this.validFrom = validFrom; + } + + public Date getValidTo() { + return validTo; + } + + public void setValidTo(Date validTo) { + this.validTo = validTo; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java new file mode 100644 index 000000000..560d147df --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java @@ -0,0 +1,15 @@ +/** + * 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.spm.exception; + +import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; + +public class LookupTableNotFoundException extends AbstractPlatformResourceNotFoundException { + + public LookupTableNotFoundException(final Long id) { + super("error.msg.survey.lookuptable.id.notfound", "Lookup table with id " + id + " not found!", id); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/SurveyNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/SurveyNotFoundException.java new file mode 100644 index 000000000..02598e625 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/SurveyNotFoundException.java @@ -0,0 +1,15 @@ +/** + * 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.spm.exception; + +import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; + +public class SurveyNotFoundException extends AbstractPlatformResourceNotFoundException { + + public SurveyNotFoundException(final Long id) { + super("error.msg.survey.id.notfound", "Survey with id " + id + " not found!", id); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java new file mode 100644 index 000000000..5b0e78dd1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java @@ -0,0 +1,17 @@ +/** + * 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.spm.repository; + +import org.mifosplatform.spm.domain.LookupTable; +import org.mifosplatform.spm.domain.Survey; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface LookupTableRepository extends JpaRepository { + + List findBySurvey(final Survey survey); +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/ScorecardRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/ScorecardRepository.java new file mode 100644 index 000000000..5076fabe0 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/ScorecardRepository.java @@ -0,0 +1,19 @@ +/** + * 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.spm.repository; + +import org.mifosplatform.portfolio.client.domain.Client; +import org.mifosplatform.spm.domain.Scorecard; +import org.mifosplatform.spm.domain.Survey; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ScorecardRepository extends JpaRepository { + + List findBySurvey(final Survey survey); + List findBySurveyAndClient(final Survey survey, final Client client); +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/SurveyRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/SurveyRepository.java new file mode 100644 index 000000000..8e644a90b --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/SurveyRepository.java @@ -0,0 +1,22 @@ +/** + * 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.spm.repository; + +import org.mifosplatform.spm.domain.Survey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Date; +import java.util.List; + +public interface SurveyRepository extends JpaRepository { + + @Query("select s from Survey s where :pointInTime between s.validFrom and s.validTo") + List fetchActiveSurveys(@Param("pointInTime") final Date pointInTime); + + Survey findByKey(final String key); +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java new file mode 100644 index 000000000..6b62fe86e --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java @@ -0,0 +1,48 @@ +/** + * 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.spm.service; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.spm.domain.LookupTable; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.repository.LookupTableRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class LookupTableService { + + private final PlatformSecurityContext securityContext; + private final LookupTableRepository lookupTableRepository; + + @Autowired + public LookupTableService(final PlatformSecurityContext securityContext, + final LookupTableRepository lookupTableRepository) { + super(); + this.securityContext = securityContext; + this.lookupTableRepository = lookupTableRepository; + } + + public LookupTable findById(final Long id) { + this.securityContext.authenticatedUser(); + + return this.lookupTableRepository.findOne(id); + } + + public List findBySurvey(final Survey survey) { + this.securityContext.authenticatedUser(); + + return this.lookupTableRepository.findBySurvey(survey); + } + + public LookupTable createLookupTable(final LookupTable lookupTable) { + this.securityContext.authenticatedUser(); + + return this.lookupTableRepository.save(lookupTable); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java new file mode 100644 index 000000000..d19e0fb70 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java @@ -0,0 +1,51 @@ +/** + * 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.spm.service; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.client.domain.Client; +import org.mifosplatform.spm.domain.Scorecard; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.repository.ScorecardRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +public class ScorecardService { + + private final PlatformSecurityContext securityContext; + private final ScorecardRepository scorecardRepository; + + @Autowired + public ScorecardService(final PlatformSecurityContext securityContext, + final ScorecardRepository scorecardRepository) { + super(); + this.securityContext = securityContext; + this.scorecardRepository = scorecardRepository; + } + + @Transactional + public Scorecard createScorecard(final Scorecard scorecard) { + this.securityContext.authenticatedUser(); + + return this.scorecardRepository.save(scorecard); + } + + public List findBySurvey(final Survey survey) { + this.securityContext.authenticatedUser(); + + return this.scorecardRepository.findBySurvey(survey); + } + + public List findBySurveyAndClient(final Survey survey, final Client client) { + this.securityContext.authenticatedUser(); + + return this.scorecardRepository.findBySurveyAndClient(survey, client); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/SpmService.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/SpmService.java new file mode 100644 index 000000000..7d884f91f --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/SpmService.java @@ -0,0 +1,100 @@ +/** + * 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.spm.service; + +import org.joda.time.DateTime; +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.spm.domain.Survey; +import org.mifosplatform.spm.repository.SurveyRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; + +@Service +public class SpmService { + + private final PlatformSecurityContext securityContext; + private final SurveyRepository surveyRepository; + + @Autowired + public SpmService(final PlatformSecurityContext securityContext, + final SurveyRepository surveyRepository) { + super(); + this.securityContext = securityContext; + this.surveyRepository = surveyRepository; + } + + public List fetchValidSurveys() { + this.securityContext.authenticatedUser(); + + return this.surveyRepository.fetchActiveSurveys(new Date()); + } + + public Survey findById(final Long id) { + this.securityContext.authenticatedUser(); + + return this.surveyRepository.findOne(id); + } + + @Transactional + public Survey createSurvey(final Survey survey) { + this.securityContext.authenticatedUser(); + + final Survey previousSurvey = this.surveyRepository.findByKey(survey.getKey()); + + if (previousSurvey != null) { + this.deactivateSurvey(previousSurvey.getId()); + } + + // set valid from to start of today + final DateTime dateTime = DateTime + .now() + .withHourOfDay(0) + .withMinuteOfHour(0) + .withSecondOfMinute(0) + .withMillisOfSecond(0); + + survey.setValidFrom(dateTime.toDate()); + + // set valid from to end in 100 years + dateTime + .withDayOfMonth(31) + .withMonthOfYear(12) + .withHourOfDay(23) + .withMinuteOfHour(59) + .withSecondOfMinute(59) + .withMillisOfSecond(999) + .plusYears(100); + + survey.setValidTo(dateTime.toDate()); + + return this.surveyRepository.save(survey); + } + + @Transactional + public void deactivateSurvey(final Long id) { + this.securityContext.authenticatedUser(); + + final Survey survey = this.surveyRepository.findOne(id); + + if (survey != null) { + // set valid to to yesterday night + final DateTime dateTime = DateTime + .now() + .withHourOfDay(23) + .withMinuteOfHour(59) + .withSecondOfMinute(59) + .withMillisOfSecond(999) + .minusDays(1); + survey.setValidTo(dateTime.toDate()); + + this.surveyRepository.save(survey); + } + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java new file mode 100644 index 000000000..05f84b148 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java @@ -0,0 +1,36 @@ +/** + * 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.spm.util; + +import org.mifosplatform.spm.data.LookupTableData; +import org.mifosplatform.spm.domain.LookupTable; +import org.mifosplatform.spm.domain.Survey; + +public class LookupTableMapper { + + private LookupTableMapper() { + super(); + } + + public static LookupTableData map(final LookupTable lookupTable) { + final LookupTableData lookupTableData = new LookupTableData( + lookupTable.getId(), lookupTable.getKey(), lookupTable.getDescription(), lookupTable.getValueFrom(), + lookupTable.getValueFrom(), lookupTable.getScore() + ); + return lookupTableData; + } + + public static LookupTable map(final LookupTableData lookupTableData, final Survey survey) { + final LookupTable lookupTable = new LookupTable(); + lookupTable.setSurvey(survey); + lookupTable.setKey(lookupTableData.getKey()); + lookupTable.setDescription(lookupTableData.getDescription()); + lookupTable.setValueFrom(lookupTableData.getValueFrom()); + lookupTable.setValueTo(lookupTableData.getValueTo()); + lookupTable.setScore(lookupTableData.getScore()); + return lookupTable; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java new file mode 100644 index 000000000..1fbd26dde --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java @@ -0,0 +1,59 @@ +/** + * 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.spm.util; + +import org.mifosplatform.organisation.staff.domain.Staff; +import org.mifosplatform.portfolio.client.domain.Client; +import org.mifosplatform.spm.data.ScorecardData; +import org.mifosplatform.spm.domain.Question; +import org.mifosplatform.spm.domain.Response; +import org.mifosplatform.spm.domain.Scorecard; +import org.mifosplatform.spm.domain.Survey; + +import java.util.List; + +public class ScorecardMapper { + + private ScorecardMapper() { + super(); + } + + public static ScorecardData map(final Scorecard scorecard) { + final ScorecardData scorecardData = new ScorecardData( + scorecard.getQuestion().getId(), scorecard.getResponse().getId(), scorecard.getStaff().getId(), + scorecard.getClient().getId(), scorecard.getCreatedOn(), scorecard.getValue() + ); + return scorecardData; + } + + public static Scorecard map(final ScorecardData scorecardData, final Survey survey, + final Staff staff, final Client client) { + final Scorecard scorecard = new Scorecard(); + ScorecardMapper.setQuestionAndResponse(scorecardData, scorecard, survey); + scorecard.setStaff(staff); + scorecard.setClient(client); + scorecard.setCreatedOn(scorecardData.getCreatedOn()); + scorecard.setValue(scorecardData.getValue()); + return scorecard; + } + + private static void setQuestionAndResponse(final ScorecardData scorecardData, final Scorecard scorecard, + final Survey survey) { + final List questions = survey.getQuestions(); + for (final Question question : questions) { + if (question.getId().equals(scorecardData.getQuestionId())) { + scorecard.setQuestion(question); + for (final Response response : question.getResponses()) { + if (response.getId().equals(scorecardData.getResponseId())) { + scorecard.setResponse(response); + break; + } + } + break; + } + } + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/SurveyMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/SurveyMapper.java new file mode 100644 index 000000000..a2dcf5c00 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/SurveyMapper.java @@ -0,0 +1,130 @@ +/** + * 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.spm.util; + +import org.mifosplatform.spm.data.ComponentData; +import org.mifosplatform.spm.data.QuestionData; +import org.mifosplatform.spm.data.ResponseData; +import org.mifosplatform.spm.data.SurveyData; +import org.mifosplatform.spm.domain.Component; +import org.mifosplatform.spm.domain.Question; +import org.mifosplatform.spm.domain.Response; +import org.mifosplatform.spm.domain.Survey; + +import java.util.ArrayList; +import java.util.List; + +public class SurveyMapper { + + private SurveyMapper() { + super(); + } + + public static SurveyData map(final Survey survey) { + final SurveyData surveyData = new SurveyData( + survey.getId(), SurveyMapper.mapComponents(survey.getComponents()), + SurveyMapper.mapQuestions(survey.getQuestions()), survey.getKey(), survey.getName(), + survey.getDescription(), survey.getCountryCode(), survey.getValidFrom(), survey.getValidTo() + ); + return surveyData; + } + + public static Survey map(final SurveyData surveyData) { + final Survey survey = new Survey(); + survey.setComponents(SurveyMapper.mapComponentDatas(surveyData.getComponentDatas())); + survey.setQuestions(SurveyMapper.mapQuestionDatas(surveyData.getQuestionDatas(), survey)); + survey.setKey(surveyData.getKey()); + survey.setName(surveyData.getName()); + survey.setDescription(surveyData.getDescription()); + survey.setCountryCode(surveyData.getCountryCode()); + return survey; + } + + private static List mapComponents(final List components) { + final List componentDatas = new ArrayList<>(); + if (components != null) { + for (final Component component : components) { + componentDatas.add(new ComponentData( + component.getKey(), component.getText(), component.getDescription(), component.getSequenceNo() + )); + } + } + return componentDatas; + } + + private static List mapComponentDatas(final List componentDatas) { + final List components = new ArrayList<>(); + if (componentDatas != null) { + for (final ComponentData componentData : componentDatas) { + final Component component = new Component(); + component.setKey(componentData.getKey()); + component.setText(componentData.getText()); + component.setDescription(componentData.getDescription()); + component.setSequenceNo(componentData.getSequenceNo()); + components.add(component); + } + } + return components; + } + + private static List mapQuestions(final List questions) { + final List questionDatas = new ArrayList<>(); + if (questions != null) { + for (final Question question : questions) { + questionDatas.add(new QuestionData( + SurveyMapper.mapResponses(question.getResponses()), question.getComponentKey(), question.getKey(), + question.getText(), question.getDescription(), question.getSequenceNo() + )); + } + } + return questionDatas; + } + + private static List mapQuestionDatas(final List questionDatas, final Survey survey) { + final List questions = new ArrayList<>(); + if (questionDatas != null) { + for (final QuestionData questionData : questionDatas) { + final Question question = new Question(); + question.setSurvey(survey); + question.setComponentKey(questionData.getComponentKey()); + question.setResponses(SurveyMapper.mapResponseDatas(questionData.getResponseDatas(), question)); + question.setKey(questionData.getKey()); + question.setText(questionData.getText()); + question.setDescription(question.getDescription()); + question.setSequenceNo(questionData.getSequenceNo()); + questions.add(question); + } + } + return questions; + } + + private static List mapResponses(final List responses) { + final List responseDatas = new ArrayList<>(); + if (responses != null) { + for (final Response response : responses) { + responseDatas.add(new ResponseData( + response.getText(), response.getValue(), response.getSequenceNo() + )); + } + } + return responseDatas; + } + + private static List mapResponseDatas(final List responseDatas, final Question question) { + final List responses = new ArrayList<>(); + if (responseDatas != null) { + for (final ResponseData responseData : responseDatas) { + final Response response = new Response(); + response.setQuestion(question); + response.setText(responseData.getText()); + response.setValue(responseData.getValue()); + response.setSequenceNo(responseData.getSequenceNo()); + responses.add(response); + } + } + return responses; + } +} diff --git a/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml b/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml index 26e8abead..7b864d0d5 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml @@ -85,4 +85,5 @@ + diff --git a/mifosng-provider/src/main/resources/META-INF/spring/spmContext.xml b/mifosng-provider/src/main/resources/META-INF/spring/spmContext.xml new file mode 100644 index 000000000..71a37b35d --- /dev/null +++ b/mifosng-provider/src/main/resources/META-INF/spring/spmContext.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/mifosng-provider/src/main/resources/sql/migrations/core_db/V280__spm_framework_initial_tables.sql b/mifosng-provider/src/main/resources/sql/migrations/core_db/V280__spm_framework_initial_tables.sql new file mode 100644 index 000000000..478df21aa --- /dev/null +++ b/mifosng-provider/src/main/resources/sql/migrations/core_db/V280__spm_framework_initial_tables.sql @@ -0,0 +1,72 @@ +CREATE TABLE `m_surveys` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `a_key` VARCHAR(32) NOT NULL, + `a_name` VARCHAR(255) NOT NULL, + `description` VARCHAR(4000) NULL, + `country_code` VARCHAR(2) NOT NULL, + `valid_from` DATETIME NULL DEFAULT NULL, + `valid_to` DATETIME NULL DEFAULT NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `m_survey_components` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `survey_id` BIGINT(20) NOT NULL, + `a_key` VARCHAR(32) NOT NULL, + `a_text` VARCHAR(255) NOT NULL, + `description` VARCHAR(4000) NULL, + `sequence_no` INT(4) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`) +); + +CREATE TABLE `m_survey_questions` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `survey_id` BIGINT(20) NOT NULL, + `component_key` VARCHAR(32) NULL, + `a_key` VARCHAR(32) NOT NULL, + `a_text` VARCHAR(255) NOT NULL, + `description` VARCHAR(4000) NULL, + `sequence_no` INT(4) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`) +); + +CREATE TABLE `m_survey_responses` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `question_id` BIGINT(20) NOT NULL, + `a_text` VARCHAR(255) NOT NULL, + `a_value` INT(4) NOT NULL, + `sequence_no` INT(4) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`) +); + +CREATE TABLE `m_survey_lookup_tables` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `survey_id` BIGINT(20) NOT NULL, + `a_key` VARCHAR(255) NOT NULL, + `description` INT(4) NULL, + `value_from` INT(4) NOT NULL, + `value_to` INT(4) NOT NULL, + `score` DECIMAL(5, 2) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`) +); + +CREATE TABLE `m_survey_scorecards` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `survey_id` BIGINT(20) NOT NULL, + `question_id` BIGINT(20) NOT NULL, + `response_id` BIGINT(20) NOT NULL, + `staff_id` BIGINT(20) NOT NULL, + `client_id` BIGINT(20) NOT NULL, + `created_on` DATETIME NULL DEFAULT NULL, + `a_value` INT(4) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`), + FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`), + FOREIGN KEY (`response_id`) REFERENCES `m_survey_responses` (`id`), + FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`), + FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`) +); \ No newline at end of file