diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 3d990ff36..86d319a1e 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -288,7 +288,7 @@ Create a Center List Centers - Delete a Center + @@ -296,7 +296,7 @@ Retrieve a Center Update a Center - + Delete a Center Group @@ -304,7 +304,7 @@ Create a Group List Groups - Delete a Group + @@ -312,7 +312,7 @@ Retrieve a Group Update a Group - + Delete a Group @@ -2705,12 +2705,33 @@ No Request Body:
Field Descriptions
+ + externalId + + + A place to put an external reference for this center e.g. The ID another system uses. If provided, it must be unique. + + name Name given to the Center. + + active + + + Indicates whether this center is to be created as active. If active=true, then activationDate must be provided. If active=false, then the center is created as pending. + + + + activationDate + + + The date on which the center became active. + + officeId @@ -2724,11 +2745,10 @@ No Request Body: The staffId of the staff member dealing with this center. The staff member is not specifically the loan officer. - externalId + groupMembers - A place to put an external reference for this center e.g. The ID another system uses. If provided, it must be unique. - + The array of groupIds to indicate what groups are part of this center. @@ -2749,6 +2769,13 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template { + "active": false, + "activationDate": [ + 2013, + 4, + 18 + ], + "officeId": 1, "officeOptions": [ { "id": 1, @@ -2757,18 +2784,31 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template }, { "id": 2, - "name": "Suboffice", - "nameDecorated": "....Suboffice" + "name": "Branch Office 1", + "nameDecorated": "....Branch Office 1" } ], "staffOptions": [ { "id": 1, - "displayName": "LoanOfficer, HeadOffice" + "displayName": "C, Mike" + } + ], + "groupMembersOptions": [ + { + "id": 1, + "name": "First Group", + "externalId": "000-1A", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".1." }, { "id": 2, - "displayName": "NonLoanOfficer, HeadOffice" + "name": "Pending Group", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".2." } ] } @@ -2780,6 +2820,12 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template?officeId=2 { + "active": false, + "activationDate": [ + 2013, + 4, + 18 + ], "officeId": 2, "officeOptions": [ { @@ -2789,18 +2835,18 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template?officeId=2 }, { "id": 2, - "name": "Suboffice", - "nameDecorated": "....Suboffice" + "name": "Branch Office 1", + "nameDecorated": "....Branch Office 1" } ], "staffOptions": [ { - "id": 3, - "displayName": "LoanOfficer, Suboffice" + "id": 2, + "displayName": "D, Mary" }, { - "id": 4, - "displayName": "NonLoanOfficer, Suboffice" + "id": 3, + "displayName": "P, Paul" } ] } @@ -2817,7 +2863,7 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template?officeId=2
Mandatory Fields
- name, officeId + name, officeId, active, activationDate (if active=true)
@@ -2826,11 +2872,12 @@ GET https://DomainName/mifosng-provider/api/v1/centers/template?officeId=2
Optional Fields
- externalId, staffId + externalId, staffId, groupMembers
+

Creater a center as pending with no association to groupMembers.

POST https://DomainName/mifosng-provider/api/v1/centers @@ -2838,15 +2885,43 @@ POST https://DomainName/mifosng-provider/api/v1/centers POST centers Content-Type: application/json Request Body: { - "name": "apicenter", - "officeId": 2 + "name": "First Center (No groups)", + "officeId": 1, + "active": false }
{ - "officeId": 2, - "groupId": 4, - "resourceId": 4 + "officeId": 1, + "groupId": 8, + "resourceId": 8 +} + +
+ +
+

Creater a center as active with no association to groupMembers.

+ +POST https://DomainName/mifosng-provider/api/v1/centers + + +POST centers +Content-Type: application/json Request Body: +{ + "name": "centerwithgroup", + "officeId": 1, + "groupMembers": ["7"], + "locale": "en", + "dateFormat": "dd MMMM yyyy", + "active": true, + "activationDate": "01 March 2011" +} + + +{ + "officeId": 1, + "groupId": 9, + "resourceId": 9 }
@@ -2862,20 +2937,20 @@ Content-Type: application/json Request Body: PUT https://DomainName/mifosng-provider/api/v1/centers/{centerId} -PUT centers/4 +PUT centers/8 Content-Type: application/json Request Body: { - "name": "apicenter(updated)" + "name": "First Center (No groups)", } { - "officeId": 4, - "groupId": 2, - "resourceId": 4, + "officeId": 8, + "groupId": 8, + "resourceId": 8, "changes": { - "name": "apicenter(updated)" + "name": "First Center (No groups) - modified" } } @@ -2886,13 +2961,14 @@ Request Body:

Delete a Center

+

A center can be delete if it is in pending state and has nothing associated with it - groups, loans, savings etc

POST https://DomainName/mifosng-provider/api/v1/centers/{centerId} -DELETE centers/1 +DELETE centers/8 { @@ -2903,7 +2979,74 @@ DELETE centers/1
-   +   +
+
+

Retrieve a Center

+

Example Requests:

+
centers/1
+
+
centers/1?associations=groupMembers
+
+
+

Retrieve an existing center with no groups information.

+ +GET https://DomainName/mifosng-provider/api/v1/centers/8 + + +{ + "id": 8, + "status": { + "id": 100, + "code": "groupingStatusType.pending", + "value": "Pending" + }, + "active": false, + "name": "First Center (No groups)", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".8." +} + +
+
+

Retrieve an existing center with no groups information.

+ +GET https://DomainName/mifosng-provider/api/v1/centers/9?associations=groupMembers + + +{ + "id": 9, + "status": { + "id": 300, + "code": "groupingStatusType.active", + "value": "Active" + }, + "active": true, + "activationDate": [ + 2011, + 3, + 1 + ], + "name": "centerwithgroup", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".9.", + "groupMembers": [ + { + "id": 7, + "name": "Othergroup", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".7." + } + ] +} + +
+
+ +  

List Centers

@@ -2917,49 +3060,40 @@ GET https://DomainName/mifosng-provider/api/v1/centers [ { - "id": 1, - "name": "Center 001", - "externalId": "001", + "id": 8, + "status": { + "id": 100, + "code": "groupingStatusType.pending", + "value": "Pending" + }, + "active": false, + "name": "First Center (No groups)", "officeId": 1, "officeName": "Head Office", - "hierarchy": ".1." + "hierarchy": ".8." }, { - "id": 3, - "name": "Suboffice Center", - "externalId": "002", - "officeId": 2, - "officeName": "Suboffice", - "hierarchy": ".3." + "id": 9, + "status": { + "id": 300, + "code": "groupingStatusType.active", + "value": "Active" + }, + "active": true, + "activationDate": [ + 2011, + 3, + 1 + ], + "name": "centerwithgroup", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".9." } ]
- -   -
-
-

Retrieve a Center

-

Example Requests:

-
centers/1
-
-
- -GET https://DomainName/mifosng-provider/api/v1/centers/1 - - -{ - "id": 1, - "name": "Center 001", - "externalId": "001", - "officeId": 1, - "officeName": "Head Office", - "hierarchy": ".1." -} - -
-
@@ -2980,18 +3114,6 @@ GET https://DomainName/mifosng-provider/api/v1/centers/1 Name given to the Group. - - officeId - - - The officeId of the office/branch this group is administrated through. - - - staffId - - - The staffId of the staff member dealing with this group. The staff member is not specifically the loan officer. - externalId @@ -2999,11 +3121,37 @@ GET https://DomainName/mifosng-provider/api/v1/centers/1 A place to put an external reference for this group e.g. The ID another system uses. If provided, it must be unique. + + officeId + + + The officeId of the office/branch this group is administrated through. + + + active + + + Indicates whether this group is to be created as active. If active=true, then activationDate must be provided. If active=false, then the group is created as pending. + + + + activationDate + + + The date on which the group became active. + + + + staffId + + + The staffId of the staff member dealing with this group. The staff member is not specifically the loan officer. The staff member must be assigned to the same office as this group. + clientMembers - The individual client members that make up the group. + The individual client members that make up the group. The clients must be assigned to the same office as this group. @@ -3014,13 +3162,16 @@ GET https://DomainName/mifosng-provider/api/v1/centers/1

Retrieve Group Template

Example Requests:

-
groups/template?centerId=1
+
groups/template

groups/template?officeId=2

-
groups/template
+
groups/template?centerId=1
+
+
+

Template to create a standard group

GET https://DomainName/mifosng-provider/api/v1/groups/template @@ -3035,24 +3186,26 @@ GET https://DomainName/mifosng-provider/api/v1/groups/template }, { "id": 2, - "name": "Suboffice", - "nameDecorated": "....Suboffice" + "name": "Branch Office 1", + "nameDecorated": "....Branch Office 1" } ], "staffOptions": [ { "id": 1, - "displayName": "LoanOfficer, HeadOffice" + "displayName": "C, Mike" + } + ], + "clientOptions": [ + { + "id": 1, + "displayName": "Petra Yton", + "officeId": 1, + "officeName": "Head Office" }, { "id": 2, - "displayName": "NonLoanOfficer, HeadOffice" - } - ], - "clientOptions": [ - { - "id": 1, - "displayName": "Test one", + "displayName": "Small shop business", "officeId": 1, "officeName": "Head Office" } @@ -3061,6 +3214,7 @@ GET https://DomainName/mifosng-provider/api/v1/groups/template
+

Template to create a standard group with specific office known. This will return only staffOptions and clientMembersOptions relevant for the chosen office.

GET https://DomainName/mifosng-provider/api/v1/groups/template?officeId=2 @@ -3075,75 +3229,30 @@ GET https://DomainName/mifosng-provider/api/v1/groups/template?officeId=2 }, { "id": 2, - "name": "Suboffice", - "nameDecorated": "....Suboffice" + "name": "Branch Office 1", + "nameDecorated": "....Branch Office 1" } ], "staffOptions": [ { - "id": 3, - "displayName": "LoanOfficer, Suboffice" + "id": 2, + "displayName": "D, Mary" }, { - "id": 4, - "displayName": "NonLoanOfficer, Suboffice" + "id": 3, + "displayName": "P, Paul" } ] }
+

Template to create a group for an existing center. As an existing center will be assigned to an office, this will return only staffOptions and clientMembersOptions relevant for the chosen center/office.

GET https://DomainName/mifosng-provider/api/v1/groups/template?centerId=1 -{ - "officeId": 1, - "centerId": 1, - "centerName": "Center 001", - "centerOptions": [ - { - "id": 1, - "name": "Center 001", - "externalId": "001", - "officeId": 1, - "officeName": "Head Office", - "hierarchy": ".1." - } - ], - "officeOptions": [ - { - "id": 1, - "name": "Head Office", - "nameDecorated": "Head Office", - "externalId": "1", - "openingDate": [ - 2009, - 1, - 1 - ], - "hierarchy": "." - } - ], - "staffOptions": [ - { - "id": 1, - "displayName": "LoanOfficer, HeadOffice" - }, - { - "id": 2, - "displayName": "NonLoanOfficer, HeadOffice" - } - ], - "clientOptions": [ - { - "id": 1, - "displayName": "Test one", - "officeId": 1, - "officeName": "Head Office" - } - ] -} +
@@ -3157,7 +3266,7 @@ GET https://DomainName/mifosng-provider/api/v1/groups/template?centerId=1
Mandatory Fields
- name,officeId + name, officeId, active, activationDate (if active=true)
@@ -3178,25 +3287,150 @@ POST https://DomainName/mifosng-provider/api/v1/groups POST groups Content-Type: application/json Request Body: { -"officeId":"1", -"name":"TA Group" + "officeId":"1", + "name":"Pending Group", + "active": false +} + + +{ + "officeId": 1, + "groupId": 2, + "resourceId": 2 } POST groups Content-Type: application/json Request Body: { -"officeId":"1", -"name":"TA Group" -"externalId": "000-1A", -"clientMembers": ["1"] + "officeId":"1", + "name":"First Group", + "externalId": "000-1A", + "clientMembers": ["1"], + "dateFormat": "dd MMMM yyyy", + "locale": "en", + "active": true, + "activationDate": "04 March 2009" } { - "officeId": 2, - "groupId": 5, - "resourceId": 5 + "officeId": 1, + "groupId": 1, + "resourceId": 1 +} + + + + +   +
+
+

Retrieve a Group

+

Example Requests:

+
groups/1
+
+
groups/1?associations=clientMembers
+
+
+

Group with no clientMembers information requested.

+ +GET https://DomainName/mifosng-provider/api/v1/groups/1 + + +{ + "id": 1, + "name": "First Group", + "externalId": "000-1A", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".1." +} + +
+
+

Group with clientMembers.

+ +GET https://DomainName/mifosng-provider/api/v1/groups/1?associations=clientMembers + + +{ + "id": 1, + "name": "First Group", + "externalId": "000-1A", + "officeId": 1, + "officeName": "Head Office", + "hierarchy": ".1.", + "clientMembers": [ + { + "id": 1, + "accountNo": "000000001", + "externalId": "786YYH7", + "activationDate": [ + 2009, + 3, + 4 + ], + "firstname": "Petra", + "lastname": "Yton", + "displayName": "Petra Yton", + "officeId": 1, + "officeName": "Head Office" + } + ] +} + +
+
+ +   +
+
+

Update a Group

+
+
+ +PUT https://DomainName/mifosng-provider/api/v1/groups/{groupid} + + +PUT groups/1 +Content-Type: application/json +Request Body: +{ + "name": "First Group (changed)" +} + + +{ + "officeId": 1, + "groupId": 1, + "resourceId": 1, + "changes": { + "name": "First Group (changed)" + } +} + +
+
+ +   +
+
+

Delete a Group

+

A group can be deleted if it is in pending state and has nothing associated with it - groups, loans, savings etc

+
+
+ +POST https://DomainName/mifosng-provider/api/v1/groups/{groupid} + + +DELETE groups/2 + + +{ + "officeId": 1, + "groupId": 2, + "resourceId": 2 }
@@ -3216,164 +3450,24 @@ GET https://DomainName/mifosng-provider/api/v1/groups [ { - "id": 10, - "name": "GroupU(Suboffice)", - "officeId": 2, - "officeName": "Suboffice", - "centerId": 4, - "centerName": "apicenter(updated)", - "hierarchy": "" - }, - { - "id": 8, - "name": "AnothergroupUI", + "id": 1, + "name": "First Group (changed)", + "externalId": "000-1A", "officeId": 1, "officeName": "Head Office", - "centerId": 1, - "centerName": "Center 001", - "hierarchy": "" - }, - { - "id": 7, - "name": "NewGroupUI", - "externalId": "0011", - "officeId": 1, - "officeName": "Head Office", - "centerId": 1, - "centerName": "Center 001", - "staffId": 1, - "staffName": "LoanOfficer, HeadOffice", - "hierarchy": "" - }, - { - "id": 9, - "name": "GroupUCenter", - "officeId": 1, - "officeName": "Head Office", - "centerId": 1, - "centerName": "Center 001", - "staffId": 1, - "staffName": "LoanOfficer, HeadOffice", - "hierarchy": "" + "hierarchy": ".1." }, { "id": 2, - "name": "Group 001-A", + "name": "Pending Group", "officeId": 1, "officeName": "Head Office", - "centerId": 1, - "centerName": "Center 001", - "hierarchy": "" - }, - { - "id": 11, - "name": "Test(no parents)", - "officeId": 1, - "officeName": "Head Office", - "hierarchy": ".11." - }, - { - "id": 12, - "name": "SubofficeGroup(no parents)", - "officeId": 2, - "officeName": "Suboffice", - "hierarchy": ".12." + "hierarchy": ".2." } ]
- -   -
-
-

Retrieve a Group

-

Example Requests:

-
groups/12
-
-
- -GET https://DomainName/mifosng-provider/api/v1/groups/12 - - -{ - "id": 12, - "name": "SubofficeGroup(no parents)", - "officeId": 2, - "officeName": "Suboffice", - "hierarchy": ".12.", - "clientMembers": [ - { - "id": 2, - "accountNo": "000000002", - "firstname": "Another", - "lastname": "client", - "displayName": "Another client", - "officeId": 2, - "officeName": "Suboffice", - "joinedDate": [ - 2012, - 4, - 14 - ] - } - ] -} - -
-
- -   -
-
-

Update a Group

-
-
- -PUT https://DomainName/mifosng-provider/api/v1/groups/{groupid} - - -PUT groups/5 -Content-Type: application/json -Request Body: -{ - "name": "apigroup(changed)" -} - - -{ - "officeId": 5, - "groupId": 2, - "resourceId": 5, - "changes": { - "name": "apigroup(changed)" - } -} - -
-
- -   -
-
-

Delete a Group

-
-
- -POST https://DomainName/mifosng-provider/api/v1/groups/{groupid} - - -DELETE groups/5 - - -{ - "officeId": 5, - "groupId": 2, - "resourceId": 5 -} - -
-
@@ -13069,7 +13163,7 @@ GET https://DomainName/api/v1/search?query=000000111 Create a Center List Centers - Delete a Center + @@ -13077,7 +13171,7 @@ GET https://DomainName/api/v1/search?query=000000111 Retrieve a Center Update a Center - + Delete a Center Group @@ -13085,7 +13179,7 @@ GET https://DomainName/api/v1/search?query=000000111 Create a Group List Groups - Delete a Group + @@ -13093,7 +13187,7 @@ GET https://DomainName/api/v1/search?query=000000111 Retrieve a Group Update a Group - + Delete a Group diff --git a/mifosng-db/migrations/core_db/V22__alter-group-for-consistency-add-permissions.sql b/mifosng-db/migrations/core_db/V22__alter-group-for-consistency-add-permissions.sql new file mode 100644 index 000000000..fc24a41d7 --- /dev/null +++ b/mifosng-db/migrations/core_db/V22__alter-group-for-consistency-add-permissions.sql @@ -0,0 +1,19 @@ +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'ACTIVATE_CENTER', 'CENTER', 'ACTIVATE', 1); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'ACTIVATE_CENTER_CHECKER', 'CENTER', 'ACTIVATE', 0); + +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'ACTIVATE_GROUP', 'GROUP', 'ACTIVATE', 1); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'ACTIVATE_GROUP_CHECKER', 'GROUP', 'ACTIVATE', 0); + + +ALTER TABLE `m_group` DROP FOREIGN KEY `FK_m_group_level`; +ALTER TABLE `m_group` +CHANGE COLUMN `external_id` `external_id` VARCHAR(100) NULL DEFAULT NULL AFTER `id`, +CHANGE COLUMN `status_enum` `status_enum` INT(5) NOT NULL DEFAULT '300' AFTER `external_id`, +CHANGE COLUMN `name` `display_name` VARCHAR(100) NOT NULL AFTER `level_id`, +CHANGE COLUMN `level_Id` `level_id` INT(11) NOT NULL, +ADD CONSTRAINT `FK_m_group_level` FOREIGN KEY (`level_id`) REFERENCES `m_group_level` (`id`); + + +ALTER TABLE `m_group` +DROP COLUMN `is_deleted`, +ADD COLUMN `activation_date` DATE NULL DEFAULT NULL AFTER `status_enum` ; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/AuditReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/AuditReadPlatformServiceImpl.java index 2bb32b986..b815b1448 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/AuditReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/AuditReadPlatformServiceImpl.java @@ -32,281 +32,234 @@ import org.springframework.stereotype.Service; @Service public class AuditReadPlatformServiceImpl implements AuditReadPlatformService { - private final static Logger logger = LoggerFactory - .getLogger(AuditReadPlatformServiceImpl.class); - private final JdbcTemplate jdbcTemplate; - private final PlatformSecurityContext context; - private final AppUserReadPlatformService appUserReadPlatformService; + private final static Logger logger = LoggerFactory.getLogger(AuditReadPlatformServiceImpl.class); + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + private final AppUserReadPlatformService appUserReadPlatformService; - @Autowired - public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, - final TenantAwareRoutingDataSource dataSource, - final AppUserReadPlatformService appUserReadPlatformService) { - this.context = context; - this.jdbcTemplate = new JdbcTemplate(dataSource); - this.appUserReadPlatformService = appUserReadPlatformService; - } + @Autowired + public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, + final AppUserReadPlatformService appUserReadPlatformService) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + this.appUserReadPlatformService = appUserReadPlatformService; + } - private static final class AuditMapper implements RowMapper { + private static final class AuditMapper implements RowMapper { - public String schema(boolean includeJson, String hierarchy) { + public String schema(final boolean includeJson, final String hierarchy) { - String commandAsJsonString = ""; - if (includeJson) - commandAsJsonString = ", aud.command_as_json as commandAsJson "; + String commandAsJsonString = ""; + if (includeJson) commandAsJsonString = ", aud.command_as_json as commandAsJson "; - String partSql = " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName," - + " aud.resource_id as resourceId, aud.subresource_id as subresourceId," - + " mk.username as maker, aud.made_on_date as madeOnDate, " - + "ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult " - + commandAsJsonString - + ", " - + " o.name as officeName, gl.level_name as groupLevelName, g.name as groupName, c.display_name as clientName, " - + " l.account_no as loanAccountNo, s.account_no as savingsAccountNo " - + " from m_portfolio_command_source aud " - + " left join m_appuser mk on mk.id = aud.maker_id" - + " left join m_appuser ck on ck.id = aud.checker_id" - + " left join m_office o on o.id = aud.office_id" - + " left join m_group g on g.id = aud.group_id" - + " left join m_group_level gl on gl.id = g.level_id" - + " left join m_client c on c.id = aud.client_id" - + " left join m_loan l on l.id = aud.loan_id" - + " left join m_savings_account s on s.id = aud.savings_account_id" - + " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum"; + String partSql = " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName," + + " aud.resource_id as resourceId, aud.subresource_id as subresourceId," + + " mk.username as maker, aud.made_on_date as madeOnDate, " + + "ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult " + + commandAsJsonString + ", " + + " o.name as officeName, gl.level_name as groupLevelName, g.display_name as groupName, c.display_name as clientName, " + + " l.account_no as loanAccountNo, s.account_no as savingsAccountNo " + " from m_portfolio_command_source aud " + + " left join m_appuser mk on mk.id = aud.maker_id" + " left join m_appuser ck on ck.id = aud.checker_id" + + " left join m_office o on o.id = aud.office_id" + " left join m_group g on g.id = aud.group_id" + + " left join m_group_level gl on gl.id = g.level_id" + " left join m_client c on c.id = aud.client_id" + + " left join m_loan l on l.id = aud.loan_id" + " left join m_savings_account s on s.id = aud.savings_account_id" + + " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum"; - // data scoping: head office (hierarchy = ".") can see all audit - // entries - if (!(hierarchy.equals("."))) { - partSql += " join m_office o2 on o2.id = aud.office_id and o2.hierarchy like '" - + hierarchy + "%' "; - } + // data scoping: head office (hierarchy = ".") can see all audit + // entries + if (!(hierarchy.equals("."))) { + partSql += " join m_office o2 on o2.id = aud.office_id and o2.hierarchy like '" + hierarchy + "%' "; + } - return partSql; - } + return partSql; + } - @Override - public AuditData mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { + @Override + public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - final Long id = rs.getLong("id"); - final String actionName = rs.getString("actionName"); - final String entityName = rs.getString("entityName"); - final Long resourceId = JdbcSupport.getLong(rs, "resourceId"); - final Long subresourceId = JdbcSupport.getLong(rs, "subresourceId"); - final String maker = rs.getString("maker"); - final DateTime madeOnDate = JdbcSupport.getDateTime(rs, - "madeOnDate"); - final String checker = rs.getString("checker"); - final DateTime checkedOnDate = JdbcSupport.getDateTime(rs, - "checkedOnDate"); - final String processingResult = rs.getString("processingResult"); - String commandAsJson; - // commandAsJson might not be on the select list of columns - try { - commandAsJson = rs.getString("commandAsJson"); - } catch (SQLException e) { - commandAsJson = null; - } + final Long id = rs.getLong("id"); + final String actionName = rs.getString("actionName"); + final String entityName = rs.getString("entityName"); + final Long resourceId = JdbcSupport.getLong(rs, "resourceId"); + final Long subresourceId = JdbcSupport.getLong(rs, "subresourceId"); + final String maker = rs.getString("maker"); + final DateTime madeOnDate = JdbcSupport.getDateTime(rs, "madeOnDate"); + final String checker = rs.getString("checker"); + final DateTime checkedOnDate = JdbcSupport.getDateTime(rs, "checkedOnDate"); + final String processingResult = rs.getString("processingResult"); + String commandAsJson; + // commandAsJson might not be on the select list of columns + try { + commandAsJson = rs.getString("commandAsJson"); + } catch (SQLException e) { + commandAsJson = null; + } - String officeName = rs.getString("officeName"); - String groupLevelName = rs.getString("groupLevelName"); - String groupName = rs.getString("groupName"); - String clientName = rs.getString("clientName"); - String loanAccountNo = rs.getString("loanAccountNo"); - String savingsAccountNo = rs.getString("savingsAccountNo"); + String officeName = rs.getString("officeName"); + String groupLevelName = rs.getString("groupLevelName"); + String groupName = rs.getString("groupName"); + String clientName = rs.getString("clientName"); + String loanAccountNo = rs.getString("loanAccountNo"); + String savingsAccountNo = rs.getString("savingsAccountNo"); - return new AuditData(id, actionName, entityName, resourceId, - subresourceId, maker, madeOnDate, checker, checkedOnDate, - processingResult, commandAsJson, officeName, - groupLevelName, groupName, clientName, loanAccountNo, - savingsAccountNo); - } - } + return new AuditData(id, actionName, entityName, resourceId, subresourceId, maker, madeOnDate, checker, checkedOnDate, + processingResult, commandAsJson, officeName, groupLevelName, groupName, clientName, loanAccountNo, savingsAccountNo); + } + } - @Override - public Collection retrieveAuditEntries(String extraCriteria, - boolean includeJson) { + @Override + public Collection retrieveAuditEntries(final String extraCriteria, final boolean includeJson) { - String updatedExtraCriteria = ""; - if (StringUtils.isNotBlank(extraCriteria)) - updatedExtraCriteria = " where (" + extraCriteria + ")"; + String updatedExtraCriteria = ""; + if (StringUtils.isNotBlank(extraCriteria)) updatedExtraCriteria = " where (" + extraCriteria + ")"; - updatedExtraCriteria += " order by aud.id DESC"; - return retrieveEntries("audit", updatedExtraCriteria, includeJson); - } + updatedExtraCriteria += " order by aud.id DESC"; + return retrieveEntries("audit", updatedExtraCriteria, includeJson); + } - @Override - public Collection retrieveAllEntriesToBeChecked( - String extraCriteria, boolean includeJson) { + @Override + public Collection retrieveAllEntriesToBeChecked(final String extraCriteria, final boolean includeJson) { - String updatedExtraCriteria = ""; - if (StringUtils.isNotBlank(extraCriteria)) - updatedExtraCriteria = " where (" + extraCriteria + ")" - + " and aud.processing_result_enum = 2"; - else - updatedExtraCriteria = " where aud.processing_result_enum = 2"; + String updatedExtraCriteria = ""; + if (StringUtils.isNotBlank(extraCriteria)) + updatedExtraCriteria = " where (" + extraCriteria + ")" + " and aud.processing_result_enum = 2"; + else + updatedExtraCriteria = " where aud.processing_result_enum = 2"; - updatedExtraCriteria += " order by aud.id"; + updatedExtraCriteria += " order by aud.id"; - return retrieveEntries("makerchecker", updatedExtraCriteria, - includeJson); - } + return retrieveEntries("makerchecker", updatedExtraCriteria, includeJson); + } - public Collection retrieveEntries(String useType, - String extraCriteria, boolean includeJson) { + public Collection retrieveEntries(final String useType, final String extraCriteria, final boolean includeJson) { - if (!(useType.equals("audit") || useType.equals("makerchecker"))) { - throw new PlatformDataIntegrityException( - "error.msg.invalid.auditSearchTemplate.useType", - "Invalid Audit Search Template UseType: " + useType); - } + if (!(useType.equals("audit") || useType.equals("makerchecker"))) { throw new PlatformDataIntegrityException( + "error.msg.invalid.auditSearchTemplate.useType", "Invalid Audit Search Template UseType: " + useType); } - AppUser currentUser = context.authenticatedUser(); - String hierarchy = currentUser.getOffice().getHierarchy(); + AppUser currentUser = context.authenticatedUser(); + String hierarchy = currentUser.getOffice().getHierarchy(); - final AuditMapper rm = new AuditMapper(); - String sql = "select " + rm.schema(includeJson, hierarchy); + final AuditMapper rm = new AuditMapper(); + String sql = "select " + rm.schema(includeJson, hierarchy); - Boolean isLimitedChecker = false; - if (useType.equals("makerchecker")) { - if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", - "CHECKER_SUPER_USER")) { - isLimitedChecker = true; - } - } + Boolean isLimitedChecker = false; + if (useType.equals("makerchecker")) { + if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", "CHECKER_SUPER_USER")) { + isLimitedChecker = true; + } + } - if (isLimitedChecker) { - sql += " join m_permission p on p.action_name = aud.action_name and p.entity_name = aud.entity_name and p.code like '%\\_CHECKER'" - + " join m_role_permission rp on rp.permission_id = p.id" - + " join m_role r on r.id = rp.role_id " - + " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " - + currentUser.getId(); - } - sql += extraCriteria; + if (isLimitedChecker) { + sql += " join m_permission p on p.action_name = aud.action_name and p.entity_name = aud.entity_name and p.code like '%\\_CHECKER'" + + " join m_role_permission rp on rp.permission_id = p.id" + + " join m_role r on r.id = rp.role_id " + + " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " + currentUser.getId(); + } + sql += extraCriteria; - logger.info("sql: " + sql); + logger.info("sql: " + sql); - return this.jdbcTemplate.query(sql, rm, new Object[] {}); - } + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } - @Override - public AuditData retrieveAuditEntry(Long auditId) { + @Override + public AuditData retrieveAuditEntry(final Long auditId) { - AppUser currentUser = context.authenticatedUser(); - String hierarchy = currentUser.getOffice().getHierarchy(); + AppUser currentUser = context.authenticatedUser(); + String hierarchy = currentUser.getOffice().getHierarchy(); - final AuditMapper rm = new AuditMapper(); + final AuditMapper rm = new AuditMapper(); - String sql = "select " + rm.schema(true, hierarchy); - sql += " where aud.id = " + auditId; + String sql = "select " + rm.schema(true, hierarchy); + sql += " where aud.id = " + auditId; - return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {}); - } + return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {}); + } - @Override - public AuditSearchData retrieveSearchTemplate(String useType) { + @Override + public AuditSearchData retrieveSearchTemplate(final String useType) { - if (!(useType.equals("audit") || useType.equals("makerchecker"))) { - throw new PlatformDataIntegrityException( - "error.msg.invalid.auditSearchTemplate.useType", - "Invalid Audit Search Template UseType: " + useType); - } + if (!(useType.equals("audit") || useType.equals("makerchecker"))) { throw new PlatformDataIntegrityException( + "error.msg.invalid.auditSearchTemplate.useType", "Invalid Audit Search Template UseType: " + useType); } - AppUser currentUser = context.authenticatedUser(); + AppUser currentUser = context.authenticatedUser(); - final Collection appUsers = appUserReadPlatformService - .retrieveSearchTemplate(); + final Collection appUsers = appUserReadPlatformService.retrieveSearchTemplate(); - String sql = " SELECT distinct(action_name) as actionName FROM m_permission p "; - sql += makercheckerCapabilityOnly(useType, currentUser); - sql += " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name"; - ActionNamesMapper mapper = new ActionNamesMapper(); - List actionNames = this.jdbcTemplate.query(sql, mapper, - new Object[] {}); + String sql = " SELECT distinct(action_name) as actionName FROM m_permission p "; + sql += makercheckerCapabilityOnly(useType, currentUser); + sql += " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name"; + ActionNamesMapper mapper = new ActionNamesMapper(); + List actionNames = this.jdbcTemplate.query(sql, mapper, new Object[] {}); - sql = " select distinct(entity_name) as entityName from m_permission p "; - sql += makercheckerCapabilityOnly(useType, currentUser); - sql += " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name"; - EntityNamesMapper mapper2 = new EntityNamesMapper(); - List entityNames = this.jdbcTemplate.query(sql, mapper2, - new Object[] {}); + sql = " select distinct(entity_name) as entityName from m_permission p "; + sql += makercheckerCapabilityOnly(useType, currentUser); + sql += " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name"; + EntityNamesMapper mapper2 = new EntityNamesMapper(); + List entityNames = this.jdbcTemplate.query(sql, mapper2, new Object[] {}); - Collection processingResults = null; - if (useType.equals("audit")) { - ProcessingResultsMapper mapper3 = new ProcessingResultsMapper(); - processingResults = this.jdbcTemplate.query(mapper3.schema(), - mapper3, new Object[] {}); - } + Collection processingResults = null; + if (useType.equals("audit")) { + ProcessingResultsMapper mapper3 = new ProcessingResultsMapper(); + processingResults = this.jdbcTemplate.query(mapper3.schema(), mapper3, new Object[] {}); + } - return new AuditSearchData(appUsers, actionNames, entityNames, - processingResults); - } + return new AuditSearchData(appUsers, actionNames, entityNames, processingResults); + } - private String makercheckerCapabilityOnly(String useType, - AppUser currentUser) { - String sql = ""; - Boolean isLimitedChecker = false; - if (useType.equals("makerchecker")) { - if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", - "CHECKER_SUPER_USER")) { - isLimitedChecker = true; - } - } + private String makercheckerCapabilityOnly(final String useType, final AppUser currentUser) { + String sql = ""; + Boolean isLimitedChecker = false; + if (useType.equals("makerchecker")) { + if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", "CHECKER_SUPER_USER")) { + isLimitedChecker = true; + } + } - if (isLimitedChecker) { - sql += " join m_role_permission rp on rp.permission_id = p.id" - + " join m_role r on r.id = rp.role_id " - + " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " - + currentUser.getId(); + if (isLimitedChecker) { + sql += " join m_role_permission rp on rp.permission_id = p.id" + " join m_role r on r.id = rp.role_id " + + " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " + currentUser.getId(); - } - sql += " where p.action_name is not null and p.action_name <> 'READ' "; - if (isLimitedChecker) { - sql += "and p.code like '%\\_CHECKER'"; - } - return sql; - } + } + sql += " where p.action_name is not null and p.action_name <> 'READ' "; + if (isLimitedChecker) { + sql += "and p.code like '%\\_CHECKER'"; + } + return sql; + } - private static final class ActionNamesMapper implements RowMapper { + private static final class ActionNamesMapper implements RowMapper { - @Override - public String mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { + @Override + public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - return rs.getString("actionName"); - } + return rs.getString("actionName"); + } - } + } - private static final class EntityNamesMapper implements RowMapper { + private static final class EntityNamesMapper implements RowMapper { - @Override - public String mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { - return rs.getString("entityName"); - } + @Override + public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + return rs.getString("entityName"); + } - } + } - private static final class ProcessingResultsMapper implements - RowMapper { + private static final class ProcessingResultsMapper implements RowMapper { - @Override - public ProcessingResultLookup mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { - Long id = JdbcSupport.getLong(rs, "id"); - String processingResult = rs.getString("processingResult"); + @Override + public ProcessingResultLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + Long id = JdbcSupport.getLong(rs, "id"); + String processingResult = rs.getString("processingResult"); - return new ProcessingResultLookup(id, processingResult); - } + return new ProcessingResultLookup(id, processingResult); + } - public String schema() { - return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' " - + " order by enum_id"; - } - } + public String schema() { + return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' " + + " order by enum_id"; + } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java index 7fa322196..bb4cf8f3b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java @@ -56,6 +56,10 @@ public final class Client extends AbstractPersistable { @Column(name = "status_enum", nullable = false) private Integer status; + @Column(name = "activation_date", nullable = true) + @Temporal(TemporalType.DATE) + private Date activationDate; + @Column(name = "firstname", length = 50) private String firstname; @@ -72,10 +76,6 @@ public final class Client extends AbstractPersistable { @Column(name = "display_name", length = 100, nullable = false) private String displayName; - @Column(name = "activation_date", nullable = true) - @Temporal(TemporalType.DATE) - private Date activationDate; - @Column(name = "external_id", length = 100, nullable = true, unique = true) private String externalId; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java index dca9a1ee4..6c183f5fd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java @@ -292,8 +292,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService private static final class ParentGroupsMapper implements RowMapper { public String parentGroupsSchema() { - return "gp.id As groupId , gp.name As groupName from m_client cl JOIN m_group_client gc ON cl.id = gc.client_id " - + "JOIN m_group gp ON gp.id = gc.group_id WHERE cl.id = ? AND gp.is_deleted = 0 "; + return "gp.id As groupId , gp.display_name As groupName from m_client cl JOIN m_group_client gc ON cl.id = gc.client_id " + + "JOIN m_group gp ON gp.id = gc.group_id WHERE cl.id = ?"; } @Override diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 0335b8335..39f68331d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -84,18 +84,15 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId); - final Long officeId = client.getOffice().getId(); - if (client.isNotPending()) { throw new ClientMustBePendingToBeDeletedException(clientId); } List relatedNotes = this.noteRepository.findByClientId(clientId); this.noteRepository.deleteInBatch(relatedNotes); - // client.delete(); this.clientRepository.delete(client); return new CommandProcessingResultBuilder() // - .withOfficeId(officeId) // + .withOfficeId(client.officeId()) // .withClientId(clientId) // .withEntityId(clientId) // .build(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java index f4c3a4e64..e3efd2b89 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java @@ -171,7 +171,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe public String collectionSheetSchema() { - return "SELECT gp.name As groupName, " + return "SELECT gp.display_name As groupName, " + "gp.id As groupId, " + "cl.display_name As clientName, " + "sf.id As staffId, " diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java index 6f003d7be..0ced66ebe 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java @@ -120,8 +120,8 @@ public class CentersApiResource { } if (!associationParameters.isEmpty()) { - if (associationParameters.contains("groups")) { - center = CenterData.setGroups(center, this.centerReadPlatformService.retriveAssociatedGroups(centerId)); + if (associationParameters.contains("groupMembers")) { + center = CenterData.setGroups(center, this.centerReadPlatformService.retrieveAssociatedGroups(centerId)); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java index f8593dfcc..c0d6d73fa 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java @@ -22,6 +22,13 @@ public class GroupingTypesApiConstants { public static final String externalIdParamName = "externalId"; public static final String officeIdParamName = "officeId"; public static final String staffIdParamName = "staffId"; + public static final String activeParamName = "active"; + public static final String activationDateParamName = "activationDate"; + public static final String groupMembersParamName = "groupMembers"; + + // group parameters + public static final String centerIdParamName = "centerId"; + public static final String clientMembersParamName = "clientMembers"; // response parameters public static final String hierarchyParamName = "hierarchy"; @@ -32,7 +39,12 @@ public class GroupingTypesApiConstants { public static final String clientOptionsParamName = "clientOptions"; public static final Set CENTER_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, - dateFormatParamName, nameParamName, externalIdParamName, officeIdParamName, staffIdParamName)); + dateFormatParamName, idParamName, nameParamName, externalIdParamName, officeIdParamName, staffIdParamName, activeParamName, + activationDateParamName, groupMembersParamName)); + + public static final Set GROUP_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, + idParamName, nameParamName, externalIdParamName, centerIdParamName, officeIdParamName, staffIdParamName, activeParamName, + activationDateParamName, clientMembersParamName)); /** * These parameters will match the class level parameters of diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index c3f6c6eab..17fcf9d69 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -124,12 +124,19 @@ public class GroupsApiResource { public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); + final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId); - Collection membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); - if (CollectionUtils.isEmpty(membersOfGroup)) { - membersOfGroup = null; + // associations + Collection membersOfGroup = null; + if (!associationParameters.isEmpty()) { + if (associationParameters.contains("clientMembers")) { + membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); + if (CollectionUtils.isEmpty(membersOfGroup)) { + membersOfGroup = null; + } + } } final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/command/GroupCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/command/GroupCommand.java deleted file mode 100644 index 4dea872a8..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/command/GroupCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.portfolio.group.command; - -public class GroupCommand { - - private final String externalId; - private final String name; - private final Long officeId; - private final Long staffId; - private final Long parentId; - private final String[] clientMembers; - private final String[] childGroups; - - public GroupCommand(final String externalId, final String name, final Long officeId, final Long staffId, final String[] clientMembers, - final String[] childGroups, final Long parentId) { - this.officeId = officeId; - this.staffId = staffId; - this.parentId = parentId; - this.externalId = externalId; - this.name = name; - this.clientMembers = clientMembers; - this.childGroups = childGroups; - - } - - public Long getOfficeId() { - return this.officeId; - } - - public Long getParentId() { - return this.parentId; - } - - public Long getStaffId() { - return this.staffId; - } - - public String getExternalId() { - return this.externalId; - } - - public String getName() { - return this.name; - } - - public String[] getClientMembers() { - return this.clientMembers; - } - - public String[] getChildGroups() { - return this.childGroups; - } - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/CenterData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/CenterData.java index 26b5731ba..277d8c85b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/CenterData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/CenterData.java @@ -7,6 +7,8 @@ package org.mifosplatform.portfolio.group.data; import java.util.Collection; +import org.joda.time.LocalDate; +import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.staff.data.StaffData; @@ -16,8 +18,15 @@ import org.mifosplatform.organisation.staff.data.StaffData; public class CenterData { private final Long id; - private final String name; private final String externalId; + + private final EnumOptionData status; + @SuppressWarnings("unused") + private final boolean active; + private final LocalDate activationDate; + + private final String name; + private final Long officeId; private final String officeName; private final Long staffId; @@ -25,51 +34,70 @@ public class CenterData { private final String hierarchy; // associations - @SuppressWarnings("unused") - private final Collection groups; + private final Collection groupMembers; // template private final Collection officeOptions; private final Collection staffOptions; + private final Collection groupMembersOptions; - public static CenterData template(final Long officeId, final Collection officeOptions, - final Collection staffOptions) { - return new CenterData(null, null, null, officeId, null, null, null, null, officeOptions, staffOptions, null); + public static CenterData template(final Long officeId, final LocalDate activationDate, final Collection officeOptions, + final Collection staffOptions, final Collection groupMembersOptions) { + return new CenterData(null, null, null, null, activationDate, officeId, null, null, null, null, null, officeOptions, staffOptions, + groupMembersOptions); } public static CenterData withTemplate(final CenterData templateCenter, final CenterData center) { - return new CenterData(center.id, center.name, center.externalId, center.officeId, center.officeName, center.staffId, - center.staffName, center.hierarchy, templateCenter.officeOptions, templateCenter.staffOptions, null); + return new CenterData(center.id, center.name, center.externalId, center.status, center.activationDate, center.officeId, + center.officeName, center.staffId, center.staffName, center.hierarchy, center.groupMembers, templateCenter.officeOptions, + templateCenter.staffOptions, templateCenter.groupMembersOptions); } - public static CenterData instance(final Long id, final String name, final String externalId, final Long officeId, - final String officeName, final Long staffId, final String staffName, final String hierarchy) { + public static CenterData instance(final Long id, final String name, final String externalId, final EnumOptionData status, + final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName, + final String hierarchy) { + final Collection groupMembers = null; final Collection officeOptions = null; final Collection staffOptions = null; + final Collection groupMembersOptions = null; - return new CenterData(id, name, externalId, officeId, officeName, staffId, staffName, hierarchy, officeOptions, staffOptions, null); - } - - public static CenterData setGroups(final CenterData centerData, final Collection groups){ - return new CenterData(centerData.id, centerData.name, centerData.externalId, centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, centerData.hierarchy, centerData.officeOptions, centerData.staffOptions, groups); + return new CenterData(id, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy, + groupMembers, officeOptions, staffOptions, groupMembersOptions); } - private CenterData(final Long id, final String name, final String externalId, final Long officeId, final String officeName, - final Long staffId, final String staffName, final String hierarchy, final Collection officeOptions, - final Collection staffOptions, final Collection groups) { + public static CenterData setGroups(final CenterData centerData, final Collection groupMembers) { + return new CenterData(centerData.id, centerData.name, centerData.externalId, centerData.status, centerData.activationDate, + centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, centerData.hierarchy, groupMembers, + centerData.officeOptions, centerData.staffOptions, centerData.groupMembersOptions); + } + + private CenterData(final Long id, final String name, final String externalId, final EnumOptionData status, + final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName, + final String hierarchy, final Collection groupMembers, final Collection officeOptions, + final Collection staffOptions, final Collection groupMembersOptions) { this.id = id; this.name = name; this.externalId = externalId; + this.status = status; + if (status != null) { + this.active = status.getId().equals(300L); + } else { + this.active = false; + } + this.activationDate = activationDate; this.officeId = officeId; this.officeName = officeName; this.staffId = staffId; this.staffName = staffName; this.hierarchy = hierarchy; + this.groupMembers = groupMembers; + + // this.officeOptions = officeOptions; this.staffOptions = staffOptions; - this.groups = groups; + this.groupMembersOptions = groupMembersOptions; } public Long officeId() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java index 4254d73dd..29318afcf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java @@ -76,7 +76,7 @@ public class GroupGeneralData { } public static GroupGeneralData instance(final Long id, final String name, final String externalId, final Long officeId, - final String officeName, final Long parentId, final String parentName, final Long staffId, final String staffName, + final String officeName, final Long centerId, final String centerName, final Long staffId, final String staffName, final String hierarchy) { final Collection clientMembers = null; @@ -85,12 +85,12 @@ public class GroupGeneralData { final Collection staffOptions = null; final Collection clientOptions = null; - return new GroupGeneralData(id, name, externalId, officeId, officeName, parentId, parentName, staffId, staffName, hierarchy, + return new GroupGeneralData(id, name, externalId, officeId, officeName, centerId, centerName, staffId, staffName, hierarchy, clientMembers, centerOptions, officeOptions, staffOptions, clientOptions); } private GroupGeneralData(final Long id, final String name, final String externalId, final Long officeId, final String officeName, - final Long parentId, final String parentName, final Long staffId, final String staffName, final String hierarchy, + final Long centerId, final String centerName, final Long staffId, final String staffName, final String hierarchy, final Collection clientMembers, final Collection centerOptions, final Collection officeOptions, final Collection staffOptions, final Collection clientOptions) { this.id = id; @@ -98,8 +98,8 @@ public class GroupGeneralData { this.externalId = externalId; this.officeId = officeId; this.officeName = officeName; - this.centerId = parentId; - this.centerName = parentName; + this.centerId = centerId; + this.centerName = centerName; this.staffId = staffId; this.staffName = staffName; this.hierarchy = hierarchy; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java deleted file mode 100644 index fc79a3493..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.portfolio.group.data; - -/** - * Immutable data object representing groups. - */ -@Deprecated -public class GroupLookup { - - private final Long id; - private final String name; - - public GroupLookup(final Long id, final String name) { - this.id = id; - this.name = name; - } - - public Long getId() { - return this.id; - } - - public String getName() { - return this.name; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index 8a4177ffb..b1c84d982 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -5,6 +5,7 @@ */ package org.mifosplatform.portfolio.group.domain; +import java.util.Date; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -19,8 +20,11 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.client.domain.Client; @@ -28,15 +32,20 @@ import org.springframework.data.jpa.domain.AbstractPersistable; @Entity @Table(name = "m_group") -public class Group extends AbstractPersistable { +public final class Group extends AbstractPersistable { - @OneToMany(fetch = FetchType.EAGER) - @JoinColumn(name = "parent_id") - private final List children = new LinkedList(); + @Column(name = "external_id", length = 100, unique = true) + private String externalId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "parent_id") - private Group parent; + /** + * A value from {@link GroupingTypeStatus}. + */ + @Column(name = "status_enum", nullable = false) + private Integer status; + + @Column(name = "activation_date", nullable = true) + @Temporal(TemporalType.DATE) + private Date activationDate; @ManyToOne @JoinColumn(name = "office_id", nullable = false) @@ -46,21 +55,27 @@ public class Group extends AbstractPersistable { @JoinColumn(name = "staff_id", nullable = true) private Staff staff; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parent_id") + private Group parent; + + /* + * TODO - kw - it might be possible to just move this to be a java enum type + * rather than 'levels' table. + */ @ManyToOne @JoinColumn(name = "level_id", nullable = false) private GroupLevel groupLevel; + @Column(name = "display_name", length = 100, unique = true) + private String name; + @Column(name = "hierarchy", length = 100) private String hierarchy; - @Column(name = "name", length = 100, unique = true) - private String name; - - @Column(name = "external_id", length = 100, unique = true) - private String externalId; - - @Column(name = "is_deleted", nullable = false) - private boolean deleted = false; + @OneToMany(fetch = FetchType.EAGER) + @JoinColumn(name = "parent_id") + private final List groupMembers = new LinkedList(); @ManyToMany @JoinTable(name = "m_group_client", joinColumns = @JoinColumn(name = "group_id"), inverseJoinColumns = @JoinColumn(name = "client_id")) @@ -73,12 +88,20 @@ public class Group extends AbstractPersistable { } public static Group newGroup(final Office office, final Staff staff, final Group parent, final GroupLevel groupLevel, - final String name, final String externalId, final Set clientMembers, final Set childGroups) { - return new Group(office, staff, parent, groupLevel, name, externalId, clientMembers, childGroups); + final String name, final String externalId, final boolean active, final LocalDate activationDate, + final Set clientMembers, final Set groupMembers) { + + GroupingTypeStatus status = GroupingTypeStatus.PENDING; + if (active) { + status = GroupingTypeStatus.ACTIVE; + } + + return new Group(office, staff, parent, groupLevel, name, externalId, status, activationDate, clientMembers, groupMembers); } public Group(final Office office, final Staff staff, final Group parent, final GroupLevel groupLevel, final String name, - final String externalId, final Set clientMembers, final Set childGroups) { + final String externalId, final GroupingTypeStatus status, final LocalDate activationDate, final Set clientMembers, + final Set groupMembers) { this.office = office; this.staff = staff; this.groupLevel = groupLevel; @@ -88,6 +111,11 @@ public class Group extends AbstractPersistable { this.parent.addChild(this); } + this.status = status.getValue(); + if (activationDate != null) { + this.activationDate = activationDate.toDate(); + } + if (StringUtils.isNotBlank(name)) { this.name = name.trim(); } else { @@ -101,13 +129,21 @@ public class Group extends AbstractPersistable { if (clientMembers != null) { this.clientMembers = clientMembers; } - if (childGroups != null) { - this.children.addAll(childGroups); + if (groupMembers != null) { + this.groupMembers.addAll(groupMembers); } } + public boolean isNotPending() { + return !isPending(); + } + + public boolean isPending() { + return GroupingTypeStatus.fromInt(this.status).isPending(); + } + private void addChild(final Group group) { - this.children.add(group); + this.groupMembers.add(group); } public Long getOfficeId() { @@ -182,22 +218,6 @@ public class Group extends AbstractPersistable { return this.clientMembers.contains(client); } - /** - * Delete is a soft delete. Updates flag on group so it wont appear - * in query/report results. - * - * Any fields with unique constraints and prepended with id of record. - */ - public void delete() { - this.deleted = true; - this.externalId = getId() + "_" + this.externalId; - this.name = getId() + "_" + this.name; - } - - public boolean isDeleted() { - return this.deleted; - } - public void generateHierarchy() { if (this.parent != null) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java index 0f32ab9c7..cb9bae6d0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java @@ -74,5 +74,4 @@ public class GroupLevel extends AbstractPersistable { public boolean isIdentifiedByParentId(final Long parentLevelId) { return this.parentId.equals(parentLevelId); } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupTypes.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupTypes.java similarity index 82% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupTypes.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupTypes.java index 9a9d83dca..32bb43a79 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupTypes.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupTypes.java @@ -1,19 +1,19 @@ -package org.mifosplatform.portfolio.group.data; +package org.mifosplatform.portfolio.group.domain; import java.util.HashMap; import java.util.Map; public enum GroupTypes { - CENTER(new Long(1), "groupTypes.center", "center"), // - GROUP(new Long(2), "groupTypes.group", "group"), // - INVALID(new Long(99), "lendingStrategy.invalid", "invalid"); + INVALID(0l, "lendingStrategy.invalid", "invalid"), // + CENTER(1l, "groupTypes.center", "center"), // + GROUP(2l, "groupTypes.group", "group"); // private Long id; private String code; private String value; - GroupTypes(final Long id, final String code, final String value) { + private GroupTypes(final Long id, final String code, final String value) { this.id = id; this.code = code; this.value = value; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeEnumerations.java new file mode 100644 index 000000000..b3ef8d8c3 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeEnumerations.java @@ -0,0 +1,40 @@ +/** + * 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.portfolio.group.domain; + +import org.mifosplatform.infrastructure.core.data.EnumOptionData; + +public class GroupingTypeEnumerations { + + public static EnumOptionData status(final Integer statusId) { + return status(GroupingTypeStatus.fromInt(statusId)); + } + + public static EnumOptionData status(final GroupingTypeStatus status) { + EnumOptionData optionData = new EnumOptionData(GroupingTypeStatus.INVALID.getValue().longValue(), + GroupingTypeStatus.INVALID.getCode(), "Invalid"); + switch (status) { + case INVALID: + optionData = new EnumOptionData(GroupingTypeStatus.INVALID.getValue().longValue(), GroupingTypeStatus.INVALID.getCode(), + "Invalid"); + break; + case PENDING: + optionData = new EnumOptionData(GroupingTypeStatus.PENDING.getValue().longValue(), GroupingTypeStatus.PENDING.getCode(), + "Pending"); + break; + case ACTIVE: + optionData = new EnumOptionData(GroupingTypeStatus.ACTIVE.getValue().longValue(), GroupingTypeStatus.ACTIVE.getCode(), + "Active"); + break; + case CLOSED: + optionData = new EnumOptionData(GroupingTypeStatus.CLOSED.getValue().longValue(), GroupingTypeStatus.CLOSED.getCode(), + "Closed"); + break; + } + + return optionData; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeStatus.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeStatus.java new file mode 100644 index 000000000..e0add459d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupingTypeStatus.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.portfolio.group.domain; + +/** + * Enum representation of grouping type status states. + */ +public enum GroupingTypeStatus { + + INVALID(0, "groupingStatusType.invalid"), // + PENDING(100, "groupingStatusType.pending"), // + ACTIVE(300, "groupingStatusType.active"), // + CLOSED(600, "groupingStatusType.closed"); + + private final Integer value; + private final String code; + + public static GroupingTypeStatus fromInt(final Integer statusValue) { + + GroupingTypeStatus enumeration = GroupingTypeStatus.INVALID; + switch (statusValue) { + case 100: + enumeration = GroupingTypeStatus.PENDING; + break; + case 300: + enumeration = GroupingTypeStatus.ACTIVE; + break; + case 600: + enumeration = GroupingTypeStatus.CLOSED; + break; + } + return enumeration; + } + + private GroupingTypeStatus(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public boolean hasStateOf(final GroupingTypeStatus state) { + return this.value.equals(state.getValue()); + } + + public Integer getValue() { + return this.value; + } + + public String getCode() { + return code; + } + + public boolean isPending() { + return this.value.equals(GroupingTypeStatus.PENDING.getValue()); + } + + public boolean isActive() { + return this.value.equals(GroupingTypeStatus.ACTIVE.getValue()); + } + + public boolean isClosed() { + return this.value.equals(GroupingTypeStatus.CLOSED.getValue()); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupMustBePendingToBeDeletedException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupMustBePendingToBeDeletedException.java new file mode 100644 index 000000000..8eea9b705 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupMustBePendingToBeDeletedException.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.portfolio.group.exception; + +import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; + +/** + * A {@link RuntimeException} thrown when attempting to delete groups. + */ +public class GroupMustBePendingToBeDeletedException extends AbstractPlatformDomainRuleException { + + public GroupMustBePendingToBeDeletedException(final Long id) { + super("error.msg.group.cannot.be.deleted", "Group with identifier " + id + " cannot be deleted as it is not in `Pending` state.", + id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateCenterCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateCenterCommandHandler.java index 2ea3d46a1..d2fd280d8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateCenterCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateCenterCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,17 +16,16 @@ import org.springframework.transaction.annotation.Transactional; @Service public class CreateCenterCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; - private static final Long LEVEL_ID = (long) 1; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public CreateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public CreateCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.groupWritePlatformService.createGroup(null , LEVEL_ID , command); + return this.groupWritePlatformService.createCenter(command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateGroupCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateGroupCommandHandler.java index 6bca12166..d89e68d89 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateGroupCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/CreateGroupCommandHandler.java @@ -8,8 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.data.GroupTypes; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,11 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class CreateGroupCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; - private static final Long LEVEL_ID = GroupTypes.GROUP.getId();; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public CreateGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public CreateGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } @@ -30,6 +28,6 @@ public class CreateGroupCommandHandler implements NewCommandSourceHandler { public CommandProcessingResult processCommand(final JsonCommand command) { final Long centerId = command.longValueOfParameterNamed("centerId"); - return this.groupWritePlatformService.createGroup(centerId , LEVEL_ID , command); + return this.groupWritePlatformService.createGroup(centerId, command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteCenterCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteCenterCommandHandler.java index 464a38780..d34ad599f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteCenterCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteCenterCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class DeleteCenterCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public DeleteCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public DeleteCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteGroupCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteGroupCommandHandler.java index 9099cdd30..88b47db1a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteGroupCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/DeleteGroupCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class DeleteGroupCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public DeleteGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public DeleteGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignStaffCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignStaffCommandHandler.java index e651a8a1f..5e6179f23 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignStaffCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignStaffCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class UnassignStaffCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public UnassignStaffCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public UnassignStaffCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateCenterCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateCenterCommandHandler.java index 2be7f6574..b2bba7595 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateCenterCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateCenterCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class UpdateCenterCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public UpdateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public UpdateCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } @@ -27,6 +27,6 @@ public class UpdateCenterCommandHandler implements NewCommandSourceHandler { @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.groupWritePlatformService.updateGroup(command.entityId(), command); + return this.groupWritePlatformService.updateCenter(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupCommandHandler.java index 347101c6e..041b07044 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupCommandHandler.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; +import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional; @Service public class UpdateGroupCommandHandler implements NewCommandSourceHandler { - private final GroupWritePlatformService groupWritePlatformService; + private final GroupingTypesWritePlatformService groupWritePlatformService; @Autowired - public UpdateGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) { + public UpdateGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) { this.groupWritePlatformService = groupWritePlatformService; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupCommandFromApiJsonDeserializer.java deleted file mode 100644 index ad66c1812..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupCommandFromApiJsonDeserializer.java +++ /dev/null @@ -1,183 +0,0 @@ -/** - * 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.portfolio.group.serialization; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; -import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer; -import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer; -import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.client.command.ClientCommand; -import org.mifosplatform.portfolio.group.command.GroupCommand; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.google.gson.JsonElement; -import com.google.gson.reflect.TypeToken; - -/** - * Implementation of {@link FromApiJsonDeserializer} for {@link ClientCommand} - * 's. - */ -@Component -public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer { - - /** - * The parameters supported for this command. - */ - private final Set supportedParameters = new HashSet(Arrays.asList("id", "externalId", "name", "officeId", "staffId", - "centerId", "clientMembers", "childGroups")); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public GroupCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - - @Override - public GroupCommand commandFromApiJson(final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - - final JsonElement element = this.fromApiJsonHelper.parse(json); - final String externalId = this.fromApiJsonHelper.extractStringNamed("externalId", element); - final String name = this.fromApiJsonHelper.extractStringNamed("name", element); - final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element); - final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element); - final Long parentId = this.fromApiJsonHelper.extractLongNamed("parentId", element); - final String[] clientMembers = this.fromApiJsonHelper.extractArrayNamed("clientMembers", element); - final String[] childGroups = this.fromApiJsonHelper.extractArrayNamed("childGroups", element); - - return new GroupCommand(externalId, name, officeId, staffId, clientMembers, childGroups, parentId); - } - - public void validateForCreate(final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - final JsonElement element = this.fromApiJsonHelper.parse(json); - - final List dataValidationErrors = new ArrayList(); - - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group"); - - /* - * Name is a mandatory field and not exceeding length 100 character - */ - final String nameParameterName = "name"; - final String name = this.fromApiJsonHelper.extractStringNamed(nameParameterName, element); - baseDataValidator.reset().parameter(nameParameterName).value(name).notNull().notExceedingLengthOf(100); - - final String externalIdParameterName = "externalId"; - if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) { - final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element); - baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100); - } - - /* - * Either OfficeId or ParentId is mandatory to have value - */ - - final String centerIdParameterName = "centerId"; - if (this.fromApiJsonHelper.parameterExists(centerIdParameterName, element)) { - final Long centerId = this.fromApiJsonHelper.extractLongNamed(centerIdParameterName, element); - baseDataValidator.reset().parameter(centerIdParameterName).value(centerId).notNull().integerGreaterThanZero(); - }else{ - final String officeIdParameterName = "officeId"; - final Long officeId = this.fromApiJsonHelper.extractLongNamed(officeIdParameterName, element); - baseDataValidator.reset().parameter(officeIdParameterName).value(officeId).notNull().integerGreaterThanZero(); - } - - final String staffIdParameterName = "staffId"; - if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) { - final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); - baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero(); - } - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - - public void validateForUpdate(final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - - /* - * Office updated is not supported - */ - final Set supportedParametersForupdate = new HashSet(Arrays.asList("id", "externalId", "name", "staffId", - "parentId", "clientMembers", "childGroups")); - - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForupdate); - final JsonElement element = this.fromApiJsonHelper.parse(json); - - final List dataValidationErrors = new ArrayList(); - - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group"); - - final String externalIdParameterName = "externalId"; - if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) { - final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element); - baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100); - } - - final String parentIdParameterName = "parentId"; - if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) { - final Long parentId = this.fromApiJsonHelper.extractLongNamed(parentIdParameterName, element); - baseDataValidator.reset().parameter(parentIdParameterName).value(parentId).ignoreIfNull().integerGreaterThanZero(); - } - - final String staffIdParameterName = "staffId"; - if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) { - final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); - baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero(); - } - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - - public void validateForUnassignStaff(final String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - - final Set supportedParametersUnassignStaff = new HashSet(Arrays.asList("staffId")); - - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff); - final JsonElement element = this.fromApiJsonHelper.parse(json); - - final List dataValidationErrors = new ArrayList(); - - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group"); - - final String staffIdParameterName = "staffId"; - final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); - baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().integerGreaterThanZero(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupingTypesDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupingTypesDataValidator.java new file mode 100644 index 000000000..3b656e18d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupingTypesDataValidator.java @@ -0,0 +1,377 @@ +/** + * 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.portfolio.group.serialization; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.ApiParameterError; +import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; +import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; +import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; +import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer; +import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; +import org.mifosplatform.portfolio.client.api.ClientApiConstants; +import org.mifosplatform.portfolio.client.command.ClientCommand; +import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; + +/** + * Implementation of {@link FromApiJsonDeserializer} for {@link ClientCommand} + * 's. + */ +@Component +public final class GroupingTypesDataValidator { + + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public GroupingTypesDataValidator(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { + // + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", + dataValidationErrors); + } + } + + public void validateForCreateCenter(final JsonCommand command) { + + final String json = command.json(); + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.CENTER_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); + + JsonElement element = command.parsedJson(); + + final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100); + } + + final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero(); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero(); + } + + final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element); + if (active != null) { + if (active.booleanValue()) { + final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName, + element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull(); + } else { + // TODO - KW - not using config for now - just supporting move + // to pending or active out of box. + boolean isPendingApprovalEnabled = true; + if (!isPendingApprovalEnabled) { + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName) + .failWithCode(".pending.status.not.allowed"); + } + } + } else { + baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false); + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForCreateCenterGroup(final JsonCommand command) { + + final String json = command.json(); + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); + + JsonElement element = command.parsedJson(); + + final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100); + } + + final Long centerId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.centerIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.centerIdParamName).value(centerId).notNull().integerGreaterThanZero(); + + // office is inherited from center + final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero(); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero(); + } + + final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element); + if (active != null) { + if (active.booleanValue()) { + final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName, + element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull(); + } else { + // TODO - KW - not using config for now - just supporting move + // to pending or active out of box. + boolean isPendingApprovalEnabled = true; + if (!isPendingApprovalEnabled) { + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName) + .failWithCode(".pending.status.not.allowed"); + } + } + } else { + baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false); + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForCreateGroup(final JsonCommand command) { + final String json = command.json(); + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); + + JsonElement element = command.parsedJson(); + + final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100); + } + + // office is inherited from center + final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero(); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero(); + } + + final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element); + if (active != null) { + if (active.booleanValue()) { + final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName, + element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull(); + } else { + // TODO - KW - not using config for now - just supporting move + // to pending or active out of box. + boolean isPendingApprovalEnabled = true; + if (!isPendingApprovalEnabled) { + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName) + .failWithCode(".pending.status.not.allowed"); + } + } + } else { + baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false); + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForUpdateCenter(final JsonCommand command) { + final String json = command.json(); + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.CENTER_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); + + JsonElement element = command.parsedJson(); + + final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100); + } + + // dont support update of office at present when updating center? + // final Long officeId = + // this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, + // element); + // baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero(); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero(); + } + + final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element); + if (active != null) { + if (active.booleanValue()) { + final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName, + element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull(); + } + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForUpdateGroup(final JsonCommand command) { + final String json = command.json(); + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); + + JsonElement element = command.parsedJson(); + + final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100); + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100); + } + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.officeIdParamName, element)) { + final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull() + .integerGreaterThanZero(); + } + + if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero(); + } + + final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element); + if (active != null) { + if (active.booleanValue()) { + final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName, + element); + baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull(); + } + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + @Deprecated + public void validateForUpdate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + + /* + * Office updated is not supported + */ + final Set supportedParametersForupdate = new HashSet(Arrays.asList("id", "externalId", "name", "staffId", + "parentId", "clientMembers", "childGroups")); + + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForupdate); + final JsonElement element = this.fromApiJsonHelper.parse(json); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group"); + + final String externalIdParameterName = "externalId"; + if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) { + final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element); + baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100); + } + + final String parentIdParameterName = "parentId"; + if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) { + final Long parentId = this.fromApiJsonHelper.extractLongNamed(parentIdParameterName, element); + baseDataValidator.reset().parameter(parentIdParameterName).value(parentId).ignoreIfNull().integerGreaterThanZero(); + } + + final String staffIdParameterName = "staffId"; + if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) { + final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); + baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero(); + } + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } + + public void validateForUnassignStaff(final String json) { + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + + final Set supportedParametersUnassignStaff = new HashSet(Arrays.asList("staffId")); + + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff); + final JsonElement element = this.fromApiJsonHelper.parse(json); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group"); + + final String staffIdParameterName = "staffId"; + final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); + baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().integerGreaterThanZero(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/AllGroupTypesDataMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/AllGroupTypesDataMapper.java new file mode 100644 index 000000000..039fa243d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/AllGroupTypesDataMapper.java @@ -0,0 +1,52 @@ +package org.mifosplatform.portfolio.group.service; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.mifosplatform.infrastructure.core.domain.JdbcSupport; +import org.mifosplatform.portfolio.group.data.GroupGeneralData; +import org.springframework.jdbc.core.RowMapper; + +/** + * + */ +public final class AllGroupTypesDataMapper implements RowMapper { + + private final String schemaSql; + + public AllGroupTypesDataMapper() { + final StringBuilder sqlBuilder = new StringBuilder(400); + sqlBuilder.append("g.id as id, g.external_id as externalId, g.display_name as displayName, "); + sqlBuilder.append("g.office_id as officeId, o.name as officeName, "); + sqlBuilder.append("g.parent_id as centerId, pg.display_name as centerName, "); + sqlBuilder.append("g.staff_id as staffId, s.display_name as staffName, "); + sqlBuilder.append("g.hierarchy as hierarchy "); + sqlBuilder.append("from m_group g "); + sqlBuilder.append("join m_office o on o.id = g.office_id "); + sqlBuilder.append("left join m_staff s on s.id = g.staff_id "); + sqlBuilder.append("left join m_group pg on pg.id = g.parent_id "); + + this.schemaSql = sqlBuilder.toString(); + } + + public String schema() { + return this.schemaSql; + } + + @Override + public GroupGeneralData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = rs.getLong("id"); + final String name = rs.getString("displayName"); + final String externalId = rs.getString("externalId"); + final Long officeId = JdbcSupport.getLong(rs, "officeId"); + final String officeName = rs.getString("officeName"); + final Long centerId = JdbcSupport.getLong(rs, "centerId"); + final String centerName = rs.getString("centerName"); + final Long staffId = JdbcSupport.getLong(rs, "staffId"); + final String staffName = rs.getString("staffName"); + final String hierarchy = rs.getString("hierarchy"); + + return GroupGeneralData.instance(id, name, externalId, officeId, officeName, centerId, centerName, staffId, staffName, hierarchy); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java index 3caf71da7..ac206efd9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java @@ -22,5 +22,5 @@ public interface CenterReadPlatformService { GroupGeneralData retrieveCenterGroupTemplate(Long centerId); - Collection retriveAssociatedGroups(Long centerId); + Collection retrieveAssociatedGroups(Long centerId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java index 5aaccd048..0df980ac0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -11,7 +11,10 @@ import java.util.Arrays; import java.util.Collection; import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; +import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; +import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -23,7 +26,8 @@ import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; import org.mifosplatform.portfolio.group.data.CenterData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; -import org.mifosplatform.portfolio.group.data.GroupTypes; +import org.mifosplatform.portfolio.group.domain.GroupTypes; +import org.mifosplatform.portfolio.group.domain.GroupingTypeEnumerations; import org.mifosplatform.portfolio.group.exception.GroupNotFoundException; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; @@ -41,14 +45,21 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService private final ClientReadPlatformService clientReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService; private final StaffReadPlatformService staffReadPlatformService; + private final ConfigurationDomainService configurationDomainService; + + // data mappers + private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper(); + + // data mappers private final CenterDataMapper centerMapper = new CenterDataMapper(); private final GroupDataMapper groupDataMapper = new GroupDataMapper(); @Autowired public CenterReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, - final ClientReadPlatformService clientReadPlatformService, final OfficeReadPlatformService officeReadPlatformService, - final StaffReadPlatformService staffReadPlatformService) { + final ConfigurationDomainService configurationDomainService, final ClientReadPlatformService clientReadPlatformService, + final OfficeReadPlatformService officeReadPlatformService, final StaffReadPlatformService staffReadPlatformService) { this.context = context; + this.configurationDomainService = configurationDomainService; this.clientReadPlatformService = clientReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); this.officeReadPlatformService = officeReadPlatformService; @@ -64,8 +75,8 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService String sqlQueryCriteria = searchCriteria.getSqlSearch(); if (StringUtils.isNotBlank(sqlQueryCriteria)) { - sqlQueryCriteria = sqlQueryCriteria.replaceAll(" name ", " g.name "); - sqlQueryCriteria = sqlQueryCriteria.replaceAll("name ", "g.name "); + sqlQueryCriteria = sqlQueryCriteria.replaceAll(" display_name ", " g.display_name "); + sqlQueryCriteria = sqlQueryCriteria.replaceAll("display_name ", "g.display_name "); extraCriteria = " and (" + sqlQueryCriteria + ")"; } @@ -81,7 +92,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService final String name = searchCriteria.getName(); if (name != null) { - extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString(name + "%"); + extraCriteria += " and g.display_name like " + ApiParameterHelper.sqlEncodeString(name + "%"); } final String hierarchy = searchCriteria.getHierarchy(); @@ -95,21 +106,22 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService return extraCriteria; } - - private static final String sqlQuery = "g.id as id, g.external_id as externalId, g.name as name, " + - "g.office_id as officeId, o.name as officeName, " + - "g.staff_id as staffId, s.display_name as staffName, " + - "g.hierarchy as hierarchy " + - "from m_group g " + - "join m_office o on o.id = g.office_id " + - "left join m_staff s on s.id = g.staff_id "; - + + private static final String sqlQuery = "g.id as id, g.external_id as externalId, g.display_name as name, " + + "g.office_id as officeId, o.name as officeName, " // + + "g.staff_id as staffId, s.display_name as staffName, " // + + "g.status_enum as statusEnum, g.activation_date as activationDate, " // + + "g.hierarchy as hierarchy " // + + "from m_group g " // + + "join m_office o on o.id = g.office_id " + + "left join m_staff s on s.id = g.staff_id "; + private static final class CenterDataMapper implements RowMapper { private final String schemaSql; public CenterDataMapper() { - + this.schemaSql = sqlQuery; } @@ -122,6 +134,9 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService final Long id = rs.getLong("id"); final String name = rs.getString("name"); + final Integer statusEnum = JdbcSupport.getInteger(rs, "statusEnum"); + final EnumOptionData status = GroupingTypeEnumerations.status(statusEnum); + final LocalDate activationDate = JdbcSupport.getLocalDate(rs, "activationDate"); final String externalId = rs.getString("externalId"); final Long officeId = rs.getLong("officeId"); final String officeName = rs.getString("officeName"); @@ -129,7 +144,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService final String staffName = rs.getString("staffName"); final String hierarchy = rs.getString("hierarchy"); - return CenterData.instance(id, name, externalId, officeId, officeName, staffId, staffName, hierarchy); + return CenterData.instance(id, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy); } } @@ -138,7 +153,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService private final String schemaSql; public GroupDataMapper() { - + this.schemaSql = sqlQuery; } @@ -161,7 +176,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService return GroupGeneralData.instance(id, name, externalId, officeId, officeName, null, null, staffId, staffName, hierarchy); } } - + @Override public Collection retrieveAll(final SearchParameters searchCriteria) { @@ -179,7 +194,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService sql += " and (" + extraCriteria + ")"; } - sql += "order by g.hierarchy"; + sql += " order by g.hierarchy"; return this.jdbcTemplate.query(sql, centerMapper, new Object[] { hierarchySearchString }); } @@ -187,8 +202,6 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService @Override public Collection retrieveAllForDropdown(final Long officeId) { - this.context.authenticatedUser(); - final AppUser currentUser = context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); final String hierarchySearchString = hierarchy + "%"; @@ -202,14 +215,47 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService @Override public CenterData retrieveTemplate(final Long officeId) { + final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId); + final Collection officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); - Collection staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeId); + Collection staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted); if (CollectionUtils.isEmpty(staffOptions)) { staffOptions = null; } - return CenterData.template(officeId, officeOptions, staffOptions); + Collection groupMembersOptions = retrieveAllGroupsForCenterDropdown(officeIdDefaulted); + if (CollectionUtils.isEmpty(groupMembersOptions)) { + groupMembersOptions = null; + } + + // final boolean clientPendingApprovalAllowed = + // this.configurationDomainService.isClientPendingApprovalAllowedEnabled(); + + return CenterData.template(officeIdDefaulted, new LocalDate(), officeOptions, staffOptions, groupMembersOptions); + } + + private Collection retrieveAllGroupsForCenterDropdown(final Long officeId) { + + final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId); + + final AppUser currentUser = context.authenticatedUser(); + final String hierarchy = currentUser.getOffice().getHierarchy(); + final String hierarchySearchString = hierarchy + "%"; + + final String sql = "select " + allGroupTypesDataMapper.schema() + + " where g.office_id = ? and g.parent_id is null and g.level_Id = ? and o.hierarchy like ? order by g.hierarchy"; + + return this.jdbcTemplate.query(sql, allGroupTypesDataMapper, new Object[] { defaultOfficeId, GroupTypes.GROUP.getId(), + hierarchySearchString }); + } + + private Long defaultToUsersOfficeIfNull(final Long officeId) { + Long defaultOfficeId = officeId; + if (defaultOfficeId == null) { + defaultOfficeId = this.context.authenticatedUser().getOffice().getId(); + } + return defaultOfficeId; } @Override @@ -222,6 +268,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService String sql = "select " + this.centerMapper.schema() + " where g.id = ? and o.hierarchy like ?"; return this.jdbcTemplate.queryForObject(sql, this.centerMapper, new Object[] { centerId, hierarchySearchString }); + } catch (EmptyResultDataAccessException e) { throw new GroupNotFoundException(centerId); } @@ -251,8 +298,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService staffOptions = null; } - Collection clientOptions = this.clientReadPlatformService - .retrieveAllForLookupByOfficeId(centerOfficeId); + Collection clientOptions = this.clientReadPlatformService.retrieveAllForLookupByOfficeId(centerOfficeId); if (CollectionUtils.isEmpty(clientOptions)) { clientOptions = null; } @@ -262,8 +308,8 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService } @Override - public Collection retriveAssociatedGroups(Long centerId) { - String sql = "select " + this.groupDataMapper.schema() + " where g.parent_id = ? "; - return this.jdbcTemplate.query(sql, groupDataMapper, new Object[] { centerId }); - } + public Collection retrieveAssociatedGroups(final Long centerId) { + String sql = "select " + this.groupDataMapper.schema() + " where g.parent_id = ? "; + return this.jdbcTemplate.query(sql, this.groupDataMapper, new Object[] { centerId }); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java index f2002a4c0..44e39d385 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java @@ -7,12 +7,9 @@ package org.mifosplatform.portfolio.group.service; import java.util.Collection; -import org.mifosplatform.organisation.monetary.data.MoneyData; -import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; -import org.mifosplatform.portfolio.group.data.GroupLevelData; public interface GroupReadPlatformService { @@ -26,18 +23,4 @@ public interface GroupReadPlatformService { GroupAccountSummaryCollectionData retrieveGroupAccountDetails(Long groupId); Collection retrieveGroupLoanAccountsByLoanOfficerId(Long groupId, Long loanOfficerId); - - GroupLevelData retrieveGroupLevelDetails(Long levelId); - - Collection retrieveStaffsbyOfficeId(Long officeId); - - Long retrieveTotalNoOfChildGroups(Long groupId); - - Long retrieveTotalClients(String hierarchy); - - Collection retrieveGroupLoanPortfolio(String hierarchy); - - StaffData retrieveStaffsbyId(Long staffId); - - Long getLevelIdByGroupId(final Long groupId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java index 4d47966aa..e296b0d4b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java @@ -5,7 +5,6 @@ */ package org.mifosplatform.portfolio.group.service; -import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -17,11 +16,9 @@ import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; -import org.mifosplatform.organisation.monetary.data.MoneyData; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.service.OfficeReadPlatformService; import org.mifosplatform.organisation.staff.data.StaffData; -import org.mifosplatform.organisation.staff.exception.StaffNotFoundException; import org.mifosplatform.organisation.staff.service.StaffReadPlatformService; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; @@ -30,9 +27,7 @@ import org.mifosplatform.portfolio.group.data.CenterData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; -import org.mifosplatform.portfolio.group.data.GroupLevelData; -import org.mifosplatform.portfolio.group.data.GroupTypes; -import org.mifosplatform.portfolio.group.exception.GroupLevelNotFoundException; +import org.mifosplatform.portfolio.group.domain.GroupTypes; import org.mifosplatform.portfolio.group.exception.GroupNotFoundException; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; @@ -50,9 +45,10 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { private final ClientReadPlatformService clientReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService; private final StaffReadPlatformService staffReadPlatformService; - private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper(); private final CenterReadPlatformService centerReadPlatformService; + private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper(); + @Autowired public GroupReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, final CenterReadPlatformService centerReadPlatformService, final ClientReadPlatformService clientReadPlatformService, @@ -81,8 +77,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { staffOptions = null; } - Collection clientOptions = this.clientReadPlatformService - .retrieveAllForLookupByOfficeId(defaultOfficeId); + Collection clientOptions = this.clientReadPlatformService.retrieveAllForLookupByOfficeId(defaultOfficeId); if (CollectionUtils.isEmpty(clientOptions)) { clientOptions = null; } @@ -132,8 +127,8 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { String sqlSearch = searchCriteria.getSqlSearch(); if (sqlSearch != null) { - sqlSearch = sqlSearch.replaceAll(" name ", " g.name "); - sqlSearch = sqlSearch.replaceAll("name ", "g.name "); + sqlSearch = sqlSearch.replaceAll(" display_name ", " g.display_name "); + sqlSearch = sqlSearch.replaceAll("display_name ", "g.display_name "); extraCriteria = " and (" + sqlSearch + ")"; } @@ -149,7 +144,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { final String name = searchCriteria.getName(); if (name != null) { - extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString("%" + name + "%"); + extraCriteria += " and g.display_name like " + ApiParameterHelper.sqlEncodeString("%" + name + "%"); } final String hierarchy = searchCriteria.getHierarchy(); @@ -179,200 +174,6 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } } - @Override - public GroupLevelData retrieveGroupLevelDetails(final Long levelId) { - - try { - this.context.authenticatedUser(); - final GroupLevelDataMapper rm = new GroupLevelDataMapper(); - final String sql = "select " + rm.groupLevelSchema() + " where gl.id = ? "; - return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { levelId }); - - } catch (final EmptyResultDataAccessException e) { - throw new GroupLevelNotFoundException(levelId); - } - } - - @Override - public Collection retrieveStaffsbyOfficeId(final Long officeId) { - - this.context.authenticatedUser(); - final StaffDataMapper rm = new StaffDataMapper(); - final String sql = "select " + rm.staffDataSchema() + " where o.id = ?"; - return this.jdbcTemplate.query(sql, rm, new Object[] { officeId }); - - } - - @Override - public StaffData retrieveStaffsbyId(final Long staffId) { - - try { - this.context.authenticatedUser(); - final StaffDataMapper rm = new StaffDataMapper(); - final String sql = "select " + rm.staffDataSchema() + " where s.id = ?"; - return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { staffId }); - - } catch (final EmptyResultDataAccessException e) { - throw new StaffNotFoundException(staffId); - } - } - - @Override - public Long getLevelIdByGroupId(final Long groupId) { - - this.context.authenticatedUser(); - final String sqlTotalClients = "SELECT g.level_Id as levelId FROM m_group g WHERE g.id = ?"; - return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupId }); - - } - - @Override - public Long retrieveTotalClients(final String hierarchy) { - - this.context.authenticatedUser(); - - final String groupHierarchy = hierarchy + "%"; - final String sqlTotalClients = "SELECT count(gc.client_id) FROM m_group_client gc JOIN m_group g " - + "ON gc.group_id = g.id WHERE g.hierarchy LIKE ? "; - return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupHierarchy }); - - } - - @Override - public Long retrieveTotalNoOfChildGroups(final Long groupId) { - - this.context.authenticatedUser(); - final String sqlTotalClients = "SELECT count(gc.id) FROM m_group g JOIN m_group gc WHERE g.id = gc.parent_id and g.id = ?"; - return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupId }); - - } - - @Override - public Collection retrieveGroupLoanPortfolio(final String hierarchy) { - - this.context.authenticatedUser(); - - final MoneyDataMapper rm = new MoneyDataMapper(); - - final String groupHierarchy = hierarchy + "%"; - final String sql = "select " + rm.moneyDataSchema() + " FROM m_group_client gc JOIN m_group g ON gc.group_id = g.id " - + "JOIN m_loan l ON l.client_id = gc.client_id LEFT JOIN m_organisation_currency oc ON oc.code = l.currency_code " - + " WHERE g.hierarchy LIKE ? GROUP BY l.currency_code "; - - return this.jdbcTemplate.query(sql, rm, new Object[] { groupHierarchy }); - - } - - private static final class MoneyDataMapper implements RowMapper { - - public String moneyDataSchema() { - return "l.currency_code as currencyCode, oc.decimal_places as decimalPlaces, sum(l.principal_amount) as amount"; - } - - @Override - public MoneyData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final String currencyCode = rs.getString("currencyCode"); - final Integer decimalPlaces = rs.getInt("decimalPlaces"); - final BigDecimal amount = rs.getBigDecimal("amount"); - - return new MoneyData(currencyCode, amount, decimalPlaces); - } - } - - // GroupTopOfHierarchyData - private static final class AllGroupTypesDataMapper implements RowMapper { - - private final String schemaSql; - - public AllGroupTypesDataMapper() { - final StringBuilder sqlBuilder = new StringBuilder(400); - sqlBuilder.append("g.id as id, g.external_id as externalId, g.name as name, "); - sqlBuilder.append("g.office_id as officeId, o.name as officeName, "); - sqlBuilder.append("g.parent_id as parentId, pg.name as parentName, "); - sqlBuilder.append("g.staff_id as staffId, s.display_name as staffName, "); - sqlBuilder.append("g.hierarchy as hierarchy "); - sqlBuilder.append("from m_group g "); - sqlBuilder.append("join m_office o on o.id = g.office_id "); - sqlBuilder.append("left join m_staff s on s.id = g.staff_id "); - sqlBuilder.append("left join m_group pg on pg.id = g.parent_id "); - - this.schemaSql = sqlBuilder.toString(); - } - - public String schema() { - return this.schemaSql; - } - - @Override - public GroupGeneralData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = rs.getLong("id"); - final String name = rs.getString("name"); - final String externalId = rs.getString("externalId"); - final Long officeId = JdbcSupport.getLong(rs, "officeId"); - final String officeName = rs.getString("officeName"); - final Long parentId = JdbcSupport.getLong(rs, "parentId"); - final String parentName = rs.getString("parentName"); - final Long staffId = JdbcSupport.getLong(rs, "staffId"); - final String staffName = rs.getString("staffName"); - final String hierarchy = rs.getString("hierarchy"); - - return GroupGeneralData.instance(id, name, externalId, officeId, officeName, parentId, parentName, staffId, staffName, - hierarchy); - } - } - - private static final class GroupLevelDataMapper implements RowMapper { - - public String groupLevelSchema() { - return "gl.id as id, gl.level_name as levelName , gl.parent_id as parentLevelId , pgl.level_name as parentName , " - + "cgl.id as childLevelId,cgl.level_name as childLevelName,gl.super_parent as superParent ," - + " gl.recursable as recursable , gl.can_have_clients as canHaveClients from m_group_level gl " - + " left join m_group_level pgl on pgl.id = gl.parent_id left join m_group_level cgl on gl.id = cgl.parent_id"; - } - - @Override - public GroupLevelData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long levelId = rs.getLong("id"); - final String levelName = rs.getString("levelName"); - final Long parentLevelId = rs.getLong("parentLevelId"); - final String parentLevelName = rs.getString("parentName"); - final Long childLevelId = rs.getLong("childLevelId"); - final String childLevelName = rs.getString("childLevelName"); - final boolean superParent = rs.getBoolean("superParent"); - final boolean recursable = rs.getBoolean("recursable"); - final boolean canHaveClients = rs.getBoolean("canHaveClients"); - - return new GroupLevelData(levelId, levelName, parentLevelId, parentLevelName, childLevelId, childLevelName, superParent, - recursable, canHaveClients); - } - - } - - private static final class StaffDataMapper implements RowMapper { - - public String staffDataSchema() { - return "s.id as id , s.is_loan_officer as isLoanOfficer , s.office_id as officeId , s.firstname as firstname, " - + "s.lastname as lastname , s.display_name as displayName , o.name as officeName from m_staff s join m_office o on s.office_id =o.id "; - } - - @Override - public StaffData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = rs.getLong("id"); - final String firstname = rs.getString("firstname"); - final String lastname = rs.getString("lastname"); - final String displayName = rs.getString("displayName"); - final Long officeId = rs.getLong("officeId"); - final String officeName = rs.getString("officeName"); - final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer"); - - return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer); - } - } - @Override public GroupAccountSummaryCollectionData retrieveGroupAccountDetails(final Long groupId) { try { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupTypeEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupTypeEnumerations.java index 4a05233e8..1c047ed1c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupTypeEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupTypeEnumerations.java @@ -6,7 +6,7 @@ package org.mifosplatform.portfolio.group.service; import org.mifosplatform.infrastructure.core.data.EnumOptionData; -import org.mifosplatform.portfolio.group.data.GroupTypes; +import org.mifosplatform.portfolio.group.domain.GroupTypes; public class GroupTypeEnumerations { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformService.java similarity index 69% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformService.java index c24ad5dab..cddaeb14b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformService.java @@ -8,14 +8,17 @@ package org.mifosplatform.portfolio.group.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -public interface GroupWritePlatformService { +public interface GroupingTypesWritePlatformService { - CommandProcessingResult createGroup(Long parentId, Long levelId, JsonCommand command); + CommandProcessingResult createCenter(JsonCommand command); + + CommandProcessingResult updateCenter(Long entityId, JsonCommand command); + + CommandProcessingResult createGroup(Long centerId, JsonCommand command); CommandProcessingResult updateGroup(Long groupId, JsonCommand command); CommandProcessingResult deleteGroup(Long groupId); CommandProcessingResult unassignStaff(Long grouptId, JsonCommand command); - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java similarity index 66% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java index a6499a9a9..a990ca337 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java @@ -8,10 +8,12 @@ package org.mifosplatform.portfolio.group.service; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; @@ -27,14 +29,19 @@ 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.portfolio.group.api.GroupingTypesApiConstants; import org.mifosplatform.portfolio.group.domain.Group; import org.mifosplatform.portfolio.group.domain.GroupLevel; import org.mifosplatform.portfolio.group.domain.GroupLevelRepository; import org.mifosplatform.portfolio.group.domain.GroupRepository; +import org.mifosplatform.portfolio.group.domain.GroupTypes; import org.mifosplatform.portfolio.group.exception.GroupHasNoStaffException; +import org.mifosplatform.portfolio.group.exception.GroupMustBePendingToBeDeletedException; import org.mifosplatform.portfolio.group.exception.GroupNotFoundException; import org.mifosplatform.portfolio.group.exception.InvalidGroupLevelException; -import org.mifosplatform.portfolio.group.serialization.GroupCommandFromApiJsonDeserializer; +import org.mifosplatform.portfolio.group.serialization.GroupingTypesDataValidator; +import org.mifosplatform.portfolio.note.domain.Note; +import org.mifosplatform.portfolio.note.domain.NoteRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -46,53 +53,47 @@ import org.springframework.util.ObjectUtils; import com.google.common.collect.Sets; @Service -public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePlatformService { +public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements GroupingTypesWritePlatformService { - private final static Logger logger = LoggerFactory.getLogger(GroupWritePlatformServiceJpaRepositoryImpl.class); + private final static Logger logger = LoggerFactory.getLogger(GroupingTypesWritePlatformServiceJpaRepositoryImpl.class); private final PlatformSecurityContext context; private final GroupRepository groupRepository; private final ClientRepository clientRepository; private final OfficeRepository officeRepository; private final StaffRepository staffRepository; + private final NoteRepository noteRepository; private final GroupLevelRepository groupLevelRepository; - private final GroupCommandFromApiJsonDeserializer fromApiJsonDeserializer; + private final GroupingTypesDataValidator fromApiJsonDeserializer; @Autowired - public GroupWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final GroupRepository groupRepository, + public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final GroupRepository groupRepository, final ClientRepository clientRepository, final OfficeRepository officeRepository, final StaffRepository staffRepository, - final GroupLevelRepository groupLevelRepository, final GroupCommandFromApiJsonDeserializer fromApiJsonDeserializer) { + final NoteRepository noteRepository, + final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer) { this.context = context; this.groupRepository = groupRepository; this.clientRepository = clientRepository; this.officeRepository = officeRepository; this.staffRepository = staffRepository; + this.noteRepository = noteRepository; this.groupLevelRepository = groupLevelRepository; this.fromApiJsonDeserializer = fromApiJsonDeserializer; } - @Transactional - @Override - public CommandProcessingResult createGroup(final Long parentId, final Long levelId, final JsonCommand command) { - - GroupLevel groupLevel = this.groupLevelRepository.findOne(levelId); + private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) { try { - this.context.authenticatedUser(); - - this.fromApiJsonDeserializer.validateForCreate(command.json()); - - final String name = command.stringValueOfParameterNamed("name"); - final String externalId = command.stringValueOfParameterNamed("externalId"); + final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); + final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); Long officeId = null; - Group parentGroup = null; - if (parentId == null) { - officeId = command.longValueOfParameterNamed("officeId"); + if (centerId == null) { + officeId = command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName); } else { - parentGroup = this.groupRepository.findOne(parentId); - if (parentGroup == null || parentGroup.isDeleted()) { throw new GroupNotFoundException(parentId); } + parentGroup = this.groupRepository.findOne(centerId); + if (parentGroup == null) { throw new GroupNotFoundException(centerId); } officeId = parentGroup.getOfficeId(); } @@ -100,29 +101,21 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla if (groupOffice == null) { throw new OfficeNotFoundException(officeId); } Staff staff = null; - final Long staffId = command.longValueOfParameterNamed("staffId"); - - /** - * Validate the staff is present in the given office or not - */ + final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName); if (staffId != null) { staff = this.staffRepository.findByOffice(staffId, officeId); if (staff == null) { throw new StaffNotFoundException(staffId); } } - Set clientMembers = null; - if (groupLevel.canHaveClients()) { - clientMembers = assembleSetOfClients(officeId, command); - } + final Set clientMembers = assembleSetOfClients(officeId, command); - //TODO -AA: Not sure about children are added at the time of group creation - /*Set childGroups = null; - if (groupLevel.isRecursable()) { - childGroups = assembleSetOfChildGroups(officeId, command); - }*/ + final Set groupMembers = assembleSetOfChildGroups(officeId, command); - final Group newGroup = Group - .newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, clientMembers, null); + final boolean active = command.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.activeParamName); + final LocalDate activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); + GroupLevel groupLevel = this.groupLevelRepository.findOne(groupingType.getId()); + final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, active, activationDate, + clientMembers, groupMembers); // pre-save to generate id for use in group hierarchy this.groupRepository.save(newGroup); @@ -139,40 +132,71 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla .build(); } catch (final DataIntegrityViolationException dve) { - handleGroupDataIntegrityIssues(command, dve, groupLevel); - return new CommandProcessingResult(Long.valueOf(-1)); + handleGroupDataIntegrityIssues(command, dve, groupingType); + return CommandProcessingResult.empty(); } } + @Transactional + @Override + public CommandProcessingResult createCenter(final JsonCommand command) { + + this.fromApiJsonDeserializer.validateForCreateCenter(command); + + final Long centerId = null; + return createGroupingType(command, GroupTypes.CENTER, centerId); + } + + @Transactional + @Override + public CommandProcessingResult createGroup(final Long centerId, final JsonCommand command) { + + if (centerId != null) { + this.fromApiJsonDeserializer.validateForCreateCenterGroup(command); + } else { + this.fromApiJsonDeserializer.validateForCreateGroup(command); + } + + return createGroupingType(command, GroupTypes.GROUP, centerId); + } + + @Transactional + @Override + public CommandProcessingResult updateCenter(final Long centerId, final JsonCommand command) { + + this.fromApiJsonDeserializer.validateForUpdateCenter(command); + + return updateGroupingType(centerId, command, GroupTypes.CENTER); + } + @Transactional @Override public CommandProcessingResult updateGroup(final Long groupId, final JsonCommand command) { - GroupLevel groupLevel = null; + this.fromApiJsonDeserializer.validateForUpdateGroup(command); + + return updateGroupingType(groupId, command, GroupTypes.GROUP); + } + + private CommandProcessingResult updateGroupingType(final Long groupId, final JsonCommand command, final GroupTypes groupingType) { try { - this.context.authenticatedUser(); - final Map actualChanges = new LinkedHashMap(9); - this.fromApiJsonDeserializer.validateForUpdate(command.json()); - final Group groupForUpdate = this.groupRepository.findOne(groupId); - if (groupForUpdate == null || groupForUpdate.isDeleted()) { throw new GroupNotFoundException(groupId); } + if (groupForUpdate == null) { throw new GroupNotFoundException(groupId); } final Long officeId = groupForUpdate.getOfficeId(); - final String nameParamName = "name"; - if (command.isChangeInStringParameterNamed(nameParamName, groupForUpdate.getName())) { - final String newValue = command.stringValueOfParameterNamed(nameParamName); - actualChanges.put(nameParamName, newValue); + if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.nameParamName, groupForUpdate.getName())) { + final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); + actualChanges.put(GroupingTypesApiConstants.nameParamName, newValue); groupForUpdate.setName(StringUtils.defaultIfEmpty(newValue, null)); } - final String externalIdParamName = "externalId"; - if (command.isChangeInStringParameterNamed(externalIdParamName, groupForUpdate.getExternalId())) { - final String newValue = command.stringValueOfParameterNamed(externalIdParamName); - actualChanges.put(externalIdParamName, newValue); + if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.externalIdParamName, groupForUpdate.getExternalId())) { + final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); + actualChanges.put(GroupingTypesApiConstants.externalIdParamName, newValue); groupForUpdate.setExternalId(StringUtils.defaultIfEmpty(newValue, null)); } @@ -182,10 +206,9 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla presentStaffId = presentStaff.getId(); } - final String staffIdParamName = "staffId"; - if (command.isChangeInLongParameterNamed(staffIdParamName, presentStaffId)) { - final Long newValue = command.longValueOfParameterNamed(staffIdParamName); - actualChanges.put(staffIdParamName, newValue); + if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.staffIdParamName, presentStaffId)) { + final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName); + actualChanges.put(GroupingTypesApiConstants.staffIdParamName, newValue); Staff newStaff = null; if (newValue != null) { @@ -195,7 +218,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla groupForUpdate.setStaff(newStaff); } - groupLevel = this.groupLevelRepository.findOne(groupForUpdate.getGroupLevel().getId()); + GroupLevel groupLevel = this.groupLevelRepository.findOne(groupForUpdate.getGroupLevel().getId()); /* * Ignoring parentId param, if group for update is super parent. @@ -204,7 +227,6 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla */ if (!groupLevel.isSuperParent()) { - final String parentIdParamName = "parentId"; Long parentId = null; final Group presentParentGroup = groupForUpdate.getParent(); @@ -212,14 +234,14 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla parentId = presentParentGroup.getId(); } - if (command.isChangeInLongParameterNamed(parentIdParamName, parentId)) { + if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.centerIdParamName, parentId)) { - final Long newValue = command.longValueOfParameterNamed(parentIdParamName); - actualChanges.put(parentIdParamName, newValue); + final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.centerIdParamName); + actualChanges.put(GroupingTypesApiConstants.centerIdParamName, newValue); Group newParentGroup = null; if (newValue != null) { newParentGroup = this.groupRepository.findOne(newValue); - if (newParentGroup == null || newParentGroup.isDeleted()) { throw new StaffNotFoundException(newValue); } + if (newParentGroup == null) { throw new StaffNotFoundException(newValue); } if (!newParentGroup.isOfficeIdentifiedBy(officeId)) { final String errorMessage = "Group and parent group must have the same office"; @@ -248,12 +270,11 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla } final Set clientMembers = assembleSetOfClients(officeId, command); - final String clientMembersParamName = "clientMembers"; if (!clientMembers.equals(groupForUpdate.getClientMembers())) { Set diffClients = Sets.symmetricDifference(clientMembers, groupForUpdate.getClientMembers()); final String[] diffClientsIds = getClientIds(diffClients); - actualChanges.put(clientMembersParamName, diffClientsIds); + actualChanges.put(GroupingTypesApiConstants.clientMembersParamName, diffClientsIds); groupForUpdate.setClientMembers(clientMembers); } @@ -262,15 +283,14 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withOfficeId(groupForUpdate.getId()) // - //apart from group context group id does not make much sense - .withGroupId(groupForUpdate.getId()) + .withGroupId(groupForUpdate.getId()) // .withEntityId(groupForUpdate.getId()) // .with(actualChanges) // .build(); } catch (final DataIntegrityViolationException dve) { - handleGroupDataIntegrityIssues(command, dve, groupLevel); - return new CommandProcessingResult(Long.valueOf(-1)); + handleGroupDataIntegrityIssues(command, dve, groupingType); + return CommandProcessingResult.empty(); } } @@ -285,7 +305,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla this.fromApiJsonDeserializer.validateForUnassignStaff(command.json()); final Group groupForUpdate = this.groupRepository.findOne(grouptId); - if (groupForUpdate == null || groupForUpdate.isDeleted()) { throw new GroupNotFoundException(grouptId); } + if (groupForUpdate == null) { throw new GroupNotFoundException(grouptId); } final Staff presentStaff = groupForUpdate.getStaff(); Long presentStaffId = null; @@ -309,26 +329,17 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla } - /** - * Switched delete to hard delete of group. Will use 'status' when is added - * to determine if group can be deleted or not along with contraints on - * database i.e. cant delete group with any loans/savings accounts. - */ @Transactional @Override public CommandProcessingResult deleteGroup(final Long groupId) { - this.context.authenticatedUser(); - final Group groupForDelete = this.groupRepository.findOne(groupId); if (groupForDelete == null) { throw new GroupNotFoundException(groupId); } - // groupForDelete.delete(); - // this.groupRepository.save(groupForDelete); + if (groupForDelete.isNotPending()) { throw new GroupMustBePendingToBeDeletedException(groupId); } - // List relatedNotes = - // this.noteRepository.findByLoanId(loan.getId()); - // this.noteRepository.deleteInBatch(relatedNotes); + final List relatedNotes = this.noteRepository.findByGroupId(groupId); + this.noteRepository.deleteInBatch(relatedNotes); this.groupRepository.delete(groupId); @@ -342,7 +353,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla private Set assembleSetOfClients(final Long officeId, final JsonCommand command) { final Set clientMembers = new HashSet(); - final String[] clientMembersArray = command.arrayValueOfParameterNamed("clientMembers"); + final String[] clientMembersArray = command.arrayValueOfParameterNamed(GroupingTypesApiConstants.clientMembersParamName); if (!ObjectUtils.isEmpty(clientMembersArray)) { for (final String clientId : clientMembersArray) { @@ -360,16 +371,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla return clientMembers; } - /*private Set assembleSetOfChildGroups(final Long officeId, final JsonCommand command) { + private Set assembleSetOfChildGroups(final Long officeId, final JsonCommand command) { final Set childGroups = new HashSet(); - final String[] childGroupsArray = command.arrayValueOfParameterNamed("childGroups"); + final String[] childGroupsArray = command.arrayValueOfParameterNamed(GroupingTypesApiConstants.groupMembersParamName); if (!ObjectUtils.isEmpty(childGroupsArray)) { for (final String groupId : childGroupsArray) { final Long id = Long.valueOf(groupId); final Group group = this.groupRepository.findOne(id); - if (group == null || group.isDeleted()) { throw new GroupNotFoundException(id); } + if (group == null) { throw new GroupNotFoundException(id); } if (!group.isOfficeIdentifiedBy(officeId)) { final String errorMessage = "Group and child groups must have the same office."; throw new InvalidOfficeException("group", "attach.to.parent.group", errorMessage); @@ -379,7 +390,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla } return childGroups; - }*/ + } private String[] getClientIds(final Set clients) { @@ -396,7 +407,19 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla * is. */ private void handleGroupDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve, - final GroupLevel groupLevel) { + final GroupTypes groupLevel) { + + String levelName = "Invalid"; + switch (groupLevel) { + case CENTER: + levelName = "Center"; + break; + case GROUP: + levelName = "Group"; + break; + case INVALID: + break; + } final Throwable realCause = dve.getMostSpecificCause(); String errorMessageForUser = null; @@ -404,20 +427,22 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla if (realCause.getMessage().contains("external_id")) { - final String externalId = command.stringValueOfParameterNamed("externalId"); - errorMessageForUser = groupLevel.getLevelName() + " with externalId `" + externalId + "` already exists."; - errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase() + ".duplicate.externalId"; - throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "externalId", externalId); + final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); + errorMessageForUser = levelName + " with externalId `" + externalId + "` already exists."; + errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.externalId"; + throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, + GroupingTypesApiConstants.externalIdParamName, externalId); } else if (realCause.getMessage().contains("name")) { - final String name = command.stringValueOfParameterNamed("name"); - errorMessageForUser = groupLevel.getLevelName() + " with name `" + name + "` already exists."; - errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase() + ".duplicate.name"; - throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "name", name); + final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); + errorMessageForUser = levelName + " with name `" + name + "` already exists."; + errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.name"; + throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, GroupingTypesApiConstants.nameParamName, + name); } logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java index cc8cddc07..a82cacdd0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java @@ -96,7 +96,8 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe private static final class StaffGroupMapper implements RowMapper { public String schema() { - return " g.id as id, g.name as name from m_group g" + " join m_loan l on g.id = l.group_id where l.loan_officer_id = ? "; + return " g.id as id, g.display_name as name from m_group g" + + " join m_loan l on g.id = l.group_id where l.loan_officer_id = ? "; } @Override diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java index d59fd4f2c..7a4ce06dd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java @@ -139,7 +139,7 @@ public class LoanAssembler { if (groupId != null) { group = this.groupRepository.findOne(groupId); - if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); } + if (group == null) { throw new GroupNotFoundException(groupId); } loanApplication = Loan.newGroupLoanApplication(accountNo, group, loanProduct, fund, loanOfficer, loanTransactionProcessingStrategy, loanSchedule, loanCharges); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index 3b278061f..b620e0dc5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -296,7 +296,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { + " l.loanpurpose_cv_id as loanPurposeId, cv.code_value as loanPurposeName," + " lp.id as loanProductId, lp.name as loanProductName, lp.description as loanProductDescription," + " c.id as clientId, c.display_name as clientName, c.office_id as clientOfficeId," - + " g.id as groupId, g.name as groupName, g.office_id as groupOfficeId, g.staff_id As groupStaffId , g.parent_id as groupParentId , g.hierarchy As groupHierarchy , g.external_id As groupExternalId , " + + " g.id as groupId, g.display_name as groupName, g.office_id as groupOfficeId, g.staff_id As groupStaffId , g.parent_id as groupParentId , g.hierarchy As groupHierarchy , g.external_id As groupExternalId , " + " l.submittedon_date as submittedOnDate, sbu.username as submittedByUsername, sbu.firstname as submittedByFirstname, sbu.lastname as submittedByLastname," + " l.rejectedon_date as rejectedOnDate, rbu.username as rejectedByUsername, rbu.firstname as rejectedByFirstname, rbu.lastname as rejectedByLastname," + " l.withdrawnon_date as withdrawnOnDate, wbu.username as withdrawnByUsername, wbu.firstname as withdrawnByFirstname, wbu.lastname as withdrawnByLastname," diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/domain/NoteRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/domain/NoteRepository.java index e68bb16f9..9d4a628f4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/domain/NoteRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/domain/NoteRepository.java @@ -16,6 +16,8 @@ public interface NoteRepository extends JpaRepository, JpaSpecificat List findByClientId(Long id); + List findByGroupId(Long groupId); + Note findByLoanIdAndId(Long loanId, Long id); Note findByClientIdAndId(Long clientId, Long id); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java index c90069cd2..050f64aa5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java @@ -84,7 +84,7 @@ public class SavingsAccountAssembler { if (groupId != null) { group = this.groupRepository.findOne(groupId); - if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); } + if (group == null) { throw new GroupNotFoundException(groupId); } } BigDecimal interestRate = null; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java index 73def8220..085fb74c9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java @@ -99,7 +99,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead sqlBuilder.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, "); sqlBuilder.append("sa.status_enum as statusEnum, sa.activation_date as activationDate, "); sqlBuilder.append("c.id as clientId, c.display_name as clientName, "); - sqlBuilder.append("g.id as groupId, g.name as groupName, "); + sqlBuilder.append("g.id as groupId, g.display_name as groupName, "); sqlBuilder.append("sp.id as productId, sp.name as productName, "); sqlBuilder.append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, "); sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 6bf9e2e00..a9088d03e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -173,7 +173,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName); if (groupId != null) { final Group group = this.groupRepository.findOne(groupId); - if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); } + if (group == null) { throw new GroupNotFoundException(groupId); } account.update(group); } else { final Group group = null; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/search/service/SearchReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/search/service/SearchReadPlatformServiceImpl.java index 3ba2e3963..131ab486a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/search/service/SearchReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/search/service/SearchReadPlatformServiceImpl.java @@ -29,7 +29,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService } @Override - public Collection retriveMatchingData(SearchConditions searchConditions) { + public Collection retriveMatchingData(final SearchConditions searchConditions) { AppUser currentUser = context.authenticatedUser(); String hierarchy = currentUser.getOffice().getHierarchy(); @@ -45,7 +45,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService private static final class SearchMapper implements RowMapper { - public String searchSchema(SearchConditions searchConditions) { + public String searchSchema(final SearchConditions searchConditions) { String union = " union all "; String clientExactMatchSql = " (select 'CLIENT' as entityType, c.id as entityId, c.display_name as entityName, c.external_id as entityExternalId, c.account_no as entityAccountNo " @@ -76,13 +76,13 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService + " from m_client_identifier ci join m_client c on ci.client_id=c.id join m_office o on o.id = c.office_id " + " where o.hierarchy like :hierarchy and ci.document_key like :partialSearch and ci.document_key not like :search) "; - String groupExactMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo " + String groupExactMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.display_name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo " + " , g.office_id as parentId, o.name as parentName " - + " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.name like :search) "; + + " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.display_name like :search) "; - String groupMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo " + String groupMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.display_name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo " + " , g.office_id as parentId, o.name as parentName " - + " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.name like :partialSearch and g.name not like :search) "; + + " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.display_name like :partialSearch and g.display_name not like :search) "; StringBuffer sql = new StringBuffer(); @@ -127,7 +127,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService } @Override - public SearchData mapRow(ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + public SearchData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long entityId = JdbcSupport.getLong(rs, "entityId"); final String entityAccountNo = rs.getString("entityAccountNo"); final String entityExternalId = rs.getString("entityExternalId");