<commit_before>/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/
package org.unitime.timetable.server.admin;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


import org.cpsolver.ifs.util.ToolBox;
import org.hibernate.criterion.Order;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.unitime.localization.impl.Localization;
import org.unitime.timetable.gwt.resources.GwtMessages;
import org.unitime.timetable.gwt.shared.SimpleEditInterface;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Field;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.FieldType;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Flag;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.ListItem;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.PageName;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Record;
import org.unitime.timetable.model.ChangeLog;
import org.unitime.timetable.model.CourseType;
import org.unitime.timetable.model.Session;
import org.unitime.timetable.model.StudentSectioningStatus;
import org.unitime.timetable.model.ChangeLog.Operation;
import org.unitime.timetable.model.ChangeLog.Source;
import org.unitime.timetable.model.dao.CourseTypeDAO;
import org.unitime.timetable.model.dao.SessionDAO;
import org.unitime.timetable.model.dao.StudentSectioningStatusDAO;
import org.unitime.timetable.security.SessionContext;
import org.unitime.timetable.security.rights.Right;
import org.unitime.timetable.util.Formats;

/**
 * @author <NAME>
 */
@Service("gwtAdminTable[type=sectioning]")
public class StudentSchedulingStatusTypes implements AdminTable {
	protected static final GwtMessages MESSAGES = Localization.create(GwtMessages.class);
	
	@Override
	public PageName name() {
		return new PageName(MESSAGES.pageStudentSchedulingStatusType(), MESSAGES.pageStudentSchedulingStatusTypes());
	}
	
	enum StatusOption {
		Access(MESSAGES.toggleAccess(), StudentSectioningStatus.Option.enabled),
		Enrollment(MESSAGES.toggleEnrollment(), StudentSectioningStatus.Option.enrollment),
		Advisor(MESSAGES.toggleAdvisor(), StudentSectioningStatus.Option.advisor),
		Admin(MESSAGES.toggleAdmin(), StudentSectioningStatus.Option.admin),
		RegAccess(MESSAGES.toggleRegAccess(), StudentSectioningStatus.Option.regenabled),
		Registration(MESSAGES.toggleRegistration(), StudentSectioningStatus.Option.registration),
		RegAdvisor(MESSAGES.toggleRegAdvisor(), StudentSectioningStatus.Option.regadvisor),
		RegAdmin(MESSAGES.toggleRegAdmin(), StudentSectioningStatus.Option.regadmin),
		Email(MESSAGES.toggleEmail(), StudentSectioningStatus.Option.email),
		WaitListing(MESSAGES.toggleWaitList(), StudentSectioningStatus.Option.waitlist),
		NoBatch(MESSAGES.toggleNoBatch(), StudentSectioningStatus.Option.nobatch),
		AdvisorCanSet(MESSAGES.toggleAdvisorCanSetStatus(), StudentSectioningStatus.Option.advcanset),
		CReqValidation(MESSAGES.toggleCourseRequestValidation(), StudentSectioningStatus.Option.reqval),
		SpecReg(MESSAGES.toggleSpecialRequests(), StudentSectioningStatus.Option.specreg),
		CanReq(MESSAGES.toggleCanRequire(), StudentSectioningStatus.Option.canreq),
		NoSchedule(MESSAGES.toggleNoSchedule(), StudentSectioningStatus.Option.noschedule),
		;
		
		private StudentSectioningStatus.Option iOption;
		private String iLabel;
		
		StatusOption(String label, StudentSectioningStatus.Option option) {
			iLabel = label; iOption = option;  
		}
		
		public String getLabel() { return iLabel; }
		public StudentSectioningStatus.Option getOption() { return iOption; }		
	}

	@Override
	@PreAuthorize("checkPermission('StudentSchedulingStatusTypes')")
	public SimpleEditInterface load(SessionContext context, org.hibernate.Session hibSession) {
		List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
		SimpleEditInterface.Field[] fields = new SimpleEditInterface.Field[courseTypes.isEmpty() ? 9 + StatusOption.values().length : 10 + StatusOption.values().length + courseTypes.size()];
		int idx = 0;
		fields[idx++] = new Field(MESSAGES.fieldAbbreviation(), FieldType.text, 160, 20, Flag.UNIQUE);
		fields[idx++] = new Field(MESSAGES.fieldName(), FieldType.text, 300, 60, Flag.UNIQUE);
		for (StatusOption t: StatusOption.values())
			fields[idx++] = new Field(t.getLabel(), FieldType.toggle, 40);
		fields[idx++] = new Field(MESSAGES.fieldMessage(), FieldType.textarea, 40, 500);
		if (!courseTypes.isEmpty()) {
			for (int i = 0; i < courseTypes.size(); i++)
				fields[idx++] = new Field(courseTypes.get(i).getReference(), FieldType.toggle, 40);
			fields[idx++] = new Field(MESSAGES.toggleNoCourseType(), FieldType.toggle, 40);
		}
		List<ListItem> fallbacks = new ArrayList<ListItem>();
		List<StudentSectioningStatus> statuses = StudentSectioningStatus.findAll(context.getUser().getCurrentAcademicSessionId()); 
		for (StudentSectioningStatus status: statuses) {
			fallbacks.add(new ListItem(status.getUniqueId().toString(), status.getLabel()));
		}
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveStartDate(), FieldType.date, 80);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveStartTime(), FieldType.time, 50);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveEndDate(), FieldType.date, 80);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveEndTime(), FieldType.time, 50);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusFallback(), FieldType.list, 100, fallbacks);
		fields[idx++] = new Field(MESSAGES.fieldSession(), FieldType.toggle, 40);
		
		SimpleEditInterface data = new SimpleEditInterface(fields);
		data.setSortBy(0, 1);
		Formats.Format<Date> dateFormat = Formats.getDateFormat(Formats.Pattern.DATE_EVENT);
		for (StudentSectioningStatus status: statuses) {
			Record r = data.addRecord(status.getUniqueId());
			idx = 0;
			r.setField(idx++, status.getReference());
			r.setField(idx++, status.getLabel());
			for (StatusOption t: StatusOption.values())<commit_msg>Administration: Student Scheduling Status Types<commit_after>/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/
package org.unitime.timetable.server.admin;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


import org.cpsolver.ifs.util.ToolBox;
import org.hibernate.criterion.Order;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.unitime.localization.impl.Localization;
import org.unitime.timetable.gwt.resources.GwtMessages;
import org.unitime.timetable.gwt.shared.SimpleEditInterface;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Field;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.FieldType;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Flag;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.ListItem;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.PageName;
import org.unitime.timetable.gwt.shared.SimpleEditInterface.Record;
import org.unitime.timetable.model.ChangeLog;
import org.unitime.timetable.model.CourseType;
import org.unitime.timetable.model.Session;
import org.unitime.timetable.model.StudentSectioningStatus;
import org.unitime.timetable.model.ChangeLog.Operation;
import org.unitime.timetable.model.ChangeLog.Source;
import org.unitime.timetable.model.dao.CourseTypeDAO;
import org.unitime.timetable.model.dao.SessionDAO;
import org.unitime.timetable.model.dao.StudentSectioningStatusDAO;
import org.unitime.timetable.security.SessionContext;
import org.unitime.timetable.security.rights.Right;
import org.unitime.timetable.util.Formats;

/**
 * @author <NAME>
 */
@Service("gwtAdminTable[type=sectioning]")
public class StudentSchedulingStatusTypes implements AdminTable {
	protected static final GwtMessages MESSAGES = Localization.create(GwtMessages.class);
	
	@Override
	public PageName name() {
		return new PageName(MESSAGES.pageStudentSchedulingStatusType(), MESSAGES.pageStudentSchedulingStatusTypes());
	}
	
	enum StatusOption {
		Access(MESSAGES.toggleAccess(), StudentSectioningStatus.Option.enabled),
		Enrollment(MESSAGES.toggleEnrollment(), StudentSectioningStatus.Option.enrollment),
		Advisor(MESSAGES.toggleAdvisor(), StudentSectioningStatus.Option.advisor),
		Admin(MESSAGES.toggleAdmin(), StudentSectioningStatus.Option.admin),
		RegAccess(MESSAGES.toggleRegAccess(), StudentSectioningStatus.Option.regenabled),
		Registration(MESSAGES.toggleRegistration(), StudentSectioningStatus.Option.registration),
		RegAdvisor(MESSAGES.toggleRegAdvisor(), StudentSectioningStatus.Option.regadvisor),
		RegAdmin(MESSAGES.toggleRegAdmin(), StudentSectioningStatus.Option.regadmin),
		Email(MESSAGES.toggleEmail(), StudentSectioningStatus.Option.email),
		WaitListing(MESSAGES.toggleWaitList(), StudentSectioningStatus.Option.waitlist),
		NoBatch(MESSAGES.toggleNoBatch(), StudentSectioningStatus.Option.nobatch),
		AdvisorCanSet(MESSAGES.toggleAdvisorCanSetStatus(), StudentSectioningStatus.Option.advcanset),
		CReqValidation(MESSAGES.toggleCourseRequestValidation(), StudentSectioningStatus.Option.reqval),
		SpecReg(MESSAGES.toggleSpecialRequests(), StudentSectioningStatus.Option.specreg),
		CanReq(MESSAGES.toggleCanRequire(), StudentSectioningStatus.Option.canreq),
		NoSchedule(MESSAGES.toggleNoSchedule(), StudentSectioningStatus.Option.noschedule),
		;
		
		private StudentSectioningStatus.Option iOption;
		private String iLabel;
		
		StatusOption(String label, StudentSectioningStatus.Option option) {
			iLabel = label; iOption = option;  
		}
		
		public String getLabel() { return iLabel; }
		public StudentSectioningStatus.Option getOption() { return iOption; }		
	}

	@Override
	@PreAuthorize("checkPermission('StudentSchedulingStatusTypes')")
	public SimpleEditInterface load(SessionContext context, org.hibernate.Session hibSession) {
		List<CourseType> courseTypes = CourseTypeDAO.getInstance().findAll(Order.asc("reference"));
		SimpleEditInterface.Field[] fields = new SimpleEditInterface.Field[courseTypes.isEmpty() ? 9 + StatusOption.values().length : 10 + StatusOption.values().length + courseTypes.size()];
		int idx = 0;
		fields[idx++] = new Field(MESSAGES.fieldAbbreviation(), FieldType.text, 160, 20, Flag.UNIQUE);
		fields[idx++] = new Field(MESSAGES.fieldName(), FieldType.text, 300, 60, Flag.UNIQUE);
		for (StatusOption t: StatusOption.values())
			fields[idx++] = new Field(t.getLabel(), FieldType.toggle, 40);
		fields[idx++] = new Field(MESSAGES.fieldMessage(), FieldType.textarea, 40, 500);
		if (!courseTypes.isEmpty()) {
			for (int i = 0; i < courseTypes.size(); i++)
				fields[idx++] = new Field(courseTypes.get(i).getReference(), FieldType.toggle, 40);
			fields[idx++] = new Field(MESSAGES.toggleNoCourseType(), FieldType.toggle, 40);
		}
		List<ListItem> fallbacks = new ArrayList<ListItem>();
		List<StudentSectioningStatus> statuses = StudentSectioningStatus.findAll(context.getUser().getCurrentAcademicSessionId());
		fallbacks.add(new ListItem("", ""));
		for (StudentSectioningStatus status: statuses) {
			fallbacks.add(new ListItem(status.getUniqueId().toString(), status.getLabel()));
		}
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveStartDate(), FieldType.date, 80);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveStartTime(), FieldType.time, 50);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveEndDate(), FieldType.date, 80);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusEffectiveEndTime(), FieldType.time, 50);
		fields[idx++] = new Field(MESSAGES.fieldStudentStatusFallback(), FieldType.list, 100, fallbacks);
		fields[idx++] = new Field(MESSAGES.fieldSession(), FieldType.toggle, 40);
		
		SimpleEditInterface data = new SimpleEditInterface(fields);
		data.setSortBy(0, 1);
		Formats.Format<Date> dateFormat = Formats.getDateFormat(Formats.Pattern.DATE_EVENT);
		for (StudentSectioningStatus status: statuses) {
			Record r = data.addRecord(status.getUniqueId());
			idx = 0;
			r.setField(idx++, status.getReference());
			r.setField(idx++, status.getLabel());
			for (StatusOption t: StatusOption.values())
{'fraction_non_alphanumeric': 0.11544528897174818, 'fraction_numerical': 0.006596873655528467, 'mean_word_length': 6.47427652733119, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2146836', 'n_tokens_mistral': 4386, 'n_tokens_neox': 3999, 'n_words': 809}