-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathComponent.java
More file actions
303 lines (240 loc) · 7.13 KB
/
Component.java
File metadata and controls
303 lines (240 loc) · 7.13 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
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
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.persistence.model;
import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.JdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import java.util.UUID;
@Entity
@RegisterForReflection
@Table(name = "COMPONENT")
public class Component extends PanacheEntityBase {
@Id
@Column(name = "ID")
private long id;
@Column(name = "\"GROUP\"", columnDefinition = "VARCHAR")
private String group;
@Column(name = "NAME", columnDefinition = "VARCHAR", nullable = false)
private String name;
@Column(name = "VERSION", columnDefinition = "VARCHAR")
private String version;
@Column(name = "FILENAME", columnDefinition = "VARCHAR")
private String filename;
@Column(name = "CPE")
private String cpe;
@Column(name = "PURL")
private String purl;
@Column(name = "PURLCOORDINATES")
private String purlCoordinates;
@Column(name = "SWIDTAGID")
private String swidTagId;
@Column(name = "INTERNAL")
private Boolean internal;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "COPYRIGHT")
private String copyright;
@Column(name = "LICENSE", columnDefinition = "VARCHAR")
private String license;
@ManyToOne
@JoinColumn(name = "PROJECT_ID", nullable = false)
private Project project;
@Column(name = "UUID", nullable = false)
@JdbcType(UUIDJdbcType.class)
private UUID uuid;
@Column(name = "MD5", columnDefinition = "VARCHAR")
private String md5;
@Column(name = "SHA1", columnDefinition = "VARCHAR")
private String sha1;
@Column(name = "SHA_256", columnDefinition = "VARCHAR")
private String sha256;
@Column(name = "SHA_512", columnDefinition = "VARCHAR")
private String sha512;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = StringUtils.abbreviate(group, 255);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = StringUtils.abbreviate(name, 255);
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = StringUtils.abbreviate(version, 255);
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = StringUtils.abbreviate(filename, 255);
}
public String getCpe() {
return cpe;
}
public void setCpe(String cpe) {
this.cpe = StringUtils.abbreviate(cpe, 255);
}
public PackageURL getPurl() {
if (purl == null) {
return null;
}
try {
return new PackageURL(purl);
} catch (MalformedPackageURLException e) {
return null;
}
}
public void setPurl(PackageURL purl) {
if (purl != null) {
this.purl = purl.canonicalize();
} else {
this.purl = null;
}
}
public void setPurl(String purl) {
this.purl = purl;
}
public PackageURL getPurlCoordinates() {
if (purlCoordinates == null) {
return null;
}
try {
return new PackageURL(purlCoordinates);
} catch (MalformedPackageURLException e) {
return null;
}
}
public void setPurlCoordinates(PackageURL purlCoordinates) {
if (purlCoordinates != null) {
this.purlCoordinates = purlCoordinates.canonicalize();
} else {
this.purlCoordinates = null;
}
}
public void setPurlCoordinates(String purlCoordinates) {
this.purlCoordinates = purlCoordinates;
}
public String getSwidTagId() {
return swidTagId;
}
public void setSwidTagId(String swidTagId) {
this.swidTagId = swidTagId;
}
public boolean isInternal() {
if (internal == null) {
return false;
}
return internal;
}
public void setInternal(boolean internal) {
this.internal = internal;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public String getSha1() {
return sha1;
}
public void setSha1(String sha1) {
this.sha1 = sha1;
}
public String getSha256() {
return sha256;
}
public void setSha256(String sha256) {
this.sha256 = sha256;
}
public String getSha512() {
return sha512;
}
public void setSha512(String sha512) {
this.sha512 = sha512;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = StringUtils.abbreviate(description, 1024);
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = StringUtils.abbreviate(copyright, 1024);
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = StringUtils.abbreviate(license, 255);
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@Override
public String toString() {
if (getPurl() != null) {
return getPurl().canonicalize();
} else {
StringBuilder sb = new StringBuilder();
if (getGroup() != null) {
sb.append(getGroup()).append(" : ");
}
sb.append(getName());
if (getVersion() != null) {
sb.append(" : ").append(getVersion());
}
return sb.toString();
}
}
}