Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
dev(components): hide inaccessible projects in component summary
Browse files Browse the repository at this point in the history
- hide inaccessible projects in the "is used by the following" section
- add usage count of linked projects
  • Loading branch information
maierthomas committed Apr 5, 2018
1 parent 243ebc6 commit 0454cbd
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2014-2017. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2014-2018. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
Expand Down Expand Up @@ -31,9 +31,6 @@ protected Project summary(SummaryType type, Project document) {
case LINKED_PROJECT_ACCESSIBLE:
setFieldsForAccessibleLinkedProject(document,copy);
break;
case LINKED_PROJECT_NOT_ACCESSIBLE:
setFieldsForUnAccessibleLinkedProject(document,copy);
break;
case SUMMARY:
setSummaryFields(document, copy);
break;
Expand Down Expand Up @@ -68,14 +65,4 @@ protected static void setFieldsForAccessibleLinkedProject(Project document, Proj
copyField(document, copy, _Fields.BUSINESS_UNIT);
copyField(document, copy, _Fields.PROJECT_RESPONSIBLE);
}

protected static void setFieldsForUnAccessibleLinkedProject(Project document, Project copy) {
copyField(document, copy, _Fields.ID);
copyField(document, copy, _Fields.NAME);
copyField(document, copy, _Fields.VERSION);
copy.setDescription("");
copy.setClearingTeam("");
copy.setBusinessUnit("");
copy.setProjectResponsible("");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
Expand Down Expand Up @@ -53,6 +53,7 @@
* @author cedric.bodet@tngtech.com
* @author daniele.fognini@tngtech.com
* @author alex.borodin@evosoft.com
* @author thomas.maier@evosoft.com
*/
public class ProjectDatabaseHandler extends AttachmentAwareDatabaseHandler {

Expand Down Expand Up @@ -430,6 +431,14 @@ public List<Project> getProjectsById(List<String> id, User user) {
return output;
}

public int getCountByReleaseIds(Set<String> ids) {
return repository.searchByReleaseId(ids).size();
}

public int getCountByProjectId(String id) {
return repository.searchByLinkingProjectId(id).size();
}

public Set<Project> getAccessibleProjects(User user) {
return repository.getAccessibleProjects(user);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2013-2016. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
Expand All @@ -10,7 +10,6 @@
*/
package org.eclipse.sw360.datahandler.db;

import com.google.common.collect.Sets;
import org.eclipse.sw360.components.summary.ProjectSummary;
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector;
Expand All @@ -21,9 +20,7 @@
import org.ektorp.support.View;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand All @@ -34,6 +31,7 @@
*
* @author cedric.bodet@tngtech.com
* @author Johannes.Najjar@tngtech.com
* @author thomas.maier@evosoft.com
*/
@View(name = "all", map = "function(doc) { if (doc.type == 'project') emit(null, doc._id) }")
public class ProjectRepository extends SummaryAwareRepository<Project> {
Expand Down Expand Up @@ -153,17 +151,14 @@ public List<Project> searchByNameAndVersion(String name, String version) {
return makeSummaryFromFullDocs(SummaryType.SHORT, projectsMatchingNameAndVersion);
}


@View(name = "byreleaseid", map = BY_RELEASE_ID_VIEW)
public Set<Project> searchByReleaseId(String id, User user) {
Set<String> searchIds = queryForIdsAsValue("byreleaseid", id);

return new HashSet<>((makeSummaryFromFullDocs(SummaryType.SHORT, filterAccessibleProjectsByIds(user, searchIds))));
return searchByReleaseId(Collections.singleton(id), user);
}

public Set<Project> searchByReleaseId(Set<String> ids, User user) {
Set<String> searchIds = queryForIdsAsValue("byreleaseid", ids);
return linkedProjectSummaryAccordingToAccessibility(searchIds, user);
return getAccessibleProjectSummary(user, searchIds);
}

@View(name = "fullbyreleaseid", map = FULL_BY_RELEASE_ID_VIEW)
Expand All @@ -175,21 +170,10 @@ public Set<Project> searchByReleaseId(Set<String> ids) {
return new HashSet<>(queryByIds("fullbyreleaseid", ids));
}


@View(name = "bylinkingprojectid", map = BY_LINKING_PROJECT_ID_VIEW)
public Set<Project> searchByLinkingProjectId(String id, User user) {
Set<String> searchIds = queryForIdsByPrefix("bylinkingprojectid", id);
return linkedProjectSummaryAccordingToAccessibility(searchIds, user);
}

private Set<Project> linkedProjectSummaryAccordingToAccessibility(Set<String> ids, User user){
Set<Project> accessibleLinkedProjects = filterAccessibleProjectsByIds(user, ids);
Set<String> accessibleLinkedProjectIds = accessibleLinkedProjects.stream().map(Project::getId).collect(Collectors.toSet());
Set<String> unaccessibleLinkedProjectIds = Sets.difference(ids, accessibleLinkedProjectIds);
List<Project> unaccessibleLinkedProjects = get(unaccessibleLinkedProjectIds);
Set<Project> projectSummary = new HashSet<>((makeSummaryFromFullDocs(SummaryType.LINKED_PROJECT_ACCESSIBLE, accessibleLinkedProjects )));
projectSummary.addAll(makeSummaryFromFullDocs(SummaryType.LINKED_PROJECT_NOT_ACCESSIBLE, unaccessibleLinkedProjects ));
return projectSummary;
return getAccessibleProjectSummary(user, searchIds);
}

@View(name = "fullbylinkingprojectid", map = FULL_BY_LINKING_PROJECT_ID_VIEW)
Expand Down Expand Up @@ -264,4 +248,9 @@ private Set<Project> filterAccessibleProjectsByIds(User user, Set<String> search

return output;
}

private Set<Project> getAccessibleProjectSummary(User user, Set<String> searchIds) {
Set<Project> accessibleProjects = filterAccessibleProjectsByIds(user, searchIds);
return new HashSet<>(makeSummaryFromFullDocs(SummaryType.LINKED_PROJECT_ACCESSIBLE, accessibleProjects));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
Expand Down Expand Up @@ -39,6 +39,7 @@
* @author cedric.bodet@tngtech.com
* @author Johannes.Najjar@tngtech.com
* @author alex.borodin@evosoft.com
* @author thomas.maier@evosoft.com
*/
public class ProjectHandler implements ProjectService.Iface {

Expand Down Expand Up @@ -139,6 +140,18 @@ public Project getProjectByIdForEdit(String id, User user) throws TException {
return project;
}

@Override
public int getCountByReleaseIds(Set<String> ids) throws TException {
assertNotEmpty(ids);
return handler.getCountByReleaseIds(ids);
}

@Override
public int getCountByProjectId(String id) throws TException {
assertNotEmpty(id);
return handler.getCountByProjectId(id);
}

////////////////////////////
// ADD INDIVIDUAL OBJECTS //
////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class PortalConstants {
public static final String USING_PROJECTS = "usingProjects";
public static final String USING_COMPONENTS = "usingComponents";
public static final String USING_RELEASES = "usingReleases";
public static final String ALL_USING_PROJECTS_COUNT = "allUsingProjectsCount";
public static final String PROJECT_LIST = "projectList";
public static final String RELEASE_LIST = "releaseList";
public static final String PROJECT_SEARCH = "projectSearch";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
* With contributions by Bosch Software Innovations GmbH, 2016.
*
* SPDX-License-Identifier: EPL-1.0
Expand Down Expand Up @@ -80,6 +80,7 @@
* @author Johannes.Najjar@tngtech.com
* @author stefan.jaeger@evosoft.com
* @author alex.borodin@evosoft.com
* @author thomas.maier@evosoft.com
*/
public class ComponentPortlet extends FossologyAwarePortlet {

Expand Down Expand Up @@ -760,19 +761,22 @@ private void prepareDetailView(RenderRequest request, RenderResponse response) {
private void setUsingDocs(RenderRequest request, User user, ComponentService.Iface client, Set<String> releaseIds) {
Set<Project> usingProjects = null;
Set<Component> usingComponentsForComponent = null;
int allUsingProjectsCount = 0;

if (releaseIds != null && releaseIds.size() > 0) {
try {
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
usingProjects = projectClient.searchByReleaseIds(releaseIds, user);
allUsingProjectsCount = projectClient.getCountByReleaseIds(releaseIds);
usingComponentsForComponent = client.getUsingComponentsForComponent(releaseIds);
} catch (TException e) {
log.error("Problem filling using docs", e);
}

}

request.setAttribute(USING_PROJECTS, nullToEmptySet(usingProjects));
request.setAttribute(USING_COMPONENTS, nullToEmptySet(usingComponentsForComponent));
request.setAttribute(ALL_USING_PROJECTS_COUNT, allUsingProjectsCount);
}

private void prepareReleaseDetailView(RenderRequest request, RenderResponse response) throws PortletException {
Expand Down Expand Up @@ -914,12 +918,14 @@ private void setUsingDocs(RenderRequest request, String releaseId, User user, Co
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Set<Project> usingProjects = projectClient.searchByReleaseId(releaseId, user);
request.setAttribute(USING_PROJECTS, nullToEmptySet(usingProjects));

int allUsingProjectsCount = projectClient.getCountByReleaseIds(Collections.singleton(releaseId));
request.setAttribute(ALL_USING_PROJECTS_COUNT, allUsingProjectsCount);
final Set<Component> usingComponentsForRelease = client.getUsingComponentsForRelease(releaseId);
request.setAttribute(USING_COMPONENTS, nullToEmptySet(usingComponentsForRelease));
} else {
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(USING_COMPONENTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
}
}

Expand Down Expand Up @@ -1050,6 +1056,7 @@ private void prepareRequestForEditAfterDuplicateError(ActionRequest request, Com
setAttachmentsInRequest(request, component.getAttachments());
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(USING_COMPONENTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
}

@UsedAsLiferayAction
Expand Down Expand Up @@ -1117,6 +1124,7 @@ private void prepareRequestForReleaseEditAfterDuplicateError(ActionRequest reque
putDirectlyLinkedReleaseRelationsInRequest(request, release);
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(USING_COMPONENTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
}

private void fillVendor(Release release) throws TException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ private void prepareDetailView(RenderRequest request, RenderResponse response) t
putDirectlyLinkedReleasesInRequest(request, project);
Set<Project> usingProjects = client.searchLinkingProjects(id, user);
request.setAttribute(USING_PROJECTS, usingProjects);
int allUsingProjectCount = client.getCountByProjectId(id);
request.setAttribute(ALL_USING_PROJECTS_COUNT, allUsingProjectCount);
putReleasesAndProjectIntoRequest(request, id, user);
putVulnerabilitiesInRequest(request, id, user);
request.setAttribute(
Expand Down Expand Up @@ -955,6 +957,7 @@ private void prepareProjectEdit(RenderRequest request) {
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
Project project;
Set<Project> usingProjects;
int allUsingProjectCount = 0;
request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());

if (id != null) {
Expand All @@ -963,6 +966,7 @@ private void prepareProjectEdit(RenderRequest request) {
ProjectService.Iface client = thriftClients.makeProjectClient();
project = client.getProjectByIdForEdit(id, user);
usingProjects = client.searchLinkingProjects(id, user);
allUsingProjectCount = client.getCountByProjectId(id);
} catch (TException e) {
log.error("Something went wrong with fetching the project", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
Expand All @@ -982,6 +986,7 @@ private void prepareProjectEdit(RenderRequest request) {
}

request.setAttribute(USING_PROJECTS, usingProjects);
request.setAttribute(ALL_USING_PROJECTS_COUNT, allUsingProjectCount);
Map<RequestedAction, Boolean> permissions = project.getPermissions();
DocumentState documentState = project.getDocumentState();

Expand All @@ -999,6 +1004,7 @@ private void prepareProjectEdit(RenderRequest request) {
log.error("Could not put empty linked projects or linked releases in projects view.", e);
}
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);

SessionMessages.add(request, "request_processed", "New Project");
}
Expand All @@ -1023,6 +1029,7 @@ private void prepareProjectDuplicate(RenderRequest request) {
putDirectlyLinkedProjectsInRequest(request, newProject, user);
putDirectlyLinkedReleasesInRequest(request, newProject);
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
} else {
Project project = new Project();
project.setBusinessUnit(user.getDepartment());
Expand All @@ -1033,6 +1040,7 @@ private void prepareProjectDuplicate(RenderRequest request) {
putDirectlyLinkedReleasesInRequest(request, project);

request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
}
} catch (TException e) {
log.error("Error fetching project from backend!", e);
Expand Down Expand Up @@ -1099,6 +1107,7 @@ private void prepareRequestForEditAfterDuplicateError(ActionRequest request, Pro
request.setAttribute(PROJECT, project);
setAttachmentsInRequest(request, project.getAttachments());
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%--
~ Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project.
~ Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
~ With modifications by Bosch Software Innovations GmbH, 2016.
~
~ SPDX-License-Identifier: EPL-1.0
Expand Down Expand Up @@ -40,6 +40,7 @@
<jsp:useBean id="selectedTab" class="java.lang.String" scope="request"/>
<jsp:useBean id="usingProjects" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.projects.Project>" scope="request"/>
<jsp:useBean id="usingComponents" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.components.Component>" scope="request"/>
<jsp:useBean id="allUsingProjectsCount" type="java.lang.Integer" scope="request"/>
<jsp:useBean id="documentType" class="java.lang.String" scope="request"/>
<jsp:useBean id="isUserAllowedToMerge" type="java.lang.Boolean" scope="request"/>
<jsp:useBean id="vulnerabilityVerificationEditable" type="java.lang.Boolean" scope="request"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<jsp:useBean id="usingProjects" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.projects.Project>"
scope="request"/>
<jsp:useBean id="usingComponents" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.components.Component>" scope="request"/>
<jsp:useBean id="allUsingProjectsCount" type="java.lang.Integer" scope="request"/>
<core_rt:set var="cotsMode" value="<%=component.componentType == ComponentType.COTS%>"/>
<jsp:useBean id="vulnerabilityVerificationEditable" type="java.lang.Boolean" scope="request"/>
<core_rt:if test="${vulnerabilityVerificationEditable}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%--
~ Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project.
~ Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
~
~ SPDX-License-Identifier: EPL-1.0
~
Expand Down Expand Up @@ -50,7 +50,7 @@

<jsp:useBean id="usingProjects" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.projects.Project>"
scope="request"/>

<jsp:useBean id="allUsingProjectsCount" type="java.lang.Integer" scope="request"/>
<jsp:useBean id="usingComponents" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.components.Component>"
scope="request"/>
</c:catch>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%--
~ Copyright Siemens AG, 2013-2016. Part of the SW360 Portal Project.
~ Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
~
~ SPDX-License-Identifier: EPL-1.0
~
Expand All @@ -26,6 +26,7 @@
<jsp:useBean id="actual_component" class="org.eclipse.sw360.datahandler.thrift.components.Component" scope="request"/>
<jsp:useBean id="selectedTab" class="java.lang.String" scope="request"/>
<jsp:useBean id="usingProjects" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.projects.Project>" scope="request"/>
<jsp:useBean id="allUsingProjectsCount" type="java.lang.Integer" scope="request"/>

<core_rt:set var="component" value="${actual_component}" scope="request"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%--
~ Copyright Siemens AG, 2013-2016. Part of the SW360 Portal Project.
~ Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project.
~
~ SPDX-License-Identifier: EPL-1.0
~
Expand All @@ -20,6 +20,7 @@
<%@ page import="javax.portlet.PortletRequest" %>

<jsp:useBean id="usingProjects" type="java.util.Set<org.eclipse.sw360.datahandler.thrift.projects.Project>" scope="request"/>
<jsp:useBean id="allUsingProjectsCount" type="java.lang.Integer" scope="request"/>
<jsp:useBean id="moderationRequest" class="org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest" scope="request"/>
<jsp:useBean id="selectedTab" class="java.lang.String" scope="request" />
<jsp:useBean id="actual_project" class="org.eclipse.sw360.datahandler.thrift.projects.Project" scope="request" />
Expand Down
Loading

0 comments on commit 0454cbd

Please sign in to comment.