Search in sources :

Example 1 with Message

use of org.eclipse.che.ide.websocket.Message in project che by eclipse.

the class GitServiceClientImpl method add.

@Override
public void add(DevMachine devMachine, ProjectConfig project, boolean update, @Nullable List<String> filePattern, RequestCallback<Void> callback) throws WebSocketException {
    AddRequest addRequest = dtoFactory.createDto(AddRequest.class).withUpdate(update);
    if (filePattern == null) {
        addRequest.setFilePattern(AddRequest.DEFAULT_PATTERN);
    } else {
        addRequest.setFilePattern(filePattern);
    }
    String url = ADD + "?projectPath=" + project.getPath();
    MessageBuilder builder = new MessageBuilder(POST, url);
    builder.data(dtoFactory.toJson(addRequest)).header(CONTENTTYPE, APPLICATION_JSON);
    Message message = builder.build();
    sendMessageToWS(message, callback);
}
Also used : AddRequest(org.eclipse.che.api.git.shared.AddRequest) RemoteAddRequest(org.eclipse.che.api.git.shared.RemoteAddRequest) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) Message(org.eclipse.che.ide.websocket.Message)

Example 2 with Message

use of org.eclipse.che.ide.websocket.Message in project che by eclipse.

the class NavigateToFilePresenter method onFileNameChanged.

@Override
public void onFileNameChanged(String fileName) {
    if (fileName.isEmpty()) {
        view.showItems(new ArrayList<ItemReference>());
        return;
    }
    // add '*' to allow search files by first letters
    final String url = SEARCH_URL + "/?name=" + URL.encodePathSegment(fileName + "*");
    final Message message = new MessageBuilder(GET, url).header(ACCEPT, APPLICATION_JSON).build();
    final Unmarshallable<List<ItemReference>> unmarshaller = dtoUnmarshallerFactory.newWSListUnmarshaller(ItemReference.class);
    try {
        wsMessageBus.send(message, new RequestCallback<List<ItemReference>>(unmarshaller) {

            @Override
            protected void onSuccess(List<ItemReference> result) {
                view.showItems(result);
            }

            @Override
            protected void onFailure(Throwable exception) {
                Log.error(getClass(), exception);
            }
        });
    } catch (WebSocketException e) {
        Log.error(getClass(), e);
    }
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Message

use of org.eclipse.che.ide.websocket.Message in project che by eclipse.

the class ProjectServiceClientImpl method importProject.

/** {@inheritDoc} */
@Override
public Promise<Void> importProject(final Path path, final SourceStorageDto source) {
    return createFromAsyncRequest(callback -> {
        final String url = PROJECT + IMPORT + path(path.toString());
        final Message message = new MessageBuilder(POST, url).data(dtoFactory.toJson(source)).header(CONTENTTYPE, APPLICATION_JSON).build();
        wsAgentStateController.getMessageBus().then(messageBus -> {
            try {
                messageBus.send(message, new RequestCallback<Void>() {

                    @Override
                    protected void onSuccess(Void result) {
                        callback.onSuccess(result);
                    }

                    @Override
                    protected void onFailure(Throwable exception) {
                        callback.onFailure(exception);
                    }
                });
            } catch (WebSocketException e) {
                callback.onFailure(e);
            }
        }).catchError(error -> {
            callback.onFailure(error.getCause());
        });
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) AsyncRequestFactory(org.eclipse.che.ide.rest.AsyncRequestFactory) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) Inject(com.google.inject.Inject) RequestCallback(org.eclipse.che.ide.websocket.rest.RequestCallback) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) DELETE(com.google.gwt.http.client.RequestBuilder.DELETE) Promise(org.eclipse.che.api.promises.client.Promise) AppContext(org.eclipse.che.ide.api.app.AppContext) Map(java.util.Map) URL(com.google.gwt.http.client.URL) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) CONTENT_TYPE(org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE) DtoUnmarshallerFactory(org.eclipse.che.ide.rest.DtoUnmarshallerFactory) DtoFactory(org.eclipse.che.ide.dto.DtoFactory) LoaderFactory(org.eclipse.che.ide.ui.loaders.request.LoaderFactory) CONTENTTYPE(org.eclipse.che.ide.rest.HTTPHeader.CONTENTTYPE) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) APPLICATION_JSON(org.eclipse.che.ide.MimeType.APPLICATION_JSON) WsAgentStateController(org.eclipse.che.ide.api.machine.WsAgentStateController) StringUnmarshaller(org.eclipse.che.ide.rest.StringUnmarshaller) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) PUT(com.google.gwt.http.client.RequestBuilder.PUT) ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) POST(com.google.gwt.http.client.RequestBuilder.POST) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) List(java.util.List) CopyOptions(org.eclipse.che.api.project.shared.dto.CopyOptions) MimeType(org.eclipse.che.ide.MimeType) ACCEPT(org.eclipse.che.ide.rest.HTTPHeader.ACCEPT) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) Path(org.eclipse.che.ide.resource.Path) UrlBuilder(org.eclipse.che.ide.rest.UrlBuilder) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) RequestCallback(org.eclipse.che.ide.websocket.rest.RequestCallback) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException)

Example 4 with Message

use of org.eclipse.che.ide.websocket.Message in project che by eclipse.

the class GitServiceClientImpl method fetch.

@Override
public void fetch(DevMachine devMachine, ProjectConfigDto project, String remote, List<String> refspec, boolean removeDeletedRefs, RequestCallback<String> callback) throws WebSocketException {
    FetchRequest fetchRequest = dtoFactory.createDto(FetchRequest.class).withRefSpec(refspec).withRemote(remote).withRemoveDeletedRefs(removeDeletedRefs);
    String url = FETCH + "?projectPath=" + project.getPath();
    MessageBuilder builder = new MessageBuilder(POST, url);
    builder.data(dtoFactory.toJson(fetchRequest)).header(CONTENTTYPE, APPLICATION_JSON);
    Message message = builder.build();
    sendMessageToWS(message, callback);
}
Also used : MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) Message(org.eclipse.che.ide.websocket.Message) FetchRequest(org.eclipse.che.api.git.shared.FetchRequest)

Example 5 with Message

use of org.eclipse.che.ide.websocket.Message in project che by eclipse.

the class GitServiceClientImpl method cloneRepository.

@Override
public void cloneRepository(DevMachine devMachine, ProjectConfigDto project, String remoteUri, String remoteName, RequestCallback<RepoInfo> callback) throws WebSocketException {
    CloneRequest cloneRequest = dtoFactory.createDto(CloneRequest.class).withRemoteName(remoteName).withRemoteUri(remoteUri).withWorkingDir(project.getPath());
    String params = "?projectPath=" + project.getPath();
    String url = CLONE + params;
    MessageBuilder builder = new MessageBuilder(POST, url);
    builder.data(dtoFactory.toJson(cloneRequest)).header(CONTENTTYPE, APPLICATION_JSON).header(ACCEPT, APPLICATION_JSON);
    Message message = builder.build();
    sendMessageToWS(message, callback);
}
Also used : MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) Message(org.eclipse.che.ide.websocket.Message) CloneRequest(org.eclipse.che.api.git.shared.CloneRequest)

Aggregations

Message (org.eclipse.che.ide.websocket.Message)7 MessageBuilder (org.eclipse.che.ide.websocket.MessageBuilder)7 List (java.util.List)2 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)2 WebSocketException (org.eclipse.che.ide.websocket.WebSocketException)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 DELETE (com.google.gwt.http.client.RequestBuilder.DELETE)1 POST (com.google.gwt.http.client.RequestBuilder.POST)1 PUT (com.google.gwt.http.client.RequestBuilder.PUT)1 URL (com.google.gwt.http.client.URL)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AddRequest (org.eclipse.che.api.git.shared.AddRequest)1 CloneRequest (org.eclipse.che.api.git.shared.CloneRequest)1 FetchRequest (org.eclipse.che.api.git.shared.FetchRequest)1 RemoteAddRequest (org.eclipse.che.api.git.shared.RemoteAddRequest)1 CopyOptions (org.eclipse.che.api.project.shared.dto.CopyOptions)1 MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)1 SourceEstimation (org.eclipse.che.api.project.shared.dto.SourceEstimation)1