Search in sources :

Example 1 with ProjectLink

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

the class ProjectDatabaseHandlerTest method testGetLinkedProjectsOfProjectForClonedProject.

@Test
public void testGetLinkedProjectsOfProjectForClonedProject() throws Exception {
    Project p = handler.getProjectById("P4", user1);
    Project clone = p.deepCopy();
    clone.unsetId();
    clone.unsetRevision();
    List<ProjectLink> projectLinks = handler.getLinkedProjects(clone, false, user1);
    assertThat(projectLinks.size(), is(1));
    assertThat(projectLinks.get(0).getSubprojects().size(), is(1));
    assertThat(projectLinks.get(0).getLinkedReleases().size(), is(2));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Test(org.junit.Test)

Example 2 with ProjectLink

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

the class ProjectDatabaseHandlerTest method testGetLinkedProjectsOfProject.

@Test
public void testGetLinkedProjectsOfProject() throws Exception {
    Project p = handler.getProjectById("P4", user1);
    List<ProjectLink> projectLinks = handler.getLinkedProjects(p, false, user1);
    assertThat(projectLinks.size(), is(1));
    assertThat(projectLinks.get(0).getSubprojects().size(), is(1));
    assertThat(projectLinks.get(0).getLinkedReleases().size(), is(2));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Test(org.junit.Test)

Example 3 with ProjectLink

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

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

the class RestControllerHelper method addEmbeddedProject.

private void addEmbeddedProject(HalResource halResource, Project project) {
    Project embeddedProject = convertToEmbeddedProject(project);
    HalResource<Project> halProject = new HalResource<>(embeddedProject);
    Link projectLink = linkTo(ProjectController.class).slash("api" + ProjectController.PROJECTS_URL + "/" + project.getId()).withSelfRel();
    halProject.add(projectLink);
    halResource.addEmbeddedResource("sw360:projects", halProject);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Link(org.springframework.hateoas.Link)

Example 5 with ProjectLink

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

the class ProjectPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    request.setAttribute(DOCUMENT_ID, id);
    request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            project = getWithFilledClearingStateSummary(project, user);
            request.setAttribute(PROJECT, project);
            setAttachmentsInRequest(request, project.getAttachments());
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            putDirectlyLinkedReleasesInRequest(request, project);
            Set<Project> usingProjects = client.searchLinkingProjects(id, user);
            request.setAttribute(USING_PROJECTS, usingProjects);
            putReleasesAndProjectIntoRequest(request, id, user);
            putVulnerabilitiesInRequest(request, id, user);
            request.setAttribute(VULNERABILITY_RATINGS_EDITABLE, PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));
            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)

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