SW360Release extends SW360HalResource<SW360ReleaseLinkObjects, SW360ReleaseEmbedded> { public SW360Release mergeWith(SW360Release releaseWithPrecedence) { name = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getName); version = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getVersion); cpeId = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getCpeId); downloadurl = getDominantGetterFromVariableMergeOrNull(releaseWithPrecedence, SW360Release::getDownloadurl); if (releaseWithPrecedence.isSetMainLicenseIds()) { setMainLicenseIds(releaseWithPrecedence.getMainLicenseIds()); } Self releaseIdWithPrecedence = releaseWithPrecedence.getLinks().getSelf(); if (releaseIdWithPrecedence != null && !releaseIdWithPrecedence.getHref().isEmpty()) { getLinks().setSelf(releaseIdWithPrecedence); } Self componentIdWithPrecedence = releaseWithPrecedence.getLinks().getSelfComponent(); if (componentIdWithPrecedence != null && !componentIdWithPrecedence.getHref().isEmpty()) { getLinks().setSelfComponent(componentIdWithPrecedence); } final Set<SW360SparseAttachment> releaseWithPrecedenceAttachments = releaseWithPrecedence.getEmbedded().getAttachments(); if (!releaseWithPrecedenceAttachments.isEmpty()) { if (getEmbedded().getAttachments().isEmpty()) { getEmbedded().setAttachments(releaseWithPrecedenceAttachments); } else { getEmbedded().setAttachments(mergeAttachments(getEmbedded().getAttachments(), releaseWithPrecedenceAttachments)); } } externalIds.putAll(releaseWithPrecedence.externalIds); additionalData.putAll(releaseWithPrecedence.additionalData); return this; }  @JsonInclude(JsonInclude.Include.NON_NULL) String getComponentId(); SW360Release setComponentId(String componentId); @JsonInclude(JsonInclude.Include.NON_NULL) String getName(); SW360Release setName(String name); @JsonInclude(JsonInclude.Include.NON_NULL) String getVersion(); SW360Release setVersion(String version); @JsonInclude(JsonInclude.Include.NON_NULL) String getCreatedOn(); SW360Release setCreatedOn(String createdOn); @JsonInclude(JsonInclude.Include.NON_NULL) String getCpeId(); SW360Release setCpeId(String cpeId); @JsonIgnore boolean isSetMainLicenseIds(); @JsonInclude(JsonInclude.Include.NON_NULL) Set<String> getMainLicenseIds(); SW360Release setMainLicenseIds(Set<String> mainLicenseIds); @JsonInclude(JsonInclude.Include.NON_NULL) String getDownloadurl(); void setDownloadurl(String downloadurl); @JsonIgnore Map<String, String> getCoordinates(); SW360Release setCoordinates(Map<String, String> coordinates); @JsonIgnore String getOverriddenLicense(); SW360Release setOverriddenLicense(String overriddenLicense); @JsonIgnore String getDeclaredLicense(); SW360Release setDeclaredLicense(String declaredLicense); @JsonIgnore String getObservedLicense(); SW360Release setObservedLicense(String observedLicense); @JsonIgnore String getReleaseTagUrl(); SW360Release setReleaseTagUrl(String releaseTagUrl); @JsonIgnore String getSoftwareHeritageId(); SW360Release setSoftwareHeritageId(String softwareHeritageId); @JsonIgnore Set<String> getHashes(); SW360Release setHashes(Set<String> hashes); @JsonIgnore String getClearingState(); SW360Release setClearingState(String clearingState); @JsonProperty("clearingState") SW360ClearingState getSw360ClearingState(); void setSw360ClearingState(SW360ClearingState sw360ClearingState); @JsonIgnore String getChangeStatus(); SW360Release setChangeStatus(String changeStatus); @JsonIgnore String getCopyrights(); SW360Release setCopyrights(String copyrights); @JsonIgnore boolean isProprietary(); @JsonIgnore SW360Release setProprietary(boolean proprietary); @JsonIgnore String getHomepageUrl(); SW360Release setHomepageUrl(String homepageUrl); Map<String,String> getExternalIds(); SW360Release setExternalIds(Map<String, String> externalIds); SW360Release setAdditionalData(Map<String, String> additionalData); boolean shareIdentifier(SW360Release releaseCompare); SW360Release mergeWith(SW360Release releaseWithPrecedence); @Override SW360ReleaseLinkObjects createEmptyLinks(); @Override SW360ReleaseEmbedded createEmptyEmbedded(); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean canEqual(Object o);  }
@Test public void testReleaseMergeWithPrecedenceHasAttachment() { SW360Release sw360Release1 = new SW360Release(); SW360Release sw360Release2 = new SW360Release(); final SW360SparseAttachment sw360SparseAttachment = makeSparseAttachment("test"); sw360Release2.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360Release1.mergeWith(sw360Release2); assertThat(sw360Release1.getEmbedded().getAttachments()).containsExactly(sw360SparseAttachment); }
@Test public void testReleaseMergeWithPrecedenceHasNoAttachment() { SW360Release sw360Release1 = new SW360Release(); SW360Release sw360Release2 = new SW360Release(); final SW360SparseAttachment sw360SparseAttachment = makeSparseAttachment("test"); sw360Release1.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360Release1.mergeWith(sw360Release2); assertThat(sw360Release1.getEmbedded().getAttachments()).containsExactly(sw360SparseAttachment); }
@Test public void testReleaseMergeWithBothHaveSameAttachment() { SW360Release sw360Release1 = new SW360Release(); SW360Release sw360Release2 = new SW360Release(); SW360SparseAttachment sw360SparseAttachment = makeSparseAttachment("test"); sw360Release1.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360Release2.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360Release1.mergeWith(sw360Release2); assertThat(sw360Release1.getEmbedded().getAttachments()).containsExactly(sw360SparseAttachment); }
@Test public void testReleaseMergeWithBothHaveSameAttachmentButOneHasHref() { SW360Release sw360Release1 = new SW360Release(); SW360Release sw360Release2 = new SW360Release(); SW360SparseAttachment sw360SparseAttachment = makeSparseAttachment("test"); sw360Release1.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360SparseAttachment.setLinks(mock(LinkObjects.class)); sw360Release2.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment)); sw360SparseAttachment.setLinks(null); sw360Release1.mergeWith(sw360Release2); assertThat(sw360Release1.getEmbedded().getAttachments()).containsExactly(sw360SparseAttachment); }
@Test public void testReleaseMergeWithBothHaveDifferentAttachment() { SW360Release sw360Release1 = new SW360Release(); SW360Release sw360Release2 = new SW360Release(); final SW360SparseAttachment sw360SparseAttachment1 = makeSparseAttachment("test_1"); sw360Release1.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment1)); final SW360SparseAttachment sw360SparseAttachment2 = makeSparseAttachment("test_2"); sw360Release2.getEmbedded().setAttachments( Collections.singleton( sw360SparseAttachment2)); sw360Release1.mergeWith(sw360Release2); assertThat(sw360Release1.getEmbedded().getAttachments()).hasSize(2); }