Search in sources :

Example 1 with Problem

use of org.eclipse.che.api.project.server.RegisteredProject.Problem in project che by eclipse.

the class ProjectManagerWriteTest method shouldSetBlankTypeAtCreatingBatchProjectsWhenConfigContainsUnregisteredProjectType.

@Test
public void shouldSetBlankTypeAtCreatingBatchProjectsWhenConfigContainsUnregisteredProjectType() throws Exception {
    // If declared primary PT is not registered, project is created as Blank, with Problem 12
    final String projectPath = "/testProject";
    final String projectType = "unregisteredProjectType";
    final NewProjectConfig config = createProjectConfigObject("projectName", projectPath, projectType, null);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    final RegisteredProject project = projectRegistry.getProject(projectPath);
    final List<Problem> problems = project.getProblems();
    checkProjectExist(projectPath);
    assertNotEquals(projectType, project.getType());
    assertEquals(1, problems.size());
    assertEquals(12, problems.get(0).code);
    assertEquals(1, projectRegistry.getProjects().size());
}
Also used : ArrayList(java.util.ArrayList) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 2 with Problem

use of org.eclipse.che.api.project.server.RegisteredProject.Problem in project che by eclipse.

the class ProjectManagerWriteTest method testConflictAttributesProjectCreateFailed.

@Test
public void testConflictAttributesProjectCreateFailed() throws Exception {
    // SPECS:
    // project will be created with problem code 13(Attribute name conflict)
    // when there are attributes with the same name in primary and mixin PT or between mixins
    final String path = "/testConflictAttributesProjectCreateFailed";
    final String projectTypeId = "pt2";
    final String mixin = "m2";
    final List<String> ms = new ArrayList<>(1);
    ms.add(mixin);
    ProjectConfig pc = new NewProjectConfigImpl(path, projectTypeId, ms, "name", "descr", null, null, null);
    pm.createProject(pc, null);
    final RegisteredProject project = projectRegistry.getProject(path);
    assertNotNull(project);
    assertNotNull(pm.getProjectsRoot().getChild(path));
    final List<String> mixins = project.getMixins();
    assertFalse(mixins.isEmpty());
    assertEquals(mixin, mixins.get(0));
    final List<Problem> problems = project.getProblems();
    assertNotNull(problems);
    assertFalse(problems.isEmpty());
    assertEquals(13, problems.get(0).code);
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ArrayList(java.util.ArrayList) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) Test(org.junit.Test)

Example 3 with Problem

use of org.eclipse.che.api.project.server.RegisteredProject.Problem in project che by eclipse.

the class ProjectManager method createBatchProjects.

/**
     * Create batch of projects according to their configurations.
     * <p/>
     * Notes: - a project will be created by importing when project configuration contains {@link SourceStorage} object,
     * otherwise this one will be created corresponding its {@link NewProjectConfig}:
     * <li> - {@link NewProjectConfig} object contains only one mandatory {@link NewProjectConfig#setPath(String)} field.
     * In this case Project will be created as project of {@link BaseProjectType} type </li>
     * <li> - a project will be created as project of {@link BaseProjectType} type with {@link Problem#code} = 12
     * when declared primary project type is not registered, </li>
     * <li> - a project will be created with {@link Problem#code} = 12 and without mixin project type
     * when declared mixin project type is not registered</li>
     * <li> - for creating a project by generator {@link NewProjectConfig#getOptions()} should be specified.</li>
     *
     * @param projectConfigList
     *         the list of configurations to create projects
     * @param rewrite
     *         whether rewrite or not (throw exception otherwise) if such a project exists
     * @return the list of new projects
     * @throws BadRequestException
     *         when {@link NewProjectConfig} object not contains mandatory {@link NewProjectConfig#setPath(String)} field.
     * @throws ConflictException
     *         when the same path project exists and {@code rewrite} is {@code false}
     * @throws ForbiddenException
     *         when trying to overwrite the project and this one contains at least one locked file
     * @throws NotFoundException
     *         when parent folder does not exist
     * @throws UnauthorizedException
     *         if user isn't authorized to access to location at importing source code
     * @throws ServerException
     *         if other error occurs
     */
public List<RegisteredProject> createBatchProjects(List<? extends NewProjectConfig> projectConfigList, boolean rewrite, ProjectOutputLineConsumerFactory lineConsumerFactory) throws BadRequestException, ConflictException, ForbiddenException, NotFoundException, ServerException, UnauthorizedException, IOException {
    fileWatcherManager.suspend();
    try {
        final List<RegisteredProject> projects = new ArrayList<>(projectConfigList.size());
        validateProjectConfigurations(projectConfigList, rewrite);
        final List<NewProjectConfig> sortedConfigList = projectConfigList.stream().sorted((config1, config2) -> config1.getPath().compareTo(config2.getPath())).collect(Collectors.toList());
        for (NewProjectConfig projectConfig : sortedConfigList) {
            RegisteredProject registeredProject;
            final String pathToProject = projectConfig.getPath();
            //creating project(by config or by importing source code)
            try {
                final SourceStorage sourceStorage = projectConfig.getSource();
                if (sourceStorage != null && !isNullOrEmpty(sourceStorage.getLocation())) {
                    doImportProject(pathToProject, sourceStorage, rewrite, lineConsumerFactory.setProjectName(projectConfig.getPath()));
                } else if (!isVirtualFileExist(pathToProject)) {
                    registeredProject = doCreateProject(projectConfig, projectConfig.getOptions());
                    projects.add(registeredProject);
                    continue;
                }
            } catch (Exception e) {
                if (!isVirtualFileExist(pathToProject)) {
                    //project folder is absent
                    rollbackCreatingBatchProjects(projects);
                    throw e;
                }
            }
            //update project
            if (isVirtualFileExist(pathToProject)) {
                try {
                    registeredProject = updateProject(projectConfig);
                } catch (Exception e) {
                    registeredProject = projectRegistry.putProject(projectConfig, asFolder(pathToProject), true, false);
                    final Problem problem = new Problem(NOT_UPDATED_PROJECT, "The project is not updated, caused by " + e.getLocalizedMessage());
                    registeredProject.getProblems().add(problem);
                }
            } else {
                registeredProject = projectRegistry.putProject(projectConfig, null, true, false);
            }
            projects.add(registeredProject);
        }
        return projects;
    } finally {
        fileWatcherManager.resume();
    }
}
Also used : LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) VirtualFileSystemProvider(org.eclipse.che.api.vfs.VirtualFileSystemProvider) Path(org.eclipse.che.api.vfs.Path) LoggerFactory(org.slf4j.LoggerFactory) ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) PreDestroy(javax.annotation.PreDestroy) FileWatcherManager(org.eclipse.che.api.vfs.watcher.FileWatcherManager) CreateProjectHandler(org.eclipse.che.api.project.server.handlers.CreateProjectHandler) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) LoggingUncaughtExceptionHandler(org.eclipse.che.commons.lang.concurrent.LoggingUncaughtExceptionHandler) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NOT_UPDATED_PROJECT(org.eclipse.che.api.core.ErrorCodes.NOT_UPDATED_PROJECT) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ProjectTypeResolution(org.eclipse.che.api.project.server.type.ProjectTypeResolution) BaseProjectType(org.eclipse.che.api.project.server.type.BaseProjectType) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) Inject(javax.inject.Inject) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Searcher(org.eclipse.che.api.vfs.search.Searcher) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) ConflictException(org.eclipse.che.api.core.ConflictException) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectType(org.eclipse.che.api.core.model.project.type.ProjectType) ServerException(org.eclipse.che.api.core.ServerException) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) FileWatcherNotificationListener(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationListener) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ArrayList(java.util.ArrayList) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) BadRequestException(org.eclipse.che.api.core.BadRequestException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException)

Example 4 with Problem

use of org.eclipse.che.api.project.server.RegisteredProject.Problem in project che by eclipse.

the class ProjectManagerWriteTest method testInvalidPTProjectCreateFailed.

@Test
public void testInvalidPTProjectCreateFailed() throws Exception {
    // SPECS:
    // project will be created as project of "blank" type
    // with problem code 12(Primary type "someType" is not registered. Base Project Type assigned.)
    // when primary project type is not registered in PT registry
    final String path = "/testInvalidPTProjectCreateFailed";
    ProjectConfig pc = new NewProjectConfigImpl(path, "invalid", null, "name", "descr", null, null, null);
    pm.createProject(pc, null);
    RegisteredProject project = projectRegistry.getProject(path);
    assertNotNull(project);
    assertNotNull(pm.getProjectsRoot().getChild(path));
    assertEquals(BaseProjectType.ID, project.getType());
    List<Problem> problems = project.getProblems();
    assertNotNull(problems);
    assertFalse(problems.isEmpty());
    assertEquals(1, problems.size());
    assertEquals(12, problems.get(0).code);
    //clean up
    project.getBaseFolder().getVirtualFile().delete();
    projectRegistry.removeProjects(path);
    assertNull(projectRegistry.getProject(path));
    // SPECS:
    // project will be created without mixin project type and
    // with problem code 12(Project type "someType" is not registered. Skipped.)
    // when mixin project type is not registered in PT registry
    List<String> ms = new ArrayList<>();
    ms.add("invalid");
    pc = new NewProjectConfigImpl(path, "blank", ms, "name", "descr", null, null, null);
    pm.createProject(pc, null);
    project = projectRegistry.getProject(path);
    assertNotNull(project);
    assertNotNull(pm.getProjectsRoot().getChild(path));
    assertTrue(project.getMixins().isEmpty());
    problems = project.getProblems();
    assertNotNull(problems);
    assertFalse(problems.isEmpty());
    assertEquals(1, problems.size());
    assertEquals(12, problems.get(0).code);
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ArrayList(java.util.ArrayList) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) Test(org.junit.Test)

Example 5 with Problem

use of org.eclipse.che.api.project.server.RegisteredProject.Problem in project che by eclipse.

the class ProjectManagerWriteTest method testCreateProjectWithRequiredProvidedAttributeWhenGivenProjectTypeHasNotGenerator.

@Test
public void testCreateProjectWithRequiredProvidedAttributeWhenGivenProjectTypeHasNotGenerator() throws Exception {
    // SPECS:
    // Project will be created with problem code = 13 (Value for required attribute is not initialized)
    // when project type has provided required attributes
    // but have not respective generator(CreateProjectHandler)
    final String path = "/testCreateProjectWithRequiredProvidedAttribute";
    final String projectTypeId = "pt4";
    final ProjectConfig pc = new NewProjectConfigImpl(path, projectTypeId, null, "name", "descr", null, null, null);
    pm.createProject(pc, null);
    final RegisteredProject project = projectRegistry.getProject(path);
    final List<VirtualFileEntry> children = project.getBaseFolder().getChildren();
    final List<Problem> problems = project.getProblems();
    assertNotNull(project);
    assertNotNull(pm.getProjectsRoot().getChild(path));
    assertEquals(projectTypeId, project.getType());
    assertTrue(children.isEmpty());
    assertTrue(project.getAttributes().isEmpty());
    assertFalse(problems.isEmpty());
    assertEquals(1, problems.size());
    assertEquals(13, problems.get(0).code);
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) Test(org.junit.Test)

Aggregations

Problem (org.eclipse.che.api.project.server.RegisteredProject.Problem)9 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)5 HashMap (java.util.HashMap)2 List (java.util.List)2 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)2 ProjectTypeDef (org.eclipse.che.api.project.server.type.ProjectTypeDef)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 PathMatcher (java.nio.file.PathMatcher)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Collectors (java.util.stream.Collectors)1 PreDestroy (javax.annotation.PreDestroy)1 Inject (javax.inject.Inject)1