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

Bahar Çağlar Oct 29, 2012

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
Carlos Oct 30, 2012

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

Bahar Çağlar Oct 30, 2012

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.

Bahar Çağlar Oct 30, 2012

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

Bahar Çağlar Nov 01, 2012

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Agile

“Save” Jira- A Practical Model of Enterprise Scaled Agile with Delicacy Management

About the Author: Yuhui Gan, 10+ years’ experiences in software engineering management and system architecture, worked in the IT department of an international bank and large consumer enterprise. Ric...

162 views 0 5
Read article

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