All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.example.expenses.fixtures.EmployeeFixture Maven / Gradle / Ivy

The newest version!
package org.nakedobjects.example.expenses.fixtures;

import org.nakedobjects.applib.DomainObjectContainer;
import org.nakedobjects.applib.annotation.Hidden;
import org.nakedobjects.applib.fixtures.AbstractFixture;
import org.nakedobjects.example.expenses.claims.ClaimRepository;
import org.nakedobjects.example.expenses.currency.Currency;
import org.nakedobjects.example.expenses.employee.Employee;
import org.nakedobjects.example.expenses.employee.EmployeeRepository;


public class EmployeeFixture extends AbstractFixture {

    // {{ Injected Services
    /*
     * This region contains references to the services (Repositories, Factories or other Services) used by
     * this domain object. The references are injected by the application container.
     */

    // {{ Injected: ClaimantRepository
    private EmployeeRepository employeeRepository;

    /**
     * This field is not persisted, nor displayed to the user.
     */
    protected EmployeeRepository getClaimantRepository() {
        return this.employeeRepository;
    }

    /**
     * Injected by the application container.
     */
    public void setClaimantRepository(EmployeeRepository employeeRepository) {
        this.employeeRepository = employeeRepository;
    }

    // }}
    
    // {{ Injected: ClaimRepository
    private ClaimRepository claimRepository;

    /**
     * This field is not persisted, nor displayed to the user.
     */
    protected ClaimRepository getClaimRepository() {
        return this.claimRepository;
    }

    /**
     * Injected by the application container.
     */
    public void setClaimRepository(ClaimRepository claimRepository) {
        this.claimRepository = claimRepository;
    }
    
    // }}
    

    // {{ Injected: Container
    private DomainObjectContainer container;
 
    /**
     * This field is not persisted, nor displayed to the user.
     */
    protected DomainObjectContainer getContainer() {
        return this.container;
    }

    /**
     * Injected by the application container itself.
     */
    public final void setContainer(final DomainObjectContainer container) {

        this.container = container;
    }

    // }}

    // }}

    public static Employee SVEN;
    public static Employee DICK;
    public static Employee BOB;
    public static Employee JOE;

    public void install() {

        createEmployees();
    }

	private void createEmployees() {
		SVEN = createEmployee("Sven Bloggs", "sven", "[email protected]", CurrencyFixture.GBP);
        DICK = createEmployee("Dick Barton", "dick", "[email protected]", CurrencyFixture.GBP);
        BOB = createEmployee("Robert Bruce", "bob", "[email protected]", CurrencyFixture.USD);
        JOE = createEmployee("Joe Sixpack", "joe", "[email protected]", CurrencyFixture.USD);
        createEmployee("Intrepid Explorer", "exploration", "[email protected]", CurrencyFixture.USD);
        
        SVEN.setNormalApprover(DICK);
        DICK.setNormalApprover(BOB);
	}


    @Hidden
    public Employee createEmployee(final String myName, final String userName, final String emailAddress, final Currency currency) {
        final Employee employee = (Employee) container.newTransientInstance(Employee.class);
        assert(myName != null && myName != "");
        assert(userName != null && userName != "");
        assert(emailAddress != null && emailAddress != "");
        assert(currency != null);
        
        employee.setName(myName);
        employee.setUserName(userName);
        employee.setEmailAddress(emailAddress);
        employee.setCurrency(currency);
        container.makePersistent(employee);
        return employee;
    }

 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy