Skip to content

Instantly share code, notes, and snippets.

@jkneal
Last active September 25, 2015 13:30
Show Gist options
  • Save jkneal/a179a4663db963f3ac15 to your computer and use it in GitHub Desktop.
Save jkneal/a179a4663db963f3ac15 to your computer and use it in GitHub Desktop.
Dept Inventory Search
private void setDepartmentInventoryResults(ClassDescriptionAdminInfo rv, ClassDescriptionAdminRequest request, AdminAcl acl) {
SisInstitution inst = request.getInstitution();
String car = request.getCar();
String strm = request.getStrm();
String subj = request.getSubj();
CatalogNumber catalogNumber = request.getCatalogNumber();
Map<String, Object> pd = new HashMap<>();
pd.put("inst", inst.name());
pd.put("car", car);
pd.put("subjRaw", subj);
if (StringUtil.hasValue(strm)) {
pd.put("strm", strm);
}
if (catalogNumber != null && StringUtil.hasValue(catalogNumber.getNumber())) {
pd.put("catalogNbr", catalogNumber.getNumber());
}
List<SisSrClass> cl = sis.searchBeans(SisSrClass.class, pd);
List<ClassDescriptionRow> rows = new ArrayList<>();
cl.stream().filter(c -> acl.isMatch(c)).forEach(srClass -> {
List<SisCourseOffering> courseOfferings = courseOfferingService.search(inst, srClass.getSubj(), srClass.getCatalogNbr());
Optional<SisCourseOffering> matchCourseOffering = courseOfferings.stream().filter(o -> o.getCourseId().equals(srClass.getCourseId())).findFirst();
SisCourseOffering courseOffering = matchCourseOffering.isPresent() ? matchCourseOffering.get() : null;
Map<String, Object> dc = new HashMap<>();
dc.put("courseId", srClass.getCourseId());
dc.put("courseOfferNumber", courseOffering.getCourseOfferNumber());
dc.put("strm", srClass.getStrm());
ClassDescription<?> description = classDescriptionService.searchDepartmentDescriptions(srClass.getCourseId(),
courseOffering.getCourseOfferNumber().intValue(), srClass.getStrm(), srClass.getSessionCode());
if (description != null && StringUtil.hasValue(description.getClassDescription())) {
rows.add(new ClassDescriptionRow(courseOffering, srClass));
}
});
rv.setClassDescriptionRows(rows);
}
public static List<GenericSrClassDeptDetailKey> getInvDeptCourseOffer(String institution, String acadGroup,
String subject, String catno, String termCode, String career) {
LOG.error("getCourseOffer " + institution + " " + acadGroup + " " + subject + " " + catno);
String subjectLike = subject + "%";
String sqlStart = " Select distinct a.crse_id as course_Id, a.crse_offer_nbr as course_offer_number, " +
" e.strm, a.institution as institution_code, a.acad_group as academic_group_code, " +
" a.subject as subject_code, a.catalog_nbr as catno, c.course_title_long as crse_title_long" +
" from ps_crse_offer a, " +
" ps_crse_catalog c, " +
" ps_iu_cls_dept_dtl e" +
" where a.institution = ? " +
" and a.acad_group = ? " ;
String sqlOption1 =
" and a.subject like ? " ;
String sqlOption2 =
" and a.catalog_nbr = ?" ;
String sqlOption3 =
" and e.strm = ?" ;
String sqlEnd =
" and a.crse_id = c.crse_id " +
" and a.crse_id = e.crse_id" +
" and a.crse_offer_nbr = e.crse_offer_nbr " +
" and e.last_update_dttm = (select max(f.last_update_dttm) " +
" from ps_iu_cls_dept_dtl f" +
" where f.crse_id = e.crse_id" +
" and f.crse_offer_nbr = e.crse_offer_nbr" +
" and f.strm = e.strm" +
" and f.session_code = e.session_code)" +
" and c.effdt = (select max(d.effdt) " +
" from ps_crse_catalog d " +
" where c.crse_id = d.crse_id) " +
" and c.eff_status = 'A' " +
" and a.effdt = (select max(b.effdt) " +
" from ps_crse_offer b " +
" where b.crse_id = a.crse_id " +
" and b.crse_offer_nbr = a.crse_offer_nbr)" ;
String sql = sqlStart;
if (subject != null) sql = sql + sqlOption1;
if (catno != null) sql = sql + sqlOption2;
if (termCode != null) sql = sql + sqlOption3;
sql = sql + sqlEnd;
List<Object> args = new java.util.LinkedList<Object>();
args.add(institution);
args.add(acadGroup);
if (subject != null) args.add(subjectLike);
if (catno != null) args.add(catno);
if (termCode != null) args.add(termCode);
SisDao dao = ServiceUtil.getFactory().getNamed("sis", SisDao.class);
List<GenericSrClassDeptDetailKey> rv = dao.getQuery(GenericSrClassDeptDetailKey.class,
sql, args.toArray()).getResults();
ListIterator<GenericSrClassDeptDetailKey> li = rv.listIterator();
while (li.hasNext()) {
GenericSrClassDeptDetailKey invDeptDetailKey = li.next();
invDeptDetailKey.setCareerCode(career);
invDeptDetailKey.setCareer(getCareer(institution, career));
invDeptDetailKey.setTerm(getTerm(invDeptDetailKey.getCareer(), invDeptDetailKey.getStrm()));
}
return rv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment