updating Client crud service & Db schema for MifosX-35

This commit is contained in:
Vishwas Babu A J
2012-09-05 01:27:54 +05:30
parent b9c8f63441
commit a22d5d10aa
4 changed files with 672 additions and 649 deletions
@@ -0,0 +1,4 @@
ALTER TABLE `m_client`
ADD COLUMN `display_name` VARCHAR(100) NOT NULL AFTER `lastname`;
update m_client set display_name = concat_ws(' ',firstname,lastname);
@@ -22,22 +22,18 @@ public class ClientData {
public ClientData(final Long officeId, final String officeName,
final Long id, final String firstname, final String lastname,
final String externalId, final LocalDate joinedDate) {
final String displayName, final String externalId,
final LocalDate joinedDate) {
this.officeId = officeId;
this.officeName = officeName;
this.id = id;
this.firstname = firstname;
this.displayName = displayName;
StringBuilder nameBuilder = new StringBuilder(this.firstname);
if (StringUtils.isNotBlank(nameBuilder.toString())) {
nameBuilder.append(' ');
}
nameBuilder.append(lastname);
this.displayName = nameBuilder.toString();
/*** unset last name for business name **/
if (StringUtils.isBlank(this.firstname)) {
this.lastname = null;
this.clientOrBusinessName = nameBuilder.toString();
this.clientOrBusinessName = lastname;
} else {
this.lastname = lastname;
this.clientOrBusinessName = null;
@@ -47,7 +43,8 @@ public class ClientData {
this.joinedDate = joinedDate;
}
public ClientData(final Long officeId, final LocalDate joinedDate, final List<OfficeLookup> offices) {
public ClientData(final Long officeId, final LocalDate joinedDate,
final List<OfficeLookup> offices) {
this.id = null;
this.officeId = officeId;
this.officeName = null;
@@ -34,6 +34,10 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "lastname", length=50)
private String lastName;
@SuppressWarnings("unused")
@Column(name = "display_name", length=50)
private String displayName;
@SuppressWarnings("unused")
@Column(name = "joining_date")
@Temporal(TemporalType.DATE)
@@ -71,6 +75,12 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
this.firstName = null;
}
this.lastName = lastName.trim();
//populate display name
if(this.firstName!=null){
this.displayName = this.firstName + " " + this.lastName;
}else{
this.displayName = this.lastName;
}
}
public boolean identifiedBy(final String identifier) {
@@ -89,6 +99,9 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
this.firstName = null;
this.lastName = command.getClientOrBusinessName().trim();
this.displayName = this.lastName;
}else{
deriveDisplayName();
}
if (StringUtils.isNotBlank(command.getExternalId())) {
@@ -115,6 +128,10 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
if (command.isClientOrBusinessNameChanged() && StringUtils.isNotBlank(command.getClientOrBusinessName())) {
this.lastName = command.getClientOrBusinessName();
this.firstName = null;
this.displayName = this.lastName;
}else if(command.isFirstnameChanged() || command.isLastnameChanged()) {
//do not want to enter this condition for business names
deriveDisplayName();
}
if (command.isExternalIdChanged()) {
@@ -122,6 +139,10 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
}
}
private void deriveDisplayName() {
this.displayName = this.firstName + " " + this.lastName;
}
/**
* Delete is a <i>soft delete</i>. Updates flag on client so it wont appear in query/report results.
*
@@ -131,8 +131,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
}
public String clientSchema() {
return "c.office_id as officeId, c.id as id, c.firstname as firstname, c.lastname as lastname, c.external_id as externalId, " +
"c.joining_date as joinedDate from m_client c";
return "c.office_id as officeId, c.id as id, c.firstname as firstname, c.lastname as lastname, c.display_name as displayName, " +
"c.external_id as externalId, c.joining_date as joinedDate from m_client c";
}
@Override
@@ -146,13 +146,14 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
firstname = "";
}
String lastname = rs.getString("lastname");
String displayName = rs.getString("displayName");
String externalId = rs.getString("externalId");
LocalDate joinedDate = JdbcSupport.getLocalDate(rs, "joinedDate");
String officeName = fromOfficeList(this.offices, officeId);
return new ClientData(officeId, officeName, id, firstname,
lastname, externalId, joinedDate);
lastname, displayName, externalId, joinedDate);
}
private String fromOfficeList(final List<OfficeData> officeList,