Template Providers Directory

In order to extend Mail Template definitions, Minyaa introduces a Template Providers Directory.

Its allows you to extend Mail Templates by replacing the Template Manager.



Currently, JIRA does not stored Mail Template in Database!

To avoid to develop a new solution with its own Database storage, with new Web interfaces and, surely, have to remove them, when Database storage will be implemented natively by JIRA, Minyaa choose to extend just the existing mechanism based on a XML configuration.

How it is working ?

The default JIRA implementation of TemplateManager (DefaultTemplateManager) is replaced by ProvidedTemplateManager



This ProvidedTemplateManager is able to offer Mail Templates provided by TemplateProvider registered into the TemplateProviderDirectory.



To extend Mail Template, you have to register your own Template Provider.

How to built you own Template Provider ?

In your plugin, follow below steps :

  1. Create TemplateProvider as follow

    				
    package com.yourcompany.jira.template.provider;
    
    import com.minyaa.jira.template.provider.TemplateProvider;
    
    public class YourTemplateProvider implements TemplateProvider {
    
    	/* Configuration fiel where template are refrenced */
    	public static String configFile = "com/yourcompany/your/email-template-id-mappings.xml";
    	
    	/** The Template Provider registers itself to the TemplateProviderDirectory */
    	public YourTemplateProvider(TemplateProviderDirectory _directory) {
    		_directory.addTemplateProvider(this);
    	}
    	
    	/** Accessor to the Configuration File */
    	public String getConfigFile() {
    		return configFile;
    	}
    
    	/** Class used by TemplateProviderDirectory the to reference the TemplateProvider */
    	public Class getTypeClass() {
    		return YourTemplateProvider.class;
    	}
    
    	/** Root Folder where the Mail Template are stored */
    	public String getTemplateRootFolder() {
    		return "com/yourcompany/your/templates/";
    	}
    	
    }
    


  2. Create the configuration file com/yourcompany/your/email-template-id-mappings.xml

    				
    <!-- this file should be updated in synch with upgrade-system-event-types.xml -->
    <templatemappings>
        <templatemapping id="100000">
            <name>Your 1st Mail Template</name>
            <template>MailTemplate1.vm</template>
            <templatetype>issueevent</templatetype>
        </templatemapping>
        <templatemapping id="100001">
            <name>Your 2nd Mail Template</name>
            <template>MailTemplate2.vm</template>
            <templatetype>issueevent</templatetype>
        </templatemapping>
    </templatemappings>
    


    Currently, JIRA Mail Template uses id 1 to 16 for Mail Template for issue event, and 10000 for the Filter Subscription template.

    Choose your id in order to avoid conflict with JIRA, and also with other implementation this TemplateProvider.



  3. Create your Mail Templates in com/yourcompany/your/templates/ ...

    • For Mail Subject : Create MailTemplate1.vm and MailTemplate2.vm in com/yourcompany/your/templates/subject
    • For HTML Core Mail : Create MailTemplate1.vm and MailTemplate2.vm in com/yourcompany/your/templates/html
    • For Text Core Mail : Create MailTemplate1.vm and MailTemplate2.vm in com/yourcompany/your/templates/text


  4. Define your TemplateProvider as component in atlassian-plugin.xml :

    				
    <atlassian-plugin key="jira.plugin.yourcompany.mail" name="Your Company Plugin for Mail Template">
    	<plugin-info>
            <description>${pom.description}</description>
            <version>${pom.version}</version>
            <vendor name="${pom.organization.name}" url="${pom.organization.url}"/>
    	</plugin-info>
    	...
    	<component key="YourTemplateProvider" name="YourTemplateProvider" class="com.yourcompany.jira.template.provider.YourTemplateProvider" />	
    	...
    </atlassian-plugin>
    
    


Existing Template Provider

Minyaa provides already Template Providers :
Provider Configuration Details
com.minyaa.jira.template.provider.DefaultTemplateProvider email-template-id-mappings.xml Default JIRA Template
com.minyaa.jira.template.provider.TimesheetTemplateProvider com/minyaa/timesheet/email-template-id-mappings.xml Timesheet Notification Templates