use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectRegistry method setProjectType.
/* ------------------------------------------ */
/* to use from extension */
/* ------------------------------------------ */
/**
* Extension writer should call this method to apply changes which (supposedly) change
* Attributes defined with particular Project Type
* If incoming Project Type is primary and:
* - If the folder located on projectPath is a Project, its Primary PT will be converted to incoming PT
* - If the folder located on projectPath is NOT a Project the folder will be converted to "detected" Project with incoming Primary PT
* If incoming Project Type is mixin and:
* - If the folder located on projectPath is a Project, this PT will be added (if not already there) to its Mixin PTs
* - If the folder located on projectPath is NOT a Project - ConflictException will be thrown
* For example:
* - extension code knows that particular file content is used by Value Provider
* so this method should be called when content of this file changed to check
* and update attributes.
* OR
* If Extension writer wants to force initializing folder to be Project
* For example:
* - extension code knows that particular folder inside should (or may) be treated
* as sub-project of same as "parent" project type
*
* @param projectPath
* absolute project path
* @param type
* type to be updated or added
* @param asMixin
* whether the type supposed to be mixin (true) or primary (false)
* @return refreshed project
* @throws ConflictException
* @throws NotFoundException
* @throws ServerException
*/
public RegisteredProject setProjectType(String projectPath, String type, boolean asMixin) throws ConflictException, NotFoundException, ServerException {
final RegisteredProject project = getProject(projectPath);
final NewProjectConfig conf;
List<String> newMixins = new ArrayList<>();
if (project == null) {
if (asMixin) {
throw new ConflictException("Can not assign as mixin type '" + type + "' since the " + projectPath + " is not a project.");
} else {
final String path = absolutizePath(projectPath);
final String name = Path.of(projectPath).getName();
conf = new NewProjectConfigImpl(path, type, newMixins, name, name, null, null, null);
return putProject(conf, root.getChildFolder(path), true, true);
}
} else {
newMixins = project.getMixins();
String newType = project.getType();
if (asMixin) {
if (!newMixins.contains(type)) {
newMixins.add(type);
}
} else {
newType = type;
}
conf = new NewProjectConfigImpl(project.getPath(), newType, newMixins, project.getName(), project.getDescription(), project.getAttributes(), null, project.getSource());
return putProject(conf, project.getBaseFolder(), true, project.isDetected());
}
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectRegistry method removeProjectType.
/**
* Extension writer should call this method to apply changes which supposedly
* make the Project no longer have particular Project Type.
* In a case of removing primary project type:
* - if the project was NOT detected BASE Project Type will be set as primary
* - if the project was detected it will be converted back to the folder
* For example:
* - extension code knows that removing some file inside project's file system
* will (or may) cause removing particular project type
*
* @param projectPath
* project path
* @param type
* project type
* @return refreshed project or null if such a project not found or was removed
* @throws ConflictException
* @throws ForbiddenException
* @throws NotFoundException
* @throws ServerException
*/
public RegisteredProject removeProjectType(String projectPath, String type) throws ConflictException, ForbiddenException, NotFoundException, ServerException {
final RegisteredProject project = getProject(projectPath);
if (project == null) {
return null;
}
List<String> newMixins = project.getMixins();
String newType = project.getType();
if (newMixins.contains(type)) {
newMixins.remove(type);
} else if (newType.equals(type)) {
if (project.isDetected()) {
projects.remove(project.getPath());
return null;
}
newType = BaseProjectType.ID;
}
final NewProjectConfig conf = new NewProjectConfigImpl(project.getPath(), newType, newMixins, project.getName(), project.getDescription(), project.getAttributes(), null, project.getSource());
return putProject(conf, project.getBaseFolder(), true, project.isDetected());
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectWizardPresenter method onProjectTemplateSelected.
@Override
public void onProjectTemplateSelected(ProjectTemplateDescriptor projectTemplate) {
final MutableProjectConfig dataObject = wizard.getDataObject();
wizard = importWizard == null ? importWizard = createDefaultWizard(dataObject, IMPORT) : importWizard;
wizard.navigateToFirst();
// set dataObject's values from projectTemplate
final NewProjectConfig newProjectConfig = new NewProjectConfigImpl(projectTemplate);
dataObject.setType(newProjectConfig.getType());
dataObject.setSource(newProjectConfig.getSource());
dataObject.setAttributes(newProjectConfig.getAttributes());
dataObject.setOptions(newProjectConfig.getOptions());
dataObject.setCommands(projectTemplate.getCommands());
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class CategoriesPagePresenter method updateProjectConfigs.
private void updateProjectConfigs(String newProjectPath, ProjectTemplateDescriptor projectTemplate) {
final List<NewProjectConfigDto> configDtoList = projectTemplate.getProjects();
if (newProjectPath.equals("/")) {
return;
}
final String templatePath = projectTemplate.getPath();
final List<NewProjectConfig> updatedConfigs = new ArrayList<>(configDtoList.size());
for (NewProjectConfigDto configDto : configDtoList) {
final NewProjectConfig newConfig = new NewProjectConfigImpl(configDto);
final String projectPath = configDto.getPath();
if (projectPath.startsWith(templatePath)) {
final String path = projectPath.replaceFirst(templatePath, newProjectPath);
newConfig.setPath(path);
}
updatedConfigs.add(newConfig);
}
dataObject.setProjects(updatedConfigs);
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig 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());
}
}
Aggregations