It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ThirdPartyPluginLicenseStorageManager Example Code

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;
        }
	}
}

1 answer

1 accepted

0 votes
Answer accepted

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.

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 :)

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?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Agile

Overview of Advanced Roadmaps UI + Get started with Automation for Jira - Demo Den September 2020

Deliver better and faster value to your customers with the Jira automation platform. Watch this Demo Den series below to learn how to use the new interface and set up automation rules to help your te...

1,293 views 3 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you