add nameDecorated to officeData to present office hierarchy easier

This commit is contained in:
John Woodlock
2012-07-12 17:17:54 +10:00
parent 574b5e025d
commit 47c5f33d23
2 changed files with 25 additions and 8 deletions
@@ -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;
}
@@ -33,11 +33,13 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
this.context = context;
this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
private static final class OfficeMapper implements RowMapper<OfficeData> {
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<OfficeLookup> {
private static final class OfficeLookupMapper implements
RowMapper<OfficeLookup> {
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