From ca82851bd314ea6384b5e47667432d4e5ca2711b Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Fri, 2 Dec 2016 18:16:27 +0200 Subject: [PATCH] Change identifier for import project channel --- .../core/jsonrpc/impl/RequestDispatcher.java | 14 ++--- .../create-project.controller.ts | 4 +- .../che/ide/CoreLocalizationConstant.java | 2 +- .../ProjectNotificationSubscriberImpl.java | 58 ++++++++----------- .../ide/CoreLocalizationConstant.properties | 2 +- .../api/project/server/ProjectManager.java | 4 -- .../ProjectOutputLineConsumerFactory.java | 6 +- .../api/project/server/ProjectService.java | 1 - 8 files changed, 37 insertions(+), 54 deletions(-) diff --git a/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/jsonrpc/impl/RequestDispatcher.java b/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/jsonrpc/impl/RequestDispatcher.java index 21779359c2..b9c2b1fc76 100644 --- a/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/jsonrpc/impl/RequestDispatcher.java +++ b/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/jsonrpc/impl/RequestDispatcher.java @@ -64,7 +64,7 @@ public class RequestDispatcher { LOG.debug("Extracted request method: " + method); final RequestHandler handler = handlers.get(method); - if(handler == null) { + if (handler == null) { LOG.error("Handler not found: " + method); // TODO make a centralized standard errors structure transmitter.transmit(endpointId, error(-32601, "Method not found: " + method)); @@ -100,24 +100,24 @@ public class RequestDispatcher { Class

paramClass, Class resultClass) { - R result; + final R result; - if(paramClass != null) { + if (paramClass != null) { final P param = DtoFactory.getInstance().createDtoFromJson(params.toString(), paramClass); result = handler.handleRequest(endpointId, param); } else { result = handler.handleRequest(endpointId); } - LOG.debug("Dispatch response: " + result); + LOG.debug("Dispatch response: ", result); - if(result instanceof Void) + if (result instanceof Void) return new JsonObject(); - else if(result instanceof String) { + else if (result instanceof String) { JsonObject response = new JsonObject(); response.addProperty("text", (String)result); return response; - } else if(result instanceof Collection) { // list of DTO objects + } else if (result instanceof Collection) { // list of DTO objects JsonArray valueArray = new JsonArray(); ((Collection)result).stream().filter(r -> r instanceof JsonSerializable).forEach(r -> { String resultString = DtoFactory.getInstance().toJson(r); diff --git a/dashboard/src/app/projects/create-project/create-project.controller.ts b/dashboard/src/app/projects/create-project/create-project.controller.ts index 5f71d8e279..6146351154 100755 --- a/dashboard/src/app/projects/create-project/create-project.controller.ts +++ b/dashboard/src/app/projects/create-project/create-project.controller.ts @@ -561,7 +561,7 @@ export class CreateProjectController { this.createProjectSvc.setCurrentProgressStep(3); var promise; - var channel = null; + let channel: string = null; // select mode (create or import) if (this.selectSourceOption === 'select-source-new' && this.templatesChoice === 'templates-wizard') { @@ -578,7 +578,7 @@ export class CreateProjectController { } // websocket channel - channel = 'importProject:output:' + workspaceId + ':' + projectName; + channel = 'importProject:output'; // on import bus.subscribe(channel, (message: any) => { diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java index 08f7556367..c5b736cf34 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java @@ -263,7 +263,7 @@ public interface CoreLocalizationConstant extends Messages { String importProjectButton(); @Key("importProject.importing") - String importingProject(); + String importingProject(String projectName); @Key("importProject.uriFieldTitle") String importProjectUriFieldTitle(); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectNotificationSubscriberImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectNotificationSubscriberImpl.java index 85231ab0d6..c7e18a3b04 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectNotificationSubscriberImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectNotificationSubscriberImpl.java @@ -10,8 +10,9 @@ *******************************************************************************/ package org.eclipse.che.ide.projectimport.wizard; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONParser; +import elemental.json.Json; +import elemental.json.JsonObject; + import com.google.inject.Inject; import com.google.inject.Singleton; @@ -19,16 +20,14 @@ import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.ide.CoreLocalizationConstant; -import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.machine.WsAgentStateController; import org.eclipse.che.ide.api.notification.NotificationManager; import org.eclipse.che.ide.api.notification.StatusNotification; import org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber; -import org.eclipse.che.ide.commons.exception.UnmarshallerException; import org.eclipse.che.ide.util.loging.Log; -import org.eclipse.che.ide.websocket.Message; import org.eclipse.che.ide.websocket.MessageBus; import org.eclipse.che.ide.websocket.WebSocketException; +import org.eclipse.che.ide.websocket.rest.StringUnmarshallerWS; import org.eclipse.che.ide.websocket.rest.SubscriptionHandler; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; @@ -48,7 +47,6 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub private final Operation logErrorHandler; private final CoreLocalizationConstant locale; private final NotificationManager notificationManager; - private final String workspaceId; private final WsAgentStateController wsAgentStateController; private String wsChannel; @@ -58,12 +56,10 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub @Inject public ProjectNotificationSubscriberImpl(CoreLocalizationConstant locale, - AppContext appContext, NotificationManager notificationManager, WsAgentStateController wsAgentStateController) { this.locale = locale; this.notificationManager = notificationManager; - this.workspaceId = appContext.getWorkspace().getId(); this.wsAgentStateController = wsAgentStateController; this.logErrorHandler = new Operation() { @Override @@ -75,19 +71,32 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub @Override public void subscribe(final String projectName) { - notification = notificationManager.notify(locale.importingProject(), PROGRESS, FLOAT_MODE); + notification = notificationManager.notify(locale.importingProject(projectName), PROGRESS, FLOAT_MODE); subscribe(projectName, notification); } @Override - public void subscribe(final String projectName, final StatusNotification existingNotification) { - this.projectName = projectName; - this.wsChannel = "importProject:output:" + workspaceId + ":" + projectName; + public void subscribe(final String name, final StatusNotification existingNotification) { + this.projectName = name; + this.wsChannel = "importProject:output"; this.notification = existingNotification; - this.subscriptionHandler = new SubscriptionHandler(new LineUnmarshaller()) { + this.subscriptionHandler = new SubscriptionHandler(new StringUnmarshallerWS()) { @Override protected void onMessageReceived(String result) { - notification.setContent(result); + JsonObject jsonObject = Json.parse(result); + + if (jsonObject == null) { + return; + } + + if (jsonObject.hasKey("project")) { + projectName = jsonObject.getString("project"); + notification.setTitle(locale.importingProject(projectName)); + } + + if (jsonObject.hasKey("line")) { + notification.setContent(jsonObject.getString("line")); + } } @Override @@ -153,25 +162,4 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub } }).catchError(logErrorHandler); } - - static class LineUnmarshaller implements org.eclipse.che.ide.websocket.rest.Unmarshallable { - private String line; - - @Override - public void unmarshal(Message response) throws UnmarshallerException { - JSONObject jsonObject = JSONParser.parseStrict(response.getBody()).isObject(); - if (jsonObject == null) { - return; - } - if (jsonObject.containsKey("line")) { - line = jsonObject.get("line").isString().stringValue(); - } - } - - @Override - public String getPayload() { - return line; - } - } - } diff --git a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties index b24fbb34bc..a84fad97cc 100644 --- a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties +++ b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties @@ -145,7 +145,7 @@ importLocalProject.openZipTitle = Select Zip archive to import: importProject.importButton = Import importProject.uriFieldTitle = URL: importProject.viewTitle = Import project -importProject.importing = Importing project(s) +importProject.importing = Importing project {0} importProject.message.success = Project {0} imported importProject.message.failure = Failed to import project {0} importProject.message.startWithWhiteSpace = The url can not start with a whitespace. diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java index 03d3535248..b2c40a2ec5 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java @@ -493,10 +493,6 @@ public final class ProjectManager { sourceStorage.getLocation(), sourceStorage.getType())); } - // Preparing websocket output publisher to broadcast output of import process to the ide clients while importing -// final LineConsumerFactory outputOutputConsumerFactory = -// () -> new ProjectImportOutputWSLineConsumer(path, workspaceProjectsHolder.getWorkspaceId(), 300); - String normalizePath = (path.startsWith("/")) ? path : "/".concat(path); FolderEntry folder = asFolder(normalizePath); if (folder != null && !rewrite) { diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectOutputLineConsumerFactory.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectOutputLineConsumerFactory.java index c4fed9c3b9..89ca29d76a 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectOutputLineConsumerFactory.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectOutputLineConsumerFactory.java @@ -15,7 +15,7 @@ import org.eclipse.che.api.core.util.LineConsumerFactory; import org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer; /** - * LineConsumerFactory dedicated to project related operations long output + * {@link LineConsumerFactory} dedicated to project related operations long output * extended standard factory with setProjectName method to make it possible * change it runtime inside ProjectManager * @@ -23,9 +23,9 @@ import org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineCons */ public class ProjectOutputLineConsumerFactory implements LineConsumerFactory { - private String projectName; + private String projectName; private final String workspaceId; - private final int delay; + private final int delay; public ProjectOutputLineConsumerFactory(String projectName, String workspaceId, int delay) { this.projectName = projectName; diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java index 24d5574d17..e711a5422b 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java @@ -232,7 +232,6 @@ public class ProjectService extends Service { List result = new ArrayList<>(projectConfigList.size()); final ProjectOutputLineConsumerFactory outputOutputConsumerFactory = new ProjectOutputLineConsumerFactory(workspace, 300); -// () -> new ProjectImportOutputWSLineConsumer("BATCH", workspace, 300); for (RegisteredProject registeredProject : projectManager.createBatchProjects(projectConfigList, rewrite, outputOutputConsumerFactory)) {