Skip to content

Commit

Permalink
API: Online Student Scheduling
Browse files Browse the repository at this point in the history
- added online student scheduling JSON API
  - pretty much all the calls in the org.unitime.timetable.gwt.services.SectioningService are covered,
    except of those related to HTTP session attributes (e.g., last request / schedule)
  - the SectioningService is used by the Online Student Scheduling Assistant and the Online Student Scheduling Dashboard pages
  • Loading branch information
tomas-muller committed Oct 22, 2015
1 parent 4d97dcf commit 611b4a3
Show file tree
Hide file tree
Showing 5 changed files with 626 additions and 13 deletions.
81 changes: 81 additions & 0 deletions JavaSource/org/unitime/timetable/api/AbstractApiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,85 @@ public org.hibernate.Session getHibSession() {

@Override
public void close() {}

@Override
public String getOptinalParameter(String name, String defaultValue) {
String ret = getParameter(name);
return (ret != null ? ret : defaultValue);
}

@Override
public String getRequiredParameter(String name) {
String ret = getParameter(name);
if (ret == null)
throw new IllegalArgumentException("Parameter '" + name + "' was not provided.");
return ret;
}

@Override
public Integer getOptinalParameterInteger(String name, Integer defaultValue) {
String ret = getParameter(name);
if (ret != null) {
try {
return Integer.valueOf(ret);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Parameter '" + name + "' must be an integer.");
}
}
return defaultValue;
}

@Override
public Integer getRequiredParameterInteger(String name) {
String ret = getParameter(name);
if (ret == null)
throw new IllegalArgumentException("Parameter '" + name + "' was not provided.");
try {
return Integer.valueOf(ret);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Parameter '" + name + "' must be an integer.");
}
}

@Override
public Long getOptinalParameterLong(String name, Long defaultValue) {
String ret = getParameter(name);
if (ret != null) {
try {
return Long.valueOf(ret);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Parameter '" + name + "' must be a long.");
}
}
return defaultValue;
}

@Override
public Long getRequiredParameterLong(String name) {
String ret = getParameter(name);
if (ret == null)
throw new IllegalArgumentException("Parameter '" + name + "' was not provided.");
try {
return Long.valueOf(ret);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Parameter '" + name + "' must be a long.");
}
}

@Override
public Boolean getOptinalParameterBoolean(String name, Boolean defaultValue) {
String ret = getParameter(name);
if (ret != null) {
return "true".equalsIgnoreCase(ret) || "1".equalsIgnoreCase(ret);
}
return defaultValue;
}

@Override
public Boolean getRequiredParameterBoolean(String name) {
String ret = getParameter(name);
if (ret == null)
throw new IllegalArgumentException("Parameter '" + name + "' was not provided.");
return "true".equalsIgnoreCase(ret) || "1".equalsIgnoreCase(ret);
}
}
16 changes: 16 additions & 0 deletions JavaSource/org/unitime/timetable/api/ApiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ public interface ApiHelper {
public org.hibernate.Session getHibSession();

public void close();

public String getOptinalParameter(String name, String defaultValue);

public String getRequiredParameter(String name);

public Integer getOptinalParameterInteger(String name, Integer defaultValue);

public Integer getRequiredParameterInteger(String name);

public Long getOptinalParameterLong(String name, Long defaultValue);

public Long getRequiredParameterLong(String name);

public Boolean getOptinalParameterBoolean(String name, Boolean defaultValue);

public Boolean getRequiredParameterBoolean(String name);
}
Loading

0 comments on commit 611b4a3

Please sign in to comment.