RegisterCustomerController.java

// license-header java merge-point
// Generated by andromda-jsf cartridge (controllers\Controller.java.vsl) DO NOT EDIT!
package org.andromda.samples.carrental.customers.web.registerCustomer;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Map;
import org.andromda.samples.carrental.ControllerBase;
import org.andromda.samples.carrental.JsfUtils;
import org.andromda.samples.carrental.ServiceLocator;
import org.andromda.samples.carrental.admins.web.main.AdministrationController;
import org.andromda.samples.carrental.customers.CustomerService;

/**
 * <p>
 * This controller allows to register a new customer. It calls the CustomerService in the server
 * side.
 * </p>
 * <p>
 * @author Carlos Cuenca
 * </p>
 */
public abstract class RegisterCustomerController
    extends ControllerBase
    implements Serializable
{
    /**
     * The serial version UID of this class. Needed for serialization.
     */
    private static final long serialVersionUID = 1L;

    /**
     * Returns an instance from the JSF context
     *
     */
    public static RegisterCustomerController instance()
    {
        return (RegisterCustomerController)JsfUtils.resolveVariable("registerCustomerController");
    }
    
    /**
     * Populate action form and page variables
     *
     * @param currentView the current view
     * @param forward the forward view
     * @param sourceForm the source form
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     * @throws NoSuchMethodException
     */
    private void populateActionFormsAndPageVariables(final String currentView, String forward, final Object sourceForm) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
    {
        if(forward == null)
        {
            forward=currentView;
        }
        
        final Map<String,Object> pageVariables=this.getPageVariables(forward);
        if("/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf".equals(forward))
        {
            RegisterANewCustomerViewPopulator.populateForm(sourceForm,this.getCreateNewCustomerNewCustomerForm());
            RegisterANewCustomerViewPopulator.populateForm(sourceForm,this.getCreateNewCustomerSelectForm());
            RegisterANewCustomerViewPopulator.populateCreateNewCustomerPageVariables(sourceForm,pageVariables);
        }
        else
        if("/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf".equals(forward))
        {
            RegisterANewCustomerViewPopulator.populateForm(sourceForm,this.getCreateLicensedDriverSaveDriverForm());
            RegisterANewCustomerViewPopulator.populateCreateLicensedDriverPageVariables(sourceForm,pageVariables);
        }
        ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
    }
    
    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.customers.web.registerCustomer.createCustomer
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract String createCustomer(CreateCustomerForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.customers.web.registerCustomer.searchAllCustomers
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract Collection searchAllCustomers(SearchAllCustomersForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.customers.web.registerCustomer.loadExistingCustomers
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void loadExistingCustomers(LoadExistingCustomersForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.customers.web.registerCustomer.loadExistingDrivers
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void loadExistingDrivers(LoadExistingDriversForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.customers.web.registerCustomer.saveDriver
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void saveDriver(SaveDriverForm form)
        throws Throwable;


    /**
     * Retrieves the {@link CreateNewCustomerNewCustomerFormImpl} form instance 
     *
     * @return CreateNewCustomerNewCustomerFormImpl
     */
    protected CreateNewCustomerNewCustomerFormImpl getCreateNewCustomerNewCustomerForm()
    {
        return (CreateNewCustomerNewCustomerFormImpl)JsfUtils.resolveVariable("registerANewCustomerCreateNewCustomerNewCustomerForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for new Customer
     * </p>
     * This method is called when 'new Customer' is triggered in the view 'Create new Customer'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _createNewCustomer_newCustomer(CreateNewCustomerNewCustomerFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves createNewCustomerNewCustomer()
     *    
     * @return createNewCustomerNewCustomer
     * @throws Throwable
     */
    public String createNewCustomerNewCustomer()
        throws Throwable
    {
        this.setLastPostedFormClientId("registerANewCustomerCreateNewCustomerNewCustomerForm");
        
        String forward=null;
        final CreateNewCustomerNewCustomerFormImpl form =
            this.getCreateNewCustomerNewCustomerForm();
            
        //trigger method execution
        _createNewCustomer_newCustomer(form);

        forward = _saveCustomerInfo(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for save customer info
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _saveCustomerInfo(final CreateNewCustomerNewCustomerFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        createCustomer(form);
        forward = _loadExistingDrivers(form);
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for load existing Drivers
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _loadExistingDrivers(final CreateNewCustomerNewCustomerFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        loadExistingDrivers(form);
        forward = "/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf";
        return forward;
    }

    /**
     * Retrieves the {@link CreateNewCustomerSelectFormImpl} form instance 
     *
     * @return CreateNewCustomerSelectFormImpl
     */
    protected CreateNewCustomerSelectFormImpl getCreateNewCustomerSelectForm()
    {
        return (CreateNewCustomerSelectFormImpl)JsfUtils.resolveVariable("registerANewCustomerCreateNewCustomerSelectForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for select
     * </p>
     * This method is called when 'select' is triggered in the view 'Create new Customer'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _createNewCustomer_select(CreateNewCustomerSelectFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves createNewCustomerSelect()
     *    
     * @return createNewCustomerSelect
     * @throws Throwable
     */
    public String createNewCustomerSelect()
        throws Throwable
    {
        this.setLastPostedFormClientId("registerANewCustomerCreateNewCustomerSelectForm");
        
        String forward=null;
        final CreateNewCustomerSelectFormImpl form =
            this.getCreateNewCustomerSelectForm();
            
        //trigger method execution
        _createNewCustomer_select(form);

        forward = _loadExistingDrivers(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for load existing Drivers
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _loadExistingDrivers(final CreateNewCustomerSelectFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        loadExistingDrivers(form);
        forward = "/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf";
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for finish
     * </p>
     * This method is called when 'finish' is triggered in the view 'Create Licensed Driver'.
     * It can be safely overridden in descendant classes.
     */
    protected void _createLicensedDriver_finish()
    {
        //this method can be overridden
    }

    /**
     * Retrieves createLicensedDriverFinish()
     *    
     * @return createLicensedDriverFinish
     * @throws Throwable
     */
    public String createLicensedDriverFinish()
        throws Throwable
    {
        this.setLastPostedFormClientId("registerANewCustomerCreateLicensedDriverFinishForm");
        
        String forward=null;
        forward=((AdministrationController)JsfUtils.resolveVariable("administrationController")).startUseCase();
        
        return forward;
    }

    /**
     * Retrieves the {@link CreateLicensedDriverSaveDriverFormImpl} form instance 
     *
     * @return CreateLicensedDriverSaveDriverFormImpl
     */
    protected CreateLicensedDriverSaveDriverFormImpl getCreateLicensedDriverSaveDriverForm()
    {
        return (CreateLicensedDriverSaveDriverFormImpl)JsfUtils.resolveVariable("registerANewCustomerCreateLicensedDriverSaveDriverForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for save Driver
     * </p>
     * This method is called when 'save Driver' is triggered in the view 'Create Licensed Driver'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _createLicensedDriver_saveDriver(CreateLicensedDriverSaveDriverFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves createLicensedDriverSaveDriver()
     *    
     * @return createLicensedDriverSaveDriver
     * @throws Throwable
     */
    public String createLicensedDriverSaveDriver()
        throws Throwable
    {
        this.setLastPostedFormClientId("registerANewCustomerCreateLicensedDriverSaveDriverForm");
        
        String forward=null;
        final CreateLicensedDriverSaveDriverFormImpl form =
            this.getCreateLicensedDriverSaveDriverForm();
            
        //trigger method execution
        _createLicensedDriver_saveDriver(form);

        forward = _savedriver(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for savedriver
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _savedriver(final CreateLicensedDriverSaveDriverFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        saveDriver(form);
        forward = _loadExistingDrivers(form);
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for load existing Drivers
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _loadExistingDrivers(final CreateLicensedDriverSaveDriverFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        loadExistingDrivers(form);
        forward = "/org/andromda/samples/carrental/customers/web/registerCustomer/create-licensed-driver.jsf";
        return forward;
    }

    /**
     * Retrieves the {@link RegisterANewCustomerFormImpl} form instance 
     *
     * @return RegisterANewCustomerFormImpl
     */
    protected RegisterANewCustomerFormImpl getRegisterANewCustomerForm()
    {
        return (RegisterANewCustomerFormImpl)JsfUtils.resolveVariable("registerANewCustomerRegisterANewCustomerForm");
    }

    /**
     * This method is called when the use case 'Register a new Customer' starts.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _registerANewCustomer_started(RegisterANewCustomerFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves the internal start use case
     *    
     * @return registerANewCustomer
     * @throws Throwable
     */
    protected String internalStartUseCase(Map<String,Object> useCaseParameters)
        throws Throwable
    {
        this.setLastPostedFormClientId("registerANewCustomerRegisterANewCustomerForm");
        
        String forward=null;
        final RegisterANewCustomerFormImpl form =
            this.getRegisterANewCustomerForm();
            
        //copy parameters form caller use case
        form.copyFrom(useCaseParameters);
        
        //trigger method execution
        _registerANewCustomer_started(form);

        forward = _loadExistingCustomers(form);
        populateActionFormsAndPageVariables(null,forward,form);
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for load existing customers
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _loadExistingCustomers(final RegisterANewCustomerFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        searchAllCustomers(form);
        forward = "/org/andromda/samples/carrental/customers/web/registerCustomer/create-new-customer.jsf";
        return forward;
    }

    /**
     * Returns a reference to the CustomerService back-end service.
     *
     * @return ServiceLocator.instance().getCustomerService()
     */
    protected final CustomerService getCustomerService()
    {
        try
        {
            return ServiceLocator.instance().getCustomerService();
        }
        catch (final Throwable throwable)
        {
            throw new RuntimeException(throwable);
        }
    }


}