Search in sources :

Example 6 with RequestedAction

use of org.eclipse.sw360.datahandler.thrift.users.RequestedAction 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

User (org.eclipse.sw360.datahandler.thrift.users.User)5 TException (org.apache.thrift.TException)4 RequestedAction (org.eclipse.sw360.datahandler.thrift.users.RequestedAction)4 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 RemoteCredentials (org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)1