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

Commit 549d605

Browse files
authored
Merge pull request #680 from bsinno/dev/654-bdp-error-messages
feat(bdpImport): Use of proper error message when importing projects review-by:weekly-dev-meeting tested-by:[email protected]
2 parents e1ecf9e + dc2d820 commit 549d605

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/PortletUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ && nullToEmptyList(updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAI
307307
JSONArray jsonNewIds = JSONFactoryUtil.createJSONArray();
308308
JSONArray jsonUpdatedIds = JSONFactoryUtil.createJSONArray();
309309

310-
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED).forEach(id -> jsonFailedIds.put(id));
311-
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW).forEach(id -> jsonNewIds.put(id));
312-
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED).forEach(id -> jsonUpdatedIds.put(id));
310+
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED).forEach(jsonFailedIds::put);
311+
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW).forEach(jsonNewIds::put);
312+
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED).forEach(jsonUpdatedIds::put);
313313

314314
responseData.put(PortalConstants.UPDATE_VULNERABILITIES__FAILED_IDS, jsonFailedIds);
315315
responseData.put(PortalConstants.UPDATE_VULNERABILITIES__NEW_IDS, jsonNewIds);

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projectimport/ProjectImportPortlet.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import com.liferay.portal.kernel.json.JSONObject;
2020
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
2121
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
22+
import org.eclipse.sw360.datahandler.thrift.projectimport.ProjectImportService;
23+
import org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials;
2224
import org.eclipse.sw360.datahandler.thrift.projects.Project;
23-
import org.eclipse.sw360.datahandler.thrift.bdpimport.BdpImportService;
24-
import org.eclipse.sw360.datahandler.thrift.bdpimport.RemoteCredentials;
2525
import org.eclipse.sw360.datahandler.thrift.importstatus.ImportStatus;
2626
import org.eclipse.sw360.datahandler.thrift.users.User;
2727
import org.eclipse.sw360.portal.portlets.Sw360Portlet;
@@ -43,7 +43,7 @@
4343
*/
4444
public class ProjectImportPortlet extends Sw360Portlet {
4545
private static final Logger log = Logger.getLogger(ProjectImportPortlet.class);
46-
private static BdpImportService.Iface bdpImportClient = new ThriftClients().makeBdpImportClient();
46+
private static ProjectImportService.Iface projectImportClient = new ThriftClients().makeProjectImportClient();
4747

4848
static class LoginState {
4949
private Boolean loggedIn;
@@ -132,7 +132,7 @@ private boolean isImportSuccessful(ImportStatus importStatus) {
132132
private ImportStatus importDatasources(List<String> toImport, User user, RemoteCredentials remoteCredentials) {
133133
ImportStatus importStatus = new ImportStatus();
134134
try {
135-
importStatus = bdpImportClient.importDatasources(toImport, user, remoteCredentials);
135+
importStatus = projectImportClient.importDatasources(toImport, user, remoteCredentials);
136136
if (!isImportSuccessful(importStatus)) {
137137
if (importStatus.getRequestStatus().equals(RequestStatus.FAILURE)) {
138138
log.error("Importing of data sources failed.");
@@ -149,7 +149,7 @@ private ImportStatus importDatasources(List<String> toImport, User user, RemoteC
149149
private List<Project> loadImportables(RemoteCredentials remoteCredentials, String projectName) {
150150
try {
151151
log.info("Looking for importables with prefix " + projectName);
152-
return bdpImportClient.suggestImportables(remoteCredentials, Strings.nullToEmpty(projectName));
152+
return projectImportClient.suggestImportables(remoteCredentials, Strings.nullToEmpty(projectName));
153153
} catch (TException e) {
154154
log.error("Thrift failed, (uncaught TException)", e);
155155
return ImmutableList.of();
@@ -158,7 +158,7 @@ private List<Project> loadImportables(RemoteCredentials remoteCredentials, Strin
158158

159159
private String getIdName() {
160160
try {
161-
return bdpImportClient.getIdName();
161+
return projectImportClient.getIdName();
162162
} catch (TException e) {
163163
log.error("Thrift failed, (uncaught TException)", e);
164164
return "";
@@ -215,7 +215,7 @@ public JSONObject handleRequestedAjaxAction(String requestedAction, ResourceRequ
215215

216216
private boolean validateCredentials(RemoteCredentials credentials) {
217217
try {
218-
return bdpImportClient.validateCredentials(credentials);
218+
return projectImportClient.validateCredentials(credentials);
219219
} catch (TException e) {
220220
log.error("Thrift failed, (uncaught TException)", e);
221221
return false;
@@ -224,8 +224,9 @@ private boolean validateCredentials(RemoteCredentials credentials) {
224224

225225
private void importBdpProjects(User user, List<String> selectedIds, JSONObject responseData, RemoteCredentials remoteCredentials) throws PortletException, IOException {
226226
ImportStatus importStatus = importDatasources(selectedIds, user, remoteCredentials);
227-
JSONArray jsonFailedIds = JSONFactoryUtil.createJSONArray();
227+
JSONObject jsonFailedIds = JSONFactoryUtil.createJSONObject();
228228
JSONArray jsonSuccessfulIds = JSONFactoryUtil.createJSONArray();
229+
229230
if (importStatus.isSetRequestStatus() && importStatus.getRequestStatus().equals(RequestStatus.SUCCESS)) {
230231
importStatus.getFailedIds().forEach(jsonFailedIds::put);
231232
importStatus.getSuccessfulIds().forEach(jsonSuccessfulIds::put);

frontend/sw360-portlet/src/main/webapp/html/projects/import.jsp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<%@ page import="com.liferay.portlet.PortletURLFactoryUtil" %>
1919
<%@ page import="org.eclipse.sw360.portal.common.PortalConstants" %>
2020
<%@ page import="javax.portlet.PortletRequest" %>
21-
<%@ page import="org.eclipse.sw360.datahandler.thrift.bdpimport.RemoteCredentials" %>
21+
<%@ page import="org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials" %>
2222
<%@ page import="org.eclipse.sw360.datahandler.thrift.projects.Project" %>
2323
<%@ page import="org.eclipse.sw360.portal.portlets.projectimport.ProjectImportConstants" %>
2424

@@ -221,8 +221,15 @@
221221
self.setContent('Projects imported successfully.');
222222
break;
223223
case '<%=ProjectImportConstants.RESPONSE__FAILURE%>':
224-
var failedIdsList = "<div>" + response.<%=ProjectImportConstants.RESPONSE__FAILED_IDS%> + "</div>";
225-
self.setContent('Some projects failed to import:' + failedIdsList);
224+
var bodyContent = "<ol>";
225+
var failedIdsList = response.<%=ProjectImportConstants.RESPONSE__FAILED_IDS%>;
226+
227+
$.each(failedIdsList, function (key, value) {
228+
bodyContent += "<li><b>" + key + "</b>: " + value + "</li>";
229+
});
230+
bodyContent += "</ol>";
231+
232+
self.setContent('Some projects failed to import:' + bodyContent);
226233
break;
227234
case '<%=ProjectImportConstants.RESPONSE__GENERAL_FAILURE%>':
228235
flashErrorMessage('Could not import the projects.');

frontend/sw360-portlet/src/test/java/org/eclipse/sw360/portal/portlets/projectimport/ProjectImportPortletTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import com.liferay.portal.kernel.json.JSONObject;
1515
import junit.framework.TestCase;
16-
import org.eclipse.sw360.datahandler.thrift.bdpimport.RemoteCredentials;
16+
import org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials;
1717
import org.junit.Test;
1818
import org.junit.runner.RunWith;
1919
import org.mockito.Mock;

libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/thrift/ThriftClients.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.eclipse.sw360.datahandler.thrift.licenses.LicenseService;
2121
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationService;
2222
import org.eclipse.sw360.datahandler.thrift.projects.ProjectService;
23-
import org.eclipse.sw360.datahandler.thrift.bdpimport.BdpImportService;
23+
import org.eclipse.sw360.datahandler.thrift.projectimport.ProjectImportService;
2424
import org.eclipse.sw360.datahandler.thrift.schedule.ScheduleService;
2525
import org.eclipse.sw360.datahandler.thrift.search.SearchService;
2626
import org.eclipse.sw360.datahandler.thrift.users.UserService;
@@ -51,20 +51,20 @@ public class ThriftClients {
5151
public static final String BACKEND_URL;
5252

5353
//! Service addresses
54-
public static final String ATTACHMENT_SERVICE_URL = "/attachments/thrift";
55-
public static final String COMPONENT_SERVICE_URL = "/components/thrift";
56-
public static final String CVESEARCH_SERVICE_URL = "/cvesearch/thrift";
57-
public static final String FOSSOLOGY_SERVICE_URL = "/fossology/thrift";
58-
public static final String LICENSE_SERVICE_URL = "/licenses/thrift";
59-
public static final String MODERATION_SERVICE_URL = "/moderation/thrift";
60-
public static final String PROJECT_SERVICE_URL = "/projects/thrift";
61-
public static final String LICENSEINFO_SERVICE_URL = "/licenseinfo/thrift";
62-
public static final String SEARCH_SERVICE_URL = "/search/thrift";
63-
public static final String USER_SERVICE_URL = "/users/thrift";
64-
public static final String VENDOR_SERVICE_URL = "/vendors/thrift";
65-
public static final String BDPIMPORT_SERVICE_URL = "/bdpimport/thrift";
66-
public static final String VULNERABILITY_SERVICE_URL = "/vulnerabilities/thrift";
67-
public static final String SCHEDULE_SERVICE_URL = "/schedule/thrift";
54+
private static final String ATTACHMENT_SERVICE_URL = "/attachments/thrift";
55+
private static final String COMPONENT_SERVICE_URL = "/components/thrift";
56+
private static final String CVESEARCH_SERVICE_URL = "/cvesearch/thrift";
57+
private static final String FOSSOLOGY_SERVICE_URL = "/fossology/thrift";
58+
private static final String LICENSE_SERVICE_URL = "/licenses/thrift";
59+
private static final String MODERATION_SERVICE_URL = "/moderation/thrift";
60+
private static final String PROJECT_SERVICE_URL = "/projects/thrift";
61+
private static final String LICENSEINFO_SERVICE_URL = "/licenseinfo/thrift";
62+
private static final String SEARCH_SERVICE_URL = "/search/thrift";
63+
private static final String USER_SERVICE_URL = "/users/thrift";
64+
private static final String VENDOR_SERVICE_URL = "/vendors/thrift";
65+
private static final String PROJECTIMPORT_SERVICE_URL = "/bdpimport/thrift";
66+
private static final String VULNERABILITY_SERVICE_URL = "/vulnerabilities/thrift";
67+
private static final String SCHEDULE_SERVICE_URL = "/schedule/thrift";
6868

6969
// A service which has to be scheduled by the scheduler should be registered here!
7070
// names of services that can be scheduled by the schedule service, i.e. that have an "update" method
@@ -133,8 +133,8 @@ public VendorService.Iface makeVendorClient() {
133133
return new VendorService.Client(makeProtocol(BACKEND_URL, VENDOR_SERVICE_URL));
134134
}
135135

136-
public BdpImportService.Iface makeBdpImportClient() {
137-
return new BdpImportService.Client(makeProtocol(BACKEND_URL, BDPIMPORT_SERVICE_URL));
136+
public ProjectImportService.Iface makeProjectImportClient() {
137+
return new ProjectImportService.Client(makeProtocol(BACKEND_URL, PROJECTIMPORT_SERVICE_URL));
138138
}
139139

140140
public VulnerabilityService.Iface makeVulnerabilityClient() {

libraries/lib-datahandler/src/main/thrift/importstatus.thrift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ typedef sw360.RequestStatus RequestStatus
2323

2424

2525
struct ImportStatus {
26+
// List of all Ids that where sucessfully imported.
2627
1: list<string> successfulIds;
27-
2: list<string> failedIds;
28+
// Map of failed Ids (key) with a message why it failed (value)
29+
2: map<string, string> failedIds;
2830
3: RequestStatus requestStatus;
2931
}

libraries/lib-datahandler/src/main/thrift/bdpimport.thrift renamed to libraries/lib-datahandler/src/main/thrift/projectimport.thrift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ include "sw360.thrift"
2020
include "users.thrift"
2121
include "importstatus.thrift"
2222

23-
namespace java org.eclipse.sw360.datahandler.thrift.bdpimport
24-
namespace php sw360.thrift.bdpimport
23+
namespace java org.eclipse.sw360.datahandler.thrift.projectimport
24+
namespace php sw360.thrift.projectimport
2525

2626
typedef projects.Project Project
2727
typedef users.User User
@@ -33,28 +33,28 @@ struct RemoteCredentials {
3333
3: string serverUrl,
3434
}
3535

36-
service BdpImportService {
36+
service ProjectImportService {
3737
/**
38-
* check credentials with bdp API
38+
* check credentials with API
3939
**/
4040
bool validateCredentials(1: RemoteCredentials credentials)
4141

4242
/**
43-
* returns a list of projects that can be imported from bdp with `reCred` credentials
43+
* returns a list of projects that can be imported with `reCred` credentials
4444
**/
4545
list<Project> loadImportables(1: RemoteCredentials reCred)
4646

4747
/**
48-
* returns a list of projects that can be imported from bdp with `reCred` credentials,
48+
* returns a list of projects that can be imported with `reCred` credentials,
4949
* where any word in the project name starts with the given string
5050
**/
5151
list<Project> suggestImportables(1: RemoteCredentials reCred, 2: string projectName)
5252

5353
/**
54-
* imports projects from bdp specified by `bdpProjectIds` with credentials `reCred` and set user as creating
54+
* imports projects from external source specified by `projectIds` with credentials `reCred` and set user as creating
5555
* user in SW360
5656
**/
57-
ImportStatus importDatasources(1: list<string> bdpProjectIds, 2: User user, 3: RemoteCredentials reCred);
57+
ImportStatus importDatasources(1: list<string> projectIds, 2: User user, 3: RemoteCredentials reCred);
5858

5959
string getIdName();
6060
}

0 commit comments

Comments
 (0)