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

org.nakedobjects.example.expenses.employee.Employees Maven / Gradle / Ivy

package org.nakedobjects.example.expenses.employee;

import java.util.List;

import org.nakedobjects.applib.AbstractService;
import org.nakedobjects.applib.annotation.Executed;
import org.nakedobjects.applib.annotation.MemberOrder;
import org.nakedobjects.applib.annotation.Named;
import org.nakedobjects.example.expenses.claims.Claim;


/**
 * Employees acts as a facade onto the EmployeeRepository.  It wraps the methods that are intended to be
 * invoked directly by a user, adding:
 * -  mark-up (e.g. naming the parameters)
 * -  helper logic e.g. default.. or choices.. methods
 * - user-friendly wrapping for error conditions.
 */
public class Employees extends AbstractService {

    private static final int MAX_NUM_EMPLOYEES = 10;

    // {{ Title & ID
    public String getId() {
    	return getClass().getSimpleName();
    }

    // }}
    public String iconName() {
        return Employee.class.getSimpleName();
    }

    // {{ 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: EmployeeRepository
    private EmployeeRepository employeeRepository;

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

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

    // }}

    // }}

    @MemberOrder(sequence = "2")
    public List findEmployeeByName(@Named("Name or start of Name")
    final String name) {
        List results = employeeRepository.findEmployeeByName(name);
        if (results.isEmpty()) {
            warnUser("No employees found matching name: " + name);
            return null;
        } else if (results.size() > MAX_NUM_EMPLOYEES) {
            warnUser("Too many employees found matching name: " + name + "\n Please refine search.");
            return null;
        }
        return results;
    }

    @Executed(Executed.Where.LOCALLY)
    public Employee me() {
        Employee me = employeeRepository.me();
        if (me == null) {
            warnUser("No Employee representing current user");
        }
        return me;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy