Search in sources :

Example 21 with ProjectConfig

use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.

the class ProjectManagerWriteTest method testUpdateProjectWithPersistedAttributes.

@Test
public void testUpdateProjectWithPersistedAttributes() throws Exception {
    Map<String, List<String>> attributes = new HashMap<>();
    ProjectConfig pc = new NewProjectConfigImpl("/testUpdateProject", BaseProjectType.ID, null, "name", "descr", null, null, null);
    RegisteredProject p = pm.createProject(pc, null);
    assertEquals(BaseProjectType.ID, p.getType());
    assertEquals("name", p.getName());
    attributes.put("pt2-var2", new AttributeValue("updated").getList());
    ProjectConfig pc1 = new NewProjectConfigImpl("/testUpdateProject", "pt2", null, "updatedName", "descr", attributes, null, null);
    p = pm.updateProject(pc1);
    assertEquals("pt2", p.getType());
    assertEquals("updated", p.getAttributes().get("pt2-var2").get(0));
    assertEquals("updatedName", p.getName());
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 22 with ProjectConfig

use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.

the class ProjectManagerWriteTest method testCreateProject.

@Test
public void testCreateProject() throws Exception {
    Map<String, List<String>> attrs = new HashMap<>();
    List<String> v = new ArrayList<>();
    v.add("meV");
    attrs.put("var1", v);
    ProjectConfig config = DtoFactory.newDto(ProjectConfigDto.class).withPath("createProject").withName("create").withType("primary1").withDescription("description").withAttributes(attrs);
    pm.createProject(config, new HashMap<>());
    RegisteredProject project = pm.getProject("/createProject");
    assertTrue(project.getBaseFolder().getVirtualFile().exists());
    assertEquals("/createProject", project.getPath());
    assertEquals(2, project.getAttributeEntries().size());
    assertEquals("meV", project.getAttributeEntries().get("var1").getString());
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) HashMap(java.util.HashMap) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 23 with ProjectConfig

use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.

the class ProjectManagerWriteTest method testUpdateProjectWithProvidedAttributes.

@Test
public void testUpdateProjectWithProvidedAttributes() throws Exception {
    // SPECS: Project should be updated with problem code = 13 when value for required attribute is not initialized
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    ProjectConfig pc = new NewProjectConfigImpl("/testUpdateProject", "pt2", null, "name", "descr", attributes, null, null);
    pm.createProject(pc, null);
    pc = new NewProjectConfigImpl("/testUpdateProject", "pt3", null, "updatedName", "descr", attributes, null, null);
    RegisteredProject project = pm.updateProject(pc);
    final List<Problem> problems = project.getProblems();
    assertNotNull(problems);
    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) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) Test(org.junit.Test)

Example 24 with ProjectConfig

use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.

the class ProjectManager method doImportProject.

/** Note: Use {@link FileWatcherManager#suspend()} and {@link FileWatcherManager#resume()} while importing source code */
private RegisteredProject doImportProject(String path, SourceStorage sourceStorage, boolean rewrite, LineConsumerFactory lineConsumerFactory) throws ServerException, IOException, ForbiddenException, UnauthorizedException, ConflictException, NotFoundException {
    final ProjectImporter importer = importers.getImporter(sourceStorage.getType());
    if (importer == null) {
        throw new NotFoundException(format("Unable import sources project from '%s'. Sources type '%s' is not supported.", sourceStorage.getLocation(), sourceStorage.getType()));
    }
    String normalizePath = (path.startsWith("/")) ? path : "/".concat(path);
    FolderEntry folder = asFolder(normalizePath);
    if (folder != null && !rewrite) {
        throw new ConflictException(format("Project %s already exists ", path));
    }
    if (folder == null) {
        folder = getProjectsRoot().createFolder(normalizePath);
    }
    try {
        importer.importSources(folder, sourceStorage, lineConsumerFactory);
    } catch (final Exception e) {
        folder.remove();
        throw e;
    }
    final String name = folder.getPath().getName();
    for (ProjectConfig project : workspaceProjectsHolder.getProjects()) {
        if (normalizePath.equals(project.getPath())) {
            // TODO Needed for factory project importing with keepDir. It needs to find more appropriate solution
            List<String> innerProjects = projectRegistry.getProjects(normalizePath);
            for (String innerProject : innerProjects) {
                RegisteredProject registeredProject = projectRegistry.getProject(innerProject);
                projectRegistry.putProject(registeredProject, asFolder(registeredProject.getPath()), true, false);
            }
            RegisteredProject rp = projectRegistry.putProject(project, folder, true, false);
            workspaceProjectsHolder.sync(projectRegistry);
            return rp;
        }
    }
    RegisteredProject rp = projectRegistry.putProject(new NewProjectConfigImpl(normalizePath, name, BaseProjectType.ID, sourceStorage), folder, true, false);
    workspaceProjectsHolder.sync(projectRegistry);
    return rp;
}
Also used : ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) 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) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Example 25 with ProjectConfig

use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.

the class WorkspaceProjectsSyncer method sync.

/**
     * Synchronizes Project Config state on Agent and Master
     * @param projectRegistry project registry
     * @throws ServerException
     */
public final void sync(ProjectRegistry projectRegistry) throws ServerException {
    List<? extends ProjectConfig> remote = getProjects();
    // check on removed
    List<ProjectConfig> removed = new ArrayList<>();
    for (ProjectConfig r : remote) {
        if (projectRegistry.getProject(r.getPath()) == null)
            removed.add(r);
    }
    for (ProjectConfig r : removed) removeProject(r);
    // update or add
    for (RegisteredProject project : projectRegistry.getProjects()) {
        if (!project.isSynced() && !project.isDetected()) {
            final ProjectConfig config = new NewProjectConfigImpl(project.getPath(), project.getType(), project.getMixins(), project.getName(), project.getDescription(), project.getPersistableAttributes(), null, project.getSource());
            boolean found = false;
            for (ProjectConfig r : remote) {
                if (r.getPath().equals(project.getPath())) {
                    updateProject(config);
                    found = true;
                }
            }
            if (!found)
                addProject(config);
            project.setSync();
        }
    }
}
Also used : ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ArrayList(java.util.ArrayList)

Aggregations

ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)26 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)20 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)7 List (java.util.List)7 ConflictException (org.eclipse.che.api.core.ConflictException)6 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)5 Problem (org.eclipse.che.api.project.server.RegisteredProject.Problem)5 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)3 ServerException (org.eclipse.che.api.core.ServerException)3 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)3 File (java.io.File)2 IOException (java.io.IOException)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)2 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)2 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)2 ProjectImporter (org.eclipse.che.api.project.server.importer.ProjectImporter)2