Skip to content

Commit

Permalink
Merge pull request #1963 from toshiba/release/feat_add-configuration-…
Browse files Browse the repository at this point in the history
…dependency-network

feat(Project): New configuration make project and releases relationship more flexible for dependencies

Reviewed by: smruti.sahoo@siemens.com, mishra.gaurav@siemens.com, anupam.ghosh@siemens.com
Tested by: anupam.ghosh@siemens.com
  • Loading branch information
ag4ums authored Aug 3, 2023
2 parents ea1236e + d25d35c commit 5f7c87a
Show file tree
Hide file tree
Showing 44 changed files with 4,953 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ public Set<T> getFullDocsById(Set<String> docIds) {
}
return docs;
}

public List<T> getFullDocsByListIds(SummaryType type, Collection<String> ids) {
if (ids == null) {
return Collections.emptyList();
}

List<T> documents = getDocsByListIds(ids);

return makeSummaryFromFullDocs(type, documents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2969,4 +2969,45 @@ public ByteBuffer getComponentReportDataStream(User user, boolean extendedByRele
throw new SW360Exception(e.getMessage());
}
}

public List<Release> getReleaseByIds(List<String> ids) {
return releaseRepository.getFullDocsByListIds(SummaryType.SHORT, ids);
}

public List<ReleaseNode> getReleaseRelationNetworkOfRelease(Release release, User user) {
ReleaseNode dependencyNetwork = new ReleaseNode(release.getId());
getReleaseNodes(dependencyNetwork, user);
return Collections.singletonList(dependencyNetwork);
}

private ReleaseNode getReleaseNodes(ReleaseNode releaseNode, User user) {
Release releaseById = null;
try {
releaseById = getAccessibleRelease(releaseNode.getReleaseId(), user);
List<Release> releaseList = new ArrayList<>();
if (releaseById.getReleaseIdToRelationship() != null) {
releaseList = getAccessibleReleases(releaseById.getReleaseIdToRelationship().keySet(), user);
}
List<ReleaseNode> linkedReleasesJSON = new ArrayList<>();
releaseNode.setMainlineState(MainlineState.OPEN.toString());
releaseNode.setReleaseRelationship(ReleaseRelationship.CONTAINED.toString());
releaseNode.setCreateOn(SW360Utils.getCreatedOn());
releaseNode.setCreateBy(user.getEmail());
releaseNode.setComment("");
for (Release release : releaseList) {
ReleaseNode node = new ReleaseNode(release.getId());
node.setMainlineState(MainlineState.OPEN.toString());
node.setReleaseRelationship(ReleaseRelationship.CONTAINED.toString());
node.setComment("");
node.setCreateOn(SW360Utils.getCreatedOn());
node.setCreateBy(user.getEmail());
linkedReleasesJSON.add(getReleaseNodes(node, user));
}
releaseNode.setReleaseLink(linkedReleasesJSON);

} catch (TException e) {
log.error("Error when get Release: " + releaseNode.getReleaseId());
}
return releaseNode;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Collections;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static org.eclipse.sw360.datahandler.couchdb.lucene.LuceneAwareDatabaseConnector.prepareWildcardQuery;

Expand Down Expand Up @@ -75,6 +79,9 @@ public class ProjectSearchHandler {
" for(var [key, value] in doc.additionalData) {" +
" ret.add(doc.additionalData[key], {\"field\": \"additionalData\"} );" +
" }" +
" if(doc.releaseRelationNetwork !== undefined && doc.releaseRelationNetwork != null && doc.releaseRelationNetwork.length > 0) { "+
" ret.add(doc.releaseRelationNetwork, {\"field\": \"releaseRelationNetwork\"} );" +
" }" +
" return ret;" +
"}");

Expand All @@ -95,4 +102,34 @@ public List<Project> search(String searchText) {
return connector.searchView(Project.class, luceneSearchView, prepareWildcardQuery(searchText));
}

public List<Project> search(String text, final Map<String , Set<String>> subQueryRestrictions) {
return connector.searchViewWithRestrictions(Project.class, luceneSearchView, text, subQueryRestrictions);
}

public Set<Project> searchByReleaseId(String id, User user) {
return searchByReleaseIds(Collections.singleton(id), user);
}

public Set<Project> searchByReleaseIds(Set<String> ids, User user) {
Map<String, Set<String>> filterMap = getFilterMapForSetReleaseIds(ids);
List<Project> projectsByReleaseIds;
if (user != null) {
projectsByReleaseIds = connector.searchProjectViewWithRestrictionsAndFilter(luceneSearchView, null, filterMap, user);
} else {
projectsByReleaseIds = connector.searchViewWithRestrictions(Project.class, luceneSearchView, null, filterMap);
}
return new HashSet<>(projectsByReleaseIds);
}

private static Map<String, Set<String>> getFilterMapForSetReleaseIds(Set<String> releaseIds) {
Map<String, Set<String>> filterMap = new HashMap<>();
Set<String> values = new HashSet<>();
for(String releaseId : releaseIds) {
values.add("\"releaseId\":\"" + releaseId + "\"");
values.add("\"releaseId\": \"" + releaseId + "\"");
}
values = values.stream().map(LuceneAwareDatabaseConnector::prepareWildcardQuery).collect(Collectors.toSet());
filterMap.put(Project._Fields.RELEASE_RELATION_NETWORK.getFieldName(), values);
return filterMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseNode;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
import org.ektorp.http.HttpClient;

import com.cloudant.client.api.CloudantClient;
Expand Down Expand Up @@ -733,4 +735,21 @@ public ByteBuffer getComponentReportDataStream(User user, boolean extendedByRele
public String getComponentReportInEmail(User user, boolean extendedByReleases) throws TException {
return handler.getComponentReportInEmail(user,extendedByReleases);
}

@Override
public boolean isReleaseActionAllowed(Release release, User user, RequestedAction action) {
return handler.isReleaseActionAllowed(release, user, action);
}

@Override
public List<Release> getReleasesByListIds(List<String> ids, User user) throws TException {
assertUser(user);
assertNotNull(ids);
return handler.getReleaseByIds(ids);
}

@Override
public List<ReleaseNode> getReleaseRelationNetworkOfRelease(Release release, User user) {
return handler.getReleaseRelationNetworkOfRelease(release, user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;
import org.eclipse.sw360.datahandler.common.SW360Constants;
import org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler;
import org.eclipse.sw360.datahandler.db.ProjectSearchHandler;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
Expand All @@ -30,6 +31,7 @@
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
Expand Down Expand Up @@ -154,11 +156,17 @@ public ProjectData searchByType(String type, User user) throws SW360Exception {

@Override
public Set<Project> searchByReleaseId(String id, User user) throws TException {
if (SW360Constants.ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP) {
return searchHandler.searchByReleaseId(id, user);
}
return handler.searchByReleaseId(id, user);
}

@Override
public Set<Project> searchByReleaseIds(Set<String> ids, User user) throws TException {
if (SW360Constants.ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP) {
return searchHandler.searchByReleaseIds(ids, user);
}
return handler.searchByReleaseId(ids, user);
}

Expand Down Expand Up @@ -524,4 +532,34 @@ public String getReportInEmail(User user, boolean extendedByReleases)
throws TException {
return handler.getReportInEmail(user, extendedByReleases);
}

@Override
public List<ReleaseLink> getReleaseLinksOfProjectNetWorkByTrace(String projectId, List<String> trace, User user) throws TException {
return handler.getReleaseLinksOfProjectNetWorkByTrace(trace, projectId, user);
}

@Override
public List<Map<String, String>> getAccessibleDependencyNetworkForListView(String projectId, User user) throws SW360Exception {
assertNotNull(projectId);
return handler.getClearingStateForDependencyNetworkListView(projectId, user, true);
}

@Override
public List<Project> refineSearchWithoutUser(String text, Map<String, Set<String>> subQueryRestrictions) {
return searchHandler.search(text, subQueryRestrictions);
}

@Override
public List<ProjectLink> getLinkedProjectsWithoutReleases(Map<String, ProjectProjectRelationship> relations, boolean depth, User user) throws TException {
assertNotNull(relations);
assertUser(user);

return handler.getLinkedProjectsWithoutReleases(relations, depth, user);
}

@Override
public List<ProjectLink> getLinkedProjectsOfProjectWithoutReleases(Project project, boolean deep, User user) throws TException {
assertNotNull(project);
return handler.getLinkedProjectsWithoutReleases(project, deep, user);
}
}
4 changes: 3 additions & 1 deletion frontend/sw360-portlet/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ Import-Package: \
com.cloudant.*, \
org.osgi.service.cm, \
org.osgi.service.component.*, \
org.slf4j
org.slf4j, \
com.fasterxml.jackson.core.*,\
com.google.gson.*

Conditional-Package: \
org.apache.http.*, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,39 @@ public class PortalConstants {
public static final String ACTUAL_PACKAGE_INFO = "actual_PackageInfo";
public static final Set<String> SET_RELATIONSHIP_TYPE;

//! Specialized keys for Flexible project and releases relationship configuration
public static final String RELEASE_ID_ARRAY = "releaseIdArray[]";
public static final String RELEASES_WITH_SAME_COMPONENT_ID = "releaseWithSameComponentId";
public static final String CURRENT_NETWORK = "currentNetwork";
public static final String CHECK_DIFF_DEPENDENCY_NETWORK_WITH_RELEASES_RELATIONSHIP = "checkDiffDependencyNetworkWithReleasesRelationship";
public static final String RESTRICTED_RELEASE = "Restricted release";
public static final String GET_HTML_RELEASE_ROWS = "getHtmlReleaseRows";
public static final String DEFAULT_RELEASE_RELATION_NETWORK = "[]";
public static final String ATTACHMENT_USAGE_ON_CLICK = "attachmentUsageOnClick";
public static final String SUB_PROJECTS_LINK_TRANSITIVE = "subProjectsLinkTransitive";
public static final String LOGIN_USER = "loginUser";
public static final String IS_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP_ENABLED = "isFlexibleProjectReleaseRelationshipEnabled";
public static final String NETWORK_PARENT_BRANCH_ID = "networkParentBranchId";
public static final String NETWORK_RELEASE_LIST = "networkReleaseList";
public static final String NETWORK_TOTAL_INACCESSIBLE_ROWS = "netWorkTotalInAccessibleRow";
public static final String DEPENDENCY_NETWORK_LIST = "dependencyNetworkList";
public static final String DEPENDENCY_NETWORK_ON_LOAD = "dependencyNetworkOnLoad";
public static final String IS_OBLIGATION_PRESENT = "isObligationPresent";
public static final String CREATE_LINKED_RELEASE_ROW = "createLinkedReleaseRow";
public static final String PARENT_NODE_ID = "parentNodeIds[]";
public static final String LAYER = "layer[]";
public static final String RELEASE_RELATION_SHIP = "releaseRelationShip[]";
public static final String MAINLINE_STATE = "mainlineState[]";
public static final String INDEXES = "indexes[]";
public static final String COMMENTS = "comments[]";
public static final String FIND_LINKED_RELEASE_OF_NODE = "findLinkedReleaseOfNode";
public static final String RELEASES_IN_NETWORK = "releasesInNetwork";
public static final String NUMBER_LINKED_RELEASE = "numberLinkedRelease";
public static final String TOTAL_RELEASE_COUNT = "totalReleaseCount";
public static final String CHECK_RELEASE_EXIST = "checkReleaseExist";
public static final String RELEASE_USAGE = "releaseUsage";
public static final String CYCLIC_LINKED_RELEASE_PATH = "cyclicLinkedReleasePath";
public static final String CHILD_RELEASE_ID_ARRAY = "childReleaseId[]";
static {
Properties props = CommonUtils.loadProperties(PortalConstants.class, PROPERTIES_FILE_PATH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -102,9 +104,19 @@ protected void dealWithLinkedObjects(ResourceRequest request, ResourceResponse r
if (PortalConstants.LOAD_LINKED_PROJECTS_ROWS.equals(action)) {
boolean overrideToRelease = Boolean.parseBoolean(request.getParameter("overrideToRelease"));
if (overrideToRelease) {
loadLinkedReleasesRows(request, response);
include("/html/utils/ajax/linkedReleasesClearingStatusRows.jsp", request, response,
PortletRequest.RESOURCE_PHASE);
if (!SW360Constants.ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP) {
loadLinkedReleasesRows(request, response);
include("/html/utils/ajax/linkedReleasesClearingStatusRows.jsp", request, response,
PortletRequest.RESOURCE_PHASE);
} else {
try {
loadLinkedReleaseOfProject(request);
include("/html/utils/ajax/linkedReleaseInNetworkRows.jsp", request, response,
PortletRequest.RESOURCE_PHASE);
} catch (TException e) {
log.error("Error when create new release row for tree view");
}
}
return;
}
serveLoadLinkedProjectsRows(request, response);
Expand Down Expand Up @@ -227,7 +239,12 @@ protected List<ProjectLink> createLinkedProjects(Project project,
}

protected void putDirectlyLinkedProjectsInRequest(PortletRequest request, Project project, User user) {
final Collection<ProjectLink> linkedProjects = SW360Utils.getLinkedProjects(project, false, thriftClients, log, user);
Collection<ProjectLink> linkedProjects;
if (!SW360Constants.ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP) {
linkedProjects = SW360Utils.getLinkedProjects(project, false, thriftClients, log, user);
} else {
linkedProjects = SW360Utils.getLinkedProjectWithoutReleases(project, false, thriftClients, log, user);
}
List<ProjectLink> secondLevelLinks = linkedProjects
.stream()
.map(ProjectLink::getSubprojects)
Expand All @@ -250,8 +267,13 @@ public Function<ProjectLink, ProjectLink> createProjectLinkMapper(Function<Relea
}

protected void serveLoadLinkedProjectsRows(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
prepareLinkedProjects(request);
include("/html/utils/ajax/linkedProjectsRows.jsp", request, response, PortletRequest.RESOURCE_PHASE);
if (!SW360Constants.ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP) {
prepareLinkedProjects(request);
include("/html/utils/ajax/linkedProjectsRows.jsp", request, response, PortletRequest.RESOURCE_PHASE);
} else {
prepareLinkedProjectDependencyNetwork(request);
include("/html/utils/ajax/linkedProjectRowsDependencyNetwork.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
}

protected void prepareLinkedProjects(ResourceRequest request) throws PortletException {
Expand Down Expand Up @@ -350,4 +372,60 @@ public Map<String, String> fillMainLineState(Set<String> releaseIds, ComponentSe
}));
return relMainLineState;
}

protected void loadLinkedReleaseOfProject(ResourceRequest request) throws TException {
String projectId = request.getParameter("projectId");
String[] trace = request.getParameterValues("trace[]");
String branchId = request.getParameter(PortalConstants.NETWORK_PARENT_BRANCH_ID);
final User user = UserCacheHolder.getUserFromRequest(request);
try {
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
List<ReleaseLink> linkedReleases = projectClient.getReleaseLinksOfProjectNetWorkByTrace(projectId, Arrays.asList(trace), user);
request.setAttribute(PortalConstants.NETWORK_PARENT_BRANCH_ID, branchId);
request.setAttribute(PortalConstants.PARENT_SCOPE_GROUP_ID, request.getParameter(PortalConstants.PARENT_SCOPE_GROUP_ID));
request.setAttribute(PortalConstants.NETWORK_RELEASE_LIST, linkedReleases);
int totalInaccessibleRow = 0;
for (ReleaseLink link : linkedReleases) {
if (!link.isAccessible()) {
totalInaccessibleRow++;
}
}
request.setAttribute(PortalConstants.NETWORK_TOTAL_INACCESSIBLE_ROWS, totalInaccessibleRow);
} catch (TException e) {
log.error("Error getting releases!", e);
request.setAttribute(PortalConstants.NETWORK_PARENT_BRANCH_ID, branchId);
request.setAttribute(PortalConstants.PARENT_SCOPE_GROUP_ID, request.getParameter(PortalConstants.PARENT_SCOPE_GROUP_ID));
request.setAttribute(PortalConstants.NETWORK_RELEASE_LIST, Collections.emptyList());
request.setAttribute(PortalConstants.NETWORK_TOTAL_INACCESSIBLE_ROWS, 0);
}
}

protected void prepareLinkedProjectDependencyNetwork(ResourceRequest request) throws PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
String branchId = request.getParameter(PortalConstants.NETWORK_PARENT_BRANCH_ID);
Optional<String> projectIdOpt = getProjectIdFromBranchId(branchId);
request.setAttribute(PortalConstants.NETWORK_PARENT_BRANCH_ID, branchId);
final Project project;
if (projectIdOpt.isPresent()) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
project = client.getProjectById(projectIdOpt.get(), user);
} catch (TException e) {
log.error("Error getting projects!", e);
throw new PortletException("cannot load project " + projectIdOpt.get(), e);
}
String parentProjectPath = request.getParameter(PortalConstants.PARENT_PROJECT_PATH);
if (parentProjectPath != null) {
request.setAttribute(PortalConstants.PARENT_PROJECT_PATH,
parentProjectPath.concat(":").concat(projectIdOpt.get()));
}
} else {
project = new Project();
}
List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);

mappedProjectLinks = sortProjectLink(mappedProjectLinks);
request.setAttribute(PROJECT_LIST, mappedProjectLinks);
request.setAttribute(PortalConstants.PARENT_SCOPE_GROUP_ID, request.getParameter(PortalConstants.PARENT_SCOPE_GROUP_ID));
}
}
Loading

0 comments on commit 5f7c87a

Please sign in to comment.