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