OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 150 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 ilm 1
package org.openconcerto.modules.operation;
2
 
3
import java.util.List;
4
 
5
import org.jopencalendar.model.Flag;
6
import org.jopencalendar.model.JCalendarItem;
150 ilm 7
import org.openconcerto.sql.element.SQLElementDirectory;
8
import org.openconcerto.sql.model.SQLRowValues;
9
import org.openconcerto.utils.CollectionUtils;
112 ilm 10
 
11
public class JCalendarItemDB extends JCalendarItem {
150 ilm 12
    private final SQLRowValues item;
13
    private final SQLRowValues group;
14
    private final OperationSQLElement operationElem;
15
    private final SQLRowValues operation;
112 ilm 16
    private String status;
17
    private String type;
18
    private String plannerXML;
19
    private String plannerUID;
20
    private String siteName;
21
    private String siteComment;
22
    private Number siteId;
23
 
150 ilm 24
    public JCalendarItemDB(final SQLElementDirectory dir, final SQLRowValues r) {
25
        assert r.isFrozen();
26
        this.item = r;
27
        this.group = dir.getElement(this.item.getTable()).getContainer(this.item);
181 ilm 28
        if (this.group == null) {
29
            throw new IllegalArgumentException("no group found for row " + r);
30
        }
150 ilm 31
        this.operationElem = dir.getElement(OperationSQLElement.class);
181 ilm 32
        if (this.operationElem == null) {
33
            throw new IllegalStateException("no element found " + OperationSQLElement.class);
34
        }
150 ilm 35
        this.operation = CollectionUtils.getSole(this.group.getReferentRows(this.operationElem.getTable()));
112 ilm 36
    }
37
 
150 ilm 38
    // OK since frozen
39
    public final SQLRowValues getRow() {
40
        return this.item;
112 ilm 41
    }
42
 
150 ilm 43
    public final OperationSQLElement getSourceElement() {
44
        return this.operationElem;
112 ilm 45
    }
46
 
150 ilm 47
    // OK since frozen
48
    public final SQLRowValues getSource() {
49
        return this.operation;
112 ilm 50
    }
51
 
150 ilm 52
    public final boolean isPlanned() {
53
        // there's also a flag "planned" but it's for the UI
54
        return !this.getSource().getString("PLANNER_UID").isEmpty();
55
    }
56
 
57
    // OK since frozen
58
    public final SQLRowValues getUserRow() {
59
        return (SQLRowValues) this.getSource().getForeign("ID_USER_COMMON");
60
    }
61
 
62
    // OK since frozen
63
    public final SQLRowValues getCalendarGroup() {
64
        return this.group;
65
    }
66
 
141 ilm 67
    public int getIdCalendarGroup() {
150 ilm 68
        return this.getCalendarGroup().getID();
112 ilm 69
    }
70
 
71
    @Override
72
    public int hashCode() {
150 ilm 73
        return this.getId();
112 ilm 74
    }
75
 
76
    @Override
77
    public boolean equals(Object obj) {
150 ilm 78
        if (this == obj)
79
            return true;
80
        if (obj == null)
81
            return false;
82
        if (getClass() != obj.getClass())
83
            return false;
84
        final JCalendarItemDB o = (JCalendarItemDB) obj;
85
        return this.item.equalsAsRow(o.item);
112 ilm 86
    }
87
 
88
    public void setOperationStatus(String status) {
89
        this.status = status;
90
    }
91
 
92
    public String getStatus() {
181 ilm 93
        return this.status;
112 ilm 94
    }
95
 
96
    public void setOperationType(String type) {
97
        this.type = type;
98
    }
99
 
100
    public String getType() {
181 ilm 101
        return this.type;
112 ilm 102
    }
103
 
104
    public String getFlagsString() {
105
        final List<Flag> flags = getFlags();
106
        final int size = flags.size();
107
        String str = "";
108
        for (int i = 0; i < size; i++) {
109
            str += flags.get(i).getTypeId();
110
            if (i < size - 1) {
111
                str += ",";
112
            }
113
        }
114
        return str;
115
    }
116
 
117
    public String getPlannerXML() {
181 ilm 118
        return this.plannerXML;
112 ilm 119
    }
120
 
121
    public void setPlannerXML(String string) {
122
        this.plannerXML = string;
123
    }
124
 
125
    public String getPlannerUID() {
181 ilm 126
        return this.plannerUID;
112 ilm 127
    }
128
 
129
    public void setPlannerUID(String plannerUID) {
130
        this.plannerUID = plannerUID;
131
    }
132
 
133
    public String getSiteName() {
181 ilm 134
        return this.siteName;
112 ilm 135
    }
136
 
137
    public void setSiteName(String siteName) {
138
        this.siteName = siteName;
139
    }
140
 
141
    public String getSiteComment() {
181 ilm 142
        return this.siteComment;
112 ilm 143
    }
144
 
145
    public void setSiteComment(String siteComment) {
146
        this.siteComment = siteComment;
147
    }
148
 
149
    public void setSiteId(Number idNumber) {
150
        this.siteId = idNumber;
151
    }
152
 
153
    public Number getSiteId() {
181 ilm 154
        return this.siteId;
112 ilm 155
    }
141 ilm 156
 
157
    public int getId() {
150 ilm 158
        return this.getRow().getID();
141 ilm 159
    }
112 ilm 160
}