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

com.marvelution.jira.plugins.sonar.web.action.AdministerSonarAssociations 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 java.util.Collection;

import com.atlassian.jira.bc.EntityNotFoundException;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import com.atlassian.jira.bc.project.component.ProjectComponentManager;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.marvelution.jira.plugins.sonar.service.SonarAssociation;
import com.marvelution.jira.plugins.sonar.service.SonarAssociationManager;

/**
 * WebAction to view SonarAssocations
 * 
 * @author Mark Rekveld
 */
@SuppressWarnings("unchecked")
public class AdministerSonarAssociations extends AbstractSonarWebActionSupport {

	private static final long serialVersionUID = 1L;

	private ProjectComponentManager projectComponentManager;

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

	/**
	 * The default Success action method
	 * 
	 * @return the Result Name
	 * @throws Exception in case of method execution errors
	 */
	public String doSuccess() throws Exception {
		if (hasPermissions()) {
			return SUCCESS;
		} else {
			return PERMISSION_VIOLATION_RESULT;
		}
	}

	/**
	 * Get the {@link Collection} of configured {@link SonarAssociation}s
	 * 
	 * @return the {@link Collection} of configured {@link SonarAssociation}s
	 */
	public Collection getSonarAssociations() {
		return getSonarAssociationManager().getSonarAssociations();
	}

	
	/**
	 * Getter for projectComponentManager
	 * 
	 * @return the projectComponentManager
	 */
	public ProjectComponentManager getProjectComponentManager() {
		return projectComponentManager;
	}

	
	/**
	 * Setter for projectComponentManager
	 * 
	 * @param projectComponentManager the projectComponentManager to set
	 */
	public void setProjectComponentManager(ProjectComponentManager projectComponentManager) {
		this.projectComponentManager = projectComponentManager;
	}

	/**
	 * @param componentId the componentId
	 * @return the Project Component, may be null
	 */
	public ProjectComponent getProjectComponent(Long componentId) {
		try {
			return getProjectComponentManager().find(componentId);
		} catch (EntityNotFoundException e) {
			return null;
		}
	}

	/**
	 * Get the Action for use in velocity templates
	 * 
	 * @return this
	 */
	public AdministerSonarAssociations getAction() {
		return this;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy