Search in sources :

Example 6 with NewProjectConfig

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());
    }
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 7 with NewProjectConfig

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());
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 8 with NewProjectConfig

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());
}
Also used : MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) NewProjectConfigImpl(org.eclipse.che.ide.api.project.NewProjectConfigImpl) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 9 with NewProjectConfig

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);
}
Also used : NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) NewProjectConfigImpl(org.eclipse.che.ide.api.project.NewProjectConfigImpl) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 10 with NewProjectConfig

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

Aggregations

NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)23 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)14 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)8 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)8 ConflictException (org.eclipse.che.api.core.ConflictException)6 BadRequestException (org.eclipse.che.api.core.BadRequestException)5 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Problem (org.eclipse.che.api.project.server.RegisteredProject.Problem)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)3 ServerException (org.eclipse.che.api.core.ServerException)3 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)3 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 String.format (java.lang.String.format)1 PathMatcher (java.nio.file.PathMatcher)1