diff options
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailTemplatePlain.java | 32 |
1 files changed, 30 insertions, 2 deletions
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; + } + } } |