com.marvelution.jira.plugins.sonar.web.action.AdministerSonarLayout 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 java.util.Map;
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;
import com.marvelution.jira.plugins.sonar.service.SonarPanelLayoutManager;
import com.marvelution.jira.plugins.sonar.utils.SonarGadgetUtils;
/**
* WebAction to view and manage the Sonar Panel Layout
*
* @author Mark Rekveld
*/
@SuppressWarnings("unchecked")
public class AdministerSonarLayout extends AbstractSonarWebActionSupport {
private static final long serialVersionUID = 1L;
private final SonarPanelLayoutManager sonarPanelLayoutManager;
private final SonarGadgetUtils sonarGadgetUtils;
/**
* Constructor
*
* @param sonarAssociationManager 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 AdministerSonarLayout(SonarAssociationManager sonarAssociationManager,
SonarPanelLayoutManager sonarPanelLayoutManager, PermissionManager permissionManager,
WebResourceManager webResourceManager, SonarGadgetUtils sonarGadgetUtils) {
super(permissionManager, sonarAssociationManager, webResourceManager);
this.sonarPanelLayoutManager = sonarPanelLayoutManager;
this.sonarGadgetUtils = sonarGadgetUtils;
}
/**
* Default success action execution method
*
* @return Result Name
* @throws Exception in case of exceptions during the method execution
*/
public String doSuccess() throws Exception {
if (hasPermissions()) {
webResourceManager.requireResource("com.marvelution.jira.plugins.sonar:sonar-admin");
webResourceManager.requireResource("com.atlassian.gadgets.embedded:gadget-standalone-resources");
return SUCCESS;
} else {
return PERMISSION_VIOLATION_RESULT;
}
}
/**
* Get the default sample {@link SonarAssociation} for the panel layout view
*
* @return the default {@link SonarAssociation}, may be null
*/
public SonarAssociation getDefaultAssociation() {
if (getSonarAssociationManager().hasSonarAssociations()) {
return getSonarAssociationManager().getSonarAssociations().toArray(
new SonarAssociation[getSonarAssociationManager().getSonarAssociations().size()])[0];
} else {
return null;
}
}
/**
* Get the current configured layout
*
* @return the current configured Layout
*/
public Map> getLayout() {
return sonarPanelLayoutManager.getLayout();
}
/**
* Get all the available gadgetIds
*
* @return {@link Collection} with all the available gadgetIds
*/
public Collection getGadgetIds() {
return sonarGadgetUtils.getGadgetIds();
}
}