recommiting change after pull that still showed as modified

This commit is contained in:
John Woodlock
2012-10-03 15:46:50 +10:00
parent b86966caf9
commit f3c63671a0
@@ -1,160 +1,160 @@
package org.mifosng.platform.client.domain; package org.mifosng.platform.client.domain;
import java.util.Date; import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.organisation.domain.Office; import org.mifosng.platform.organisation.domain.Office;
import org.mifosng.platform.user.domain.AppUser; import org.mifosng.platform.user.domain.AppUser;
@Entity @Entity
@Table(name = "m_client") @Table(name = "m_client")
public class Client extends AbstractAuditableCustom<AppUser, Long> { public class Client extends AbstractAuditableCustom<AppUser, Long> {
@ManyToOne @ManyToOne
@JoinColumn(name = "office_id", nullable = false) @JoinColumn(name = "office_id", nullable = false)
private Office office; private Office office;
@Column(name = "firstname", length=50) @Column(name = "firstname", length=50)
private String firstName; private String firstName;
@Column(name = "lastname", length=50) @Column(name = "lastname", length=50)
private String lastName; private String lastName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Column(name = "display_name", length=50) @Column(name = "display_name", length=50)
private String displayName; private String displayName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Column(name = "joining_date") @Column(name = "joining_date")
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
private Date joiningDate; private Date joiningDate;
@Column(name = "external_id", length=100, unique=true) @Column(name = "external_id", length=100, unique=true)
private String externalId; private String externalId;
@Column(name = "is_deleted", nullable=false) @Column(name = "is_deleted", nullable=false)
private boolean deleted = false; private boolean deleted = false;
public static Client newClient(Office clientOffice, String firstname, String lastname, LocalDate joiningDate, String externalId) { public static Client newClient(Office clientOffice, String firstname, String lastname, LocalDate joiningDate, String externalId) {
return new Client(clientOffice, firstname, lastname, joiningDate, externalId); return new Client(clientOffice, firstname, lastname, joiningDate, externalId);
} }
protected Client() { protected Client() {
this.office = null; this.office = null;
this.joiningDate = null; this.joiningDate = null;
this.firstName = null; this.firstName = null;
this.lastName = null; this.lastName = null;
this.externalId = null; this.externalId = null;
} }
private Client(final Office office, final String firstName, final String lastName, final LocalDate openingDate, final String externalId) { private Client(final Office office, final String firstName, final String lastName, final LocalDate openingDate, final String externalId) {
this.office = office; this.office = office;
if (StringUtils.isNotBlank(externalId)) { if (StringUtils.isNotBlank(externalId)) {
this.externalId = externalId.trim(); this.externalId = externalId.trim();
} else { } else {
this.externalId = null; this.externalId = null;
} }
this.joiningDate = openingDate.toDateMidnight().toDate(); this.joiningDate = openingDate.toDateMidnight().toDate();
if (StringUtils.isNotBlank(firstName)) { if (StringUtils.isNotBlank(firstName)) {
this.firstName = firstName.trim(); this.firstName = firstName.trim();
} else { } else {
this.firstName = null; this.firstName = null;
} }
this.lastName = lastName.trim(); this.lastName = lastName.trim();
//populate display name //populate display name
if(this.firstName!=null){ if(this.firstName!=null){
this.displayName = this.firstName + " " + this.lastName; this.displayName = this.firstName + " " + this.lastName;
}else{ }else{
this.displayName = this.lastName; this.displayName = this.lastName;
} }
} }
public boolean identifiedBy(final String identifier) { public boolean identifiedBy(final String identifier) {
return identifier.equalsIgnoreCase(this.externalId); return identifier.equalsIgnoreCase(this.externalId);
} }
public boolean identifiedBy(Long clientId) { public boolean identifiedBy(Long clientId) {
return getId().equals(clientId); return getId().equals(clientId);
} }
public void update(ClientCommand command) { public void update(ClientCommand command) {
this.joiningDate = command.getJoiningDate().toDate(); this.joiningDate = command.getJoiningDate().toDate();
this.firstName = command.getFirstname(); this.firstName = command.getFirstname();
this.lastName = command.getLastname(); this.lastName = command.getLastname();
if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
this.firstName = null; this.firstName = null;
this.lastName = command.getClientOrBusinessName().trim(); this.lastName = command.getClientOrBusinessName().trim();
this.displayName = this.lastName; this.displayName = this.lastName;
}else{ }else{
deriveDisplayName(); deriveDisplayName();
} }
if (StringUtils.isNotBlank(command.getExternalId())) { if (StringUtils.isNotBlank(command.getExternalId())) {
this.externalId = command.getExternalId().trim(); this.externalId = command.getExternalId().trim();
} else { } else {
this.externalId = null; this.externalId = null;
} }
} }
public void update(final Office clientOffice, final ClientCommand command) { public void update(final Office clientOffice, final ClientCommand command) {
if (command.isOfficeChanged()) { if (command.isOfficeChanged()) {
this.office = clientOffice; this.office = clientOffice;
} }
if (command.isJoiningDateChanged()) { if (command.isJoiningDateChanged()) {
this.joiningDate = command.getJoiningDate().toDate(); this.joiningDate = command.getJoiningDate().toDate();
} }
if (command.isFirstnameChanged()) { if (command.isFirstnameChanged()) {
this.firstName = command.getFirstname(); this.firstName = command.getFirstname();
} }
if (command.isLastnameChanged()) { if (command.isLastnameChanged()) {
this.lastName = command.getLastname(); this.lastName = command.getLastname();
} }
if (command.isClientOrBusinessNameChanged() && StringUtils.isNotBlank(command.getClientOrBusinessName())) { if (command.isClientOrBusinessNameChanged() && StringUtils.isNotBlank(command.getClientOrBusinessName())) {
this.lastName = command.getClientOrBusinessName(); this.lastName = command.getClientOrBusinessName();
this.firstName = null; this.firstName = null;
this.displayName = this.lastName; this.displayName = this.lastName;
}else if(command.isFirstnameChanged() || command.isLastnameChanged()) { }else if(command.isFirstnameChanged() || command.isLastnameChanged()) {
//do not want to enter this condition for business names //do not want to enter this condition for business names
deriveDisplayName(); deriveDisplayName();
} }
if (command.isExternalIdChanged()) { if (command.isExternalIdChanged()) {
this.externalId = StringUtils.defaultIfEmpty(command.getExternalId().trim(), null); this.externalId = StringUtils.defaultIfEmpty(command.getExternalId().trim(), null);
} }
} }
private void deriveDisplayName() { private void deriveDisplayName() {
this.displayName = this.firstName + " " + this.lastName; 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. * Delete is a <i>soft delete</i>. Updates flag on client so it wont appear in query/report results.
* *
* Any fields with unique constraints and prepended with id of record. * Any fields with unique constraints and prepended with id of record.
*/ */
public void delete() { public void delete() {
this.deleted = true; this.deleted = true;
this.externalId = this.getId() + "_" + this.externalId; this.externalId = this.getId() + "_" + this.externalId;
} }
public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }
public boolean isOfficeIdentifiedBy(final Long officeId) { public boolean isOfficeIdentifiedBy(final Long officeId) {
return this.office.identifiedBy(officeId); return this.office.identifiedBy(officeId);
} }
} }