1 package org.kuali.student.enrollment.class2.courseoffering.service.assembler; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.RegistrationGroupTransformer; 7 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo; 8 import org.kuali.student.enrollment.lui.dto.LuiInfo; 9 import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo; 10 import org.kuali.student.enrollment.lui.service.LuiService; 11 import org.kuali.student.r2.common.assembler.AssemblyException; 12 import org.kuali.student.r2.common.assembler.DTOAssembler; 13 import org.kuali.student.r2.common.dto.ContextInfo; 14 import org.kuali.student.r2.common.exceptions.DoesNotExistException; 15 import org.kuali.student.r2.common.exceptions.InvalidParameterException; 16 import org.kuali.student.r2.common.exceptions.MissingParameterException; 17 import org.kuali.student.r2.common.exceptions.OperationFailedException; 18 import org.kuali.student.r2.common.exceptions.PermissionDeniedException; 19 import org.kuali.student.r2.common.util.constants.LuiServiceConstants; 20 21 public class RegistrationGroupAssembler { 22 23 private LuiService luiService; 24 private RegistrationGroupTransformer registrationGroupTransformer; 25 26 public RegistrationGroupTransformer getRegistrationGroupTransformer() { 27 return registrationGroupTransformer; 28 } 29 30 public void setRegistrationGroupTransformer(RegistrationGroupTransformer registrationGroupTransformer) { 31 this.registrationGroupTransformer = registrationGroupTransformer; 32 } 33 34 public LuiService getLuiService() { 35 return luiService; 36 } 37 38 public void setLuiService(LuiService luiService) { 39 this.luiService = luiService; 40 } 41 42 public RegistrationGroupInfo assemble(LuiInfo lui, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { 43 if (lui != null) { 44 RegistrationGroupInfo rg = registrationGroupTransformer.lui2Rg(lui, context); 45 assembleLuiLuiRelations(rg, lui.getId(), context); 46 return rg; 47 } else { 48 return null; 49 } 50 } 51 52 private void assembleLuiLuiRelations(RegistrationGroupInfo rg, String luiId, ContextInfo context) 53 throws DoesNotExistException, InvalidParameterException, MissingParameterException, 54 OperationFailedException, PermissionDeniedException { 55 String courseOfferingId = null; 56 ; 57 List<String> activityIds = new ArrayList<String>(); 58 List<LuiLuiRelationInfo> rels = luiService.getLuiLuiRelationsByLui(luiId, context); 59 if (rels != null && !rels.isEmpty()) { 60 for (LuiLuiRelationInfo rel : rels) { 61 if (rel.getLuiId().equals(luiId)) { 62 if (rel.getTypeKey().equals(LuiServiceConstants.LUI_LUI_RELATION_REGISTEREDFORVIA_TYPE_KEY)) { 63 LuiInfo lui = luiService.getLui(rel.getRelatedLuiId(), context); 64 if (lui != null) { 65 if (lui.getTypeKey().equals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY)) { 66 courseOfferingId = rel.getRelatedLuiId(); 67 } else { 68 if (!activityIds.contains(rel.getRelatedLuiId())) { 69 activityIds.add(rel.getRelatedLuiId()); 70 } 71 } 72 } 73 } 74 } 75 } 76 } 77 78 if (null != courseOfferingId) 79 rg.setCourseOfferingId(courseOfferingId); 80 if (!activityIds.isEmpty()) 81 rg.setActivityOfferingIds(activityIds); 82 83 } 84 85 public LuiInfo disassemble(RegistrationGroupInfo rg, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, OperationFailedException, PermissionDeniedException { 86 LuiInfo lui = registrationGroupTransformer.rg2Lui(rg, context); 87 return lui; 88 } 89 }