1 package de.dhbwloe.campusapp.vorlesungen;
3 import net.fortuna.ical4j.model.Component;
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
8 import de.dhbwloe.campusapp.database.DatabaseManager;
11 * Created by pk910 on 20.01.2016.
13 public class CourseEvent implements Comparable<CourseEvent> {
14 public enum CourseType {
21 private String sCourseName;
22 private String sUniqueId;
23 private int iSequenceId;
24 private long iEventFrom, iEventTo;
25 private String sEventTitle, sEventTitleShort, sEventTitleAuthor, sEventLocation, sEventStatus;
26 private String sRecurRule, sExcludeDates;
27 private CourseGroup oCourseGroup;
28 private CourseType oCourseType = null;
30 private boolean bMustUpdate = false;
31 private boolean bIsNew = false;
33 private boolean bIsKlausurPraesi = false;
35 public CourseEvent(int id, String coursename, String uniqueid, int sequenceid, long eventfrom, long eventto, String title, String location, String status, String rrule, String exdates, CourseGroup group, int eventtype) {
37 sCourseName = coursename;
39 iSequenceId = sequenceid;
40 iEventFrom = eventfrom;
43 sEventLocation = location;
44 sEventStatus = status;
46 sExcludeDates = exdates;
50 group.addCourseEvent(this);
52 oCourseType = CourseType.values()[eventtype];
53 } catch(Exception e) {}
59 public CourseEvent(String coursename, String uniqueid, int sequenceid, boolean isNew) {
60 sCourseName = coursename;
62 iSequenceId = sequenceid;
67 public void ParseEventTitle() {
68 Pattern pattern = Pattern.compile("^((Klausur|Tutorium|Pr(ä|ae)sentation)[ :]+)?(.*?)( - ([a-zA-Z., -]+))?$");
69 Matcher m = pattern.matcher(sEventTitle);
70 CourseType oldtype = oCourseType;
71 boolean typeisset = (oCourseType != null);
73 String eventType = m.group(2);
74 if (!typeisset && eventType != null && !eventType.isEmpty()) {
75 if(eventType.equalsIgnoreCase("Klausur"))
76 oCourseType = CourseType.COURSETYPE_KLAUSUR;
77 else if(eventType.equalsIgnoreCase("Präsentation") || eventType.equalsIgnoreCase("Praesentation")) {
78 oCourseType = CourseType.COURSETYPE_KLAUSUR;
79 bIsKlausurPraesi = true;
80 } else if(eventType.equalsIgnoreCase("Tutorium"))
81 oCourseType = CourseType.COURSETYPE_SPECIAL;
85 sEventTitleShort = m.group(4);
86 sEventTitleAuthor = m.group(6);
88 sEventTitleShort = sEventTitle;
89 sEventTitleAuthor = "";
92 oCourseType = CourseType.COURSETYPE_NORMAL;
94 if(oldtype != oCourseType)
98 public void setEventId(int id) {
102 public int getEventId() {
106 private void resetUpdateFlag() {
111 public void update(DatabaseManager dbm, Component event) {
115 dbm.updateCourseCalendar(this, event);
119 public CourseGroup getCourseGroup() {
123 public void setCourseType(CourseType type) {
127 public CourseType getCourseType() {
131 public int getCourseTypeId() {
132 for(int i = 0; i < CourseType.values().length; i++) {
133 if(oCourseType == CourseType.values()[i])
139 public void setCourseGroup(CourseGroup group) {
140 group.addCourseEvent(this);
141 oCourseGroup = group;
144 public String getUniqueId() {
148 public boolean IsPendingUpdate() {
152 public boolean IsNewEvent() {
156 public String getEventStatus() {
160 public void setEventStatus(String sEventStatus) {
161 this.sEventStatus = sEventStatus;
165 public String getEventLocation() {
166 return sEventLocation;
169 public void setEventLocation(String sEventLocation) {
170 this.sEventLocation = sEventLocation;
174 public String getEventTitle() {
177 public String getGroupTitle() {
178 return sEventTitleShort + (sEventTitleAuthor == null ? "" : " - " + sEventTitleAuthor);
180 public String getEventShortTitle() {
181 return sEventTitleShort;
183 public String getEventDozent() {
184 return sEventTitleAuthor;
187 public void setEventTitle(String sEventTitle) {
188 this.sEventTitle = sEventTitle;
193 public long getEventTo() {
197 public void setEventTo(long iEventTo) {
198 this.iEventTo = iEventTo;
202 public long getEventFrom() {
206 public void setEventFrom(long iEventFrom) {
207 this.iEventFrom = iEventFrom;
211 public String getCourseName() {
215 public int getSequenceId() {
219 public void setSequenceId(int iSequenceId) {
220 this.iSequenceId = iSequenceId;
224 public String getRecurRule() {
228 public void setRecurRule(String rrule) {
229 this.sRecurRule = rrule;
233 public String getExcludeDates() {
234 return sExcludeDates;
237 public void setExcludeDates(String exrules) {
238 this.sExcludeDates = exrules;
242 public boolean getIsKlausurPraesi() {
243 return bIsKlausurPraesi;
247 public int compareTo(CourseEvent another) {
248 return (int)(another.getEventFrom() - iEventFrom);