All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marvelution.jira.plugins.sonar.web.action.AbstractSonarWebActionSupport Maven / Gradle / Ivy

/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution licenses this file to you 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 com.marvelution.jira.plugins.sonar.web.action;

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.jira.security.Permissions;
import com.atlassian.jira.util.I18nHelper;
import com.atlassian.jira.web.action.JiraWebActionSupport;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.marvelution.jira.plugins.sonar.service.SonarAssociationManager;

/**
 * Abstract Web Action for Sonar actions
 * 
 * @author Mark Rekveld
 * @since 1.1.0
 */
@SuppressWarnings("unchecked")
public abstract class AbstractSonarWebActionSupport extends JiraWebActionSupport {

	/**
	 * Default administrator redirect
	 */
	public static final String ADMIN_REDIRECT = "AdministerSonarAssociations.jspa";

	private static final long serialVersionUID = 1L;

	protected WebResourceManager webResourceManager;

	private SonarAssociationManager sonarAssociationManager;

	private PermissionManager permissionManager;

	/**
	 * Constructor
	 * 
	 * @param permissionManager the {@link PermissionManager} implementation
	 * @param sonarAssociationManager the {@link SonarAssociationManager} implementation
	 * @param webResourceManager the {@link WebResourceManager} implementation
	 */
	public AbstractSonarWebActionSupport(PermissionManager permissionManager,
											SonarAssociationManager sonarAssociationManager,
											WebResourceManager webResourceManager) {
		this.permissionManager = permissionManager;
		this.sonarAssociationManager = sonarAssociationManager;
		this.webResourceManager = webResourceManager;
	}

	/**
	 * Check if the users has the required permissions
	 * 
	 * @return true if so, false otherwise
	 */
	public boolean hasPermissions() {
		return permissionManager.hasPermission(Permissions.ADMINISTER, getRemoteUser());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String doDefault() throws Exception {
		if (hasPermissions()) {
			webResourceManager.requireResource("com.marvelution.jira.plugins.sonar:sonar-admin");
			return INPUT;
		} else {
			return PERMISSION_VIOLATION_RESULT;
		}
	}

	/**
	 * Get the {@link SonarAssociationManager}
	 * 
	 * @return the {@link SonarAssociationManager}
	 */
	public SonarAssociationManager getSonarAssociationManager() {
		return sonarAssociationManager;
	}

	/**
	 * Get the {@link I18nHelper}
	 * 
	 * @return the {@link I18nHelper}
	 */
	public I18nHelper getI18nHelper() {
		return ComponentManager.getInstance().getJiraAuthenticationContext().getI18nHelper();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getText(String i18nKey) {
		return getI18nHelper().getText(i18nKey);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getText(String i18nKey, String value) {
		return getI18nHelper().getText(i18nKey, value);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy