-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCalEntryBase.java
More file actions
115 lines (102 loc) · 3.9 KB
/
Copy pathCalEntryBase.java
File metadata and controls
115 lines (102 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package cz.smarteon.loxone.calendar;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import static java.util.Objects.requireNonNull;
/**
* Base class for every calendar entry.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "calMode")
@JsonSubTypes({
@JsonSubTypes.Type(name = CalEntrySingleDay.CAL_MODE, value = CalEntrySingleDay.class),
@JsonSubTypes.Type(name = CalEntryDayOfWeek.CAL_MODE, value = CalEntryDayOfWeek.class),
@JsonSubTypes.Type(name = CalEntryPeriodYearly.CAL_MODE, value = CalEntryPeriodYearly.class),
@JsonSubTypes.Type(name = CalEntryEasterOffset.CAL_MODE, value = CalEntryEasterOffset.class),
@JsonSubTypes.Type(name = CalEntryPeriod.CAL_MODE, value = CalEntryPeriod.class),
@JsonSubTypes.Type(name = CalEntryEveryYear.CAL_MODE, value = CalEntryEveryYear.class)
})
public abstract class CalEntryBase {
protected static final String CREATE_ENTRY = "calendarcreateentry/";
protected static final String DELETE_ENTRY = "calendardeleteentry/";
protected static final String UPDATE_ENTRY = "calendarupdateentry/";
/**
* UUID of this calendar entry, should be unique.
*/
protected LoxoneUuid uuid;
/**
* Calendar entry name - usually localized, non unique.
*/
@NotNull
@Setter
protected String name;
/**
* Determines which user mode this calendar entry controls e.g. Vacation = 1, Holiday = 0.
*/
@Setter
protected int operatingMode;
/**
* Calendar entry mode
* <pre>
* 0 - One day every year
* 1 - One day dependent on Easter
* 2 - One day
* 3 - Period
* 4 - Period every year
* 5 - A day in a week
* </pre>
*/
protected int calMode;
@JsonCreator
protected CalEntryBase(@NotNull LoxoneUuid uuid, @NotNull String name, int operatingMode, @NotNull String calMode) {
this.uuid = uuid;
this.name = name;
this.operatingMode = operatingMode;
this.calMode = Integer.parseInt(calMode);
}
protected CalEntryBase(@NotNull String name, int operatingMode, @NotNull String calMode) {
this.uuid = null;
this.name = name;
this.operatingMode = operatingMode;
this.calMode = Integer.parseInt(calMode);
}
/**
* Creates delete calendar entry command.
* Command deletes a calendar entry with a given uuid.
*
* @return delete calendar entry command
* @throws NullPointerException user has to have UUID
*/
public CalendarCommand<EmptyValue> deleteEntryCommand(){
requireNonNull(uuid, "Cal entry UUID cannot be null when deleting it");
return new CalendarCommand<>(DELETE_ENTRY + uuid, EmptyValue.class);
}
/**
* Creates create calendar entry command.
* Command creates a new calendar entry with the given parameters.
*
* @return create calendar entry command
*/
public CalendarCommand<EmptyValue> createEntryCommand() {
return new CalendarCommand<>(CREATE_ENTRY + this, EmptyValue.class);
}
/**
* Creates update calendar entry command.
* Command updates an existing calendar entry with the given parameters.
*
* @return update calendar entry command
* @param uuid - uuid of an existing entry to be updated
*/
public CalendarCommand<EmptyValue> updateEntryCommand(LoxoneUuid uuid) {
return new CalendarCommand<>(UPDATE_ENTRY + uuid + "/" + this, EmptyValue.class);
}
}