Search in sources :

Example 1 with RemoteCredentials

use of org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials in project sw360portal by sw360.

the class ProjectImportPortlet method updateImportables.

private void updateImportables(JSONObject responseData, LoginState loginState, RemoteCredentials remoteCredentials, String projectName) throws JsonProcessingException {
    if (!nullToEmpty(remoteCredentials.getServerUrl()).isEmpty()) {
        List<Project> importables = loadImportables(remoteCredentials, projectName);
        JSONArray serializedProjects = JSONFactoryUtil.createJSONArray();
        for (Project p : importables) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
            if (p.isSetExternalIds() && !isNullOrEmpty(p.getExternalIds().get(getIdName())))
                jsonObject.put("externalId", p.getExternalIds().get(getIdName()));
            jsonObject.put("name", p.getName());
            serializedProjects.put(jsonObject.toString());
        }
        responseData.put(ProjectImportConstants.RESPONSE__NEW_IMPORTABLES, serializedProjects);
    }
    responseData.put(ProjectImportConstants.RESPONSE__DB_URL, remoteCredentials.getServerUrl());
    loginState.login(remoteCredentials.getServerUrl());
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 2 with RemoteCredentials

use of org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials in project sw360portal by sw360.

the class ProjectImportPortletTest method testUpdateInputSourceWithUrlUpdatesResponse.

@Test
public void testUpdateInputSourceWithUrlUpdatesResponse() throws Exception {
    ProjectImportPortlet.LoginState loginState = new ProjectImportPortlet.LoginState();
    RemoteCredentials remoteCredentials = new RemoteCredentials();
    remoteCredentials.setUsername(name);
    remoteCredentials.setPassword(password);
    remoteCredentials.setServerUrl(newURL);
    new ProjectImportPortlet().setNewImportSource(remoteCredentials, session, responseData, loginState);
    verify(responseData).put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__DB_CHANGED);
    verify(responseData).put(ProjectImportConstants.RESPONSE__DB_URL, newURL);
}
Also used : RemoteCredentials(org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials) Test(org.junit.Test)

Example 3 with RemoteCredentials

use of org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials in project sw360portal by sw360.

the class ProjectImportPortlet method importBdpProjects.

private void importBdpProjects(User user, List<String> selectedIds, JSONObject responseData, RemoteCredentials remoteCredentials) throws PortletException, IOException {
    ImportStatus importStatus = importDatasources(selectedIds, user, remoteCredentials);
    JSONObject jsonFailedIds = JSONFactoryUtil.createJSONObject();
    JSONArray jsonSuccessfulIds = JSONFactoryUtil.createJSONArray();
    if (importStatus.isSetRequestStatus() && importStatus.getRequestStatus().equals(RequestStatus.SUCCESS)) {
        importStatus.getFailedIds().forEach(jsonFailedIds::put);
        importStatus.getSuccessfulIds().forEach(jsonSuccessfulIds::put);
        responseData.put(ProjectImportConstants.RESPONSE__FAILED_IDS, jsonFailedIds);
        responseData.put(ProjectImportConstants.RESPONSE__SUCCESSFUL_IDS, jsonSuccessfulIds);
    }
    if (isImportSuccessful(importStatus)) {
        responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__SUCCESS);
    } else if (importStatus.isSetRequestStatus() && importStatus.getRequestStatus().equals(RequestStatus.SUCCESS)) {
        responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__FAILURE);
    } else {
        responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__GENERAL_FAILURE);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) ImportStatus(org.eclipse.sw360.datahandler.thrift.importstatus.ImportStatus) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 4 with RemoteCredentials

use of org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials in project sw360portal by sw360.

the class ProjectImportPortlet method getRemoteCredentialsFromSession.

private RemoteCredentials getRemoteCredentialsFromSession(PortletSession session) {
    String dbUserName = (String) session.getAttribute(ProjectImportConstants.USERNAME);
    String dbUserPass = (String) session.getAttribute(ProjectImportConstants.PASSWORD);
    String dbUrl = (String) session.getAttribute(ProjectImportConstants.SERVER_URL);
    return new RemoteCredentials().setPassword(dbUserPass).setUsername(dbUserName).setServerUrl(dbUrl);
}
Also used : RemoteCredentials(org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials)

Example 5 with RemoteCredentials

use of org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials in project sw360portal by sw360.

the class ProjectImportPortlet method handleRequestedAjaxAction.

public JSONObject handleRequestedAjaxAction(String requestedAction, ResourceRequest request, ResourceResponse response, LoginState loginState) throws IOException, PortletException {
    PortletSession session = request.getPortletSession();
    RemoteCredentials remoteCredentials = getRemoteCredentialsFromSession(session);
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    switch(requestedAction) {
        case ProjectImportConstants.USER_ACTION__IMPORT_DATA:
            User user = UserCacheHolder.getUserFromRequest(request);
            List<String> selectedIds = getProjectIdsForImport(request);
            importBdpProjects(user, selectedIds, responseData, remoteCredentials);
            break;
        case ProjectImportConstants.USER_ACTION__NEW_IMPORT_SOURCE:
            RemoteCredentials newCredentials = new RemoteCredentials().setUsername(request.getParameter(ProjectImportConstants.USERNAME)).setPassword(request.getParameter(ProjectImportConstants.PASSWORD)).setServerUrl(request.getParameter(ProjectImportConstants.SERVER_URL));
            if (!validateCredentials(newCredentials)) {
                responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__UNAUTHORIZED);
            } else {
                setNewImportSource(newCredentials, session, responseData, loginState);
            }
            break;
        case ProjectImportConstants.USER_ACTION__UPDATE_IMPORTABLES:
            String projectName = request.getParameter(ProjectImportConstants.PROJECT_NAME);
            updateImportables(responseData, loginState, remoteCredentials, projectName);
            break;
        case ProjectImportConstants.USER_ACTION__DISCONNECT:
            putRemoteCredentialsIntoSession(session, new RemoteCredentials());
            loginState.logout();
            break;
        default:
            loginState.logout();
            break;
    }
    return responseData;
}
Also used : RemoteCredentials(org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Aggregations

RemoteCredentials (org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)3 Test (org.junit.Test)3 JSONArray (com.liferay.portal.kernel.json.JSONArray)2 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)2 ArrayList (java.util.ArrayList)1 ImportStatus (org.eclipse.sw360.datahandler.thrift.importstatus.ImportStatus)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1