Navigation
Academic Area Reservations
Academic Areas
Academic Classifications
Academic Sessions
Add Academic Session
Add Application Setting
Add Building
Add Course Credit Type
Add Course Credit Unit
Add Course Offering
Add Course Type
Add Curriculum
Add Date Pattern
Add Default Manager Setting
Add Department
Add Designator
Add Distribution Preference
Add Event
Add Event Date Mapping
Add Event Info
Add Event Meetings
Add Examination
Add Examination Distribution Preference
Add Examination Period
Add Examination Type
Add Instructional Type
Add Instructor
Add Instructor Role
Add Logging Level
Add Non-University Location
Add Position Type
Add Reservation
Add Role
Add Room
Add Room Feature
Add Room Feature Type
Add Room Group
Add Room Type
Add Solver Configuration
Add Solver Group
Add Solver Parameter
Add Solver Parameter Group
Add Special Use Room
Add Sponsoring Organization
Add Standard Event Note
Add Status Type
Add Student Accommodation
Add Student Group
Add Student Scheduling Status Type
Add Subject Area
Add Time Pattern
Add Timetable Manager
Add User
Administration Reports
Alternatives for Class
Application Configuration
Application Of Preferences
Application.properties
Assign Instructors
Assigned Classes
Assigned Examinations
Assignment History
Bugs
Buildings
CPSolver
Chameleon
Change Log for Student
Change Message for Student
Changes
Class Assignment
Class Assignment Properties
Class Assignments
Class Detail
Class Schedule
Classes
Classes for Student
Conflict-Based Statistics
Constraint Solver Howto
Contact Us
Course Credit
Course Credit Formats
Course Credit Types
Course Credit Units
Course Finder
Course Reports
Course Reservations
Course Types
Credits
Current User
Curricula
Curriculum Detail
Curriculum Projection Rules
Curriculum Requested Enrollments
Curriculum Timetable
Custom Room Availability
Customizations
Data Exchange
Date Patterns
Default Academic Session
Default Manager Settings
Departmental Timetable
Departments
Designator List
Distribution Preferences
Distribution Types
Eclipse
Edit Academic Session
Edit Application Setting
Edit Building
Edit Class
Edit Course Credit Format
Edit Course Credit Formats
Edit Course Credit Type
Edit Course Credit Types
Edit Course Credit Unit
Edit Course Credit Units
Edit Course Offering
Edit Course Type
Edit Course Types
Edit Curriculum
Edit Date Pattern
Edit Default Manager Setting
Edit Department
Edit Designator
Edit Distribution Preference
Edit Distribution Type
Edit Event
Edit Event Date Mapping
Edit Event Date Mappings
Edit Event Status
Edit Event Statuses
Edit Examination
Edit Examination Distribution Preference
Edit Examination Period
Edit Examination Type
Edit Examination Types
Edit Instructional Type
Edit Instructor
Edit Instructor Role
Edit Instructor Roles
Edit Logging Level
Edit Logging Levels
Edit Manager Setting
Edit Offering Consent Type
Edit Offering Consent Types
Edit Permission
Edit Permissions
Edit Position Type
Edit Position Types
Edit Reservation
Edit Role
Edit Roles
Edit Room
Edit Room Availability
Edit Room Departments
Edit Room Event Availability
Edit Room Feature
Edit Room Feature Type
Edit Room Feature Types
Edit Room Features
Edit Room Group
Edit Room Groups
Edit Room Preference
Edit Room Type
Edit Scheduling Subpart
Edit Solver Configuration
Edit Solver Group
Edit Solver Parameter
Edit Solver Parameter Group
Edit Sponsoring Organization
Edit Standard Event Note
Edit Status Type
Edit Student Accommodation
Edit Student Accommodations
Edit Student Group
Edit Student Groups
Edit Student Scheduling Status Type
Edit Student Scheduling Status Types
Edit Subject Area
Edit Time Pattern
Edit Timetable Manager
Edit User
Enrollment Audit PDF Reports
Enrollments of Class or Course
Event Date Mappings
Event Detail
Event Reports
Event Room Availability
Event Room Selection
Event Statuses
Event Timetable
Events
Exact Time Pattern
Exam Naming Convention
Examination Assignment
Examination Assignment Changes
Examination Conflict-Based Statistics
Examination Detail
Examination Distribution Preferences
Examination PDF Reports
Examination Periods
Examination Reports
Examination Schedule
Examination Solution Properties
Examination Solver
Examination Solver Log
Examination Solver Status
Examination Timetable
Examination Timetabling
Examination Types
Examinations
Frequently Asked Questions
Hibernate Statistics
Instructional Offering Configuration
Instructional Offering Cross Lists
Instructional Offering Detail
Instructional Offerings
Instructional Types
Instructor Detail
Instructor Preferences
Instructor Roles
Instructors
LDAP Authentication / Lookup
Last Changes
Localization
Logging Levels
Main Page
Majors
Manage Instructor List
Manage Solvers
Manager Settings
Mass cancel...
Meetings
Minors
Multiple Class Setup
Not-Assigned Classes
Not-Assigned Examinations
Offering Consent Types
Online Student Scheduling Dashboard
Page Statistics
People
People Lookup
Permissions
Personal Schedule
Personal Timetable
Position Types
Reservations
Roles
Roll Forward Session
Room Availability
Room Detail
Room Feature Types
Room Features
Room Groups
Room Timetable
Room Types
Rooms
SVN
Scheduling Subpart Detail
Scripts
Select Academic Session
Select User Role
Send email...
Setup Examination Periods
Solution Properties
Solution Reports
Solver
Solver Configurations
Solver Groups
Solver Load Balancing
Solver Log
Solver Parameter Groups
Solver Parameters
Solver Status
Solver Warnings
Special:Userlogin
Sponsoring Organizations
Standard Event Notes
Status Types
Structure of Distribution Preferences
Student Accommodations
Student Conflicts
Student Groups
Student Scheduling Assistant
Student Scheduling Status Types
Student Sectioning Dashboard
Student Sectioning Reports
Student Sectioning Solution Properties
Student Sectioning Solver
Student Sectioning Solver Log
Subject Areas
Subject Timetable
Suggestions
Test HQL
Time Patterns
Timetable
Timetable Managers
Timetables
Timetabling
Timetabling Benchmarks
Timetabling CVS Access
Timetabling Development using MyEclipse
Timetabling Development using NetBeans
Timetabling Installation FAQ
Tips and Tricks
Types of Distribution Preferences
UniTime 3.4 Online Documentation
UniTime Installation
UniTime:Documentation Guidelines
Update Meetings
Users (Database Authentication)
 

Scripts

Screen Description

The Scripts page allows to create a run pretty much any script within UniTime. A script can have many parameters, it can read or write a file, as well as change the database. The JSR 223: Scripting for the Java Platform is used, so many scripting engines can be plugged in if needed. The JavaScript based ECMAScript is available by default, Jython has been tested as well.

The creation of such scripts requires a working knowledge of the UniTime's source code and the Hibernate model. There is no comprehensive development documentation at the moment, except of the source code itself. The Hibernate model (i.e., the *.hbm.xml files in JavaSource folder) is a good place to start. Please contact us at support@unitime.org if you need a help with development of a particular script.

Users with Scripts permission can open the Scripts page, however, each script may require a particular permission for the user to be able to select and execute the script. To create, modify, or delete a script permission Script Edit is required.

Details

To add a new script click on the Add New button. To edit an existing script, select the script in the drop down and click on Edit button. A script can be deleted from the Edit Script dialog, by clicking on the Delete button.


A script has a name and a description. A particular engine has to be selected as well (the list of available scripting engines is in the Engine drop down). The Permission drop down allows to select a permission that the user must have to be able to execute the script (or to be even able to see it in the drop down of available scripts). A script can have one or more parameters. A parameter has a name (and it is referred by this name from the script), a label that is visible to the user, a type (various types are supported, see the example below) and it may have a default value.

Example

Here is an example of what is possible to do with a script (using ECMAScript engine). While the code looks like JavaScript it runs on the server and it can access parameters and all the UniTime classes.

// Logging
if (name != null) {
  log.info(greeting + ' ' + name + '!');
} else {
  log.info(greeting + '!');
  log.warn('No name was given.');
}

// Reading an input (text) file
if (file != null) {
  var lines = file.getString('utf-8').split('\n');
  for (var i = 0; i < lines.length; i++) {
    log.debug((1 + i) + ': ' + lines[i]);
  }
} else {
  log.error('No file to read.', null);
}

// Writing an output file
importPackage(java.io);
var file = log.createOutput('test', 'txt');
var out = new PrintWriter(new FileWriter(file));
out.println('This is a test.');
out.flush(); out.close();

// Special parameters
log.info('Current academic session: ' + session.getLabel());
if (dept != null) {
  log.info('Selected department: ' + dept.getDeptCode() + ' - ' + dept.getLabel());
}
if (subjects != null) {
  log.info('Selected subject areas:');
  for (var i = 0; i < subjects.size(); i++) {
    var subject = subjects.get(i);
    log.info('&nbsp;&nbsp;&nbsp;' + subject.getSubjectAreaAbbreviation() + ' - ' + subject.getTitle());
  }
}
if (type != null) {
  var t = hibSession.createQuery('from RoomType where reference = :reference').setString('reference', type).uniqueResult();
  log.info('Room type: ' + t.getLabel() + ' (' + t.countRooms(session.getUniqueId()) + ' rooms in ' + session.getLabel() + ')');
}

// Progress
log.setStatus('Counting to ten. Slowly.', 10);
importClass(java.lang.Thread);
for (var i = 0; i < 9; i++) {
  Thread.sleep(i * 1000);
  log.incProgress();
  log.debug('-- ' + (1 + i));
}
Besides of the parameters, it can access a hibernate session (parameter hibSession of org.hibernate.Session class), current academic session (parameter session, of Session class) and the object running the script (parameter log, of ScriptExecution class). The hibernate session is opened with a transaction started. This transaction is committed when the script finishes fine, it is rollbacked otherwise. The log can be used to print debug, info, warn, and error message; to control script status and progress; and to create an output file.

The parameters can be of various types. Basic types are string, boolean, int, long, double, float, short, and byte. There can be a drop down selection of one or multiple departments (type department or departments of class Department or List<Department>), one or multiple subject areas (type subject or subjects of class SubjectArea or List<SubjectArea>), one or multiple buildings (type building or buildings of class Building or List<Building>), one or more locations (type location or locations of class Location or List<Location>), or one or more rooms (type room or rooms of class Room or List<Room>). It can also be an input file (type file). A selection of one of given strings (type enum) or a value from a reference table (type reference(RefTableEntry), where RefTableEntry is a model class inherited from RefTableEntry, the result is a string with the value of the reference column of the selected item) are also accepted.

If a user has a department dependent role (e.g., departmental schedule manager), only associated departments, subject areas, rooms, and buildings will be available in the drop downs.

Python

To allow python scripting, the standalone jar version of Jython (e.g., jython-standalone-2.5.3.jar, see Jython downloads) needs to be put in Tomcat/libs folder. After Tomcat is restarted, python should appear as an available engine. Here is an example script (same as the one above) written using python:

# Logging
if name:
  print '%s %s!' % (greeting, name)
else:
  print '%s!' % greeting
  log.warn('No name was given.')

# Reading an input (text) file
if file:
  i = 1
  for line in file.getString('utf-8').split('\n'):
    log.debug('%d: %s' % (i, line))
    i = i + 1
else:
  log.error('No file to read.', None)

# Writing an output file
f = open(log.createOutput('test','txt').getAbsolutePath(), 'w')
f.write('This is a test.\n')
f.close()

# Special parameters
print 'Current academic session: %s' % session.getLabel()
if dept:
  print 'Selected department: %s - %s' % (dept.getDeptCode(), dept.getLabel())
if subjects:
  for subject in subjects:
    print '&nbsp;&nbsp;&nbsp;%s - %s' % (subject.getSubjectAreaAbbreviation(), subject.getTitle())
if type:
  t = hibSession.createQuery('from RoomType where reference = :reference').setString('reference', type).uniqueResult()
  print 'Room type: %s (%d rooms in %s)' % (t.getLabel(), t.countRooms(session.getUniqueId()), session.getLabel())

# Progress
log.setStatus('Counting to ten. Slowly.', 10)
from java.lang import Thread
for i in range(10):
  Thread.sleep(i * 1000)
  log.incProgress()
  log.debug('-- %d' % (1 + i))



Back to Timetabling Documentation.©2013 UniTime LLCContent available under GNU Free Documentation License 1.3.

Updated on Jul 2, 2013 by Tomáš Müller (Version 9)


Attachments (2)

Scripts.png - on Jul 2, 2013 by Tomáš Müller (Version 2)

ScriptsEdit.png - on Jul 2, 2013 by Tomáš Müller (Version 2)