2021-11-29 15:44:55 +01:00
package res ;
import com.sun.jdi.event.StepEvent ;
2022-01-19 00:16:23 +01:00
import java.io.Serializable ;
2022-01-11 17:14:30 +01:00
import java.nio.charset.StandardCharsets ;
2022-01-19 00:30:13 +01:00
import java.sql.SQLOutput ;
2021-12-20 12:57:18 +01:00
import java.time.Duration ;
import java.time.LocalDate ;
2021-11-29 15:44:55 +01:00
import java.time.LocalDateTime ;
2022-01-19 00:30:13 +01:00
import java.time.LocalTime ;
2021-11-29 15:44:55 +01:00
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
2021-12-20 12:57:18 +01:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import java.util.regex.PatternSyntaxException ;
2021-11-29 15:44:55 +01:00
public class Event {
private int id ;
private String name ;
private int priority ;
private boolean isFullDay ;
private boolean isPrivate ;
private String start ;
private String end ;
private LocalDateTime date ;
private int ownerId ;
private String ownerName ;
2022-01-25 19:37:49 +01:00
public Event ( ) { }
2022-01-19 00:16:23 +01:00
2021-11-29 15:44:55 +01:00
public Event ( String name ,
int priority ,
boolean isFullDay ,
boolean isPrivate ,
2022-01-19 00:30:13 +01:00
LocalTime start ,
LocalTime end ,
2021-11-29 15:44:55 +01:00
LocalDateTime date ,
int ownerId
2022-01-19 00:30:13 +01:00
) throws IllegalArgumentException {
System . out . println ( " Create Event " ) ;
if ( name . length ( ) < 3 ) {
2021-12-20 12:57:18 +01:00
throw new IllegalArgumentException ( " Der Name muss eine L \ u00e4nge von 3 haben. " ) ;
}
2022-01-13 07:57:10 +01:00
Pattern pattern = Pattern . compile ( " [A-Za-z \ u00e4 \ u00f6 \ u00fc \ u00c4 \ u00d6 \ u00dc \ u00df0-9 =!?+*/$.:,;_<>()-]* " ) ;
2021-12-20 12:57:18 +01:00
Matcher matcher = pattern . matcher ( name ) ;
2022-01-19 00:30:13 +01:00
if ( ! matcher . matches ( ) ) {
2022-01-13 07:57:10 +01:00
throw new IllegalArgumentException ( " Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \ u00e4 \ u00f6 \ u00fc \ u00c4 \ u00d6 \ u00dc \ u00df =!?+*/$.:,;_ <>()- " ) ;
2021-12-20 12:57:18 +01:00
}
2022-01-19 00:30:13 +01:00
if ( priority < 0 ) {
2021-12-20 12:57:18 +01:00
throw new IllegalArgumentException ( " Bitte eine Priorit \ u00e4t w \ u00e4hlen. " ) ;
}
LocalDateTime today = LocalDateTime . now ( ) . toLocalDate ( ) . atStartOfDay ( ) ;
2022-01-19 00:30:13 +01:00
if ( Duration . between ( today , date ) . isNegative ( ) ) {
2021-12-20 12:57:18 +01:00
throw new IllegalArgumentException ( " Das Datum muss in der Zukunft liegen. " ) ;
}
2021-11-29 15:44:55 +01:00
this . name = name ;
this . priority = priority ;
this . isFullDay = isFullDay ;
this . isPrivate = isPrivate ;
2022-01-19 00:30:13 +01:00
if ( start ! = null ) this . start = start . toString ( ) ;
if ( start ! = null ) this . end = end . toString ( ) ;
2021-11-29 15:44:55 +01:00
this . date = date ;
this . ownerId = ownerId ;
}
public int getId ( ) {
return id ;
}
public void setId ( int id ) {
this . id = id ;
}
public String getName ( ) {
return name ;
}
public void setName ( String name ) {
2022-01-24 12:45:08 +01:00
System . out . println ( name ) ;
this . name = name ;
System . out . println ( this . name ) ;
2021-11-29 15:44:55 +01:00
}
public int getPriority ( ) {
return priority ;
}
public void setPriority ( int priority ) {
this . priority = priority ;
}
public boolean isFullDay ( ) {
return isFullDay ;
}
public void setFullDay ( boolean fullDay ) {
isFullDay = fullDay ;
}
public boolean isPrivate ( ) {
return isPrivate ;
}
public void setPrivate ( boolean aPrivate ) {
isPrivate = aPrivate ;
}
public String getStart ( ) {
return start ;
}
public void setStart ( String start ) {
this . start = start ;
}
public String getEnd ( ) {
return end ;
}
public void setEnd ( String end ) {
this . end = end ;
}
public LocalDateTime getDate ( ) {
return date ;
}
2022-01-19 00:16:23 +01:00
public void setDate ( String date ) {
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( " yyyy-MM-dd HH:mm " ) ;
this . date = LocalDateTime . parse ( date + " 00:00 " , formatter ) ;
2021-11-29 15:44:55 +01:00
}
public int getOwnerId ( ) {
return ownerId ;
}
public void setOwnerId ( int ownerId ) {
this . ownerId = ownerId ;
}
public String getOwnerName ( ) {
return ownerName ;
}
public void setOwnerName ( String ownerName ) {
this . ownerName = ownerName ;
}
@Override
public String toString ( ) {
return name +
" \ nVon: " + start +
" \ nBis: " + start +
( isFullDay ? " \ nDen ganzen Tag lang " : " " ) ;
}
public String getAsUrlParam ( ) {
return " userId= " + getOwnerId ( ) +
" &date= " + getDate ( ) . toLocalDate ( ) +
" &name= " + getName ( ) +
" &start= " + getStart ( ) +
" &end= " + getEnd ( ) +
2022-01-19 00:30:13 +01:00
" &priority= " + getPriority ( ) +
2021-11-29 15:44:55 +01:00
" &isFullDay= " + isFullDay ( ) +
" &isPrivate= " + isPrivate ( ) ;
}
}