Search in sources :

Example 6 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ResourceManager method asDto.

private NewProjectConfigDto asDto(MutableProjectConfig config) {
    final SourceStorage source = config.getSource();
    final SourceStorageDto sourceStorageDto = dtoFactory.createDto(SourceStorageDto.class).withType(source.getType()).withLocation(source.getLocation()).withParameters(source.getParameters());
    return dtoFactory.createDto(NewProjectConfigDto.class).withName(config.getName()).withPath(config.getPath()).withDescription(config.getDescription()).withSource(sourceStorageDto).withType(config.getType()).withMixins(config.getMixins()).withAttributes(config.getAttributes()).withOptions(config.getOptions());
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)

Example 7 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto 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 8 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method shouldThrowBadRequestExceptionAtCreatingBatchProjectsWhenConfigNotContainsPath.

@Test
public void shouldThrowBadRequestExceptionAtCreatingBatchProjectsWhenConfigNotContainsPath() throws Exception {
    //Path is mandatory field for NewProjectConfig
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfig config = createProjectConfigObject("project", null, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("BadRequestException should be thrown : path field is mandatory");
    } catch (BadRequestException e) {
        assertEquals(0, projectRegistry.getProjects().size());
    }
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ArrayList(java.util.ArrayList) BadRequestException(org.eclipse.che.api.core.BadRequestException) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 9 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method testCreateProjectWhenSourceCodeIsNotReachable.

@Test
public void testCreateProjectWhenSourceCodeIsNotReachable() throws Exception {
    final String projectPath = "/testProject";
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfigDto config = createProjectConfigObject("testProject1", projectPath, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("Exception should be thrown when source code is not reachable");
    } catch (Exception e) {
        assertEquals(0, projectRegistry.getProjects().size());
        assertNull(projectRegistry.getProject(projectPath));
        assertNull(pm.getProjectsRoot().getChild(projectPath));
    }
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 10 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProject.

@Test
public void testCreateBatchProjectsWithInnerProject() throws Exception {
    final String rootProjectPath = "/testProject1";
    final String innerProjectPath = "/testProject1/innerProject";
    final String importType = "importType1";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final String[] paths2 = { "innerProject/", "innerProject/folder2/", "innerProject/folder2/file2.txt" };
    final List<String> children1 = Arrays.asList(paths1);
    final List<String> children2 = Arrays.asList(paths2);
    final List<String> children = new ArrayList<>(children1);
    children.addAll(children2);
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType);
    NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source);
    NewProjectConfigDto config2 = createProjectConfigObject("innerProject", innerProjectPath, innerProjectType, null);
    config2.setAttributes(attributes);
    List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(rootProject);
    assertTrue(rootProjectFolder.getVirtualFile().exists());
    assertEquals(rootProjectPath, rootProject.getPath());
    checkChildrenFor(rootProjectFolder, children1);
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(rootProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Aggregations

SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)13 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)10 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 List (java.util.List)4 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 HashMap (java.util.HashMap)3 BadRequestException (org.eclipse.che.api.core.BadRequestException)3 Promise (org.eclipse.che.api.promises.client.Promise)3 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)2 Function (org.eclipse.che.api.promises.client.Function)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2