Search in sources :

Example 1 with IdeDto

use of org.eclipse.che.api.factory.shared.dto.IdeDto in project che by eclipse.

the class FactoryBuilderTest method prepareFactory.

private static FactoryDto prepareFactory() {
    ProjectConfigDto project = dto.createDto(ProjectConfigDto.class).withSource(dto.createDto(SourceStorageDto.class).withType("git").withLocation("location")).withType("type").withAttributes(singletonMap("key", singletonList("value"))).withDescription("description").withName("name").withPath("/path");
    EnvironmentDto environment = dto.createDto(EnvironmentDto.class).withRecipe(newDto(EnvironmentRecipeDto.class).withType("compose").withContentType("application/x-yaml").withContent("some content")).withMachines(singletonMap("devmachine", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L))));
    WorkspaceConfigDto workspaceConfig = dto.createDto(WorkspaceConfigDto.class).withProjects(singletonList(project)).withCommands(singletonList(dto.createDto(CommandDto.class).withName("command1").withType("maven").withCommandLine("mvn test"))).withDefaultEnv("env1").withEnvironments(singletonMap("test", environment));
    IdeDto ide = dto.createDto(IdeDto.class).withOnAppClosed(dto.createDto(OnAppClosedDto.class).withActions(singletonList(dto.createDto(IdeActionDto.class).withId("warnOnClose")))).withOnAppLoaded(dto.createDto(OnAppLoadedDto.class).withActions(asList(dto.createDto(IdeActionDto.class).withId("newProject"), dto.createDto(IdeActionDto.class).withId("openWelcomePage").withProperties(ImmutableMap.of("authenticatedTitle", "Greeting title for authenticated users", "authenticatedContentUrl", "http://example.com/content.url"))))).withOnProjectsLoaded(dto.createDto(OnProjectsLoadedDto.class).withActions(asList(dto.createDto(IdeActionDto.class).withId("openFile").withProperties(singletonMap("file", "pom.xml")), dto.createDto(IdeActionDto.class).withId("run"), dto.createDto(IdeActionDto.class).withId("findReplace").withProperties(ImmutableMap.of("in", "src/main/resources/consts2.properties", "find", "OLD_VALUE_2", "replace", "NEW_VALUE_2", "replaceMode", "mode")))));
    return dto.createDto(FactoryDto.class).withV("4.0").withWorkspace(workspaceConfig).withCreator(dto.createDto(AuthorDto.class).withEmail("email").withName("name")).withPolicies(dto.createDto(PoliciesDto.class).withReferer("referrer").withSince(123L).withUntil(123L)).withButton(dto.createDto(ButtonDto.class).withType(Button.Type.LOGO).withAttributes(dto.createDto(ButtonAttributesDto.class).withColor("color").withCounter(true).withLogo("logo").withStyle("style"))).withIde(ide);
}
Also used : ButtonAttributesDto(org.eclipse.che.api.factory.shared.dto.ButtonAttributesDto) OnAppLoadedDto(org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)

Example 2 with IdeDto

use of org.eclipse.che.api.factory.shared.dto.IdeDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed.

@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile"));
    IdeDto ide = newDto(IdeDto.class).withOnAppClosed(newDto(OnAppClosedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 3 with IdeDto

use of org.eclipse.che.api.factory.shared.dto.IdeDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded.

@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("findReplace"));
    IdeDto ide = newDto(IdeDto.class).withOnAppLoaded(newDto(OnAppLoadedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 4 with IdeDto

use of org.eclipse.che.api.factory.shared.dto.IdeDto in project che by eclipse.

the class DtoConverter method asDto.

public static IdeDto asDto(Ide ide) {
    final IdeDto ideDto = newDto(IdeDto.class);
    final OnAppClosed onAppClosed = ide.getOnAppClosed();
    final OnAppLoaded onAppLoaded = ide.getOnAppLoaded();
    final OnProjectsLoaded onProjectsLoaded = ide.getOnProjectsLoaded();
    if (onAppClosed != null) {
        ideDto.withOnAppClosed(newDto(OnAppClosedDto.class).withActions(asDto(onAppClosed.getActions())));
    }
    if (onAppLoaded != null) {
        ideDto.withOnAppLoaded(newDto(OnAppLoadedDto.class).withActions(asDto(onAppLoaded.getActions())));
    }
    if (onProjectsLoaded != null) {
        ideDto.withOnProjectsLoaded(newDto(OnProjectsLoadedDto.class).withActions(asDto(onProjectsLoaded.getActions())));
    }
    return ideDto;
}
Also used : IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) OnAppClosed(org.eclipse.che.api.core.model.factory.OnAppClosed) OnProjectsLoaded(org.eclipse.che.api.core.model.factory.OnProjectsLoaded) OnAppLoaded(org.eclipse.che.api.core.model.factory.OnAppLoaded)

Example 5 with IdeDto

use of org.eclipse.che.api.factory.shared.dto.IdeDto in project che by eclipse.

the class FactoryBaseValidator method validateProjectActions.

/**
     * Validates IDE actions
     *
     * @param factory
     *         factory to validate
     * @throws BadRequestException
     *         when factory actions is invalid
     */
protected void validateProjectActions(FactoryDto factory) throws BadRequestException {
    final IdeDto ide = factory.getIde();
    if (ide == null) {
        return;
    }
    final List<IdeActionDto> applicationActions = new ArrayList<>();
    if (ide.getOnAppClosed() != null) {
        applicationActions.addAll(ide.getOnAppClosed().getActions());
    }
    if (ide.getOnAppLoaded() != null) {
        applicationActions.addAll(ide.getOnAppLoaded().getActions());
    }
    for (IdeActionDto applicationAction : applicationActions) {
        String id = applicationAction.getId();
        if ("openFile".equals(id) || "findReplace".equals(id) || "runCommand".equals(id) || "newTerminal".equals(id)) {
            throw new BadRequestException(format(FactoryConstants.INVALID_ACTION_SECTION, id));
        }
    }
    final OnAppLoadedDto onAppLoaded = ide.getOnAppLoaded();
    if (onAppLoaded != null) {
        for (IdeActionDto action : onAppLoaded.getActions()) {
            final Map<String, String> properties = action.getProperties();
            if ("openWelcomePage".equals(action.getId()) && isNullOrEmpty(properties.get("greetingContentUrl"))) {
                throw new BadRequestException(FactoryConstants.INVALID_WELCOME_PAGE_ACTION);
            }
        }
    }
    final OnProjectsLoadedDto onLoaded = ide.getOnProjectsLoaded();
    if (onLoaded != null) {
        final List<IdeActionDto> onProjectOpenedActions = onLoaded.getActions();
        for (IdeActionDto applicationAction : onProjectOpenedActions) {
            final String id = applicationAction.getId();
            final Map<String, String> properties = applicationAction.getProperties();
            switch(id) {
                case "openFile":
                    if (isNullOrEmpty(properties.get("file"))) {
                        throw new BadRequestException(FactoryConstants.INVALID_OPENFILE_ACTION);
                    }
                    break;
                case "runCommand":
                    if (isNullOrEmpty(properties.get("name"))) {
                        throw new BadRequestException(FactoryConstants.INVALID_RUNCOMMAND_ACTION);
                    }
                    break;
                case "findReplace":
                    if (isNullOrEmpty(properties.get("in")) || isNullOrEmpty(properties.get("find")) || isNullOrEmpty(properties.get("replace"))) {
                        throw new BadRequestException(FactoryConstants.INVALID_FIND_REPLACE_ACTION);
                    }
                    break;
            }
        }
    }
}
Also used : OnAppLoadedDto(org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) ArrayList(java.util.ArrayList) BadRequestException(org.eclipse.che.api.core.BadRequestException) OnProjectsLoadedDto(org.eclipse.che.api.factory.shared.dto.OnProjectsLoadedDto)

Aggregations

IdeDto (org.eclipse.che.api.factory.shared.dto.IdeDto)11 IdeActionDto (org.eclipse.che.api.factory.shared.dto.IdeActionDto)10 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)8 Test (org.testng.annotations.Test)8 HashMap (java.util.HashMap)3 OnAppLoadedDto (org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto)3 ArrayList (java.util.ArrayList)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 OnAppClosed (org.eclipse.che.api.core.model.factory.OnAppClosed)1 OnAppLoaded (org.eclipse.che.api.core.model.factory.OnAppLoaded)1 OnProjectsLoaded (org.eclipse.che.api.core.model.factory.OnProjectsLoaded)1 ButtonAttributesDto (org.eclipse.che.api.factory.shared.dto.ButtonAttributesDto)1 OnProjectsLoadedDto (org.eclipse.che.api.factory.shared.dto.OnProjectsLoadedDto)1 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)1 EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)1 EnvironmentRecipeDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)1 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)1 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)1