org.nakedobjects.example.expenses.employee.Employee Maven / Gradle / Ivy
package org.nakedobjects.example.expenses.employee;
import org.nakedobjects.applib.AbstractDomainObject;
import org.nakedobjects.applib.annotation.Disabled;
import org.nakedobjects.applib.annotation.Hidden;
import org.nakedobjects.applib.annotation.MemberOrder;
import org.nakedobjects.applib.annotation.Optional;
import org.nakedobjects.applib.annotation.RegEx;
import org.nakedobjects.example.expenses.currency.Currency;
import org.nakedobjects.example.expenses.recordedAction.Actor;
import org.nakedobjects.example.expenses.recordedAction.RecordActionService;
import org.nakedobjects.example.expenses.recordedAction.RecordedActionContext;
import org.nakedobjects.example.expenses.services.UserFinder;
public class Employee extends AbstractDomainObject implements Actor, RecordedActionContext {
// {{ Title
public String title() {
return getName();
}
// }}
// {{ Injected Services
// {{ Injected: RecordActionService
private RecordActionService recordActionService;
/**
* This property is not persisted, nor displayed to the user.
*/
protected RecordActionService getRecordActionService() {
return this.recordActionService;
}
/**
* Injected by the application container.
*/
public void setRecordActionService(final RecordActionService recordActionService) {
this.recordActionService = recordActionService;
}
// }}
// {{ Injected: UserFinder
private UserFinder userFinder;
/**
* This property is not persisted, nor displayed to the user.
*/
protected UserFinder getUserFinder() {
return this.userFinder;
}
/**
* Injected by the application container.
*/
public void setUserFinder(final UserFinder userFinder) {
this.userFinder = userFinder;
}
// }}
// }}
// {{ Name
private String name;
@MemberOrder(sequence = "1")
@Disabled
public String getName() {
resolve(name);
return this.name;
}
public void setName(String name) {
this.name = name;
objectChanged();
}
// }}
// {{ UserName field
private String userName;
/**
* Hidden field containing this TeamMember log-on username
*/
@Hidden
public String getUserName() {
resolve(userName);
return userName;
}
/**
* @see #getUserName
*/
public void setUserName(final String variable) {
this.userName = variable;
objectChanged();
}
// }}
// {{ EmailAddress
private String emailAddress;
@RegEx(validation = "(\\w+\\.)*\\w+@(\\w+\\.)+[A-Za-z]+")
@MemberOrder(sequence = "2")
@Optional
public String getEmailAddress() {
resolve(emailAddress);
return this.emailAddress;
}
public void setEmailAddress(final String emailAddress) {
this.emailAddress = emailAddress;
objectChanged();
}
public void modifyEmailAddress(final String emailAddress) {
getRecordActionService().recordFieldChange(this, "Email Address", getEmailAddress(), emailAddress);
setEmailAddress(emailAddress);
}
public void clearEmailAddress() {
getRecordActionService().recordFieldChange(this, "Email Address", getEmailAddress(), "EMPTY");
setEmailAddress(null);
}
public boolean hideEmailAddress() {
return !employeeIsCurrentUser();
}
private Object currentUser;
private boolean employeeIsCurrentUser() {
if (currentUser == null) {
currentUser = getUserFinder().currentUserAsObject();
}
return currentUser == this;
}
// }}
// {{ Currency
private Currency currency;
@MemberOrder(sequence = "3")
@Disabled
public Currency getCurrency() {
resolve(currency);
return this.currency;
}
public void setCurrency(final Currency currency) {
this.currency = currency;
objectChanged();
}
// }}
// {{ NormalApprover
private Employee normalApprover;
@MemberOrder(sequence = "4")
@Optional
public Employee getNormalApprover() {
resolve(normalApprover);
return this.normalApprover;
}
public void setNormalApprover(final Employee normalAuthoriser) {
this.normalApprover = normalAuthoriser;
objectChanged();
}
public void modifyNormalApprover(final Employee normalAuthoriser) {
getRecordActionService().recordFieldChange(this, "Normal Approver", getNormalApprover(), normalApprover);
setNormalApprover(normalAuthoriser);
}
public void clearNormalApprover() {
getRecordActionService().recordFieldChange(this, "Normal Approver", getNormalApprover(), "EMPTY");
setNormalApprover(null);
}
public String validateNormalApprover(Employee newApprover) {
return newApprover == this ? CANT_BE_APPROVER_FOR_OWN_CLAIMS : null;
}
public String disableNormalApprover() {
return employeeIsCurrentUser() ? null : NOT_MODIFIABLE;
}
public static final String NOT_MODIFIABLE = "Not modifiable by current user";
public static final String CANT_BE_APPROVER_FOR_OWN_CLAIMS = "Can't be the approver for your own claims";
// }}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy