jetbrains.buildServer.projectPush.ProjectPushSettingsController.java Source code

Java tutorial

Introduction

Here is the source code for jetbrains.buildServer.projectPush.ProjectPushSettingsController.java

Source

/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.projectPush;

import jetbrains.buildServer.controllers.BaseController;
import jetbrains.buildServer.serverSide.ProjectManager;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import jetbrains.buildServer.web.openapi.WebControllerManager;
import jetbrains.buildServer.web.util.ProjectHierarchyBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Evgeniy.Koshkin
 */
public class ProjectPushSettingsController extends BaseController {

    public static final String PATH = "/app/push/settings";

    @NotNull
    private final ProjectPushSettingsStorage mySettings;
    @NotNull
    private final ProjectManager myProjectManager;
    @NotNull
    private final PluginDescriptor myPluginDescriptor;

    public ProjectPushSettingsController(@NotNull WebControllerManager web,
            @NotNull final ProjectPushSettingsStorage settings, @NotNull ProjectManager projectManager,
            @NotNull PluginDescriptor pluginDescriptor) {
        mySettings = settings;
        myProjectManager = projectManager;
        myPluginDescriptor = pluginDescriptor;
        web.registerController(PATH, this);
    }

    @Nullable
    @Override
    protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
            throws Exception {
        if (!isGet(request))
            return null;

        final String disable = request.getParameter("disable");
        if (disable != null) {
            mySettings.setDisabled(Boolean.parseBoolean(disable));
        }

        final String sandboxProjectId = request.getParameter("sandboxProjectId");
        if (sandboxProjectId != null && !sandboxProjectId.isEmpty())
            mySettings.setSandboxProjectId(sandboxProjectId);

        final ModelAndView view = new ModelAndView(myPluginDescriptor.getPluginResourcesPath("admin-page.jsp"));
        view.getModel().put("settings",
                new ProjectPushSettingsBean(
                        myProjectManager.findProjectByExternalId(mySettings.getSandboxProjectId()),
                        mySettings.isDisabled()));
        view.getModel().put("projects", ProjectHierarchyBean.getProjectsFor(myProjectManager));
        return view;
    }
}