package oracle.fodemo.storefront.store.queries;


import oracle.fodemo.storefront.store.queries.common.PersonsVO;

import oracle.jbo.Row;
import oracle.jbo.RowIterator;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
import oracle.jbo.server.ViewObjectImpl;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class PersonsVOImpl extends ViewObjectImpl implements PersonsVO {
    /**This is the default constructor (do not remove).
     */
    public PersonsVOImpl() {
    }


    /**Gets the variable value for userPrincipal.
     * @return
     */
    public String getuserPrincipal() {
        return (String)ensureVariableManager().getVariableValue("userPrincipal");
    }

    /**Sets <code>value</code> for variable userPrincipal.
     * @param value
     */
    public void setuserPrincipal(String value) {
        ensureVariableManager().setVariableValue("userPrincipal", value);
    }
    
    public String findPerson(String principalName){
        ViewCriteria personVC = createViewCriteria();
        ViewCriteriaRow personVCR = personVC.createViewCriteriaRow();
        personVCR.setAttribute("PrincipalName", "=" + principalName.toUpperCase());
        personVC.addElement(personVCR);
        RowIterator personItr = findByViewCriteria(personVC, -1, ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES); 
        // hack for Bug 9160013 - d8b2d-blk:jbo-26000: a generic exception occurred during loading customizations
        if (personItr == null || personItr.first() == null) 
        {
          System.out.println("Could not find the person with principal name: " + principalName);  
          return null;
        }
        return personItr.first().getAttribute("PersonTypeCode").toString();
    }

}
