3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.vorlesungen;
17 import net.fortuna.ical4j.model.Component;
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
22 import de.dhbwloe.campusapp.database.DatabaseManager;
25 * Created by pk910 on 20.01.2016.
27 public class CourseEvent implements Comparable<CourseEvent> {
28 public enum CourseType {
35 private String sCourseName;
36 private String sUniqueId;
37 private int iSequenceId;
38 private long iEventFrom, iEventTo;
39 private String sEventTitle, sEventTitleShort, sEventTitleAuthor, sEventLocation, sEventStatus;
40 private String sRecurRule, sExcludeDates;
41 private CourseGroup oCourseGroup;
42 private CourseType oCourseType = null;
44 private boolean bMustUpdate = false;
45 private boolean bIsNew = false;
47 private boolean bIsKlausurPraesi = false;
49 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) {
51 sCourseName = coursename;
53 iSequenceId = sequenceid;
54 iEventFrom = eventfrom;
57 sEventLocation = location;
58 sEventStatus = status;
60 sExcludeDates = exdates;
64 group.addCourseEvent(this);
66 oCourseType = CourseType.values()[eventtype];
67 } catch(Exception e) {}
73 public CourseEvent(String coursename, String uniqueid, int sequenceid, boolean isNew) {
74 sCourseName = coursename;
76 iSequenceId = sequenceid;
81 public void ParseEventTitle() {
82 Pattern pattern = Pattern.compile("^((Klausur|Tutorium|Pr(ä|ae)sentation)[ :]+)?(.*?)( - ([a-zA-Z., -]+))?$");
83 Matcher m = pattern.matcher(sEventTitle);
84 CourseType oldtype = oCourseType;
85 boolean typeisset = (oCourseType != null);
87 String eventType = m.group(2);
88 if (!typeisset && eventType != null && !eventType.isEmpty()) {
89 if(eventType.equalsIgnoreCase("Klausur"))
90 oCourseType = CourseType.COURSETYPE_KLAUSUR;
91 else if(eventType.equalsIgnoreCase("Präsentation") || eventType.equalsIgnoreCase("Praesentation")) {
92 oCourseType = CourseType.COURSETYPE_KLAUSUR;
93 bIsKlausurPraesi = true;
94 } else if(eventType.equalsIgnoreCase("Tutorium"))
95 oCourseType = CourseType.COURSETYPE_SPECIAL;
99 sEventTitleShort = m.group(4);
100 sEventTitleAuthor = m.group(6);
102 sEventTitleShort = sEventTitle;
103 sEventTitleAuthor = "";
106 oCourseType = CourseType.COURSETYPE_NORMAL;
108 if(oldtype != oCourseType)
112 public void setEventId(int id) {
116 public int getEventId() {
120 private void resetUpdateFlag() {
125 public void update(DatabaseManager dbm, Component event) {
129 dbm.updateCourseCalendar(this, event);
133 public CourseGroup getCourseGroup() {
137 public void setCourseType(CourseType type) {
141 public CourseType getCourseType() {
145 public int getCourseTypeId() {
146 for(int i = 0; i < CourseType.values().length; i++) {
147 if(oCourseType == CourseType.values()[i])
153 public void setCourseGroup(CourseGroup group) {
154 group.addCourseEvent(this);
155 oCourseGroup = group;
158 public String getUniqueId() {
162 public boolean IsPendingUpdate() {
166 public boolean IsNewEvent() {
170 public String getEventStatus() {
174 public void setEventStatus(String sEventStatus) {
175 this.sEventStatus = sEventStatus;
179 public String getEventLocation() {
180 return sEventLocation;
183 public void setEventLocation(String sEventLocation) {
184 this.sEventLocation = sEventLocation;
188 public String getEventTitle() {
191 public String getGroupTitle() {
192 return sEventTitleShort + (sEventTitleAuthor == null ? "" : " - " + sEventTitleAuthor);
194 public String getEventShortTitle() {
195 return sEventTitleShort;
197 public String getEventDozent() {
198 return sEventTitleAuthor;
201 public void setEventTitle(String sEventTitle) {
202 this.sEventTitle = sEventTitle;
207 public long getEventTo() {
211 public void setEventTo(long iEventTo) {
212 this.iEventTo = iEventTo;
216 public long getEventFrom() {
220 public void setEventFrom(long iEventFrom) {
221 this.iEventFrom = iEventFrom;
225 public String getCourseName() {
229 public int getSequenceId() {
233 public void setSequenceId(int iSequenceId) {
234 this.iSequenceId = iSequenceId;
238 public String getRecurRule() {
242 public void setRecurRule(String rrule) {
243 this.sRecurRule = rrule;
247 public String getExcludeDates() {
248 return sExcludeDates;
251 public void setExcludeDates(String exrules) {
252 this.sExcludeDates = exrules;
256 public boolean getIsKlausurPraesi() {
257 return bIsKlausurPraesi;
261 public int compareTo(CourseEvent another) {
262 return (int)(another.getEventFrom() - iEventFrom);