RegisterAccidentController.java

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

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
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.contracts.ContractService;
import org.andromda.samples.carrental.contracts.web.returnCar.ReturnCarController;

/**
 * <p>
 * This controller registers an accident from a customer that had rented a car. It calls the
 * Contract Service on the server side
 * </p>
 * <p>
 * @author Carlos Cuenca
 * </p>
 */
public abstract class RegisterAccidentController
    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 RegisterAccidentController instance()
    {
        return (RegisterAccidentController)JsfUtils.resolveVariable("registerAccidentController");
    }
    
    /**
     * 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/contracts/web/registerAccident/select-contract.jsf".equals(forward))
        {
            RegisteringAndAccidentViewPopulator.populateForm(sourceForm,this.getSelectContractRegisterForm());
            RegisteringAndAccidentViewPopulator.populateSelectContractPageVariables(sourceForm,pageVariables);
        }
        ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
    }
    
    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.contracts.web.registerAccident.searchForContractsOfCustomer
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void searchForContractsOfCustomer(SearchForContractsOfCustomerForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.contracts.web.registerAccident.registerAccident
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract String registerAccident(RegisterAccidentForm form)
        throws Throwable;


    /**
     * Retrieves the {@link SelectContractRegisterFormImpl} form instance 
     *
     * @return SelectContractRegisterFormImpl
     */
    protected SelectContractRegisterFormImpl getSelectContractRegisterForm()
    {
        return (SelectContractRegisterFormImpl)JsfUtils.resolveVariable("registeringAndAccidentSelectContractRegisterForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for register
     * </p>
     * This method is called when 'register' is triggered in the view 'Select Contract'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _selectContract_register(SelectContractRegisterFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves selectContractRegister()
     *    
     * @return selectContractRegister
     * @throws Throwable
     */
    public String selectContractRegister()
        throws Throwable
    {
        this.setLastPostedFormClientId("registeringAndAccidentSelectContractRegisterForm");
        
        String forward=null;
        final SelectContractRegisterFormImpl form =
            this.getSelectContractRegisterForm();
            
        //trigger method execution
        _selectContract_register(form);

        forward = _registeringAccident(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/contracts/web/registerAccident/select-contract.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/contracts/web/registerAccident/select-contract.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for registering Accident
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _registeringAccident(final SelectContractRegisterFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        registerAccident(form);
        forward = ((ReturnCarController)JsfUtils.resolveVariable("returnCarController")).startUseCase();
        return forward;
    }

    /**
     * Retrieves the {@link RegisteringAndAccidentFormImpl} form instance 
     *
     * @return RegisteringAndAccidentFormImpl
     */
    protected RegisteringAndAccidentFormImpl getRegisteringAndAccidentForm()
    {
        return (RegisteringAndAccidentFormImpl)JsfUtils.resolveVariable("registeringAndAccidentRegisteringAndAccidentForm");
    }

    /**
     * This method is called when the use case 'Registering and Accident' starts.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _registeringAndAccident_started(RegisteringAndAccidentFormImpl form)
    {
        //this method can be overridden
    }

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

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

    /**
     * <p>
     * TODO: Model Documentation for search for contract
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _searchForContract(final RegisteringAndAccidentFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        searchForContractsOfCustomer(form);
        forward = "/org/andromda/samples/carrental/contracts/web/registerAccident/select-contract.jsf";
        return forward;
    }

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


}