/*
 * Copyright 2012-2013 inBloom, Inc. and its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.slc.sli.bulk.extract.context.resolver.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Context resolver for cohorts, be base on ed org association
 * 
 * @author nbrown
 *
 */
@Component
public class CohortContextResolver extends RelatedContextResolver {
    @Autowired
    private EducationOrganizationContextResolver edOrgResolver;
    
    @Override
    protected String getReferenceProperty(String entityType) {
        return "educationOrgId";
    }
    
    @Override
    protected ReferrableResolver getReferredResolver() {
        return edOrgResolver;
    }
    
}

@@ -668,16 +668,299 @@
 .impl;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport javax.annotation.PostConstruct;%0A%0Aimport org.slc.sli.common.constants.EntityNames;%0Aimport org.slc.sli.domain.Entity;%0Aimport org.slc.sli.domain.utils.EdOrgHierarchyHelper;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1220,13 +1220,166 @@
 s Re
-lated
+ferrableResolver %7B%0A%09%0A    public final static String EDORG_REFERENCE = %22educationOrgId%22;%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(Section
 Cont
@@ -1389,18 +1389,25 @@
 Resolver
- %7B
+.class);%0A
 %0A    @Au
@@ -1491,230 +1491,768 @@
     
-@Override%0A    protected String getReferenceProperty(String entityType) %7B%0A        return %22educationOrgId%22;%0A    %7D%0A    %0A    @Override%0A    protected ReferrableResolver getReferredResolver() %7B%0A        return edOrgResolver;%0A    
+private EdOrgHierarchyHelper edOrgHelper;%0A%0A    @PostConstruct%0A    public void init() %7B%0A    %09edOrgHelper = new EdOrgHierarchyHelper(getRepo());%0A    %7D%0A%0A%09@Override%0A%09protected String getCollection() %7B%0A        return EntityNames.COHORT;%0A%09%7D%0A%0A%09@Override%0A%09protected Set%3CString%3E resolve(Entity entity) %7B%0A%09%09Set%3CString%3E leas = new HashSet%3CString%3E();%0A%0A%09%09String id = entity.getEntityId();%0A%09%09if (id == null) %7B%0A%09%09%09return leas;%0A%09%09%7D%0A%0A%09%09String edorgReference = (String) entity.getBody().get(EDORG_REFERENCE);%0A%0A%09%09Entity edOrg = getRepo().findById(EntityNames.EDUCATION_ORGANIZATION,%0A%09%09%09%09edorgReference);%0A%0A%09%09if (edOrgHelper.isSEA(edOrg)) %7B%0A%09%09%09return leas;%0A%09%09%7D%0A%09%09if (edorgReference != null) %7B%0A%09%09%09leas.addAll(edOrgResolver.findGoverningEdOrgs(edorgReference));%0A%09%09%7D%0A%0A%09%09return leas;%0A%09
 %7D%0A  

change CohortContextResolver so it will not appear in the SEA extract