I am trying to implement a license validiy in a jira plugin. I need this check in a velocity file.
I have a class for this. I cannot find any example about it. How can I make licence validity check in velocity file?
import com.atlassian.upm.api.license.entity.PluginLicense; import com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginUnresolvedException; import com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManager; public class License { private final ThirdPartyPluginLicenseStorageManager licenseManager; public License(ThirdPartyPluginLicenseStorageManager licenseManager){ this.licenseManager = licenseManager; } public boolean isLicenseValid(){ try { //Check and see if a license is currently stored. //This accessor method can be used whether or not a licensing-aware UPM is present. if (licenseManager.getLicense().isDefined()) { PluginLicense pluginLicense = licenseManager.getLicense().get(); //Check and see if the stored license has an error. If not, it is currently valid. if (pluginLicense.getError().isDefined()) { //A license is currently stored, however, it is invalid (e.g. expired or user count mismatch) return false; } else { //A license is currently stored and it is valid. return true; } } else { //No license (valid or invalid) is stored. return false; } } catch (PluginLicenseStoragePluginUnresolvedException e) { //The current license status cannot be retrieved because the Plugin License Storage plugin is unavailable. return false; } } }
Hi,
Which element loads the velocity file? Servlet, JiraWebActionSuport...
In this controller Class, in constructor you inject the ThirdPartyPluginLicenseStorageManager component as licenseManager and then pass it as parameter when create License object:
public boolean hasLicense(){ License license = new License(licenseManager); return license.isLicenseValid(); }
In the velocity file you could do this:
#if($action.hasLicense()) //Error license #else //...
or you could pass the result of the method as velocityparams and then check it in the velocity.
Regards
Thank you Carlos. I am using JiraWebActionSupport. I created the method hasLicence(), but how can I create the licenceManager object? I looked the ThirdPartyPluginLicenseStorageManager API. However, it is an interface, so it has no constructor.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I got it. I must use ThirdPartyPluginLicenseStorageManager in a servlet or jirawebaction. Pass parameters in constructor. Because it is an abstract class, and has no constructor. I used the code in this example https://developer.atlassian.com/display/UPM/Tutorial%3A+Adding+Licensing+Support+to+Your+Add-on I just added ThirdPartyPluginLicenseStorageManager to the constructor of my action class, and a method hasLicense(), its content is also copied from LicenseHelloServlet. It is totally works :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When license is invalid, settings page will not be displayed great :). However, plugin has custom field modules. When license has expired, the custom field is still on the custom field list, and the custom fields added before the expiration of the lisence are usable in related screens. How can I solve it? Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Recommended Learning For You
Level up your skills with Atlassian learning
Jira Align Program Essentials
Learn how to use Jira Align at the program level and how to plan for and manage your Program Increment (PI).
Managing Agile Boards and Reports
Learn how to pick the right board type for your team and customize it to fit your specific requirements.
Atlassian Certified Associate
Jira Software Board Configuration
Earn an associate-level credential from Atlassian that shows you can effectively configure Jira Software boards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.