Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public List<ReleaseLink> convertReleaseToReleaseLink(String id,User user) throws

ClearingReport clearingReport = new ClearingReport();
Set<Attachment> attachments = getAttachmentForClearingReport(release);
if (attachments.size() != 0 ) {
if (!attachments.equals(Collections.emptySet())) {
Set<Attachment> attachmentsAccepted = getAttachmentsStatusAccept(attachments);
if(attachmentsAccepted.size() != 0) {
clearingReport.setClearingReportStatus(ClearingReportStatus.DOWNLOAD);
Expand All @@ -217,6 +217,8 @@ public List<ReleaseLink> convertReleaseToReleaseLink(String id,User user) throws

private Set<Attachment> getAttachmentForClearingReport(Release release){
final Set<Attachment> attachments = release.getAttachments();
if (CommonUtils.isNullOrEmptyCollection(attachments))
return Collections.emptySet();
return attachments.stream().filter(attachment -> AttachmentType.COMPONENT_LICENSE_INFO_XML.equals(attachment.getAttachmentType()) ||
AttachmentType.CLEARING_REPORT.equals(attachment.getAttachmentType()))
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ static abstract class ComponentMixin extends Component {
"revision",
"permissions",
"moderators",
"subscribers",
"contributors",
"clearingInformation",
"setAttachments",
"setCreatedOn",
Expand Down Expand Up @@ -471,7 +473,6 @@ static abstract class ComponentMixin extends Component {
"otherLicenseIdsSize",
"setOtherLicenseIds",
"setModifiedOn",
"modifiedOn",
"setModifiedBy",
"modifiedBy",
"setComponentType"
Expand All @@ -488,18 +489,12 @@ static abstract class ReleaseMixin extends Release {

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({
"vendor",
"longName",
"releaseRelationship",
"hasSubreleases",
"nodeId",
"parentNodeId",
"componentType",
"licenseIds",
"licenseNames",
"comment",
"otherLicenseIds",
"accessible",
"attachmentsSize",
"setName",
"setVersion",
Expand Down Expand Up @@ -997,11 +992,6 @@ public static abstract class VulnerabilityApiDTOMixin extends VulnerabilityApiDT

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties({
"assessorContactPerson",
Copy link
Contributor

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.

Copy link
Contributor Author

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.

"assessorDepartment",
"eccComment",
"materialIndexNumber",
"assessmentDate",
"setEccComment",
"setEccn",
"setEccStatus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -1007,4 +1092,18 @@ public void addEmbeddedComponentOwnerToComponent(HalResource halResource, Compon
}
}
}

public void addEmbeddedSubcribeToHalResourceComponent(HalResource halResource, Component sw360Component) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentDTO;
import org.eclipse.sw360.datahandler.thrift.attachments.UsageAttachment;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.components.Component;
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcess;
Expand Down Expand Up @@ -173,13 +174,10 @@ public ResponseEntity<EntityModel> getRelease(
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
Release sw360Release = releaseService.getReleaseForUserById(id, sw360User);
HalResource halRelease = createHalReleaseResource(sw360Release, true);
Map<String, ReleaseRelationship> releaseIdToRelationship = sw360Release.getReleaseIdToRelationship();
if (releaseIdToRelationship != null) {
List<Release> listOfLinkedRelease = releaseIdToRelationship.keySet().stream()
.map(linkedReleaseId -> wrapTException(
() -> releaseService.getReleaseForUserById(linkedReleaseId, sw360User)))
.collect(Collectors.toList());
restControllerHelper.addEmbeddedReleases(halRelease, listOfLinkedRelease);
restControllerHelper.addEmbeddedDataToHalResourceRelease(halRelease, sw360Release);
List<ReleaseLink> linkedReleaseRelations = releaseService.getLinkedReleaseRelations(sw360Release, sw360User);
if (linkedReleaseRelations != null) {
restControllerHelper.addEmbeddedReleaseLinks(halRelease, linkedReleaseRelations);
}
return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
Expand Down Expand Up @@ -607,7 +605,7 @@ private HalResource<Release> createHalReleaseResource(Release release, boolean v
}
if (release.getVendor() != null) {
Vendor vendor = release.getVendor();
HalResource<Vendor> vendorHalResource = restControllerHelper.addEmbeddedVendor(vendor.getFullname());
HalResource<Vendor> vendorHalResource = restControllerHelper.addEmbeddedVendor(vendor);
halRelease.addEmbeddedResource("sw360:vendors", vendorHalResource);
release.setVendor(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType;
import org.eclipse.sw360.datahandler.thrift.components.Component;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.ComponentType;
import org.eclipse.sw360.datahandler.thrift.components.ExternalTool;
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcess;
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcessStatus;
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcessStep;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.fossology.FossologyService;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.users.User;
Expand All @@ -57,16 +51,13 @@
import org.springframework.util.FileCopyUtils;

import static org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace;
import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString;
import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
Expand Down Expand Up @@ -118,6 +109,22 @@ public Release getReleaseForUserById(String releaseId, User sw360User) throws TE
return releaseById;
}

public List<ReleaseLink> getLinkedReleaseRelations(Release release, User user) throws TException {
List<ReleaseLink> linkedReleaseRelations = getLinkedReleaseRelationsWithAccessibility(release, user);
linkedReleaseRelations = linkedReleaseRelations.stream().filter(Objects::nonNull).sorted(Comparator.comparing(
rl -> rl.isAccessible() ? SW360Utils.getVersionedName(nullToEmptyString(rl.getName()), rl.getVersion()) : "~", String.CASE_INSENSITIVE_ORDER)
).collect(Collectors.toList());
return linkedReleaseRelations;
}

public List<ReleaseLink> getLinkedReleaseRelationsWithAccessibility(Release release, User user) throws TException {
if (release != null && release.getReleaseIdToRelationship() != null) {
ComponentService.Iface componentClient = getThriftComponentClient();
return componentClient.getLinkedReleaseRelationsWithAccessibility(release.getReleaseIdToRelationship(), user);
}
return Collections.emptyList();
}

public Release setComponentDependentFieldsInRelease(Release releaseById, User sw360User) {
String componentId = releaseById.getComponentId();
if (CommonUtils.isNullEmptyOrWhitespace(componentId)) {
Expand Down
Loading