<commit_before>/*
 * UniTime 3.1 (University Timetabling Application)
 * Copyright (C) 2008, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.unitime.timetable.form;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.unitime.commons.User;
import org.unitime.commons.web.Web;
import org.unitime.timetable.model.Department;
import org.unitime.timetable.model.Event;
import org.unitime.timetable.model.Roles;
import org.unitime.timetable.model.SponsoringOrganization;
import org.unitime.timetable.model.TimetableManager;
import org.unitime.timetable.model.UserData;
import org.unitime.timetable.util.CalendarUtils;
import org.unitime.timetable.util.ComboBoxLookup;

/**
 * @author <NAME>
 */
public class EventListForm extends ActionForm {
	private String iOp;
	private String iEventNameSubstring;
	private String iEventMainContactSubstring;
	private String iEventDateFrom;
	private String iEventDateTo;
	private Integer[] iEventTypes = null;
	private Long iSponsorOrgId = null;
	
	public static final int sModeMyEvents = 0;
	public static final int sModeEvents4Approval = 1;
	public static final int sModeAllEvents = 2;
	public static final int sModeAllApprovedEvents = 3;
	public static final int sModeAllEventsWaitingApproval = 4;
	public static final int sModeAllConflictingEvents = 5;
	
	private int iMode = sModeMyEvents;
	private boolean iAdmin = false;
	private boolean iEventMgr = false;
	private boolean iNoRole = false;
	private String iUserId = null;
	private Set iManagingDepts = null;
	private boolean iConf = false;
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();

		String df = "MM/dd/yyyy";
		Date start = null;
		if (iEventDateFrom==null || iEventDateFrom.trim().length()==0)
			;
		else if (!CalendarUtils.isValidDate(iEventDateFrom, df))
			errors.add("eventDateFrom", new ActionMessage("errors.invalidDate", "Date '"+iEventDateFrom+"' (From)"));
		else
			start = CalendarUtils.getDate(iEventDateFrom, df);
		
		Date end = null;
		if (iEventDateTo==null || iEventDateTo.trim().length()==0) {
			//no end
		} else if (!CalendarUtils.isValidDate(iEventDateTo, df))
			errors.add("eventDateTo", new ActionMessage("errors.invalidDate", "Date '"+iEventDateTo+"' (To)"));
		else
			end = CalendarUtils.getDate(iEventDateTo, df);
		
		if (end!=null && !start.equals(end) && !start.before(end))
			errors.add("eventDateTo", new ActionMessage("errors.generic", "Date From cannot occur after Date To"));

		return errors;
	}
	
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		iEventDateFrom = new SimpleDateFormat("MM/dd/yyyy").format(new Date());
		iEventDateTo = null;
		iEventTypes = new Integer[] {
				Event.sEventTypeSpecial
		};
		iOp = null;
		User user = Web.getUser(request.getSession());
		iAdmin = false; iEventMgr = false; iNoRole = false;
		if (user==null || user.getRole()==null) {
		    iMode = sModeMyEvents; iNoRole = true;
		} else if (Roles.EVENT_MGR_ROLE.equals(user.getRole())) {
		    iMode = sModeEvents4Approval; iEventMgr = true;
		    TimetableManager mgr = (user==null?null:TimetableManager.getManager(user));
            if (mgr!=null) iManagingDepts = mgr.getDepartments();
		} else if (user.isAdmin()) {
		    iMode = sModeAllEvents;
		    iAdmin = true;
		}
		iUserId = (user==null?null:user.getId());
		iSponsorOrgId = null;
		iConf = false;
	}
	
	public void load(HttpSession session) {<commit_msg>fixed null pointer exception when end date is provided but no start date<commit_after>/*
 * UniTime 3.1 (University Timetabling Application)
 * Copyright (C) 2008, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.unitime.timetable.form;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.unitime.commons.User;
import org.unitime.commons.web.Web;
import org.unitime.timetable.model.Department;
import org.unitime.timetable.model.Event;
import org.unitime.timetable.model.Roles;
import org.unitime.timetable.model.SponsoringOrganization;
import org.unitime.timetable.model.TimetableManager;
import org.unitime.timetable.model.UserData;
import org.unitime.timetable.util.CalendarUtils;
import org.unitime.timetable.util.ComboBoxLookup;

/**
 * @author <NAME>
 */
public class EventListForm extends ActionForm {
	private String iOp;
	private String iEventNameSubstring;
	private String iEventMainContactSubstring;
	private String iEventDateFrom;
	private String iEventDateTo;
	private Integer[] iEventTypes = null;
	private Long iSponsorOrgId = null;
	
	public static final int sModeMyEvents = 0;
	public static final int sModeEvents4Approval = 1;
	public static final int sModeAllEvents = 2;
	public static final int sModeAllApprovedEvents = 3;
	public static final int sModeAllEventsWaitingApproval = 4;
	public static final int sModeAllConflictingEvents = 5;
	
	private int iMode = sModeMyEvents;
	private boolean iAdmin = false;
	private boolean iEventMgr = false;
	private boolean iNoRole = false;
	private String iUserId = null;
	private Set iManagingDepts = null;
	private boolean iConf = false;
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();

		String df = "MM/dd/yyyy";
		Date start = null;
		if (iEventDateFrom==null || iEventDateFrom.trim().length()==0)
			;
		else if (!CalendarUtils.isValidDate(iEventDateFrom, df))
			errors.add("eventDateFrom", new ActionMessage("errors.invalidDate", "Date '"+iEventDateFrom+"' (From)"));
		else
			start = CalendarUtils.getDate(iEventDateFrom, df);
		
		Date end = null;
		if (iEventDateTo==null || iEventDateTo.trim().length()==0) {
			//no end
		} else if (!CalendarUtils.isValidDate(iEventDateTo, df))
			errors.add("eventDateTo", new ActionMessage("errors.invalidDate", "Date '"+iEventDateTo+"' (To)"));
		else
			end = CalendarUtils.getDate(iEventDateTo, df);
		
		if (end!=null && start!=null && !start.equals(end) && !start.before(end))
			errors.add("eventDateTo", new ActionMessage("errors.generic", "Date From cannot occur after Date To"));

		return errors;
	}
	
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		iEventDateFrom = new SimpleDateFormat("MM/dd/yyyy").format(new Date());
		iEventDateTo = null;
		iEventTypes = new Integer[] {
				Event.sEventTypeSpecial
		};
		iOp = null;
		User user = Web.getUser(request.getSession());
		iAdmin = false; iEventMgr = false; iNoRole = false;
		if (user==null || user.getRole()==null) {
		    iMode = sModeMyEvents; iNoRole = true;
		} else if (Roles.EVENT_MGR_ROLE.equals(user.getRole())) {
		    iMode = sModeEvents4Approval; iEventMgr = true;
		    TimetableManager mgr = (user==null?null:TimetableManager.getManager(user));
            if (mgr!=null) iManagingDepts = mgr.getDepartments();
		} else if (user.isAdmin()) {
		    iMode = sModeAllEvents;
		    iAdmin = true;
		}
		iUserId = (user==null?null:user.getId());
		iSponsorOrgId = null;
		iConf = false;
	}
	
	public void load(HttpSession session) {
{'fraction_non_alphanumeric': 0.10352233676975946, 'fraction_numerical': 0.006013745704467354, 'mean_word_length': 4.7030006123698715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3311444', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2798, 'n_words': 833}