Search in sources :

Example 1 with OnAppLoadedDto

use of org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto 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

ArrayList (java.util.ArrayList)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 IdeActionDto (org.eclipse.che.api.factory.shared.dto.IdeActionDto)1 IdeDto (org.eclipse.che.api.factory.shared.dto.IdeDto)1 OnAppLoadedDto (org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto)1 OnProjectsLoadedDto (org.eclipse.che.api.factory.shared.dto.OnProjectsLoadedDto)1