OWL ITS + 탐지시스템(인터넷 진흥원)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package kr.wisestone.owl.domain;
 
 
import kr.wisestone.owl.domain.enumType.ServiceType;
import kr.wisestone.owl.util.DateUtil;
 
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
 
/**
 * Created by wisestone on 2018-02-13.
 */
@Entity
public class Workspace extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final Long DEFAULT_FREE_ALLOCATE_DISK = 10737418240L;
    private static final Long DEFAULT_USER_ALLOCATE_DISK = 3221225472L;
 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private Integer maxUser;
    private Date startDate;
    private Date expireDate;
    private Long storageSize = 0L;
    private Long useTraffic = 0L;    //  트레픽 사용량 측정
    @Enumerated(EnumType.STRING)
    private ServiceType serviceType;    //  사용자가 서비스를 취소할 경우에 UNUSED 로 값이 변경된다. - 일반적인 경우에는 USE 값이다.
 
    @OneToOne(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Payment payment;
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<AttachedFile> attachedFiles = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<Project> projects = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<CustomField> customFields = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<IssueType> issueTypes = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<Workflow> workflows = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<IssueStatus> issueStatuses = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<UserWorkspace> userWorkspaces = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<UserInvite> userInvites = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<PaymentHistory> paymentHistories = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private Set<IssueUser> issueUsers = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private Set<IssueRisk> issueRisks = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private Set<IssueComment> issueComments = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private Set<UserLikeIssue> userLikeIssues = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = { CascadeType.ALL }, orphanRemoval = true)
    private Set<IssueSearch> issueSearches = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<IssueTableConfig> issueTableConfigs = new HashSet<>();
 
    @OneToMany(mappedBy = "workspace", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Set<Priority> priorities = new HashSet<>();
 
 
 
    public Workspace() {
    }
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public Integer getMaxUser() {
        return maxUser;
    }
 
    public void setMaxUser(Integer maxUser) {
        this.maxUser = maxUser;
    }
 
    public Date getStartDate() {
        return startDate;
    }
 
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
 
    public Date getExpireDate() {
        return expireDate;
    }
 
    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }
 
    public Long getStorageSize() {
        return storageSize;
    }
 
    public void setStorageSize(Long storageSize) {
        this.storageSize = storageSize;
    }
 
    public Payment getPayment() {
        return payment;
    }
 
    public void setPayment(Payment payment) {
        this.payment = payment;
    }
 
    public Set<PaymentHistory> getPaymentHistories() {
        return paymentHistories;
    }
 
    public void setPaymentHistories(Set<PaymentHistory> paymentHistories) {
        this.paymentHistories = paymentHistories;
    }
 
    public Long calculateStorageSize() {
        //  10명 이하는 5GB 제공
        if (this.maxUser < 11) {
            return DEFAULT_FREE_ALLOCATE_DISK;
        }
 
        //  10명 이상은 10GB + 사용자수 * 3기가 제공
        return DEFAULT_FREE_ALLOCATE_DISK + (this.maxUser * DEFAULT_USER_ALLOCATE_DISK);
    }
 
    public Set<Project> getProjects() {
        return projects;
    }
 
    public void setProjects(Set<Project> projects) {
        this.projects = projects;
    }
 
    public Set<IssueStatus> getIssueStatuses() {
        return issueStatuses;
    }
 
    public void setIssueStatuses(Set<IssueStatus> issueStatuses) {
        this.issueStatuses = issueStatuses;
    }
 
    public Set<AttachedFile> getAttachedFiles() {
        return attachedFiles;
    }
 
    public void setAttachedFiles(Set<AttachedFile> attachedFiles) {
        this.attachedFiles = attachedFiles;
    }
 
    public Set<UserWorkspace> getUserWorkspaces() {
        return userWorkspaces;
    }
 
    public void setUserWorkspaces(Set<UserWorkspace> userWorkspaces) {
        this.userWorkspaces = userWorkspaces;
    }
 
    public Set<UserInvite> getUserInvites() {
        return userInvites;
    }
 
    public void setUserInvites(Set<UserInvite> userInvites) {
        this.userInvites = userInvites;
    }
 
    public Set<IssueType> getIssueTypes() {
        return issueTypes;
    }
 
    public void setIssueTypes(Set<IssueType> issueTypes) {
        this.issueTypes = issueTypes;
    }
 
    public Set<Workflow> getWorkflows() {
        return workflows;
    }
 
    public void setWorkflows(Set<Workflow> workflows) {
        this.workflows = workflows;
    }
 
    public Set<CustomField> getCustomFields() {
        return customFields;
    }
 
    public void setCustomFields(Set<CustomField> customFields) {
        this.customFields = customFields;
    }
 
    public ServiceType getServiceType() {
        return serviceType;
    }
 
    public void setServiceType(ServiceType serviceType) {
        this.serviceType = serviceType;
    }
 
    public Set<IssueUser> getIssueUsers() {
        return issueUsers;
    }
 
    public void setIssueUsers(Set<IssueUser> issueUsers) {
        this.issueUsers = issueUsers;
    }
 
    public Set<IssueRisk> getIssueRisks() {
        return issueRisks;
    }
 
    public void setIssueRisks(Set<IssueRisk> issueRisks) {
        this.issueRisks = issueRisks;
    }
 
    public Set<IssueComment> getIssueComments() {
        return issueComments;
    }
 
    public void setIssueComments(Set<IssueComment> issueComments) {
        this.issueComments = issueComments;
    }
 
    public Set<UserLikeIssue> getUserLikeIssues() {
        return userLikeIssues;
    }
 
    public void setUserLikeIssues(Set<UserLikeIssue> userLikeIssues) {
        this.userLikeIssues = userLikeIssues;
    }
 
    public Long getUseTraffic() {
        return useTraffic;
    }
 
    public void setUseTraffic(Long useTraffic) {
        this.useTraffic = useTraffic;
    }
 
    public Set<IssueSearch> getIssueSearches() {
        return issueSearches;
    }
 
    public void setIssueSearches(Set<IssueSearch> issueSearches) {
        this.issueSearches = issueSearches;
    }
 
    public Set<IssueTableConfig> getIssueTableConfigs() {
        return issueTableConfigs;
    }
 
    public void setIssueTableConfigs(Set<IssueTableConfig> issueTableConfigs) {
        this.issueTableConfigs = issueTableConfigs;
    }
 
    public Set<Priority> getPriorities() {
        return priorities;
    }
 
    public void setPriorities(Set<Priority> priorities) {
        this.priorities = priorities;
    }
 
    public String makeCustomerUid(String account) {
        account = account.replaceAll(".", "_");
 
        MessageDigest messageDigest = null;
 
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
 
        if (messageDigest != null) {
            byte[] digest = messageDigest.digest((account + this.getId()).getBytes());
            BigInteger bigInt = new BigInteger(1, digest);
            return bigInt.toString(16);
        }
        else {
            return account + this.getId();
        }
    }
 
    //  OWL ITS 결제는 매달일 경우 30일, 1년일 경우 365일로 한다.
    public Date calculateNextPaymentDate(String decisionType, Date expireDate) {
        Date toDay = new Date();
 
        if (Payment.MONTH.equals(decisionType)) {
            int compare = toDay.compareTo(expireDate);
 
            if (compare > 0) {
                //  오늘 날짜가 더 클 때 - 한동안 사용안하다가 결제한 경우
                return DateUtil.addDays(toDay, 30);
            }
            else {
                //  만료 날짜가 같거나 더 클 때 - 만료일에 결제했거나 무료 사용기간에 결제했을 때
                return DateUtil.addDays(expireDate, 30);
            }
        }
        else {
            //  매년 결제
            return DateUtil.addDays(expireDate, 365);
        }
    }
}