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);
|
}
|
}
|
}
|