/********************************************************************
 * Copyright © 2006 VHA. All rights reserved
 ********************************************************************/
package gov.va.med.esr.ui.common.dao;

// Java Classes
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

// ESR Classes
import gov.va.med.esr.service.UnknownLookupTypeException;
import gov.va.med.esr.ui.common.beans.VISNSite;
import gov.va.med.esr.common.model.lookup.VAFacility;
import gov.va.med.esr.common.model.lookup.VISN;

/**
 * UI lookup DAO for VISN facilities.
 *
 * @author Muddaiah Ranga
 * @version 3.0
 */
public class VISNSiteDAO extends VAFacilityAbstractLookupDAO
{
    /**
     * Gets the list VISNs and facilities.
     *
     * @return The list of objects.
     * @throws gov.va.med.esr.service.UnknownLookupTypeException
     * @throws ClassNotFoundException
     */
    public List findAll() throws UnknownLookupTypeException, ClassNotFoundException {
 
        List filteredLocations = new ArrayList();

        Map facilityByVisn = this.getLookupService().getVISNSiteMap();
        if(facilityByVisn != null) {
            for(Iterator iter = facilityByVisn.keySet().iterator(); iter.hasNext();) {
                VISN visn = (VISN)iter.next();
                List visnSites = (visn != null) ? (List)facilityByVisn.get(visn) : null;
                if(visnSites != null) {
                    filteredLocations.add(visn);
                    for(Iterator facIter=visnSites.iterator(); facIter.hasNext();) {
                        VAFacility facility = (VAFacility)facIter.next();
                        if(facility != null) {
                            filteredLocations.add(new VISNSite(facility));
                        }
                    } 
                }
            }
        }
        return filteredLocations;
    }
}
