Search in sources :

Example 11 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class ProjectHandler method getLinkedProjectsById.

@Override
public List<ProjectLink> getLinkedProjectsById(String id, boolean deep, User user) throws TException {
    assertId(id);
    Project project = getProjectById(id, user);
    return getLinkedProjectsOfProject(project, deep, user);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 12 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink 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)

Example 13 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class ProjectPortlet method prepareSourceCodeBundle.

private void prepareSourceCodeBundle(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(PortalConstants.SW360_USER, user);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    request.setAttribute(PROJECT_LINK_TABLE_MODE, PROJECT_LINK_TABLE_MODE_SOURCE_BUNDLE);
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            request.setAttribute(PROJECT, project);
            request.setAttribute(DOCUMENT_ID, id);
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, filterAndSortAttachments(SW360Constants.SOURCE_CODE_ATTACHMENT_TYPES), true, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            addProjectBreadcrumb(request, response, project);
        } catch (TException e) {
            log.error("Error fetching project from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
        }
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 14 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class ProjectPortlet method serveNewTableRowLinkedProjects.

private void serveNewTableRowLinkedProjects(ResourceRequest request, ResourceResponse response, String[] linkedIds) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<ProjectLink> linkedProjects = new ArrayList<>();
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        for (String linkedId : linkedIds) {
            Project project = client.getProjectById(linkedId, user);
            ProjectLink linkedProject = new ProjectLink(linkedId, project.getName());
            linkedProject.setRelation(ProjectRelationship.CONTAINED);
            linkedProject.setVersion(project.getVersion());
            linkedProjects.add(linkedProject);
        }
    } catch (TException e) {
        log.error("Error getting projects!", e);
        throw new PortletException("cannot get projects " + Arrays.toString(linkedIds), e);
    }
    request.setAttribute(PROJECT_LIST, linkedProjects);
    include("/html/projects/ajax/linkedProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Aggregations

TException (org.apache.thrift.TException)7 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)7 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)6 User (org.eclipse.sw360.datahandler.thrift.users.User)5 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)4 ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)3 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)2 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 com.google.common.collect (com.google.common.collect)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONException (com.liferay.portal.kernel.json.JSONException)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1