Skip to content

Commit

Permalink
Merge branch 'master' into releases/feature-spdx_information_management
Browse files Browse the repository at this point in the history
  • Loading branch information
tuannn2 authored May 25, 2022
2 parents ef94a18 + 011762a commit 7dee8c6
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public RequestStatus markFossologyProcessOutdated(String releaseId, User user) t
}

@Override
public ExternalToolProcess process(String releaseId, User user) throws TException {
public ExternalToolProcess process(String releaseId, User user, String uploadDescription) throws TException {
ExternalToolProcess fossologyProcess;

Iface componentClient = thriftClients.makeComponentClient();
Expand Down Expand Up @@ -159,7 +159,7 @@ public ExternalToolProcess process(String releaseId, User user) throws TExceptio

ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1);
if (FossologyUtils.FOSSOLOGY_STEP_NAME_UPLOAD.equals(furthestStep.getStepName())) {
handleUploadStep(componentClient, release, user, fossologyProcess, sourceAttachment);
handleUploadStep(componentClient, release, user, fossologyProcess, sourceAttachment, uploadDescription);
} else if (FossologyUtils.FOSSOLOGY_STEP_NAME_SCAN.equals(furthestStep.getStepName())) {
handleScanStep(componentClient, release, user, fossologyProcess);
} else if (FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT.equals(furthestStep.getStepName())) {
Expand Down Expand Up @@ -313,7 +313,7 @@ private ExternalToolProcessStep createFossologyProcessStep(User user, String ste
}

private void handleUploadStep(Iface componentClient, Release release, User user,
ExternalToolProcess fossologyProcess, Attachment sourceAttachment) throws TException {
ExternalToolProcess fossologyProcess, Attachment sourceAttachment, String uploadDescription) throws TException {
ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps()
.get(fossologyProcess.getProcessSteps().size() - 1);
switch (furthestStep.getStepStatus()) {
Expand All @@ -332,7 +332,7 @@ private void handleUploadStep(Iface componentClient, Release release, User user,
AttachmentContent attachmentContent = attachmentConnector.getAttachmentContent(attachmentContentId);

InputStream attachmentStream = attachmentConnector.getAttachmentStream(attachmentContent, user, release);
int uploadId = fossologyRestClient.uploadFile(attachmentFilename, attachmentStream);
int uploadId = fossologyRestClient.uploadFile(attachmentFilename, attachmentStream, uploadDescription);
if (uploadId > -1) {
furthestStep.setFinishedOn(Instant.now().toString());
furthestStep.setStepStatus(ExternalToolProcessStatus.DONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.fossology.config.FossologyRestConfig;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -139,7 +140,7 @@ public boolean checkConnection() {
* @return the uploadId provided by FOSSology in case of an successful upload,
* -1 otherwise
*/
public int uploadFile(String filename, InputStream fileStream) {
public int uploadFile(String filename, InputStream fileStream, String uploadDescription) {
String baseUrl = restConfig.getBaseUrlWithSlash();
String token = restConfig.getAccessToken();
String folderId = restConfig.getFolderId();
Expand All @@ -160,6 +161,9 @@ public int uploadFile(String filename, InputStream fileStream) {
headers.set("Authorization", "Bearer " + token);
headers.set("folderId", folderId);

if (CommonUtils.isNotNullEmptyOrWhitespace(uploadDescription)) {
headers.set("uploadDescription", uploadDescription);
}
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("fileInput", new FossologyInputStreamResource(filename, fileStream));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void test_01_noFossologyProcessYet_soUploadSource() throws TException, Fi
prepareValidPreconditions(user);

// when:
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user);
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user, "");

// then:
assertNotNull(actual);
Expand All @@ -207,7 +207,7 @@ public void test_02_uploadFinishedSynchronously_soStartScan()
|| actual.getProcessSteps().get(1).getStepStatus().equals(ExternalToolProcessStatus.NEW)) {
// give fossology some time to process the upload
Thread.sleep(1_000l);
actual = uut.process(sharedRelease.getId(), user);
actual = uut.process(sharedRelease.getId(), user, "");
}

// then:
Expand All @@ -228,7 +228,7 @@ public void test_03_scanRunning() throws TException, FileNotFoundException, Inte
prepareValidPreconditions(user);

// when:
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user);
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user, "");

// then:
assertNotNull(actual);
Expand All @@ -252,7 +252,7 @@ public void test_04_scanRunning_soWaitOnResult() throws TException, FileNotFound
while (actual.getProcessSteps().get(1).getStepStatus().equals(ExternalToolProcessStatus.IN_WORK)) {
// give fossology some time to process the scan
Thread.sleep(5_000l);
actual = uut.process(sharedRelease.getId(), user);
actual = uut.process(sharedRelease.getId(), user, "");
}

// then:
Expand All @@ -273,7 +273,7 @@ public void test_05_scanFinished_soStartReport() throws TException, FileNotFound
prepareValidPreconditions(user);

// when:
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user);
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user, "");

// then:
assertNotNull(actual);
Expand All @@ -293,7 +293,7 @@ public void test_06_reportRunning() throws TException, FileNotFoundException, In
prepareValidPreconditions(user);

// when:
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user);
ExternalToolProcess actual = uut.process(sharedRelease.getId(), user, "");

// then:
assertNotNull(actual);
Expand Down Expand Up @@ -326,7 +326,7 @@ public void test_07_reportRunning_soWaitOnResult() throws TException, FileNotFou
while (actual.getProcessSteps().get(2).getStepStatus().equals(ExternalToolProcessStatus.IN_WORK)) {
// give fossology some time to process the report generation
Thread.sleep(1_000l);
actual = uut.process(sharedRelease.getId(), user);
actual = uut.process(sharedRelease.getId(), user, "");
}

// then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected void serveFossologyProcess(ResourceRequest request, ResourceResponse r
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
try {
ExternalToolProcess fossologyProcess = fossologyClient.process(releaseId,
UserCacheHolder.getUserFromRequest(request));
UserCacheHolder.getUserFromRequest(request), "");
fillJsonObjectFromFossologyProcess(jsonObject, Stream.of(fossologyProcess).collect(Collectors.toSet()));
} catch (TException e) {
jsonObject.put("error", "Could not determine FOSSology state for this release!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<script>
document.title = $("<span></span>").html("<sw360:out value='${component.name}'/> - " + document.title).text();

require(['jquery', 'modules/button', 'modules/listgroup', 'utils/link', 'utils/includes/clipboard'], function($, button, listgroup, linkutil, clipboard) {
require(['jquery', 'components/includes/releases/regexjs','modules/button', 'modules/listgroup', 'utils/link', 'utils/includes/clipboard'], function($,regexjs, button, listgroup, linkutil, clipboard) {
listgroup.initialize('detailTab', $('#detailTab').data('initial-tab') || 'tab-Summary');

$('#mergeButton').on('click', function(event) {
Expand Down Expand Up @@ -213,5 +213,18 @@
textToCopy = $(textSelector).clone().children().remove().end().text().trim();
clipboard.copyToClipboard(textToCopy, textSelector);
});

let keyComponent, valueComponent;
renderDataComponent();
function renderDataComponent() {
let content = '';
<core_rt:forEach items="${component.additionalData}" var="additional">
keyComponent = '<sw360:out value='${additional.key}'/>';
valueComponent = '<sw360:out value='${additional.value}'/>';
content+=regexjs.regex(keyComponent,valueComponent);
</core_rt:forEach>
$('#list-data-additional-contentComponent').append(content);
}
});

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</tr>
<tr>
<td><liferay-ui:message key="additional.data" />:</td>
<td><sw360:DisplayMap value="${component.additionalData}"/></td>
<td><ul id="list-data-additional-contentComponent" class="mapDisplayRootItem"></ul> </td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@
<script>
document.title = $("<span></span>").html("<sw360:out value='${component.name}'/> - " + document.title).text();

require(['jquery', 'components/includes/releases/linkProject', 'modules/button', 'modules/listgroup', 'utils/includes/clipboard', 'modules/dialog'], function($, linkProject, button, listgroup, clipboard, dialog) {

require(['jquery','components/includes/releases/regexjs','components/includes/releases/linkProject', 'modules/button', 'modules/listgroup', 'utils/includes/clipboard'], function($,regexjs,linkProject, button, listgroup, clipboard) {
linkProject.initialize();
listgroup.initialize('detailTab', $('#detailTab').data('initial-tab') || 'tab-Summary');

Expand Down Expand Up @@ -362,5 +363,17 @@
}
});
}

let keyReleases, valueReleases;
renderDataReleases();
function renderDataReleases() {
let content ='';
<core_rt:forEach items="${release.additionalData}" var="additional">
keyReleases = '<sw360:out value='${additional.key}'/>';
valueReleases = '<sw360:out value='${additional.value}'/>';
content+=regexjs.regex(keyReleases,valueReleases);
</core_rt:forEach>
$('#list-data-additional-release').append(content);
}
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</tr>
<tr>
<td><liferay-ui:message key="additional.data" />:</td>
<td><sw360:DisplayMap value="${release.additionalData}"/></td>
<td><ul id="list-data-additional-release" class="mapDisplayRootItem"></ul> </td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ AUI().use('liferay-portlet-url', function () {
projCell.data(renderLinkToProject(response[i].id, projName));
if (isOpenCrTable) {
let clearing = response[i].clearing,
totalCount = d(clearing.newRelease) + d(clearing.underClearing) + d(clearing.sentToClearingTool) + d(clearing.reportAvailable) + d(clearing.approved),
totalCount = d(clearing.newRelease) + d(clearing.underClearing) + d(clearing.sentToClearingTool) + d(clearing.reportAvailable) + d(clearing.approved) + d(clearing.scanAvailable),
approvedCount = d(clearing.reportAvailable) + d(clearing.approved);
compCell.data(totalCount - approvedCount);
if (!totalCount || $(table.cell('#'+crId, 4).node()).find('span.sw360-tt-ClearingRequestState-NEW').text()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
approvedCount;
if (clearing) {
releaseCount = d(clearing.newRelease) + d(clearing.underClearing) + d(clearing.sentToClearingTool) + d(clearing.reportAvailable) + d(clearing.approved);
releaseCount = d(clearing.newRelease) + d(clearing.underClearing) + d(clearing.sentToClearingTool) + d(clearing.reportAvailable) + d(clearing.approved) + d(clearing.scanAvailable);
approvedCount = d(clearing.approved);
resultElementAsString = "<span class=\"clearingstate content-center\" title=\"" + approvedCount + (approvedCount === 1 ? " <liferay-ui:message key='release' />" : " <liferay-ui:message key='releases' />")
+ " <liferay-ui:message key='out.of' /> " + releaseCount + (approvedCount === 1 ? " <liferay-ui:message key='has' />" : " <liferay-ui:message key='have' />")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright TOSHIBA CORPORATION, 2022. Part of the SW360 Portal Project.
* Copyright Toshiba Software Development (Vietnam) Co., Ltd., 2022. Part of the SW360 Portal Project.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

define('components/includes/releases/regexjs', ['jquery'] , function($) {
function regex(key,value) {
let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
let regexUrl = /^(https?|chrome):\/\/[^\s$.?#].[^\s]*$/g;
let content = '';
if (value.match(regexEmail)) {
content +=
'<li>' +
'<span class="mapDisplayChildItemLeft">'+ key +': </span>'+
'<span class="mapDisplayChildItemRight"><a href="mailto:'+ value +'"> '+ value +'</a></span>'+
'</li>'
} else if (value.match(regexUrl)) {
content +=
'<li>' +
'<span class="mapDisplayChildItemLeft">'+ key +': </span>'+
'<span class="mapDisplayChildItemRight"><a href="'+ value +'"> '+ value +'</a></span>'+
'</li>'
} else {
content +=
'<li>' +
'<span class="mapDisplayChildItemLeft">' + key + ': </span>' +
'<span class="mapDisplayChildItemRight"> ' + value + '</span>' +
'</li>'
}
return content;
}
return {
regex: regex,
};
});
2 changes: 1 addition & 1 deletion libraries/lib-datahandler/src/main/thrift/fossology.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ service FossologyService {
* Not only saves the reached state in the release, but also returns the
* ExternalToolProcess.
**/
ExternalToolProcess process(1: string releaseId, 2: User user);
ExternalToolProcess process(1: string releaseId, 2: User user,3: string uploadDescription);

/**
* Since there should only be one actice Fossology process at most for a release
Expand Down
4 changes: 3 additions & 1 deletion rest/resource-server/src/docs/asciidoc/releases.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ have been successful.
==== Trigger FOSSology process

A `GET` request will allow you to Trigger FOSSology process for a release. +
Please set the request parameter `&markFossologyProcessOutdated=<true|false>` to set previous FOSSology process outdated and generate new.
Please set the request parameter +
`&markFossologyProcessOutdated=<true|false>` to set previous FOSSology process outdated and generate new. +
`&uploadDescription=uploadDescription` with the upload description to FOSSology +

===== Response structure
include::{snippets}/should_document_trigger_fossology_process/response-fields.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public ResponseEntity<Map<String, Object>> checkFossologyProcessStatus(@PathVari
@RequestMapping(value = RELEASES_URL + "/{id}/triggerFossologyProcess", method = RequestMethod.GET)
public ResponseEntity<HalResource> triggerFossologyProcess(@PathVariable("id") String releaseId,
@RequestParam(value = "markFossologyProcessOutdated", required = false) boolean markFossologyProcessOutdated,
@RequestParam(value = "uploadDescription", required = false) String uploadDescription,
HttpServletResponse response) throws TException, IOException {
releaseService.checkFossologyConnection();

Expand All @@ -412,7 +413,7 @@ public ResponseEntity<HalResource> triggerFossologyProcess(@PathVariable("id") S
} else {
User user = restControllerHelper.getSw360UserFromAuthentication();
releaseService.executeFossologyProcess(user, attachmentService, mapOfLocks, releaseId,
markFossologyProcessOutdated);
markFossologyProcessOutdated, uploadDescription);
responseMap.put("message", "FOSSology Process for Release Id : " + releaseId + " has been triggered.");
status = HttpStatus.OK;
}
Expand Down
Loading

0 comments on commit 7dee8c6

Please sign in to comment.