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