Search in sources :

Example 1 with ReleaseLink

use of org.eclipse.sw360.datahandler.thrift.components.ReleaseLink in project sw360portal by sw360.

the class ProjectDatabaseHandler method createProjectLink.

private Optional<ProjectLink> createProjectLink(String id, ProjectRelationship relationship, String parentNodeId, Deque<String> visitedIds, Map<String, Project> projectMap, Map<String, Release> releaseMap, int maxDepth) {
    ProjectLink projectLink = null;
    if (!visitedIds.contains(id) && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
        visitedIds.push(id);
        Project project = projectMap.get(id);
        if (project != null) {
            projectLink = new ProjectLink(id, project.name);
            if (project.isSetReleaseIdToUsage() && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
                // ProjectLink on the last level does not get children added
                List<ReleaseLink> linkedReleases = componentDatabaseHandler.getLinkedReleases(project, releaseMap, visitedIds);
                fillMainlineStates(linkedReleases, project.getReleaseIdToUsage());
                projectLink.setLinkedReleases(nullToEmptyList(linkedReleases));
            }
            projectLink.setNodeId(generateNodeId(id)).setParentNodeId(parentNodeId).setRelation(relationship).setVersion(project.getVersion()).setState(project.getState()).setProjectType(project.getProjectType()).setClearingState(project.getClearingState()).setTreeLevel(visitedIds.size() - 1);
            if (project.isSetLinkedProjects()) {
                List<ProjectLink> subprojectLinks = iterateProjectRelationShips(project.getLinkedProjects(), projectLink.getNodeId(), visitedIds, projectMap, releaseMap, maxDepth);
                projectLink.setSubprojects(subprojectLinks);
            }
        } else {
            log.error("Broken ProjectLink in project with id: " + parentNodeId + ". Linked project with id " + id + " was not in the project cache");
        }
        visitedIds.pop();
    }
    return Optional.ofNullable(projectLink);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)

Example 2 with ReleaseLink

use of org.eclipse.sw360.datahandler.thrift.components.ReleaseLink in project sw360portal by sw360.

the class ProjectPortletUtils method extractContainedAttachments.

/**
 * Walks through a list of project links and extracts all release attachments
 * with their owner. The returned map is a mapping from a release to its
 * attachment content ids.
 *
 * @param projectLinks
 *            list of project links to walk through
 *
 * @return map of releases and their attachment content ids
 */
public static Map<Source, Set<String>> extractContainedAttachments(Collection<ProjectLink> projectLinks) {
    Map<Source, Set<String>> attachments = Maps.newHashMap();
    for (ProjectLink projectLink : projectLinks) {
        for (ReleaseLink releaseLink : projectLink.linkedReleases) {
            Set<String> attachmentIds = attachments.getOrDefault(Source.releaseId(releaseLink.getId()), Sets.newHashSet());
            attachmentIds.addAll(releaseLink.getAttachments().stream().map(a -> a.getAttachmentContentId()).collect(Collectors.toList()));
            attachments.put(Source.releaseId(releaseLink.getId()), attachmentIds);
        }
    }
    return attachments;
}
Also used : ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)

Example 3 with ReleaseLink

use of org.eclipse.sw360.datahandler.thrift.components.ReleaseLink in project sw360portal by sw360.

the class ComponentPortlet method serveNewTableRowLinkedRelease.

private void serveNewTableRowLinkedRelease(ResourceRequest request, ResourceResponse response, String[] linkedIds) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<ReleaseLink> linkedReleases = new ArrayList<>();
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        for (Release release : client.getReleasesById(new HashSet<>(Arrays.asList(linkedIds)), user)) {
            final Vendor vendor = release.getVendor();
            final String vendorName = vendor != null ? vendor.getShortname() : "";
            ReleaseLink linkedRelease = new ReleaseLink(release.getId(), vendorName, release.getName(), release.getVersion(), SW360Utils.printFullname(release), !nullToEmptyMap(release.getReleaseIdToRelationship()).isEmpty());
            linkedRelease.setReleaseRelationship(ReleaseRelationship.CONTAINED);
            linkedReleases.add(linkedRelease);
        }
    } catch (TException e) {
        log.error("Error getting releases!", e);
        throw new PortletException("cannot get releases " + Arrays.toString(linkedIds), e);
    }
    request.setAttribute(RELEASE_LIST, linkedReleases);
    include("/html/utils/ajax/linkedReleasesRelationAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 4 with ReleaseLink

use of org.eclipse.sw360.datahandler.thrift.components.ReleaseLink in project sw360portal by sw360.

the class AttachmentController method createHalAttachment.

private HalResource<Attachment> createHalAttachment(Attachment sw360Attachment, Release sw360Release, User sw360User) {
    HalResource<Attachment> halAttachment = new HalResource<>(sw360Attachment);
    String componentUUID = sw360Attachment.getAttachmentContentId();
    Link releaseLink = linkTo(AttachmentController.class).slash("api/releases/" + sw360Release.getId()).withRel("release");
    halAttachment.add(releaseLink);
    restControllerHelper.addEmbeddedRelease(halAttachment, sw360Release);
    restControllerHelper.addEmbeddedUser(halAttachment, sw360User, "createdBy");
    return halAttachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Link(org.springframework.hateoas.Link)

Example 5 with ReleaseLink

use of org.eclipse.sw360.datahandler.thrift.components.ReleaseLink in project sw360portal by sw360.

the class ProjectDatabaseHandlerTest method testGetLinkedProjects.

@Test
public void testGetLinkedProjects() throws Exception {
    // we wrap the potentially infinite loop in an executor
    final ExecutorService service = Executors.newSingleThreadExecutor();
    Project project = handler.getProjectById("P1", user);
    final Future<List<ProjectLink>> completionFuture = service.submit(() -> handler.getLinkedProjects(project, true, user));
    service.shutdown();
    service.awaitTermination(10, TimeUnit.SECONDS);
    final List<ProjectLink> linkedProjects = completionFuture.get();
    ReleaseLink releaseLinkR1A = new ReleaseLink("R1A", "vendor", "component1", "releaseA", "vendor component1 releaseA", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R1A").setComponentType(ComponentType.OSS);
    ReleaseLink releaseLinkR1B = new ReleaseLink("R1B", "vendor", "component1", "releaseB", "vendor component1 releaseB", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R1B").setComponentType(ComponentType.OSS);
    ReleaseLink releaseLinkR2A = new ReleaseLink("R2A", "vendor", "component2", "releaseA", "vendor component2 releaseA", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R2A").setComponentType(ComponentType.COTS);
    ReleaseLink releaseLinkR2B = new ReleaseLink("R2B", "vendor", "component2", "releaseB", "vendor component2 releaseB", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R2B").setComponentType(ComponentType.COTS);
    ProjectLink link3 = new ProjectLink("P3", "project3").setRelation(ProjectRelationship.REFERRED).setNodeId("P3").setParentNodeId("P2").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(2).setLinkedReleases(Arrays.asList(releaseLinkR2A, releaseLinkR2B)).setSubprojects(Collections.emptyList());
    ProjectLink link4 = new ProjectLink("P4", "project4").setRelation(ProjectRelationship.CONTAINED).setNodeId("P4").setParentNodeId("P2").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(2).setSubprojects(Collections.emptyList());
    ProjectLink link2 = new ProjectLink("P2", "project2").setRelation(ProjectRelationship.CONTAINED).setNodeId("P2").setParentNodeId("P1").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(1).setLinkedReleases(Arrays.asList(releaseLinkR1A, releaseLinkR1B)).setSubprojects(Arrays.asList(link3, link4));
    ProjectLink link1 = new ProjectLink("P1", "project1").setRelation(ProjectRelationship.UNKNOWN).setNodeId("P1").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(0).setSubprojects(Arrays.asList(link2));
    stripRandomPartsOfNodeIds(linkedProjects);
    assertThat(linkedProjects, contains(link1));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink) Test(org.junit.Test)

Aggregations

ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)3 TException (org.apache.thrift.TException)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)2 Link (org.springframework.hateoas.Link)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 ProjectReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship)1 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)1 ProjectController (org.eclipse.sw360.rest.resourceserver.project.ProjectController)1 Test (org.junit.Test)1