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

com.quamto.jira.api.config.WebDirectoryManager 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.api.config;

import java.io.File;

import com.quamto.core.QException;
import com.quamto.core.QException.ExceptionType;
import com.quamto.util.TypesValidator;
import com.quamto.core.UserMessages;
import com.quamto.core.UserMessages.ErrorMessages;
import com.quamto.jira.data.common.JEnumerators.PluginEntities;

/**
 * Class responsible for administering the directory of JIRA Plugins
 *  
 * @author jholguin
 * @since 16/12/2015
 *
 */
public abstract class WebDirectoryManager {
	
	public enum AppDirectories{
		Configuration,
		Attachements
	}
	
	/**
	 * Declaration of constants directory names or configuration files
	 * 
	 */
	private static final String dirAttachements = "attachments";
	private static final String dirConfiguration = "config";
	
	private static String servletName = "";
	private static String applicationRealPath = "";
	
	
	
	/**
	 * Sets the absolute path of the application within the information environment 
	 * to establish application directories
	 * 
	 * @param path Physical path of the application directory
	 */
	public static void setAbsolutePathApp(String path) throws QException{
		
		if(!TypesValidator.isNullOrEmpty(path)){
			
			File directoryPath = new File(path);
			
			if(directoryPath.exists()){
				
				applicationRealPath = path;
			}else{
				throw new QException(ExceptionType.OperationNotAllowed_err, 
						new UserMessages(ErrorMessages.InvalidApplicationPath));
			}
		}else{
			throw new QException(ExceptionType.OperationNotAllowed_err, 
					new UserMessages(ErrorMessages.InvalidApplicationPath));
		}
	}
	
	/**
	 * Gets the directory name given identity attachments
	 * @param entityType Entity that is desired attachments
	 * @return The directory name of the identity given to attachment handling
	 */
	public static String getAttachementPathName(PluginEntities entityType){
		
		String pathName = "";
		 
		switch (entityType) {
			case DesignElements:
				pathName += "design/";
				break;
			case TestCases:
				pathName += "tests/";
				break;
			case Projects:
				pathName += "projects/";
				break;
			default:
				break;
			}
		return pathName;
	}
	
	/**
	 * It lets get physical directory path attachments
	 * @param entityType Entity that is desired attachments
	 * @return Physical directory path attachments
	 */
	public static String getAttachementsAbsolutePath(PluginEntities entityType){
		return getAbsolutePath(AppDirectories.Attachements) + getAttachementPathName(entityType);
		 
	}
	
	/**
	 * It lets get physical directory path configuration files
	 * @return Physical directory path settings
	 */
	public static String getConfigAbsolutePath(){
		return getAbsolutePath(AppDirectories.Configuration);
	}
	
	/**
	 * Returns the physical path of the directory of the application attachments
	 * @param enumDir Directory to be obtained
	 * @return The absolute path of the directory of the application requested
	 */
	public static String getAbsolutePath(AppDirectories enumDir){
		
		String dir = "";
		
		switch (enumDir) {
			case Attachements:
				dir = dirAttachements;
				break;
			case Configuration:
				dir = dirConfiguration;
				break;
		}
		return applicationRealPath + dir + "/";
	}
	
	/**
	 * Gets the virtual path where attachments are stored in the application
	 */
	public static String getAttachementsVirtualPath(){
		return getServletName() + "/" +dirAttachements + "/";
	}
	
	/**
	 * Gets the virtual path for the associated file attachments to the elements of the application
	 * @param entityType Type of entity that is desired attachments
	 * @return String with the virtual directory path attachment feature type requested
	 */
	public static String getAttachementsVirtualPath(PluginEntities entityType){
		return getAttachementsVirtualPath() + getAttachementPathName(entityType);
	}
	
	/**
	 * Gets the servlet name
	 */
	public static String getServletName(){
		return servletName;
	}
	
	/**
	 * Sets the servlet name
	 * @param value Servlet name
	 */
	public static void setServletName(String value){
		servletName = "/" + value;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy