-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rest): update response API Get a single release #2009
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.eclipse.sw360.datahandler.thrift.components.Component; | ||
import org.eclipse.sw360.datahandler.thrift.components.ComponentService; | ||
import org.eclipse.sw360.datahandler.thrift.components.Release; | ||
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink; | ||
import org.eclipse.sw360.datahandler.thrift.licenses.License; | ||
import org.eclipse.sw360.datahandler.thrift.licenses.Obligation; | ||
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest; | ||
|
@@ -100,6 +101,7 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace; | ||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
|
@@ -293,6 +295,56 @@ public void addEmbeddedContributors(HalResource halResource, Set<String> contrib | |
} | ||
} | ||
|
||
public void addEmbeddedDataToHalResourceRelease(HalResource halResource, Release sw360Release) { | ||
addEmbeddedContributorsToHalResourceRelease(halResource, sw360Release); | ||
addEmbeddedCreatedByToHalResourceRelease(halResource, sw360Release.getCreatedBy()); | ||
addEmbeddedModifiedByToHalResourceRelease(halResource, sw360Release.getModifiedBy()); | ||
addEmbeddedSubcribeToHalResourceRelease(halResource, sw360Release); | ||
} | ||
|
||
public void addEmbeddedContributorsToHalResourceRelease(HalResource halResource, Release sw360Release) { | ||
if (!CommonUtils.isNullOrEmptyCollection(sw360Release.getContributors())) { | ||
Set<String> contributors = sw360Release.getContributors(); | ||
for (String contributorEmail : contributors) { | ||
User sw360User = getUserByEmail(contributorEmail); | ||
if (null != sw360User) { | ||
addEmbeddedUser(halResource, sw360User, "sw360:contributors"); | ||
sw360Release.setContributors(null); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
public void addEmbeddedSubcribeToHalResourceRelease(HalResource halResource, Release sw360Release) { | ||
if (!CommonUtils.isNullOrEmptyCollection(sw360Release.getSubscribers())) { | ||
Set<String> subscribers = sw360Release.getSubscribers(); | ||
for (String subscribersEmail : subscribers) { | ||
User sw360User = getUserByEmail(subscribersEmail); | ||
if (null != sw360User) { | ||
addEmbeddedUser(halResource, sw360User, "sw360:subscribers"); | ||
sw360Release.setSubscribers(null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void addEmbeddedCreatedByToHalResourceRelease(HalResource halRelease, String createdBy) { | ||
if (CommonUtils.isNotNullEmptyOrWhitespace(createdBy)) { | ||
User releaseCreator = getUserByEmail(createdBy); | ||
if (null != releaseCreator ) | ||
addEmbeddedUser(halRelease, releaseCreator, "sw360:createdBy"); | ||
} | ||
} | ||
|
||
public void addEmbeddedModifiedByToHalResourceRelease(HalResource halRelease, String modifiedBy) { | ||
if (CommonUtils.isNotNullEmptyOrWhitespace(modifiedBy)) { | ||
User releaseModify = getUserByEmail(modifiedBy); | ||
if (null != releaseModify) | ||
addEmbeddedUser(halRelease, releaseModify, "sw360:modifiedBy"); | ||
} | ||
} | ||
|
||
public void addEmbeddedLeadArchitect(HalResource halResource, String leadArchitect) { | ||
User sw360User = getUserByEmail(leadArchitect); | ||
addEmbeddedUser(halResource, sw360User, "leadArchitect"); | ||
|
@@ -317,6 +369,15 @@ public void addEmbeddedReleases( | |
} | ||
} | ||
|
||
public void addEmbeddedReleaseLinks( | ||
HalResource halResource, | ||
List<ReleaseLink> releaseLinks) { | ||
List<ReleaseLink> releaseLinkInogreAttachments = releaseLinks.stream().map(releaseLink -> releaseLink.setAttachments(null)).collect(Collectors.toList()); | ||
for (ReleaseLink releaseLink : releaseLinkInogreAttachments) { | ||
addEmbeddedReleaseLink(halResource, releaseLink); | ||
} | ||
} | ||
|
||
public void addEmbeddedUser(HalResource halResource, User user, String relation) { | ||
User embeddedUser = convertToEmbeddedUser(user); | ||
EntityModel<User> embeddedUserResource = EntityModel.of(embeddedUser); | ||
|
@@ -353,6 +414,23 @@ public HalResource<Vendor> addEmbeddedVendor(String vendorFullName) { | |
return null; | ||
} | ||
|
||
public HalResource<Vendor> addEmbeddedVendor(Vendor vendor) { | ||
Vendor embeddedVendor = convertToEmbeddedVendor(vendor); | ||
HalResource<Vendor> halVendor = new HalResource<>(embeddedVendor); | ||
try { | ||
Vendor vendorByFullName = vendorService.getVendorByFullName(vendor.getFullname()); | ||
if(vendorByFullName != null) { | ||
Link vendorSelfLink = linkTo(UserController.class) | ||
.slash("api" + VendorController.VENDORS_URL + "/" + vendorByFullName.getId()).withSelfRel(); | ||
halVendor.add(vendorSelfLink); | ||
} | ||
return halVendor; | ||
} catch (Exception e) { | ||
LOGGER.error("cannot create self link for vendor with full name: " + vendor.getFullname()); | ||
} | ||
return null; | ||
} | ||
|
||
public void addEmbeddedLicenses(HalResource<Release> halComponent, Set<String> licenseIds) { | ||
for (String licenseId : licenseIds) { | ||
HalResource<License> licenseHalResource = addEmbeddedLicense(licenseId); | ||
|
@@ -395,6 +473,11 @@ public void addEmbeddedRelease(HalResource halResource, Release release) { | |
halResource.addEmbeddedResource("sw360:releases", halRelease); | ||
} | ||
|
||
public void addEmbeddedReleaseLink(HalResource halResource, ReleaseLink releaseLink) { | ||
HalResource<ReleaseLink> halRelease = new HalResource<>(releaseLink); | ||
halResource.addEmbeddedResource("sw360:releaseLinks", halRelease); | ||
} | ||
|
||
public void addEmbeddedAttachments( | ||
HalResource halResource, | ||
Set<Attachment> attachments) { | ||
|
@@ -652,9 +735,10 @@ public Obligation convertToEmbeddedObligation(Obligation obligation) { | |
} | ||
|
||
public Vendor convertToEmbeddedVendor(Vendor vendor) { | ||
Vendor embeddedVendor = convertToEmbeddedVendor(vendor.getFullname()); | ||
Vendor embeddedVendor = new Vendor(); | ||
embeddedVendor.setId(vendor.getId()); | ||
embeddedVendor.setShortname(vendor.getShortname()); | ||
embeddedVendor.setFullname(vendor.getFullname()); | ||
embeddedVendor.setUrl(vendor.getUrl()); | ||
return embeddedVendor; | ||
} | ||
|
@@ -988,6 +1072,7 @@ public void addEmbeddedModerationRequest(HalResource halResource, ModerationRequ | |
public void addEmbeddedDataToComponent(HalResource halResource, Component sw360Component) { | ||
addEmbeddedModifiedByToComponent(halResource,sw360Component); | ||
addEmbeddedComponentOwnerToComponent(halResource,sw360Component); | ||
addEmbeddedSubcribeToHalResourceComponent(halResource,sw360Component); | ||
} | ||
|
||
public void addEmbeddedModifiedByToComponent(HalResource halResource, Component sw360Component) { | ||
|
@@ -1007,4 +1092,18 @@ public void addEmbeddedComponentOwnerToComponent(HalResource halResource, Compon | |
} | ||
} | ||
} | ||
|
||
public void addEmbeddedSubcribeToHalResourceComponent(HalResource halResource, Component sw360Component) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has nothing to do with this PR, right? you just added for future use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because PR(#1983) was merged before, to avoid duplicate PR I added it to this same PR. |
||
if (!CommonUtils.isNullOrEmptyCollection(sw360Component.getSubscribers())) { | ||
Set<String> subscribers = sw360Component.getSubscribers(); | ||
for (String subscribersEmail : subscribers) { | ||
User sw360User = getUserByEmail(subscribersEmail); | ||
if (null != sw360User) { | ||
addEmbeddedUser(halResource, sw360User, "sw360:subscribers"); | ||
sw360Component.setSubscribers(null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you removed these 5 fields, as I'm not able to see any of these fields in response structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. I updated response structure.