Skip to content

Commit be3559b

Browse files
feat(rest): add declaredLicense field to Release model
Signed-off-by: krrish175-byte <krrishbiswas175@gmail.com>
1 parent 2b2b0c7 commit be3559b

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

clients/client/src/main/java/org/eclipse/sw360/clients/rest/resource/releases/SW360Release.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public final class SW360Release extends SW360HalResource<SW360ReleaseLinkObjects
4444
private boolean isProprietary;
4545
private String name;
4646
private String version;
47+
private String declaredLicense;
4748
private String createdOn;
4849
private String cpeId;
4950
private String downloadurl;
@@ -175,13 +176,13 @@ public SW360Release setOverriddenLicense(String overriddenLicense) {
175176
return this;
176177
}
177178

178-
@JsonIgnore
179+
@JsonInclude(JsonInclude.Include.NON_NULL)
179180
public String getDeclaredLicense() {
180-
return additionalData.get(DECLARED_LICENSE_KEY);
181+
return declaredLicense != null ? declaredLicense : additionalData.get(DECLARED_LICENSE_KEY);
181182
}
182183

183184
public SW360Release setDeclaredLicense(String declaredLicense) {
184-
additionalData.put(DECLARED_LICENSE_KEY, declaredLicense);
185+
this.declaredLicense = declaredLicense;
185186
return this;
186187
}
187188

@@ -326,6 +327,7 @@ public boolean shareIdentifier(SW360Release releaseCompare) {
326327
public SW360Release mergeWith(SW360Release releaseWithPrecedence) {
327328
name = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getName);
328329
version = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getVersion);
330+
declaredLicense = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getDeclaredLicense);
329331
cpeId = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getCpeId);
330332
downloadurl = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getDownloadurl);
331333
if (releaseWithPrecedence.isSetMainLicenseIds()) {
@@ -385,13 +387,14 @@ public boolean equals(Object o) {
385387
Objects.equals(externalIds, release.externalIds) &&
386388
Objects.equals(additionalData, release.additionalData) &&
387389
Objects.equals(createdOn, release.createdOn) &&
390+
Objects.equals(declaredLicense, release.declaredLicense) &&
388391
Objects.equals(sw360ClearingState, release.sw360ClearingState) &&
389392
isProprietary == release.isProprietary;
390393
}
391394

392395
@Override
393396
public int hashCode() {
394-
return Objects.hash(super.hashCode(), name, version, cpeId, downloadurl, externalIds, additionalData,
397+
return Objects.hash(super.hashCode(), name, version, declaredLicense, cpeId, downloadurl, externalIds, additionalData,
395398
isProprietary, createdOn, sw360ClearingState);
396399
}
397400

libraries/datahandler/src/main/thrift/components.thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct Release {
264264

265265
65: optional set<string> mainLicenseIds,
266266
66: optional set<string> otherLicenseIds,
267+
67: optional string declaredLicense,
267268

268269
40: optional Vendor vendor,
269270
41: optional string vendorId,

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ public static abstract class RequestSummaryMixin extends RequestSummary {
11041104
"rolesIsSet",
11051105
"mainLicenseIdsIsSet",
11061106
"otherLicenseIdsIsSet",
1107+
"declaredLicenseIsSet",
11071108
"vendorIsSet",
11081109
"vendorIdIsSet",
11091110
"clearingInformationIsSet",
@@ -1231,6 +1232,7 @@ static abstract class ReleaseMixin extends Release {
12311232
"rolesIsSet",
12321233
"mainLicenseIdsIsSet",
12331234
"otherLicenseIdsIsSet",
1235+
"declaredLicenseIsSet",
12341236
"vendorIsSet",
12351237
"vendorIdIsSet",
12361238
"clearingInformationIsSet",

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ public Package convertToEmbeddedPackage(Package pkg) {
992992

993993
public Release convertToEmbeddedReleaseWithDet(Release release) {
994994
List<String> fields = List.of("id", "name", "version", "cpeid", "createdBy", "createdOn", "componentId","componentType",
995-
"additionalData", "clearingState", "mainLicenseIds", "binaryDownloadurl", "sourceCodeDownloadurl",
995+
"additionalData", "clearingState", "declaredLicense", "mainLicenseIds", "binaryDownloadurl", "sourceCodeDownloadurl",
996996
"releaseDate", "externalIds", "languages", "operatingSystems", "softwarePlatforms", "vendor",
997997
"mainlineState", "packageIds");
998998
return convertToEmbeddedRelease(release, fields);

rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ReleaseSpecTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public void before() throws TException, IOException {
284284
release.setLanguages(new HashSet<>(Arrays.asList("C++", "Java")));
285285
release.setMainLicenseIds(new HashSet<>(Arrays.asList("GPL-2.0-or-later", "Apache-2.0")));
286286
release.setOtherLicenseIds(new HashSet<>(Arrays.asList("MIT", "BSD-3-Clause")));
287+
release.setDeclaredLicense("MIT OR GPL-2.0-or-later");
287288
release.setOperatingSystems(ImmutableSet.of("Windows", "Linux"));
288289
release.setSoftwarePlatforms(new HashSet<>(Arrays.asList("Java SE", ".NET")));
289290
release.setEccInformation(eccInformation);
@@ -759,6 +760,7 @@ public void should_document_get_release_all_details() throws Exception {
759760
subsectionWithPath("_embedded.sw360:releases.[]additionalData").description("A place to store additional data used by external tools").optional(),
760761
subsectionWithPath("_embedded.sw360:releases.[]releaseIdToRelationship").description("Release Id To Relationship of Release").optional(),
761762
subsectionWithPath("_embedded.sw360:releases.[]languages").description("The language of the component"),
763+
subsectionWithPath("_embedded.sw360:releases.[]declaredLicense").description("The declared SPDX license expression").optional(),
762764
subsectionWithPath("_embedded.sw360:releases.[]mainLicenseIds").description("An array of all main licenses").optional(),
763765
subsectionWithPath("_embedded.sw360:releases.[]otherLicenseIds").description("An array of all other licenses associated with the release").optional(),
764766
subsectionWithPath("_embedded.sw360:releases.[]operatingSystems").description("The OS on which the release operates"),
@@ -910,6 +912,7 @@ public void should_document_get_release() throws Exception {
910912
fieldWithPath("releaseDate").description("The date of this release"),
911913
fieldWithPath("createdOn").description("The creation date of the internal sw360 release"),
912914
fieldWithPath("componentType").description("The componentType of the release, possible values are " + Arrays.asList(ComponentType.values())),
915+
fieldWithPath("declaredLicense").description("The declared SPDX license expression").optional(),
913916
fieldWithPath("mainlineState").description("the mainline state of the release, possible values are: " + Arrays.asList(MainlineState.values())),
914917
subsectionWithPath("eccInformation").description("The eccInformation of this release"),
915918
fieldWithPath("sourceCodeDownloadurl").description("the source code download url of the release"),
@@ -1457,6 +1460,7 @@ private RestDocumentationResultHandler documentReleaseProperties() {
14571460
fieldWithPath("version").description("The version of the release"),
14581461
fieldWithPath("createdBy").description("Email of the release creator"),
14591462
fieldWithPath("cpeid").description("CpeId of the release"),
1463+
fieldWithPath("declaredLicense").description("The declared SPDX license expression").optional(),
14601464
fieldWithPath("mainLicenseIds").description("An array of all main licenses"),
14611465
fieldWithPath("clearingState").description("The clearing of the release, possible values are " + Arrays.asList(ClearingState.values())),
14621466
fieldWithPath("releaseDate").description("The date of this release"),

0 commit comments

Comments
 (0)