1 package org.kuali.student.ap.bookmark.service.impl; 2 3 import org.kuali.rice.krad.lookup.LookupForm; 4 import org.kuali.rice.krad.lookup.LookupableImpl; 5 import org.kuali.student.ap.academicplan.constants.AcademicPlanServiceConstants; 6 import org.kuali.student.ap.academicplan.dto.LearningPlanInfo; 7 import org.kuali.student.ap.academicplan.dto.PlanItemInfo; 8 import org.kuali.student.ap.academicplan.infc.PlanItem; 9 import org.kuali.student.ap.academicplan.service.AcademicPlanService; 10 import org.kuali.student.ap.bookmark.dto.BookmarkDetailWrapper; 11 import org.kuali.student.ap.coursesearch.dataobject.CourseDetailsWrapper; 12 import org.kuali.student.ap.coursesearch.service.impl.CourseDetailsInquiryHelperImpl2; 13 import org.kuali.student.ap.framework.config.KsapFrameworkServiceLocator; 14 import org.kuali.student.ap.framework.context.PlanConstants; 15 import org.kuali.student.ap.planner.service.PlanEventViewHelperService; 16 import org.kuali.student.ap.planner.util.PlanEventUtils; 17 import org.kuali.student.r2.common.exceptions.DoesNotExistException; 18 import org.kuali.student.r2.common.exceptions.InvalidParameterException; 19 import org.kuali.student.r2.common.exceptions.MissingParameterException; 20 import org.kuali.student.r2.common.exceptions.OperationFailedException; 21 import org.kuali.student.r2.common.exceptions.PermissionDeniedException; 22 import org.kuali.student.r2.lum.course.infc.Course; 23 24 import javax.json.JsonObjectBuilder; 25 import javax.servlet.ServletException; 26 import javax.servlet.http.HttpServletResponse; 27 import java.io.IOException; 28 import java.util.ArrayList; 29 import java.util.Collections; 30 import java.util.List; 31 import java.util.Map; 32 import java.util.Set; 33 import java.util.UUID; 34 35 public class BookmarkDetailLookupableHelper extends 36 LookupableImpl implements PlanEventViewHelperService{ 37 private static final long serialVersionUID = -8872944782230428634L; 38 CourseDetailsInquiryHelperImpl2 courseDetailsInquiryHelper; 39 40 @Override 41 public List<BookmarkDetailWrapper> performSearch( 42 LookupForm lookupForm, Map<String, String> searchCriteria, 43 boolean bounded) { 44 String studentId = KsapFrameworkServiceLocator.getUserSessionHelper() 45 .getStudentId(); 46 try { 47 List<BookmarkDetailWrapper> plannedCoursesList = getPlanItemsWishList(studentId); 48 Collections.sort(plannedCoursesList); 49 return plannedCoursesList; 50 } catch (Exception e) { 51 throw new RuntimeException(e); 52 } 53 } 54 protected List<BookmarkDetailWrapper> getPlanItemsWishList(String studentId) 55 throws InvalidParameterException, MissingParameterException, DoesNotExistException, 56 OperationFailedException, PermissionDeniedException { 57 List<BookmarkDetailWrapper> bookmarkList = new ArrayList<BookmarkDetailWrapper>(); 58 59 AcademicPlanService academicPlanService = KsapFrameworkServiceLocator.getAcademicPlanService(); 60 String planTypeKey = PlanConstants.LEARNING_PLAN_TYPE_PLAN; 61 62 List<LearningPlanInfo> learningPlanList = academicPlanService.getLearningPlansForStudentByType(studentId, 63 planTypeKey, KsapFrameworkServiceLocator.getContext().getContextInfo()); 64 Map<String, List<PlanItemInfo>> itemsByPlan = new java.util.HashMap<String, List<PlanItemInfo>>( 65 learningPlanList.size()); 66 Set<String> courseIds = new java.util.LinkedHashSet<String>(); 67 for (LearningPlanInfo learningPlan : learningPlanList) { 68 String learningPlanID = learningPlan.getId(); 69 List<PlanItemInfo> planItems = academicPlanService.getPlanItemsInPlanByCategory(learningPlanID,AcademicPlanServiceConstants.ItemCategory.WISHLIST, 70 KsapFrameworkServiceLocator.getContext().getContextInfo()); 71 itemsByPlan.put(learningPlanID, planItems); 72 if (planItems != null) 73 for (PlanItemInfo planItem : planItems) 74 if (PlanConstants.COURSE_TYPE.equals(planItem.getRefObjectType())) 75 courseIds.add(KsapFrameworkServiceLocator.getCourseHelper().getCurrentVersionOfCourseByVersionIndependentId(planItem 76 .getRefObjectId()).getId()); 77 } 78 KsapFrameworkServiceLocator.getCourseHelper().frontLoad(new ArrayList<String>(courseIds)); 79 80 for (Map.Entry<String, List<PlanItemInfo>> entry : itemsByPlan.entrySet()){ 81 for (PlanItemInfo planItem : entry.getValue()) { 82 BookmarkDetailWrapper bookmark = new BookmarkDetailWrapper(); 83 bookmark.setLearningPlanId(entry.getKey()); 84 bookmark.setPlanItemId(planItem.getId()); 85 bookmark.setDateAdded(planItem.getMeta().getCreateTime()); 86 bookmark.setUniqueId(UUID.randomUUID().toString()); 87 88 Course course = KsapFrameworkServiceLocator.getCourseHelper().getCurrentVersionOfCourseByVersionIndependentId 89 (planItem.getRefObjectId()); 90 CourseDetailsWrapper courseDetails = getCourseDetailsInquiryService().retrieveCourseSummary(course); 91 bookmark.setCourseDetailsWrapper(courseDetails); 92 bookmarkList.add(bookmark); 93 94 } 95 } 96 Collections.sort(bookmarkList); 97 return bookmarkList; 98 } 99 100 public synchronized CourseDetailsInquiryHelperImpl2 getCourseDetailsInquiryService() { 101 if (this.courseDetailsInquiryHelper == null) { 102 this.courseDetailsInquiryHelper = new CourseDetailsInquiryHelperImpl2(); 103 } 104 return courseDetailsInquiryHelper; 105 } 106 107 public JsonObjectBuilder makeAddEvent(PlanItem planItem, JsonObjectBuilder eventList) { 108 return PlanEventUtils.makeAddEvent(planItem, eventList); 109 } 110 111 public JsonObjectBuilder makeRemoveEvent(String uniqueId, PlanItem planItem, JsonObjectBuilder eventList) { 112 return PlanEventUtils.makeRemoveEvent(uniqueId, planItem, eventList); 113 } 114 115 public JsonObjectBuilder updatePlanItemEvent(String uniqueId, PlanItem planItem, JsonObjectBuilder eventList) { 116 return PlanEventUtils.updatePlanItemEvent(uniqueId, planItem, eventList); 117 } 118 119 public JsonObjectBuilder updateTotalCreditsEvent(boolean newTerm, String termId, JsonObjectBuilder eventList) { 120 return PlanEventUtils.updateTotalCreditsEvent(newTerm,termId,eventList); 121 } 122 123 public JsonObjectBuilder updateTermNoteEvent(String uniqueId, String termId, String termNote, JsonObjectBuilder eventList) { 124 return PlanEventUtils.updateTermNoteEvent(uniqueId, termId, termNote, eventList); 125 } 126 127 public void sendJsonEvents(boolean success, String message, HttpServletResponse response, 128 JsonObjectBuilder eventList) throws IOException, ServletException { 129 PlanEventUtils.sendJsonEvents(success,message,response,eventList); 130 } 131 132 public JsonObjectBuilder makeAddBookmarkEvent(PlanItem planItem, JsonObjectBuilder eventList) { 133 return PlanEventUtils.makeAddBookmarkEvent(planItem, eventList); 134 } 135 136 public JsonObjectBuilder makeUpdateBookmarkTotalEvent(PlanItem planItem, JsonObjectBuilder eventList) { 137 return PlanEventUtils.makeUpdateBookmarkTotalEvent(planItem, eventList); 138 } 139 140 public JsonObjectBuilder makeUpdateBookmarkTotalEvent(String learningPlanId, JsonObjectBuilder eventList) { 141 return PlanEventUtils.makeUpdateBookmarkTotalEvent(learningPlanId, eventList); 142 } 143 144 public JsonObjectBuilder makeUpdatePlanItemStatusMessage(List<PlanItem> planItems, JsonObjectBuilder eventList) { 145 return PlanEventUtils.makeUpdatePlanItemStatusMessage(planItems, eventList); 146 } 147 }