Skip to content

Commit

Permalink
feat(Project): New configuration make project and releases relationsh…
Browse files Browse the repository at this point in the history
…ip more flexible

Signed-off-by: hoangnt2 <hoang2.nguyenthai@toshiba.co.jp>
  • Loading branch information
hoangnt2 committed Jul 21, 2023
1 parent 50e4f07 commit 5c4f93b
Show file tree
Hide file tree
Showing 44 changed files with 4,936 additions and 92 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 @@ -2886,4 +2886,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().stream().collect(Collectors.toSet()), 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 @@ -15,6 +15,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 @@ -24,6 +25,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 @@ -150,11 +152,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 @@ -500,4 +508,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 @@ -769,6 +769,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
Loading

0 comments on commit 5c4f93b

Please sign in to comment.