@Override
 @PreAuthorize("checkPermission('StudentSchedulingStatusTypeEdit')")
 public void save(Record record, SessionContext context, Session hibSession) {
   StudentSectioningStatus status = new StudentSectioningStatus();
   int value = 0;
   for (int i = 0; i < StatusOption.values().length; i++)
     if ("true".equals(record.getField(2 + i)))
       value += StatusOption.values()[i].getOption().toggle();
   status.setTypes(new HashSet<CourseType>());
   List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
   if (!courseTypes.isEmpty()) {
     for (int i = 0; i < courseTypes.size(); i++)
       if ("true".equals(record.getField(3 + StatusOption.values().length + i)))
         status.getTypes().add(courseTypes.get(i));
     if (!"true".equals(record.getField(3 + StatusOption.values().length + courseTypes.size())))
       value += StudentSectioningStatus.Option.notype.toggle();
   }
   status.setReference(record.getField(0));
   status.setLabel(record.getField(1));
   status.setStatus(value);
   status.setMessage(record.getField(2 + StatusOption.values().length));
   record.setUniqueId((Long) hibSession.save(status));
   ChangeLog.addChange(
       hibSession,
       context,
       status,
       status.getReference() + " " + status.getLabel(),
       Source.SIMPLE_EDIT,
       Operation.CREATE,
       null,
       null);
 }
 protected void update(
     StudentSectioningStatus status, Record record, SessionContext context, Session hibSession) {
   if (status == null) return;
   int value = 0;
   for (int i = 0; i < StatusOption.values().length; i++)
     if ("true".equals(record.getField(2 + i)))
       value += StatusOption.values()[i].getOption().toggle();
   Set<CourseType> types = new HashSet<CourseType>();
   List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
   if (!courseTypes.isEmpty()) {
     for (int i = 0; i < courseTypes.size(); i++)
       if ("true".equals(record.getField(3 + StatusOption.values().length + i)))
         types.add(courseTypes.get(i));
     if (!"true".equals(record.getField(3 + StatusOption.values().length + courseTypes.size())))
       value += StudentSectioningStatus.Option.notype.toggle();
   }
   boolean changed =
       !ToolBox.equals(status.getReference(), record.getField(0))
           || !ToolBox.equals(status.getLabel(), record.getField(1))
           || !ToolBox.equals(status.getStatus(), value)
           || !ToolBox.equals(status.getTypes(), types)
           || !ToolBox.equals(
               status.getMessage(), record.getField(2 + StatusOption.values().length));
   status.setReference(record.getField(0));
   status.setLabel(record.getField(1));
   status.setStatus(value);
   status.setTypes(types);
   status.setMessage(record.getField(2 + StatusOption.values().length));
   hibSession.saveOrUpdate(status);
   if (changed)
     ChangeLog.addChange(
         hibSession,
         context,
         status,
         status.getReference() + " " + status.getLabel(),
         Source.SIMPLE_EDIT,
         Operation.UPDATE,
         null,
         null);
 }