From 47c5f33d23670a071b155b5e61426a77afe78c38 Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Thu, 12 Jul 2012 17:17:54 +1000 Subject: [PATCH] add nameDecorated to officeData to present office hierarchy easier --- .../mifosng/platform/api/data/OfficeData.java | 15 +++++++++++++-- .../service/OfficeReadPlatformServiceImpl.java | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java index 886b77742..b863c47c3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java @@ -12,6 +12,7 @@ public class OfficeData implements Serializable { private Long id; private String name; + private String nameDecorated; private String externalId; private LocalDate openingDate; private String hierarchy; @@ -24,10 +25,12 @@ public class OfficeData implements Serializable { } public OfficeData(final Long id, final String name, - final String externalId, final LocalDate openingDate, - String hierarchy, final Long parentId, final String parentName) { + final String nameDecorated, final String externalId, + final LocalDate openingDate, String hierarchy, final Long parentId, + final String parentName) { this.id = id; this.name = name; + this.nameDecorated = nameDecorated; this.externalId = externalId; this.openingDate = openingDate; this.hierarchy = hierarchy; @@ -43,6 +46,10 @@ public class OfficeData implements Serializable { return this.name; } + public String getNameDecorated() { + return nameDecorated; + } + public String getExternalId() { return this.externalId; } @@ -67,6 +74,10 @@ public class OfficeData implements Serializable { this.name = name; } + public void setNameDecorated(String nameDecorated) { + this.nameDecorated = nameDecorated; + } + public void setExternalId(final String externalId) { this.externalId = externalId; } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java index 3bc5a91f9..62c21cba0 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java @@ -33,11 +33,13 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService this.context = context; this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); } - + private static final class OfficeMapper implements RowMapper { public String officeSchema() { - return " o.id as id, o.name as name, o.external_id as externalId, o.opening_date as openingDate, o.hierarchy as hierarchy, parent.id as parentId, parent.name as parentName " + return " o.id as id, o.name as name, " + + "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)" + + " as nameDecorated, o.external_id as externalId, o.opening_date as openingDate, o.hierarchy as hierarchy, parent.id as parentId, parent.name as parentName " + "from org_office o LEFT JOIN org_office AS parent ON parent.id = o.parent_id "; } @@ -47,17 +49,20 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService Long id = rs.getLong("id"); String name = rs.getString("name"); + String nameDecorated = rs.getString("nameDecorated"); String externalId = rs.getString("externalId"); LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate"); String hierarchy = rs.getString("hierarchy"); Long parentId = JdbcSupport.getLong(rs, "parentId"); String parentName = rs.getString("parentName"); - return new OfficeData(id, name, externalId, openingDate, hierarchy, parentId, parentName); + return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, + parentId, parentName); } } - - private static final class OfficeLookupMapper implements RowMapper { + + private static final class OfficeLookupMapper implements + RowMapper { public String officeLookupSchema() { return " o.id as id, o.name as name from org_office o "; @@ -103,7 +108,8 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService + rm.officeLookupSchema() + "where o.org_id = ? and o.hierarchy like ? order by o.hierarchy"; - return this.jdbcTemplate.query(sql, rm, new Object[] {currentUser.getOrganisation().getId(), hierarchySearchString }); + return this.jdbcTemplate.query(sql, rm, new Object[] { + currentUser.getOrganisation().getId(), hierarchySearchString }); } @Override