Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CR): Disable Clearing Request creation for the projects which have linked releases without SRC type attachment #2263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,22 @@ public List<ReleaseNode> getReleaseRelationNetworkOfRelease(Release release, Use
getReleaseNodes(dependencyNetwork, user);
return Collections.singletonList(dependencyNetwork);
}

public List<Release> releasesWithoutSRC(String id, User user) throws TException{
ProjectService.Iface projectClient = new ThriftClients().makeProjectClient();
Project project = projectClient.getProjectById(id, user);
List<Release> releasesWithoutSRC = new ArrayList<>();
Map<String, ProjectReleaseRelationship> releaseIdToUsage = project.getReleaseIdToUsage();
List<String> releaseIdsList = new ArrayList<>(releaseIdToUsage.keySet());
List<Release> releaseObjects = getReleaseByIds(releaseIdsList);
for (Release release : releaseObjects) {
Set<Attachment> srcAttachments = getSourceAttachments(release.id);
if(srcAttachments.size() == 0){
releasesWithoutSRC.add(release);
}
}
return releasesWithoutSRC;
}

private ReleaseNode getReleaseNodes(ReleaseNode releaseNode, User user) {
Release releaseById = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,15 @@ public List<Project> searchByName(String name, User user) {
// CREATE CLEARING REQUEST //
/////////////////////////////

public AddDocumentRequestSummary createClearingRequest(ClearingRequest clearingRequest, User user, String projectUrl) throws SW360Exception {
public AddDocumentRequestSummary createClearingRequest(ClearingRequest clearingRequest, User user, String projectUrl) throws TException {
Project project = getProjectById(clearingRequest.getProjectId(), user);
AddDocumentRequestSummary requestSummary = new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.FAILURE);

int numReleaseWithoutSRC = doAllReleasesHaveSourceAttachment(project.id, user);
if(numReleaseWithoutSRC > 0) {
log.error("Failed to create CR as " + numReleaseWithoutSRC + " releases do not have SRC type attachment");
return requestSummary.setMessage("one.or.more.linked.releases.do.not.have.src.type.attachment");
}

if (!isWriteActionAllowedOnProject(project, user)) {
return requestSummary.setMessage("You do not have WRITE access to the project");
}
Expand Down Expand Up @@ -255,6 +260,11 @@ public AddDocumentRequestSummary createClearingRequest(ClearingRequest clearingR
}
return requestSummary.setMessage("Failed to create clearing request");
}

private int doAllReleasesHaveSourceAttachment(String id, User user) throws TException {
List<Release> releaseWithoutSource = componentDatabaseHandler.releasesWithoutSRC(id, user);
return releaseWithoutSource.size();
}

private boolean isWriteActionAllowedOnProject(Project project, User user) {
return makePermission(project, user).isActionAllowed(RequestedAction.WRITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ clearing.expert=Clearing Expert
clearing.progress=Clearing Progress
clearing.report=Clearing Report
clearing.request=Clearing Request
one.or.more.linked.releases.do.not.have.src.type.attachment=One or more linked releases do not have SRC type attachment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this in all language.properties files

clearing.request.already.present.for.project=Clearing request already present for project
clearing.request.cannot.be.created.for.project.with.specific.bu.or.closed.or.private.project=Clearing Request cannot be created for project with specific <b>Business unit</b> or <b>CLOSED</b> or <b>PRIVATE</b> project!
clearing.request.comments=Clearing request comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ clearing.expert=クリアリングエキスパート
clearing.progress=クリアリングの進捗
clearing.report=クリアリングレポート
clearing.request=クリアリングリクエスト
one.or.more.linked.releases.do.not.have.src.type.attachment=One or more linked releases do not have SRC type attachment.
clearing.request.already.present.for.project=プロジェクトに既にクリアリングリクエストが存在しています
clearing.request.cannot.be.created.for.project.with.specific.bu.or.closed.or.private.project=Clearing Request cannot be created for project with specific <b>Business unit</b> or <b>CLOSED</b> or <b>PRIVATE</b> project!
clearing.request.comments=クリアリングリクエストコメント
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ clearing.expert=Clearing Expert
clearing.progress=Clearing Progress
clearing.report=Báo cáo dọn dẹp
clearing.request=Yêu cầu thanh toán bù trừ
one.or.more.linked.releases.do.not.have.src.type.attachment=One or more linked releases do not have SRC type attachment.
clearing.request.already.present.for.project=Clearing request already present for project
clearing.request.cannot.be.created.for.project.with.specific.bu.or.closed.or.private.project=Clearing Request cannot be created for project with specific <b>Business unit</b> or <b>CLOSED</b> or <b>PRIVATE</b> project!
clearing.request.comments=Clearing request comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ clearing.expert=明确专家
clearing.progress=明确进度
clearing.report=明确报告
clearing.request=明确请求
one.or.more.linked.releases.do.not.have.src.type.attachment=One or more linked releases do not have SRC type attachment.
clearing.request.already.present.for.project=项目的明确请求已经存在
clearing.request.cannot.be.created.for.project.with.specific.bu.or.closed.or.private.project=Clearing Request cannot be created for project with specific <b>Business unit</b> or <b>CLOSED</b> or <b>PRIVATE</b> project!
clearing.request.comments=明确请求注释
Expand Down