com.marvelution.jira.plugins.sonar.web.action.AbstractEditSonarAssociationWebActionSupport 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 org.apache.commons.lang.StringUtils;
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.project.Project;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.marvelution.jira.plugins.sonar.DefaultSonarAssociationImpl;
import com.marvelution.jira.plugins.sonar.service.SonarAssociation;
import com.marvelution.jira.plugins.sonar.service.SonarAssociationManager;
/**
* Abstract Web Action for Adding and Updating Sonar Associations
*
* @author Mark Rekveld
*/
@SuppressWarnings("unchecked")
public class AbstractEditSonarAssociationWebActionSupport extends AbstractSonarWebActionSupport {
private static final long serialVersionUID = 1L;
private SonarAssociation association;
private ProjectComponentManager projectComponentManager;
/**
* Constructor
*
* @param permissionManager the {@link PermissionManager} implementation
* @param sonarAssociationManager the {@link SonarAssociationManager} implementation
* @param webResourceManager the {@link WebResourceManager} implementation
* @param projectComponentManager the {@link ProjectComponentManager} implementation
*/
public AbstractEditSonarAssociationWebActionSupport(PermissionManager permissionManager,
SonarAssociationManager sonarAssociationManager,
WebResourceManager webResourceManager,
ProjectComponentManager projectComponentManager) {
super(permissionManager, sonarAssociationManager, webResourceManager);
association = new DefaultSonarAssociationImpl();
this.projectComponentManager = projectComponentManager;
}
/**
* {@inheritDoc}
*/
@Override
protected void doValidation() {
if (getProject() == null) {
addError("projectId", getText("sonar.config.projectid.required"));
}
if (getComponentId() > 0) {
try {
getProjectComponentManager().find(getComponentId());
} catch (EntityNotFoundException e) {
addError("componentId", getText("sonar.config.componentid.invalid"));
}
}
if (StringUtils.isBlank(getSonarServer())) {
addError("sonarServer", getText("sonar.config.server.required"));
} else if ((!(getSonarServer().startsWith("http://"))) && (!(getSonarServer().startsWith("https://")))) {
addError("sonarServer", getText("sonar.config.server.invalid", getSonarServer()));
}
if (StringUtils.isBlank(getSonarProject())) {
addError("sonarProject", getText("sonar.config.project.required"));
}
}
/**
* {@inheritDoc}
*/
@Override
public String doExecute() throws Exception {
if (hasAnyErrors()) {
return INPUT;
}
getSonarAssociationManager().put(getAssociation());
return getRedirect(ADMIN_REDIRECT);
}
/**
* @return the association
*/
public SonarAssociation getAssociation() {
return association;
}
/**
* @return the project
*/
public Project getProject() {
return getProjectManager().getProjectObj(getProjectId());
}
/**
* @return the Project Component
*/
public ProjectComponent getComponent() {
try {
return getProjectComponentManager().find(getComponentId());
} catch (EntityNotFoundException e) {
return null;
}
}
/**
* @return the associationId
*/
public Long getAssociationId() {
return association.getAssociationId();
}
/**
* @param associationId the associationId to set
*/
public void setAssociationId(Long associationId) {
association.setAssociationId(associationId);
}
/**
* @return the projectId
*/
public Long getProjectId() {
return association.getProjectId();
}
/**
* @param projectId the projectId to set
*/
public void setProjectId(Long projectId) {
association.setProjectId(projectId);
}
/**
* @return the componentId
*/
public Long getComponentId() {
return association.getComponentId();
}
/**
* @param componentId the componentId to set
*/
public void setComponentId(Long componentId) {
association.setComponentId(componentId);
}
/**
* @return the sonarServer
*/
public String getSonarServer() {
return association.getSonarServer();
}
/**
* @param sonarServer the sonarServer
*/
public void setSonarServer(String sonarServer) {
association.setSonarServer(sonarServer);
}
/**
* @return the sonarProject
*/
public String getSonarProject() {
return association.getSonarProject();
}
/**
* @param sonarProject the sonarProject
*/
public void setSonarProject(String sonarProject) {
association.setSonarProject(sonarProject);
}
/**
* 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;
}
}