summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver
diff options
context:
space:
mode:
authorSimon Rettberg2017-06-02 16:21:38 +0200
committerSimon Rettberg2017-06-02 16:21:38 +0200
commita42ccfe7f8cfd1eef6ca47ba0ccf5421d9d0fd92 (patch)
treef28f42f494e66f342629d379896d4a86d825e291 /dozentenmodulserver
parent[server] Fix placeholder inconsistency, backwards compatible (diff)
downloadtutor-module-a42ccfe7f8cfd1eef6ca47ba0ccf5421d9d0fd92.tar.gz
tutor-module-a42ccfe7f8cfd1eef6ca47ba0ccf5421d9d0fd92.tar.xz
tutor-module-a42ccfe7f8cfd1eef6ca47ba0ccf5421d9d0fd92.zip
[server] Add versioning and modification checking to mail templates
Diffstat (limited to 'dozentenmodulserver')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplateConfiguration.java54
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java32
2 files changed, 65 insertions, 21 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplateConfiguration.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplateConfiguration.java
index 938ba359..43b68a70 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplateConfiguration.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplateConfiguration.java
@@ -19,18 +19,20 @@ public class MailTemplateConfiguration {
"Wird an die Verantwortlichen einer Veranstaltung gesendet, wenn die verknüpfte VM aktualisiert wurde.",
"Die zur Veranstaltung '%lecture%' gehörige VM wurde aktualisiert.",
new String[]{"image", "created", "uploader"},
- new String[]{"lecture"}
+ new String[]{"lecture"},
+ 1
),
new MailTemplatePlain(
Template.LECTURE_DEACTIVATED,
"Wird versendet, wenn eine Veranstaltung unerwartet deaktiviert werden musste.",
"Die Veranstaltung '%lecture%' musste deaktiviert werden,"
- + " da die verknüpfte VM gelöscht oder beschädigt wurde. Bitte überprüfen"
+ + " da die verknüpfte VM '%image%' gelöscht oder beschädigt wurde. Bitte überprüfen"
+ " Sie die Veranstaltung und ändern Sie ggf. die Verlinkung,"
+ " damit die Veranstaltung wieder verwendbar ist.",
new String[] {"image"},
- new String[] {"lecture"}
+ new String[] {"lecture"},
+ 0
),
new MailTemplatePlain(
@@ -39,7 +41,8 @@ public class MailTemplateConfiguration {
"Die aktuellste Version der VM '%image%' läuft in %remaining_days% Tag(en) ab."
+ " Bitte aktualisieren Sie die VM, da verknüpfte Veranstaltungen sonst deaktiviert werden.",
new String[]{"remaining_days", "created", "image_expiretime"},
- new String[]{"image"}
+ new String[]{"image"},
+ 0
),
new MailTemplatePlain(
@@ -48,7 +51,8 @@ public class MailTemplateConfiguration {
"Eine alte Version der VM '%image%' läuft in %remaining_days% Tag(en) ab (Version vom %created%)."
+ " Eine aktuellere Version ist vorhanden, diese Nachricht dient nur der Information.",
new String[]{"remaining_days", "created", "image_expiretime"},
- new String[]{"image"}
+ new String[]{"image"},
+ 0
),
new MailTemplatePlain(
@@ -57,7 +61,8 @@ public class MailTemplateConfiguration {
"Hinweis zur Veranstaltung '%lecture%': Die verwendete VM '%image%'"
+ " läuft in %remaining_days% Tag(en) ab. Bitte aktualisieren oder wechseln Sie die VM.",
new String[]{"remaining_days", "image_expiretime"},
- new String[]{"lecture", "image"}
+ new String[]{"lecture", "image"},
+ 1
),
new MailTemplatePlain(
@@ -65,7 +70,8 @@ public class MailTemplateConfiguration {
"Wird versendet, wenn eine Veranstaltung kurz vor dem Enddatum steht.",
"Die Veranstaltung '%lecture%' läuft in %remaining_days% Tag(en) ab. Verlängern Sie bei Bedarf das Ablaufdatum.",
new String[]{"remaining_days", "lecture_endtime"},
- new String[]{"lecture"}
+ new String[]{"lecture"},
+ 0
),
new MailTemplatePlain(
@@ -75,7 +81,8 @@ public class MailTemplateConfiguration {
+ " eine neue Version hochladen möchte, ohne die Metadaten erneut eingeben zu müssen.",
"Die letzte verbliebene Version der VM '%image%' wurde gelöscht. Die Metadaten der VM wurden zur Löschung vorgemerkt.",
new String[]{},
- new String[]{"image"}
+ new String[]{"image"},
+ 0
),
new MailTemplatePlain(
@@ -84,7 +91,8 @@ public class MailTemplateConfiguration {
"Eine alte Version der VM '%image%' vom %old_created% wurde gelöscht\n"
+ "Die neueste Version ist jetzt vom %new_created% (erstellt von %uploader%)",
new String[]{"old_created", "new_created", "uploader"},
- new String[]{"image"}
+ new String[]{"image"},
+ 0
),
new MailTemplatePlain(
@@ -96,7 +104,8 @@ public class MailTemplateConfiguration {
+ " Daher verweist sie jetzt auf die VM-Version vom %created%."
+ " Bitte überprüfen Sie ggf., ob diese VM-Version für Ihren Kurs geeignet ist.",
new String[]{"created"},
- new String[]{"lecture"}
+ new String[]{"lecture"},
+ 1
),
new MailTemplatePlain(
@@ -105,7 +114,8 @@ public class MailTemplateConfiguration {
"Test der Mailkonfiguration.\n\n%host%:%port% \nSSL: %ssl%"
+ "\nLogin: %username%",
new String[]{"host", "port", "ssl", "username"},
- new String[]{}
+ new String[]{},
+ 0
),
new MailTemplatePlain(
@@ -122,7 +132,8 @@ public class MailTemplateConfiguration {
+ "e-Mail-Benachrichtigungen."
+ "\n\n-- \n" + "Generiert auf %sender_name%",
new String[]{"first_name", "last_name", "sender_name"},
- new String[]{"messages"}
+ new String[]{"messages"},
+ 0
)
};
@@ -154,23 +165,28 @@ public class MailTemplateConfiguration {
/**
*
- * @param conf the configuration that will be merged
+ * @param newconf the configuration that will be merged
* @return a new configuration containing templates from "this" and conf.
* If a template with the same name exists in both then "this" has priority
*/
- public MailTemplateConfiguration merge(MailTemplateConfiguration conf) {
+ public MailTemplateConfiguration merge(MailTemplateConfiguration newconf) {
HashMap<Template, MailTemplatePlain> templates = new HashMap<>();
- /* add all templates from conf */
- for (MailTemplatePlain t : conf.templates) {
+
+ /* add all templates from here */
+ for (MailTemplatePlain t : this.templates) {
if (t.getName() != null) {
templates.put(t.getName(), t);
}
}
- /* add all templates from here */
- for (MailTemplatePlain t : this.templates) {
- if (t.getName() != null) {
+ /* add all templates from conf that don't exist yet */
+ for (MailTemplatePlain t : newconf.templates) {
+ if (t.getName() == null)
+ continue;
+ if (!templates.containsKey(t.getName())) {
templates.put(t.getName(), t);
+ } else {
+ templates.get(t.getName()).mergeWithUpdatedVersion(t);
}
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java
index 1a20d003..54ee81ee 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java
@@ -27,14 +27,25 @@ public class MailTemplatePlain {
@SerializedName("mandatory_variables")
private String[] mandatoryVariables;
+
+ private int version;
+
+ @SerializedName("edit_version")
+ private int editVersion;
+
+ private boolean original = false;
+
+ private String original_template;
public MailTemplatePlain(Template name, String description, String template, String[] optionalVariables,
- String[] mandatoryVariables) {
+ String[] mandatoryVariables, int version) {
this.name = name;
this.description = description;
- this.template = template;
+ this.original_template = this.template = template;
this.optionalVariables = optionalVariables;
this.mandatoryVariables = mandatoryVariables;
+ this.version = version;
+ this.original = true;
}
public Template getName() {
@@ -44,5 +55,22 @@ public class MailTemplatePlain {
public MailTemplate toMailTemplate() {
return new MailTemplate(template);
}
+
+ public void mergeWithUpdatedVersion(MailTemplatePlain updated) {
+ this.description = updated.description;
+ this.optionalVariables = updated.optionalVariables;
+ this.mandatoryVariables = updated.mandatoryVariables;
+ if (this.original || this.template.trim().replace("\r\n", "\n").equals(updated.template.trim().replace("\r\n", "\n"))) {
+ // they are the same or it has not been edited
+ this.original = true;
+ this.template = updated.template;
+ this.editVersion = this.version = updated.version;
+ this.original_template = "";
+ } else {
+ // Just update what the latest version is
+ this.version = updated.version;
+ this.original_template = updated.template;
+ }
+ }
}