@@ -0,0 +1,3032 @@
+/*%0A * Copyright 2012 Shared Learning Collaborative, LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A%0Apackage org.slc.sli.api.security.context.resolver;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0A%0Aimport org.slc.sli.api.constants.EntityNames;%0Aimport org.slc.sli.api.security.context.AssociativeContextHelper;%0Aimport org.slc.sli.api.security.context.traversal.cache.impl.SessionSecurityCache;%0Aimport org.slc.sli.domain.Entity;%0Aimport org.slc.sli.domain.NeutralCriteria;%0Aimport org.slc.sli.domain.NeutralQuery;%0Aimport org.slc.sli.domain.Repository;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.beans.factory.annotation.Qualifier;%0Aimport org.springframework.stereotype.Component;%0A%0A/**%0A * Resolves Teachers context to Students. Finds accessible students through section, program, and cohort associations.%0A */%0A@Component%0Apublic class TeacherToStudentCompetencyResolver implements EntityContextResolver %7B%0A%0A    @Autowired%0A    private AssociativeContextHelper helper;%0A    @Autowired%0A    private SessionSecurityCache securityCachingStrategy;%0A    %0A    @Autowired%0A    private TeacherStudentResolver studentResolver;%0A    %0A    %0A    @Autowired%0A    @Qualifier(%22validationRepo%22)%0A    private Repository%3CEntity%3E repo;%0A%0A    @Override%0A    public boolean canResolve(String fromEntityType, String toEntityType) %7B%0A//        return false;%0A        return EntityNames.TEACHER.equals(fromEntityType) && EntityNames.STUDENT_COMPETENCY.equals(toEntityType);%0A    %7D%0A%0A    @Override%0A    public List%3CString%3E findAccessible(Entity principal) %7B%0A        List%3CString%3E studentIds = new ArrayList%3CString%3E();%0A        if (!securityCachingStrategy.contains(EntityNames.STUDENT)) %7B%0A            studentIds = studentResolver.findAccessible(principal);%0A        %7D else %7B%0A            studentIds = new ArrayList%3CString%3E(securityCachingStrategy.retrieve(EntityNames.STUDENT));%0A        %7D%0A        Iterable%3CString%3E assocIds = repo.findAllIds(EntityNames.STUDENT_SECTION_ASSOCIATION, new NeutralQuery(new NeutralCriteria(%0A                %22studentId%22, NeutralCriteria.CRITERIA_IN, studentIds)));%0A        List%3CString%3E ids = new ArrayList%3CString%3E();%0A        for (String id : assocIds) %7B%0A            ids.add(id);%0A        %7D%0A        List%3CString%3E finalIds = helper.findEntitiesContainingReference(EntityNames.STUDENT_COMPETENCY, %22studentSectionAssociationId%22, ids);%0A        securityCachingStrategy.warm(EntityNames.STUDENT_COMPETENCY, new HashSet%3CString%3E(finalIds));%0A        return finalIds;%0A    %7D%0A%7D%0A

Add an ugly competency resolver