Skip to content

Commit ca82851

Browse files
Change identifier for import project channel
1 parent 664bbf8 commit ca82851

8 files changed

Lines changed: 37 additions & 54 deletions

File tree

core/che-core-api-core/src/main/java/org/eclipse/che/api/core/jsonrpc/impl/RequestDispatcher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void dispatch(String endpointId, JsonObject incomingJson) {
6464
LOG.debug("Extracted request method: " + method);
6565

6666
final RequestHandler handler = handlers.get(method);
67-
if(handler == null) {
67+
if (handler == null) {
6868
LOG.error("Handler not found: " + method);
6969
// TODO make a centralized standard errors structure
7070
transmitter.transmit(endpointId, error(-32601, "Method not found: " + method));
@@ -100,24 +100,24 @@ private <P, R> JsonElement response(String endpointId,
100100
Class<P> paramClass,
101101
Class<R> resultClass) {
102102

103-
R result;
103+
final R result;
104104

105-
if(paramClass != null) {
105+
if (paramClass != null) {
106106
final P param = DtoFactory.getInstance().createDtoFromJson(params.toString(), paramClass);
107107
result = handler.handleRequest(endpointId, param);
108108
} else {
109109
result = handler.handleRequest(endpointId);
110110
}
111111

112-
LOG.debug("Dispatch response: " + result);
112+
LOG.debug("Dispatch response: ", result);
113113

114-
if(result instanceof Void)
114+
if (result instanceof Void)
115115
return new JsonObject();
116-
else if(result instanceof String) {
116+
else if (result instanceof String) {
117117
JsonObject response = new JsonObject();
118118
response.addProperty("text", (String)result);
119119
return response;
120-
} else if(result instanceof Collection) { // list of DTO objects
120+
} else if (result instanceof Collection) { // list of DTO objects
121121
JsonArray valueArray = new JsonArray();
122122
((Collection)result).stream().filter(r -> r instanceof JsonSerializable).forEach(r -> {
123123
String resultString = DtoFactory.getInstance().toJson(r);

dashboard/src/app/projects/create-project/create-project.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export class CreateProjectController {
561561
this.createProjectSvc.setCurrentProgressStep(3);
562562

563563
var promise;
564-
var channel = null;
564+
let channel: string = null;
565565
// select mode (create or import)
566566
if (this.selectSourceOption === 'select-source-new' && this.templatesChoice === 'templates-wizard') {
567567

@@ -578,7 +578,7 @@ export class CreateProjectController {
578578
}
579579

580580
// websocket channel
581-
channel = 'importProject:output:' + workspaceId + ':' + projectName;
581+
channel = 'importProject:output';
582582

583583
// on import
584584
bus.subscribe(channel, (message: any) => {

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public interface CoreLocalizationConstant extends Messages {
263263
String importProjectButton();
264264

265265
@Key("importProject.importing")
266-
String importingProject();
266+
String importingProject(String projectName);
267267

268268
@Key("importProject.uriFieldTitle")
269269
String importProjectUriFieldTitle();

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectNotificationSubscriberImpl.java

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.projectimport.wizard;
1212

13-
import com.google.gwt.json.client.JSONObject;
14-
import com.google.gwt.json.client.JSONParser;
13+
import elemental.json.Json;
14+
import elemental.json.JsonObject;
15+
1516
import com.google.inject.Inject;
1617
import com.google.inject.Singleton;
1718

1819
import org.eclipse.che.api.promises.client.Operation;
1920
import org.eclipse.che.api.promises.client.OperationException;
2021
import org.eclipse.che.api.promises.client.PromiseError;
2122
import org.eclipse.che.ide.CoreLocalizationConstant;
22-
import org.eclipse.che.ide.api.app.AppContext;
2323
import org.eclipse.che.ide.api.machine.WsAgentStateController;
2424
import org.eclipse.che.ide.api.notification.NotificationManager;
2525
import org.eclipse.che.ide.api.notification.StatusNotification;
2626
import org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber;
27-
import org.eclipse.che.ide.commons.exception.UnmarshallerException;
2827
import org.eclipse.che.ide.util.loging.Log;
29-
import org.eclipse.che.ide.websocket.Message;
3028
import org.eclipse.che.ide.websocket.MessageBus;
3129
import org.eclipse.che.ide.websocket.WebSocketException;
30+
import org.eclipse.che.ide.websocket.rest.StringUnmarshallerWS;
3231
import org.eclipse.che.ide.websocket.rest.SubscriptionHandler;
3332

3433
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
@@ -48,7 +47,6 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub
4847
private final Operation<PromiseError> logErrorHandler;
4948
private final CoreLocalizationConstant locale;
5049
private final NotificationManager notificationManager;
51-
private final String workspaceId;
5250
private final WsAgentStateController wsAgentStateController;
5351

5452
private String wsChannel;
@@ -58,12 +56,10 @@ public class ProjectNotificationSubscriberImpl implements ProjectNotificationSub
5856

5957
@Inject
6058
public ProjectNotificationSubscriberImpl(CoreLocalizationConstant locale,
61-
AppContext appContext,
6259
NotificationManager notificationManager,
6360
WsAgentStateController wsAgentStateController) {
6461
this.locale = locale;
6562
this.notificationManager = notificationManager;
66-
this.workspaceId = appContext.getWorkspace().getId();
6763
this.wsAgentStateController = wsAgentStateController;
6864
this.logErrorHandler = new Operation<PromiseError>() {
6965
@Override
@@ -75,19 +71,32 @@ public void apply(PromiseError error) throws OperationException {
7571

7672
@Override
7773
public void subscribe(final String projectName) {
78-
notification = notificationManager.notify(locale.importingProject(), PROGRESS, FLOAT_MODE);
74+
notification = notificationManager.notify(locale.importingProject(projectName), PROGRESS, FLOAT_MODE);
7975
subscribe(projectName, notification);
8076
}
8177

8278
@Override
83-
public void subscribe(final String projectName, final StatusNotification existingNotification) {
84-
this.projectName = projectName;
85-
this.wsChannel = "importProject:output:" + workspaceId + ":" + projectName;
79+
public void subscribe(final String name, final StatusNotification existingNotification) {
80+
this.projectName = name;
81+
this.wsChannel = "importProject:output";
8682
this.notification = existingNotification;
87-
this.subscriptionHandler = new SubscriptionHandler<String>(new LineUnmarshaller()) {
83+
this.subscriptionHandler = new SubscriptionHandler<String>(new StringUnmarshallerWS()) {
8884
@Override
8985
protected void onMessageReceived(String result) {
90-
notification.setContent(result);
86+
JsonObject jsonObject = Json.parse(result);
87+
88+
if (jsonObject == null) {
89+
return;
90+
}
91+
92+
if (jsonObject.hasKey("project")) {
93+
projectName = jsonObject.getString("project");
94+
notification.setTitle(locale.importingProject(projectName));
95+
}
96+
97+
if (jsonObject.hasKey("line")) {
98+
notification.setContent(jsonObject.getString("line"));
99+
}
91100
}
92101

93102
@Override
@@ -153,25 +162,4 @@ public void apply(MessageBus messageBus) throws OperationException {
153162
}
154163
}).catchError(logErrorHandler);
155164
}
156-
157-
static class LineUnmarshaller implements org.eclipse.che.ide.websocket.rest.Unmarshallable<String> {
158-
private String line;
159-
160-
@Override
161-
public void unmarshal(Message response) throws UnmarshallerException {
162-
JSONObject jsonObject = JSONParser.parseStrict(response.getBody()).isObject();
163-
if (jsonObject == null) {
164-
return;
165-
}
166-
if (jsonObject.containsKey("line")) {
167-
line = jsonObject.get("line").isString().stringValue();
168-
}
169-
}
170-
171-
@Override
172-
public String getPayload() {
173-
return line;
174-
}
175-
}
176-
177165
}

ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ importLocalProject.openZipTitle = Select Zip archive to import:
145145
importProject.importButton = Import
146146
importProject.uriFieldTitle = URL:
147147
importProject.viewTitle = Import project
148-
importProject.importing = Importing project(s)
148+
importProject.importing = Importing project {0}
149149
importProject.message.success = Project {0} imported
150150
importProject.message.failure = Failed to import project {0}
151151
importProject.message.startWithWhiteSpace = The url can not start with a whitespace.

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,6 @@ private RegisteredProject doImportProject(String path, SourceStorage sourceStora
493493
sourceStorage.getLocation(), sourceStorage.getType()));
494494
}
495495

496-
// Preparing websocket output publisher to broadcast output of import process to the ide clients while importing
497-
// final LineConsumerFactory outputOutputConsumerFactory =
498-
// () -> new ProjectImportOutputWSLineConsumer(path, workspaceProjectsHolder.getWorkspaceId(), 300);
499-
500496
String normalizePath = (path.startsWith("/")) ? path : "/".concat(path);
501497
FolderEntry folder = asFolder(normalizePath);
502498
if (folder != null && !rewrite) {

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectOutputLineConsumerFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
import org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer;
1616

1717
/**
18-
* LineConsumerFactory dedicated to project related operations long output
18+
* {@link LineConsumerFactory} dedicated to project related operations long output
1919
* extended standard factory with setProjectName method to make it possible
2020
* change it runtime inside ProjectManager
2121
*
2222
* @author gazarenkov
2323
*/
2424
public class ProjectOutputLineConsumerFactory implements LineConsumerFactory {
2525

26-
private String projectName;
26+
private String projectName;
2727
private final String workspaceId;
28-
private final int delay;
28+
private final int delay;
2929

3030
public ProjectOutputLineConsumerFactory(String projectName, String workspaceId, int delay) {
3131
this.projectName = projectName;

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ public List<ProjectConfigDto> createBatchProjects(
232232

233233
List<ProjectConfigDto> result = new ArrayList<>(projectConfigList.size());
234234
final ProjectOutputLineConsumerFactory outputOutputConsumerFactory = new ProjectOutputLineConsumerFactory(workspace, 300);
235-
// () -> new ProjectImportOutputWSLineConsumer("BATCH", workspace, 300);
236235

237236
for (RegisteredProject registeredProject : projectManager.createBatchProjects(projectConfigList, rewrite, outputOutputConsumerFactory)) {
238237

0 commit comments

Comments
 (0)