com.marvelution.jira.plugins.sonar.panels.SonarProjectTabPanel 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.panels;
import java.util.HashMap;
import java.util.Map;
import com.atlassian.jira.plugin.projectpanel.impl.AbstractProjectTabPanel;
import com.atlassian.jira.project.browse.BrowseContext;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.jira.security.Permissions;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.marvelution.jira.plugins.sonar.service.SonarAssociation;
import com.marvelution.jira.plugins.sonar.service.SonarAssociationManager;
import com.marvelution.jira.plugins.sonar.service.SonarPanelLayoutManager;
import com.marvelution.jira.plugins.sonar.utils.SonarGadgetUtils;
/**
* Tabpanel to show Sonar data
*
* @author Mark Rekveld
*/
public class SonarProjectTabPanel extends AbstractProjectTabPanel {
private final SonarAssociationManager associationManager;
private final SonarPanelLayoutManager sonarPanelLayoutManager;
private final PermissionManager permissionManager;
private final WebResourceManager webResourceManager;
private final SonarGadgetUtils sonarGadgetUtils;
/**
* Constructor
*
* @param authenticationContext the {@link JiraAuthenticationContext} implementation
* @param associationManager the {@link SonarAssociationManager} implementation
* @param sonarPanelLayoutManager the {@link SonarPanelLayoutManager} implementation
* @param permissionManager the {@link PermissionManager} implementation
* @param webResourceManager the {@link WebResourceManager} implementation
* @param sonarGadgetUtils the {@link SonarGadgetUtils} helper class
*/
public SonarProjectTabPanel(JiraAuthenticationContext authenticationContext,
SonarAssociationManager associationManager,
SonarPanelLayoutManager sonarPanelLayoutManager, PermissionManager permissionManager,
WebResourceManager webResourceManager, SonarGadgetUtils sonarGadgetUtils) {
super(authenticationContext);
this.associationManager = associationManager;
this.sonarPanelLayoutManager = sonarPanelLayoutManager;
this.permissionManager = permissionManager;
this.webResourceManager = webResourceManager;
this.sonarGadgetUtils = sonarGadgetUtils;
}
/**
* {@inheritDoc}
*/
@Override
public String getHtml(BrowseContext context) {
webResourceManager.requireResource("com.atlassian.gadgets.embedded:gadget-standalone-resources");
final Map params = new HashMap();
params.put("waitImage", "/download/resources/com.marvelution.jira.plugins.sonar/images/wait.gif");
params.put("projectId", context.getProject().getId());
if (associationManager.hasSonarAssociation(context.getProject().getId())) {
params.put("isAssociated", Boolean.TRUE);
final SonarAssociation sonarAssociation =
associationManager.getSonarAssociation(context.getProject().getId());
params.put("currentSonarServer", sonarAssociation.getSonarServer());
params.put("currentSonarProject", sonarAssociation.getSonarProject());
params.put("gadgetIds", sonarGadgetUtils.getGadgetIds());
params.put("layout", sonarPanelLayoutManager.getLayout());
} else {
params.put("isAssociated", Boolean.FALSE);
}
final boolean isAdmin = permissionManager.hasPermission(Permissions.ADMINISTER, context.getUser());
params.put("isAdmin", isAdmin);
if (isAdmin) {
webResourceManager.requireResource("com.marvelution.jira.plugins.sonar:sonar-admin");
} else {
webResourceManager.requireResource("com.marvelution.jira.plugins.sonar:sonar-panel");
}
return descriptor.getHtml("view", params);
}
/**
* {@inheritDoc}
*/
@Override
public boolean showPanel(BrowseContext context) {
return permissionManager.hasPermission(Permissions.BROWSE, context.getProject(), context.getUser());
}
}