diff --git a/mifosng-db/patches/22-group_name_modified_to_not_null.sql b/mifosng-db/patches/22-group_name_modified_to_not_null.sql new file mode 100644 index 000000000..72eae9345 --- /dev/null +++ b/mifosng-db/patches/22-group_name_modified_to_not_null.sql @@ -0,0 +1 @@ +ALTER TABLE m_group MODIFY name VARCHAR(100) NOT NULL; \ No newline at end of file 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 a99f56e38..c3b4b43fc 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 @@ -45,9 +45,13 @@ import org.springframework.stereotype.Component; @Scope("singleton") public class GroupsApiResource { - private static final Set GROUP_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "officeId", "name", "externalId", - "clientMembers", "allowedClients", "allowedOffices", "allowedParentGroups", "groupLevel", "allowedStaffs", "childGroups")); - + /* + * GROUP_DATA_PARAMETERS is used by ToApiJsonSerializer, make sure E's properties and E_PARAMETERS are in same + */ + private static final Set GROUP_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "name", "externalId", "officeId", + "officeName", "staffId", "staffName", "parentId", "parentName", "hierarchy", "groupSummaryData", "groupLevelData", + "clientMembers", "allowedClients", "allowedOffices", "allowedParentGroups", "allowedStaffs", "childGroups")); + private final PlatformSecurityContext context; private final GroupReadPlatformService groupReadPlatformService; private final ToApiJsonSerializer toApiJsonSerializer; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java index a0c1e3adc..4aaabe103 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java @@ -23,12 +23,11 @@ public class GroupData { private final String officeName; private final Long staffId; private final String staffName; - private final Long groupLevel; private final Long parentId; private final String parentName; private final String hierarchy; @SuppressWarnings("unused") - private final GroupSummaryData groupSummaryData; + private final GroupSummary groupSummaryData; @SuppressWarnings("unused") private final GroupLevelData groupLevelData; private final Collection clientMembers; @@ -37,21 +36,19 @@ public class GroupData { @SuppressWarnings("unused") private final Collection allowedOffices; @SuppressWarnings("unused") - private final Collection allowedParentGroups; + private final Collection allowedParentGroups; @SuppressWarnings("unused") private final Collection allowedStaffs; @SuppressWarnings("unused") - private final Collection childGroups; + private final Collection childGroups; public GroupData(final Long id, final Long officeId, final String officeName, final String name, final String externalId, - final Long groupLevel, final Long parentId, final String parentName, final Long staffId, final String staffName, - final String hierarchy) { + final Long parentId, final String parentName, final Long staffId, final String staffName, final String hierarchy) { this.id = id; this.officeId = officeId; this.officeName = officeName; this.name = name; this.externalId = externalId; - this.groupLevel = groupLevel; this.parentId = parentId; this.parentName = parentName; this.staffId = staffId; @@ -68,15 +65,14 @@ public class GroupData { } public GroupData(final GroupData group, final Collection clientMembers, final Collection allowedClients, - final Collection allowedOffices, final Collection allowedParentGroups, - final GroupLevelData groupLevelData, final Collection allowedStaffs, final Collection childGroups, - final GroupSummaryData groupSummaryData) { + final Collection allowedOffices, final Collection allowedParentGroups, + final GroupLevelData groupLevelData, final Collection allowedStaffs, final Collection childGroups, + final GroupSummary groupSummaryData) { this.id = group.getId(); this.officeId = group.getOfficeId(); this.officeName = group.getOfficeName(); this.name = group.getName(); this.externalId = group.getExternalId(); - this.groupLevel = group.getGroupLevel(); this.parentId = group.getParentId(); this.parentName = group.getParentName(); this.staffId = group.getStaffId(); @@ -94,7 +90,7 @@ public class GroupData { } public GroupData(final Long officeId, final Collection allowedClients, final Collection allowedOffices, - final Collection allowedParentGroups, final GroupLevelData groupLevelData, + final Collection allowedParentGroups, final GroupLevelData groupLevelData, final Collection allowedStaffs) { this.id = null; this.officeId = officeId; @@ -102,7 +98,6 @@ public class GroupData { this.name = null; this.externalId = null; this.clientMembers = null; - this.groupLevel = null; this.parentId = null; this.parentName = null; this.staffId = null; @@ -137,10 +132,6 @@ public class GroupData { return this.officeName; } - public Long getGroupLevel() { - return this.groupLevel; - } - public Long getParentId() { return this.parentId; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookupData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java similarity index 85% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookupData.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java index 557a7415c..eb2793e99 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookupData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupLookup.java @@ -8,12 +8,12 @@ package org.mifosplatform.portfolio.group.data; /** * Immutable data object representing groups. */ -public class GroupLookupData { +public class GroupLookup { private final Long id; private final String name; - public GroupLookupData(final Long id, final String name) { + public GroupLookup(final Long id, final String name) { this.id = id; this.name = name; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummaryData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummary.java similarity index 87% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummaryData.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummary.java index 4d700a9cc..fc4993160 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummaryData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupSummary.java @@ -9,14 +9,14 @@ import java.util.Collection; import org.mifosplatform.organisation.monetary.data.MoneyData; -public class GroupSummaryData { +public class GroupSummary { private final Long totalActiveClients; private final Long totalChildGroups; private final Collection totalLoanPortfolio; private final Collection totalSavings; - public GroupSummaryData(final Long totalActiveClients, final Long totalChildGroups, final Collection totalLoanPortfolio, + public GroupSummary(final Long totalActiveClients, final Long totalChildGroups, final Collection totalLoanPortfolio, final Collection totalSavings) { this.totalActiveClients = totalActiveClients; this.totalChildGroups = totalChildGroups; 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 index eaeee4d3b..ce4dc8673 100644 --- 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 @@ -80,6 +80,13 @@ public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJs 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)) { @@ -87,11 +94,13 @@ public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJs baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100); } + /* + * OfficeId is mandatory field + */ final String officeIdParameterName = "officeId"; - if (this.fromApiJsonHelper.parameterExists(officeIdParameterName, element)) { - final Long officeId = this.fromApiJsonHelper.extractLongNamed(officeIdParameterName, element); - baseDataValidator.reset().parameter(officeIdParameterName).value(officeId).notNull().integerGreaterThanZero(); - } + final Long officeId = this.fromApiJsonHelper.extractLongNamed(officeIdParameterName, element); + baseDataValidator.reset().parameter(officeIdParameterName).value(officeId).notNull().integerGreaterThanZero(); + final String parentIdParameterName = "parentId"; if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) { 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 2019a8ef9..4c9b057b8 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 @@ -14,7 +14,7 @@ import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.group.data.GroupLevelData; -import org.mifosplatform.portfolio.group.data.GroupLookupData; +import org.mifosplatform.portfolio.group.data.GroupLookup; public interface GroupReadPlatformService { @@ -30,7 +30,7 @@ public interface GroupReadPlatformService { Collection retrieveGroupLoanAccountsByLoanOfficerId(Long groupId, Long loanOfficerId); - Collection retrieveAllGroupsbyOfficeIdAndLevelId(Long officeId, Long levelId); + Collection retrieveAllGroupsbyOfficeIdAndLevelId(Long officeId, Long levelId); GroupLevelData retrieveGroupLevelDetails(Long levelId); @@ -38,7 +38,7 @@ public interface GroupReadPlatformService { GroupData retrieveGroupDetails(Long groupId, boolean template); - Collection retrieveChildGroupsbyGroupId(Long groupId); + Collection retrieveChildGroupsbyGroupId(Long groupId); Long retrieveTotalNoOfChildGroups(Long groupId); @@ -49,4 +49,6 @@ public interface GroupReadPlatformService { GroupData retrieveNewChildGroupDetails(Long officeId, Long levelId, Long parentGroupId); StaffData retrieveStaffsbyId(Long staffId); + + Long getLevelIdByGroupId(final Long groupId); } 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 4dee80941..d3645cbb7 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 @@ -28,8 +28,8 @@ import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.group.data.GroupLevelData; -import org.mifosplatform.portfolio.group.data.GroupLookupData; -import org.mifosplatform.portfolio.group.data.GroupSummaryData; +import org.mifosplatform.portfolio.group.data.GroupLookup; +import org.mifosplatform.portfolio.group.data.GroupSummary; import org.mifosplatform.portfolio.group.domain.Group; import org.mifosplatform.portfolio.group.domain.GroupRepository; import org.mifosplatform.portfolio.group.exception.GroupLevelNotFoundException; @@ -93,7 +93,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } @Override - public Collection retrieveAllGroupsbyOfficeIdAndLevelId(final Long officeId, final Long levelId) { + public Collection retrieveAllGroupsbyOfficeIdAndLevelId(final Long officeId, final Long levelId) { this.context.authenticatedUser(); final GroupLookupMapper rm = new GroupLookupMapper(); @@ -101,7 +101,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { return this.jdbcTemplate.query(sql, rm, new Object[] { officeId, levelId }); } - private GroupLookupData retrieveGroupbyId(final Long parentGroupId) { + private GroupLookup retrieveGroupbyId(final Long parentGroupId) { try { this.context.authenticatedUser(); final GroupLookupMapper rm = new GroupLookupMapper(); @@ -114,7 +114,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } @Override - public Collection retrieveChildGroupsbyGroupId(final Long groupId) { + public Collection retrieveChildGroupsbyGroupId(final Long groupId) { this.context.authenticatedUser(); final GroupLookupMapper rm = new GroupLookupMapper(); @@ -155,10 +155,10 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { final List allowedOffices = new ArrayList(this.officeReadPlatformService.retrieveAllOfficesForDropdown()); - List allowedParentGroups = null; + List allowedParentGroups = null; if (groupLevelData.getParentLevelId() != null) { - allowedParentGroups = new ArrayList(retrieveAllGroupsbyOfficeIdAndLevelId(officeId, + allowedParentGroups = new ArrayList(retrieveAllGroupsbyOfficeIdAndLevelId(officeId, groupLevelData.getParentLevelId())); } @@ -190,7 +190,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { final List allowedOffices = new ArrayList(); allowedOffices.add(this.officeReadPlatformService.retrieveOffice(officeId)); - final List allowedParentGroups = new ArrayList(); + final List allowedParentGroups = new ArrayList(); allowedParentGroups.add(retrieveGroupbyId(parentGroupId)); final List allowedStaffs = new ArrayList(); @@ -206,17 +206,17 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { final Collection clientMembers = retrieveClientMembers(groupId); Collection availableClients = null; Collection allowedOffices = null; - Collection allowedParentGroups = null; - final GroupLevelData groupLevelData = retrieveGroupLevelDetails(group.getGroupLevel()); + Collection allowedParentGroups = null; + final GroupLevelData groupLevelData = retrieveGroupLevelDetails(getLevelIdByGroupId(groupId)); ; Collection allowedStaffs = null; - final Collection childGroups = retrieveChildGroupsbyGroupId(groupId); + final Collection childGroups = retrieveChildGroupsbyGroupId(groupId); final Long totalActiveClients = retrieveTotalClients(group.getHierarchy()); final Long totalChildGroups = retrieveTotalNoOfChildGroups(groupId); final Collection totalLoanPortfolio = retrieveGroupLoanPortfolio(group.getHierarchy()); - final GroupSummaryData groupSummaryData = new GroupSummaryData(totalActiveClients, totalChildGroups, totalLoanPortfolio, null); + final GroupSummary groupSummaryData = new GroupSummary(totalActiveClients, totalChildGroups, totalLoanPortfolio, null); group = new GroupData(group, clientMembers, availableClients, allowedOffices, allowedParentGroups, groupLevelData, allowedStaffs, childGroups, groupSummaryData); @@ -265,6 +265,15 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } } + @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) { @@ -323,7 +332,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { private static final class GroupDataMapper implements RowMapper { public String groupSchema() { - return "g.office_id as officeId, g.level_id as groupLevel , g.parent_id as parentId , o.name as officeName," + return "g.office_id as officeId, g.parent_id as parentId , o.name as officeName," + " g.id as id, g.external_id as externalId, g.name as name , s.display_name as staffName , pg.name as" + " parentName , g.staff_id as staffId , 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 left join m_group pg on pg.id = g.parent_id"; @@ -337,32 +346,31 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { final String externalId = rs.getString("externalId"); final Long officeId = rs.getLong("officeId"); final String officeName = rs.getString("officeName"); - final Long groupLevel = rs.getLong("groupLevel"); - final Long parentId = JdbcSupport.getLong(rs, "parentId"); + final Long parentId = rs.getLong("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 new GroupData(id, officeId, officeName, name, externalId, groupLevel, parentId, parentName, staffId, staffName, + return new GroupData(id, officeId, officeName, name, externalId, parentId, parentName, staffId, staffName, hierarchy); } } - private static final class GroupLookupMapper implements RowMapper { + private static final class GroupLookupMapper implements RowMapper { public String groupLookupSchema() { return "g.id as id, g.name as name "; } @Override - public GroupLookupData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + public GroupLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = rs.getLong("id"); final String name = rs.getString("name"); - return new GroupLookupData(id, name); + return new GroupLookup(id, name); } }