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());
}
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());
}
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);
}
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;
}
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();
}
}
}
Aggregations