summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-25 14:58:20 +0200
committerJonathan Bauer2015-08-25 14:58:20 +0200
commit7a7edd6f989ade3dfad56039633a0b02a6d7ea84 (patch)
treefdb5c64466ec3189690613bd03417ac04f10e842 /dozentenmodul/src/main/java/org
parent[client] null check the result in UserCache (diff)
downloadtutor-module-7a7edd6f989ade3dfad56039633a0b02a6d7ea84.tar.gz
tutor-module-7a7edd6f989ade3dfad56039633a0b02a6d7ea84.tar.xz
tutor-module-7a7edd6f989ade3dfad56039633a0b02a6d7ea84.zip
[client] check maxValidity for lecture when creating them
Diffstat (limited to 'dozentenmodul/src/main/java/org')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java21
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java17
2 files changed, 28 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
index 6c404f9b..3c6710de 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
@@ -8,6 +8,11 @@ import javax.swing.JSpinner;
import org.jdatepicker.impl.JDatePickerImpl;
public class DateTimeHelper {
+ private static Calendar calendar = null;
+ static {
+ if (calendar == null)
+ calendar = Calendar.getInstance();
+ }
/**
* Returns the Date composed of the given datePicker's date and the given timeSpinner's time
*
@@ -22,13 +27,17 @@ public class DateTimeHelper {
int days = datePicker.getModel().getDay();
// start time from the Spinner
Date time = (Date) timeSpinner.getValue();
- Calendar cal = Calendar.getInstance();
- cal.setTime(time);
- int hours = cal.get(Calendar.HOUR_OF_DAY);
- int minutes = cal.get(Calendar.MINUTE);
+ calendar.setTime(time);
+ int hours = calendar.get(Calendar.HOUR_OF_DAY);
+ int minutes = calendar.get(Calendar.MINUTE);
// build the time from the single values
- cal.set(years, months, days, hours, minutes);
- Date date = cal.getTime();
+ calendar.set(years, months, days, hours, minutes);
+ Date date = calendar.getTime();
return date;
}
+ public static Date addDaysTo(Date start, int days) {
+ calendar.setTime(start);
+ calendar.add(Calendar.DAY_OF_MONTH, days);
+ return calendar.getTime();
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
index 5adff7ba..3f47aa0d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
@@ -14,6 +14,8 @@ import org.openslx.dozmod.gui.helper.DateTimeHelper;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCreationPageLayout;
import org.openslx.dozmod.state.LectureWizardState;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.dozmod.util.FormatHelper;
@SuppressWarnings("serial")
public class LectureCreationPage extends LectureCreationPageLayout {
@@ -97,7 +99,6 @@ public class LectureCreationPage extends LectureCreationPageLayout {
} else {
state.description = descriptionText.getText();
}
- // TODO max <sat config> months checks
final Date now = new Date();
final Date start = DateTimeHelper.getDateFrom(startDate, startTime);
final Date end = DateTimeHelper.getDateFrom(endDate, endTime);
@@ -108,9 +109,17 @@ public class LectureCreationPage extends LectureCreationPageLayout {
} else if (now.after(end)) {
setWarningMessage("Endzeit liegt in die Vergangenheit!");
return false;
- } else { // all good, save them both
- state.start = start;
- state.end = end;
+ } else {
+ int validityPeriod = Session.getSatelliteConfig().getMaxLectureValidityDays();
+ Date validityPeriodEnd = DateTimeHelper.addDaysTo(start, validityPeriod); // all good, save them both
+ if (end.after(validityPeriodEnd)) {
+ setWarningMessage("Endzeit liegt über das maximale Datum: "
+ + FormatHelper.shortDate(validityPeriodEnd.getTime() / 1000L));
+ return false;
+ } else {
+ state.start = start;
+ state.end = end;
+ }
}
setDescription("Klicken Sie auf 'Weiter' für Berechtigungen oder 'Fertigstellen'");
return true;