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

com.quamto.jira.web.base.BaseWebController Maven / Gradle / Ivy

Go to download

Library that contains the class base to support functionalities in the JIRA Plugins

The newest version!
package com.quamto.jira.web.base;


import javax.servlet.http.HttpServletRequest;

import com.quamto.jira.business.config.model.AddOnSettingsModel;
import com.quamto.jira.business.context.EnvironmentVariables;
import org.springframework.web.servlet.ModelAndView;

import com.atlassian.connect.spring.AtlassianHostUser;
import com.quamto.core.Result;
import com.quamto.jira.base.BaseController;

public class BaseWebController extends BaseController {

	protected String addonKey = "";
	
	public BaseWebController(Class subClass, String addonKey) {
		this(subClass.getName(), addonKey);
	}
	
	public BaseWebController(String subClassName, String addonKey) {
		super(subClassName);
		this.addonKey = addonKey;
	}

	/**
	 * Set the global parameters for the application views
	 * @param mv Model and view to set global parameters
	 * @param request Http request
	 * @param hostUser Host user information
	 * @return View with the model attributes added
	 */
	protected ModelAndView setGlobalParameters(ModelAndView mv, HttpServletRequest request, AtlassianHostUser hostUser) throws Exception{
		try {
			if(mv != null){
				Result  result = getAddOnSettings(hostUser);
				
				if(result.isSuccessful()){
					AddOnSettingsModel addOnSettingsModel = (AddOnSettingsModel) result.getPayload();
					
					String hostJiraBaseURL = addOnSettingsModel.getBaseUrl();
					String requestURL = request.getRequestURL().toString();
					mv.addObject("allJs", hostJiraBaseURL + "/atlassian-connect/all.js");
					mv.addObject("baseJiraUrl", hostJiraBaseURL);
					/* change HTTP by HTTPS*/
					mv.addObject("baseUrl", requestURL.replace(request.getRequestURI(), "").replace("http:", "https:"));
					mv.addObject("userKey", hostUser.getUserKey());
					mv.addObject("clientId", addOnSettingsModel.getId());
					mv.addObject("appVersion", EnvironmentVariables.getAppVersion());

				}else{
					throw new Exception(result.getStringMessage());
				}	
			}
		} catch (Exception e) {
			throw e;
		}
		return mv;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy