-
Notifications
You must be signed in to change notification settings - Fork 0
/
Product.java
176 lines (138 loc) · 4.67 KB
/
Product.java
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
package edu.tamu.app.model;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonView;
import edu.tamu.app.model.validation.ProductValidator;
import edu.tamu.weaver.response.ApiView;
import edu.tamu.weaver.validation.model.ValidatingBaseEntity;
@Entity
public class Product extends ValidatingBaseEntity {
@Column(unique = true, nullable = false)
@JsonView(ApiView.Partial.class)
private String name;
@Column(nullable = true)
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private String scopeId;
@Column(nullable = true)
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private String devUrl;
@Column(nullable = true)
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private String preUrl;
@Column(nullable = true)
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private String productionUrl;
@Column(nullable = true)
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private String wikiUrl;
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private List<String> otherUrls;
@ElementCollection(fetch = FetchType.EAGER)
@JsonView(ApiView.Partial.class)
private List<RemoteProjectInfo> remoteProjectInfo;
public Product() {
super();
this.modelValidator = new ProductValidator();
}
public Product(String name) {
this();
this.name = name;
}
public Product(String name, List<RemoteProjectInfo> remoteProjectInfo) {
this();
this.name = name;
this.remoteProjectInfo = remoteProjectInfo;
}
public Product(String name, List<RemoteProjectInfo> remoteProjectInfo, String scopeId, String devUrl, String preUrl, String productionUrl, String wikiUrl, List<String> otherUrls) {
this();
this.name = name;
this.remoteProjectInfo = remoteProjectInfo;
this.scopeId = scopeId;
this.devUrl = devUrl;
this.preUrl = preUrl;
this.productionUrl = productionUrl;
this.wikiUrl = wikiUrl;
this.otherUrls = otherUrls;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getScopeId() {
return scopeId;
}
public void setScopeId(String scopeId) {
this.scopeId = scopeId;
}
public String getDevUrl() {
return devUrl;
}
public void setDevUrl(String devUrl) {
this.devUrl = devUrl;
}
public String getPreUrl() {
return preUrl;
}
public void setPreUrl(String preUrl) {
this.preUrl = preUrl;
}
public String getProductionUrl() {
return productionUrl;
}
public void setProductionUrl(String productionUrl) {
this.productionUrl = productionUrl;
}
public String getWikiUrl() {
return wikiUrl;
}
public void setWikiUrl(String wikiUrl) {
this.wikiUrl = wikiUrl;
}
public List<String> getOtherUrls() {
return otherUrls;
}
public void setOtherUrls(List<String> otherUrls) {
this.otherUrls = otherUrls;
}
public void addOtherUrl(String otherUrl) {
this.otherUrls.add(otherUrl);
}
public void removeOtherUrl(String otherUrl) {
this.otherUrls = this.otherUrls.stream()
.filter(o -> !o.equals(otherUrl))
.collect(Collectors.toList());
}
public List<RemoteProjectInfo> getRemoteProjectInfo() {
return remoteProjectInfo;
}
public void setRemoteProductInfo(List<RemoteProjectInfo> remoteProjectInfo) {
this.remoteProjectInfo = remoteProjectInfo;
}
public void addRemoteProductInfo(RemoteProjectInfo remoteProjectInfo) {
this.remoteProjectInfo.add(remoteProjectInfo);
}
public void removeRemoteProduct(RemoteProjectInfo remoteProjectInfo) {
this.remoteProjectInfo = this.remoteProjectInfo.stream()
.filter(rp -> {
return !rp.getScopeId().equals(remoteProjectInfo.getScopeId()) && !rp.getRemoteProjectManager().equals(remoteProjectInfo.getRemoteProjectManager());
}).collect(Collectors.toList());
}
}